<?
include "var.php";
$quizid = "";
if(isset($_POST['action'])){ $quizid = $_POST['action']; }
if ($quizid == "")
{
	if(isset($_GET['q'])){ $quizid = $_GET['q']; }
}
if ($quizid == "")
{
	echo "<script type='text/javascript'>top.location.href = '".$domain."';</script>";
}
$qorder = "";
if(isset($_POST['qorder'])){ $qorder = $_POST['qorder']; }
$qorder = $qorder + 1;
$oldscore = "";
if(isset($_POST['oldscore'])){ $oldscore = $_POST['oldscore']; }
$newscore = "";
if(isset($_POST['score'])){ $newscore = $_POST['score']; }
$score = $oldscore + $newscore;

if ($qorder == "")
{
	$qorder = 1;
}
$con = mysqli_connect($DBHOST,$DBUSER,$DBPASS,$DBNAME) or die("Some error occurred during connection " . mysqli_error($con));  
mysqli_query($con, "SET CHARACTER SET 'utf8'");

ob_start();
session_start();
$quizinfo = mysqli_query($con, "SELECT * FROM `quiz` WHERE `id` = '".$quizid."'");
$quizexist = @mysqli_num_rows($quizinfo);
if ($quizexist > 0)
{
	$quiz = mysqli_fetch_array($quizinfo);
	$title = $quiz["title"];
	$desc = $quiz["desc"];
	$_SESSION['lang'] = $quiz["lang"];
}
else
{
	echo "<script type='text/javascript'>top.location.href = '".$domain."';</script>";
}
$defaultlang = $_SESSION['lang'];

$globaldata = @mysqli_fetch_array(mysqli_query($con, "select * from `lang` where `id`='$defaultlang' limit 0,1"));
?>
<!DOCTYPE html>
<html>
<head>
<title><?=base64_decode($title)?></title>
<?
include "header.php";
?>
<script>
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/<?=$globaldata["fblang"]?>/sdk.js#xfbml=1&appId=1423206947972681&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.onload = function() {
<?
if ($globaldata["sharepopup"] > 0)
{
$popup1delay = $globaldata["sharepopup"] * 1000;
echo "setTimeout(SharePopup, ".$popup1delay.");";
}
if ($globaldata["quizpopup"] > 0)
{
$popup2delay = $globaldata["quizpopup"] * 1000;
echo "setTimeout(QuizPopup, ".$popup2delay.");";
}
?>
};
</script>
<body>
		<div style="background: #EEE; margin-bottom: 0px; margin-top: 0px;">
			<a href='<?=$domain?>' style='text-decoration: none;text-align: right;right: 15px;position: absolute;top: 5px;color: #5CB85C;font-size: 15px;font-weight: bold;'>الصفحة الرئيسية</a>
				<h3 style="padding: 30px 0px 11px 0; margin-top: 0px;text-align: center;" align='center'>
					<span style='color: #5CB85C' ><?=base64_decode($title)?></span>
				</h3>
		</div>
<center>
</center>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<div class="container">
<?
   $string = str_replace(' ', '-', base64_decode($title)); // Replaces all spaces with hyphens.
   $string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
$total = mysqli_query($con, "SELECT * FROM questions WHERE `quizid` = '".$quizid."' AND `qorder` = '".$qorder."'");
$totalq = mysqli_query($con, "SELECT * FROM questions WHERE `quizid` = '".$quizid."' order by qorder ASC");
$totalq = @mysqli_num_rows($totalq);
$qdata = mysqli_fetch_array($total);
?>
<form method="post" 
<?
if ($qorder == $totalq)
echo 'action="./result"';
?>
>
<input type="hidden" name="action" value="<?=$quizid?>"> 
<input type="hidden" name="oldscore" value="<?=$score?>"> 
<input type="hidden" name="qorder" value="<?=$qorder?>"> 
<!-- Question Start -->
<?
if ($qorder > $totalq)
{
	$resultcount = mysqli_query($con, "SELECT * FROM result WHERE `quizid` = '".$quizid."'");
	$resultcount = @mysqli_num_rows($resultcount);
	$maxscore = $totalq * 3;
	$math1 = $maxscore / $resultcount;
	$resultscore = round($score / $math1 - 0.3);
	$result = mysqli_query($con, "SELECT * FROM result WHERE `quizid` = '".$quizid."' AND `score` = '".$resultscore."'");
	$rdata = mysqli_fetch_array($result);
	$title = $quiz["result"];
	//Update Stats
	$rids = $rdata["id"];
	$quizid = $rdata["quizid"];
	mysqli_query($con, "update quiz set stats = stats+1 where id=$quizid");
	mysqli_query($con, "update result set stats = stats+1 where id=$rids");
	$minitxt = '<h1 id="result" class="realResult" style="margin-bottom: 20px;font-size:63px;">'.base64_decode($rdata["title"]).'</h1>';
}
else
{
	$minitxt = '<small class="questionNumbers">'.base64_decode($globaldata["question"]).' '.$qorder.' '.base64_decode($globaldata["outof"]).' '.$totalq.'</small>
	<br><progress value="'.$qorder.'" max="'.$totalq.'"></progress> ';
}
?>
			<div class="jumbotron jumboPad"
				style="margin-bottom: 15px; margin-top: 10px; margin-left: 5px; margin-right: 5px">
