<?php


if (ini_get('register_globals') != 1) {
	if ((isset($_POST) == true) && (is_array($_POST) == true)) extract($_POST, EXTR_OVERWRITE);
	if ((isset($_GET) == true) && (is_array($_GET) == true)) extract($_GET, EXTR_OVERWRITE);
}
require_once "../../maincore.php";
require_once THEMES."templates/header.php";

if (file_exists(INFUSIONS."ticket_system/locale/".$settings['locale'].".php")) {
	include INFUSIONS."ticket_system/locale/".$settings['locale'].".php";
} else { include INFUSIONS."ticket_system/locale/English.php"; }

include INFUSIONS."ticket_system/infusion_db.php";
error_reporting(E_ALL ^ E_NOTICE);
if (iMEMBER){

if (!isset($stype) || !in_array($stype, array("uvt","uvtl","ust"))) redirect("index.php");
if ($stype == "uvt") {

opentable("  ");

$tic = dbquery("SELECT * FROM ".DB_TICKETSYSTEM." WHERE id = '".$_POST['id']."'");
while($test21 = mysql_fetch_assoc($tic)){

echo "
<font size = '6'><b>".$test21['subject']."</b><br></font>
<legend>".$locale['tick_001']."</legend>
		<table class= 'tbl1' border='0' cellpadding='2' cellspacing='1' width='100%'>
			   <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_002']."</td>
			<td><input name='username' size='30' value='".$test21['username']."' type='text' disabled='disabled' class='textbox'></td>
		  </tr>
			  <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_003']."</td>
			<td><input name='name' size='30' value='".$test21['name']."' type='text' disabled='disabled' class='textbox'></td>
		  </tr>
		  <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_004']."</td>
			<td><select name='priority disabled='disabled' class='textbox'>";
			
if ( $test21['priority'] == "4"){echo "<option value='4' style='color: rgb(0, 255, 0);' selected='selected'>".$locale['tick_005']."</option>";}
if ( $test21['priority'] == "3"){echo "<option value='3' style='color: rgb(255, 255, 0);'selected='selected'>".$locale['tick_006']."</option>";}
if ( $test21['priority'] == "2"){echo "<option value='2' style='color: rgb(255, 0, 0);'selected='selected'>".$locale['tick_007']."</option>";}
if ( $test21['priority'] == "1"){echo "<option value='1' style='color: rgb(0, 0, 255);'selected='selected'>".$locale['tick_008']."</option>";}
			        
echo"		

					</select></td>
		  </tr>
		  </table>
			  </fieldset>
		<legend>".$locale['tick_012']."</legend>
		<table class= 'tbl1' border='0' cellpadding='2' cellspacing='0' width='100%'>
		  <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_013']."</td>
			  <td><input name='subject' class='textbox' size='40' value='".$test21['subject']."' type='text'disabled='disabled'></td>
		  </tr>

		  <tr><td align='left' valign='top' width='10%'></td>
			<td><textarea name='message' cols='85' rows='10' class='textbox' disabled='disabled'>".$test21['message']."</textarea>
			<br><table border='0' cellpadding='3' cellspacing='1' width='100%'><tr>
                      
                      </tr></table></div></td>
		  </tr>
		</table>
		  </fieldset>

		

";

$tic1 = dbquery("SELECT * FROM ".DB_TICKETSYSTEM." WHERE addition = '".$_POST['id']."' Order BY date ASC");
while($test2 = mysql_fetch_assoc($tic1)){
echo"
<legend>".$locale['tick_014']."</legend>
		<table class= 'tbl1' border='0' cellpadding='2' cellspacing='0' width='100%'>
		 
		  <tr><td align='left' valign='top' width='10%'></td>
			<td><textarea name='message' cols='85' rows='10' class='textbox'>".$test2['message']."</textarea>
			<br><table border='0' cellpadding='3' cellspacing='1' width='100%'><tbody><tr>
           </tr></table></div></td>
		  </tr>
		</tbody></table>
		  </fieldset>

";
}
if ( $test21['closed'] == "0"){
echo "
<form name='inputform' method='post' action='ticket.php?stype=uvtl'>
<legend>".$locale['tick_015']."</legend>
		<table class= 'tbl1' border='0' cellpadding='2' cellspacing='0' width='100%'>
		  <tbody>
		  <tr><td align='left' valign='top' width='10%'></td>
			<td><textarea name='message' cols='85' rows='10' class='textbox'></textarea>
			<br><table border='0' cellpadding='3' cellspacing='1' width='100%'><tbody><INPUT TYPE='hidden' NAME='addition1' VALUE='".$_POST['id']."'><tr>
           </tr></tbody></table></td>
		  </tr>
		</tbody></table>
		  </fieldset>
		  		  	<table border='0' cellpadding='2' cellspacing='1' width='100%'>
		  <tbody><tr>
			<td><input name='submit' value='".$locale['tick_016']."' type='submit' class='button'>&nbsp;&nbsp;<input name='reset' value='".$locale['tick_017']."' type='reset'class='button'></td>
		  </tr>
		</tbody></table>		
		</form>
";
}else{
echo "<div align = 'center'><font size='4'>".$locale['tick_018']."</font></div>";
}
echo "</div>";
}
closetable();
}

if ($stype == "uvtl") {


if (isset($_POST['addition1'])) {

$addition = $_POST['addition1'];
$message = stripinput($_POST['message']);
$result = dbquery("INSERT INTO ".DB_TICKETSYSTEM." (addition, date, message) VALUES ('".$addition."', '".time()."', '".$message."')");
$result1 = dbquery("UPDATE ".DB_TICKETSYSTEM." SET active = '1' WHERE id = '".$_POST['addition1']."'");
}

opentable("  ");
echo "
 <div align='center'><font size = '6'><b>".$locale['tick_019']."</b></font>
        <table class= 'tbl1' border='2' width ='100%'>
        <tr><td width ='50%'>".$locale['tick_020']."</td><td width= '10%'>".$locale['tick_021']."</td><td width='10%'>".$locale['tick_022']."</td><td width='10%'>".$locale['tick_023']."</td><td width='10%'>".$locale['tick_024']."</td><td width='10%'>".$locale['tick_025']."</td></tr>
";
$t="1";
$tic4 = dbquery("SELECT * FROM ".DB_TICKETSYSTEM." WHERE username = '".$userdata['user_name']."' ORDER BY closed ASC, active DESC, priority ASC, date DESC");
while($test25 = mysql_fetch_assoc($tic4)){

$t= $t + "1";
if ( $test25['closed'] == "1"){
$status= $locale['tick_026'];
}else{
$status= $locale['tick_027'];
}
$progress = "";


if ( $test25['active'] == "1"){
$progress= $locale['tick_030'];
}else{
$progress= $locale['tick_031'];
}



if ( $test25['priority'] == "1"){ 
$priority = "<font color ='blue'>".$locale['tick_032']."</font>";
}
if ( $test25['priority'] == "2"){ 
$priority = "<font color ='red'>".$locale['tick_033']."</font>";
}
if ( $test25['priority'] == "3"){ 
$priority = "<font color ='yellow'>".$locale['tick_034']."</font>";
}
if ( $test25['priority'] == "4"){ 
$priority = "<font color ='green'>".$locale['tick_035']."</font>";
}
$meh = $test25['id'];
$dame = showdate("%d-%m-%y %H:%M", $test25['date']);
echo"
<form name='inputform".$t."' method='post' action='ticket.php?stype=uvt'>
<tr><td>".$test25['subject']."</td><td>".$status."</td><td>".$progress."</td><td>".$priority."</td><td>".$dame."</td><td><input name='submit1' value='".$locale['tick_036']."' type='submit' class='button'><INPUT TYPE='hidden' NAME='id' VALUE='".$meh."'></td></tr>
</form>
";

}
echo"
</table></div>
";
closetable();
}

if ($stype == "ust") {

if (isset($_POST['subject'])) {
$addition = "0";
$closed = "0";
$active = "1";
$username = $userdata['user_name'];
$subject = stripinput($_POST['subject']);
$name = stripinput($_POST['name']);
$message = stripinput($_POST['message']);
$priority = stripinput($_POST['priority']);
$result = dbquery("INSERT INTO ".DB_TICKETSYSTEM." (addition, username, name, subject, priority, message, closed, active, date) VALUES ('".$addition."', '".$username."', '".$name."', '".$subject."', '".$priority."', '".$message."', '".$closed."', '".$active."', '".time()."')");
}

opentable("  ");
echo "    

 <div align='center'><font size = '6'><b>".$locale['tick_040']."</b></font></div>
        <form name='inputform' method='post' action='ticket.php?stype=ust' onSubmit='return ValidateForm(this)'>		
		<legend>".$locale['tick_041']."</legend>
		<table class= 'tbl1' border='0' cellpadding='2' cellspacing='1' width='100%'>
			  <tbody>
			  <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_042']."</td>
			<td><input name='username' size='30' class='textbox' value='".$userdata['user_name']."' type='text' disabled='disabled'></td>
		  </tr>
			  <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_043']."</td>
			<td><input name='name' size='30' value='' class='textbox' type='text'></td>
		  </tr>
		  <tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_044']."</td>
			<td><select class='textbox' name='priority'>
					<option value='4' style='color: rgb(0, 255, 0);' selected='selected'>".$locale['tick_035']."</option>
					<option value='3' style='color: rgb(255, 255, 0);'>".$locale['tick_034']."</option>
					<option value='2' style='color: rgb(255, 0, 0);'>".$locale['tick_033']."</option>
					<option value='1' style='color: rgb(0, 0, 255);'>".$locale['tick_032']."</option>
					</select></td>
		  </tr>
		  </tbody></table>
			  </fieldset>
		<legend>".$locale['tick_045']."</legend>
		<table class= 'tbl1' border='0' cellpadding='2' cellspacing='0' width='100%'>
		  <tbody><tr>
			<td align='left' valign='top' width='10%'>".$locale['tick_046']."</td>
			  <td><input name='subject' size='40'class='textbox value='' type='text'></td>
		  </tr>

		  <tr><td align='left' valign='top' width='10%'></td>
			<td><textarea name='message' cols='85' rows='10' class='textbox'></textarea>
			<br><table border='0' cellpadding='3' cellspacing='1' width='100%'><tbody><tr>
                        <td>&nbsp; </td>
                      </tr></tbody></table></div></td>
		  </tr>
		</tbody></table>
		  </fieldset>
		
		  
		  
		<table border='0' cellpadding='2' cellspacing='1' width='100%'>

		  <tbody><tr>
			<td><input name='submit' value='".$locale['tick_047']."' type='submit' class='button'>&nbsp;&nbsp;<input name='reset' value='".$locale['tick_048']."' type='reset' class='button'></td>
		  </tr>
		</tbody></table>		
		</form>";
	$rule=$locale['tick_049'];	

		
	echo "<script language='JavaScript'>
function ValidateForm(frm) {
	
	
	if (frm.name.value==\"\") {
		alert(\"".$rule."\");
		return false;
	}
	if (frm.subject.value==\"\") {
		alert(\"".$rule."\");
		return false;
	}
	if (frm.message.value==\"\") {
		alert(\"".$rule."\");
		return false;

}
}
</script>\n";

closetable();
}

}
require_once THEMES."templates/footer.php";
?>