]>
Commit | Line | Data |
---|---|---|
1cd17194 | 1 | <? |
090e250b AD |
2 | $op = $_GET["op"]; |
3 | ||
4 | if ($op == "rpc") { | |
5 | header("Content-Type: application/xml"); | |
6 | } | |
1cd17194 | 7 | |
82baad4a | 8 | require_once "config.php"; |
648472a7 | 9 | require_once "db.php"; |
82baad4a AD |
10 | require_once "functions.php"; |
11 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 12 | |
648472a7 | 13 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
d76a3b03 | 14 | |
648472a7 AD |
15 | if (DB_TYPE == "pgsql") { |
16 | pg_query("set client_encoding = 'utf-8'"); | |
17 | } | |
090e250b | 18 | |
331900c6 | 19 | $fetch = $_GET["fetch"]; |
175847de | 20 | |
8143ae1f AD |
21 | /* FIXME this needs reworking */ |
22 | ||
23 | function getTagCounters($link) { | |
24 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
25 | FROM ttrss_tags,ttrss_entries WHERE | |
26 | post_id = ttrss_entries.id AND unread = true GROUP BY tag_name | |
27 | UNION | |
28 | select tag_name,0 as count FROM ttrss_tags"); | |
29 | ||
30 | $tags = array(); | |
31 | ||
32 | while ($line = db_fetch_assoc($result)) { | |
33 | $tags[$line["tag_name"]] += $line["count"]; | |
34 | } | |
35 | ||
36 | foreach (array_keys($tags) as $tag) { | |
37 | $unread = $tags[$tag]; | |
38 | ||
39 | $tag = htmlspecialchars($tag); | |
40 | print "<tag id=\"$tag\" counter=\"$unread\"/>"; | |
41 | } | |
42 | } | |
43 | ||
090e250b AD |
44 | function getLabelCounters($link) { |
45 | ||
46 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
8073cce7 | 47 | WHERE marked = true AND unread = true"); |
090e250b | 48 | |
d61fd764 | 49 | $count = db_fetch_result($result, 0, "count"); |
090e250b AD |
50 | |
51 | print "<label id=\"-1\" counter=\"$count\"/>"; | |
52 | ||
53 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
54 | ttrss_labels ORDER by description"); | |
55 | ||
56 | while ($line = db_fetch_assoc($result)) { | |
57 | ||
58 | $id = -$line["id"] - 11; | |
59 | ||
60 | error_reporting (0); | |
d61fd764 AD |
61 | |
62 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
392d4563 | 63 | WHERE (" . $line["sql_exp"] . ") AND unread = true"); |
090e250b | 64 | |
d61fd764 | 65 | $count = db_fetch_result($tmp_result, 0, "count"); |
090e250b AD |
66 | |
67 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
68 | ||
69 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
70 | ||
71 | } | |
72 | } | |
73 | ||
8073cce7 AD |
74 | function getFeedCounter($link, $id) { |
75 | ||
76 | $result = db_query($link, "SELECT | |
77 | count(id) as count FROM ttrss_entries | |
78 | WHERE feed_id = '$id' AND unread = true"); | |
79 | ||
80 | $count = db_fetch_result($result, 0, "count"); | |
81 | ||
82 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
83 | } | |
090e250b | 84 | |
8073cce7 AD |
85 | function getFeedCounters($link) { |
86 | ||
090e250b AD |
87 | $result = db_query($link, "SELECT id, |
88 | (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id | |
89 | AND unread = true) as count | |
90 | FROM ttrss_feeds"); | |
91 | ||
92 | while ($line = db_fetch_assoc($result)) { | |
93 | ||
94 | $id = $line["id"]; | |
95 | $count = $line["count"]; | |
96 | ||
97 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
98 | } | |
99 | } | |
100 | ||
8143ae1f | 101 | function outputFeedList($link, $tags = false) { |
175847de | 102 | |
1a66d16e AD |
103 | print "<html><head> |
104 | <title>Tiny Tiny RSS : Feedlist</title> | |
105 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
106 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
107 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> | |
108 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
109 | </head><body>"; | |
254e0e4b AD |
110 | |
111 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
112 | ||
8143ae1f | 113 | if (!$tags) { |
254e0e4b | 114 | |
8143ae1f | 115 | /* virtual feeds */ |
254e0e4b | 116 | |
8143ae1f AD |
117 | $result = db_query($link, "SELECT count(id) as num_starred |
118 | FROM ttrss_entries WHERE marked = true AND unread = true"); | |
119 | $num_starred = db_fetch_result($result, 0, "num_starred"); | |
254e0e4b | 120 | |
8add756a AD |
121 | $class = "odd"; |
122 | ||
123 | if ($num_starred > 0) $class .= "Unread"; | |
124 | ||
125 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
8143ae1f | 126 | "images/mark_set.png"); |
48f0adb0 | 127 | |
8143ae1f AD |
128 | if (ENABLE_LABELS) { |
129 | ||
130 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
131 | ttrss_labels ORDER by description"); | |
132 | ||
133 | if (db_num_rows($result) > 0) { | |
134 | print "<li><hr></li>"; | |
135 | } | |
136 | ||
137 | while ($line = db_fetch_assoc($result)) { | |
48f0adb0 | 138 | |
8143ae1f AD |
139 | error_reporting (0); |
140 | ||
141 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
142 | WHERE (" . $line["sql_exp"] . ") AND unread = true"); | |
143 | ||
144 | $count = db_fetch_result($tmp_result, 0, "count"); | |
145 | ||
146 | $class = "odd"; | |
147 | ||
148 | if ($count > 0) { | |
149 | $class .= "Unread"; | |
150 | } | |
151 | ||
152 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
153 | ||
154 | printFeedEntry(-$line["id"]-11, | |
155 | $class, $line["description"], $count, "images/label.png"); | |
156 | ||
157 | } | |
48f0adb0 AD |
158 | } |
159 | ||
8143ae1f AD |
160 | print "<li><hr></li>"; |
161 | ||
162 | $result = db_query($link, "SELECT *, | |
163 | (SELECT count(id) FROM ttrss_entries | |
164 | WHERE feed_id = ttrss_feeds.id) AS total, | |
165 | (SELECT count(id) FROM ttrss_entries | |
166 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
167 | FROM ttrss_feeds ORDER BY title"); | |
168 | ||
169 | $actid = $_GET["actid"]; | |
170 | ||
171 | /* real feeds */ | |
172 | ||
173 | $lnum = 0; | |
174 | ||
175 | $total_unread = 0; | |
176 | ||
48f0adb0 | 177 | while ($line = db_fetch_assoc($result)) { |
8143ae1f AD |
178 | |
179 | $feed = $line["title"]; | |
180 | $feed_id = $line["id"]; | |
181 | ||
182 | $subop = $_GET["subop"]; | |
183 | ||
184 | $total = $line["total"]; | |
185 | $unread = $line["unread"]; | |
186 | ||
187 | // $class = ($lnum % 2) ? "even" : "odd"; | |
48f0adb0 | 188 | |
392d4563 | 189 | $class = "odd"; |
8143ae1f AD |
190 | |
191 | if ($unread > 0) $class .= "Unread"; | |
192 | ||
193 | if ($actid == $feed_id) { | |
194 | $class .= "Selected"; | |
392d4563 | 195 | } |
48f0adb0 | 196 | |
8143ae1f AD |
197 | $total_unread += $unread; |
198 | ||
199 | printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico"); | |
200 | ||
201 | ++$lnum; | |
48f0adb0 | 202 | } |
8143ae1f | 203 | } else { |
a1a8a2be | 204 | |
8143ae1f | 205 | // tags |
a1a8a2be | 206 | |
8143ae1f AD |
207 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
208 | FROM ttrss_tags,ttrss_entries WHERE | |
209 | post_id = ttrss_entries.id AND unread = true GROUP BY tag_name | |
210 | UNION | |
211 | select tag_name,0 as count FROM ttrss_tags"); | |
212 | ||
213 | $tags = array(); | |
214 | ||
215 | while ($line = db_fetch_assoc($result)) { | |
216 | $tags[$line["tag_name"]] += $line["count"]; | |
1a66d16e | 217 | } |
8143ae1f AD |
218 | |
219 | foreach (array_keys($tags) as $tag) { | |
220 | ||
221 | $unread = $tags[$tag]; | |
222 | ||
223 | $class = "odd"; | |
224 | ||
225 | if ($unread > 0) { | |
226 | $class .= "Unread"; | |
227 | } | |
228 | ||
229 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png"); | |
230 | ||
231 | } | |
1a66d16e | 232 | |
e828e31e | 233 | } |
82baad4a | 234 | |
8143ae1f | 235 | print "</ul>"; |
1cd17194 | 236 | |
caa4e57f AD |
237 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
238 | ||
c3b81db0 AD |
239 | } |
240 | ||
241 | ||
242 | if ($op == "rpc") { | |
243 | ||
244 | $subop = $_GET["subop"]; | |
245 | ||
090e250b | 246 | if ($subop == "getLabelCounters") { |
8073cce7 | 247 | $aid = $_GET["aid"]; |
090e250b AD |
248 | print "<rpc-reply>"; |
249 | getLabelCounters($link); | |
8073cce7 AD |
250 | if ($aid) { |
251 | getFeedCounter($link, $aid); | |
252 | } | |
090e250b AD |
253 | print "</rpc-reply>"; |
254 | } | |
255 | ||
256 | if ($subop == "getFeedCounters") { | |
257 | print "<rpc-reply>"; | |
258 | getFeedCounters($link); | |
259 | print "</rpc-reply>"; | |
260 | } | |
261 | ||
262 | if ($subop == "getAllCounters") { | |
263 | print "<rpc-reply>"; | |
264 | getLabelCounters($link); | |
265 | getFeedCounters($link); | |
8143ae1f | 266 | getTagCounters($link); |
090e250b AD |
267 | print "</rpc-reply>"; |
268 | ||
269 | } | |
270 | ||
f4c10d44 AD |
271 | if ($subop == "mark") { |
272 | $mark = $_GET["mark"]; | |
648472a7 | 273 | $id = db_escape_string($_GET["id"]); |
f4c10d44 AD |
274 | |
275 | if ($mark == "1") { | |
276 | $mark = "true"; | |
277 | } else { | |
278 | $mark = "false"; | |
279 | } | |
280 | ||
648472a7 | 281 | $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark |
f4c10d44 AD |
282 | WHERE id = '$id'"); |
283 | } | |
284 | ||
caa4e57f | 285 | if ($subop == "updateFeed") { |
648472a7 | 286 | $feed_id = db_escape_string($_GET["feed"]); |
9cfc649a | 287 | |
648472a7 | 288 | $result = db_query($link, |
caa4e57f | 289 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'"); |
9cfc649a | 290 | |
648472a7 AD |
291 | if (db_num_rows($result) > 0) { |
292 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
caa4e57f AD |
293 | // update_rss_feed($link, $feed_url, $feed_id); |
294 | } | |
9cfc649a | 295 | |
caa4e57f | 296 | print "DONE-$feed_id"; |
9cfc649a | 297 | |
caa4e57f | 298 | return; |
9cfc649a AD |
299 | } |
300 | ||
090e250b | 301 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { |
c3b81db0 | 302 | update_all_feeds($link, true); |
c3b81db0 | 303 | |
090e250b AD |
304 | print "<rpc-reply>"; |
305 | getLabelCounters($link); | |
306 | getFeedCounters($link); | |
8143ae1f | 307 | getTagCounters($link); |
090e250b | 308 | print "</rpc-reply>"; |
c3b81db0 AD |
309 | } |
310 | ||
311 | if ($subop == "catchupPage") { | |
312 | ||
313 | $ids = split(",", $_GET["ids"]); | |
314 | ||
315 | foreach ($ids as $id) { | |
316 | ||
648472a7 | 317 | db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW() |
c3b81db0 AD |
318 | WHERE id = '$id'"); |
319 | ||
320 | } | |
321 | ||
322 | print "Marked active page as read."; | |
323 | } | |
c3b81db0 AD |
324 | } |
325 | ||
326 | if ($op == "feeds") { | |
327 | ||
8143ae1f AD |
328 | $tags = $_GET["tags"]; |
329 | ||
c3b81db0 AD |
330 | $subop = $_GET["subop"]; |
331 | ||
332 | if ($subop == "catchupAll") { | |
648472a7 | 333 | db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); |
c3b81db0 AD |
334 | } |
335 | ||
8143ae1f | 336 | outputFeedList($link, $tags); |
c3b81db0 | 337 | |
1cd17194 AD |
338 | } |
339 | ||
340 | if ($op == "view") { | |
341 | ||
d76a3b03 | 342 | $id = $_GET["id"]; |
8073cce7 | 343 | $feed_id = $_GET["feed"]; |
d76a3b03 | 344 | |
648472a7 | 345 | $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); |
a1a8a2be | 346 | |
70830c87 AD |
347 | $addheader = $_GET["addheader"]; |
348 | ||
648472a7 | 349 | $result = db_query($link, "SELECT title,link,content,feed_id,comments, |
b7f4bda2 AD |
350 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url |
351 | FROM ttrss_entries | |
d76a3b03 | 352 | WHERE id = '$id'"); |
1cd17194 | 353 | |
70830c87 | 354 | if ($addheader) { |
f0601b87 | 355 | print "<html><head> |
70830c87 AD |
356 | <title>Tiny Tiny RSS : Article $id</title> |
357 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 358 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 359 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 360 | </head><body>"; |
70830c87 AD |
361 | } |
362 | ||
d76a3b03 | 363 | if ($result) { |
1cd17194 | 364 | |
648472a7 | 365 | $line = db_fetch_assoc($result); |
1cd17194 | 366 | |
b7f4bda2 AD |
367 | if ($line["icon_url"]) { |
368 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
369 | } else { | |
370 | $feed_icon = " "; | |
371 | } | |
d76a3b03 | 372 | |
f7181e9b AD |
373 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
374 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
375 | } else { | |
376 | $entry_comments = ""; | |
377 | } | |
378 | ||
e828e31e AD |
379 | print "<div class=\"postReply\">"; |
380 | ||
381 | print "<div class=\"postHeader\"><table>"; | |
382 | ||
383 | print "<tr><td><b>Title:</b></td> | |
384 | <td width='100%'>" . $line["title"] . "</td></tr>"; | |
f7181e9b | 385 | |
e828e31e | 386 | print "<tr><td><b>Link:</b></td> |
f7181e9b AD |
387 | <td width='100%'> |
388 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> | |
389 | $entry_comments</td></tr>"; | |
e828e31e AD |
390 | |
391 | print "</table></div>"; | |
392 | ||
393 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
394 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
395 | ||
396 | print "</div>"; | |
397 | ||
090e250b | 398 | print "<script type=\"text/javascript\"> |
8143ae1f | 399 | update_label_counters('$feed_id'); |
090e250b | 400 | </script>"; |
d76a3b03 | 401 | } |
70830c87 AD |
402 | |
403 | if ($addheader) { | |
404 | print "</body></html>"; | |
405 | } | |
1cd17194 AD |
406 | } |
407 | ||
408 | if ($op == "viewfeed") { | |
409 | ||
410 | $feed = $_GET["feed"]; | |
d76a3b03 | 411 | $skip = $_GET["skip"]; |
476cac42 | 412 | $subop = $_GET["subop"]; |
f175937c | 413 | $view_mode = $_GET["view"]; |
f0601b87 | 414 | $addheader = $_GET["addheader"]; |
cb1083a1 | 415 | $limit = $_GET["limit"]; |
a1a8a2be | 416 | |
8d7008c7 AD |
417 | if (!$feed) { |
418 | print "Error: no feed to display."; | |
419 | return; | |
420 | } | |
421 | ||
ac53063a AD |
422 | if (!$skip) $skip = 0; |
423 | ||
476cac42 | 424 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 425 | |
f0601b87 AD |
426 | if ($addheader) { |
427 | print "<html><head> | |
ac43eba1 | 428 | <title>Tiny Tiny RSS : Feed $feed</title> |
f0601b87 AD |
429 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> |
430 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
431 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
432 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
433 | </head><body>"; | |
434 | } | |
435 | ||
8143ae1f | 436 | if (sprintf("%d", $feed) != 0 && $feed >= 0) { |
d76a3b03 | 437 | |
254e0e4b AD |
438 | $result = db_query($link, |
439 | "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s | |
440 | FROM ttrss_feeds WHERE id = '$feed'"); | |
441 | ||
442 | if ($result) { | |
443 | ||
444 | $line = db_fetch_assoc($result); | |
445 | ||
446 | update_rss_feed($link, $line["feed_url"], $feed); | |
447 | ||
448 | if ($subop == "MarkAllRead") { | |
449 | ||
450 | db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() | |
451 | WHERE feed_id = '$feed'"); | |
452 | } | |
a1a8a2be AD |
453 | } |
454 | } | |
d76a3b03 | 455 | |
175847de | 456 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 457 | |
c374a3fe AD |
458 | $search = $_GET["search"]; |
459 | ||
f175937c | 460 | if ($search) { |
ac53063a AD |
461 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
462 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
463 | } else { |
464 | $search_query_part = ""; | |
465 | } | |
466 | ||
467 | $view_query_part = ""; | |
468 | ||
469 | if ($view_mode == "Starred") { | |
470 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
471 | } |
472 | ||
ac43eba1 AD |
473 | if ($view_mode == "Unread") { |
474 | $view_query_part = " unread = true AND "; | |
475 | } | |
476 | ||
254e0e4b | 477 | /* $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
478 | FROM ttrss_entries WHERE |
479 | $search_query_part | |
480 | feed_id = '$feed'"); | |
e6d1c0a0 | 481 | |
254e0e4b | 482 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ |
e6d1c0a0 | 483 | |
648472a7 | 484 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
485 | FROM ttrss_entries WHERE |
486 | $search_query_part | |
487 | unread = true AND | |
488 | feed_id = '$feed'"); | |
489 | ||
648472a7 | 490 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 491 | |
8d7008c7 | 492 | if ($limit && $limit != "All") { |
82c9223c | 493 | $limit_query_part = "LIMIT " . $limit; |
ad3cb710 | 494 | } |
f0601b87 | 495 | |
254e0e4b AD |
496 | $vfeed_query_part = ""; |
497 | ||
8143ae1f AD |
498 | if (sprintf("%d", $feed) == 0) { |
499 | $query_strategy_part = "ttrss_entries.id > 0"; | |
500 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
501 | id = feed_id) as feed_title,"; | |
502 | } else if ($feed >= 0) { | |
254e0e4b | 503 | $query_strategy_part = "feed_id = '$feed'"; |
48f0adb0 | 504 | } else if ($feed == -1) { // starred virtual feed |
254e0e4b | 505 | $query_strategy_part = "marked = true"; |
48f0adb0 AD |
506 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
507 | id = feed_id) as feed_title,"; | |
508 | } else if ($feed <= -10) { // labels | |
509 | $label_id = -$feed - 11; | |
510 | ||
511 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
512 | WHERE id = '$label_id'"); | |
513 | ||
514 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
515 | ||
254e0e4b AD |
516 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
517 | id = feed_id) as feed_title,"; | |
518 | } else { | |
48f0adb0 | 519 | $query_strategy_part = "id > 0"; // dumb |
254e0e4b AD |
520 | } |
521 | ||
f99321a3 AD |
522 | $order_by = "updated DESC"; |
523 | ||
524 | // if ($feed < -10) { | |
525 | // $order_by = "feed_id,updated DESC"; | |
526 | // } | |
527 | ||
48f0adb0 AD |
528 | if ($feed < -10) error_reporting (0); |
529 | ||
8143ae1f AD |
530 | if (sprintf("%d", $feed) != 0) { |
531 | ||
532 | $result = db_query($link, "SELECT | |
533 | id,title,updated,unread,feed_id,marked,link,last_read, | |
534 | SUBSTRING(last_read,1,19) as last_read_noms, | |
535 | $vfeed_query_part | |
536 | SUBSTRING(updated,1,19) as updated_noms | |
537 | FROM | |
538 | ttrss_entries | |
539 | WHERE | |
540 | $search_query_part | |
541 | $view_query_part | |
542 | $query_strategy_part ORDER BY $order_by | |
543 | $limit_query_part"); | |
544 | ||
545 | } else { | |
546 | // browsing by tag | |
547 | ||
548 | $result = db_query($link, "SELECT | |
549 | ttrss_entries.id as id,title,updated,unread,feed_id, | |
550 | marked,link,last_read, | |
c05a19f3 | 551 | SUBSTRING(last_read,1,19) as last_read_noms, |
254e0e4b | 552 | $vfeed_query_part |
c05a19f3 | 553 | SUBSTRING(updated,1,19) as updated_noms |
8143ae1f AD |
554 | FROM |
555 | ttrss_entries,ttrss_tags | |
556 | WHERE | |
557 | post_id = ttrss_entries.id AND tag_name = '$feed' AND | |
558 | $view_query_part | |
559 | $search_query_part | |
560 | $query_strategy_part ORDER BY $order_by | |
561 | $limit_query_part"); | |
562 | } | |
d76a3b03 | 563 | |
48f0adb0 AD |
564 | if (!$result) { |
565 | print "<tr><td colspan='4' align='center'> | |
566 | Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; | |
567 | return; | |
568 | } | |
569 | ||
a1a8a2be | 570 | $lnum = 0; |
48f0adb0 AD |
571 | |
572 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
573 | ||
e1123aee | 574 | $num_unread = 0; |
d76a3b03 | 575 | |
648472a7 | 576 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 577 | |
a1a8a2be | 578 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 579 | |
ad99045e AD |
580 | $id = $line["id"]; |
581 | $feed_id = $line["feed_id"]; | |
582 | ||
c43f77f5 | 583 | // printf("L %d (%s) > U %d (%s) = %d<br>", |
c05a19f3 | 584 | // strtotime($line["last_read_noms"]), $line["last_read_noms"], |
c43f77f5 AD |
585 | // strtotime($line["updated"]), $line["updated"], |
586 | // strtotime($line["last_read"]) >= strtotime($line["updated"])); | |
587 | ||
588 | if ($line["last_read"] != "" && $line["updated"] != "" && | |
c05a19f3 | 589 | strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) { |
c43f77f5 AD |
590 | |
591 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
592 | alt=\"Updated\">"; | |
593 | ||
594 | } else { | |
595 | ||
5bfef089 | 596 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" |
c43f77f5 AD |
597 | alt=\"Updated\">"; |
598 | ||
599 | } | |
b197f117 | 600 | |
8158c57a | 601 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 602 | $class .= "Unread"; |
e1123aee AD |
603 | ++$num_unread; |
604 | } | |
d76a3b03 | 605 | |
8158c57a | 606 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
607 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
608 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
609 | } else { | |
610 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
611 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
612 | } | |
613 | ||
ac43eba1 | 614 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
615 | $line["title"] . "</a>"; |
616 | ||
d5224f0d | 617 | print "<tr class='$class' id='RROW-$id'>"; |
5f89f780 | 618 | // onclick=\"javascript:view($id,$feed_id)\"> |
b197f117 | 619 | |
8d7008c7 AD |
620 | print "<td valign='center' align='center'>$update_pic</td>"; |
621 | print "<td valign='center' align='center'>$marked_pic</td>"; | |
b197f117 | 622 | |
8d7008c7 | 623 | print "<td width='25%'> |
a3ee2a38 | 624 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
254e0e4b AD |
625 | |
626 | if ($line["feed_title"]) { | |
627 | print "<td width='50%'>$content_link</td>"; | |
628 | print "<td width='20%'>".$line["feed_title"]."</td>"; | |
629 | } else { | |
630 | print "<td width='70%'>$content_link</td>"; | |
631 | } | |
d76a3b03 | 632 | |
a1a8a2be | 633 | print "</tr>"; |
d76a3b03 | 634 | |
a1a8a2be AD |
635 | ++$lnum; |
636 | } | |
d76a3b03 | 637 | |
ac53063a | 638 | if ($lnum == 0) { |
a82065a1 | 639 | print "<tr><td align='center'>No articles found.</td></tr>"; |
047bae73 | 640 | } |
a2015351 | 641 | |
a1a8a2be | 642 | print "</table>"; |
6113ef7d AD |
643 | |
644 | print "<script type=\"text/javascript\"> | |
bb7cface | 645 | document.onkeydown = hotkey_handler; |
8143ae1f | 646 | update_label_counters('$feed'); |
6113ef7d | 647 | </script>"; |
d76a3b03 | 648 | |
f0601b87 AD |
649 | if ($addheader) { |
650 | print "</body></html>"; | |
651 | } | |
652 | ||
1cd17194 AD |
653 | } |
654 | ||
0e091d38 | 655 | if ($op == "pref-rpc") { |
331900c6 | 656 | |
0e091d38 | 657 | $subop = $_GET["subop"]; |
331900c6 | 658 | |
83fe4d6d AD |
659 | if ($subop == "unread") { |
660 | $ids = split(",", $_GET["ids"]); | |
661 | foreach ($ids as $id) { | |
648472a7 | 662 | db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); |
83fe4d6d | 663 | } |
0e091d38 AD |
664 | |
665 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
666 | } |
667 | ||
668 | if ($subop == "read") { | |
669 | $ids = split(",", $_GET["ids"]); | |
670 | foreach ($ids as $id) { | |
648472a7 | 671 | db_query($link, "UPDATE ttrss_entries |
b197f117 | 672 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); |
83fe4d6d | 673 | } |
0e091d38 AD |
674 | |
675 | print "Marked selected feeds as unread."; | |
676 | ||
677 | } | |
678 | ||
679 | } | |
680 | ||
681 | if ($op == "pref-feeds") { | |
682 | ||
683 | $subop = $_GET["subop"]; | |
684 | ||
508a81e1 | 685 | if ($subop == "editSave") { |
648472a7 AD |
686 | $feed_title = db_escape_string($_GET["t"]); |
687 | $feed_link = db_escape_string($_GET["l"]); | |
508a81e1 AD |
688 | $feed_id = $_GET["id"]; |
689 | ||
648472a7 | 690 | $result = db_query($link, "UPDATE ttrss_feeds SET |
508a81e1 AD |
691 | title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'"); |
692 | ||
83fe4d6d AD |
693 | } |
694 | ||
331900c6 | 695 | if ($subop == "remove") { |
331900c6 | 696 | |
b0b4abcf | 697 | if (!WEB_DEMO_MODE) { |
331900c6 | 698 | |
b0b4abcf AD |
699 | $ids = split(",", $_GET["ids"]); |
700 | ||
701 | foreach ($ids as $id) { | |
648472a7 | 702 | db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); |
d5caaae5 AD |
703 | |
704 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
705 | unlink(ICONS_DIR . "/$id.ico"); | |
706 | } | |
b0b4abcf | 707 | } |
331900c6 AD |
708 | } |
709 | } | |
710 | ||
711 | if ($subop == "add") { | |
b0b4abcf AD |
712 | |
713 | if (!WEB_DEMO_MODE) { | |
331900c6 | 714 | |
648472a7 | 715 | $feed_link = db_escape_string($_GET["link"]); |
b0b4abcf | 716 | |
648472a7 | 717 | $result = db_query($link, |
b0b4abcf | 718 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); |
331900c6 | 719 | |
648472a7 | 720 | $result = db_query($link, |
e9c54861 | 721 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); |
331900c6 | 722 | |
648472a7 | 723 | $feed_id = db_fetch_result($result, 0, "id"); |
331900c6 | 724 | |
b0b4abcf AD |
725 | if ($feed_id) { |
726 | update_rss_feed($link, $feed_link, $feed_id); | |
727 | } | |
728 | } | |
331900c6 | 729 | } |
a0d53889 AD |
730 | |
731 | print "<table class=\"prefAddFeed\"><tr> | |
732 | <td><input id=\"fadd_link\"></td> | |
733 | <td colspan=\"4\" align=\"right\"> | |
734 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
735 | </table>"; | |
736 | ||
648472a7 | 737 | $result = db_query($link, "SELECT |
c0e5a40e AD |
738 | id,title,feed_url,substring(last_updated,1,16) as last_updated |
739 | FROM | |
740 | ttrss_feeds ORDER by title"); | |
1cd17194 | 741 | |
331900c6 | 742 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 743 | print "<tr class=\"title\"> |
603c27f8 | 744 | <td> </td><td>Select</td><td width=\"40%\">Title</td> |
0afbd851 | 745 | <td width=\"40%\">Link</td><td>Last updated</td></tr>"; |
007bda35 AD |
746 | |
747 | $lnum = 0; | |
748 | ||
648472a7 | 749 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
750 | |
751 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 752 | |
331900c6 | 753 | $feed_id = $line["id"]; |
603c27f8 AD |
754 | |
755 | $edit_feed_id = $_GET["id"]; | |
756 | ||
9b307248 AD |
757 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
758 | $class .= "Grayed"; | |
759 | } | |
760 | ||
331900c6 | 761 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 762 | |
c0e5a40e AD |
763 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
764 | ||
765 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
766 | $feed_icon = "<img width=\"16\" height=\"16\" | |
767 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
768 | } else { | |
769 | $feed_icon = " "; | |
770 | } | |
771 | print "<td align='center'>$feed_icon</td>"; | |
772 | ||
9b307248 | 773 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
774 | |
775 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 776 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
777 | |
778 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
779 | $line["title"] . "</td>"; | |
780 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
781 | $line["feed_url"] . "</td>"; | |
9b307248 AD |
782 | |
783 | ||
784 | } else if ($feed_id != $edit_feed_id) { | |
785 | ||
e9c54861 AD |
786 | print "<td><input disabled=\"true\" type=\"checkbox\" |
787 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 AD |
788 | |
789 | print "<td>".$line["title"]."</td>"; | |
790 | print "<td>".$line["feed_url"]."</td>"; | |
791 | ||
603c27f8 AD |
792 | } else { |
793 | ||
e9c54861 | 794 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; |
603c27f8 AD |
795 | |
796 | print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>"; | |
797 | print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>"; | |
798 | ||
799 | } | |
0afbd851 AD |
800 | |
801 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
802 | ||
007bda35 | 803 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 804 | |
007bda35 AD |
805 | print "</tr>"; |
806 | ||
807 | ++$lnum; | |
808 | } | |
809 | ||
0afbd851 AD |
810 | if ($lnum == 0) { |
811 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
812 | } | |
813 | ||
007bda35 AD |
814 | print "</table>"; |
815 | ||
603c27f8 AD |
816 | print "<p>"; |
817 | ||
818 | if ($subop == "edit") { | |
819 | print "Edit feed: | |
e828e31e AD |
820 | <input type=\"submit\" class=\"button\" |
821 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
822 | <input type=\"submit\" class=\"button\" | |
8158c57a | 823 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
824 | } else { |
825 | ||
603c27f8 AD |
826 | print " |
827 | Selection: | |
e828e31e AD |
828 | <input type=\"submit\" class=\"button\" |
829 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
830 | <input type=\"submit\" class=\"button\" | |
831 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
832 | ||
f92db4f5 AD |
833 | if (ENABLE_PREFS_CATCHUP_UNCATCHUP) { |
834 | print " | |
e828e31e AD |
835 | <input type=\"submit\" class=\"button\" |
836 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
837 | <input type=\"submit\" class=\"button\" | |
838 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
839 | } |
840 | print " | |
e828e31e AD |
841 | All feeds: |
842 | <input type=\"submit\" | |
8158c57a | 843 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 844 | |
603c27f8 AD |
845 | } |
846 | ||
007bda35 AD |
847 | } |
848 | ||
a0d53889 AD |
849 | if ($op == "pref-filters") { |
850 | ||
851 | $subop = $_GET["subop"]; | |
852 | ||
853 | if ($subop == "editSave") { | |
a0d53889 | 854 | |
648472a7 AD |
855 | $regexp = db_escape_string($_GET["r"]); |
856 | $descr = db_escape_string($_GET["d"]); | |
857 | $match = db_escape_string($_GET["m"]); | |
858 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 859 | |
648472a7 | 860 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 861 | reg_exp = '$regexp', |
0afbd851 AD |
862 | description = '$descr', |
863 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
864 | description = '$match') | |
865 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
866 | } |
867 | ||
868 | if ($subop == "remove") { | |
869 | ||
870 | if (!WEB_DEMO_MODE) { | |
871 | ||
872 | $ids = split(",", $_GET["ids"]); | |
873 | ||
874 | foreach ($ids as $id) { | |
648472a7 | 875 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
876 | |
877 | } | |
878 | } | |
879 | } | |
880 | ||
881 | if ($subop == "add") { | |
882 | ||
de435974 | 883 | if (!WEB_DEMO_MODE) { |
a0d53889 | 884 | |
8158c57a | 885 | $regexp = db_escape_string($_GET["regexp"]); |
648472a7 | 886 | $match = db_escape_string($_GET["match"]); |
a0d53889 | 887 | |
648472a7 | 888 | $result = db_query($link, |
4b3dff6e | 889 | "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES |
de435974 AD |
890 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
891 | description = '$match'))"); | |
892 | } | |
a0d53889 AD |
893 | } |
894 | ||
648472a7 | 895 | $result = db_query($link, "SELECT description |
a0d53889 AD |
896 | FROM ttrss_filter_types ORDER BY description"); |
897 | ||
898 | $filter_types = array(); | |
899 | ||
648472a7 | 900 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
901 | array_push($filter_types, $line["description"]); |
902 | } | |
903 | ||
904 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 905 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 906 | <td>"; |
bdc00fe0 | 907 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
908 | |
909 | print"</td><td colspan=\"4\" align=\"right\"> | |
910 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
911 | </table>"; | |
912 | ||
648472a7 | 913 | $result = db_query($link, "SELECT |
4b3dff6e | 914 | id,reg_exp,description, |
a0d53889 AD |
915 | (SELECT name FROM ttrss_filter_types WHERE |
916 | id = filter_type) as filter_type_name, | |
917 | (SELECT description FROM ttrss_filter_types | |
918 | WHERE id = filter_type) as filter_type_descr | |
919 | FROM | |
4b3dff6e | 920 | ttrss_filters ORDER by reg_exp"); |
a0d53889 AD |
921 | |
922 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
923 | ||
924 | print "<tr class=\"title\"> | |
0afbd851 AD |
925 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
926 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
927 | |
928 | $lnum = 0; | |
929 | ||
648472a7 | 930 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
931 | |
932 | $class = ($lnum % 2) ? "even" : "odd"; | |
933 | ||
934 | $filter_id = $line["id"]; | |
935 | $edit_filter_id = $_GET["id"]; | |
936 | ||
937 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
938 | $class .= "Grayed"; | |
939 | } | |
940 | ||
941 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
942 | ||
4b3dff6e | 943 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
944 | $line["description"] = htmlspecialchars($line["description"]); |
945 | ||
a0d53889 AD |
946 | if (!$edit_filter_id || $subop != "edit") { |
947 | ||
0afbd851 AD |
948 | if (!$line["description"]) $line["description"] = "[No description]"; |
949 | ||
a0d53889 AD |
950 | print "<td><input onclick='toggleSelectRow(this);' |
951 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
952 | ||
953 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 954 | $line["reg_exp"] . "</td>"; |
a0d53889 AD |
955 | |
956 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
957 | $line["description"] . "</td>"; | |
958 | ||
959 | print "<td>".$line["filter_type_descr"]."</td>"; | |
960 | ||
961 | } else if ($filter_id != $edit_filter_id) { | |
962 | ||
0afbd851 AD |
963 | if (!$line["description"]) $line["description"] = "[No description]"; |
964 | ||
a0d53889 AD |
965 | print "<td><input disabled=\"true\" type=\"checkbox\" |
966 | id=\"FICHK-".$line["id"]."\"></td>"; | |
967 | ||
4b3dff6e | 968 | print "<td>".$line["reg_exp"]."</td>"; |
a0d53889 AD |
969 | print "<td>".$line["description"]."</td>"; |
970 | print "<td>".$line["filter_type_descr"]."</td>"; | |
971 | ||
972 | } else { | |
973 | ||
974 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
975 | ||
4b3dff6e | 976 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
977 | "\"></td>"; |
978 | ||
979 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
980 | "\"></td>"; | |
981 | ||
982 | print "<td>"; | |
983 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
984 | print "</td>"; | |
985 | ||
986 | } | |
987 | ||
988 | ||
989 | print "</tr>"; | |
990 | ||
991 | ++$lnum; | |
992 | } | |
993 | ||
0afbd851 AD |
994 | if ($lnum == 0) { |
995 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
996 | } | |
997 | ||
a0d53889 AD |
998 | print "</table>"; |
999 | ||
1000 | print "<p>"; | |
1001 | ||
1002 | if ($subop == "edit") { | |
e828e31e AD |
1003 | print "Edit feed: |
1004 | <input type=\"submit\" class=\"button\" | |
1005 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1006 | <input type=\"submit\" class=\"button\" | |
1007 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
1008 | |
1009 | } else { | |
1010 | ||
1011 | print " | |
e828e31e AD |
1012 | Selection: |
1013 | <input type=\"submit\" class=\"button\" | |
1014 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
1015 | <input type=\"submit\" class=\"button\" | |
1016 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
1017 | } |
1018 | } | |
1019 | ||
48f0adb0 AD |
1020 | if ($op == "pref-labels") { |
1021 | ||
1022 | $subop = $_GET["subop"]; | |
1023 | ||
1024 | if ($subop == "editSave") { | |
1025 | ||
1026 | $sql_exp = $_GET["s"]; | |
1027 | $descr = $_GET["d"]; | |
1028 | $label_id = db_escape_string($_GET["id"]); | |
1029 | ||
1030 | // print "$sql_exp : $descr : $label_id"; | |
1031 | ||
1032 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1033 | sql_exp = '$sql_exp', | |
1034 | description = '$descr' | |
1035 | WHERE id = '$label_id'"); | |
1036 | } | |
1037 | ||
1038 | if ($subop == "remove") { | |
1039 | ||
1040 | if (!WEB_DEMO_MODE) { | |
1041 | ||
1042 | $ids = split(",", $_GET["ids"]); | |
1043 | ||
1044 | foreach ($ids as $id) { | |
1045 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1046 | ||
1047 | } | |
1048 | } | |
1049 | } | |
1050 | ||
1051 | if ($subop == "add") { | |
1052 | ||
1053 | if (!WEB_DEMO_MODE) { | |
1054 | ||
1055 | $exp = $_GET["exp"]; | |
1056 | ||
1057 | $result = db_query($link, | |
1058 | "INSERT INTO ttrss_labels (sql_exp,description) | |
1059 | VALUES ('$exp', '$exp')"); | |
1060 | } | |
1061 | } | |
1062 | ||
1063 | print "<table class=\"prefAddFeed\"><tr> | |
1064 | <td><input id=\"ladd_expr\"></td>"; | |
1065 | ||
1066 | print"<td colspan=\"4\" align=\"right\"> | |
1067 | <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr> | |
1068 | </table>"; | |
1069 | ||
1070 | $result = db_query($link, "SELECT | |
1071 | id,sql_exp,description | |
1072 | FROM | |
1073 | ttrss_labels ORDER by description"); | |
1074 | ||
1075 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; | |
1076 | ||
1077 | print "<tr class=\"title\"> | |
1078 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression</td> | |
1079 | <td width=\"40%\">Caption</td></tr>"; | |
1080 | ||
1081 | $lnum = 0; | |
1082 | ||
1083 | while ($line = db_fetch_assoc($result)) { | |
1084 | ||
1085 | $class = ($lnum % 2) ? "even" : "odd"; | |
1086 | ||
1087 | $label_id = $line["id"]; | |
1088 | $edit_label_id = $_GET["id"]; | |
1089 | ||
1090 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1091 | $class .= "Grayed"; | |
1092 | } | |
1093 | ||
1094 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1095 | ||
1096 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1097 | $line["description"] = htmlspecialchars($line["description"]); | |
1098 | ||
1099 | if (!$edit_label_id || $subop != "edit") { | |
1100 | ||
1101 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1102 | ||
1103 | print "<td><input onclick='toggleSelectRow(this);' | |
1104 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1105 | ||
1106 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1107 | $line["sql_exp"] . "</td>"; | |
1108 | ||
1109 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1110 | $line["description"] . "</td>"; | |
1111 | ||
1112 | } else if ($label_id != $edit_label_id) { | |
1113 | ||
1114 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1115 | ||
1116 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1117 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1118 | ||
1119 | print "<td>".$line["sql_exp"]."</td>"; | |
1120 | print "<td>".$line["description"]."</td>"; | |
1121 | ||
1122 | } else { | |
1123 | ||
1124 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1125 | ||
1126 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1127 | "\"></td>"; | |
1128 | ||
1129 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1130 | "\"></td>"; | |
1131 | ||
1132 | } | |
1133 | ||
1134 | ||
1135 | print "</tr>"; | |
1136 | ||
1137 | ++$lnum; | |
1138 | } | |
1139 | ||
1140 | if ($lnum == 0) { | |
1141 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1142 | } | |
1143 | ||
1144 | print "</table>"; | |
1145 | ||
1146 | print "<p>"; | |
1147 | ||
1148 | if ($subop == "edit") { | |
1149 | print "Edit label: | |
1150 | <input type=\"submit\" class=\"button\" | |
1151 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1152 | <input type=\"submit\" class=\"button\" | |
1153 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1154 | ||
1155 | } else { | |
1156 | ||
1157 | print " | |
1158 | Selection: | |
1159 | <input type=\"submit\" class=\"button\" | |
1160 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
1161 | <input type=\"submit\" class=\"button\" | |
1162 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
1163 | } | |
1164 | } | |
1165 | ||
e828e31e AD |
1166 | if ($op == "error") { |
1167 | print "<div width=\"100%\" align='center'>"; | |
1168 | $msg = $_GET["msg"]; | |
1169 | print $msg; | |
1170 | print "</div>"; | |
1171 | } | |
1172 | ||
4b3dff6e | 1173 | db_close($link); |
1cd17194 | 1174 | ?> |