<?
ob_start();
session_start();
if($_SESSION['admin']=="")
{
	header("location: login.php");
}
include("../var.php");
$getid = "";
if(isset($_GET['id'])){ $getid = $_GET['id']; }
$id = $getid;
$con = mysqli_connect($DBHOST,$DBUSER,$DBPASS,$DBNAME) or die("Some error occurred during connection " . mysqli_error($con));
mysqli_query($con, "SET CHARACTER SET 'utf8'");
$type = "";
if(isset($_GET['type'])){ $type = $_GET['type']; }
if ($type == "result")
{
	$del = $_GET["del"];
	mysqli_query($con, "delete from result where id='$del'");
}
if ($type == "question")
{
	$del = $_GET["del"];
	mysqli_query($con, "delete from questions where id='$del'");
}
if ($type == "quiz")
{
	$del = $_GET["del"];
	mysqli_query($con, "delete from quiz where id='$del'");
	mysqli_query($con, "delete from result where quizid='$del'");
	mysqli_query($con, "delete from questions where quizid='$del'");
	header("location:quizlist.php?qdel=1");
}

$G = @mysqli_fetch_array(mysqli_query($con, "select * from quiz where id=$id limit 0,1"));
$pageTitle = "تفاصيل الاختبار";
include("header.php");
$live = $G['live'];
?>
	<a href="quizlist.php" class="in_link"><center><<== الرجوع لقائمة الاختبارات</center></a>
	<table width="800" cellpadding="5" cellspacing="1">
	<tr class="tablehead" width="100%"><td colspan="2" align="center">معلومات الاختبار</td></tr>
	<tr>
		<td class="td_view1">الاسم</td>
		<td class="td_view2"><?=base64_decode($G['title'])?> <? if ($live == 1) { echo "<img title='الاختبار نشط' src='img/online.png'/>"; } else{ echo "<img title='الاختبار غير نشط' src='img/offline.png'/>"; } ?></td>
	</tr>
	<tr>
		<td class="td_view1" width="120">الوصف</td>
		<td class="td_view2"><?=base64_decode($G['desc'])?></td>
	</tr>
	<tr>
		<td class="td_view1" width="120">تم اختباره</td>
		<td class="td_view2"><?=$G['stats']?></td>
	</tr>
	<tr>
		<td class="td_view1">الاسئلة المتاحة</td>
<?
$asker = "";
$sql = "SELECT * FROM `questions` where quizid=$id order by id ASC";
$res = mysqli_query($con, $sql);
$n = @mysqli_num_rows($res);
if($n)
{
?>
		<td class="td_view2">
<?php
			while($game = mysqli_fetch_array($res))
			{
?>
				<a style='text-decoration: none;' href="question_edit.php?id=<?php echo $game['id'];?>"><?=base64_decode($game['question'])?></a> <a href="quiz_view.php?id=<?=$id?>&del=<?php echo $game['id'];?>&type=question" onclick="return confirm('هل انت متاكد من حذف هذا؟?');"><img title='p`t' src='img/delete.png'/></a><br><?=base64_decode($game['an1'])?>
				<font color='grey'>النقط: <?=$game['sc1']?></font><br>
				<?=base64_decode($game['an2'])?>  <font color='grey'>النقط: <?=$game['sc2']?></font><br>
				<?=base64_decode($game['an3'])?>  <font color='grey'>النقط: <?=$game['sc3']?></font><br><hr>
<?php
			}
?>
		</td>
	</tr>
<?
$asker = 1;
}else{
?>
		<td class="td_view2"><font color="red">لا يوجد اسئلة لهذا الاختبار!</font> <a href="question_add.php?id=<?=$_GET['id']?>" class="in_link" style="text-decoration: none;"><b>اضف سؤال جديد?<font color="green"> + </font></b></a></td>
<?
}
$sql = "SELECT * FROM `result` where quizid=$id order by score ASC";
$res = mysqli_query($con, $sql);
$n = @mysqli_num_rows($res);
if($n)
{
?>
	<tr>
		<td class="td_view1" width="120">نتيجة الاختبار</td>
		<td class="td_view2"><?=base64_decode($G['result'])?></td>
	</tr>
	<tr>
		<td class="td_view1" width="120">اسم الحصول على نتيجة الاختبار (مثال : لقد حصلت على)</td>
		<td class="td_view2"><?=base64_decode($G['igot'])?></td>
	</tr>
	<tr>
		<td class="td_view1">النتائج المتوفرة</td>
		<td class="td_view2">
<?php
$mt = 0;
$grapht = "";
$graphs = "";
			while($game = mysqli_fetch_array($res))
			{
?>
				<a style='text-decoration: none; color: blue;' title='تعديل' href="result_edit.php?id=<?php echo $game['id'];?>"><?=base64_decode($game['title'])?></a> <font color='grey'>النقط: <b><?=$game['score']?></b></font> <a href="quiz_view.php?id=<?=$id?>&del=<?php echo $game['id'];?>&type=result" onclick="return confirm('هل انت متاكد من حذف هذا?');"><img title='حذف' src='img/delete.png'/></a>
				<br><font color='#6986A4'><?=base64_decode($game['desc'])?></font><br><hr>
<?php
				if ($mt == 0)
				{
				$graphs = $game['stats'];
				$mt++;
				}else{
				$graphs = $graphs.",".$game['stats'];
				}
				$grapht = $grapht.base64_decode($game['title'])." (".$game['stats'].") |";
				
			}
if ($G['stats'] > 4)
{
?>
<img src="http://chart.apis.google.com/chart?chs=520x256&cht=p&chtt=احصائية نتائج الاختبار&chd=t:<?=$graphs?>&chco=0000ff&chxl=0:|<?=$grapht?>&chxt=x&pieSliceText:percentage" />
<? } else { echo "بعد ما يتم الاختبار هذا 5 مرات سيتم اظهار احصائية مفصلة!"; }?>
		</td>
	</tr>
<?
$asker = "";
}
if ($asker ==1)
{?>
	<tr>
		<td class="td_view1">النتائج المتوفرة</td>
<td class="td_view2"><font color="red">لا يوجد نتائج بعد</font> <a href="result_add.php?id=<?=$_GET['id']?>" class="in_link" style="text-decoration: none;"><b>اضف نتيجة جديده<font color="green"> + </font></b></a></td>
</tr>
<?
}
?>
	<tr>
		<td class="td_view1">تعديلات</td>
		<td class="td_view2">
		<a href="question_add.php?id=<?=$_GET['id']?>" class="in_link" style="text-decoration: none;"><b>اضف سؤال جديد<font color="green"> + </font></b></a>&nbsp;|
		<a href="result_add.php?id=<?=$_GET['id']?>" class="in_link" style="text-decoration: none;"><b>اضف نتيجة جديده<font color="green"> + </font></b></a>&nbsp;|&nbsp;
		<a href="edit_quiz.php?id=<?=$_GET['id']?>" class="in_link" style="text-decoration: none;"><b>تعديل الاختبار</b></a>&nbsp;|&nbsp;
		<a href="quiz_view.php?id=<?=$id?>&del=<?=$_GET['id']?>&type=quiz" onclick="return confirm('حذف هذا الاختبار سيقوم بحذف كافة الاسئلة والاجوبة .هل انت متاكد??');" style="text-decoration: none; color: red;">حذف الاختبار</a>
		</td>
	</tr>
	<tr>
	</tr>
	</table>
<?	include("footer.php");?>
