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 pathflagged.php
73 lines (60 loc) · 2.15 KB
/
flagged.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
<?php
include_once 'data.php';
include_once 'functions.php';
if (!empty($_GET['database'])) {
$database = $_GET['database'];
$allowed_databases = array('pubmed', 'pmc', 'nasaads', 'arxiv');
if (!in_array($database, $allowed_databases))
die();
} else {
die();
}
if (!empty($_SESSION['user_id'])) {
$user_id = intval($_SESSION['user_id']);
} else {
die();
}
// CLEAN DOWNLOAD CACHE
$clean_files = glob(IL_TEMP_PATH . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'page_*_download', GLOB_NOSORT);
if (is_array($clean_files)) {
foreach ($clean_files as $clean_file) {
if (is_file($clean_file) && is_writable($clean_file))
@unlink($clean_file);
}
}
database_connect(IL_DATABASE_PATH, 'library');
if (!empty($_GET['empty'])) {
$dbHandle->exec("DELETE FROM flagged WHERE userID=" . $user_id . " AND database='" . $database . "'");
die();
}
if (!empty($_GET['uid'])) {
$uid_query = $dbHandle->quote($_GET['uid']);
$result = $dbHandle->query("SELECT id FROM flagged WHERE userID=" . $user_id . " AND database='" . $database . "' AND uid=" . $uid_query . " LIMIT 1");
$relation = $result->fetchColumn();
$result = null;
if (!$relation) {
//HOW MANY FLAGGED?
$result = $dbHandle->query("SELECT count(*) FROM flagged WHERE userID=" . $user_id . " AND database='" . $database . "'");
$flagged_count = $result->fetchColumn();
$result = null;
//FLAG IF < 100
if ($flagged_count > 99)
die();
$update = $dbHandle->exec("INSERT OR IGNORE INTO flagged (userID,database,uid) VALUES ($user_id,'" . $database . "',$uid_query)");
if ($update)
echo 'added';
} else {
//UNFLAG
$update = $dbHandle->exec("DELETE FROM flagged WHERE id=$relation");
if ($update)
echo 'removed';
}
} else {
//RETURN FLAGGED AS JSON
$result = $dbHandle->query("SELECT uid FROM flagged WHERE userID=" . $user_id . " AND database='" . $database . "'");
$uid_list = $result->fetchAll(PDO::FETCH_COLUMN);
$result = null;
print json_encode($uid_list);
}
$dbHandle = null;
?>