forked from mkucej/i-librarian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename_category.php
115 lines (103 loc) · 4.34 KB
/
rename_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
<?php
include_once 'data.php';
if (isset($_SESSION['auth']) && isset($_SESSION['permissions']) && ($_SESSION['permissions'] == 'A' || $_SESSION['permissions'] == 'U')) {
include_once 'functions.php';
database_connect(IL_DATABASE_PATH, 'library');
if (!empty($_GET['old_category']))
$old_category_query = $dbHandle->quote($_GET['old_category']);
if (!empty($_GET['add_category'])) {
$categories = array();
$categories = array_values(array_filter($_GET['new_category']));
$dbHandle->beginTransaction();
foreach($categories as $category) {
$new_category_query = $dbHandle->quote($category);
$result = $dbHandle->query("SELECT count(*) FROM categories WHERE category=".$new_category_query);
$count = $result->fetchColumn();
$result = null;
if ($count === '1') {
$dbHandle->rollBack();
die('Error! This category already exists.');
}
if ($count === '0')
$dbHandle->exec("INSERT INTO categories (category) VALUES ($new_category_query)");
$count = null;
}
$dbHandle->commit();
get_db_error($dbHandle, basename(__FILE__), __LINE__);
die();
}
if (!empty($_GET['change_category']) && !empty($_GET['new_category']) && !empty($_GET['old_category'])) {
$new_category_query = $dbHandle->quote($_GET['new_category']);
$exec = $dbHandle->exec("UPDATE categories SET category=$new_category_query WHERE categoryID=$old_category_query");
if ($exec == 1)
die('OK');
die('Error! Database update unsuccessful.');
}
if (!empty($_GET['delete_category']) && !empty($_GET['old_category'])) {
$dbHandle->beginTransaction();
$dbHandle->exec("DELETE FROM filescategories WHERE categoryID=$old_category_query");
$dbHandle->exec("DELETE FROM categories WHERE categoryID=$old_category_query");
$dbHandle->commit();
get_db_error($dbHandle, basename(__FILE__), __LINE__);
die('OK');
}
$stmt = $dbHandle->prepare("SELECT categories.categoryID,categories.category,count(filescategories.categoryID)
FROM categories LEFT OUTER JOIN filescategories
ON filescategories.categoryID=categories.categoryID
GROUP BY categories.categoryID
ORDER BY category COLLATE NOCASE");
?>
<form action="rename_category.php" method="GET">
<input type="hidden" name="add_category" value="1">
<table style="float:left;width:40%">
<tr>
<td class="details alternating_row">
<b>Add categories:</b>
</td>
</tr>
<?php
for ($i = 1; $i <= 10; $i++) {
?>
<tr>
<td style="padding:3px">
<input type="text" size="30" name="new_category[]" style="width:95%">
</td>
</tr>
<?php
}
?>
<tr>
<td style="padding:3px">
<button><i class="fa fa-save"></i> Save</button>
</td>
</tr>
</table>
</form>
<table style="width:60%">
<tr>
<td class="details alternating_row" colspan="3"><b>Edit categories</b></td>
</tr>
<?php
$stmt->execute();
while ($category = $stmt->fetch(PDO::FETCH_NUM)) {
?>
<tr>
<td style="padding:4px" <?php if ($category[2] == 0) echo 'class="ui-state-active"'; ?>>
<span class="ui-state-default deletebutton" style="padding:1px 3px"><i class="fa fa-trash-o"></i> Delete</span>
<span class="ui-state-default renamebutton" style="padding:1px 3px"><i class="fa fa-pencil"></i> Rename</span>
<?php
print '<input type="text" class="editcategory" style="width:60%;padding:0 4px" data-id="' . htmlspecialchars($category[0]) . '" '
. 'data-content="' . htmlspecialchars($category[1]) . '" value="'. htmlspecialchars($category[1]).'"> Items: '. $category[2];
?>
</td>
</tr>
<?php
}
?>
</table>
<br>
<?php
} else {
print 'Super User or User permissions required.';
}
?>