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