-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.php
65 lines (49 loc) · 1.55 KB
/
utils.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
<?php
require_once 'dbcon.php';
function storeSchedule($scharray)
{
global $mysql, $NUM_SLOTS, $NUM_TRACKS;
error_log(print_r($scharray, true));
mysqli_query($mysql, "delete from sch_generated_schedule");
$stmt = mysqli_prepare($mysql, "insert into sch_generated_schedule (timeslot, track, session) values (?, ?, ?)");
for ($i = 0; $i < $NUM_SLOTS; $i++) {
for ($j = 0; $j < $NUM_TRACKS; $j++) {
$store_session = null;
if ($scharray[$i][$j] != null)
{
$store_session = $scharray[$i][$j]['session'];
}
mysqli_stmt_bind_param($stmt, "iii", $i, $j, $store_session);
mysqli_stmt_execute($stmt);
}
}
}
function getSchedule()
{
global $mysql, $NUM_SLOTS, $NUM_TRACKS;
$scharray = array();
for($i = 0; $i < $NUM_SLOTS; $i++) {
$scharray[$i] = array();
for($j = 0; $j < $NUM_TRACKS; $j++) {
$scharray[$i][$j] = null;
}
}
$res = mysqli_query($mysql, "SELECT timeslot, track, session FROM sch_generated_schedule");
while($row = mysqli_fetch_assoc($res)) {
$timeslot = $row['timeslot'];
$track = $row['track'];
$scharray[$timeslot][$track] = $row['session'];
}
return $scharray;
}
function truncateTitle( $title, $length = 60) {
if(strlen($title) >= $length) {
$title = substr($title, 0, $length);
if(strrpos($title, ' ') != strlen($title)) {
$title = substr($title, 0, strrpos($title, ' '));
}
$title = $title . '...';
}
return $title;
}
?>