<?php
include "db.php";
$rightnow = date('Y-m-d H:i:s');
$expTime=$db->getVal("select exp_date from result where paper_id='".$_GET["id"]."' and student_id='".$_SESSION["user"]["uid"]."'");
$odt="";

if($expTime!=""){
	$odt=strtotime($expTime)-strtotime($rightnow);				
}
//echo $rightnow."<br>".$expTime."<br>".$odt;exit;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript"
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<title>Exam start</title>
<style type="text/css">
<!--
body {
	font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
	margin: 0;
	padding: 0;
	color: #000;
}
/* ~~ Element/tag selectors ~~ */
ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
	padding: 0;
	margin: 0;
}
h1, h2, h3, h4, h5, h6, p {
	margin-top: 0;	 /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
	padding-right: 15px;
	padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
}
a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
	border: none;
}
/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
a:link {
	color: #414958;
	text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
}
a:visited {
	color: #4E5869;
	text-decoration: underline;
}
a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
	text-decoration: none;
}
/* ~~ this container surrounds all other divs giving them their percentage-based width ~~ */
.container {
	width: 99%;
	/* a max-width may be desirable to keep this layout from getting too wide on a large monitor. This keeps line length more readable. IE6 does not respect this declaration. */
	min-width: 780px;/* a min-width may be desirable to keep this layout from getting too narrow. This keeps line length more readable in the side columns. IE6 does not respect this declaration. */
	background-color: #FFF;
	margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout. It is not needed if you set the .container's width to 100%. */
	border: 1px solid #000;
}
/* ~~ the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo ~~ */
.header {
	background-color: rgba(6, 20, 90, 0.75);
}

.sidebar1 {
	float: right;
	width: 20%;
	background-color: rgba(6, 20, 90, 0.75);
	padding-bottom: 10px;
	height: 550px;
	overflow: auto;
}
.content {
	padding: 10px 0;
	width: 80%;
	float: right;
	height: 550px;
	overflow: auto;
}
.content ul, .content ol {
	padding: 0 15px 15px 15px; 
}
ul.nav {
	list-style: none; /* this removes the list marker */
	border-top: 1px solid #666;
	margin-bottom: 15px; 
	}
ul.nav li {
	border-bottom: 1px solid #666; /* this creates the button separation */
}
ul.nav a, ul.nav a:visited { 
	padding: 5px 5px 5px 15px;
	display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
	text-decoration: none;
	background-color: #8090AB;
	color: #000;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
	background-color: #6F7D94;
	color: #FFF;
}
/* ~~ The footer ~~ */
.footer {
	padding: 10px 0;
	background-color: rgba(6, 20, 90, 0.75);
	position: relative;/* this gives IE6 hasLayout to properly clear */
	clear: both; /* this clear property forces the .container to understand where the columns end and contain them */
}
/* ~~ miscellaneous float/clear classes ~~ */
.fltrt {  /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
	clear: both;
	height: 0;
	font-size: 1px;
	line-height: 0px;
}
-->
</style> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="extra/jquery.plugin.js"></script>
<script src="extra/jquery.countdown.js"></script>

<style>
.qus{display:none}
.active{display:block}
body {
  -webkit-user-select: none;
     -moz-user-select: -moz-none;
      -ms-user-select: none;
          user-select: none;
}
.question{
  background-color:#EEEEEE;
  display:block;
  padding:5px;
}
#qus li{
border:1px solid #CCCCCC;
  padding-bottom:15px;
  list-style:none;margin-bottom: 15px;
}
#no li{list-style:none;display:block; cursor:pointer; border-bottom:1px solid #ccc;
    padding: 5px;}
#no li:hover{
	box-shadow: inset 0 0 0px #4E5869;
}
a.btn {
    border-radius: 3px;
    text-decoration: none;
    border: 1px solid #ccc;
    padding: 5px;
    display: block;
	color:#fff;
    text-align: center;
    margin: 5px;
}
a#btn:hover{
    box-shadow: inset 0 0 12px #4E5869;
}
#qus .done .question, .questionspan.done {
    background-color: #10BF1E !important;
}
#qus .active .question,  .questionspan.current{
    background-color: rgba(6, 20, 90, 0.75);
	color:#fff;
}

