<?php 	if(! function_exists('check_session')){ die(); } if(! isset($rows)){$rows=$GLOBALS['rows'];} ?>
    <form method="post" action="tickets.php?step=update&id=<?= $rows['id']; ?>&to=tickets.php?step=read[and]id=<?= $rows['id']; ?>">

	<table style="width: 90%"><tr>
			  <td class="right_table" style="font-size:12pt;text-align:center;font-weight:bold">&nbsp;القسم :-&nbsp;</td>
			  <td class="right_table" style="font-size:12pt;text-align:center;font-weight:bold">&nbsp;حالة التذكرة :-&nbsp;</td>
			  <td class="right_table" style="font-size:12pt;text-align:center;font-weight:bold">&nbsp;الأهمية :-&nbsp;</td>
	</tr><tr>
			  <td class="left_table">
						<?php sections_list($rows['section_id']); ?>
			</td>
			  <td class="left_table">
			  <select name="status">
				<option value="1" style="color: green" <?php if($rows['status'] == 1){ echo 'SELECTED'; } ?>>مفتوحة</option>
				<option value="2" style="color: red" <?php if($rows['status'] == 2){ echo 'SELECTED'; } ?>>مغلقة</option>
				<option value="3" style="color: orange" <?php if($rows['status'] == 3){ echo 'SELECTED'; } ?>>تنتظر الرد</option>				
			  </select>
			</td>
			  <td class="left_table">
			  <select name="level">
			  <option value="1" style="color: red" <? if($rows['level'] == 1){ echo 'SELECTED'; }?>>مهمة</option>
			  <option value="2" style="color: green" <? if($rows['level'] == 2){ echo 'SELECTED'; }?>>متوسطة</option>
			  <option value="3" <? if($rows['level'] == 3){ echo 'SELECTED'; }?>>عادية</option>
			  </select>
			</td>
	</tr></table>
	
	
	  <table style="width: 90%">
		  <tr>
			  <td class="head"><span style="font-size: 8pt;text-align: right">#<?= $rows['id']; ?></span> قراءة تذكرة  </td>
		  </tr>
	  </table>
	  <table cellspacing="1" class="style4" style="width: 90%">
		  <tr>
			  <td class="right_table" >&nbsp;الموضوع :-&nbsp;</td>
			  <td class="left_table" style="background: #F8F8F8;"><?= $rows['subject']; ?></td>
			</tr>
		  <tr>
			  <td class="right_table" >&nbsp;نص التذكرة :-&nbsp;</td>
			  <td class="left_table" style="background: #F1f1f1;;border:2px solid #c0c0c0;border-right:0;border-left:0"><?= $rows['text']; ?></td>
			</tr>
		  <tr>
		  <?php if($rows['user_id'] == 0){ ?>
			  <td class="right_table" >&nbsp;بيانات المُرسل :-&nbsp;</td>
			  <td class="left_table" style="font-size: 8pt">العضوية : (غير مُسجل)  <br />الإسم : <?= $rows['name']; ?><br />البريد الإلكتروني : <?= $rows['email']; ?></td>
			<? }else{
			get_userinfo($rows['user_id']);
			?>
			  <td class="right_table" >&nbsp;بيانات المُرسل :-&nbsp;</td>
			  <td class="left_table">عضو مُسجل : <a href="members.php?step=edit&id=<?= $GLOBALS['minfo']['id'] ?>&to=tickets.php?step=read[and]id=<?= $_GET['id']; ?>"><?= $GLOBALS['minfo']['username'] ?></a></td>
			<? } ?>
			</tr>
		  <tr>
			  <td class="right_table" >&nbsp;الـ IP :-&nbsp;</td>
			  <td class="left_table"><?= $rows['ip']; ?></td>
			</tr>
		  <tr>
			  <td class="right_table" >&nbsp;رمز التذكرة :-&nbsp;</td>
			  <td class="left_table"><?= $rows['code']; ?></td>
			</tr>

		  <tr>
			  <td class="right_table" >&nbsp;تاريخ الإضافة :-&nbsp;</td>
			  <td class="left_table"><?= $rows['date']; ?></td>
			</tr>
		<? if($GLOBALS['permission']['top_man'] == 1){
		get_userinfo($rows['first_read']);
		$user	= $GLOBALS['minfo'];
		?>
		  <tr>
			  <td class="right_table" >&nbsp;تاريخ أول قراءة للتذكرة :-&nbsp;</td>
			  <td class="left_table" style="background: #F8F8F8;"><?= $rows['read_date']; ?> بواسطة <a href="members.php?step=edit&id=<?= $user['id']; ?>&to=tickets.php?step=read&id=<?= $_GET['id']; ?>"><?= $user['username'] ?></a></td>
			</tr>
		  <tr>
			  <td class="right_table">&nbsp;نجديد الحالة :-&nbsp;</td>
			  <td class="left_table" style="background: #F8F8F8;">
			  <a href="tickets.php?step=make_new&id=<?= $rows['id']; ?>&to=<?= $_GET['to'] ?>">جعل التذكرة غير مقروءة</a>
			  </td>
			</tr>
		<? } ?>
			
		  </table>

  <br/>
		<input type="submit" value="تحديث البيانات" class="button" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>أو</em>&nbsp;&nbsp;&nbsp;
		<a onclick="return confirm('هل انت متأكد ؟');" href="tickets.php?step=delete_one&id=<?= $rows['id']; ?>&to=<?= $_GET['to']; ?>">حذف التذكرة و جميع الردود عليها</a>
			</form>

	<hr style="border:1px dotted silver" />
	<h3>الردود على التذكرة (<?= $GLOBALS['r_num'];?>): </h3>
	<br />
	<?php if($GLOBALS['r_num'] == 0){ ?><div class="notice">لايوجد ردود على هذه التذكرة حالياً</div><?php }else{
	$r_query	= mysql_query("SELECT * FROM `reply` WHERE `ticket_id`='".$rows['id']."'");
	while($r_rows	= mysql_fetch_array($r_query)){ 
	?>
	
	<table style="width: 100%">
		<tr>
			<td class="right_table" style="font-size: 8pt">#<?= $r_rows['id']; ?></td>
			<td class="left_table" style="background: #F8F8F8;">رد : <?= $r_rows['subject']; ?> | بتاريخ : <?= $r_rows['date']; ?></td>
		</tr>
			<td class="right_table" style="border-top: 1px dotted silver;border-bottom: 1px dotted silver">الرد : </td>
			<td class="left_table" style="border-top: 1px dotted silver;border-bottom: 1px dotted silver"><?= $r_rows['text']; ?></td>
		</tr>
		<?php if($r_rows['user_id'] == 0){ ?>
		<tr>
			<td class="right_table">بواسطة :</td>
			<td class="left_table">
			(<em>غير مُسجل</em>) : 
			<?= $r_rows['name']; ?><br />البريد الإلكتروني: <?= $r_rows['email']; ?></td>
		</tr>
		<?php }else{ ?>
		<tr>
			<td class="right_table">بواسطة :</td>
			<td class="left_table">
			<?php
				$user	= mysql_fetch_array(mysql_query("SELECT `id`,`username`,`group_id` FROM `members` WHERE `id`='".$r_rows['user_id']."'"));
			?>
			<a href="members.php?step=edit&id=<?= $user['id']; ?>&to=tickets.php?step=read[and]id=<?= $rows['id']; ?>"><?= $user['username']; ?></a></td>
		</tr>
		<?php } ?>
		<tr>
			<td class="right_table">الـ IP :</td>
			<td class="left_table"><?= $r_rows['ip']; ?></td>
		</tr>
		</tr>
			<td class="right_table">خيارات :</td>
			<td class="left_table" style="background: #F8F8F8;font-weight: bold">
			<a href="reply.php?step=edit&id=<?= $r_rows['id']; ?>&to=tickets.php?step=read[and]id=<?= $rows['id']; ?>">تعديل</a> | <a onclick="return confirm('هل أنت متأكد ؟');" href="reply.php?step=delete&id=<?= $r_rows['id']; ?>&to=tickets.php?step=read[and]id=<?= $rows['id']; ?>">حذف</a></td>
		</tr>
		
	</table>
	
	<br />
	<?php } } ?>
	
	<div style="clear: both;line-height:20px">&nbsp;</div>
	
		<br />
	<center>
	<form method="post" action="tickets.php?step=reply&id=<?= $rows['id']; ?>&to=tickets.php?step=read[and]id=<?= $rows['id']; ?>">
	<input type="hidden" value="{if $posted.id == ''}{$ticket.id}{else}{$posted.id}{/if}" name="id" />
			<h2>إضافة رد</h2><br />
			<br />
			<?php
			if(! isset($error)){ $error = $GLOBALS['error']; }
			if(! isset($posted)){ $posted	= $GLOBALS['posted']; }
			if($error['error'] == 1){ ?>
			<div style="width: 550px" class="error"><?= $error['msg']; ?></div>
			<br />
			<? } ?>
			
			<table style="width: 550px">
			<tr>
				<td class="right_table" style="width: 200px">الرد : <span class="star">*</span></td>
				<td class="left_table"><textarea name="text" style="width: 250px;height: 100px"><?= $posted['text']; ?></textarea>
			</tr>
			
			</table>
			<br />
			<input class="button" type="submit" value="إرسال الرد" />
			</form>
	</center>

	<br />
	<br />
	<br />
