-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbookmark.php
42 lines (38 loc) · 1.3 KB
/
bookmark.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
<?php
require "include/bittorrent.php";
dbconn();
checkHTTPMethod('POST');
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-Type: application/json; charset=utf-8");
$torrentid = 0 + $_REQUEST['torrentid'];
if ($torrentid == 0) {
header('HTTP/1.1 400 Bad Request');
$result = 'failed';
}
else if (isset($CURUSER)) {
if ($_REQUEST['action'] == 'del'){
sql_query("DELETE FROM bookmarks WHERE torrentid= ? AND userid=?", [$torrentid, $CURUSER['id']]);
$result = "deleted";
$Cache->delete_value('user_'.$CURUSER['id'].'_bookmark_array');
}
else {
if (get_row_count('bookmarks', 'WHERE torrentid=? AND userid=?', [$torrentid, $CURUSER['id']]) == 0) {
sql_query("INSERT INTO bookmarks (torrentid, userid) VALUES (?, ?)", [$torrentid, $CURUSER['id']]);
$result = "added";
$Cache->delete_value('user_'.$CURUSER['id'].'_bookmark_array');
}
else {
header('HTTP/1.1 409 Conflict');
$result = 'failed';
}
}
}
else {
header('HTTP/1.1 401 Unauthorized');
$result = "failed";
}
echo json_encode(array('status' => $result));