-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrentLab.php
56 lines (39 loc) · 1.23 KB
/
currentLab.php
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
46
47
48
49
50
51
52
53
54
55
56
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include("credentials.php");
date_default_timezone_set('Europe/London');
$dateAndTime = new DateTime('now');
$weekday = $dateAndTime->format('w');
$time = $dateAndTime->format("H:i:s");
$mCode = 'null';
//Query the module code
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare("SELECT * FROM Labs WHERE (:time BETWEEN Start_Time AND End_Time) AND Weekday = :weekday;");
$stmt->bindParam(':time', $time);
$stmt->bindParam(':weekday', $weekday);
$stmt->execute();
$rows = $stmt->fetchAll();
if (count($rows) > 1) {
echo "duplicate labs";
$_SESSION['currentLab'] = $mCode;
exit(0);
}
foreach ($rows as $row) {
$mCode = $row['mCode'];
}
if ($mCode == 'null'){
echo "no lab";
$_SESSION['currentLab'] = $mCode;
exit(0);
}
$_SESSION['currentLab'] = $mCode;
echo $mCode;
} catch (Exception $exception){
echo "<script type='text/javascript'> alert('Error for module code query!') </script>";
exit(0);
}