</style>
<script>
$(document).on("contextmenu", function (event) { event.preventDefault(); });
$(document).ready(function(e) {
    $("#no li").each(function(index, element) {
        $(this).on("click",function(){
			var dataid=$(this).attr("data-id");
			$("#qus li").removeClass("active");
			$("#qus #test"+dataid).addClass("active");
		})
    });
	$("#switchv").on("click",function(){
		var type=$(this).attr("data-type");
		if(type=="list"){
			$("#qus li").removeClass("qus");
			$(this).attr("data-type","grid");
			$(this).html("Switch to grid view");
		}
		else{
			$("#qus li").addClass("qus");
			$(this).attr("data-type","list");
			$(this).html("Switch to list view");
		}
	})
});
function nextAnswer(adata,i){
	var id=parseInt(i)+1;
	$("#no"+id).click();
	//$("#no"+i).addClass("done");
	$("#no li").removeClass("current");
	//$("#test"+i).addClass("done");
	$("#no"+id).addClass("current");
}
function selectAnswer(adata,i){
 //$("#sts"+i).html(" Please wait...")
     //var id=parseInt(i)+1;
	 //$("#no"+id).click();
	 $("#no"+i).addClass("done");
	 //$("#no li").removeClass("current");
	 $("#test"+i).addClass("done");
	 //$("#no"+id).addClass("current done");
	 //$("#sts"+i).html('');
 $.post("newajax.php",
 {
	 type:"question",
	 bdata:adata,
	
 },
 function(data){
    
 });
}
function checkTime(h,i,s)
{
	if(h==0 && i==0 && s==0 )
	{
		//alert(" Time finish ");
		$("#submitPaper").submit();
		
	}
	
}

function asssignVal(a,b){
 $("#next"+b).val(a);
}
$(document).ready(function () {
	shortly = new Date();
	var lefttime='<?php echo $odt ?>';
	shortly.setSeconds(lefttime); 
	$('#counttime').countdown({until: shortly,  
    onExpiry: liftOff, onTick: watchCountdown});

	function liftOff() { 
		$("#colpleteDetail").hide();
		$("#counttime").hide();
	} 
	 //Username, your picture will appear for: xx Days. Xx Hours xx minutes
	function watchCountdown(periods) { 
	//alert(periods);
		checkTime(periods[4] , periods[5] , periods[6]);
		$('#colpleteDetail').text( periods[4] + ':' + periods[5] + ':' + periods[6] + '');
		 $("#counttime").hide();
	}
	
});
function printDiv(divID) {
	var divElements = document.getElementById(divID).innerHTML;
	var newbody="<html><head><title></title><style>.nextBtn{display:none;}</style></head><body>" + divElements + "<hr/><div class='footerPrint'><span>signature...............................</span></div></body>";
    var thePopup = window.open( '', "Print", "menubar=0,location=0,height=700,width=700" );
    thePopup.document.write(newbody);
    thePopup.print();
}

</script>
</head>
<style>
.optionspan{
 display:block;
}

.questionspan {
    display: block;
    width: 15px;
    height: 13px;
    float: left;
    margin: 4px;
    text-align: center;
    border-radius: 50%;
    text-align: center;
    /* color: #fff; */
    font-size: 10px;
    background-color: rgba(240, 243, 54, 0.94);}
</style>
<script type="text/javascript" language="text/javascript"> 
function handleBrowserCloseButton(event) { 
   if (($(window).width() - window.event.clientX) < 35 && window.event.clientY < 0) 
    {
      //Call method by Ajax call
      alert('Browser close button clicked');    
    } 
} 

</script>
<body  onbeforeunload="handleBrowserCloseButton(event);">
<?php // echo $odt ?>
<span id="counttime"></span>
<div style="background-color:#FFF;color:#F00">
  <?php
//echo "<p>".$_REQUEST['id']."</p>";

$ques=$objindex->get_ques($_REQUEST['id']);

$instName=$LinksDetails['site_name'];

//echo "<pre>hallua $ques";print_r($ques);exit;

$contentDetail = $db->getRow(" select marks,name,totalqus from papers where id=".$_REQUEST['id']);
$getMyDetal=$db->getVal("select school_id from student where idno='".$_SESSION['user']['uid']."'");

