-
Notifications
You must be signed in to change notification settings - Fork 0
/
omnitool.php
276 lines (252 loc) · 12.6 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
<?php
include_once 'data.php';
include_once 'functions.php';
$isapc = ini_get('apc.enabled');
$export_files = read_export_files(0);
if (!empty($_POST['omnitool']) && !empty($export_files)) {
database_connect($database_path, 'library');
$user_query = $dbHandle->quote($_SESSION['user_id']);
$dbHandle->beginTransaction();
if ($_POST['omnitool'] == '1') {
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id=$file_query");
$exists = $result->fetchColumn();
$result = null;
if ($exists == 1) $dbHandle->exec("INSERT OR IGNORE INTO shelves (userID,fileID) VALUES ($user_query,$file_query)");
}
if (!empty($isapc)) {
apc_delete($_SESSION['user_id'].'_shelf_files');
}
}
if ($_POST['omnitool'] == '2') {
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$dbHandle->exec("DELETE FROM shelves WHERE fileID=$file_query AND userID=$user_query");
}
if (!empty($isapc)) {
apc_delete($_SESSION['user_id'].'_shelf_files');
}
}
if ($_POST['omnitool'] == '3' && !empty($_POST['project3'])) {
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id=$file_query");
$exists = $result->fetchColumn();
$result = null;
if ($exists == 1) $dbHandle->exec("INSERT OR IGNORE INTO projectsfiles (projectID,fileID) VALUES (".intval($_POST['project3']).",$file_query)");
}
if (!empty($isapc)) {
apc_delete($_SESSION['user_id'].'_desk_files');
}
}
if ($_POST['omnitool'] == '4' && !empty($_POST['project4'])) {
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$dbHandle->exec("DELETE FROM projectsfiles WHERE projectID=".intval($_POST['project4'])." AND fileID=$file_query");
}
if (!empty($isapc)) {
apc_delete($_SESSION['user_id'].'_desk_files');
}
}
if ($_POST['omnitool'] == '5') {
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id=$file_query");
$exists = $result->fetchColumn();
$result = null;
if ($exists == 1) $_SESSION['session_clipboard'][] = $value;
}
$_SESSION['session_clipboard'] = array_unique($_SESSION['session_clipboard']);
}
if ($_POST['omnitool'] == '6') {
while (list(,$value) = each($export_files)) {
$key = array_search($value, $_SESSION['session_clipboard']);
unset($_SESSION['session_clipboard'][$key]);
}
}
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;
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id=$file_query");
$exists = $result->fetchColumn();
$result = null;
if ($exists == 1) $dbHandle->exec("INSERT OR IGNORE INTO filescategories (fileID,categoryID) VALUES ($file_query,$last_insert_rowid)");
}
reset($export_files);
}
}
}
if ($_POST['omnitool'] == '7' && !empty($_POST['category'])) {
while (list(,$value) = each($export_files)) {
$file_query = $dbHandle->quote($value);
$result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id=$file_query");
$exists = $result->fetchColumn();
$result = null;
if ($exists == 1) {
while (list(,$cat) = each($_POST['category'])) {
$dbHandle->exec("INSERT OR IGNORE INTO filescategories (fileID,categoryID) VALUES ($file_query,".intval($cat).")");
}
}
reset($_POST['category']);
}
}
$dbHandle->commit();
if ($_POST['omnitool'] == '8') delete_record($dbHandle, $export_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%">
<input type="radio" style="display:none" name="omnitool" value="1">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Save to Shelf
</td>
<td class="threed select_span omnitooltd" style="width:32%">
<input type="radio" style="display:none" name="omnitool" value="5">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Save to Clipboard
</td>
<td class="threed select_span omnitooltd" style="width:36%">
<input type="radio" style="display:none" name="omnitool" value="3">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Save to Project
<select name="project3" style="width:100px">
<?php
database_connect($database_path,'library');
$desktop_projects = array();
$desktop_projects = read_desktop($dbHandle);
while(list(,$value)=each($desktop_projects)) {
print '<option value="'.$value['projectID'].'">'.$value['project'].'</option>';
}
reset($desktop_projects);
?>
</select>
</td>
</tr>
<tr>
<td class="threed select_span omnitooltd">
<input type="radio" style="display:none" name="omnitool" value="2">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Remove from Shelf
</td>
<td class="threed select_span omnitooltd">
<input type="radio" style="display:none" name="omnitool" value="6">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Remove from Clipboard
</td>
<td class="threed select_span omnitooltd">
<input type="radio" style="display:none" name="omnitool" value="4">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Remove from Project
<select name="project4" style="width:100px">
<?php
while(list(,$value)=each($desktop_projects)) {
print '<option value="'.$value['projectID'].'">'.$value['project'].'</option>';
}
reset($desktop_projects);
?>
</select>
</td>
</tr>
<tr>
<td class="threed select_span omnitooltd" colspan=3>
<input type="radio" style="display:none" name="omnitool" value="7">
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
Add to Categories:
<div style="width:99.5%;overflow:auto;height:240px;background-color:#fff;border:1px solid #C5C6C9;margin-top:2px;margin-bottom:10px">
<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\"><span class=\"ui-icon ui-icon-close\" style=\"float:left\"></span>".htmlspecialchars($category['category'])."</td></tr>";
$i=$i+1;
}
$result3 = null;
?>
</table>
</form>
</div>
</td>
</tr>
<?php
if ($_SESSION['permissions'] != 'G') {
?>
<tr>
<td class="select_span omnitooltd" id="lock" style="padding-top:10px">
<span class="ui-icon ui-icon-locked" style="float:left"></span>
unlock
</td>
<td class="omnitooltd" colspan=2>
</td>
</tr>
<tr>
<td class="omnitooltd ui-state-disabled" colspan=2>
<input type="radio" style="display:none" name="omnitool" value="8" disabled>
<span class="ui-icon ui-icon-radio-on" style="float:left"></span>
<div class="ui-state-error-text" style="float:left;margin-right:6px"><span class="ui-icon ui-icon-alert"></span></div>
Permanently delete from Library
</td>
<td class="omnitooltd">
</td>
</tr>
<?php
}
?>
</table>
</div>
<?php
}
?>