<style>
.quizName {
	font-size: 30px;
}

@media ( min-height : 580px) {
	.quizName {
		font-size: 24px;
	}
}
</style>
				<h2 class="quizName">
					<?=base64_decode($title)?><br>

<style>
.questionNumbers {
	font-size: 11px;
}

@media ( min-height : 580px) {
	.questionNumbers {
		font-size: 16px;
	}
}
</style>

					<?=$minitxt?>
				</h2>

<style>
.textOfQuestion {
	font-size: 20px;
	font-weight: bold;
}

@media ( min-height : 580px) {
	.textOfQuestion {
		font-size: 30px;
		font-weight: normal;
	}
}
</style>

				<h1>
					<p class="text-primary textOfQuestion"><?=base64_decode($qdata["question"])?>
					<? if($qdata["img"] != "")
					echo "<img src='".$domain."img/".$qdata['img']."' width='80%'/>";
					?>
					</p>
				</h1>
					<style>
.answer {
	font-size: 15px;
}

@media ( min-height : 580px) {
	.answer {
		font-size: 18px;
	}
}
</style>
<?
if ($qorder > $totalq)
{
$img = $rdata["img"];
echo "<img src='".$domain."img/".$img."' width='80%'>";
$url = rawurlencode('http:'.$domain.'quiz.php?q='.$quizid.'&r='.$resultscore.'');
?>
<h3 id="resultDescription" class="resultDesc">
<?=base64_decode($rdata["desc"])?>
</h3>
<center>
<hr style="border-top: 1px solid rgba(0, 0, 0, 0.36) !important;">
<h3 style="color:red;font-size:16px;">شارك نتيجة هذا الاختبار على شبكات التواصل الاجتماعي</h3>
<div class="hidden-xs hidden-sm">
						<a class="btn btn-lg btn-primary" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://www.facebook.com/sharer/sharer.php?m2w&u=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/f.png"> <?=base64_decode($globaldata["sharetext"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br />
						<a class="btn btn-lg btn-danger" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://plus.google.com/share?url=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/g.png"> <?=base64_decode($globaldata["sharegoogle"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br />
						<a class="btn btn-lg btn-info" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://twitter.com/intent/tweet?text=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>&hashtags=&via=<?=$twitter_username?>&url=http:<?=$domain ?>quiz.php?q=<?=$quizid?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/t.png"> <?=base64_decode($globaldata["sharetwitter"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br />
						<a class="btn btn-lg btn-warning" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('//www.pinterest.com/pin/create/button/?url=<?=$url?>&media=http:<?=$domain?>img/<?=$rdata["img"]?>&description=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/p.png"> <?=base64_decode($globaldata["sharepinterest"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br /><br />
</div>
<div class="visible-xs visible-sm">
						<a class="btn btn-lg btn-primary" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://www.facebook.com/sharer/sharer.php?m2w&u=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/f.png"></a>
						<a class="btn btn-lg btn-danger" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://plus.google.com/share?url=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/g.png"></a>
            <br />
						<a class="btn btn-lg btn-info" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://twitter.com/intent/tweet?text=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>&hashtags=&via=<?=$twitter_username?>&url=http:<?=$domain ?>quiz.php?q=<?=$quizid?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/t.png"></a>
						<a class="btn btn-lg btn-warning" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('//www.pinterest.com/pin/create/button/?url=<?=$url?>&media=http:<?=$domain?>img/<?=$rdata["img"]?>&description=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/p.png"></a>
            <br /><br />
</div>
<?
$html = $quiz["html"];
if($html == "")
{
include 'ads_234x250.php';
}else{
echo '<div class="hidden-xs hidden-sm">';
echo base64_decode($html);
echo '</div>';
}
?>
<hr style="border-top: 1px solid rgba(0, 0, 0, 0.36) !important;">
<h3 style="color:red;font-size:16px;">علق على هذا الاختبار في شبكات التواصل الاجتماعي</h3>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/<?=$globaldata["fblang"]?>/sdk.js#xfbml=1&appId=1423206947972681&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="http:<?=$domain?>?q=<?=$quizid?>&r=0" data-numposts="5" data-colorscheme="light"></div>
</center>
<?
}
else
{
?>
				<div class="btn-group-vertical btn-group btn-group-lg">
<button class="btn btn-default answer" type="submit" name="score" value="<?=$qdata["sc1"]?>" style="white-space: normal; font-size: 15px;"><?=base64_decode($qdata["an1"])?></button>
<button class="btn btn-default answer" type="submit" name="score" value="<?=$qdata["sc2"]?>" style="white-space: normal; font-size: 15px;"><?=base64_decode($qdata["an2"])?></button>
<button class="btn btn-default answer" type="submit" name="score" value="<?=$qdata["sc3"]?>" style="white-space: normal; font-size: 15px;"><?=base64_decode($qdata["an3"])?></button>
				</div>
                <br /><br />
                <? include 'ads_234x250.php'; ?>
                <br /><br />
                <div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/<?=$globaldata["fblang"]?>/sdk.js#xfbml=1&appId=1423206947972681&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="http:<?=$domain?>?q=<?=$quizid?>&r=0" data-numposts="5" data-colorscheme="light"></div>
<? } ?>
<a class="btn btn-lg btn-success" href='<?=$domain?>'><?=base64_decode($globaldata["takenewquiz"]);?></a>
				</div>
				<br>
			</div>
<!-- Question End -->
</form>
</div>
<?
include "footer.php";
if ($qorder > $totalq)
{
?>
<div class="modal fade" id="QuizPopup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"></span></button>
        <h4 class="modal-title" id="myModalLabel"><center><?=base64_decode($globaldata["takenewquiz"])?></center></h4>
      </div>
      <div class="modal-body">
<?
$sql = "SELECT * FROM `quiz` WHERE `lang`='$defaultlang' AND `live`=1 ORDER BY RAND() LIMIT 0,3";
$res = mysqli_query($con, $sql);
			while($game = mysqli_fetch_array($res))
			{
				$string = str_replace(' ', '-', base64_decode($game['title'])); // Replaces all spaces with hyphens.
				$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
?>
<div>
<a href="id=<?=$game['id']?>" class="list-group-item more-quizzes" data-clicksource="popup">
<h5><center><?=base64_decode($game['title'])?></center></h5> </a>
</div>
<?
			}
?>
	  </div>
    </div>
  </div>
</div>

<div class="modal fade" id="SharePopup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only"></span></button>
        <h4 class="modal-title" id="myModalLabel"><center><?=base64_decode($quiz["title"])?></center></h4>
      </div>
      <div class="modal-body">
<center><h2><?=base64_decode($title)?></h2>
<?=$minitxt?>
<img src="http:<?=$domain?>img/<?=$rdata["img"]?>" width='80%'/><br />
<h3 id="resultDescription" class="resultDesc">
<?=base64_decode($rdata["desc"])?></h3>
<div class="hidden-xs hidden-sm">
						<a class="btn btn-lg btn-primary" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://www.facebook.com/sharer/sharer.php?m2w&u=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/f.png"> <?=base64_decode($globaldata["sharetext"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br />
						<a class="btn btn-lg btn-danger" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://plus.google.com/share?url=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/g.png"> <?=base64_decode($globaldata["sharegoogle"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br />
						<a class="btn btn-lg btn-info" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://twitter.com/intent/tweet?text=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>&hashtags=&via=<?=$twitter_username?>&url=http:<?=$domain ?>quiz.php?q=<?=$quizid?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/t.png"> <?=base64_decode($globaldata["sharetwitter"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br />
						<a class="btn btn-lg btn-warning" target="_blank" style="width: 320px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('//www.pinterest.com/pin/create/button/?url=<?=$url?>&media=http:<?=$domain?>img/<?=$rdata["img"]?>&description=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/p.png"> <?=base64_decode($globaldata["sharepinterest"]);?> <i class="fa fa-refresh fa-spin"></i></a>
            <br /><br />
</div>
<div class="visible-xs visible-sm">
						<a class="btn btn-lg btn-primary" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://www.facebook.com/sharer/sharer.php?m2w&u=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/f.png"></a>
						<a class="btn btn-lg btn-danger" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://plus.google.com/share?url=<?=$url?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/g.png"></a>
            <br />
						<a class="btn btn-lg btn-info" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('https://twitter.com/intent/tweet?text=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>&hashtags=&via=<?=$twitter_username?>&url=http:<?=$domain ?>quiz.php?q=<?=$quizid?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/t.png"></a>
						<a class="btn btn-lg btn-warning" target="_blank" style="width: 90px;" onclick="var sTop=window.screen.height/2-(218);var sLeft=window.screen.width/2-(313);window.open('//www.pinterest.com/pin/create/button/?url=<?=$url?>&media=http:<?=$domain?>img/<?=$rdata["img"]?>&description=<?=base64_decode($quiz["igot"])?> <?=base64_decode($rdata["title"])?> - <?=base64_decode($quiz["title"])?>','sharer','toolbar=0,status=0,width=580,height=400,top='+sTop+',left='+sLeft);return false"
							 target="_blank"><img class="icon-pulse" src="<?=$domain?>img/p.png"></a>
            <br /><br />
</div>
<? include 'ads_234x250.php'; ?>
</center>
	  </div>
    </div>
  </div>
</div>
<script type="text/javascript">
    function QuizPopup() {
        $('#QuizPopup').modal('show');
    };
</script>
<script type="text/javascript">
    function SharePopup() {
        $('#SharePopup').modal('show');
    };
</script>
<?
}
?>
</body>