if($getMyDetal!=0){
	$instName=$db->getVal("select fullname from siteuser where id='".$getMyDetal."'");	
}

//echo "hey".$getMyDetal;echo "<br>";print_r($getMyDetal);exit;



$k=0;
$ans_arr=array('A','B','C','D');
?>
</div>
<div class="container">
  <div class="header"> 
  <table border="1" style="width: 100%;color: #fff;font-size: 12px;margin: 0 auto; text-align:center" cellpadding="0" cellspacing="0">
  	<tr>
    	<td rowspan="2"><span style="display:inline-block" > <a href="#"><img src="<?php echo $LinksDetails["logo"] ?>" alt="Insert Logo Here" name="Insert_logo" height="90" id="Insert_logo" style="display:block;" /></a> </span></td>
    	<td colspan="5"><center><span style="font-size:24px; font-weight:bold"><?php echo $instName; ?></span><center></td>
    </tr>
    <tr>
    	<td>Exam Name: <strong><?php echo $contentDetail['name'] ?></strong></td>
        <td>Login Name:  <strong><?php echo $_SESSION['user']['email'] ?></strong></td>
        <td>Total Questions: <strong><?php echo $contentDetail['totalqus'] ?></strong></td>
        <td>Total Marks:  <?php echo $contentDetail['marks'] ?></td>
        <td>Left Time: <strong><span id="colpleteDetail"></span></strong></td>
    </tr>
  </table>
    
    
    <!-- end .header --></div>
  <form action="newajax.php" id="submitPaper" class="form" method="post">
    <div class="sidebar1"> <a href="#" id="switchv" class="btn" data-type="list">switch list view</a>
      <ul id="no">
        <?php 
	$i=0;
	 foreach($ques as $q)
	{$i++;
	
		?>
        <li id="no<?php echo $i;?>" data-id="<?php echo $i;?>" class="questionspan"> <?php echo $i;?></li>
        <?php				
	} 
	  ?>
      </ul>
      <!-- end .sidebar1 --> <br /><br /><br />
       <span style="clear:both; position:absolute; right:56px; bottom:3%;">
        <input type="hidden" name="type" id="type" value="smtppr">
        <input type="hidden" name="pprdtl" value="<?php echo $_REQUEST['id']."||".$_SESSION['user']['uid'] ;?>">
        <input type="submit" name="finalsubmit" id="finalsubmit" value="Finish Exam">
        <input type="button" onclick="printDiv('qus');" value="Print">
      </span>
    </div>
    <div class="content">
      <ul id="qus">
        <?php 
	 $j=0; 
	 foreach($ques as $q)
		{$j++;
		?>
        <li class="qus <?php if($j==1)echo "active";?>" id="test<?php echo $j;?>"> <span class="question"><?php echo $j.") ".unPOST($q['question']); ?> <b id="sts<?php echo $j;?>"></b> </span> <br>
          <span style="float: right;margin-right: 34px;color: red;font-weight: bold;">[Mark: <?php echo $q['marks'];?>]</span>
          <table>
            <?php
        foreach($q["options"] as $option){
		
$ab=$q["qid"]."||".$ans_arr[$k]."||".$_REQUEST['id']."||".$_SESSION['user']['uid'] ;

?>
            <tr class="optionspan">
              <td><input type="radio" value="<?php echo $ans_arr[$k];?>" onchange="selectAnswer('<?php echo $ab;?>','<?php echo $j;?>')" name="radio||<?php echo $j."||".$q["qid"]; ?>" /></td>
              <td><?php echo unPOST($option);
		?></td>
            </tr>
            <?php
		$k++;
		}
$k=0;		
		?>
          </table>
          <span style="padding-right: 15px;display: block;top: -19px;position: relative;">
          <button type="button" name="next<?php echo $j;?>" id="next<?php echo $j;?>" style="float:right;" onclick="nextAnswer(this.value,'<?php echo $j ?>')" class="nextBtn" >Next</button>
          </span> </li>
        <?php				
		} 
	 
	  ?>
      </ul>
    </div>
  </form>
  <!-- end .container --></div>
</body>
</html>