-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajaxshelf.php
49 lines (41 loc) · 1.6 KB
/
ajaxshelf.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
<?php
include_once 'data.php';
include_once 'functions.php';
if (isset($_GET['file']) && isset($_SESSION['auth'])) {
database_connect($database_path, 'library');
$user_query = $dbHandle->quote($_SESSION['user_id']);
$file_query = $dbHandle->quote($_GET['file']);
$result = $dbHandle->query("SELECT rowid FROM shelves WHERE userID=$user_query AND fileID=$file_query LIMIT 1");
$relation = $result->fetchColumn();
$result = null;
if (!$relation) {
$dbHandle->beginTransaction();
$result = $dbHandle->query("SELECT COUNT(*) FROM library WHERE id=$file_query");
$exists = $result->fetchColumn();
$result = null;
if ($exists == 1) {
$update = $dbHandle->exec("INSERT OR IGNORE INTO shelves (userID,fileID) VALUES ($user_query,$file_query)");
$dbHandle->commit();
if ($update) echo 'added';
} else {
$dbHandle->rollBack();
echo 'Error! This item does not exist anymore.';
}
} else {
$update = $dbHandle->exec("DELETE FROM shelves WHERE rowid=$relation");
if (isset($_GET['selection']) && $_GET['selection'] == 'shelf') {
$export_files = read_export_files(0);
unset($export_files[array_search($_GET['file'], $export_files)]);
$export_files = array_values($export_files);
save_export_files($export_files);
}
if ($update)
echo 'removed';
}
$dbHandle = null;
$isapc = ini_get('apc.enabled');
if (!empty($isapc)) {
apc_delete($_SESSION['user_id'].'_shelf_files');
}
}
?>