/
lists.php
268 lines (248 loc) · 9.96 KB
/
lists.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
* Common functions to manage lists in PHPlist
*/
class PHPlist_API_Lists{
/**
* <p>Gets all lists in PHPlist as an array.</p>
* <p><strong>Parameters:</strong><br/>
* (none)
* <p><strong>Returns:</strong><br/>
* Array of lists.
* </p>
*/
static function listsGet() {
PHPlist_API_Common::select( 'Lists', "SELECT * FROM " . $GLOBALS['table_prefix'] . "list ORDER BY listorder;" );
}
/**
* <p>Gets one (1) list.</p>
* <p><strong>Parameters:</strong><br/>
* [*id] {integer} the ID of the list.
* <p><strong>Returns:</strong><br/>
* One list.
* </p>
*/
static function listGet( $id=0 ) {
if ( $id==0 ) $id = $_REQUEST['id'];
PHPlist_API_Common::select( 'List', "SELECT * FROM " . $GLOBALS['table_prefix'] . "list WHERE id = $id;", true );
}
/**
* <p>Adds a new list.</p>
* <p><strong>Parameters:</strong><br/>
* [*name] {string} the name of the list.<br/>
* [description] {string} adds a description to the list.<br/>
* [listorder] {integer} an expression to sortorder, eg 100.<br/>
* [prefix] {string} adds a prefix to the list (?).<br/>
* [rssfeed] {string} the url to the feed for this list (?).<br/>
* [active] {integer} if list should be active set this one to 1, otherwise it will be disabled.<br/>
* <p><strong>Returns:</strong><br/>
* The list added.
* </p>
*/
static function listAdd(){
$sql = "INSERT INTO " . $GLOBALS['table_prefix'] . "list (name, description, listorder, prefix, rssfeed, active) VALUES (:name, :description, :listorder, :prefix, :rssfeed, :active);";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("name", $_REQUEST['name']);
$stmt->bindParam("description", $_REQUEST['description']);
$stmt->bindParam("listorder", $_REQUEST['listorder']);
$stmt->bindParam("prefix", $_REQUEST['prefix']);
$stmt->bindParam("rssfeed", $_REQUEST['rssfeed']);
$stmt->bindParam("active", $_REQUEST['active']);
$stmt->execute();
$id = $db->lastInsertId();
$db = null;
PHPlist_API_Lists::listGet( $id );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>Updates existing list.</p>
* <p><strong>Parameters:</strong><br/>
* [*id] {integer} the ID of the list.<br/>
* [*name] {string} the name of the list.<br/>
* [description] {string} adds a description to the list.<br/>
* [listorder] {integer} an expression to sortorder, eg 100.<br/>
* [prefix] {string} adds a prefix to the list (?).<br/>
* [rssfeed] {string} the url to the feed for this list (?).<br/>
* [active] {integer} if list should be active set this one to 1, otherwise it will be disabled.<br/>
* <p><strong>Returns:</strong><br/>
* The list updated.
* </p>
*/
static function listUpdate(){
$sql = "UPDATE " . $GLOBALS['table_prefix'] . "list SET name=:name, description=:description, listorder=:listorder, prefix=:prefix, rssfeed=:rssfeed, active=:active WHERE id=:id;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $_REQUEST['id']);
$stmt->bindParam("name", $_REQUEST['name'] );
$stmt->bindParam("description", $_REQUEST['description'] );
$stmt->bindParam("listorder", $_REQUEST['listorder'] );
$stmt->bindParam("prefix", $_REQUEST['prefix'] );
$stmt->bindParam("rssfeed", $_REQUEST['rssfeed'] );
$stmt->bindParam("active", $_REQUEST['active'] );
$stmt->execute();
$db = null;
PHPlist_API_Lists::listGet( $_REQUEST['id'] );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>Deletes a list.</p>
* <p><strong>Parameters:</strong><br/>
* [*id] {integer} the ID of the list.
* <p><strong>Returns:</strong><br/>
* System message of action.
* </p>
*/
static function listDelete(){
$sql = "DELETE FROM " . $GLOBALS['table_prefix'] . "list WHERE id=:id;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("id", $_REQUEST['id']);
$stmt->execute();
$db = null;
PHPlist_API_Response::outputDeleted( 'List', $_REQUEST['id'] );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>Lists assigned to User.</p>
* <p><strong>Parameters:</strong><br/>
* [*user_id] {integer} the User-ID.
* <p><strong>Returns:</strong><br/>
* Array of lists where the user is assigned to.
* </p>
*/
static function listsUser( $user_id=0 ) {
$response = new PHPlist_API_Response();
if ( $user_id==0 ) $user_id = $_REQUEST['user_id'];
$sql = "SELECT * FROM " . $GLOBALS['table_prefix'] . "list WHERE id IN (SELECT listid FROM " . $GLOBALS['table_prefix'] . "listuser WHERE userid=" . $user_id . ") ORDER BY listorder;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
$response->setData('Lists', $result);
$response->output();
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>Adds a user to a list.</p>
* <p>The user then subscribes to the list.</p>
* <p><strong>Parameters:</strong><br/>
* [*list_id] {integer} the ID of the list.<br/>
* [*user_id] {integer} the ID of the user.<br/>
* <p><strong>Returns:</strong><br/>
* Array of lists where the user is assigned to.
* </p>
*/
static function listUserAdd( $list_id=0, $user_id=0 ){
if ( $list_id==0 ) $list_id = $_REQUEST['list_id'];
if ( $user_id==0 ) $user_id = $_REQUEST['user_id'];
$sql = "INSERT INTO " . $GLOBALS['table_prefix'] . "listuser (userid, listid, entered) VALUES (:user_id, :list_id, now());";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("user_id", $user_id );
$stmt->bindParam("list_id", $list_id );
$stmt->execute();
$db = null;
PHPlist_API_Lists::listsUser( $user_id );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>UnassignsAdds a user to a list.</p>
* <p><strong>Parameters:</strong><br/>
* [*list_id] {integer} the ID of the list.<br/>
* [*user_id] {integer} the ID of the user.
* <p><strong>Returns:</strong><br/>
* System message of action.
* </p>
*/
static function listUserDelete( $list_id=0, $user_id=0 ){
if ( $list_id==0 ) $list_id = $_REQUEST['list_id'];
if ( $user_id==0 ) $user_id = $_REQUEST['user_id'];
$sql = "DELETE FROM " . $GLOBALS['table_prefix'] . "listuser WHERE listid=:list_id AND userid=:user_id;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("user_id", $user_id );
$stmt->bindParam("list_id", $list_id );
$stmt->execute();
$db = null;
PHPlist_API_Response::outputMessage( 'User ' . $user_id . ' is unassigned from list ' . $list_id );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>Assigns a list to a message.</p>
* <p><strong>Parameters:</strong><br/>
* [*list_id] {integer} the ID of the list.<br/>
* [*message_id] {integer} the ID of the message.
* <p><strong>Returns:</strong><br/>
* The list assigned.
* </p>
*/
static function listMessageAdd( $list_id=0, $message_id=0 ){
if ( $list_id==0 ) $list_id = $_REQUEST['list_id'];
if ( $message_id==0 ) $message_id = $_REQUEST['message_id'];
$sql = "INSERT INTO " . $GLOBALS['table_prefix'] . "listmessage (messageid, listid, entered) VALUES (:message_id, :list_id, now());";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("message_id", $message_id );
$stmt->bindParam("list_id", $list_id );
$stmt->execute();
$db = null;
PHPlist_API_Lists::listGet( $list_id );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
/**
* <p>Unassigns a list from a message.</p>
* <p><strong>Parameters:</strong><br/>
* [*list_id] {integer} the ID of the list.<br/>
* [*message_id] {integer} the ID of the message.
* <p><strong>Returns:</strong><br/>
* System message of action.
* </p>
*/
static function listMessageDelete( $list_id=0, $message_id=0 ){
if ( $list_id==0 ) $list_id = $_REQUEST['list_id'];
if ( $message_id==0 ) $message_id = $_REQUEST['message_id'];
$sql = "DELETE FROM " . $GLOBALS['table_prefix'] . "listmessage WHERE listid=:list_id AND messageid=:message_id;";
try {
$db = PHPlist_API_PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam("message_id", $message_id );
$stmt->bindParam("list_id", $list_id );
$stmt->execute();
$db = null;
PHPlist_API_Response::outputMessage( 'Message ' . $message_id . ' is unassigned from list ' . $list_id );
} catch(PDOException $e) {
PHPlist_API_Response::outputError($e);
}
die(0);
}
}
?>