-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory.php
353 lines (304 loc) · 11.3 KB
/
category.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<script type="text/javascript">
function showPopUp(el) {
var cvr = document.getElementById("cover")
var dlg = document.getElementById(el)
cvr.style.display = "block"
dlg.style.display = "block"
if (document.body.style.overflow = "hidden") {
cvr.style.width = "1024"
cvr.style.height = "100%"
}
}
function closePopUp(el) {
var cvr = document.getElementById("cover")
var dlg = document.getElementById(el)
cvr.style.display = "none"
dlg.style.display = "none"
document.body.style.overflowY = "scroll"
}
</script>
<?php
// BarcodeSystem for MAGFest 2.0
// Designed for MAGFest 9 and BEYOND! by gergc and LANJesus
// File: category.php
// Purpose: Allows admins to add and modify rooms and their respective item types and descriptions
include('header.php');
//print_r($_POST);
$sorttype = 0;
if(isset($_GET['sort']))
{
$sorttype = $_GET['sort'];
}
$addroom = false;
if(isset($_POST['addroom']))
{
$addroom = true;
}
$addmagfestroom = false;
if(isset($_POST['addmagfestroom']))
{
$addmagfestroom = true;
}
$magfestcat = false;
if(isset($_POST['magfest_cat']))
{
$magfestcat = true;
}
$addcat = false;
if(isset($_POST['addcat']))
{
$addcat = true;
}
$edittype = false;
if(isset($_POST['edittype']))
{
$edittype = true;
}
if($_SESSION['login_auth'] == true && $_SESSION['user_level']==2) {
if($sorttype==-1)
echo '<button class="big" onClick="parent.location=\'category.php?sort=0\'">Attendee Inventory</button><br /><br />';
else
echo '<button class="big" onClick="parent.location=\'category.php?sort=-1\'">MAGFest Inventory</button><br /><br />';
//Input handler
if($addmagfestroom)
{
$roomname = $_POST['roomname'];
if (ereg("[^A-Za-z0-9]", $roomname)) {
echo '<big><red>Invalid Room Name: Please input only letters or numbers for the room name.</big></red>';
}
else {
$conn = connectDB();
$q = "SELECT * FROM mag_names GROUP BY id DESC LIMIT 1";
$res = mysql_query($q,$conn);
$row = mysql_fetch_array($res);
$nextid = $row['id']+1;
$q = "INSERT INTO mag_names(name) VALUES ('$roomname')";
$res = mysql_query($q,$conn);
$nodetype = '$$Node$$';
$q = "INSERT INTO mag_category(roomid, categoryname, categorytypes) VALUES ('$nextid','$nodetype','$nodetype')";
$res = mysql_query($q,$conn);
if(!$res)
echo '<big><red>SQL Error</red></big>';
else
echo '<big>Added MAGFest-owned Inventory Room: '.$roomname.'</big><br />';
mysql_close($conn);
}
}
if($addroom)
{
$roomname = $_POST['roomname'];
if (ereg("[^A-Za-z0-9]", $roomname)) {
echo '<big><red>Invalid Room Name: Please input only letters or numbers for the room name.</big></red>';
}
else {
$conn = connectDB();
$q = "SELECT * FROM cat_names GROUP BY id DESC LIMIT 1";
$res = mysql_query($q,$conn);
$row = mysql_fetch_array($res);
$nextid = $row['id']+1;
$q = "INSERT INTO cat_names(name) VALUES ('$roomname')";
$res = mysql_query($q,$conn);
$nodetype = '$$Node$$';
$q = "INSERT INTO category(roomid, categoryname, categorytypes) VALUES ('$nextid','$nodetype','$nodetype')";
$res = mysql_query($q,$conn);
if(!$res)
echo '<big><red>SQL Error</red></big>';
else
echo '<big>Added Room: '.$roomname.'</big><br />';
mysql_close($conn);
}
}
if($addcat)
{
$input = explode(';',$_POST['catdesc']);
foreach($input as $key => $value)
{
$input[$key] = filter_var($value, FILTER_SANITIZE_STRING);
}
$catdesc = implode(';',$input);
$conn = connectDB();
$roomid = $_POST['catid'];
$catname = $_POST['catname'];
if(!$magfestcat)
$q = "INSERT INTO category(roomid,categoryname,categorytypes) VALUES('$roomid','$catname','$catdesc')";
else
$q = "INSERT INTO mag_category(roomid,categoryname,categorytypes) VALUES('$roomid','$catname','$catdesc')";
$res = mysql_query($q,$conn);
if(!$res)
echo '<big><red>SQL Error</red></big>';
else
if(!$magfestcat)
echo '<big>Added Category: '.$catname.'</big><br />';
else
echo '<big>Added MAGFest-Owned Category: '.$catname.'</big><br />';
mysql_close($conn);
}
if($edittype)
{
$input = explode(';',$_POST['typedesc']);
foreach($input as $key => $value)
{
$input[$key] = filter_var($value, FILTER_SANITIZE_STRING);
}
$catdesc = implode(';',$input);
$conn = connectDB();
$catid = $_POST['typeid'];
$roomid = $_POST['catid'];
$catname = $_POST['catname'];
if(!$magfestcat)
$q = "REPLACE INTO category(id,roomid,categoryname,categorytypes) VALUES('$catid','$roomid','$catname','$catdesc')";
else
$q = "REPLACE INTO mag_category(id,roomid,categoryname,categorytypes) VALUES('$catid','$roomid','$catname','$catdesc')";
$res = mysql_query($q,$conn);
if(!$res)
echo '<big><red>SQL Error</red></big>';
else
echo '<big>Edited Type Sucessfully</big><br />';
mysql_close($conn);
}
$conn = connectDB();
if($sorttype!=-1)
{
//list
//Get list of rooms
$q = "SELECT * FROM cat_names";
$res = mysql_query($q,$conn);
//<OPTION VALUE="">select...
echo 'Display types from:<FORM NAME="nav"><DIV>
<SELECT NAME="SelectURL" onChange=
"document.location.href=
document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value">
<OPTION VALUE="category.php?sort=0"'; if($_GET['sort']==0) echo 'SELECTED';echo '>Show All</OPTION>';
$c=0;
while($row = mysql_fetch_row($res))
{
$c++;
echo '<OPTION VALUE="category.php?sort='.$c.'"'; if($_GET['sort']==$c) echo 'SELECTED';echo '>'.$row[1];
}
//MAGFest Items only
//echo '<OPTION VALUE="category.php?sort=-1"'; if($_GET['sort']==-1) echo 'SELECTED';echo '>MAGFest Items</OPTION>';
echo '</SELECT><DIV></FORM>';
}
echo '<fieldset style="width: 750px; height: 55px;">';
if($sorttype==-1)
echo "<legend>MAGFest-Owned Inventory Rooms and Item Types</legend>";
else
echo "<legend>Attendee Rooms and Item Types</legend>";
echo '<div><br />';
echo '<table border class="list">
<tr class="header"><td style="width: 70px">ID</td>
<td>Room</td>
<td>Category</td>
<td>Description Types</td>
<td>Action</td>
</tr>';
$toggle = true;
if($sorttype == 0)
$q = "SELECT category.id, category.roomid,name,categoryname,categorytypes FROM category,cat_names WHERE category.roomid=cat_names.id ORDER BY roomid ASC";
else if($sorttype == -1)
$q = "SELECT mag_category.id, mag_category.roomid,name,categoryname,categorytypes FROM mag_category,mag_names WHERE mag_category.roomid=mag_names.id ORDER BY roomid ASC";
else
$q = "SELECT category.id, category.roomid,name,categoryname,categorytypes FROM category,cat_names WHERE category.roomid=cat_names.id AND roomid = $sorttype ORDER BY roomid ASC";
$res = mysql_query($q,$conn);
$lastid = 0;
$firstnode1 = true;
$firstnode2 = true;
while($row = mysql_fetch_row($res))
{
$currentid = $row[1];
if($row[3]=='$$Node$$') //Main node, skip
{
echo '<tr><td>'; //bgcolor="#DDDDDD"
echo '<b>'.$currentid.'</b></td><td>';
echo $row[2].'<td /><td /><b><div id="cover" style="display:none;position:absolute;left:0px;top:0px;width:100%;height:100%;background:gray;filter:alpha(Opacity=50);opacity:0.5;-moz-opacity:0.5;-khtml-opacity:0.5"></div>
<div id="dialogC'.$row[0].'" style="display:none;left:200px;top:200px;width:600px;height:400px;position:absolute;z-index:100;background:white;padding:2px;font:10pt tahoma;border:1px solid gray"><br /><br />
<h1>Adding Category to '.$row[2].' Room</h1>
<h2>Category Name:</h2>
<form autocomplete="off" action="'.$_SERVER['REQUEST_URI'].'" name="addcat" method="POST">
<input name="catname" style="width: 600px" type="text" />
<h2>Description: <br />Please put each description type in between semicolons (;) </h2>
<input name="catdesc" style="width: 600px" type="text" />';
if($sorttype==-1)
{
echo '<input name="magfest_cat" type="hidden" value="true" />';
}
echo '<input name="addcat" type="hidden" value="true" />
<input name="catid" type="hidden" value="'.$row[1].'" />
<br><input type="submit" value="Submit" /></form>
<br><a href="#" onclick="closePopUp(\'dialogC'.$row[0].'\');">[Cancel]</a>
</div>
<a href="#" onclick="showPopUp(\'dialogC'.$row[0].'\');">Add Category to '.$row[2].'</a></b>
<td /></tr>';
continue;
}
echo '</td><td>';
echo '»<td>';
echo $row[2]; //roomid
echo '</td><td>';
echo $row[3]; //type
echo '</td><td>';
echo $row[4]; //typedescs
echo '</td>';
echo '<td>
<div id="cover" style="display:none;position:absolute;left:0px;top:0px;width:100%;height:100%;background:gray;filter:alpha(Opacity=50);opacity:0.5;-moz-opacity:0.5;-khtml-opacity:0.5"></div>
<div id="dialog'.$row[0].'" style="display:none;left:200px;top:200px;width:600px;height:400px;position:absolute;z-index:100;background:white;padding:2px;font:10pt tahoma;border:1px solid gray"><br /><br />
<form autocomplete="off" action="'.$_SERVER['REQUEST_URI'].'" name="edittype" method="POST">
<h1>Editing Type: "'.$row[3].'" in the '.$row[2].' Room</h1>
<h2>Please put each description type in between semicolons (;) </h2>
<br><input style="width: 600px" type="text" name="typedesc" value="'.$row[4].'" />
<input name="typeid" type="hidden" value="'.$row[0].'" />
<input name="catid" type="hidden" value="'.$row[1].'" />
<input name="edittype" type="hidden" value="true" />
<input name="catname" type="hidden" value="'.$row[3].'" />';
if($sorttype==-1)
{
echo '<input name="magfest_cat" type="hidden" value="true" />';
}
echo'
<br><input type="submit" value="Submit" /></form>
<br><a href="#" onclick="closePopUp(\'dialog'.$row[0].'\');">[Cancel]</a>
</div>
<a href="#" onclick="showPopUp(\'dialog'.$row[0].'\');">Edit_Description</a>
</td></tr>';
$lastid = $row[1];
}
$rows = mysql_num_rows($res);
if($rows==0)
{
echo '</table><table border class="list"><tr><td>No Rooms Added</td></tr></table>';
}
echo '</table>';
echo '</div><br /><br />';
echo '';
mysql_close($conn);
if($sorttype==-1)
{
//Show page
echo '<form autocomplete="off" action="'.$_SERVER['REQUEST_URI'].'" name="addroom" method="POST">';
echo '<fieldset style="width: 750px; height: 55px;">';
echo "<legend>Add New Room for MAGFest Items</legend>";
echo '<div>';
echo 'Room Name: <input type="text" name="roomname" /><br />';
echo '<input type="hidden" name="addmagfestroom" value="true" />';
echo '<input type="submit" value="Submit" />';
echo '</div>';
echo '</form></fieldset></fieldset>';
}
else
{
//Show page
echo '<form autocomplete="off" action="'.$_SERVER['REQUEST_URI'].'" name="addroom" method="POST">';
echo '<fieldset style="width: 750px; height: 55px;">';
echo "<legend>Add New Room</legend>";
echo '<div>';
echo 'Room Name: <input type="text" name="roomname" /><br />';
echo '<input type="hidden" name="addroom" value="true" />';
echo '<input type="submit" value="Submit" />';
echo '</div>';
echo '</form></fieldset></fieldset>';
}
}
else { echo 'Access Denied'; }
?>
</body>
</html>