Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added alert and timer #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions account.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,43 @@
echo '</table></div>';

}?>
<!--<span id="countdown" class="timer"></span>
<script>
var seconds = 40;
function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = "Buzz Buzz";
} else {
seconds--;
}
}
var countdownTimer = setInterval('secondPassed()', 1000);
</script>-->
<span id="countdown" class="timer"></span>
<span id="countdown_alert" class="text-danger"></span>
<?php if(isset($_SESSION['timeLeft'])) {
if(@$_GET['q']=='quiz' && @$_GET['step']==2){
$eid=@$_GET['eid'];
$sn=@$_GET['n'];
if($sn==1){
$q=mysqli_query($con, "SELECT time FROM quiz WHERE eid='$eid'");
$r=mysqli_fetch_assoc($q);
$_SESSION['timeLeft']=$r['time']*60;
}
?>
<script>
var seconds = <?php echo $_SESSION['timeLeft'] ?>;
function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds;
if(minutes<2) {
document.getElementById('countdown_alert').innerHTML = "<br>Hurry up!! Less than 2 minutes left.";
}
if (seconds == 0) {
clearInterval(countdownTimer);
document.getElementById('countdown').innerHTML = "Buzz Buzz";
document.getElementById('submitBtn').style.display = 'none';
document.getElementById('countdown_alert').innerHTML = "<br>You did not get it on time, please try again!";
} else {
seconds--;
$.post('update.php', { timeLeft: seconds, q: 'timeUpdate' });
}
}
var countdownTimer = setInterval('secondPassed()', 1000);
</script>
<?php } } ?>

<!--home closed-->

Expand Down Expand Up @@ -161,7 +179,7 @@ function secondPassed() {
$optionid=$row['optionid'];
echo'<input type="radio" name="ans" value="'.$optionid.'">'.$option.'<br /><br />';
}
echo'<br /><button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span>&nbsp;Submit</button></form></div>';
echo'<br /><button type="submit" id="submitBtn" class="btn btn-primary"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span>&nbsp;Submit</button></form></div>';
//header("location:dash.php?q=4&step=2&eid=$id&n=$total");
}
//result display
Expand Down
5 changes: 4 additions & 1 deletion update.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@
header("location:account.php?q=result&eid=$eid");
}
}

//set time session
if(@$_POST['q']=='timeUpdate' && @$_POST['timeLeft']) {
$_SESSION['timeLeft']=$_POST['timeLeft'];
}
//restart quiz
if(@$_GET['q']== 'quizre' && @$_GET['step']== 25 ) {
$eid=@$_GET['eid'];
Expand Down