This repository has been archived by the owner on Mar 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewRota.php
153 lines (135 loc) · 6.38 KB
/
viewRota.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* This is the page for viewing rotas.
*
* More information...
*/
// Require the php setup file
require('phpsetup.php');
// Base url, this will get changed when we have the rota id
$url = "viewRota.php";
// Get the rota id, or set -1 if there is none
if(isset($_GET['rota'])){
$rotaid = $_GET['rota'];
}else{
$rotaid = -1;
}
$smarty->assign('rotaid',$rotaid);
$query = "SELECT rotaname FROM rota
WHERE rotaid=$rotaid";
$result = $database->sql($query);
$row = $result->fetch_row();
$rotaname = $row[0];
$smarty->assign('rotaname',$rotaname);
// Record the url for logging in
$url = $url . "?rota=$rotaid";
// Check if the rota id is correct.
if(!$database->isValidRota($rotaid)){
/*
* If the rota id is incorrect, just say so
* Frankly, the user shouldn't ever be coming
* to this page, so it doesn't matter if it looks nice, or
* has much information.
*/
$smarty->assign('validrota','false');
$smarty->assign('error','Not valid rota id');
}else{
/*
* If the rota id is correct. We need to get all the information
* and pass it through to the template.
*/
// Get the information from the database
$array = $database->getTableArray($rotaid);
if($array == false){
/*
* Technically it should never reach this point. When the system
* creates a rota, it adds in at least 1 block and 1 strip, so
* it should never be empty. But I just can't leave this option
* not accounted for. So, just throw a weird error. The user
* will never get to this point unless they delete everything
* I guess...
*
* Maybe I should add something in to allow for having deleted
* all strips/blocks. TODO!!!
*/
$smarty->assign('validrota','false');
$smarty->assign('error','No valid information strips/blocks');
}else{
/*
* This is what we do when we have a correct rota
* with information in. Basically, just passes the 2d array
* through to the template. It does the rest.
*/
$smarty->assign('validrota', 'true');
$smarty->assign('table', $array);
$smarty->assign('tablearray', json_encode($array));
/*
* This sets up the javascript arrays for the blocks/strips, so
* that my javascript know what ones it is dealing with.
*/
$blocks = $database->getBlockArray($rotaid);
$strips = $database->getStripArray($rotaid);
$smarty->assign('strips', json_encode($strips));
$smarty->assign('blocks', json_encode($blocks));
/*
* Check if the current user is the owner of this rota.
* We only allow editing of the rota if he is. Otherwise, they
* just get to view it.
*/
if($loggedIn){
$query = "SELECT r.rotaowner FROM `rota` r
WHERE r.rotaowner='$user'
AND r.rotaid=$rotaid";
$result = $database->sql($query);
$smarty->assign('user', $user);
if($result == false){
$smarty->assign('owner','false');
}else{
$smarty->assign('owner','true');
/*
* This is for the user list. Grab the names of the users, and
* add them into an array. It contains the names and the usernames,
* so that we can have the actual name showing on the page, but
* of course the username is the primary key, so we need that
* to chagne anything.
*
* Note, it is within this if statement because there is
* no point in doing this if the user can't edit.
*/
$users = $database->getRotaUsers($rotaid);
if($users != false){
$x = 0;
while($test = $users->fetch_row()){
/*
* Just changing the data into an easy way for the
* template to deal with it. It doesn't like mysqli
* output for some reason.
*/
$userlist[$x][0] = $test[0];
$userlist[$x++][1] = $test[1];
}
$smarty->assign('users',$userlist);
$smarty->assign('userlistjson', json_encode($userlist));
}
}
}else{
$smarty->assign('owner','false');
}
}
}
/*
* This bit is obvious, however I might change this to have 2
* different templates. Basically, I'm not convinced about having loads
* of logic in my template, for example if there is an error, then
* there is an if statement in the template. I can't get away from
* some things, like the loop for the table. But I can get away from
* having the if statement just by extending the template, and having
* 1 for correct rota, and 1 for incorrect...
*
* Anyway, this just assigns the url and displays the page. The url
* is assigned all the way down here incase it needs to change earlier
* on in the page.
*/
$smarty->assign('url',$url);
$smarty->display('viewrota.tpl');
?>