This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathomnitool.php
281 lines (239 loc) · 13.3 KB
/
omnitool.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
<?php
include_once 'data.php';
include_once 'functions.php';
if (!empty($_POST['omnitool'])) {
database_connect(IL_DATABASE_PATH, 'library');
$user_query = $dbHandle->quote($_SESSION['user_id']);
$quoted_path = $dbHandle->quote(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'history.sq3');
$dbHandle->exec("ATTACH DATABASE $quoted_path as history");
if ($_POST['omnitool'] == '5' || $_POST['omnitool'] == '6') {
attach_clipboard($dbHandle);
}
$dbHandle->beginTransaction();
// SAVE TO SHELF
if ($_POST['omnitool'] == '1') {
$dbHandle->exec("INSERT OR IGNORE INTO shelves (userID,fileID) SELECT $user_query, itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id DESC");
$dbHandle->exec("DELETE FROM shelves WHERE fileID NOT IN (SELECT id from library)");
}
// REMOVE FROM SHELF
if ($_POST['omnitool'] == '2') {
$dbHandle->exec("DELETE FROM shelves WHERE fileID IN (SELECT itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id) AND userID=$user_query");
}
// SAVE TO PROJECT
if ($_POST['omnitool'] == '3' && !empty($_POST['project3'])) {
$dbHandle->exec("INSERT OR IGNORE INTO projectsfiles (projectID,fileID) SELECT " . intval($_POST['project3']) . ", itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id DESC");
$dbHandle->exec("DELETE FROM projectsfiles WHERE fileID NOT IN (SELECT id from library)");
}
// REMOVE FROM PROJECT
if ($_POST['omnitool'] == '4' && !empty($_POST['project4'])) {
$dbHandle->exec("DELETE FROM projectsfiles WHERE projectID=" . intval($_POST['project4']) . " AND fileID IN (SELECT itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id)");
}
// SAVE TO CLIPBOARD
if ($_POST['omnitool'] == '5') {
$dbHandle->exec("INSERT OR IGNORE INTO clipboard.files (id) SELECT itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id DESC");
}
// REMOVE FROM CLIPBOARD
if ($_POST['omnitool'] == '6') {
$dbHandle->exec("DELETE FROM clipboard.files WHERE id IN (SELECT itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id)");
}
// SAVE TO CATEGORIES INCLUDING NEW ONES
if ($_POST['omnitool'] == '7' && !empty($_POST['category2'])) {
$_POST['category2'] = preg_replace('/\s{2,}/', '', $_POST['category2']);
$_POST['category2'] = preg_replace('/^\s$/', '', $_POST['category2']);
$_POST['category2'] = array_filter($_POST['category2']);
$query = "INSERT INTO categories (category) VALUES (:category)";
$stmt = $dbHandle->prepare($query);
$stmt->bindParam(':category', $new_category, PDO::PARAM_STR);
while (list($key, $new_category) = each($_POST['category2'])) {
$new_category_quoted = $dbHandle->quote($new_category);
$result = $dbHandle->query("SELECT categoryID FROM categories WHERE category=$new_category_quoted");
$exists = $result->fetchColumn();
$result = null;
if (empty($exists)) {
$stmt->execute();
$last_id = $dbHandle->query("SELECT last_insert_rowid() FROM categories");
$last_insert_rowid = $last_id->fetchColumn();
$last_id = null;
$dbHandle->exec("INSERT OR IGNORE INTO filescategories (fileID,categoryID) SELECT itemID, " . intval($last_insert_rowid) . " FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id DESC");
}
}
$dbHandle->exec("DELETE FROM filescategories WHERE fileID NOT IN (SELECT id from library)");
}
// SAVE TO EXISTING CATEGORIES
if ($_POST['omnitool'] == '7' && !empty($_POST['category'])) {
while (list(, $cat) = each($_POST['category'])) {
$dbHandle->exec("INSERT OR IGNORE INTO filescategories (fileID,categoryID) SELECT itemID, " . intval($cat) . " FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id DESC");
}
$dbHandle->exec("DELETE FROM filescategories WHERE fileID NOT IN (SELECT id from library)");
}
// REMOVE FROM CATEGORIES
if ($_POST['omnitool'] == '9' && !empty($_POST['category'])) {
while (list(, $cat) = each($_POST['category'])) {
$dbHandle->exec("DELETE FROM filescategories WHERE categoryID=" . intval($cat) . " AND fileID IN (SELECT itemID FROM history.`" . $_SESSION['display_files'] . "` ORDER BY id)");
}
}
$dbHandle->commit();
// DELETE ITEMS
if ($_POST['omnitool'] == '8' && isset($_SESSION['permissions']) && $_SESSION['permissions'] == 'A') {
$result = $dbHandle->query("SELECT itemID FROM history.`" . $_SESSION['display_files'] . "` LIMIT 10000");
$delete_files = $result->fetchAll(PDO::FETCH_COLUMN);
delete_record($dbHandle, $delete_files);
}
$dbHandle = null;
} elseif (isset($_SESSION['auth'])) {
?>
<div>
<table class="threed" cellspacing=0 style="width:100%">
<tr>
<td class="threed select_span omnitooltd" style="width:32%;line-height:22px">
<input type="radio" style="display:none" name="omnitool" value="1">
<i class="fa fa-circle-o"></i>
Save to Shelf
</td>
<td class="threed select_span omnitooltd" style="width:32%;line-height:22px">
<input type="radio" style="display:none" name="omnitool" value="5">
<i class="fa fa-circle-o"></i>
Save to Clipboard
</td>
<td class="threed select_span omnitooltd" style="width:36%;line-height:22px">
<input type="radio" style="display:none" name="omnitool" value="3">
<span style="position:relative;top:4px">
<i class="fa fa-circle-o"></i>
Save to
</span>
<div style="float:right;position:relative;top:2px">
<select name="project3" style="width:150px">
<?php
database_connect(IL_DATABASE_PATH, 'library');
$desktop_projects = array();
$desktop_projects = read_desktop($dbHandle);
while (list(, $value) = each($desktop_projects)) {
print '<option value="' . $value['projectID'] . '">' . htmlspecialchars($value['project']) . '</option>';
}
reset($desktop_projects);
?>
</select>
</div>
</td>
</tr>
<tr>
<td class="threed select_span omnitooltd" style="line-height:22px">
<input type="radio" style="display:none" name="omnitool" value="2">
<i class="fa fa-circle-o"></i>
Remove from Shelf
</td>
<td class="threed select_span omnitooltd" style="line-height:22px">
<input type="radio" style="display:none" name="omnitool" value="6">
<i class="fa fa-circle-o"></i>
Remove from Clipboard
</td>
<td class="threed select_span omnitooltd" style="line-height:22px">
<input type="radio" style="display:none" name="omnitool" value="4">
<span style="position:relative;top:4px">
<i class="fa fa-circle-o"></i>
Remove from
</span>
<div style="float:right;position:relative;top:2px">
<select name="project4" style="width:150px">
<?php
while (list(, $value) = each($desktop_projects)) {
print '<option value="' . $value['projectID'] . '">' . htmlspecialchars($value['project']) . '</option>';
}
reset($desktop_projects);
?>
</select>
</div>
</td>
</tr>
<tr>
<td class="threed select_span omnitooltd" colspan=1 style="padding:8px 4px">
<input type="radio" style="display:none" name="omnitool" value="7">
<i class="fa fa-circle-o"></i>
Add to Categories:
</td>
<td class="threed select_span omnitooltd" colspan=2>
<input type="radio" style="display:none" name="omnitool" value="9">
<i class="fa fa-circle-o"></i>
Remove from Categories:
</td>
</tr>
<tr>
<td class="threed" style="padding:4px" colspan=3>
<div style="overflow:auto;height:240px;background-color:#fff;border:1px solid #C5C6C9;margin-left:auto">
<form action="display.php" id="omnitoolcategories">
<table cellspacing=0 style="width: 99.5%">
<tr>
<td style="width: 33.2%;padding:2px">
<input type="text" name="category2[]" value="" style="width:99.5%" placeholder="Enter new category">
</td>
<td style="width: 33.2%;padding:2px">
<input type="text" name="category2[]" value="" style="width:99.5%" placeholder="Enter new category">
</td>
<td style="width: 33.2%;padding:2px">
<input type="text" name="category2[]" value="" style="width:99.5%" placeholder="Enter new category">
</td>
</tr>
</table>
<table cellspacing=0 style="float:left;width: 33.2%;padding:2px">
<?php
$category_string = null;
$result3 = $dbHandle->query("SELECT count(*) FROM categories");
$totalcount = $result3->fetchColumn();
$result3 = null;
$i = 1;
$isdiv = null;
$isdiv2 = null;
$result3 = $dbHandle->query("SELECT categoryID,category FROM categories ORDER BY category COLLATE NOCASE ASC");
while ($category = $result3->fetch(PDO::FETCH_ASSOC)) {
$cat_all[$category['categoryID']] = $category['category'];
if ($i > 1 && $i > ($totalcount / 3) && !$isdiv) {
print '</table><table cellspacing=0 style="width: 33.2%;float: left;padding:2px">';
$isdiv = true;
}
if ($i > 2 && $i > (2 * $totalcount / 3) && !$isdiv2) {
print '</table><table cellspacing=0 style="width: 33.2%;float: left;padding:2px">';
$isdiv2 = true;
}
print PHP_EOL . '<tr><td class="select_span">';
print "<input type=\"checkbox\" name=\"category[]\" value=\"" . htmlspecialchars($category['categoryID']) . "\"";
print " style=\"display:none\"> <i class=\"fa fa-square-o\"></i> " . htmlspecialchars($category['category']) . "</td></tr>";
$i = $i + 1;
}
$result3 = null;
?>
</table>
</form>
</div>
</td>
</tr>
<?php
if ($_SESSION['permissions'] == 'A') {
?>
<tr>
<td class="select_span omnitooltd" id="lock" style="padding-top:10px">
<i class="fa fa-lock"></i>
unlock
</td>
<td class="omnitooltd" colspan=2>
</td>
</tr>
<tr>
<td class="omnitooltd ui-state-disabled" colspan=2>
<input type="checkbox" style="display:none" name="omnitool" value="8" disabled>
<i class="fa fa-square-o"></i>
<span class="ui-state-error-text fa fa-exclamation-triangle"></span>
Permanently delete from Library
</td>
<td class="omnitooltd">
</td>
</tr>
<?php
}
?>
</table>
</div>
<?php
}
?>