|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Teampass - a collaborative passwords manager. |
|
4
|
|
|
* |
|
5
|
|
|
* This library is distributed in the hope that it will be useful, |
|
6
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
8
|
|
|
* |
|
9
|
|
|
* @category Teampass |
|
10
|
|
|
* |
|
11
|
|
|
* @author Nils Laumaillé <[email protected]> |
|
12
|
|
|
* @copyright 2009-2018 Nils Laumaillé |
|
13
|
|
|
* @license https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0 |
|
14
|
|
|
* |
|
15
|
|
|
* @version GIT: <git_id> |
|
16
|
|
|
* |
|
17
|
|
|
* @see http://www.teampass.net |
|
18
|
|
|
*/ |
|
19
|
|
|
require_once 'SecureHandler.php'; |
|
20
|
|
|
session_start(); |
|
21
|
|
|
if (isset($_SESSION['CPM']) === false |
|
22
|
|
|
|| $_SESSION['CPM'] != 1 |
|
23
|
|
|
|| isset($_SESSION['user_id']) === false || empty($_SESSION['user_id']) |
|
24
|
|
|
|| isset($_SESSION['key']) === false || empty($_SESSION['key']) |
|
25
|
|
|
) { |
|
26
|
|
|
die('Hacking attempt...'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Load config if $SETTINGS not defined |
|
30
|
|
|
if (isset($SETTINGS['cpassman_dir']) === false || empty($SETTINGS['cpassman_dir'])) { |
|
31
|
|
|
if (file_exists('../includes/config/tp.config.php')) { |
|
32
|
|
|
include_once '../includes/config/tp.config.php'; |
|
33
|
|
|
} elseif (file_exists('./includes/config/tp.config.php')) { |
|
34
|
|
|
include_once './includes/config/tp.config.php'; |
|
35
|
|
|
} elseif (file_exists('../../includes/config/tp.config.php')) { |
|
36
|
|
|
include_once '../../includes/config/tp.config.php'; |
|
37
|
|
|
} else { |
|
38
|
|
|
throw new Exception("Error file '/includes/config/tp.config.php' not exists", 1); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/* do checks */ |
|
43
|
|
|
require_once $SETTINGS['cpassman_dir'].'/includes/config/include.php'; |
|
44
|
|
|
require_once $SETTINGS['cpassman_dir'].'/sources/checks.php'; |
|
45
|
|
|
if (!checkUser($_SESSION['user_id'], $_SESSION['key'], 'options', $SETTINGS)) { |
|
46
|
|
|
$_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page |
|
47
|
|
|
include $SETTINGS['cpassman_dir'].'/error.php'; |
|
48
|
|
|
exit(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
require_once $SETTINGS['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'.php'; |
|
52
|
|
|
require_once $SETTINGS['cpassman_dir'].'/includes/config/settings.php'; |
|
53
|
|
|
require_once $SETTINGS['cpassman_dir'].'/includes/config/tp.config.php'; |
|
54
|
|
|
|
|
55
|
|
|
header('Content-type: text/html; charset=utf-8'); |
|
56
|
|
|
header('Cache-Control: no-cache, no-store, must-revalidate'); |
|
57
|
|
|
|
|
58
|
|
|
require_once $SETTINGS['cpassman_dir'].'/sources/SplClassLoader.php'; |
|
59
|
|
|
|
|
60
|
|
|
// connect to the server |
|
61
|
|
|
require_once $SETTINGS['cpassman_dir'].'/includes/libraries/Database/Meekrodb/db.class.php'; |
|
62
|
|
|
DB::$host = DB_HOST; |
|
63
|
|
|
DB::$user = DB_USER; |
|
64
|
|
|
DB::$password = defuseReturnDecrypted(DB_PASSWD, $SETTINGS); |
|
65
|
|
|
DB::$dbName = DB_NAME; |
|
66
|
|
|
DB::$port = DB_PORT; |
|
67
|
|
|
DB::$encoding = DB_ENCODING; |
|
68
|
|
|
$link = mysqli_connect(DB_HOST, DB_USER, defuseReturnDecrypted(DB_PASSWD, $SETTINGS), DB_NAME, DB_PORT); |
|
69
|
|
|
$link->set_charset(DB_ENCODING); |
|
70
|
|
|
|
|
71
|
|
|
//Load AES |
|
72
|
|
|
$aes = new SplClassLoader('Encryption\Crypt', '../includes/libraries'); |
|
73
|
|
|
$aes->register(); |
|
74
|
|
|
|
|
75
|
|
|
// Prepare POST variables |
|
76
|
|
|
$post_title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING); |
|
77
|
|
|
$post_field_title = filter_input(INPUT_POST, 'field_title', FILTER_SANITIZE_STRING); |
|
78
|
|
|
$post_field_type = filter_input(INPUT_POST, 'field_type', FILTER_SANITIZE_STRING); |
|
79
|
|
|
$post_type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_STRING); |
|
80
|
|
|
$post_data = filter_input(INPUT_POST, 'data', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); |
|
81
|
|
|
$post_key = filter_input(INPUT_POST, 'key', FILTER_SANITIZE_STRING); |
|
82
|
|
|
$post_id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT); |
|
83
|
|
|
|
|
84
|
|
|
if (null !== $post_type) { |
|
85
|
|
|
switch ($post_type) { |
|
86
|
|
|
// LOADING THE TABLE |
|
87
|
|
|
case 'loadFieldsList': |
|
88
|
|
|
// Check KEY |
|
89
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
90
|
|
|
echo prepareExchangedData( |
|
91
|
|
|
array( |
|
92
|
|
|
'error' => true, |
|
93
|
|
|
'message' => langHdl('key_is_not_correct'), |
|
94
|
|
|
), |
|
95
|
|
|
'encode' |
|
96
|
|
|
); |
|
97
|
|
|
break; |
|
98
|
|
|
} elseif ($_SESSION['is_admin'] === false) { |
|
99
|
|
|
echo prepareExchangedData( |
|
100
|
|
|
array( |
|
101
|
|
|
'error' => true, |
|
102
|
|
|
'message' => langHdl('error_not_allowed_to'), |
|
103
|
|
|
), |
|
104
|
|
|
'encode' |
|
105
|
|
|
); |
|
106
|
|
|
break; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$categoriesSelect = ''; |
|
110
|
|
|
$arrCategories = $arrFields = array(); |
|
111
|
|
|
$rows = DB::query( |
|
112
|
|
|
'SELECT * |
|
113
|
|
|
FROM '.prefixTable('categories').' |
|
114
|
|
|
WHERE level = %i |
|
115
|
|
|
ORDER BY '.prefixTable('categories').'.order ASC', |
|
116
|
|
|
0 |
|
117
|
|
|
); |
|
118
|
|
|
foreach ($rows as $record) { |
|
119
|
|
|
// get associated folders |
|
120
|
|
|
$foldersList = $foldersNumList = ''; |
|
121
|
|
|
$arrayFolders = array(); |
|
122
|
|
|
$arrayRoles = array(); |
|
123
|
|
|
|
|
124
|
|
|
$rowsF = DB::query( |
|
125
|
|
|
'SELECT t.title AS title, c.id_folder as id_folder |
|
126
|
|
|
FROM '.prefixTable('categories_folders').' AS c |
|
127
|
|
|
INNER JOIN '.prefixTable('nested_tree').' AS t ON (c.id_folder = t.id) |
|
128
|
|
|
WHERE c.id_category = %i', |
|
129
|
|
|
$record['id'] |
|
130
|
|
|
); |
|
131
|
|
|
foreach ($rowsF as $recordF) { |
|
132
|
|
|
array_push( |
|
133
|
|
|
$arrayFolders, |
|
134
|
|
|
array( |
|
135
|
|
|
'title' => $recordF['title'], |
|
136
|
|
|
'id' => $recordF['id_folder'], |
|
137
|
|
|
) |
|
138
|
|
|
); |
|
139
|
|
|
/* |
|
140
|
|
|
if (empty($foldersList)) { |
|
141
|
|
|
$foldersList = $recordF['title']; |
|
142
|
|
|
$foldersNumList = $recordF['id_folder']; |
|
143
|
|
|
} else { |
|
144
|
|
|
$foldersList .= ' | '.$recordF['title']; |
|
145
|
|
|
$foldersNumList .= ';'.$recordF['id_folder']; |
|
146
|
|
|
} |
|
147
|
|
|
*/ |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
// store |
|
151
|
|
|
array_push( |
|
152
|
|
|
$arrCategories, |
|
153
|
|
|
array( |
|
154
|
|
|
'category' => true, |
|
155
|
|
|
'id' => (int) $record['id'], |
|
156
|
|
|
'title' => $record['title'], |
|
157
|
|
|
'order' => (int) $record['order'], |
|
158
|
|
|
'folders' => $arrayFolders, |
|
159
|
|
|
//$foldersNumList, |
|
160
|
|
|
) |
|
161
|
|
|
); |
|
162
|
|
|
$rows = DB::query( |
|
163
|
|
|
'SELECT * |
|
164
|
|
|
FROM '.prefixTable('categories').' |
|
165
|
|
|
WHERE parent_id = %i |
|
166
|
|
|
ORDER BY '.prefixTable('categories').'.order ASC', |
|
167
|
|
|
$record['id'] |
|
168
|
|
|
); |
|
169
|
|
|
if (count($rows) > 0) { |
|
170
|
|
|
foreach ($rows as $field) { |
|
171
|
|
|
$arrayRoles = array(); |
|
172
|
|
|
// Get lsit of Roles |
|
173
|
|
|
if ($field['role_visibility'] === 'all') { |
|
174
|
|
|
array_push( |
|
175
|
|
|
$arrayRoles, |
|
176
|
|
|
array( |
|
177
|
|
|
'id' => 'all', |
|
178
|
|
|
'title' => langHdl('every_roles'), |
|
179
|
|
|
) |
|
180
|
|
|
); |
|
181
|
|
|
} else { |
|
182
|
|
|
//echo $field['role_visibility']; |
|
183
|
|
|
foreach (explode(',', $field['role_visibility']) as $role) { |
|
184
|
|
|
if (empty($role) === false && $role !== null) { |
|
185
|
|
|
$data = DB::queryFirstRow( |
|
186
|
|
|
'SELECT title |
|
187
|
|
|
FROM '.prefixTable('roles_title').' |
|
188
|
|
|
WHERE id = %i', |
|
189
|
|
|
$role |
|
190
|
|
|
); |
|
191
|
|
|
array_push( |
|
192
|
|
|
$arrayRoles, |
|
193
|
|
|
array( |
|
194
|
|
|
'id' => $role, |
|
195
|
|
|
'title' => $data['title'], |
|
196
|
|
|
) |
|
197
|
|
|
); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
// Store for exchange |
|
202
|
|
|
array_push( |
|
203
|
|
|
$arrCategories, |
|
204
|
|
|
array( |
|
205
|
|
|
'category' => false, |
|
206
|
|
|
'id' => (int) $field['id'], |
|
207
|
|
|
'title' => $field['title'], |
|
208
|
|
|
'order' => (int) $field['order'], |
|
209
|
|
|
'encrypted' => (int) $field['encrypted_data'], |
|
210
|
|
|
'type' => $field['type'], |
|
211
|
|
|
'masked' => (int) $field['masked'], |
|
212
|
|
|
'roles' => $arrayRoles, |
|
213
|
|
|
//'role' => $field['role_visibility'], |
|
214
|
|
|
'mandatory' => (int) $field['is_mandatory'], |
|
215
|
|
|
) |
|
216
|
|
|
); |
|
217
|
|
|
} |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
echo prepareExchangedData( |
|
222
|
|
|
array( |
|
223
|
|
|
'error' => false, |
|
224
|
|
|
'message' => '', |
|
225
|
|
|
'array' => $arrCategories, |
|
226
|
|
|
), |
|
227
|
|
|
'encode' |
|
228
|
|
|
); |
|
229
|
|
|
break; |
|
230
|
|
|
|
|
231
|
|
|
// LOADING THE TABLE |
|
232
|
|
|
case 'add_new_category': |
|
233
|
|
|
// Check KEY |
|
234
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
235
|
|
|
echo prepareExchangedData( |
|
236
|
|
|
array( |
|
237
|
|
|
'error' => true, |
|
238
|
|
|
'message' => langHdl('key_is_not_correct'), |
|
239
|
|
|
), |
|
240
|
|
|
'encode' |
|
241
|
|
|
); |
|
242
|
|
|
break; |
|
243
|
|
|
} elseif ($_SESSION['is_admin'] === false) { |
|
244
|
|
|
echo prepareExchangedData( |
|
245
|
|
|
array( |
|
246
|
|
|
'error' => true, |
|
247
|
|
|
'message' => langHdl('error_not_allowed_to'), |
|
248
|
|
|
), |
|
249
|
|
|
'encode' |
|
250
|
|
|
); |
|
251
|
|
|
break; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
// Decrypt and retrieve data in JSON format |
|
255
|
|
|
$dataReceived = prepareExchangedData($post_data, 'decode'); |
|
256
|
|
|
|
|
257
|
|
|
// Prepare variables |
|
258
|
|
|
$post_label = filter_var($dataReceived['label'], FILTER_SANITIZE_STRING); |
|
259
|
|
|
$post_position = filter_var($dataReceived['position'], FILTER_SANITIZE_STRING); |
|
260
|
|
|
$post_folders = filter_var_array($dataReceived['folders'], FILTER_SANITIZE_STRING); |
|
261
|
|
|
|
|
262
|
|
|
// Store in DB |
|
263
|
|
|
DB::insert( |
|
264
|
|
|
prefixTable('categories'), |
|
265
|
|
|
array( |
|
266
|
|
|
'parent_id' => 0, |
|
267
|
|
|
'title' => $post_label, |
|
268
|
|
|
'level' => 0, |
|
269
|
|
|
'order' => 1, |
|
270
|
|
|
) |
|
271
|
|
|
); |
|
272
|
|
|
$newCategoryId = DB::insertId(); |
|
273
|
|
|
|
|
274
|
|
|
// Order the new item |
|
275
|
|
|
DB::update( |
|
276
|
|
|
prefixTable('categories'), |
|
277
|
|
|
array( |
|
278
|
|
|
'order' => calculateOrder($newCategoryId, $post_position), |
|
279
|
|
|
), |
|
280
|
|
|
'id = %i', |
|
281
|
|
|
$newCategoryId |
|
282
|
|
|
); |
|
283
|
|
|
|
|
284
|
|
|
// Store the folders |
|
285
|
|
|
foreach ($post_folders as $folder) { |
|
286
|
|
|
//add CF Category to this subfolder |
|
287
|
|
|
DB::insert( |
|
288
|
|
|
prefixTable('categories_folders'), |
|
289
|
|
|
array( |
|
290
|
|
|
'id_category' => $newCategoryId, |
|
291
|
|
|
'id_folder' => $folder, |
|
292
|
|
|
) |
|
293
|
|
|
); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
echo prepareExchangedData( |
|
297
|
|
|
array( |
|
298
|
|
|
'error' => false, |
|
299
|
|
|
'message' => '', |
|
300
|
|
|
), |
|
301
|
|
|
'encode' |
|
302
|
|
|
); |
|
303
|
|
|
break; |
|
304
|
|
|
|
|
305
|
|
|
// LOADING THE TABLE |
|
306
|
|
|
case 'edit_category': |
|
307
|
|
|
// Check KEY |
|
308
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
309
|
|
|
echo prepareExchangedData( |
|
310
|
|
|
array( |
|
311
|
|
|
'error' => true, |
|
312
|
|
|
'message' => langHdl('key_is_not_correct'), |
|
313
|
|
|
), |
|
314
|
|
|
'encode' |
|
315
|
|
|
); |
|
316
|
|
|
break; |
|
317
|
|
|
} elseif ($_SESSION['is_admin'] === false) { |
|
318
|
|
|
echo prepareExchangedData( |
|
319
|
|
|
array( |
|
320
|
|
|
'error' => true, |
|
321
|
|
|
'message' => langHdl('error_not_allowed_to'), |
|
322
|
|
|
), |
|
323
|
|
|
'encode' |
|
324
|
|
|
); |
|
325
|
|
|
break; |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
// Decrypt and retrieve data in JSON format |
|
329
|
|
|
$dataReceived = prepareExchangedData($post_data, 'decode'); |
|
330
|
|
|
|
|
331
|
|
|
// Prepare variables |
|
332
|
|
|
$post_label = filter_var($dataReceived['label'], FILTER_SANITIZE_STRING); |
|
333
|
|
|
$post_position = filter_var($dataReceived['position'], FILTER_SANITIZE_STRING); |
|
334
|
|
|
$post_folders = filter_var_array($dataReceived['folders'], FILTER_SANITIZE_STRING); |
|
335
|
|
|
$post_categoryId = filter_var($dataReceived['categoryId'], FILTER_SANITIZE_NUMBER_INT); |
|
336
|
|
|
|
|
337
|
|
|
// Update category |
|
338
|
|
|
DB::update( |
|
339
|
|
|
prefixTable('categories'), |
|
340
|
|
|
array( |
|
341
|
|
|
'title' => $post_label, |
|
342
|
|
|
'order' => calculateOrder($post_categoryId, $post_position), |
|
343
|
|
|
), |
|
344
|
|
|
'id = %i', |
|
345
|
|
|
$post_categoryId |
|
346
|
|
|
); |
|
347
|
|
|
|
|
348
|
|
|
// Delete all folders |
|
349
|
|
|
DB::delete( |
|
350
|
|
|
prefixTable('categories_folders'), |
|
351
|
|
|
'id_category = %i', |
|
352
|
|
|
$post_categoryId |
|
353
|
|
|
); |
|
354
|
|
|
|
|
355
|
|
|
// Store the folders |
|
356
|
|
|
foreach ($post_folders as $folder) { |
|
357
|
|
|
//add Category to this subfolder |
|
358
|
|
|
DB::insert( |
|
359
|
|
|
prefixTable('categories_folders'), |
|
360
|
|
|
array( |
|
361
|
|
|
'id_category' => $post_categoryId, |
|
362
|
|
|
'id_folder' => $folder, |
|
363
|
|
|
) |
|
364
|
|
|
); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
echo prepareExchangedData( |
|
368
|
|
|
array( |
|
369
|
|
|
'error' => false, |
|
370
|
|
|
'message' => '', |
|
371
|
|
|
), |
|
372
|
|
|
'encode' |
|
373
|
|
|
); |
|
374
|
|
|
break; |
|
375
|
|
|
|
|
376
|
|
|
// LOADING THE TABLE |
|
377
|
|
|
case 'delete': |
|
378
|
|
|
// Check KEY |
|
379
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
380
|
|
|
echo prepareExchangedData( |
|
381
|
|
|
array( |
|
382
|
|
|
'error' => true, |
|
383
|
|
|
'message' => langHdl('key_is_not_correct'), |
|
384
|
|
|
), |
|
385
|
|
|
'encode' |
|
386
|
|
|
); |
|
387
|
|
|
break; |
|
388
|
|
|
} elseif ($_SESSION['is_admin'] === false) { |
|
389
|
|
|
echo prepareExchangedData( |
|
390
|
|
|
array( |
|
391
|
|
|
'error' => true, |
|
392
|
|
|
'message' => langHdl('error_not_allowed_to'), |
|
393
|
|
|
), |
|
394
|
|
|
'encode' |
|
395
|
|
|
); |
|
396
|
|
|
break; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
// Decrypt and retrieve data in JSON format |
|
400
|
|
|
$dataReceived = prepareExchangedData($post_data, 'decode'); |
|
401
|
|
|
|
|
402
|
|
|
// Prepare variables |
|
403
|
|
|
$post_idToRemove = filter_var($dataReceived['idToRemove'], FILTER_SANITIZE_NUMBER_INT); |
|
404
|
|
|
$post_action = filter_var($dataReceived['action'], FILTER_SANITIZE_STRING); |
|
405
|
|
|
|
|
406
|
|
|
if ($post_action === 'category') { |
|
407
|
|
|
// DELETING A CATEGORY |
|
408
|
|
|
// Delete ID |
|
409
|
|
|
DB::delete( |
|
410
|
|
|
prefixTable('categories'), |
|
411
|
|
|
'id = %i', |
|
412
|
|
|
$post_idToRemove |
|
413
|
|
|
); |
|
414
|
|
|
|
|
415
|
|
|
// Remove data from fields |
|
416
|
|
|
$rows = DB::query( |
|
417
|
|
|
'SELECT id |
|
418
|
|
|
FROM '.prefixTable('categories').' |
|
419
|
|
|
WHERE parent_id = %i', |
|
420
|
|
|
$post_idToRemove |
|
421
|
|
|
); |
|
422
|
|
|
foreach ($rows as $record) { |
|
423
|
|
|
DB::delete( |
|
424
|
|
|
prefixTable('categories_items'), |
|
425
|
|
|
'field_id = %i', |
|
426
|
|
|
$record['id'] |
|
427
|
|
|
); |
|
428
|
|
|
} |
|
429
|
|
|
|
|
430
|
|
|
// Remove all fields of this category |
|
431
|
|
|
DB::delete( |
|
432
|
|
|
prefixTable('categories'), |
|
433
|
|
|
'parent_id = %i', |
|
434
|
|
|
$post_idToRemove |
|
435
|
|
|
); |
|
436
|
|
|
|
|
437
|
|
|
// Remove all folders belonging to this category |
|
438
|
|
|
DB::delete( |
|
439
|
|
|
prefixTable('categories_folders'), |
|
440
|
|
|
'id_category = %i', |
|
441
|
|
|
$post_idToRemove |
|
442
|
|
|
); |
|
443
|
|
|
} else { |
|
444
|
|
|
// DELETING A FIELD |
|
445
|
|
|
// Delete ID |
|
446
|
|
|
DB::delete( |
|
447
|
|
|
prefixTable('categories'), |
|
448
|
|
|
'id = %i', |
|
449
|
|
|
$post_idToRemove |
|
450
|
|
|
); |
|
451
|
|
|
|
|
452
|
|
|
// Delete all data |
|
453
|
|
|
DB::delete( |
|
454
|
|
|
prefixTable('categories_items'), |
|
455
|
|
|
'field_id = %i', |
|
456
|
|
|
$post_idToRemove |
|
457
|
|
|
); |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
echo prepareExchangedData( |
|
461
|
|
|
array( |
|
462
|
|
|
'error' => false, |
|
463
|
|
|
'message' => '', |
|
464
|
|
|
), |
|
465
|
|
|
'encode' |
|
466
|
|
|
); |
|
467
|
|
|
break; |
|
468
|
|
|
|
|
469
|
|
|
// EDIT FIELD |
|
470
|
|
|
case 'edit_field': |
|
471
|
|
|
// Check KEY |
|
472
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
473
|
|
|
echo prepareExchangedData( |
|
474
|
|
|
array( |
|
475
|
|
|
'error' => true, |
|
476
|
|
|
'message' => langHdl('key_is_not_correct'), |
|
477
|
|
|
), |
|
478
|
|
|
'encode' |
|
479
|
|
|
); |
|
480
|
|
|
break; |
|
481
|
|
|
} elseif ($_SESSION['is_admin'] === false) { |
|
482
|
|
|
echo prepareExchangedData( |
|
483
|
|
|
array( |
|
484
|
|
|
'error' => true, |
|
485
|
|
|
'message' => langHdl('error_not_allowed_to'), |
|
486
|
|
|
), |
|
487
|
|
|
'encode' |
|
488
|
|
|
); |
|
489
|
|
|
break; |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
// Decrypt and retrieve data in JSON format |
|
493
|
|
|
$dataReceived = prepareExchangedData($post_data, 'decode'); |
|
494
|
|
|
|
|
495
|
|
|
// Prepare variables |
|
496
|
|
|
$post_label = filter_var($dataReceived['label'], FILTER_SANITIZE_STRING); |
|
497
|
|
|
$post_order = filter_var($dataReceived['order'], FILTER_SANITIZE_STRING); |
|
498
|
|
|
$post_categoryId = filter_var($dataReceived['categoryId'], FILTER_SANITIZE_NUMBER_INT); |
|
499
|
|
|
$post_type = filter_var($dataReceived['type'], FILTER_SANITIZE_STRING); |
|
500
|
|
|
$post_mandatory = filter_var($dataReceived['mandatory'], FILTER_SANITIZE_STRING); |
|
501
|
|
|
$post_masked = filter_var($dataReceived['masked'], FILTER_SANITIZE_STRING); |
|
502
|
|
|
$post_encrypted = filter_var($dataReceived['encrypted'], FILTER_SANITIZE_STRING); |
|
503
|
|
|
$post_roles = filter_var_array($dataReceived['roles'], FILTER_SANITIZE_STRING); |
|
504
|
|
|
$post_fieldId = isset($dataReceived['fieldId']) === false ? '' : |
|
505
|
|
|
filter_var($dataReceived['fieldId'], FILTER_SANITIZE_NUMBER_INT); |
|
506
|
|
|
|
|
507
|
|
|
if (empty($post_fieldId) === false) { |
|
508
|
|
|
// UPDATE FIELD |
|
509
|
|
|
|
|
510
|
|
|
// Perform update |
|
511
|
|
|
DB::update( |
|
512
|
|
|
prefixTable('categories'), |
|
513
|
|
|
array( |
|
514
|
|
|
'title' => $post_label, |
|
515
|
|
|
'parent_id' => $post_categoryId, |
|
516
|
|
|
'type' => $post_type, |
|
517
|
|
|
'encrypted_data' => $post_encrypted, |
|
518
|
|
|
'is_mandatory' => $post_mandatory, |
|
519
|
|
|
'masked' => $post_masked, |
|
520
|
|
|
'role_visibility' => implode(',', $post_roles), |
|
521
|
|
|
'order' => calculateOrder($post_fieldId, $post_order), |
|
522
|
|
|
), |
|
523
|
|
|
'id = %i', |
|
524
|
|
|
$post_fieldId |
|
525
|
|
|
); |
|
526
|
|
|
|
|
527
|
|
|
// encrypt/decrypt existing data |
|
528
|
|
|
$rowsF = DB::query( |
|
529
|
|
|
'SELECT i.id, i.data, i.data_iv, i.encryption_type |
|
530
|
|
|
FROM '.$pre.'categories_items AS i |
|
531
|
|
|
INNER JOIN '.prefixTable('categories').' AS c ON (i.field_id = c.id) |
|
532
|
|
|
WHERE c.id = %i', |
|
533
|
|
|
$post_fieldId |
|
534
|
|
|
); |
|
535
|
|
|
foreach ($rowsF as $recordF) { |
|
536
|
|
|
$encryption_type = ''; |
|
537
|
|
|
// decrypt/encrypt |
|
538
|
|
|
if ($post_encrypted === '0' && $recordF['encryption_type'] === 'defuse') { |
|
539
|
|
|
$encrypt = cryption( |
|
|
|
|
|
|
540
|
|
|
$recordF['data'], |
|
541
|
|
|
'', |
|
542
|
|
|
'decrypt' |
|
543
|
|
|
); |
|
544
|
|
|
$encryption_type = 'none'; |
|
545
|
|
|
} elseif ($recordF['encryption_type'] === 'none' || $recordF['encryption_type'] === '') { |
|
546
|
|
|
$encrypt = cryption( |
|
547
|
|
|
$recordF['data'], |
|
548
|
|
|
'', |
|
549
|
|
|
'encrypt' |
|
550
|
|
|
); |
|
551
|
|
|
$encryption_type = 'defuse'; |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
// store in DB |
|
555
|
|
|
if ($encryption_type !== '') { |
|
556
|
|
|
DB::update( |
|
557
|
|
|
prefixTable('categories_items'), |
|
558
|
|
|
array( |
|
559
|
|
|
'data' => $encrypt['string'], |
|
560
|
|
|
'data_iv' => '', |
|
561
|
|
|
'encryption_type' => $encryption_type, |
|
562
|
|
|
), |
|
563
|
|
|
'id = %i', |
|
564
|
|
|
$recordF['id'] |
|
565
|
|
|
); |
|
566
|
|
|
} |
|
567
|
|
|
} |
|
568
|
|
|
} else { |
|
569
|
|
|
echo prepareExchangedData( |
|
570
|
|
|
array( |
|
571
|
|
|
'error' => true, |
|
572
|
|
|
'message' => langHdl('error_could_not_update_the_field'), |
|
573
|
|
|
), |
|
574
|
|
|
'encode' |
|
575
|
|
|
); |
|
576
|
|
|
break; |
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
echo prepareExchangedData( |
|
580
|
|
|
array( |
|
581
|
|
|
'error' => false, |
|
582
|
|
|
'message' => '', |
|
583
|
|
|
), |
|
584
|
|
|
'encode' |
|
585
|
|
|
); |
|
586
|
|
|
break; |
|
587
|
|
|
|
|
588
|
|
|
// ADD NEW FIELD |
|
589
|
|
|
case 'add_new_field': |
|
590
|
|
|
// Check KEY |
|
591
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
592
|
|
|
echo prepareExchangedData( |
|
593
|
|
|
array( |
|
594
|
|
|
'error' => true, |
|
595
|
|
|
'message' => langHdl('key_is_not_correct'), |
|
596
|
|
|
), |
|
597
|
|
|
'encode' |
|
598
|
|
|
); |
|
599
|
|
|
break; |
|
600
|
|
|
} elseif ($_SESSION['is_admin'] === false) { |
|
601
|
|
|
echo prepareExchangedData( |
|
602
|
|
|
array( |
|
603
|
|
|
'error' => true, |
|
604
|
|
|
'message' => langHdl('error_not_allowed_to'), |
|
605
|
|
|
), |
|
606
|
|
|
'encode' |
|
607
|
|
|
); |
|
608
|
|
|
break; |
|
609
|
|
|
} |
|
610
|
|
|
|
|
611
|
|
|
// Decrypt and retrieve data in JSON format |
|
612
|
|
|
$dataReceived = prepareExchangedData($post_data, 'decode'); |
|
613
|
|
|
|
|
614
|
|
|
// Prepare variables |
|
615
|
|
|
$post_label = filter_var($dataReceived['label'], FILTER_SANITIZE_STRING); |
|
616
|
|
|
$post_order = filter_var($dataReceived['order'], FILTER_SANITIZE_STRING); |
|
617
|
|
|
$post_categoryId = filter_var($dataReceived['categoryId'], FILTER_SANITIZE_NUMBER_INT); |
|
618
|
|
|
$post_type = filter_var($dataReceived['type'], FILTER_SANITIZE_STRING); |
|
619
|
|
|
$post_mandatory = filter_var($dataReceived['mandatory'], FILTER_SANITIZE_STRING); |
|
620
|
|
|
$post_masked = filter_var($dataReceived['masked'], FILTER_SANITIZE_STRING); |
|
621
|
|
|
$post_encrypted = filter_var($dataReceived['encrypted'], FILTER_SANITIZE_STRING); |
|
622
|
|
|
$post_roles = filter_var_array($dataReceived['roles'], FILTER_SANITIZE_STRING); |
|
623
|
|
|
$post_fieldId = isset($dataReceived['fieldId']) === false ? '' : |
|
624
|
|
|
filter_var($dataReceived['fieldId'], FILTER_SANITIZE_NUMBER_INT); |
|
625
|
|
|
|
|
626
|
|
|
// NEW FIELD |
|
627
|
|
|
DB::insert( |
|
628
|
|
|
prefixTable('categories'), |
|
629
|
|
|
array( |
|
630
|
|
|
'parent_id' => $post_categoryId, |
|
631
|
|
|
'title' => $post_label, |
|
632
|
|
|
'type' => $post_type, |
|
633
|
|
|
'masked' => $post_masked, |
|
634
|
|
|
'encrypted_data' => $post_encrypted, |
|
635
|
|
|
'is_mandatory' => $post_mandatory, |
|
636
|
|
|
'role_visibility' => implode(',', $post_roles), |
|
637
|
|
|
'level' => 1, |
|
638
|
|
|
'order' => 1, |
|
639
|
|
|
) |
|
640
|
|
|
); |
|
641
|
|
|
$newFieldId = DB::insertId(); |
|
642
|
|
|
|
|
643
|
|
|
// Order the new item |
|
644
|
|
|
DB::update( |
|
645
|
|
|
prefixTable('categories'), |
|
646
|
|
|
array( |
|
647
|
|
|
'order' => calculateOrder($newFieldId, $post_order), |
|
648
|
|
|
), |
|
649
|
|
|
'id = %i', |
|
650
|
|
|
$newFieldId |
|
651
|
|
|
); |
|
652
|
|
|
|
|
653
|
|
|
echo prepareExchangedData( |
|
654
|
|
|
array( |
|
655
|
|
|
'error' => false, |
|
656
|
|
|
'message' => '', |
|
657
|
|
|
), |
|
658
|
|
|
'encode' |
|
659
|
|
|
); |
|
660
|
|
|
break; |
|
661
|
|
|
} |
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
function calculateOrder($id, $position) |
|
665
|
|
|
{ |
|
666
|
|
|
if ($position === 'top') { |
|
667
|
|
|
// Set this new category to the top |
|
668
|
|
|
$orderNewCategory = 1; |
|
669
|
|
|
$newOrder = 2; |
|
670
|
|
|
} elseif ($position === 'bottom') { |
|
671
|
|
|
// Set this new category to the bottom |
|
672
|
|
|
|
|
673
|
|
|
// Get number of categories |
|
674
|
|
|
$rows = DB::query( |
|
|
|
|
|
|
675
|
|
|
'SELECT id |
|
676
|
|
|
FROM '.prefixTable('categories').' |
|
677
|
|
|
WHERE level = %i', |
|
678
|
|
|
0 |
|
679
|
|
|
); |
|
680
|
|
|
$orderNewCategory = DB::count() + 1; |
|
681
|
|
|
|
|
682
|
|
|
return $orderNewCategory; |
|
683
|
|
|
} else { |
|
684
|
|
|
// Get position of selected folder |
|
685
|
|
|
$data = DB::queryFirstRow( |
|
686
|
|
|
'SELECT c.order AS position |
|
687
|
|
|
FROM '.prefixTable('categories').' AS c |
|
688
|
|
|
WHERE id = %i', |
|
689
|
|
|
(int) $position |
|
690
|
|
|
); |
|
691
|
|
|
|
|
692
|
|
|
$orderNewCategory = (int) $data['position'] - 1; |
|
693
|
|
|
|
|
694
|
|
|
// Manage case of top |
|
695
|
|
|
if ($orderNewCategory === 0) { |
|
696
|
|
|
$orderNewCategory = 1; |
|
697
|
|
|
$newOrder = 2; |
|
698
|
|
|
} else { |
|
699
|
|
|
$newOrder = 1; |
|
700
|
|
|
} |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
// Update all orders |
|
704
|
|
|
$rows = DB::query( |
|
705
|
|
|
'SELECT id, c.order AS position |
|
706
|
|
|
FROM '.prefixTable('categories').' AS c |
|
707
|
|
|
WHERE level = %i |
|
708
|
|
|
ORDER BY c.order ASC, c.title ASC', |
|
709
|
|
|
0 |
|
710
|
|
|
); |
|
711
|
|
|
foreach ($rows as $record) { |
|
712
|
|
|
if ($record['id'] !== $id) { |
|
713
|
|
|
DB::update( |
|
714
|
|
|
prefixTable('categories'), |
|
715
|
|
|
array( |
|
716
|
|
|
'order' => $newOrder, |
|
717
|
|
|
), |
|
718
|
|
|
'id = %i', |
|
719
|
|
|
$record['id'] |
|
720
|
|
|
); |
|
721
|
|
|
} |
|
722
|
|
|
++$newOrder; |
|
723
|
|
|
} |
|
724
|
|
|
|
|
725
|
|
|
// update for the new item |
|
726
|
|
|
return (int) $orderNewCategory; |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
/* |
|
730
|
|
|
if (null !== $post_type) { |
|
731
|
|
|
switch ($post_type) { |
|
732
|
|
|
case "addNewCategory": |
|
733
|
|
|
// store key |
|
734
|
|
|
DB::insert( |
|
735
|
|
|
prefixTable("categories"), |
|
736
|
|
|
array( |
|
737
|
|
|
'parent_id' => 0, |
|
738
|
|
|
'title' => $post_title, |
|
739
|
|
|
'level' => 0, |
|
740
|
|
|
'order' => 1 |
|
741
|
|
|
) |
|
742
|
|
|
); |
|
743
|
|
|
echo '[{"error" : "", "id" : "'.DB::insertId().'"}]'; |
|
744
|
|
|
break; |
|
745
|
|
|
|
|
746
|
|
|
case "deleteCategory": |
|
747
|
|
|
DB::delete(prefixTable("categories"), "id = %i", $post_id); |
|
748
|
|
|
DB::delete(prefixTable("categories_folders"), "id_category = %i", $post_id); |
|
749
|
|
|
echo '[{"error" : ""}]'; |
|
750
|
|
|
break; |
|
751
|
|
|
|
|
752
|
|
|
case "addNewField": |
|
753
|
|
|
// Check KEY and rights |
|
754
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
755
|
|
|
echo prepareExchangedData(array("error" => "ERR_KEY_NOT_CORRECT"), "encode"); |
|
756
|
|
|
break; |
|
757
|
|
|
} |
|
758
|
|
|
|
|
759
|
|
|
// decrypt and retreive data in JSON format |
|
760
|
|
|
$dataReceived = prepareExchangedData( |
|
761
|
|
|
$post_data, |
|
762
|
|
|
"decode" |
|
763
|
|
|
); |
|
764
|
|
|
|
|
765
|
|
|
$post_title = filter_var($dataReceived['title'], FILTER_SANITIZE_STRING); |
|
766
|
|
|
|
|
767
|
|
|
// store key |
|
768
|
|
|
if (empty($post_title) === false) { |
|
769
|
|
|
DB::insert( |
|
770
|
|
|
prefixTable("categories"), |
|
771
|
|
|
array( |
|
772
|
|
|
'parent_id' => filter_var($dataReceived['id'], FILTER_SANITIZE_NUMBER_INT), |
|
773
|
|
|
'title' => filter_var($dataReceived['title'], FILTER_SANITIZE_STRING), |
|
774
|
|
|
'type' => filter_var($dataReceived['type'], FILTER_SANITIZE_STRING), |
|
775
|
|
|
'masked' => filter_var($dataReceived['masked'], FILTER_SANITIZE_STRING), |
|
776
|
|
|
'encrypted_data' => filter_var($dataReceived['encrypted'], FILTER_SANITIZE_STRING), |
|
777
|
|
|
'is_mandatory' => filter_var($dataReceived['is_mandatory'], FILTER_SANITIZE_STRING), |
|
778
|
|
|
'role_visibility' => filter_var($dataReceived['field_visibility'], FILTER_SANITIZE_STRING), |
|
779
|
|
|
'level' => 1, |
|
780
|
|
|
'order' => filter_var($dataReceived['order'], FILTER_SANITIZE_NUMBER_INT) |
|
781
|
|
|
) |
|
782
|
|
|
); |
|
783
|
|
|
echo '[{"error" : "", "id" : "'.DB::insertId().'"}]'; |
|
784
|
|
|
} |
|
785
|
|
|
break; |
|
786
|
|
|
|
|
787
|
|
|
case "saveOrder": |
|
788
|
|
|
// update order |
|
789
|
|
|
if (empty($post_type) === false) { |
|
790
|
|
|
foreach (explode(';', $post_data) as $data) { |
|
791
|
|
|
$elem = explode(':', $data); |
|
792
|
|
|
DB::update( |
|
793
|
|
|
prefixTable("categories"), |
|
794
|
|
|
array( |
|
795
|
|
|
'order' => $elem[1] |
|
796
|
|
|
), |
|
797
|
|
|
"id=%i", |
|
798
|
|
|
$elem[0] |
|
799
|
|
|
); |
|
800
|
|
|
} |
|
801
|
|
|
echo '[{"error" : ""}]'; |
|
802
|
|
|
} |
|
803
|
|
|
break; |
|
804
|
|
|
|
|
805
|
|
|
case "update_category_and_field": |
|
806
|
|
|
// Check KEY and rights |
|
807
|
|
|
if ($post_key !== $_SESSION['key']) { |
|
808
|
|
|
echo prepareExchangedData(array("error" => "ERR_KEY_NOT_CORRECT"), "encode"); |
|
809
|
|
|
break; |
|
810
|
|
|
} |
|
811
|
|
|
|
|
812
|
|
|
// decrypt and retreive data in JSON format |
|
813
|
|
|
$dataReceived = prepareExchangedData( |
|
814
|
|
|
$post_data, |
|
815
|
|
|
"decode" |
|
816
|
|
|
); |
|
817
|
|
|
|
|
818
|
|
|
if (filter_var(($dataReceived['field_is_category']), FILTER_SANITIZE_NUMBER_INT) === 1) { |
|
819
|
|
|
$array = array( |
|
820
|
|
|
'title' => filter_var($dataReceived['title'], FILTER_SANITIZE_STRING) |
|
821
|
|
|
); |
|
822
|
|
|
} else { |
|
823
|
|
|
$array = array( |
|
824
|
|
|
'title' => filter_var($dataReceived['title'], FILTER_SANITIZE_STRING), |
|
825
|
|
|
'parent_id' => filter_var($dataReceived['category'], FILTER_SANITIZE_NUMBER_INT), |
|
826
|
|
|
'type' => filter_var($dataReceived['type'], FILTER_SANITIZE_STRING), |
|
827
|
|
|
'encrypted_data' => filter_var($dataReceived['encrypted'], FILTER_SANITIZE_STRING), |
|
828
|
|
|
'is_mandatory' => filter_var($dataReceived['is_mandatory'], FILTER_SANITIZE_STRING), |
|
829
|
|
|
'masked' => filter_var($dataReceived['masked'], FILTER_SANITIZE_STRING), |
|
830
|
|
|
'role_visibility' => filter_var($dataReceived['roles'], FILTER_SANITIZE_STRING), |
|
831
|
|
|
'order' => filter_var($dataReceived['order'], FILTER_SANITIZE_NUMBER_INT) |
|
832
|
|
|
); |
|
833
|
|
|
} |
|
834
|
|
|
|
|
835
|
|
|
// Perform update |
|
836
|
|
|
DB::update( |
|
837
|
|
|
prefixTable("categories"), |
|
838
|
|
|
$array, |
|
839
|
|
|
"id=%i", |
|
840
|
|
|
filter_var(($dataReceived['id']), FILTER_SANITIZE_NUMBER_INT) |
|
841
|
|
|
); |
|
842
|
|
|
echo '[{"error" : ""}]'; |
|
843
|
|
|
|
|
844
|
|
|
break; |
|
845
|
|
|
|
|
846
|
|
|
case "loadFieldsList": |
|
847
|
|
|
$categoriesSelect = ""; |
|
848
|
|
|
$arrCategories = $arrFields = array(); |
|
849
|
|
|
$rows = DB::query( |
|
850
|
|
|
"SELECT * |
|
851
|
|
|
FROM ".$pre."categories |
|
852
|
|
|
WHERE level = %i |
|
853
|
|
|
ORDER BY ".$pre."categories.order ASC", |
|
854
|
|
|
0 |
|
855
|
|
|
); |
|
856
|
|
|
foreach ($rows as $record) { |
|
857
|
|
|
// get associated folders |
|
858
|
|
|
$foldersList = $foldersNumList = ""; |
|
859
|
|
|
$rowsF = DB::query( |
|
860
|
|
|
"SELECT t.title AS title, c.id_folder as id_folder |
|
861
|
|
|
FROM ".$pre."categories_folders AS c |
|
862
|
|
|
INNER JOIN ".prefixTable("nested_tree")." AS t ON (c.id_folder = t.id) |
|
863
|
|
|
WHERE c.id_category = %i", |
|
864
|
|
|
$record['id'] |
|
865
|
|
|
); |
|
866
|
|
|
foreach ($rowsF as $recordF) { |
|
867
|
|
|
if (empty($foldersList)) { |
|
868
|
|
|
$foldersList = $recordF['title']; |
|
869
|
|
|
$foldersNumList = $recordF['id_folder']; |
|
870
|
|
|
} else { |
|
871
|
|
|
$foldersList .= " | ".$recordF['title']; |
|
872
|
|
|
$foldersNumList .= ";".$recordF['id_folder']; |
|
873
|
|
|
} |
|
874
|
|
|
} |
|
875
|
|
|
|
|
876
|
|
|
// store |
|
877
|
|
|
array_push( |
|
878
|
|
|
$arrCategories, |
|
879
|
|
|
array( |
|
880
|
|
|
'1', |
|
881
|
|
|
$record['id'], |
|
882
|
|
|
$record['title'], |
|
883
|
|
|
$record['order'], |
|
884
|
|
|
$foldersList, |
|
885
|
|
|
$foldersNumList |
|
886
|
|
|
) |
|
887
|
|
|
); |
|
888
|
|
|
$rows = DB::query( |
|
889
|
|
|
"SELECT * |
|
890
|
|
|
FROM ".prefixTable("categories")." |
|
891
|
|
|
WHERE parent_id = %i |
|
892
|
|
|
ORDER BY ".$pre."categories.order ASC", |
|
893
|
|
|
$record['id'] |
|
894
|
|
|
); |
|
895
|
|
|
if (count($rows) > 0) { |
|
896
|
|
|
foreach ($rows as $field) { |
|
897
|
|
|
// Get lsit of Roles |
|
898
|
|
|
if ($field['role_visibility'] === 'all') { |
|
899
|
|
|
$roleVisibility = $LANG['every_roles']; |
|
900
|
|
|
} else { |
|
901
|
|
|
$roleVisibility = ''; |
|
902
|
|
|
foreach (explode(',', $field['role_visibility']) as $role) { |
|
903
|
|
|
$data = DB::queryFirstRow( |
|
904
|
|
|
"SELECT title |
|
905
|
|
|
FROM ".$pre."roles_title |
|
906
|
|
|
WHERE id = %i", |
|
907
|
|
|
$role |
|
908
|
|
|
); |
|
909
|
|
|
if (empty($roleVisibility) === true) { |
|
910
|
|
|
$roleVisibility = $data['title']; |
|
911
|
|
|
} else { |
|
912
|
|
|
$roleVisibility .= ', '.$data['title']; |
|
913
|
|
|
} |
|
914
|
|
|
} |
|
915
|
|
|
} |
|
916
|
|
|
// Store for exchange |
|
917
|
|
|
array_push( |
|
918
|
|
|
$arrCategories, |
|
919
|
|
|
array( |
|
920
|
|
|
'2', |
|
921
|
|
|
$field['id'], |
|
922
|
|
|
$field['title'], |
|
923
|
|
|
$field['order'], |
|
924
|
|
|
$field['encrypted_data'], |
|
925
|
|
|
"", |
|
926
|
|
|
$field['type'], |
|
927
|
|
|
$field['masked'], |
|
928
|
|
|
addslashes($roleVisibility), |
|
929
|
|
|
$field['role_visibility'], |
|
930
|
|
|
$field['is_mandatory'] |
|
931
|
|
|
) |
|
932
|
|
|
); |
|
933
|
|
|
} |
|
934
|
|
|
} |
|
935
|
|
|
} |
|
936
|
|
|
echo json_encode($arrCategories, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); |
|
937
|
|
|
break; |
|
938
|
|
|
|
|
939
|
|
|
case "categoryInFolders": |
|
940
|
|
|
// Prepare POST variables |
|
941
|
|
|
$post_foldersIds = filter_input(INPUT_POST, 'foldersIds', FILTER_SANITIZE_STRING); |
|
942
|
|
|
$post_id = $post_id; |
|
943
|
|
|
|
|
944
|
|
|
// update order |
|
945
|
|
|
if (empty($post_foldersIds) === false) { |
|
946
|
|
|
// delete all existing inputs |
|
947
|
|
|
DB::delete( |
|
948
|
|
|
$pre."categories_folders", |
|
949
|
|
|
"id_category = %i", |
|
950
|
|
|
$post_id |
|
951
|
|
|
); |
|
952
|
|
|
// create new list |
|
953
|
|
|
$list = ""; |
|
954
|
|
|
foreach (explode(';', $post_foldersIds) as $folder) { |
|
955
|
|
|
DB::insert( |
|
956
|
|
|
prefixTable("categories_folders"), |
|
957
|
|
|
array( |
|
958
|
|
|
'id_category' => $post_id, |
|
959
|
|
|
'id_folder' => $folder |
|
960
|
|
|
) |
|
961
|
|
|
); |
|
962
|
|
|
|
|
963
|
|
|
// prepare a list |
|
964
|
|
|
$row = DB::queryfirstrow("SELECT title FROM ".prefixTable("nested_tree")." WHERE id=%i", $folder); |
|
965
|
|
|
if (empty($list)) { |
|
966
|
|
|
$list = $row['title']; |
|
967
|
|
|
} else { |
|
968
|
|
|
$list .= " | ".$row['title']; |
|
969
|
|
|
} |
|
970
|
|
|
} |
|
971
|
|
|
echo '[{"list" : "'.$list.'"}]'; |
|
972
|
|
|
} |
|
973
|
|
|
break; |
|
974
|
|
|
|
|
975
|
|
|
case "dataIsEncryptedInDB": |
|
976
|
|
|
// Prepare POST variables |
|
977
|
|
|
$post_encrypt = filter_input(INPUT_POST, 'encrypt', FILTER_SANITIZE_STRING); |
|
978
|
|
|
|
|
979
|
|
|
// store key |
|
980
|
|
|
DB::update( |
|
981
|
|
|
prefixTable("categories"), |
|
982
|
|
|
array( |
|
983
|
|
|
'encrypted_data' => $post_encrypt |
|
984
|
|
|
), |
|
985
|
|
|
"id = %i", |
|
986
|
|
|
$post_id |
|
987
|
|
|
); |
|
988
|
|
|
|
|
989
|
|
|
// encrypt/decrypt existing data |
|
990
|
|
|
$rowsF = DB::query( |
|
991
|
|
|
"SELECT i.id, i.data, i.data_iv, i.encryption_type |
|
992
|
|
|
FROM ".$pre."categories_items AS i |
|
993
|
|
|
INNER JOIN ".prefixTable("categories")." AS c ON (i.field_id = c.id) |
|
994
|
|
|
WHERE c.id = %i", |
|
995
|
|
|
$post_id |
|
996
|
|
|
); |
|
997
|
|
|
foreach ($rowsF as $recordF) { |
|
998
|
|
|
$encryption_type = ""; |
|
999
|
|
|
// decrypt/encrypt |
|
1000
|
|
|
if ($post_encrypt === "0" && $recordF['encryption_type'] === "defuse") { |
|
1001
|
|
|
$encrypt = cryption( |
|
1002
|
|
|
$recordF['data'], |
|
1003
|
|
|
"", |
|
1004
|
|
|
"decrypt" |
|
1005
|
|
|
); |
|
1006
|
|
|
$encryption_type = "none"; |
|
1007
|
|
|
} elseif ($recordF['encryption_type'] === "none" || $recordF['encryption_type'] === "") { |
|
1008
|
|
|
$encrypt = cryption( |
|
1009
|
|
|
$recordF['data'], |
|
1010
|
|
|
"", |
|
1011
|
|
|
"encrypt" |
|
1012
|
|
|
); |
|
1013
|
|
|
$encryption_type = "defuse"; |
|
1014
|
|
|
} |
|
1015
|
|
|
|
|
1016
|
|
|
// store in DB |
|
1017
|
|
|
if ($encryption_type !== "") { |
|
1018
|
|
|
DB::update( |
|
1019
|
|
|
prefixTable("categories_items"), |
|
1020
|
|
|
array( |
|
1021
|
|
|
'data' => $encrypt['string'], |
|
1022
|
|
|
'data_iv' => "", |
|
1023
|
|
|
'encryption_type' => $encryption_type |
|
1024
|
|
|
), |
|
1025
|
|
|
"id = %i", |
|
1026
|
|
|
$recordF['id'] |
|
1027
|
|
|
); |
|
1028
|
|
|
} |
|
1029
|
|
|
} |
|
1030
|
|
|
|
|
1031
|
|
|
echo '[{"error" : ""}]'; |
|
1032
|
|
|
break; |
|
1033
|
|
|
|
|
1034
|
|
|
case "refreshCategoriesHTML": |
|
1035
|
|
|
//Build tree of Categories |
|
1036
|
|
|
$categoriesSelect = ""; |
|
1037
|
|
|
$arrCategories = array(); |
|
1038
|
|
|
$rows = DB::query( |
|
1039
|
|
|
"SELECT * FROM ".prefixTable("categories")." |
|
1040
|
|
|
WHERE level = %i |
|
1041
|
|
|
ORDER BY ".$pre."categories.order ASC", |
|
1042
|
|
|
'0' |
|
1043
|
|
|
); |
|
1044
|
|
|
foreach ($rows as $record) { |
|
1045
|
|
|
array_push( |
|
1046
|
|
|
$arrCategories, |
|
1047
|
|
|
array( |
|
1048
|
|
|
$record['id'], |
|
1049
|
|
|
$record['title'], |
|
1050
|
|
|
$record['order'] |
|
1051
|
|
|
) |
|
1052
|
|
|
); |
|
1053
|
|
|
} |
|
1054
|
|
|
$arrReturn = array( |
|
1055
|
|
|
'html' => '', |
|
1056
|
|
|
'no_category' => false |
|
1057
|
|
|
); |
|
1058
|
|
|
$html = ''; |
|
1059
|
|
|
|
|
1060
|
|
|
if (isset($arrCategories) && count($arrCategories) > 0) { |
|
1061
|
|
|
// build table |
|
1062
|
|
|
foreach ($arrCategories as $category) { |
|
1063
|
|
|
// get associated Folders |
|
1064
|
|
|
$foldersList = $foldersNumList = ""; |
|
1065
|
|
|
$rows = DB::query( |
|
1066
|
|
|
"SELECT t.title AS title, c.id_folder as id_folder |
|
1067
|
|
|
FROM ".prefixTable("categories_folders")." AS c |
|
1068
|
|
|
INNER JOIN ".prefixTable("nested_tree")." AS t ON (c.id_folder = t.id) |
|
1069
|
|
|
WHERE c.id_category = %i", |
|
1070
|
|
|
$category[0] |
|
1071
|
|
|
); |
|
1072
|
|
|
foreach ($rows as $record) { |
|
1073
|
|
|
if (empty($foldersList)) { |
|
1074
|
|
|
$foldersList = $record['title']; |
|
1075
|
|
|
$foldersNumList = $record['id_folder']; |
|
1076
|
|
|
} else { |
|
1077
|
|
|
$foldersList .= " | ".$record['title']; |
|
1078
|
|
|
$foldersNumList .= ";".$record['id_folder']; |
|
1079
|
|
|
} |
|
1080
|
|
|
} |
|
1081
|
|
|
// display each cat and fields |
|
1082
|
|
|
$html .= ' |
|
1083
|
|
|
<tr id="t_cat_'.$category[0].'"> |
|
1084
|
|
|
<td colspan="2"> |
|
1085
|
|
|
<input type="text" id="catOrd_'.$category[0].'" size="1" class="category_order" value="'.$category[2].'" /> |
|
1086
|
|
|
<span class="fa-stack tip" title="'.$LANG['field_add_in_category'].'" onclick="fieldAdd('.$category[0].')" style="cursor:pointer;"> |
|
1087
|
|
|
<i class="fa fa-square fa-stack-2x"></i> |
|
1088
|
|
|
<i class="fa fa-plus fa-stack-1x fa-inverse"></i> |
|
1089
|
|
|
</span> |
|
1090
|
|
|
|
|
1091
|
|
|
<input type="radio" name="sel_item" id="item_'.$category[0].'_cat" /> |
|
1092
|
|
|
<label for="item_'.$category[0].'_cat" id="item_'.$category[0].'" style="font-weight:bold;">'.$category[1].'</label> |
|
1093
|
|
|
</td> |
|
1094
|
|
|
<td> |
|
1095
|
|
|
<span class="fa-stack tip" title="'.$LANG['category_in_folders'].'" onclick="catInFolders('.$category[0].')" style="cursor:pointer;"> |
|
1096
|
|
|
<i class="fa fa-square fa-stack-2x"></i> |
|
1097
|
|
|
<i class="fa fa-edit fa-stack-1x fa-inverse"></i> |
|
1098
|
|
|
</span> |
|
1099
|
|
|
|
|
1100
|
|
|
'.$LANG['category_in_folders_title'].': |
|
1101
|
|
|
<span style="font-family:italic; margin-left:10px;" id="catFolders_'.$category[0].'">'.$foldersList.'</span> |
|
1102
|
|
|
<input type="hidden" id="catFoldersList_'.$category[0].'" value="'.$foldersNumList.'" /> |
|
1103
|
|
|
</td> |
|
1104
|
|
|
</tr>'; |
|
1105
|
|
|
$rows = DB::query( |
|
1106
|
|
|
"SELECT * FROM ".prefixTable("categories")." |
|
1107
|
|
|
WHERE parent_id = %i |
|
1108
|
|
|
ORDER BY ".$pre."categories.order ASC", |
|
1109
|
|
|
$category[0] |
|
1110
|
|
|
); |
|
1111
|
|
|
$counter = DB::count(); |
|
1112
|
|
|
if ($counter > 0) { |
|
1113
|
|
|
foreach ($rows as $field) { |
|
1114
|
|
|
$html .= ' |
|
1115
|
|
|
<tr id="t_field_'.$field['id'].'"> |
|
1116
|
|
|
<td width="60px"></td> |
|
1117
|
|
|
<td colspan="2"> |
|
1118
|
|
|
<input type="text" id="catOrd_'.$field['id'].'" size="1" class="category_order" value="'.$field['order'].'" /> |
|
1119
|
|
|
<input type="radio" name="sel_item" id="item_'.$field['id'].'_cat" /> |
|
1120
|
|
|
<label for="item_'.$field['id'].'_cat" id="item_'.$field['id'].'">'.($field['title']).'</label> |
|
1121
|
|
|
<span id="encryt_data_'.$field['id'].'" style="margin-left:4px; cursor:pointer;">'.(isset($field['encrypted_data']) && $field['encrypted_data'] === "1") ? '<i class="fa fa-key tip" title="'.$LANG['encrypted_data'].'" onclick="changeEncrypMode(\''.$field['id'].'\', \'1\')"></i>' : '<span class="fa-stack" title="'.$LANG['not_encrypted_data'].'" onclick="changeEncrypMode(\''.$field['id'].'\', \'0\')"><i class="fa fa-key fa-stack-1x"></i><i class="fa fa-ban fa-stack-1x fa-lg" style="color:red;"></i></span>'.' |
|
1122
|
|
|
</span>'; |
|
1123
|
|
|
if (isset($field['type'])) { |
|
1124
|
|
|
if ($field['type'] === "text") { |
|
1125
|
|
|
$html .= ' |
|
1126
|
|
|
<span style="margin-left:4px;"><i class="fa fa-paragraph tip" title="'.$LANG['data_is_text'].'"></i></span>'; |
|
1127
|
|
|
} elseif ($field['type'] === "masked") { |
|
1128
|
|
|
$html .= ' |
|
1129
|
|
|
<span style="margin-left:4px;"><i class="fa fa-eye-slash tip" title="'.$LANG['data_is_masked'].'"></i></span>'; |
|
1130
|
|
|
} |
|
1131
|
|
|
} |
|
1132
|
|
|
$html .= ' |
|
1133
|
|
|
</td> |
|
1134
|
|
|
<td></td> |
|
1135
|
|
|
</tr>'; |
|
1136
|
|
|
} |
|
1137
|
|
|
} |
|
1138
|
|
|
} |
|
1139
|
|
|
} else { |
|
1140
|
|
|
$arrReturn['no_category'] === true; |
|
1141
|
|
|
$html = addslashes($LANG['no_category_defined']); |
|
1142
|
|
|
} |
|
1143
|
|
|
|
|
1144
|
|
|
$arrReturn['html'] === $html; |
|
1145
|
|
|
|
|
1146
|
|
|
echo json_encode($arrReturn, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); |
|
1147
|
|
|
break; |
|
1148
|
|
|
} |
|
1149
|
|
|
} |
|
1150
|
|
|
*/ |
|
1151
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.