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 pathajaxdesk.php
157 lines (122 loc) · 4.91 KB
/
ajaxdesk.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
<?php
include_once 'data.php';
include_once 'functions.php';
if (isset($_GET['file']) && isset($_GET['project']) && isset($_SESSION['auth'])) {
database_connect(IL_DATABASE_PATH, 'library');
$id_query = $dbHandle->quote($_GET['project']);
$file_query = $dbHandle->quote($_GET['file']);
$dbHandle->beginTransaction();
$result = $dbHandle->query("SELECT rowid FROM projectsfiles WHERE projectID=$id_query AND fileID=$file_query LIMIT 1");
$rowid = $result->fetchColumn();
$result = null;
if (empty($rowid)) {
$result = $dbHandle->query("SELECT count(*) from projectsfiles WHERE projectID=" . $id_query);
$count = $result->fetchColumn();
$result = null;
if ($count >= 100000) {
$dbHandle->rollBack();
echo 'Error! Desk project can hold up to 100,000 items.';
die();
}
$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 projectsfiles (projectID,fileID) VALUES ($id_query,$file_query)");
if ($update)
echo 'added';
} else {
$dbHandle->rollBack();
echo 'Error! This item does not exist anymore.';
}
} else {
$update = $dbHandle->exec("DELETE FROM projectsfiles WHERE rowid=$rowid");
if ($update)
echo 'removed';
}
$dbHandle->commit();
$dbHandle = null;
die();
}
if (isset($_GET['adduser']) && isset($_GET['userID']) && isset($_GET['projectID'])) {
database_connect(IL_USER_DATABASE_PATH, 'users');
$user_query = $dbHandle->quote($_GET['userID']);
$result = $dbHandle->query("SELECT count(*) FROM users WHERE userID=$user_query");
$exists = $result->fetchColumn();
$dbHandle = null;
if ($exists == 1) {
database_connect(IL_DATABASE_PATH, 'library');
$user_query = $dbHandle->quote($_GET['userID']);
$project_query = $dbHandle->quote($_GET['projectID']);
$dbHandle->exec("INSERT INTO projectsusers (projectID,userID) VALUES ($project_query,$user_query)");
$dbHandle = null;
echo 'done';
} else {
echo 'Error! This user does not exists.';
}
die();
}
if (isset($_GET['removeuser']) && isset($_GET['userID']) && isset($_GET['projectID'])) {
database_connect(IL_DATABASE_PATH, 'library');
$user_query = $dbHandle->quote($_GET['userID']);
$project_query = $dbHandle->quote($_GET['projectID']);
$dbHandle->exec("DELETE FROM projectsusers WHERE projectID=$project_query AND userID=$user_query");
$dbHandle = null;
echo 'done';
die();
}
if (isset($_GET['create']) && !empty($_GET['project'])) {
database_connect(IL_DATABASE_PATH, 'library');
$stmt = $dbHandle->prepare("INSERT INTO projects (userID, project, active) VALUES (:userID, :project, :active)");
$stmt->bindParam(':userID', $userID);
$stmt->bindParam(':project', $project);
$stmt->bindParam(':active', $active);
$userID = $_SESSION['user_id'];
$project = $_GET['project'];
$active = '1';
$insert = $stmt->execute();
$dbHandle = null;
echo 'done';
die();
}
if (isset($_GET['rename']) && !empty($_GET['project']) && isset($_GET['id'])) {
database_connect(IL_DATABASE_PATH, 'library');
$id_query = $dbHandle->quote($_GET['id']);
$query = $dbHandle->quote($_GET['project']);
$dbHandle->exec("UPDATE projects SET project=$query WHERE projectID=$id_query");
$dbHandle = null;
echo 'done';
die();
}
if (isset($_GET['delete']) && isset($_GET['id'])) {
database_connect(IL_DATABASE_PATH, 'library');
$query = $dbHandle->quote($_GET['id']);
$dbHandle->beginTransaction();
$dbHandle->exec("DELETE FROM projects WHERE projectID=$query");
$dbHandle->exec("DELETE FROM projectsfiles WHERE projectID=$query");
$dbHandle->exec("DELETE FROM projectsusers WHERE projectID=$query");
$dbHandle->commit();
$dbHandle = null;
if (is_writable(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'project' . intval($_GET['id']) . '.sq3'))
unlink(IL_DATABASE_PATH . DIRECTORY_SEPARATOR . 'project' . intval($_GET['id']) . '.sq3');
echo 'done';
die();
}
if (isset($_GET['empty']) && isset($_GET['id'])) {
database_connect(IL_DATABASE_PATH, 'library');
$query = $dbHandle->quote($_GET['id']);
$dbHandle->exec("DELETE FROM projectsfiles WHERE projectID=$query");
$dbHandle = null;
echo 'done';
die();
}
if (isset($_GET['active']) && isset($_GET['projectID'])) {
database_connect(IL_DATABASE_PATH, 'library');
$id_query = $dbHandle->quote($_GET['projectID']);
$active_query = $dbHandle->quote($_GET['active']);
$dbHandle->exec("UPDATE projects SET active=" . $active_query . " WHERE projectID=" . $id_query);
$dbHandle = null;
echo 'done';
die();
}
?>