<?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'");

$type = "";
if(isset($_GET['type'])){ $type = $_GET['type']; }
if ($type == "lang")
{
	$del = $_GET["del"];
	mysqli_query($con, "delete from lang where id='$del'");
}
if ($type == "primary")
{
	$getid = $_GET["id"];
	mysqli_query($con, "UPDATE `lang` SET `default` = '0'");
	mysqli_query($con, "UPDATE `lang` SET `default` = '1' WHERE `id`='$getid'");
}
	$sql = "SELECT * FROM `lang` order by id ASC";
	$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="langlist.php?pg='.$p.'" class="vi_page">'.$p.'</a>';
		else
			$Page[] = '<a href="langlist.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">
<?
if ($type == "lang")
{
?>
	<tr class="tablehead">
		<td colspan="7" align="center" style="color: red;">تم حذف اللغة بنجاح</td>
	</tr>
<?}?>
	<tr class="tablehead">
		<td width="50" align="center">#</td>
		<td width="120" align="center">اللغة</td>
		<td width="50" align="center">الايقونة</td>
		<td width="350" align="center">تعديل / جعله افتراضي / حذف</td>
	</tr>
	<?php
	$sno = $from + 1;
	while($game = mysqli_fetch_array($res))
	{
		$qid = $game['id'];
		$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];
		?>
		<tr class="row<?php echo $sno%2;?>_view">
		<td align="center"><?=$game['id'];?></td>
		<td align="center"><?=$game['lang'];?> <? if ($game['default'] == 1) echo '<img src="img/primary.png" border="0" title="اللغة الافتراضية">'; ?></td>
		<td align="center"><img src="../img/<?=$game['icon'];?>" title="<?=$game['lang'];?>"></td>
		<td align="center">
		<a href="lang_edit.php?id=<?php echo $game['id'];?>"><img src="img/b_edit.png" border="0" title="Edit"></a>&nbsp;
		<a href="langlist.php?id=<?php echo $game['id'];?>&type=primary" disabled><img src="img/primary.png" border="0" title="Make Primary"></a>&nbsp;
		<a href="langlist.php?del=<?=$game['id']?>&type=lang" onclick="return confirm('Are you sure you want to delete this Language?');" style="text-decoration: none; color: red;">
		<img src="img/delete.png" border="0" title="Delete"></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="lang_add.php" class="in_link" style="text-decoration: none;"><b><font color="green"> + </font>اضف لغة جديده</b></a></td>
	</tr>
	<tr><td colspan="4"><small>عدد اللغات المعروضة <?php echo ($from+1);?> حتى <?php echo $tRec;?> من  <?php echo $n;?></small>
	</td></tr>
	<tr><td colspan="4"><font color="red" size="2"><b>ملاحظة: </b>عند عدم توفر الى لغة واحده فى الموقع سيتم ازالة قائمة اللغات من رئيسية الموقع</font>
	</td></tr>
	</table>
	<?php
}
else
{
	echo '<br><br><br><br><br><br><center><b>لا يوجد لغات متوفرة</b></center>';
}
?>
</td></tr></table>
<?php	include("footer.php");?>