]>
Commit | Line | Data |
---|---|---|
1cd17194 | 1 | <? |
295f9b42 | 2 | define(SCHEMA_VERSION, 2); |
7ec2a838 | 3 | |
77e96719 | 4 | $op = $_REQUEST["op"]; |
090e250b | 5 | |
e65af9c1 | 6 | if ($op == "rpc" || $op == "updateAllFeeds") { |
090e250b AD |
7 | header("Content-Type: application/xml"); |
8 | } | |
1cd17194 | 9 | |
82baad4a | 10 | require_once "config.php"; |
648472a7 | 11 | require_once "db.php"; |
3bac89ad | 12 | require_once "db-prefs.php"; |
82baad4a AD |
13 | require_once "functions.php"; |
14 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 15 | |
406d9489 AD |
16 | $script_started = getmicrotime(); |
17 | ||
648472a7 | 18 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
d76a3b03 | 19 | |
5136011e AD |
20 | if (!$link) { |
21 | if (DB_TYPE == "mysql") { | |
22 | print mysql_error(); | |
23 | } | |
24 | // PG seems to display its own errors just fine by default. | |
25 | return; | |
26 | } | |
27 | ||
648472a7 AD |
28 | if (DB_TYPE == "pgsql") { |
29 | pg_query("set client_encoding = 'utf-8'"); | |
30 | } | |
7ec2a838 | 31 | |
295f9b42 | 32 | /* |
7ec2a838 AD |
33 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); |
34 | ||
35 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
36 | ||
37 | if ($schema_version != SCHEMA_VERSION) { | |
38 | print "Error: database schema is invalid | |
39 | (got version $schema_version; expected ".SCHEMA_VERSION.")"; | |
40 | return; | |
41 | } | |
295f9b42 AD |
42 | */ |
43 | ||
331900c6 | 44 | $fetch = $_GET["fetch"]; |
175847de | 45 | |
8143ae1f AD |
46 | /* FIXME this needs reworking */ |
47 | ||
fc69e641 AD |
48 | function getGlobalCounters($link) { |
49 | $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries | |
50 | WHERE unread = true"); | |
51 | $c_id = db_fetch_result($result, 0, "c_id"); | |
52 | print "<counter id='global-unread' counter='$c_id'/>"; | |
53 | } | |
54 | ||
8143ae1f AD |
55 | function getTagCounters($link) { |
56 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count | |
57 | FROM ttrss_tags,ttrss_entries WHERE | |
58 | post_id = ttrss_entries.id AND unread = true GROUP BY tag_name | |
59 | UNION | |
60 | select tag_name,0 as count FROM ttrss_tags"); | |
61 | ||
62 | $tags = array(); | |
63 | ||
64 | while ($line = db_fetch_assoc($result)) { | |
65 | $tags[$line["tag_name"]] += $line["count"]; | |
66 | } | |
67 | ||
68 | foreach (array_keys($tags) as $tag) { | |
69 | $unread = $tags[$tag]; | |
70 | ||
71 | $tag = htmlspecialchars($tag); | |
72 | print "<tag id=\"$tag\" counter=\"$unread\"/>"; | |
73 | } | |
74 | } | |
75 | ||
090e250b AD |
76 | function getLabelCounters($link) { |
77 | ||
78 | $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
8073cce7 | 79 | WHERE marked = true AND unread = true"); |
090e250b | 80 | |
d61fd764 | 81 | $count = db_fetch_result($result, 0, "count"); |
090e250b AD |
82 | |
83 | print "<label id=\"-1\" counter=\"$count\"/>"; | |
84 | ||
85 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
86 | ttrss_labels ORDER by description"); | |
87 | ||
88 | while ($line = db_fetch_assoc($result)) { | |
89 | ||
90 | $id = -$line["id"] - 11; | |
91 | ||
92 | error_reporting (0); | |
d61fd764 AD |
93 | |
94 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
392d4563 | 95 | WHERE (" . $line["sql_exp"] . ") AND unread = true"); |
090e250b | 96 | |
d61fd764 | 97 | $count = db_fetch_result($tmp_result, 0, "count"); |
090e250b | 98 | |
ab3f3f72 | 99 | print "<label id=\"$id\" counter=\"$count\"/>"; |
090e250b AD |
100 | |
101 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
102 | ||
103 | } | |
104 | } | |
105 | ||
8073cce7 AD |
106 | function getFeedCounter($link, $id) { |
107 | ||
108 | $result = db_query($link, "SELECT | |
109 | count(id) as count FROM ttrss_entries | |
110 | WHERE feed_id = '$id' AND unread = true"); | |
111 | ||
112 | $count = db_fetch_result($result, 0, "count"); | |
113 | ||
114 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
115 | } | |
090e250b | 116 | |
8073cce7 AD |
117 | function getFeedCounters($link) { |
118 | ||
090e250b AD |
119 | $result = db_query($link, "SELECT id, |
120 | (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id | |
121 | AND unread = true) as count | |
122 | FROM ttrss_feeds"); | |
123 | ||
124 | while ($line = db_fetch_assoc($result)) { | |
125 | ||
126 | $id = $line["id"]; | |
127 | $count = $line["count"]; | |
128 | ||
129 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
130 | } | |
131 | } | |
132 | ||
8143ae1f | 133 | function outputFeedList($link, $tags = false) { |
175847de | 134 | |
1a66d16e AD |
135 | print "<html><head> |
136 | <title>Tiny Tiny RSS : Feedlist</title> | |
430bf183 AD |
137 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
138 | ||
4769ddaf | 139 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
140 | print "<link rel=\"stylesheet\" type=\"text/css\" |
141 | href=\"tt-rss_compact.css\"/>"; | |
142 | } else { | |
143 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
144 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
145 | } | |
146 | ||
147 | print "<script type=\"text/javascript\" src=\"functions.js\"></script> | |
1a66d16e AD |
148 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> |
149 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
3745788e | 150 | </head><body onload=\"init()\">"; |
254e0e4b AD |
151 | |
152 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
153 | ||
8143ae1f | 154 | if (!$tags) { |
254e0e4b | 155 | |
8143ae1f | 156 | /* virtual feeds */ |
254e0e4b | 157 | |
8143ae1f AD |
158 | $result = db_query($link, "SELECT count(id) as num_starred |
159 | FROM ttrss_entries WHERE marked = true AND unread = true"); | |
160 | $num_starred = db_fetch_result($result, 0, "num_starred"); | |
254e0e4b | 161 | |
3745788e | 162 | $class = "virt"; |
8add756a AD |
163 | |
164 | if ($num_starred > 0) $class .= "Unread"; | |
165 | ||
166 | printFeedEntry(-1, $class, "Starred articles", $num_starred, | |
4668523d | 167 | "images/mark_set.png", $link); |
48f0adb0 | 168 | |
4769ddaf | 169 | if (get_pref($link, 'ENABLE_LABELS')) { |
8143ae1f AD |
170 | |
171 | $result = db_query($link, "SELECT id,sql_exp,description FROM | |
172 | ttrss_labels ORDER by description"); | |
173 | ||
174 | if (db_num_rows($result) > 0) { | |
175 | print "<li><hr></li>"; | |
176 | } | |
177 | ||
178 | while ($line = db_fetch_assoc($result)) { | |
48f0adb0 | 179 | |
8143ae1f AD |
180 | error_reporting (0); |
181 | ||
182 | $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries | |
183 | WHERE (" . $line["sql_exp"] . ") AND unread = true"); | |
184 | ||
185 | $count = db_fetch_result($tmp_result, 0, "count"); | |
186 | ||
3745788e | 187 | $class = "label"; |
8143ae1f AD |
188 | |
189 | if ($count > 0) { | |
190 | $class .= "Unread"; | |
191 | } | |
192 | ||
193 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
194 | ||
195 | printFeedEntry(-$line["id"]-11, | |
4668523d | 196 | $class, $line["description"], $count, "images/label.png", $link); |
8143ae1f AD |
197 | |
198 | } | |
48f0adb0 AD |
199 | } |
200 | ||
8143ae1f AD |
201 | print "<li><hr></li>"; |
202 | ||
203 | $result = db_query($link, "SELECT *, | |
204 | (SELECT count(id) FROM ttrss_entries | |
205 | WHERE feed_id = ttrss_feeds.id) AS total, | |
206 | (SELECT count(id) FROM ttrss_entries | |
207 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
208 | FROM ttrss_feeds ORDER BY title"); | |
209 | ||
210 | $actid = $_GET["actid"]; | |
211 | ||
212 | /* real feeds */ | |
213 | ||
214 | $lnum = 0; | |
215 | ||
216 | $total_unread = 0; | |
217 | ||
48f0adb0 | 218 | while ($line = db_fetch_assoc($result)) { |
8143ae1f AD |
219 | |
220 | $feed = $line["title"]; | |
221 | $feed_id = $line["id"]; | |
222 | ||
223 | $subop = $_GET["subop"]; | |
224 | ||
225 | $total = $line["total"]; | |
226 | $unread = $line["unread"]; | |
227 | ||
228 | // $class = ($lnum % 2) ? "even" : "odd"; | |
48f0adb0 | 229 | |
3745788e | 230 | $class = "feed"; |
8143ae1f AD |
231 | |
232 | if ($unread > 0) $class .= "Unread"; | |
233 | ||
234 | if ($actid == $feed_id) { | |
235 | $class .= "Selected"; | |
392d4563 | 236 | } |
48f0adb0 | 237 | |
8143ae1f AD |
238 | $total_unread += $unread; |
239 | ||
4668523d | 240 | printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link); |
8143ae1f AD |
241 | |
242 | ++$lnum; | |
48f0adb0 | 243 | } |
8143ae1f | 244 | } else { |
a1a8a2be | 245 | |
8143ae1f | 246 | // tags |
a1a8a2be | 247 | |
8143ae1f AD |
248 | $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count |
249 | FROM ttrss_tags,ttrss_entries WHERE | |
250 | post_id = ttrss_entries.id AND unread = true GROUP BY tag_name | |
251 | UNION | |
252 | select tag_name,0 as count FROM ttrss_tags"); | |
253 | ||
254 | $tags = array(); | |
255 | ||
256 | while ($line = db_fetch_assoc($result)) { | |
257 | $tags[$line["tag_name"]] += $line["count"]; | |
1a66d16e | 258 | } |
8143ae1f AD |
259 | |
260 | foreach (array_keys($tags) as $tag) { | |
261 | ||
262 | $unread = $tags[$tag]; | |
263 | ||
264 | $class = "odd"; | |
265 | ||
266 | if ($unread > 0) { | |
267 | $class .= "Unread"; | |
268 | } | |
269 | ||
4668523d | 270 | printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link); |
8143ae1f AD |
271 | |
272 | } | |
1a66d16e | 273 | |
e828e31e | 274 | } |
82baad4a | 275 | |
dc33ec95 AD |
276 | if (db_num_rows($result) == 0) { |
277 | print "<li>No tags to display.</li>"; | |
278 | } | |
279 | ||
8143ae1f | 280 | print "</ul>"; |
1cd17194 | 281 | |
caa4e57f AD |
282 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
283 | ||
c3b81db0 AD |
284 | } |
285 | ||
286 | ||
287 | if ($op == "rpc") { | |
288 | ||
289 | $subop = $_GET["subop"]; | |
290 | ||
090e250b | 291 | if ($subop == "getLabelCounters") { |
8073cce7 | 292 | $aid = $_GET["aid"]; |
090e250b AD |
293 | print "<rpc-reply>"; |
294 | getLabelCounters($link); | |
8073cce7 AD |
295 | if ($aid) { |
296 | getFeedCounter($link, $aid); | |
297 | } | |
090e250b AD |
298 | print "</rpc-reply>"; |
299 | } | |
300 | ||
301 | if ($subop == "getFeedCounters") { | |
302 | print "<rpc-reply>"; | |
303 | getFeedCounters($link); | |
304 | print "</rpc-reply>"; | |
305 | } | |
306 | ||
307 | if ($subop == "getAllCounters") { | |
308 | print "<rpc-reply>"; | |
309 | getLabelCounters($link); | |
310 | getFeedCounters($link); | |
8143ae1f | 311 | getTagCounters($link); |
fc69e641 | 312 | getGlobalCounters($link); |
090e250b | 313 | print "</rpc-reply>"; |
090e250b AD |
314 | } |
315 | ||
f4c10d44 AD |
316 | if ($subop == "mark") { |
317 | $mark = $_GET["mark"]; | |
648472a7 | 318 | $id = db_escape_string($_GET["id"]); |
f4c10d44 AD |
319 | |
320 | if ($mark == "1") { | |
321 | $mark = "true"; | |
322 | } else { | |
323 | $mark = "false"; | |
324 | } | |
325 | ||
648472a7 | 326 | $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark |
f4c10d44 AD |
327 | WHERE id = '$id'"); |
328 | } | |
329 | ||
caa4e57f | 330 | if ($subop == "updateFeed") { |
648472a7 | 331 | $feed_id = db_escape_string($_GET["feed"]); |
9cfc649a | 332 | |
648472a7 | 333 | $result = db_query($link, |
caa4e57f | 334 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'"); |
9cfc649a | 335 | |
648472a7 AD |
336 | if (db_num_rows($result) > 0) { |
337 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
caa4e57f AD |
338 | // update_rss_feed($link, $feed_url, $feed_id); |
339 | } | |
9cfc649a | 340 | |
caa4e57f | 341 | print "DONE-$feed_id"; |
9cfc649a | 342 | |
caa4e57f | 343 | return; |
9cfc649a AD |
344 | } |
345 | ||
090e250b | 346 | if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") { |
c5142cca | 347 | |
c3b81db0 | 348 | update_all_feeds($link, true); |
c3b81db0 | 349 | |
ab3f3f72 AD |
350 | $omode = $_GET["omode"]; |
351 | ||
352 | if (!$omode) $omode = "tfl"; | |
353 | ||
090e250b | 354 | print "<rpc-reply>"; |
ab3f3f72 AD |
355 | if (strchr($omode, "l")) getLabelCounters($link); |
356 | if (strchr($omode, "f")) getFeedCounters($link); | |
357 | if (strchr($omode, "t")) getTagCounters($link); | |
fc69e641 | 358 | getGlobalCounters($link); |
090e250b | 359 | print "</rpc-reply>"; |
c3b81db0 AD |
360 | } |
361 | ||
362 | if ($subop == "catchupPage") { | |
363 | ||
364 | $ids = split(",", $_GET["ids"]); | |
365 | ||
366 | foreach ($ids as $id) { | |
367 | ||
648472a7 | 368 | db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW() |
c3b81db0 AD |
369 | WHERE id = '$id'"); |
370 | ||
371 | } | |
372 | ||
373 | print "Marked active page as read."; | |
374 | } | |
295f9b42 AD |
375 | |
376 | if ($subop == "sanityCheck") { | |
377 | ||
378 | $error_code = 0; | |
379 | ||
380 | $result = db_query($link, "SELECT schema_version FROM ttrss_version"); | |
381 | ||
382 | $schema_version = db_fetch_result($result, 0, "schema_version"); | |
383 | ||
384 | if ($schema_version != SCHEMA_VERSION) { | |
385 | $error_code = 5; | |
386 | } | |
387 | ||
388 | print "<error code='$error_code'/>"; | |
389 | } | |
c3b81db0 AD |
390 | } |
391 | ||
392 | if ($op == "feeds") { | |
393 | ||
8143ae1f AD |
394 | $tags = $_GET["tags"]; |
395 | ||
c3b81db0 AD |
396 | $subop = $_GET["subop"]; |
397 | ||
398 | if ($subop == "catchupAll") { | |
648472a7 | 399 | db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); |
c3b81db0 AD |
400 | } |
401 | ||
8143ae1f | 402 | outputFeedList($link, $tags); |
c3b81db0 | 403 | |
1cd17194 AD |
404 | } |
405 | ||
406 | if ($op == "view") { | |
407 | ||
d76a3b03 | 408 | $id = $_GET["id"]; |
8073cce7 | 409 | $feed_id = $_GET["feed"]; |
d76a3b03 | 410 | |
648472a7 | 411 | $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); |
a1a8a2be | 412 | |
70830c87 AD |
413 | $addheader = $_GET["addheader"]; |
414 | ||
648472a7 | 415 | $result = db_query($link, "SELECT title,link,content,feed_id,comments, |
b7f4bda2 AD |
416 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url |
417 | FROM ttrss_entries | |
d76a3b03 | 418 | WHERE id = '$id'"); |
1cd17194 | 419 | |
70830c87 | 420 | if ($addheader) { |
f0601b87 | 421 | print "<html><head> |
70830c87 AD |
422 | <title>Tiny Tiny RSS : Article $id</title> |
423 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 424 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 425 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 426 | </head><body>"; |
70830c87 AD |
427 | } |
428 | ||
d76a3b03 | 429 | if ($result) { |
1cd17194 | 430 | |
648472a7 | 431 | $line = db_fetch_assoc($result); |
1cd17194 | 432 | |
b7f4bda2 AD |
433 | if ($line["icon_url"]) { |
434 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
435 | } else { | |
436 | $feed_icon = " "; | |
437 | } | |
d76a3b03 | 438 | |
f7181e9b AD |
439 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
440 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
441 | } else { | |
442 | $entry_comments = ""; | |
443 | } | |
444 | ||
e828e31e AD |
445 | print "<div class=\"postReply\">"; |
446 | ||
447 | print "<div class=\"postHeader\"><table>"; | |
448 | ||
449 | print "<tr><td><b>Title:</b></td> | |
450 | <td width='100%'>" . $line["title"] . "</td></tr>"; | |
f7181e9b | 451 | |
e828e31e | 452 | print "<tr><td><b>Link:</b></td> |
f7181e9b AD |
453 | <td width='100%'> |
454 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> | |
455 | $entry_comments</td></tr>"; | |
e828e31e AD |
456 | |
457 | print "</table></div>"; | |
458 | ||
459 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
460 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
461 | ||
462 | print "</div>"; | |
463 | ||
090e250b | 464 | print "<script type=\"text/javascript\"> |
8143ae1f | 465 | update_label_counters('$feed_id'); |
090e250b | 466 | </script>"; |
d76a3b03 | 467 | } |
70830c87 AD |
468 | |
469 | if ($addheader) { | |
470 | print "</body></html>"; | |
471 | } | |
1cd17194 AD |
472 | } |
473 | ||
474 | if ($op == "viewfeed") { | |
475 | ||
476 | $feed = $_GET["feed"]; | |
d76a3b03 | 477 | $skip = $_GET["skip"]; |
476cac42 | 478 | $subop = $_GET["subop"]; |
f175937c | 479 | $view_mode = $_GET["view"]; |
f0601b87 | 480 | $addheader = $_GET["addheader"]; |
cb1083a1 | 481 | $limit = $_GET["limit"]; |
a1a8a2be | 482 | |
8d7008c7 AD |
483 | if (!$feed) { |
484 | print "Error: no feed to display."; | |
485 | return; | |
486 | } | |
487 | ||
ac53063a AD |
488 | if (!$skip) $skip = 0; |
489 | ||
476cac42 | 490 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 491 | |
f0601b87 AD |
492 | if ($addheader) { |
493 | print "<html><head> | |
ac43eba1 | 494 | <title>Tiny Tiny RSS : Feed $feed</title> |
430bf183 AD |
495 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">"; |
496 | ||
4769ddaf | 497 | if (get_pref($link, 'USE_COMPACT_STYLESHEET')) { |
430bf183 AD |
498 | print "<link rel=\"stylesheet\" |
499 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
500 | ||
501 | } else { | |
502 | print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\" | |
503 | type=\"text/css\" href=\"tt-rss_compact.css\"/>"; | |
504 | } | |
505 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
f0601b87 AD |
506 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
507 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
b623b3ed | 508 | </head><body onload='init()'>"; |
f0601b87 AD |
509 | } |
510 | ||
dcee8f61 AD |
511 | if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) { |
512 | ||
513 | $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds | |
514 | WHERE id = '$feed'"); | |
515 | ||
516 | $feed_url = db_fetch_result($tmp_result, 0, "feed_url"); | |
517 | ||
518 | update_rss_feed($link, $feed_url, $feed); | |
519 | ||
520 | } | |
521 | ||
0e32076b | 522 | if ($subop == "MarkAllRead") { |
d76a3b03 | 523 | |
0e32076b AD |
524 | if (sprintf("%d", $feed) != 0) { |
525 | ||
526 | if ($feed > 0) { | |
527 | db_query($link, "UPDATE ttrss_entries | |
528 | SET unread = false,last_read = NOW() | |
254e0e4b | 529 | WHERE feed_id = '$feed'"); |
0e32076b AD |
530 | |
531 | } else if ($feed < 0 && $feed > -10) { // special, like starred | |
532 | ||
533 | if ($feed == -1) { | |
534 | db_query($link, "UPDATE ttrss_entries | |
535 | SET unread = false,last_read = NOW() | |
536 | WHERE marked = true"); | |
537 | } | |
538 | ||
539 | } else if ($feed < -10) { // label | |
540 | ||
7db95187 | 541 | $label_id = -$feed - 11; |
0e32076b | 542 | |
7db95187 AD |
543 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels |
544 | WHERE id = '$label_id'"); | |
545 | ||
546 | if ($tmp_result) { | |
547 | $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp"); | |
548 | ||
549 | db_query($link, "UPDATE ttrss_entries | |
550 | SET unread = false,last_read = NOW() | |
551 | WHERE $sql_exp"); | |
552 | } | |
254e0e4b | 553 | } |
0e32076b AD |
554 | } else { // tag |
555 | // FIXME, implement catchup for tags | |
a1a8a2be | 556 | } |
0e32076b | 557 | |
a1a8a2be | 558 | } |
d76a3b03 | 559 | |
175847de | 560 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 561 | |
c374a3fe AD |
562 | $search = $_GET["search"]; |
563 | ||
52b51244 AD |
564 | $search_mode = $_GET["smode"]; |
565 | ||
f175937c | 566 | if ($search) { |
ac53063a AD |
567 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
568 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
569 | } else { |
570 | $search_query_part = ""; | |
571 | } | |
572 | ||
573 | $view_query_part = ""; | |
574 | ||
575 | if ($view_mode == "Starred") { | |
576 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
577 | } |
578 | ||
ac43eba1 AD |
579 | if ($view_mode == "Unread") { |
580 | $view_query_part = " unread = true AND "; | |
581 | } | |
582 | ||
b5aa95e7 AD |
583 | if ($view_mode == "Unread or Starred") { |
584 | $view_query_part = " (unread = true OR marked = true) AND "; | |
585 | } | |
586 | ||
bdd01d3f AD |
587 | if ($view_mode == "Unread or Updated") { |
588 | $view_query_part = " (unread = true OR last_read is NULL) AND "; | |
589 | } | |
590 | ||
254e0e4b | 591 | /* $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
592 | FROM ttrss_entries WHERE |
593 | $search_query_part | |
594 | feed_id = '$feed'"); | |
e6d1c0a0 | 595 | |
254e0e4b | 596 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ |
e6d1c0a0 | 597 | |
648472a7 | 598 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
599 | FROM ttrss_entries WHERE |
600 | $search_query_part | |
601 | unread = true AND | |
602 | feed_id = '$feed'"); | |
603 | ||
648472a7 | 604 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 605 | |
8d7008c7 | 606 | if ($limit && $limit != "All") { |
82c9223c | 607 | $limit_query_part = "LIMIT " . $limit; |
ad3cb710 | 608 | } |
f0601b87 | 609 | |
254e0e4b AD |
610 | $vfeed_query_part = ""; |
611 | ||
52b51244 AD |
612 | // override query strategy and enable feed display when searching globally |
613 | if ($search_mode == "All feeds") { | |
614 | $query_strategy_part = "id > 0"; | |
615 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
616 | id = feed_id) as feed_title,"; | |
617 | } else if (sprintf("%d", $feed) == 0) { | |
8143ae1f AD |
618 | $query_strategy_part = "ttrss_entries.id > 0"; |
619 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
620 | id = feed_id) as feed_title,"; | |
621 | } else if ($feed >= 0) { | |
254e0e4b | 622 | $query_strategy_part = "feed_id = '$feed'"; |
48f0adb0 | 623 | } else if ($feed == -1) { // starred virtual feed |
254e0e4b | 624 | $query_strategy_part = "marked = true"; |
48f0adb0 AD |
625 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
626 | id = feed_id) as feed_title,"; | |
627 | } else if ($feed <= -10) { // labels | |
628 | $label_id = -$feed - 11; | |
629 | ||
630 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
631 | WHERE id = '$label_id'"); | |
632 | ||
633 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
634 | ||
254e0e4b AD |
635 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
636 | id = feed_id) as feed_title,"; | |
637 | } else { | |
48f0adb0 | 638 | $query_strategy_part = "id > 0"; // dumb |
254e0e4b AD |
639 | } |
640 | ||
52b51244 | 641 | |
f99321a3 AD |
642 | $order_by = "updated DESC"; |
643 | ||
644 | // if ($feed < -10) { | |
645 | // $order_by = "feed_id,updated DESC"; | |
646 | // } | |
647 | ||
48f0adb0 AD |
648 | if ($feed < -10) error_reporting (0); |
649 | ||
8143ae1f AD |
650 | if (sprintf("%d", $feed) != 0) { |
651 | ||
652 | $result = db_query($link, "SELECT | |
653 | id,title,updated,unread,feed_id,marked,link,last_read, | |
654 | SUBSTRING(last_read,1,19) as last_read_noms, | |
655 | $vfeed_query_part | |
656 | SUBSTRING(updated,1,19) as updated_noms | |
657 | FROM | |
658 | ttrss_entries | |
659 | WHERE | |
660 | $search_query_part | |
661 | $view_query_part | |
662 | $query_strategy_part ORDER BY $order_by | |
663 | $limit_query_part"); | |
664 | ||
665 | } else { | |
666 | // browsing by tag | |
667 | ||
668 | $result = db_query($link, "SELECT | |
669 | ttrss_entries.id as id,title,updated,unread,feed_id, | |
670 | marked,link,last_read, | |
c05a19f3 | 671 | SUBSTRING(last_read,1,19) as last_read_noms, |
254e0e4b | 672 | $vfeed_query_part |
c05a19f3 | 673 | SUBSTRING(updated,1,19) as updated_noms |
8143ae1f AD |
674 | FROM |
675 | ttrss_entries,ttrss_tags | |
676 | WHERE | |
677 | post_id = ttrss_entries.id AND tag_name = '$feed' AND | |
678 | $view_query_part | |
679 | $search_query_part | |
680 | $query_strategy_part ORDER BY $order_by | |
681 | $limit_query_part"); | |
682 | } | |
d76a3b03 | 683 | |
48f0adb0 AD |
684 | if (!$result) { |
685 | print "<tr><td colspan='4' align='center'> | |
686 | Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; | |
687 | return; | |
688 | } | |
689 | ||
a1a8a2be | 690 | $lnum = 0; |
48f0adb0 AD |
691 | |
692 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
693 | ||
e1123aee | 694 | $num_unread = 0; |
d76a3b03 | 695 | |
648472a7 | 696 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 697 | |
a1a8a2be | 698 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 699 | |
ad99045e AD |
700 | $id = $line["id"]; |
701 | $feed_id = $line["feed_id"]; | |
702 | ||
c43f77f5 | 703 | // printf("L %d (%s) > U %d (%s) = %d<br>", |
c05a19f3 | 704 | // strtotime($line["last_read_noms"]), $line["last_read_noms"], |
c43f77f5 AD |
705 | // strtotime($line["updated"]), $line["updated"], |
706 | // strtotime($line["last_read"]) >= strtotime($line["updated"])); | |
707 | ||
ecb14114 | 708 | /* if ($line["last_read"] != "" && $line["updated"] != "" && |
c05a19f3 | 709 | strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) { |
c43f77f5 AD |
710 | |
711 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
712 | alt=\"Updated\">"; | |
713 | ||
714 | } else { | |
715 | ||
5bfef089 | 716 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" |
c43f77f5 AD |
717 | alt=\"Updated\">"; |
718 | ||
ecb14114 AD |
719 | } */ |
720 | ||
4cc6ea5e AD |
721 | if ($line["last_read"] == "" && |
722 | ($line["unread"] != "t" && $line["unread"] != "1")) { | |
723 | ||
ecb14114 AD |
724 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" |
725 | alt=\"Updated\">"; | |
726 | } else { | |
727 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
728 | alt=\"Updated\">"; | |
c43f77f5 | 729 | } |
b197f117 | 730 | |
8158c57a | 731 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 732 | $class .= "Unread"; |
e1123aee AD |
733 | ++$num_unread; |
734 | } | |
d76a3b03 | 735 | |
8158c57a | 736 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
737 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
738 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
739 | } else { | |
740 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
741 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
742 | } | |
743 | ||
ac43eba1 | 744 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
745 | $line["title"] . "</a>"; |
746 | ||
d5224f0d | 747 | print "<tr class='$class' id='RROW-$id'>"; |
5f89f780 | 748 | // onclick=\"javascript:view($id,$feed_id)\"> |
b197f117 | 749 | |
8d7008c7 AD |
750 | print "<td valign='center' align='center'>$update_pic</td>"; |
751 | print "<td valign='center' align='center'>$marked_pic</td>"; | |
b197f117 | 752 | |
8d7008c7 | 753 | print "<td width='25%'> |
a3ee2a38 | 754 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
254e0e4b AD |
755 | |
756 | if ($line["feed_title"]) { | |
757 | print "<td width='50%'>$content_link</td>"; | |
2db4190c AD |
758 | print "<td width='20%'> |
759 | <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>"; | |
254e0e4b AD |
760 | } else { |
761 | print "<td width='70%'>$content_link</td>"; | |
762 | } | |
d76a3b03 | 763 | |
a1a8a2be | 764 | print "</tr>"; |
d76a3b03 | 765 | |
a1a8a2be AD |
766 | ++$lnum; |
767 | } | |
d76a3b03 | 768 | |
ac53063a | 769 | if ($lnum == 0) { |
a82065a1 | 770 | print "<tr><td align='center'>No articles found.</td></tr>"; |
047bae73 | 771 | } |
a2015351 | 772 | |
a1a8a2be | 773 | print "</table>"; |
6113ef7d AD |
774 | |
775 | print "<script type=\"text/javascript\"> | |
bb7cface | 776 | document.onkeydown = hotkey_handler; |
8143ae1f | 777 | update_label_counters('$feed'); |
6113ef7d | 778 | </script>"; |
d76a3b03 | 779 | |
f0601b87 AD |
780 | if ($addheader) { |
781 | print "</body></html>"; | |
782 | } | |
783 | ||
1cd17194 AD |
784 | } |
785 | ||
0e091d38 | 786 | if ($op == "pref-rpc") { |
331900c6 | 787 | |
0e091d38 | 788 | $subop = $_GET["subop"]; |
331900c6 | 789 | |
83fe4d6d AD |
790 | if ($subop == "unread") { |
791 | $ids = split(",", $_GET["ids"]); | |
792 | foreach ($ids as $id) { | |
648472a7 | 793 | db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); |
83fe4d6d | 794 | } |
0e091d38 AD |
795 | |
796 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
797 | } |
798 | ||
799 | if ($subop == "read") { | |
800 | $ids = split(",", $_GET["ids"]); | |
801 | foreach ($ids as $id) { | |
648472a7 | 802 | db_query($link, "UPDATE ttrss_entries |
b197f117 | 803 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); |
83fe4d6d | 804 | } |
0e091d38 AD |
805 | |
806 | print "Marked selected feeds as unread."; | |
807 | ||
808 | } | |
809 | ||
810 | } | |
811 | ||
812 | if ($op == "pref-feeds") { | |
813 | ||
814 | $subop = $_GET["subop"]; | |
815 | ||
508a81e1 | 816 | if ($subop == "editSave") { |
648472a7 AD |
817 | $feed_title = db_escape_string($_GET["t"]); |
818 | $feed_link = db_escape_string($_GET["l"]); | |
d148926e | 819 | $upd_intl = db_escape_string($_GET["ui"]); |
5d73494a | 820 | $purge_intl = db_escape_string($_GET["pi"]); |
508a81e1 AD |
821 | $feed_id = $_GET["id"]; |
822 | ||
d148926e AD |
823 | if (strtoupper($upd_intl) == "DEFAULT") |
824 | $upd_intl = 0; | |
825 | ||
5d73494a AD |
826 | if (strtoupper($purge_intl) == "DEFAULT") |
827 | $purge_intl = 0; | |
828 | ||
140aae81 AD |
829 | if (strtoupper($purge_intl) == "DISABLED") |
830 | $purge_intl = -1; | |
831 | ||
648472a7 | 832 | $result = db_query($link, "UPDATE ttrss_feeds SET |
d148926e | 833 | title = '$feed_title', feed_url = '$feed_link', |
5d73494a AD |
834 | update_interval = '$upd_intl', |
835 | purge_interval = '$purge_intl' | |
836 | WHERE id = '$feed_id'"); | |
508a81e1 | 837 | |
83fe4d6d AD |
838 | } |
839 | ||
331900c6 | 840 | if ($subop == "remove") { |
331900c6 | 841 | |
b0b4abcf | 842 | if (!WEB_DEMO_MODE) { |
331900c6 | 843 | |
b0b4abcf AD |
844 | $ids = split(",", $_GET["ids"]); |
845 | ||
846 | foreach ($ids as $id) { | |
648472a7 | 847 | db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); |
4769ddaf AD |
848 | |
849 | $icons_dir = get_pref($link, 'ICONS_DIR'); | |
d5caaae5 | 850 | |
4769ddaf AD |
851 | if (file_exists($icons_dir . "/$id.ico")) { |
852 | unlink($icons_dir . "/$id.ico"); | |
d5caaae5 | 853 | } |
b0b4abcf | 854 | } |
331900c6 AD |
855 | } |
856 | } | |
857 | ||
858 | if ($subop == "add") { | |
b0b4abcf AD |
859 | |
860 | if (!WEB_DEMO_MODE) { | |
331900c6 | 861 | |
648472a7 | 862 | $feed_link = db_escape_string($_GET["link"]); |
b0b4abcf | 863 | |
648472a7 | 864 | $result = db_query($link, |
b0b4abcf | 865 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); |
331900c6 | 866 | |
648472a7 | 867 | $result = db_query($link, |
e9c54861 | 868 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); |
331900c6 | 869 | |
648472a7 | 870 | $feed_id = db_fetch_result($result, 0, "id"); |
331900c6 | 871 | |
b0b4abcf AD |
872 | if ($feed_id) { |
873 | update_rss_feed($link, $feed_link, $feed_id); | |
874 | } | |
875 | } | |
331900c6 | 876 | } |
a0d53889 | 877 | |
ab3d0b99 AD |
878 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
879 | FROM ttrss_feeds WHERE last_error != ''"); | |
880 | ||
881 | if (db_num_rows($result) > 0) { | |
882 | ||
883 | print "<div class=\"warning\">"; | |
884 | ||
885 | print "<b>Feeds with update errors:</b>"; | |
886 | ||
887 | print "<ul class=\"nomarks\">"; | |
888 | ||
889 | while ($line = db_fetch_assoc($result)) { | |
890 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
891 | $line["last_error"]; | |
892 | } | |
893 | ||
894 | print "</ul>"; | |
895 | print "</div>"; | |
896 | ||
897 | } | |
898 | ||
a0d53889 AD |
899 | print "<table class=\"prefAddFeed\"><tr> |
900 | <td><input id=\"fadd_link\"></td> | |
901 | <td colspan=\"4\" align=\"right\"> | |
902 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
903 | </table>"; | |
904 | ||
648472a7 | 905 | $result = db_query($link, "SELECT |
d148926e | 906 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
5d73494a | 907 | update_interval,purge_interval |
c0e5a40e AD |
908 | FROM |
909 | ttrss_feeds ORDER by title"); | |
1cd17194 | 910 | |
331900c6 | 911 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 912 | print "<tr class=\"title\"> |
5d73494a AD |
913 | <td> </td><td>Select</td><td width=\"30%\">Title</td> |
914 | <td width=\"30%\">Link</td> | |
915 | <td width=\"10%\">Update Interval</td> | |
916 | <td width=\"10%\">Purge Days</td> | |
d148926e | 917 | <td>Last updated</td></tr>"; |
007bda35 AD |
918 | |
919 | $lnum = 0; | |
920 | ||
648472a7 | 921 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
922 | |
923 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 924 | |
331900c6 | 925 | $feed_id = $line["id"]; |
603c27f8 AD |
926 | |
927 | $edit_feed_id = $_GET["id"]; | |
928 | ||
9b307248 AD |
929 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
930 | $class .= "Grayed"; | |
931 | } | |
932 | ||
331900c6 | 933 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 934 | |
4769ddaf | 935 | $icon_file = get_pref($link, 'ICONS_DIR') . "/$feed_id.ico"; |
c0e5a40e AD |
936 | |
937 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
938 | $feed_icon = "<img width=\"16\" height=\"16\" | |
4769ddaf | 939 | src=\"" . get_pref($link, 'ICONS_URL') . "/$feed_id.ico\">"; |
c0e5a40e AD |
940 | } else { |
941 | $feed_icon = " "; | |
942 | } | |
943 | print "<td align='center'>$feed_icon</td>"; | |
944 | ||
6e0584e9 AD |
945 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); |
946 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
947 | ||
9b307248 | 948 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
949 | |
950 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 951 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
952 | |
953 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
5d73494a | 954 | $edit_title . "</a></td>"; |
603c27f8 | 955 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
5d73494a | 956 | $edit_link . "</a></td>"; |
d148926e AD |
957 | |
958 | if ($line["update_interval"] == "0") | |
959 | $line["update_interval"] = "Default"; | |
960 | ||
5d73494a AD |
961 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
962 | $line["update_interval"] . "</a></td>"; | |
d148926e | 963 | |
5d73494a AD |
964 | if ($line["purge_interval"] == "0") |
965 | $line["purge_interval"] = "Default"; | |
966 | ||
140aae81 AD |
967 | if ($line["purge_interval"] < 0) |
968 | $line["purge_interval"] = "Disabled"; | |
969 | ||
5d73494a AD |
970 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
971 | $line["purge_interval"] . "</a></td>"; | |
9b307248 AD |
972 | |
973 | } else if ($feed_id != $edit_feed_id) { | |
974 | ||
e9c54861 AD |
975 | print "<td><input disabled=\"true\" type=\"checkbox\" |
976 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 | 977 | |
6e0584e9 AD |
978 | print "<td>$edit_title</td>"; |
979 | print "<td>$edit_link</td>"; | |
9b307248 | 980 | |
d148926e AD |
981 | if ($line["update_interval"] == "0") |
982 | $line["update_interval"] = "Default"; | |
983 | ||
984 | print "<td>" . $line["update_interval"] . "</td>"; | |
985 | ||
5d73494a AD |
986 | if ($line["purge_interval"] == "0") |
987 | $line["purge_interval"] = "Default"; | |
988 | ||
140aae81 AD |
989 | if ($line["purge_interval"] < 0) |
990 | $line["purge_interval"] = "Disabled"; | |
991 | ||
5d73494a AD |
992 | print "<td>" . $line["purge_interval"] . "</td>"; |
993 | ||
603c27f8 AD |
994 | } else { |
995 | ||
e9c54861 | 996 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; |
603c27f8 | 997 | |
6e0584e9 AD |
998 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; |
999 | print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>"; | |
d148926e | 1000 | print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>"; |
5d73494a | 1001 | print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>"; |
d148926e | 1002 | |
603c27f8 | 1003 | } |
0afbd851 AD |
1004 | |
1005 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
1006 | ||
007bda35 | 1007 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 1008 | |
007bda35 AD |
1009 | print "</tr>"; |
1010 | ||
1011 | ++$lnum; | |
1012 | } | |
1013 | ||
0afbd851 AD |
1014 | if ($lnum == 0) { |
1015 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
1016 | } | |
1017 | ||
007bda35 AD |
1018 | print "</table>"; |
1019 | ||
603c27f8 AD |
1020 | print "<p>"; |
1021 | ||
1022 | if ($subop == "edit") { | |
1023 | print "Edit feed: | |
e828e31e AD |
1024 | <input type=\"submit\" class=\"button\" |
1025 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
1026 | <input type=\"submit\" class=\"button\" | |
8158c57a | 1027 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
1028 | } else { |
1029 | ||
603c27f8 AD |
1030 | print " |
1031 | Selection: | |
e828e31e AD |
1032 | <input type=\"submit\" class=\"button\" |
1033 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
1034 | <input type=\"submit\" class=\"button\" | |
1035 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
1036 | ||
4769ddaf | 1037 | if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) { |
f92db4f5 | 1038 | print " |
e828e31e AD |
1039 | <input type=\"submit\" class=\"button\" |
1040 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
1041 | <input type=\"submit\" class=\"button\" | |
1042 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
1043 | } |
1044 | print " | |
e828e31e AD |
1045 | All feeds: |
1046 | <input type=\"submit\" | |
8158c57a | 1047 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 1048 | |
603c27f8 AD |
1049 | } |
1050 | ||
f5a50b25 AD |
1051 | print "<h3>OPML Import</h3> |
1052 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> | |
1053 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
1054 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
1055 | type=\"submit\" value=\"Import\"> | |
1056 | </form>"; | |
1057 | ||
007bda35 AD |
1058 | } |
1059 | ||
a0d53889 AD |
1060 | if ($op == "pref-filters") { |
1061 | ||
1062 | $subop = $_GET["subop"]; | |
1063 | ||
1064 | if ($subop == "editSave") { | |
a0d53889 | 1065 | |
648472a7 AD |
1066 | $regexp = db_escape_string($_GET["r"]); |
1067 | $descr = db_escape_string($_GET["d"]); | |
1068 | $match = db_escape_string($_GET["m"]); | |
1069 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 1070 | |
648472a7 | 1071 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 1072 | reg_exp = '$regexp', |
0afbd851 AD |
1073 | description = '$descr', |
1074 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
1075 | description = '$match') | |
1076 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
1077 | } |
1078 | ||
1079 | if ($subop == "remove") { | |
1080 | ||
1081 | if (!WEB_DEMO_MODE) { | |
1082 | ||
1083 | $ids = split(",", $_GET["ids"]); | |
1084 | ||
1085 | foreach ($ids as $id) { | |
648472a7 | 1086 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
1087 | |
1088 | } | |
1089 | } | |
1090 | } | |
1091 | ||
1092 | if ($subop == "add") { | |
1093 | ||
de435974 | 1094 | if (!WEB_DEMO_MODE) { |
a0d53889 | 1095 | |
8158c57a | 1096 | $regexp = db_escape_string($_GET["regexp"]); |
648472a7 | 1097 | $match = db_escape_string($_GET["match"]); |
a0d53889 | 1098 | |
648472a7 | 1099 | $result = db_query($link, |
4b3dff6e | 1100 | "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES |
de435974 AD |
1101 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
1102 | description = '$match'))"); | |
1103 | } | |
a0d53889 AD |
1104 | } |
1105 | ||
648472a7 | 1106 | $result = db_query($link, "SELECT description |
a0d53889 AD |
1107 | FROM ttrss_filter_types ORDER BY description"); |
1108 | ||
1109 | $filter_types = array(); | |
1110 | ||
648472a7 | 1111 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1112 | array_push($filter_types, $line["description"]); |
1113 | } | |
1114 | ||
1115 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 1116 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 1117 | <td>"; |
bdc00fe0 | 1118 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
1119 | |
1120 | print"</td><td colspan=\"4\" align=\"right\"> | |
1121 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
1122 | </table>"; | |
1123 | ||
648472a7 | 1124 | $result = db_query($link, "SELECT |
4b3dff6e | 1125 | id,reg_exp,description, |
a0d53889 AD |
1126 | (SELECT name FROM ttrss_filter_types WHERE |
1127 | id = filter_type) as filter_type_name, | |
1128 | (SELECT description FROM ttrss_filter_types | |
1129 | WHERE id = filter_type) as filter_type_descr | |
1130 | FROM | |
4b3dff6e | 1131 | ttrss_filters ORDER by reg_exp"); |
a0d53889 AD |
1132 | |
1133 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
1134 | ||
1135 | print "<tr class=\"title\"> | |
0afbd851 AD |
1136 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
1137 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
1138 | |
1139 | $lnum = 0; | |
1140 | ||
648472a7 | 1141 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1142 | |
1143 | $class = ($lnum % 2) ? "even" : "odd"; | |
1144 | ||
1145 | $filter_id = $line["id"]; | |
1146 | $edit_filter_id = $_GET["id"]; | |
1147 | ||
1148 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
1149 | $class .= "Grayed"; | |
1150 | } | |
1151 | ||
1152 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
1153 | ||
4b3dff6e | 1154 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
1155 | $line["description"] = htmlspecialchars($line["description"]); |
1156 | ||
a0d53889 AD |
1157 | if (!$edit_filter_id || $subop != "edit") { |
1158 | ||
0afbd851 AD |
1159 | if (!$line["description"]) $line["description"] = "[No description]"; |
1160 | ||
a0d53889 AD |
1161 | print "<td><input onclick='toggleSelectRow(this);' |
1162 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
1163 | ||
1164 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 1165 | $line["reg_exp"] . "</td>"; |
a0d53889 AD |
1166 | |
1167 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1168 | $line["description"] . "</td>"; | |
1169 | ||
1170 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1171 | ||
1172 | } else if ($filter_id != $edit_filter_id) { | |
1173 | ||
0afbd851 AD |
1174 | if (!$line["description"]) $line["description"] = "[No description]"; |
1175 | ||
a0d53889 AD |
1176 | print "<td><input disabled=\"true\" type=\"checkbox\" |
1177 | id=\"FICHK-".$line["id"]."\"></td>"; | |
1178 | ||
4b3dff6e | 1179 | print "<td>".$line["reg_exp"]."</td>"; |
a0d53889 AD |
1180 | print "<td>".$line["description"]."</td>"; |
1181 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1182 | ||
1183 | } else { | |
1184 | ||
1185 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1186 | ||
4b3dff6e | 1187 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
1188 | "\"></td>"; |
1189 | ||
1190 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1191 | "\"></td>"; | |
1192 | ||
1193 | print "<td>"; | |
1194 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
1195 | print "</td>"; | |
1196 | ||
1197 | } | |
1198 | ||
1199 | ||
1200 | print "</tr>"; | |
1201 | ||
1202 | ++$lnum; | |
1203 | } | |
1204 | ||
0afbd851 AD |
1205 | if ($lnum == 0) { |
1206 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
1207 | } | |
1208 | ||
a0d53889 AD |
1209 | print "</table>"; |
1210 | ||
1211 | print "<p>"; | |
1212 | ||
1213 | if ($subop == "edit") { | |
e828e31e AD |
1214 | print "Edit feed: |
1215 | <input type=\"submit\" class=\"button\" | |
1216 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1217 | <input type=\"submit\" class=\"button\" | |
1218 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
1219 | |
1220 | } else { | |
1221 | ||
1222 | print " | |
e828e31e AD |
1223 | Selection: |
1224 | <input type=\"submit\" class=\"button\" | |
1225 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
1226 | <input type=\"submit\" class=\"button\" | |
1227 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
1228 | } |
1229 | } | |
1230 | ||
48f0adb0 AD |
1231 | if ($op == "pref-labels") { |
1232 | ||
1233 | $subop = $_GET["subop"]; | |
1234 | ||
1235 | if ($subop == "editSave") { | |
1236 | ||
1237 | $sql_exp = $_GET["s"]; | |
1238 | $descr = $_GET["d"]; | |
1239 | $label_id = db_escape_string($_GET["id"]); | |
1240 | ||
1241 | // print "$sql_exp : $descr : $label_id"; | |
1242 | ||
1243 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1244 | sql_exp = '$sql_exp', | |
1245 | description = '$descr' | |
1246 | WHERE id = '$label_id'"); | |
1247 | } | |
1248 | ||
1249 | if ($subop == "remove") { | |
1250 | ||
1251 | if (!WEB_DEMO_MODE) { | |
1252 | ||
1253 | $ids = split(",", $_GET["ids"]); | |
1254 | ||
1255 | foreach ($ids as $id) { | |
1256 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1257 | ||
1258 | } | |
1259 | } | |
1260 | } | |
1261 | ||
1262 | if ($subop == "add") { | |
1263 | ||
1264 | if (!WEB_DEMO_MODE) { | |
1265 | ||
1266 | $exp = $_GET["exp"]; | |
1267 | ||
1268 | $result = db_query($link, | |
1269 | "INSERT INTO ttrss_labels (sql_exp,description) | |
1270 | VALUES ('$exp', '$exp')"); | |
1271 | } | |
1272 | } | |
1273 | ||
1274 | print "<table class=\"prefAddFeed\"><tr> | |
1275 | <td><input id=\"ladd_expr\"></td>"; | |
1276 | ||
1277 | print"<td colspan=\"4\" align=\"right\"> | |
1278 | <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr> | |
1279 | </table>"; | |
1280 | ||
1281 | $result = db_query($link, "SELECT | |
1282 | id,sql_exp,description | |
1283 | FROM | |
1284 | ttrss_labels ORDER by description"); | |
1285 | ||
1286 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; | |
1287 | ||
1288 | print "<tr class=\"title\"> | |
7dc66a61 AD |
1289 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression |
1290 | <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a> | |
1291 | </td> | |
48f0adb0 AD |
1292 | <td width=\"40%\">Caption</td></tr>"; |
1293 | ||
1294 | $lnum = 0; | |
1295 | ||
1296 | while ($line = db_fetch_assoc($result)) { | |
1297 | ||
1298 | $class = ($lnum % 2) ? "even" : "odd"; | |
1299 | ||
1300 | $label_id = $line["id"]; | |
1301 | $edit_label_id = $_GET["id"]; | |
1302 | ||
1303 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1304 | $class .= "Grayed"; | |
1305 | } | |
1306 | ||
1307 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1308 | ||
1309 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1310 | $line["description"] = htmlspecialchars($line["description"]); | |
1311 | ||
1312 | if (!$edit_label_id || $subop != "edit") { | |
1313 | ||
1314 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1315 | ||
1316 | print "<td><input onclick='toggleSelectRow(this);' | |
1317 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1318 | ||
1319 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1320 | $line["sql_exp"] . "</td>"; | |
1321 | ||
1322 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1323 | $line["description"] . "</td>"; | |
1324 | ||
1325 | } else if ($label_id != $edit_label_id) { | |
1326 | ||
1327 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1328 | ||
1329 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1330 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1331 | ||
1332 | print "<td>".$line["sql_exp"]."</td>"; | |
1333 | print "<td>".$line["description"]."</td>"; | |
1334 | ||
1335 | } else { | |
1336 | ||
1337 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1338 | ||
1339 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1340 | "\"></td>"; | |
1341 | ||
1342 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1343 | "\"></td>"; | |
1344 | ||
1345 | } | |
1346 | ||
1347 | ||
1348 | print "</tr>"; | |
1349 | ||
1350 | ++$lnum; | |
1351 | } | |
1352 | ||
1353 | if ($lnum == 0) { | |
1354 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1355 | } | |
1356 | ||
1357 | print "</table>"; | |
1358 | ||
1359 | print "<p>"; | |
1360 | ||
1361 | if ($subop == "edit") { | |
1362 | print "Edit label: | |
1363 | <input type=\"submit\" class=\"button\" | |
1364 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1365 | <input type=\"submit\" class=\"button\" | |
1366 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1367 | ||
1368 | } else { | |
1369 | ||
1370 | print " | |
1371 | Selection: | |
1372 | <input type=\"submit\" class=\"button\" | |
1373 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
1374 | <input type=\"submit\" class=\"button\" | |
1375 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
1376 | } | |
1377 | } | |
1378 | ||
e828e31e AD |
1379 | if ($op == "error") { |
1380 | print "<div width=\"100%\" align='center'>"; | |
1381 | $msg = $_GET["msg"]; | |
1382 | print $msg; | |
1383 | print "</div>"; | |
1384 | } | |
1385 | ||
7dc66a61 AD |
1386 | if ($op == "help") { |
1387 | print "<html><head> | |
1388 | <title>Tiny Tiny RSS : Help</title> | |
1389 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
1390 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
7dc66a61 AD |
1391 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
1392 | </head><body>"; | |
1393 | ||
1394 | $tid = sprintf("%d", $_GET["tid"]); | |
1395 | ||
1396 | /* FIXME this badly needs real implementation */ | |
1397 | ||
1398 | print "<div class='helpResponse'>"; | |
1399 | ||
1400 | ?> | |
1401 | ||
1402 | <h1>Help for SQL expressions</h1> | |
1403 | ||
1404 | <h2>Description</h2> | |
1405 | ||
1406 | <p>The «SQL expression» is added to WHERE clause of | |
d1f948d1 | 1407 | view feed query. You can match on ttrss_entries table fields |
7dc66a61 AD |
1408 | and even use subselect to query additional information. This |
1409 | functionality is considered to be advanced and requires basic | |
1410 | understanding of SQL.</p> | |
1411 | ||
1412 | <h2>Examples</h2> | |
1413 | ||
1414 | <pre>unread = true</pre> | |
1415 | ||
1416 | Matches all unread articles | |
1417 | ||
1418 | <pre>title like '%Linux%'</pre> | |
1419 | ||
1420 | Matches all articles which mention Linux in the title. You get the idea. | |
1421 | ||
1422 | <p>See the database schema included in the distribution package for gruesome | |
1423 | details.</p> | |
1424 | ||
1425 | <? | |
1426 | ||
1427 | print "<div align='center'> | |
1428 | <a class=\"helpLink\" | |
1429 | href=\"javascript:window.close()\">(Close this window)</a></div>"; | |
1430 | ||
1431 | print "</div>"; | |
1432 | ||
1433 | print "</body></html>"; | |
1434 | ||
1435 | } | |
1436 | ||
f84a97a3 AD |
1437 | if ($op == "dlg") { |
1438 | $id = $_GET["id"]; | |
6de5d056 | 1439 | $param = $_GET["param"]; |
f84a97a3 AD |
1440 | |
1441 | if ($id == "quickAddFeed") { | |
033e47e0 AD |
1442 | print "Feed URL: <input |
1443 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1444 | id=\"qafInput\"> | |
f84a97a3 AD |
1445 | <input class=\"button\" |
1446 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
1447 | <input class=\"button\" | |
1448 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1449 | value=\"Cancel\">"; | |
1450 | } | |
6de5d056 AD |
1451 | |
1452 | if ($id == "quickDelFeed") { | |
1453 | ||
1454 | $param = db_escape_string($param); | |
1455 | ||
1456 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
1457 | ||
1458 | if ($result) { | |
1459 | ||
1460 | $f_title = db_fetch_result($result, 0, "title"); | |
1461 | ||
1462 | print "Remove current feed ($f_title)? | |
1463 | <input class=\"button\" | |
1464 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
1465 | <input class=\"button\" | |
1466 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1467 | value=\"Cancel\">"; | |
1468 | } else { | |
1469 | print "Error: Feed $param not found. | |
1470 | <input class=\"button\" | |
1471 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1472 | value=\"Cancel\">"; | |
1473 | } | |
1474 | } | |
1475 | ||
033e47e0 AD |
1476 | if ($id == "search") { |
1477 | ||
1478 | print "<input id=\"searchbox\" class=\"extSearch\" | |
1479 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1480 | onchange=\"javascript:search()\"> | |
1481 | <select id=\"searchmodebox\"> | |
1482 | <option selected>All feeds</option> | |
1483 | <option>This feed</option> | |
1484 | </select> | |
1485 | <input type=\"submit\" | |
1486 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
1487 | <input class=\"button\" | |
1488 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1489 | value=\"Close\">"; | |
1490 | ||
1491 | } | |
1492 | ||
f84a97a3 AD |
1493 | } |
1494 | ||
e65af9c1 AD |
1495 | if ($op == "updateAllFeeds") { |
1496 | update_all_feeds($link, true); | |
1497 | ||
1498 | print "<rpc-reply>"; | |
1499 | getLabelCounters($link); | |
1500 | getFeedCounters($link); | |
1501 | getTagCounters($link); | |
1502 | getGlobalCounters($link); | |
1503 | print "</rpc-reply>"; | |
1504 | ||
1505 | } | |
1506 | ||
77e96719 AD |
1507 | if ($op == "pref-prefs") { |
1508 | ||
1509 | $subop = $_POST["subop"]; | |
1510 | ||
1511 | if ($subop == "Save configuration") { | |
1512 | ||
1513 | foreach (array_keys($_POST) as $pref_name) { | |
1514 | ||
1515 | $pref_name = db_escape_string($pref_name); | |
1516 | $value = db_escape_string($_POST[$pref_name]); | |
1517 | ||
1518 | $result = db_query($link, "SELECT type_name | |
1519 | FROM ttrss_prefs,ttrss_prefs_types | |
1520 | WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id"); | |
1521 | ||
1522 | if (db_num_rows($result) > 0) { | |
1523 | ||
1524 | $type_name = db_fetch_result($result, 0, "type_name"); | |
1525 | ||
5da169d9 AD |
1526 | // print "$pref_name : $type_name : $value<br>"; |
1527 | ||
77e96719 | 1528 | if ($type_name == "bool") { |
5da169d9 | 1529 | if ($value == "1") { |
77e96719 AD |
1530 | $value = "true"; |
1531 | } else { | |
1532 | $value = "false"; | |
1533 | } | |
1534 | } else if ($type_name == "integer") { | |
1535 | $value = sprintf("%d", $value); | |
1536 | } | |
1537 | ||
1538 | // print "$pref_name : $type_name : $value<br>"; | |
1539 | ||
1540 | db_query($link, "UPDATE ttrss_prefs SET value = '$value' | |
1541 | WHERE pref_name = '$pref_name'"); | |
1542 | ||
1543 | } | |
1544 | ||
1545 | header("Location: prefs.php"); | |
1546 | ||
1547 | } | |
1548 | ||
1549 | } else if ($subop == "Reset to defaults") { | |
1550 | ||
5da169d9 AD |
1551 | db_query($link, "UPDATE ttrss_prefs SET value = def_value"); |
1552 | ||
77e96719 AD |
1553 | header("Location: prefs.php"); |
1554 | ||
1555 | } else { | |
1556 | ||
1557 | $result = db_query($link, "SELECT | |
1558 | pref_name,short_desc,help_text,value,type_name, | |
1559 | section_name,def_value | |
1560 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections | |
1561 | WHERE type_id = ttrss_prefs_types.id AND | |
1562 | section_id = ttrss_prefs_sections.id | |
1563 | ORDER BY section_name,short_desc"); | |
1564 | ||
1565 | print "<form action=\"backend.php\" method=\"POST\">"; | |
1566 | ||
1567 | print "<table width=\"100%\" class=\"prefPrefsList\">"; | |
1568 | ||
1569 | $lnum = 0; | |
1570 | ||
1571 | $active_section = ""; | |
1572 | ||
1573 | while ($line = db_fetch_assoc($result)) { | |
1574 | ||
1575 | if ($active_section != $line["section_name"]) { | |
59a654ba AD |
1576 | |
1577 | if ($active_section != "") { | |
1578 | print "</table><p><table width=\"100%\" class=\"prefPrefsList\">"; | |
1579 | } | |
1580 | ||
1581 | $active_section = $line["section_name"]; | |
1582 | ||
77e96719 | 1583 | print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>"; |
59a654ba AD |
1584 | // print "<tr class=\"title\"> |
1585 | // <td width=\"25%\">Option</td><td>Value</td></tr>"; | |
77e96719 AD |
1586 | } |
1587 | ||
1588 | $class = ($lnum % 2) ? "even" : "odd"; | |
1589 | ||
1590 | print "<tr class=\"$class\">"; | |
1591 | ||
1592 | print "<td width=\"40%\">" . $line["short_desc"] . "</td>"; | |
1593 | ||
1594 | $type_name = $line["type_name"]; | |
1595 | $pref_name = $line["pref_name"]; | |
1596 | $value = $line["value"]; | |
1597 | $def_value = $line["def_value"]; | |
1598 | ||
1599 | print "<td>"; | |
1600 | ||
1601 | if ($type_name == "bool") { | |
1602 | // print_select($pref_name, $value, array("true", "false")); | |
1603 | ||
1604 | if ($value == "true") { | |
1605 | $value = "Yes"; | |
1606 | } else { | |
1607 | $value = "No"; | |
1608 | } | |
1609 | ||
1610 | print_radio($pref_name, $value, array("Yes", "No")); | |
1611 | ||
1612 | } else { | |
1613 | print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">"; | |
1614 | } | |
1615 | ||
1616 | print "</td>"; | |
1617 | ||
1618 | print "</tr>"; | |
1619 | ||
1620 | $lnum++; | |
1621 | } | |
1622 | ||
1623 | print "</table>"; | |
1624 | ||
1625 | print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">"; | |
1626 | ||
1627 | print "<p><input class=\"button\" type=\"submit\" | |
1628 | name=\"subop\" value=\"Save configuration\">"; | |
1629 | ||
1630 | print " <input class=\"button\" type=\"submit\" | |
1631 | name=\"subop\" value=\"Reset to defaults\"></p>"; | |
1632 | ||
1633 | print "</form>"; | |
1634 | ||
1635 | } | |
1636 | ||
1637 | } | |
1638 | ||
4b3dff6e | 1639 | db_close($link); |
1cd17194 | 1640 | ?> |
406d9489 AD |
1641 | |
1642 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
1643 |