<?php
	if(! function_exists('check_session')){ die(); }

	$permissions	=	$GLOBALS['permission'];
	$AS			= $permissions['allowed_sections'];
	if(empty($AS) OR $AS == 'all' OR ! is_numeric($AS)){
		$ADD	= '';
	}else{
		$ADD	= 'AND `section_id` IN ('.$AS.')';
	}
	$tickets_query		= mysql_query("SELECT `id`,`subject`,`level`,`section_id` FROM `tickets` WHERE `new`='1' ".$ADD." ORDER BY `id` DESC LIMIT 5");
	$num['tickets']		= mysql_num_rows($tickets_query);
	$members_query		= mysql_query("SELECT `id`,`username`,`reg_date` FROM `members` ORDER BY `id` DESC LIMIT 5");
	$num['members']		= mysql_num_rows($members_query);
	$query1				= mysql_query("SELECT `id` FROM `members`");
	$query2				= mysql_query("SELECT `id` FROM `tickets`");
	$query3				= mysql_query("SELECT `id` FROM `tickets` WHERE `new`='1'");
	$num['tot_members']	= mysql_num_rows($query1);
	$num['tot_tickets']	= mysql_num_rows($query2);
	$num['tot_tickets2']= mysql_num_rows($query3);

?>

       			<div id="rightnow">
                    <h3 class="reallynow">
                        <span>مرحباً <?= $_SESSION['member_username']; ?></span>
                        <br />
                    </h3>
				    <p class="youhave" style="text-align: right">مرحباً , يوجد <strong><?= $num['tot_tickets']; ?></strong>
					تذكرة منها <strong><?= $num['tot_tickets2']; ?></strong> غير مقروءة
					ولديك <strong><?= $num['tot_members']; ?></strong> عضو .
                    </p>
			  </div>
			
	<?php
	if($permissions['top_man'] == 1 AND is_dir('../setup')){
	?>
	<br />
	<div class="error"><strong>تنبيه ! :</strong>المجلد setup موجود للآن ! الرجاء حذفه لأسباب أمنيه .</div>
	<br />
	<?php
	}
	?>

			<br />
			<?php if($permissions['top_man'] == 1 OR $permissions['allow_control'] == 1){ ?>
			     <div id="rightnow" style="width: 50%">
                    <h3 class="reallynow">
                        <span>الإستعراض السريع للتذاكر</span>
                        <br />
                    </h3>
					<form method="post" action="tickets.php?step=find_ticket" style="margin: 0">
					أدخل رمز التذكرة لإستعراضها : <input style="margin: 0" type="text" name="code" />
					<input type="submit" value="ذهاب" style="margin: 0" />
					</form>
			  </div><br /><div style="clear: both">&nbsp;</div>
			 
			<?php } if($permissions['allow_members'] == 1){ ?>
                  <div id="infobox" class="margin-left">
                    <h3>آخر الأعضاء المُسجلون</h3> 
                    <table>
						<thead>
							<tr>
                            	<th>الإسم</th>
                                <th>تاريخ التسجيل</th>
                                <th>تحكم</th>
                            </tr>
						</thead>
						<tbody>
						<?php while($rows = mysql_fetch_array($members_query)){ ?>
							<tr>
                            	<td><a href="members.php?step=edit&id=<?= $rows['id']; ?>"><?= $rows['username']; ?></a></td>
                                <td><?= $rows['reg_date']; ?></td>
                                <td>
								<a href="members.php?step=edit&id=<?= $rows['id']; ?>" alt="تعديل"><img src="style/img/icons/page_white_edit.png" title="تعديل" /></a>
								<a onclick="return confirm('هل أنت متأكد ؟');" href="members.php?step=delete_one&id=<?= $rows['id']; ?>"><img src="style/img/icons/page_white_delete.png" title="حذف" /></a></td>
                            </tr>
						<? } ?>
						</tbody>
					</table>

                  </div>
			<? } ?>

			<?php if($permissions['allow_control'] == 1){ ?>
                  <div id="infobox">
                    <h3>آخر التذاكر</h3> 
                    <table>
						<thead>
						<?php if($num['tickets'] > 0){ ?>
							<tr>
                            	<th>الموضوع</th>
                                <th>الأهمية</th>
                                <th>تحكم</th>
                            </tr>
						<? }else{ ?>
							<tr>
                            	<th>لانتائج</th>
                            </tr>
						<? } ?>
						</thead>
						<tbody>
						<?php
						if($num['tickets'] > 0){
						while($rows	= @mysql_fetch_array($tickets_query)){ ?>
							<tr>
                            	<td><a href="tickets.php?step=read&amp;id=<?= $rows['id']; ?>&amp;to=tickets.php?step=control[and]do=unread"><?= substr($rows['subject'],0,20); ?></a></td>
                                <td><?= level_replacer($rows['level']); ?></td>
                                <td>
								<a href="tickets.php?step=read&id=<?= $rows['id']; ?>&amp;to=tickets.php?step=control[and]do=unread" alt="تعديل"><img src="style/img/icons/page_white_edit.png" title="تعديل" /></a>
								<a onclick="return confirm('هل أنت متأكد ؟');" href="tickets.php?step=delete_one&id=<?= $rows['id']; ?>&to=tickets.php?step=control[and]do=unread"><img src="style/img/icons/page_white_delete.png" title="حذف" /></a></td>
                            </tr>
						<? }
						}else{ ?>
							<tr>
                            	<td>ليس لديك أي تذاكر غير مقروءة</td>
                            </tr>
						<? } ?>
						</tbody>
					</table>
                  </div>

			<? } ?>
			<br /><div style="clear: both">&nbsp;</div>