<?php
ob_start();
session_start();
if($_SESSION['admin']=="")
{
	header("location: login.php");
}
include("../var.php");

$pageTitle = "قائمة الاختبارات";

include("header.php");
?>
<table cellpadding="5" cellspacing="0">
<tr><td valign="top">
<?php
	$pgget = "";
	if(isset($_GET['pg'])){ $pgget = $_GET['pg']; }
$pg = ($pgget)?$pgget:1;
$rec = 20;
$from = ($pg-1)*$rec;

	$con = mysqli_connect($DBHOST,$DBUSER,$DBPASS,$DBNAME) or die("Some error occurred during connection " . mysqli_error($con));
	mysqli_query($con, "SET CHARACTER SET 'utf8'");
	$sql = "SELECT * FROM `quiz` order by id DESC";
	$res = mysqli_query($con, $sql);

$n = @mysqli_num_rows($res);

if($n)
{
	$totalPage = ceil($n/$rec);
	for($p=1;$p<=$totalPage;$p++)
	{
		if($p==$pg)
			$Page[] = '<a href="quizlist.php?pg='.$p.'" class="vi_page">'.$p.'</a>';
		else
			$Page[] = '<a href="quizlist.php?pg='.$p.'" class="invi_page">'.$p.'</a>';
	}
	$sql .= " limit $from,$rec";
	$res = mysqli_query($con, $sql);
	$tRec = @mysqli_num_rows($res);
	?>
	<table cellpadding="5" cellspacing="0" float="left">
<?
$qdel = "";
if(isset($_GET['qdel'])){ $qdel = $_GET['qdel']; }
if ($qdel == 1)
{
?>
	<tr class="tablehead">
		<td colspan="8" align="center" style="color: red;">تم حذف الاختبار بنجاح</td>
	</tr>
<?}?>
	<tr class="tablehead">
		<td width="70" align="center">#</td>
		<td width="300" align="center">اسم الاختبار</td>
		<td width="50" align="center">اللغة</td>
		<td width="130" align="center">تم اختباره</td>
		<td width="130" align="center">عدد الاسئلة</td>
		<td width="130" align="center">عدد الاجوبة</td>
		<td width="70" align="center">الحالة</td>
		<td width="200" align="center">تعديل / مشاهدة</td>
	</tr>
	<?php
	$sno = $from + 1;
	while($game = mysqli_fetch_array($res))
	{
		$qid = $game['id'];
		$langid = $game['lang'];
		$totalquestions = mysqli_fetch_row(mysqli_query($con, "SELECT count(*) FROM questions where quizid=$qid"));
		$totalquestions = $totalquestions[0];
		$totalresult = mysqli_fetch_row(mysqli_query($con, "SELECT count(*) FROM result where quizid=$qid"));
		$totalresult = $totalresult[0];
		$langTitle = @mysqli_fetch_array(mysqli_query($con, "select * from lang where id=$langid limit 0,1"));
		?>
		<tr class="row<?php echo $sno%2;?>_view">
		<td align="center"><?=$game['id'];?></td>
		<td align="center"><?=base64_decode($game['title']);?></td>
		<td align="center"><?=$langTitle['lang'];?></td>
		<td align="center"><?=$game['stats'];?></td>
		<td align="center"><?=$totalquestions;?></td>
		<td align="center"><?=$totalresult;?></td>
		<td align="center">
		<?
		if ($game['live'] == 1) { echo "<img src='img/online.png'/>"; } else{ echo "<img src='img/offline.png'/>"; } ?>
		</td>
		<td align="center">
		<a href="edit_quiz.php?id=<?php echo $game['id'];?>"><img src="img/b_edit.png" border="0"></a>&nbsp;
		<a href="quiz_view.php?id=<?php echo $game['id'];?>"><img src="img/b_view.png" border="0"></a>
		</td>
		</tr>
		<?php
		$sno++;
	}	?>
	<tr>
	<td colspan="2"><b>الصفحة &raquo;</b>&nbsp;<?php echo implode("",$Page);?></td>
	<td colspan="5" align="right"><a href="add_quiz.php" class="in_link" style="text-decoration: none;"><b><font color="green"> + </font>اضف اختبار جديد</b></a></td>
	</tr>
	<tr><td colspan="3"><small>مشاهدة <?php echo ($from+1);?> حتى <?php echo $tRec;?> من  <?php echo $n;?></small></td></tr>
	</table>
	<?php
}
else
{
	echo '<br><br><br><br><br><br><center><b>لا يوجد اقسام</b></center>';
}
?>
</td></tr></table>
<?php	include("footer.php");?>
