forked from Avinm/QuickSlots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect_db.php
70 lines (67 loc) · 1.92 KB
/
connect_db.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Initiates database connections
* @author Avin E.M
*/
if (file_exists('config.php')) {
include('config.php');
}
if(isset($config))
{
try
{
// Establish mysql connection
$current = null;
$db = new PDO("mysql:dbname={$config['db_name']};host={$config['db_host']}", $config['db_user'], $config['db_pswd'],
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_FOUND_ROWS => true
]);
if(!empty($_GET['table']))
{
if(sessionCheck('level','dean'))
{
$query = $db->prepare("INSERT IGNORE into timetables(table_name) VALUES(?)");
$query->execute([$_GET['table']]);
}
$query = $db->prepare("SELECT * FROM timetables where table_name=?");
$query->execute([$_GET['table']]);
$current = $query->fetch(PDO::FETCH_ASSOC);
$_SESSION['timetable'] = $current;
}
else if(empty($_SESSION['timetable']) || empty($_SESSION['timetable']['table_name']))
{
$current = $db->query("SELECT * FROM timetables where table_name=(SELECT table_name from timetables where active=1)")->fetch(PDO::FETCH_ASSOC);
if(!$current)
{
$current['start_hr'] = '08';
$current['slots'] = 0;
$current['duration'] = 90;
$current['days'] = 0;
$current['start_mer'] = 'AM';
$current['start_min'] ='30';
$current['allowConflicts'] = 0;
$current['frozen'] = 0;
$current['table_name'] = '';
$current['active'] = 0;
}
$_SESSION['timetable'] = $current;
}
else
{
$query = $db->prepare("SELECT * FROM timetables where table_name=?");
$query->execute([$_SESSION['timetable']['table_name']]);
$current = $query->fetch(PDO::FETCH_ASSOC);
$_SESSION['timetable'] = $current;
}
}
catch(PDOException $e){
die($e->getMessage()."\n");
}
}
else
{
header("Location: ./setup.php");
die();
}
?>