-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpauseTimer.php
More file actions
45 lines (39 loc) · 1.21 KB
/
Copy pathpauseTimer.php
File metadata and controls
45 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
//CORS Headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
//HTTP inputs
$rest_json = file_get_contents("php://input");
$_POST = json_decode($rest_json, true);
$ispreflight = $_POST['ispreflight'];
if($ispreflight!=3){
echo "Exiting";
exit;
}
$con = mysqli_connect("localhost", "root", "", "othscmsdb");
$res = mysqli_query($con, "SELECT * from timer");
$response = -1;
if(mysqli_num_rows($res)>0){
while($row = mysqli_fetch_assoc($res)){
echo $row['paused'];
$response = $row['paused'];
}
}
echo (int)$response;
$newResp = $response;
if((int)$response==0)$newResp=1;
else $newResp = 0;
$sql = "UPDATE timer SET paused = $newResp";
echo $sql;
mysqli_query($con, $sql);
if($newResp==1){
$now = time();
$sql = "UPDATE timer SET now = $now";
mysqli_query($con, $sql);
}else{
$set = mysqli_query($con, "SELECT timer from timer")->fetch_object()->timer+(time()-mysqli_query($con, "SELECT now from timer")->fetch_object()->now);
$sql = "UPDATE timer SET timer = $set";
mysqli_query($con, $sql);
}
exit;
?>