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