]> git.wh0rd.org Git - tt-rss.git/blob - modules/pref-feeds.php
interface tweaks, add info/question/exclamation pics
[tt-rss.git] / modules / pref-feeds.php
1 <?php
2
3         function module_pref_feeds($link) {
4
5                 global $update_intervals;
6                 global $purge_intervals;
7
8                 $subop = $_REQUEST["subop"];
9                 $quiet = $_REQUEST["quiet"];
10
11                 if ($subop == "massSubscribe") {
12                         $ids = split(",", db_escape_string($_GET["ids"]));
13
14                         $subscribed = array();
15
16                         foreach ($ids as $id) {
17                                 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
18                                         WHERE id = '$id'");
19
20                                 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
21                                 $title = db_escape_string(db_fetch_result($result, 0, "title"));
22
23                                 $title_orig = db_fetch_result($result, 0, "title");
24
25                                 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
26                                         feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
27
28                                 if (db_num_rows($result) == 0) {                        
29                                         $result = db_query($link,
30                                                 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) 
31                                                 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
32
33                                         array_push($subscribed, $title_orig);
34                                 }
35                         }
36
37                         if (count($subscribed) > 0) {
38                                 $msg = "<b>Subscribed to feeds:</b>".
39                                         "<ul class=\"nomarks\">";
40
41                                 foreach ($subscribed as $title) {
42                                         $msg .= "<li>$title</li>";
43                                 }
44                                 $msg .= "</ul>";
45
46                                 print format_notice($msg);
47                         }
48                 }               
49
50                 if ($subop == "browse") {
51
52                         if (!ENABLE_FEED_BROWSER) {
53                                 print "Feed browser is administratively disabled.";
54                                 return;
55                         }
56
57                         print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>";
58                         
59                         print "<div class=\"infoBoxContents\">";
60
61                         print "<p>Showing top 25 registered feeds, sorted by popularity:</p>";
62
63 #                       $result = db_query($link, "SELECT feed_url,count(id) AS subscribers 
64 #                               FROM ttrss_feeds 
65 #                               WHERE auth_login = '' AND auth_pass = '' AND private = false
66 #                               GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
67
68                         $owner_uid = $_SESSION["uid"];
69
70                         $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
71                                 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf 
72                                         WHERE tf.feed_url = ttrss_feeds.feed_url 
73                                                 AND owner_uid = '$owner_uid') GROUP BY feed_url 
74                                                         ORDER BY subscribers DESC LIMIT 25");
75
76                         print "<ul class='browseFeedList' id='browseFeedList'>";
77
78                         $feedctr = 0;
79                         
80                         while ($line = db_fetch_assoc($result)) {
81                                 $feed_url = $line["feed_url"];
82                                 $subscribers = $line["subscribers"];
83
84                                 $det_result = db_query($link, "SELECT site_url,title,id 
85                                         FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
86
87                                 $details = db_fetch_assoc($det_result);
88                         
89                                 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
90
91                                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
92                                                 $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . 
93                                                         "/".$details["id"].".ico\">";
94                                 } else {
95                                         $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
96                                 }
97
98                                 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB' 
99                                         type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
100
101                                 $class = ($feedctr % 2) ? "even" : "odd";
102
103                                 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
104                                         "$feed_icon " . db_unescape_string($details["title"]) . 
105                                         "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
106
107                                         ++$feedctr;
108                         }
109
110                         if ($feedctr == 0) {
111                                 print "<li>No feeds found to subscribe.</li>";
112                         }
113
114                         print "</ul>";
115
116                         print "<div align='center'>
117                                 <input type=\"submit\" class=\"button\" 
118                                 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
119                                 <input type='submit' class='button'                     
120                                 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
121
122                         print "</div>";
123                         return;
124                 }
125
126                 if ($subop == "editfeed") {
127                         $feed_id = db_escape_string($_REQUEST["id"]);
128
129                         $result = db_query($link, 
130                                 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
131                                         owner_uid = " . $_SESSION["uid"]);
132
133                         $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
134                                 0, "title")));
135
136                         $icon_file = ICONS_DIR . "/$feed_id.ico";
137         
138                         if (file_exists($icon_file) && filesize($icon_file) > 0) {
139                                         $feed_icon = "<img width=\"16\" height=\"16\"
140                                                 src=\"" . ICONS_URL . "/$feed_id.ico\">";
141                         } else {
142                                 $feed_icon = "";
143                         }
144
145                         print "<div id=\"infoBoxTitle\">Feed editor</div>";
146
147                         print "<div class=\"infoBoxContents\">";
148
149                         print "<form id=\"edit_feed_form\">";   
150
151                         print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
152                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
153                         print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
154
155                         print "<table width='100%'>";
156
157                         print "<tr><td>Title:</td>";
158                         print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
159                                 name=\"title\" value=\"$title\"></td></tr>";
160
161                         $feed_url = db_fetch_result($result, 0, "feed_url");
162                         $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
163                                 0, "feed_url")));
164                                 
165                         print "<tr><td>Feed URL:</td>";
166                         print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
167                                 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
168
169                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
170
171                                 $cat_id = db_fetch_result($result, 0, "cat_id");
172
173                                 print "<tr><td>Category:</td>";
174                                 print "<td>";
175
176                                 $parent_feed = db_fetch_result($result, 0, "parent_feed");
177
178                                 if (sprintf("%d", $parent_feed) > 0) {
179                                         $disabled = "disabled";
180                                 } else {
181                                         $disabled = "";
182                                 }
183
184                                 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled");
185
186                                 print "</td>";
187                                 print "</td></tr>";
188         
189                         }
190
191                         $update_interval = db_fetch_result($result, 0, "update_interval");
192
193                         print "<tr><td>Update Interval:</td>";
194
195                         print "<td>";
196
197                         print_select_hash("update_interval", $update_interval, $update_intervals,
198                                 "class=\"iedit\"");
199
200                         print "</td>";
201
202                         print "<tr><td>Link to:</td><td>";
203
204                         $tmp_result = db_query($link, "SELECT COUNT(id) AS count
205                                 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
206
207                         $linked_count = db_fetch_result($tmp_result, 0, "count");
208
209                         $parent_feed = db_fetch_result($result, 0, "parent_feed");
210
211                         if ($linked_count > 0) {
212                                 $disabled = "disabled";
213                         } else {
214                                 $disabled = "";
215                         }
216
217                         print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
218                         
219                         print "<option value=\"0\">Not linked</option>";
220
221                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
222                                 if ($cat_id) {
223                                         $cat_qpart = "AND cat_id = '$cat_id'";
224                                 } else {
225                                         $cat_qpart = "AND cat_id IS NULL";
226                                 }
227                         }
228
229                         $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
230                                 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
231                                         (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
232                                         $cat_qpart ORDER BY title");
233
234                                 if (db_num_rows($tmp_result) > 0) {
235                                         print "<option disabled>--------</option>";
236                                 }
237
238                                 while ($tmp_line = db_fetch_assoc($tmp_result)) {
239                                         if ($tmp_line["id"] == $parent_feed) {
240                                                 $is_selected = "selected";
241                                         } else {
242                                                 $is_selected = "";
243                                         }
244                                         printf("<option $is_selected value='%d'>%s</option>", 
245                                                 $tmp_line["id"], $tmp_line["title"]);
246                                 }
247
248                         print "</select>";
249                         print "</td></tr>";
250
251                         $purge_interval = db_fetch_result($result, 0, "purge_interval");
252
253                         print "<tr><td>Article purging:</td>";
254
255                         print "<td>";
256
257                         print_select_hash("purge_interval", $purge_interval, $purge_intervals, 
258                                 "class=\"iedit\"");
259                         
260                         print "</td>";
261
262                         $auth_login = escape_for_form(db_fetch_result($result, 0, "auth_login"));
263
264                         print "<tr><td>Login:</td>";
265                         print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event, feedEditSave)\"
266                                 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
267
268                         $auth_pass = escape_for_form(db_fetch_result($result, 0, "auth_pass"));
269
270                         print "<tr><td>Password:</td>";
271                         print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\" 
272                                 onkeypress=\"return filterCR(event, feedEditSave)\"
273                                 value=\"$auth_pass\"></td></tr>";
274
275                         $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
276
277                         if ($private) {
278                                 $checked = "checked";
279                         } else {
280                                 $checked = "";
281                         }
282
283                         print "<tr><td valign='top'>Options:</td>";
284                         print "<td><input type=\"checkbox\" name=\"private\" id=\"private\" 
285                                 $checked><label for=\"private\">Hide from \"Other Feeds\"</label>";
286
287                         $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
288
289                         if ($rtl_content) {
290                                 $checked = "checked";
291                         } else {
292                                 $checked = "";
293                         }
294
295                         print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
296                                 $checked><label for=\"rtl_content\">Right-to-left content</label>";
297
298                         $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
299
300                         if ($hidden) {
301                                 $checked = "checked";
302                         } else {
303                                 $checked = "";
304                         }
305
306                         print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
307                                 $checked><label for=\"hidden\">Hide from my feed list</label>";
308
309                         $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
310
311                         if ($include_in_digest) {
312                                 $checked = "checked";
313                         } else {
314                                 $checked = "";
315                         }
316
317                         print "<br><input type=\"checkbox\" id=\"include_in_digest\" 
318                                 name=\"include_in_digest\"
319                                 $checked><label for=\"include_in_digest\">Include in e-mail digest</label>";
320
321                         print "</td></tr>";
322
323                         print "</table>";
324
325                         print "</form>";
326
327                         print "<div align='right'>
328                                 <input type=\"submit\" class=\"button\" 
329                                 onclick=\"return feedEditSave()\" value=\"Save\">
330                                 <input type='submit' class='button'                     
331                                 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
332
333                         print "</div>";
334
335                         return;
336                 }
337
338                 if ($subop == "editSave") {
339
340                         $feed_title = db_escape_string(trim($_POST["title"]));
341                         $feed_link = db_escape_string(trim($_POST["feed_url"]));
342                         $upd_intl = db_escape_string($_POST["update_interval"]);
343                         $purge_intl = db_escape_string($_POST["purge_interval"]);
344                         $feed_id = db_escape_string($_POST["id"]);
345                         $cat_id = db_escape_string($_POST["cat_id"]);
346                         $auth_login = db_escape_string(trim($_POST["auth_login"]));
347                         $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
348                         $parent_feed = db_escape_string($_POST["parent_feed"]);
349                         $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
350                         $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
351                         $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
352                         $include_in_digest = checkbox_to_sql_bool(
353                                 db_escape_string($_POST["include_in_digest"]));
354
355                         if (get_pref($link, 'ENABLE_FEED_CATS')) {                      
356                                 if ($cat_id && $cat_id != 0) {
357                                         $category_qpart = "cat_id = '$cat_id',";
358                                         $category_qpart_nocomma = "cat_id = '$cat_id'";
359                                 } else {
360                                         $category_qpart = 'cat_id = NULL,';
361                                         $category_qpart_nocomma = 'cat_id = NULL';
362                                 }
363                         } else {
364                                 $category_qpart = "";
365                                 $category_qpart_nocomma = "";
366                         }
367
368                         if ($parent_feed && $parent_feed != 0) {
369                                 $parent_qpart = "parent_feed = '$parent_feed'";
370                         } else {
371                                 $parent_qpart = 'parent_feed = NULL';
372                         }
373
374                         $result = db_query($link, "UPDATE ttrss_feeds SET 
375                                 $category_qpart $parent_qpart,
376                                 title = '$feed_title', feed_url = '$feed_link',
377                                 update_interval = '$upd_intl',
378                                 purge_interval = '$purge_intl',
379                                 auth_login = '$auth_login',
380                                 auth_pass = '$auth_pass',
381                                 private = $private,
382                                 rtl_content = $rtl_content,
383                                 hidden = $hidden,
384                                 include_in_digest = $include_in_digest
385                                 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
386
387                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
388                                 # update linked feed categories
389                                 $result = db_query($link, "UPDATE ttrss_feeds SET
390                                         $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
391                                         owner_uid = " . $_SESSION["uid"]);
392                         }
393                 }
394
395                 if ($subop == "remove") {
396
397                         if (!WEB_DEMO_MODE) {
398
399                                 $ids = split(",", db_escape_string($_GET["ids"]));
400
401                                 foreach ($ids as $id) {
402
403                                         if ($id > 0) {
404
405                                                 db_query($link, "DELETE FROM ttrss_feeds 
406                                                         WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
407
408                                                 $icons_dir = ICONS_DIR;
409                                         
410                                                 if (file_exists($icons_dir . "/$id.ico")) {
411                                                         unlink($icons_dir . "/$id.ico");
412                                                 }
413                                         } else if ($id < -10) {
414
415                                                 $label_id = -$id - 11;
416
417                                                 db_query($link, "DELETE FROM ttrss_labels
418                                                         WHERE   id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
419                                         }
420                                 }
421                         }
422                 }
423
424                 if ($subop == "add") {
425                 
426                         if (!WEB_DEMO_MODE) {
427
428                                 $feed_url = db_escape_string(trim($_GET["feed_url"]));
429                                 $cat_id = db_escape_string($_GET["cat_id"]);
430                                 $p_from = db_escape_string($_GET["from"]);
431
432                                 if ($p_from != 'tt-rss') {
433                                         print "<html>
434                                                 <head>
435                                                         <title>Tiny Tiny RSS - Subscribe to feed...</title>
436                                                         <link rel=\"stylesheet\" type=\"text/css\" href=\"quicksub.css\">
437                                                 </head>
438                                                 <body>
439                                                 <img class=\"logo\" src=\"images/ttrss_logo.png\"
440                                                         alt=\"Tiny Tiny RSS\"/> 
441                                                 <h1>Subscribe to feed...</h1>
442                                                 <div class=\"content\">";
443                                 }
444
445                                 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
446                                         print format_notice("Subscribed to <b>$feed_url</b>.");
447                                 } else {
448                                         print format_warning("Already subscribed to <b>$feed_url</b>.");
449                                 }
450
451                                 if ($p_from != 'tt-rss') {
452                                         $tt_uri = 'http://' . $_SERVER['SERVER_NAME'] . 
453                                                 preg_replace('/backend\.php.*$/', 
454                                                         'tt-rss.php', $_SERVER["REQUEST_URI"]);
455
456                                         $tp_uri = 'http://' . $_SERVER['SERVER_NAME'] . 
457                                                 preg_replace('/backend\.php.*$/', 
458                                                         'prefs.php', $_SERVER["REQUEST_URI"]);
459
460                                         print "<p><a href='$tt_uri'>Return to Tiny Tiny RSS</a> |";
461
462                                         $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
463                                                 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
464
465                                         $feed_id = db_fetch_result($result, 0, "id");
466
467                                         if ($feed_id) {
468                                                 print "<a href='$tp_uri?tab=feedConfig&subop=editFeed:$feed_id'>
469                                                         Edit subscription options</a> | ";
470                                         }
471
472                                         print "<a href='javascript:window.close()'>Close this window</a>.</p>";
473
474                                         print "</div></body></html>";
475                                         return;
476                                 }
477                         }
478                 }
479
480                 if ($subop == "categorize") {
481
482                         if (!WEB_DEMO_MODE) {
483
484                                 $ids = split(",", db_escape_string($_GET["ids"]));
485
486                                 $cat_id = db_escape_string($_GET["cat_id"]);
487
488                                 if ($cat_id == 0) {
489                                         $cat_id_qpart = 'NULL';
490                                 } else {
491                                         $cat_id_qpart = "'$cat_id'";
492                                 }
493
494                                 db_query($link, "BEGIN");
495
496                                 foreach ($ids as $id) {
497                                 
498                                         db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
499                                                 WHERE id = '$id' AND parent_feed IS NULL
500                                                 AND owner_uid = " . $_SESSION["uid"]);
501
502                                         # update linked feed categories
503                                         db_query($link, "UPDATE ttrss_feeds SET
504                                                 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND 
505                                                 owner_uid = " . $_SESSION["uid"]);
506
507                                 }
508
509                                 db_query($link, "COMMIT");
510                         }
511
512                 }
513
514                 if ($subop == "editCats") {
515
516                         print "<div id=\"infoBoxTitle\">Category editor</div>";
517                         
518                         print "<div class=\"infoBoxContents\">";
519
520                         $action = $_REQUEST["action"];
521
522                         if ($action == "save") {
523
524                                 $cat_title = db_escape_string(trim($_GET["title"]));
525                                 $cat_id = db_escape_string($_GET["id"]);
526         
527                                 $result = db_query($link, "UPDATE ttrss_feed_categories SET
528                                         title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
529         
530                         }
531
532                         if ($action == "add") {
533
534                                 if (!WEB_DEMO_MODE) {
535         
536                                         $feed_cat = db_escape_string(trim($_GET["cat"]));
537         
538                                         $result = db_query($link,
539                                                 "SELECT id FROM ttrss_feed_categories
540                                                 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
541         
542                                         if (db_num_rows($result) == 0) {
543                                                 
544                                                 $result = db_query($link,
545                                                         "INSERT INTO ttrss_feed_categories (owner_uid,title) 
546                                                         VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
547         
548                                         } else {
549         
550                                                 print format_warning("Category <b>$feed_cat</b> already exists in the database.");
551                                         }
552
553                                 }
554                         }
555
556                         if ($action == "remove") {
557         
558                                 if (!WEB_DEMO_MODE) {
559         
560                                         $ids = split(",", db_escape_string($_GET["ids"]));
561         
562                                         foreach ($ids as $id) {
563         
564                                                 db_query($link, "BEGIN");
565         
566                                                 $result = db_query($link, 
567                                                         "SELECT count(id) as num_feeds FROM ttrss_feeds 
568                                                                 WHERE cat_id = '$id'");
569         
570                                                 $num_feeds = db_fetch_result($result, 0, "num_feeds");
571         
572                                                 if ($num_feeds == 0) {
573                                                         db_query($link, "DELETE FROM ttrss_feed_categories
574                                                                 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
575                                                 } else {
576         
577                                                         print format_warning("Unable to delete non empty feed categories.");
578                                                                 
579                                                 }
580         
581                                                 db_query($link, "COMMIT");
582                                         }
583                                 }
584                         }
585
586                         print "<div class=\"prefGenericAddBox\">
587                                 <input id=\"fadd_cat\" 
588                                         onkeypress=\"return filterCR(event, addFeedCat)\"
589                                         onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
590                                         onchange=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
591                                         size=\"40\">&nbsp;
592                                 <input 
593                                         type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
594                                         onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
595         
596                         $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
597                                 WHERE owner_uid = ".$_SESSION["uid"]."
598                                 ORDER BY title");
599
600                         print "<p>";
601
602                         if (db_num_rows($result) != 0) {
603
604                                 print "<table width=\"100%\" class=\"prefFeedCatList\" 
605                                         cellspacing=\"0\">";
606
607                                 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
608                                 Select: 
609                                         <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
610                                         <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
611                                         </td></tr>";
612
613                                 print "</table>";
614
615                                 print "<div class=\"prefFeedCatHolder\">";
616
617                                 print "<form id=\"feed_cat_edit_form\">";
618
619                                 print "<table width=\"100%\" class=\"prefFeedCatList\" 
620                                         cellspacing=\"0\" id=\"prefFeedCatList\">";
621
622 /*                              print "<tr class=\"title\">
623                                                         <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
624                                                         </tr>"; */
625                                                 
626                                 $lnum = 0;
627                                 
628                                 while ($line = db_fetch_assoc($result)) {
629                 
630                                         $class = ($lnum % 2) ? "even" : "odd";
631                 
632                                         $cat_id = $line["id"];
633                 
634                                         $edit_cat_id = $_GET["id"];
635
636                                         if ($action == "edit" && $cat_id == $edit_cat_id) {
637                                                 $class .= "Selected";
638                                                 $this_row_id = "";
639                                         } else if ($action == "edit" && $cat_id != $edit_cat_id) {
640                                                 $class .= "Grayed";
641                                                 $this_row_id = "";
642                                         } else {
643                                                 $this_row_id = "id=\"FCATR-$cat_id\"";
644                                         }
645                 
646                                         print "<tr class=\"$class\" $this_row_id>";
647                 
648                                         $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
649                 
650                                         if (!$edit_cat_id || $action != "edit") {
651                 
652                                                 print "<td width='5%' align='center'><input 
653                                                         onclick='toggleSelectPrefRow(this, \"fcat\");' 
654                                                         type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
655                 
656                                                 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" . 
657                                                         $edit_title . "</a></td>";              
658                 
659                                         } else if ($cat_id != $edit_cat_id) {
660                 
661                                                 print "<td width='5%' align='center'><input disabled=\"true\" type=\"checkbox\" 
662                                                         id=\"FRCHK-".$line["id"]."\"></td>";
663                 
664                                                 print "<td>$edit_title</td>";           
665                 
666                                         } else {
667                 
668                                                 print "<td width='5%' align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
669                                                 
670                                                 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
671                                                 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
672                                                 print "<input type=\"hidden\" name=\"subop\" value=\"editCats\">";
673                                                 print "<input type=\"hidden\" name=\"action\" value=\"save\">";
674                                 
675                                                 print "</td>";
676                 
677                                                 print "<td><input onkeypress=\"return filterCR(event, feedCatEditSave)\"
678                                                         name=\"title\" size=\"40\" value=\"$edit_title\"></td>";
679                                                 
680                                         }
681                                         
682                                         print "</tr>";
683                 
684                                         ++$lnum;
685                                 }
686         
687                                 print "</table>";
688
689                                 print "</form>";
690
691                                 print "</div>";
692
693                         } else {
694                                 print "<p>No feed categories defined.</p>";
695                         }
696
697                         print "<div style='float : right'>
698                                 <input type='submit' class='button'                     
699                                 onclick=\"selectTab('feedConfig')\" value=\"Close this window\"></div>";
700
701                         print "<div id=\"catOpToolbar\">";
702         
703                         if ($action == "edit") {
704                                 print "<input type=\"submit\" class=\"button\"
705                                                 onclick=\"return feedCatEditSave()\" value=\"Save\">
706                                         <input type=\"submit\" class=\"button\"
707                                                 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
708                         } else {
709
710                                 print "
711                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
712                                         onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
713                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
714                                         onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
715                         }
716
717                         print "</div>";
718
719                         print "</div>";
720
721                         return;
722
723                 }
724
725                 if ($quiet) return;
726
727                 $result = db_query($link, "SELECT COUNT(id) AS num_errors
728                         FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
729
730                 $num_errors = db_fetch_result($result, 0, "num_errors");
731
732                 if ($num_errors > 0) {
733
734                         print "<a href=\"javascript:showFeedsWithErrors()\" 
735                                 class=\"feedUpdErrLink\">Some feeds have update errors (click 
736                                 for details)</a>";
737                 }
738
739                 $feed_search = db_escape_string($_GET["search"]);
740
741                 if (array_key_exists("search", $_GET)) {
742                         $_SESSION["prefs_feed_search"] = $feed_search;
743                 } else {
744                         $feed_search = $_SESSION["prefs_feed_search"];
745                 }
746
747                 print "<div class=\"feedEditSearch\">
748                         <input id=\"feed_search\" size=\"20\"  
749                                 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
750                         <input type=\"submit\" class=\"button\" 
751                                 onclick=\"javascript:updateFeedList()\" value=\"Search\">
752                         </div>";
753
754                 print "<div class=\"prefGenericAddBox\">
755                         <input id=\"fadd_link\" 
756                                 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
757                                 onchange=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
758                                 size=\"40\">
759                         <input type=\"submit\" class=\"button\"
760                                 disabled=\"true\" id=\"fadd_submit_btn\"
761                                 onclick=\"addFeed()\" value=\"Subscribe\">";
762
763                 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
764                         print " <input type=\"submit\" class=\"button\"
765                                 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
766                 }
767
768                 print "</div>";
769
770                 $feeds_sort = db_escape_string($_GET["sort"]);
771
772                 if (!$feeds_sort || $feeds_sort == "undefined") {
773                         $feeds_sort = $_SESSION["pref_sort_feeds"];                     
774                         if (!$feeds_sort) $feeds_sort = "title";
775                 }
776
777                 $_SESSION["pref_sort_feeds"] = $feeds_sort;
778
779                 if ($feed_search) {
780                         $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
781                                 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
782                 } else {
783                         $search_qpart = "";
784                 }
785
786                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
787                         $order_by_qpart = "category,$feeds_sort,title";
788                 } else {
789                         $order_by_qpart = "$feeds_sort,title";
790                 }
791
792                 $result = db_query($link, "SELECT 
793                                 F1.id,
794                                 F1.title,
795                                 F1.feed_url,
796                                 substring(F1.last_updated,1,16) AS last_updated,
797                                 F1.parent_feed,
798                                 F1.update_interval,
799                                 F1.purge_interval,
800                                 F1.cat_id,
801                                 F2.title AS parent_title,
802                                 C1.title AS category,
803                                 F1.hidden,
804                                 F1.include_in_digest,
805                                 (SELECT SUBSTRING(MAX(updated),1,16) FROM ttrss_user_entries, 
806                                         ttrss_entries WHERE ref_id = ttrss_entries.id 
807                                         AND feed_id = F1.id) AS last_article
808                         FROM 
809                                 ttrss_feeds AS F1 
810                                 LEFT JOIN ttrss_feeds AS F2
811                                         ON (F1.parent_feed = F2.id)
812                                 LEFT JOIN ttrss_feed_categories AS C1
813                                         ON (F1.cat_id = C1.id)
814                         WHERE 
815                                 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'                     
816                         ORDER by $order_by_qpart");
817
818                 if (db_num_rows($result) != 0) {
819
820 //                      print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
821
822                         print "<p><table width=\"100%\" cellspacing=\"0\" 
823                                 class=\"prefFeedList\" id=\"prefFeedList\">";
824                         print "<tr><td class=\"selectPrompt\" colspan=\"8\">
825                                 Select: 
826                                         <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
827                                         <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
828                                 </td</tr>";
829
830                         if (!get_pref($link, 'ENABLE_FEED_CATS')) {
831                                 print "<tr class=\"title\">
832                                         <td width='5%' align='center'>&nbsp;</td>";
833
834                                 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
835                                         print "<td width='3%'>&nbsp;</td>";
836                                 }
837
838                                 print "
839                                         <td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
840                                         <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
841                                         <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last&nbsp;Article</a></td>
842                                         <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
843                         }
844                         
845                         $lnum = 0;
846
847                         $cur_cat_id = -1;
848                         
849                         while ($line = db_fetch_assoc($result)) {
850         
851                                 $feed_id = $line["id"];
852                                 $cat_id = $line["cat_id"];
853
854                                 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
855                                 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
856                                 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
857
858                                 $hidden = sql_bool_to_bool($line["hidden"]);
859
860                                 if (!$edit_cat) $edit_cat = "Uncategorized";
861
862                                 $last_updated = $line["last_updated"];
863
864                                 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
865                                         $last_updated = smart_date_time(strtotime($last_updated));
866                                 } else {
867                                         $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
868                                         $last_updated = date($short_date, strtotime($last_updated));
869                                 }
870
871                                 $last_article = $line["last_article"];
872
873                                 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
874                                         $last_article = smart_date_time(strtotime($last_article));
875                                 } else {
876                                         $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
877                                         $last_article = date($short_date, strtotime($last_article));
878                                 }
879
880                                 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
881                                         $lnum = 0;
882                                 
883                                         print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
884
885                                         print "<tr class=\"title\">
886                                                 <td width='5%'>&nbsp;</td>";
887
888                                         if (get_pref($link, 'ENABLE_FEED_ICONS')) {
889                                                 print "<td width='3%'>&nbsp;</td>";
890                                         }
891
892                                         print "<td width='35%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
893                                                 <td width='35%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
894                                                 <td width='15%'><a href=\"javascript:updateFeedList('last_article')\">Last&nbsp;Article</a></td>
895                                                 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
896
897                                         $cur_cat_id = $cat_id;
898                                 }
899
900                                 $class = ($lnum % 2) ? "even" : "odd";
901                                 $this_row_id = "id=\"FEEDR-$feed_id\"";
902
903                                 print "<tr class=\"$class\" $this_row_id>";
904         
905                                 $icon_file = ICONS_DIR . "/$feed_id.ico";
906         
907                                 if (file_exists($icon_file) && filesize($icon_file) > 0) {
908                                                 $feed_icon = "<img class=\"tinyFeedIcon\"       src=\"" . ICONS_URL . "/$feed_id.ico\">";
909                                 } else {
910                                         $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
911                                 }
912                                 
913                                 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");' 
914                                 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
915
916                                 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
917                                         print "<td class='feedIcon'>$feed_icon</td>";           
918                                 }
919
920                                 $edit_title = truncate_string($edit_title, 40);
921                                 $edit_link = truncate_string($edit_link, 60);
922
923                                 if ($hidden) {
924                                         $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
925                                         $edit_link = "<span class=\"insensitive\">$edit_link</span>";
926                                         $last_updated = "<span class=\"insensitive\">$last_updated</span>";
927                                         $last_article = "<span class=\"insensitive\">$last_article</span>";
928                                 }
929
930                                 $parent_title = $line["parent_title"];
931                                 if ($parent_title) {
932                                         $parent_title = "<span class='groupPrompt'>(linked to 
933                                                 $parent_title)</span>";
934                                 }
935
936                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
937                                         "$edit_title $parent_title" . "</a></td>";              
938                                         
939                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
940                                         $edit_link . "</a></td>";               
941
942                                 print "<td><a href=\"javascript:editFeed($feed_id);\">" . 
943                                         "$last_article</a></td>";
944
945                                 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" . 
946                                         "$last_updated</a></td>";
947
948                                 print "</tr>";
949         
950                                 ++$lnum;
951                         }
952         
953                         print "</table>";
954
955                         print "<p><span id=\"feedOpToolbar\">";
956         
957                         if ($subop == "edit") {
958                                 print "Edit feed:&nbsp;
959                                         <input type=\"submit\" class=\"button\" 
960                                                 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
961                                         <input type=\"submit\" class=\"button\" 
962                                                 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
963                         } else {
964         
965                                 print "
966                                         Selection:&nbsp;
967                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
968                                         onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
969                                 <input type=\"submit\" class=\"button\" disabled=\"true\"
970                                         onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
971
972                                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
973
974                                         print "&nbsp;|&nbsp;";                          
975
976                                         print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
977
978                                         print " <input type=\"submit\" class=\"button\" disabled=\"true\"
979                                         onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
980
981                                 }
982                                 
983                                 print "</span>";
984
985                                 if (get_pref($link, 'ENABLE_FEED_CATS')) {
986
987                                         print " <input type=\"submit\" class=\"button\"
988                                                 onclick=\"javascript:editFeedCats()\" value=\"Edit categories\">";
989
990 #                                       print "&nbsp;|&nbsp;";                          
991
992                                 }
993
994                                 }
995                 } else {
996
997 //                      print "<p>No feeds defined.</p>";
998
999                 }
1000
1001                 print "<h3>OPML</h3>
1002
1003                 <div style='float : left'>
1004                 <form   enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1005                         File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1006                         <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1007                                 type=\"submit\" value=\"Import\">
1008                                 </form></div>";
1009
1010                 print "&nbsp; or &nbsp;";                               
1011
1012                 print "<input type=\"submit\" 
1013                         class=\"button\" onclick=\"gotoExportOpml()\" 
1014                                 value=\"Export OPML\">";                        
1015
1016         }
1017 ?>