forked from opendocman/opendocman
-
Notifications
You must be signed in to change notification settings - Fork 1
/
category.php
392 lines (357 loc) · 14.6 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
use Aura\Html\Escaper as e;
use Aura\Html\Escaper\AttrEscaper as a;
/*
category.php - Administer Categories
Copyright (C) 2002-2011 Stephen Lawrence Jr.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// check for valid session
session_start();
// includes
include('odm-load.php');
if (!isset($_SESSION['uid'])) {
redirect_visitor();
}
$user_obj = new User($_SESSION['uid'], $pdo);
// Check to see if user is admin
if (!$user_obj->isAdmin()) {
header('Location:error.php?ec=4');
exit;
}
$last_message = (isset($_REQUEST['last_message']) ? $_REQUEST['last_message'] : '');
if (isset($_GET['submit']) && $_GET['submit'] == 'add') {
draw_header(msg('area_add_new_category'), $last_message);
?>
<form id="categoryAddForm" action="category.php" method="GET" enctype="multipart/form-data">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><b><?php echo msg('category')?></b></td>
<td colspan="3"><input name="category" type="text" class="required" maxlength="40"></td>
<td>
<div class="buttons">
<button class="positive" type="Submit" name="submit" value="Add Category"><?php echo msg('button_add_category')?></button>
</div>
</td>
<td>
<div class="buttons">
<button class="negative cancel" type="submit" name="cancel" value="Cancel"><?php echo msg('button_cancel')?></button>
</div>
</td>
</tr>
</table>
</form>
<script>
$(document).ready(function(){
$('#categoryAddForm').validate();
});
</script>
<?php
draw_footer();
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit']=='Add Category') {
// Make sure they are an admin
if (!$user_obj->isAdmin()) {
header('Location:error.php?ec=4');
exit;
}
$query = "INSERT INTO {$GLOBALS['CONFIG']['db_prefix']}category (name) VALUES (:category)";
$stmt = $pdo->prepare($query);
$stmt->execute(array(':category' => $_REQUEST['category']));
// back to main page
$last_message = urlencode(msg('message_category_successfully_added'));
header('Location:admin.php?last_message=' . urlencode($last_message));
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'delete') {
// If demo mode, don't allow them to update the demo account
if ($GLOBALS['CONFIG']['demo'] == 'True') {
draw_header(msg('area_delete_category'), $last_message);
echo msg('message_sorry_demo_mode');
draw_footer();
exit;
}
draw_header(msg('area_delete_category'), $last_message);
$item = (int) $_REQUEST['item'];
// query to show item
echo '<table border=0>';
$query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}category WHERE id = :item";
$stmt = $pdo->prepare($query);
$stmt->execute(array(':item' => $_REQUEST['item']));
$result = $stmt->fetch();
echo '<tr><td>' .msg('label_id'). ' # :</td><td>' . e::h($result['id']) . '</td></tr>';
echo '<tr><td>'.msg('label_name').' :</td><td>' . e::h($result['name']) . '</td></tr>';
?>
<form action="category.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo e::h($item);
?>">
<tr>
<td>
<?php echo msg('label_reassign_to');
?>:
</td>
<td>
<select name="assigned_id">
<?php
$query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}category WHERE id != :item ORDER BY name";
$stmt = $pdo->prepare($query);
$stmt->execute(array(':item' => $_REQUEST['item']));
$result = $stmt->fetchAll();
foreach ($result as $row) {
echo '<option value="' . e::h($row['id']) . '">' . e::h($row['name']) . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td valign="top"><?php echo msg('message_are_you_sure_remove')?></td>
<td align="center">
<div class="buttons">
<button class="positive" type="submit" name="deletecategory" value="Yes"><?php echo msg('button_yes')?></button>
</div>
<div class="buttons">
<button class="negative cancel" type="submit" name="cancel" value="Cancel"><?php echo msg('button_cancel')?></button>
</div>
</td>
</form>
</tr>
</TABLE>
<?php
draw_footer();
} elseif (isset($_REQUEST['deletecategory'])) {
// Delete category
//
//
// Make sure they are an admin
if (!$user_obj->isAdmin()) {
header('Location:error.php?ec=4');
exit;
}
$query = "DELETE FROM {$GLOBALS['CONFIG']['db_prefix']}category where id=:id";
$stmt = $pdo->prepare($query);
$stmt->execute(array(':id' => $_REQUEST[id]));
// Set all old category_id's to the new re-assigned category
$query = "UPDATE {$GLOBALS['CONFIG']['db_prefix']}data SET category = :assigned_id WHERE category = :id";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':assigned_id' => $_REQUEST['assigned_id'],
':id' => $_REQUEST[id]
));
// back to main page
$last_message = msg('message_category_successfully_deleted') . ' id:' . $_REQUEST['id'];
header('Location: admin.php?last_message=' . urlencode($last_message));
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'deletepick') {
$deletepick='';
draw_header(msg('area_delete_category'). ' : ' .msg('choose'), $last_message);
?>
<table border="0" cellspacing="5" cellpadding="5">
<form action="category.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="state" value="<?php echo(e::h($_REQUEST['state']+1));
?>">
<tr>
<td><b><?php echo msg('category')?></b></td>
<td colspan=3><select name="item">
<?php
$query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}category ORDER BY name";
$stmt = $pdo->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
foreach ($result as $row) {
$str = '<option value="' . e::h($row['id']) . '"';
$str .= '>' . e::h($row['name']) . '</option>';
echo $str;
}
$deletepick='';
?>
</select></td>
<td></td>
<td colspan="2" align="center">
<div class="buttons">
<button class="positive" type="submit" name="submit" value="delete"><?php echo msg('button_delete')?></button>
<button class="negative cancel" type="submit" name="cancel" value="Cancel"><?php echo msg('button_cancel')?></button>
</div>
</td>
</tr>
</form>
</table>
<?php
draw_footer();
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'Show Category') {
// query to show item
draw_header(msg('area_view_category'), $last_message);
$category_id = (int) $_REQUEST['item'];
// Select name
$query = "SELECT name FROM {$GLOBALS['CONFIG']['db_prefix']}category WHERE id = :category_id";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':category_id' => $category_id
));
$result = $stmt->fetchAll();
echo('<table name="main" cellspacing="15" border="0">');
foreach ($result as $row) {
echo '<th>' . msg('label_name') . '</th><th>' . msg('label_id') . '</th>';
echo '<tr>';
echo '<td>' . e::h($row['name']) . '</td>';
echo '<td>' . e::h($category_id) . '</td>';
echo '</tr>';
}
?>
<form action="admin.php" method="POST" enctype="multipart/form-data">
<tr>
<td colspan="4" align="center"><div class="buttons"><button class="regular" type="submit" name="submit" value="Back"><?php echo msg('button_back')?></button></div></td>
</tr>
</form>
</table>
<!-- ADD THE LIST OF FILES HERE -->
<?php
echo msg('categoryviewpage_list_of_files_title') . '<br />';
$query = "SELECT id, realname FROM `{$GLOBALS['CONFIG']['db_prefix']}data` WHERE category = :category_id";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':category_id' => $category_id
));
$result = $stmt->fetchAll();
foreach ($result as $row) {
echo '<a href="edit.php?id=' . e::h($row['id']) . '&state=3">ID: ' . e::h($row['id']) . ',' . e::h($row['realname']) . '</a><br />';
}
draw_footer();
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'showpick') {
draw_header(msg('area_view_category') . ' : ' . msg('choose'), $last_message);
?>
<table border="0" cellspacing="5" cellpadding="5">
<form action="category.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="state" value="<?php echo(e::h($_REQUEST['state']+1));
?>">
<tr>
<td><b><?php echo msg('category')?></b></td>
<td colspan="3"><select name="item">
<?php
$query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}category ORDER BY name";
$stmt = $pdo->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
foreach ($result as $row) {
echo '<option value="' . e::h($row['id']) . '">' . e::h($row['name']) . '</option>';
}
?>
</select></td>
<td></td>
<td colspan="3" align="center">
<div class="buttons">
<button class="positive" type="Submit" name="submit" value="Show Category"><?php echo msg('area_view_category')?></button>
<button class="negative cancel" type="Submit" name="cancel" value="Cancel"><?php echo msg('button_cancel')?></button>
</div>
</td>
</tr>
</form>
</table>
</body>
</html>
<?php
draw_footer();
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'Update') {
draw_header(msg('area_update_category'), $last_message);
?>
<form id="updateCategoryForm" action="category.php" method="POST" enctype="multipart/form-data">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<?php
$item = (int)$_REQUEST['item'];
// query to get a list of users
$query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}category where id = :item";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':item' => $item
));
$result = $stmt->fetchAll();
foreach ($result as $row) {
echo '<tr>';
echo '<td colspan="2">' . msg('category') . ': <input type="textbox" name="name" value="' . e::h($row['name']) . '" class="required" maxlength="40"></td>';
echo '<input type="hidden" name="id" value="' . e::h($row['id']) . '">';
}
?>
<td align="center">
<div class="buttons">
<button class="positive" type="Submit" name="updatecategory" value="Modify Category"><?php echo msg('area_update_category')?></button>
</div>
</td>
<td align="center">
<div class="buttons">
<button class="negative cancel" type="Submit" name="cancel" value="Cancel"><?php echo msg('button_cancel')?></button>
</div>
</td>
</tr>
</table>
</form>
<script>
$(document).ready(function(){
$('#updateCategoryForm').validate();
});
</script>
<?php
draw_footer();
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'updatepick') {
draw_header(msg('area_update_category'). ': ' .msg('choose'), $last_message);
?>
<form action="category.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="state" value="<?php echo(e::h($_REQUEST['state']+1));
?>">
<table border="0">
<tr>
<td><b><?php echo msg('choose')?> <?php echo msg('category')?>:</b></td>
<td colspan="3"><select name="item">
<?php
// query to get a list of users
$query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}category ORDER BY name";
$stmt = $pdo->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
foreach ($result as $row) {
echo '<option value="' . e::h($row['id']) . '">' . e::h($row['name']) . '</option>';
}
?>
</td>
<td align="center">
<div class="buttons">
<button class="positive" type="submit" name="submit" value="Update"><?php echo msg('choose')?></button>
</div>
</td>
<td align="center">
<div class="buttons">
<button class="negative cancel" type="submit" name="cancel" value="Cancel"><?php echo msg('button_cancel')?></button>
</div>
</td>
</tr>
</form></TD>
</tr>
</table>
<?php
draw_footer();
} elseif (isset($_REQUEST['updatecategory'])) {
// Make sure they are an admin
if (!$user_obj->isAdmin()) {
header('Location: error.php?ec=4');
exit;
}
$id = (int) $_REQUEST['id'];
$query = "UPDATE {$GLOBALS['CONFIG']['db_prefix']}category SET name = :name where id = :id";
$stmt = $pdo->prepare($query);
$stmt->execute(array(
':name' => $_REQUEST['name'],
':id' => $id
));
// back to main page
$last_message = msg('message_category_successfully_updated') .' : ' . $_REQUEST['name'];
header('Location: admin.php?last_message=' . urlencode($last_message));
} elseif (isset($_REQUEST['cancel']) && $_REQUEST['cancel'] == 'Cancel') {
$last_message = msg('message_action_cancelled');
header('Location: admin.php?last_message=' . urlencode($last_message));
}