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 Timer #5

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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
db.php
dbConnection.php
140 changes: 101 additions & 39 deletions account.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
$title = $row['title'];
$total = $row['total'];
$sahi = $row['sahi'];
$time = $row['time'];
$time = $row['time'];
$eid = $row['eid'];
$q12=mysqli_query($con,"SELECT score FROM history WHERE eid='$eid' AND email='$email'" )or die('Error98');
$rowcount=mysqli_num_rows($q12);
Expand All @@ -115,25 +115,10 @@
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>-->

<div class="timerblock">
Time Remaining : <span id="countdown" class="timer"></span>
</div>

<!--home closed-->

Expand Down Expand Up @@ -296,38 +281,117 @@ function secondPassed() {
</div><!-- /.modal -->

<!--Modal for admin login-->
<div class="modal fade" id="login">
<div class="modal fade" id="login">
<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">Close</span></button>
<h4 class="modal-title"><span style="color:orange;font-family:'typo' ">LOGIN</span></h4>
</div>
<div class="modal-body title1">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<form role="form" method="post" action="admin.php?q=index.php">
<div class="form-group">
<input type="text" name="uname" maxlength="20" placeholder="Admin user id" class="form-control"/>
</div>
<div class="form-group">
<input type="password" name="password" maxlength="15" placeholder="Password" class="form-control"/>
</div>
<div class="form-group" align="center">
<input type="submit" name="login" value="Login" class="btn btn-primary" />
</div>
</form>
</div><div class="col-md-3"></div></div>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<form role="form" method="post" action="admin.php?q=index.php">
<div class="form-group">
<input type="text" name="uname" maxlength="20" placeholder="Admin user id" class="form-control"/>
</div>
<div class="form-group">
<input type="password" name="password" maxlength="15" placeholder="Password" class="form-control"/>
</div>
<div class="form-group" align="center">
<input type="submit" name="login" value="Login" class="btn btn-primary" />
</div>
</form>
</div><div class="col-md-3"></div></div>
</div>
<!--<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>-->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<!--Modal for Timeups-->
<div class="modal fade" id="timeup">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><span style="color:orange;font-family:'typo' ">Time's up</span></h4>
</div>
<div class="modal-body title1">
<div class="row">
<div class="col-md-12">
<h2 class="text-center">Buzz Buzz... Time's up</h2>
<br>
<div class="text-center">
<a href="account.php?q=result&eid=<?php @$_GET['eid'];?>" class="btn btn-success">View Result</a>
</div>

</div>
</div>
</div>
</div>
</div>
</div>



<!--footer end-->

<?php
//Check if it's first question and countdown has initialized
$timleft=isset($_SESSION['countdown'])?$_SESSION['countdown']:0;
$result=isset($_SESSION['result'])?$_SESSION['result']:0;

if(isset($_SESSION['result'])){
unset($_SESSION['result']);
}

if(@$_GET['n']==1 && empty($timleft)){
$timleft=@$_GET['t']*60;
$_SESSION['countdown']=$timleft;
}else if(isset($_SESSION['countdown'])){
$timleft=$_SESSION['countdown'];
}
?>
<script>
var seconds = <?php echo $timleft;?>;
var result= <?php echo $result;?>;
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<1){
$('.timerblock').addClass('timeralert');
}
if (seconds == 0) {
clearInterval(countdownTimer);
$.post('update.php', { q:'stoptimer'});
if(result==0){
$('#timeup').modal({
show: 'true',
backdrop: 'static',
keyboard: false
});
}
//document.getElementById('countdown').innerHTML = "Buzz Buzz... Time's up";
} else {
seconds--;
//Update countdown session
$.post('update.php', { q:'updatetimer',countdown:seconds });
}

}

var countdownTimer = setInterval('secondPassed()', 1000);
</script>

<!--


Expand All @@ -354,9 +418,7 @@ function secondPassed() {



-->


-->

</body>
</html>
18 changes: 18 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,21 @@ border-top:2px solid;
border-color:orange;
text-decoration:none;
}

.timerblock{
float: right;
margin-right: 5%;
background: #1DE9B6;
padding: 10px;
}

.timerblock .timeralert{
background: #F44336;
}


.timerblock span{
font-size: 18px;
font-weight: bold;
width: 20px;
}
2 changes: 1 addition & 1 deletion db.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
$conn=mysql_connect('localhost','root','');
$db=mysql_select_db('2mylogin',$conn);
$db=mysql_select_db('vinnovate',$conn);
?>
2 changes: 1 addition & 1 deletion dbConnection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

$con= new mysqli('localhost','root','root','vinnovateit')or die("Could not connect to mysql".mysqli_error($con));
$con= new mysqli('localhost','root','','vinnovate')or die("Could not connect to mysql".mysqli_error($con));

?>
2 changes: 1 addition & 1 deletion session.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location:index.php");
header("Location:index.php");
}
?>
11 changes: 11 additions & 0 deletions update.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,15 @@
header("location:account.php?q=quiz&step=2&eid=$eid&n=1&t=$t");
}

//update countdown
if(@$_POST['q']=='updatetimer' && isset($_POST['countdown'])) {
$_SESSION['countdown']=$_POST['countdown'];
}

//Destroy session
if(@$_POST['q']=='stoptimer' && isset($_SESSION['countdown'])) {
$_SESSION['result']=1;
unset($_SESSION['countdown']);
}

?>