]> git.wh0rd.org - tt-rss.git/blame - backend.php
fix reset to default for mysql
[tt-rss.git] / backend.php
CommitLineData
1cd17194 1<?
4356293a 2 session_start();
090e250b 3
1c7f75ed
AD
4 if (!$_SESSION["uid"]) { exit; }
5
4356293a 6 define(SCHEMA_VERSION, 2);
1cd17194 7
82baad4a 8 require_once "config.php";
648472a7 9 require_once "db.php";
3bac89ad 10 require_once "db-prefs.php";
82baad4a
AD
11 require_once "functions.php";
12 require_once "magpierss/rss_fetch.inc";
1cd17194 13
1c7f75ed
AD
14// $_SESSION["uid"] = PLACEHOLDER_UID; // FIXME: placeholder
15// $_SESSION["name"] = PLACEHOLDER_NAME;
4356293a
AD
16
17 $op = $_REQUEST["op"];
18
19 if ($op == "rpc" || $op == "updateAllFeeds") {
20 header("Content-Type: application/xml");
21 }
22
406d9489
AD
23 $script_started = getmicrotime();
24
648472a7 25 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 26
5136011e
AD
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
648472a7
AD
35 if (DB_TYPE == "pgsql") {
36 pg_query("set client_encoding = 'utf-8'");
37 }
7ec2a838 38
295f9b42 39/*
7ec2a838
AD
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 }
295f9b42
AD
49*/
50
331900c6 51 $fetch = $_GET["fetch"];
175847de 52
8143ae1f
AD
53 /* FIXME this needs reworking */
54
fc69e641
AD
55 function getGlobalCounters($link) {
56 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
4356293a 57 WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
fc69e641
AD
58 $c_id = db_fetch_result($result, 0, "c_id");
59 print "<counter id='global-unread' counter='$c_id'/>";
60 }
61
8143ae1f
AD
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
4356293a 65 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
8143ae1f
AD
66 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
67 UNION
4356293a
AD
68 select tag_name,0 as count FROM ttrss_tags
69 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
8143ae1f
AD
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
090e250b
AD
85 function getLabelCounters($link) {
86
87 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
4356293a 88 WHERE marked = true AND unread = true AND owner_uid = ".$_SESSION["uid"]);
090e250b 89
d61fd764 90 $count = db_fetch_result($result, 0, "count");
090e250b
AD
91
92 print "<label id=\"-1\" counter=\"$count\"/>";
93
4356293a
AD
94 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
95 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
090e250b
AD
96
97 while ($line = db_fetch_assoc($result)) {
98
99 $id = -$line["id"] - 11;
100
101 error_reporting (0);
d61fd764
AD
102
103 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
655be073
AD
104 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
105 owner_uid = ".$_SESSION["uid"]);
090e250b 106
d61fd764 107 $count = db_fetch_result($tmp_result, 0, "count");
090e250b 108
ab3f3f72 109 print "<label id=\"$id\" counter=\"$count\"/>";
090e250b
AD
110
111 error_reporting (E_ERROR | E_WARNING | E_PARSE);
112
113 }
114 }
115
8073cce7
AD
116 function getFeedCounter($link, $id) {
117
118 $result = db_query($link, "SELECT
119 count(id) as count FROM ttrss_entries
4356293a 120 WHERE feed_id = '$id' AND unread = true");
8073cce7
AD
121
122 $count = db_fetch_result($result, 0, "count");
123
124 print "<feed id=\"$id\" counter=\"$count\"/>";
125 }
090e250b 126
8073cce7
AD
127 function getFeedCounters($link) {
128
090e250b
AD
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
4356293a 132 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
090e250b
AD
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
8143ae1f 143 function outputFeedList($link, $tags = false) {
175847de 144
1a66d16e
AD
145 print "<html><head>
146 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
147 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
148
4769ddaf 149 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
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>
1a66d16e
AD
158 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
159 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3745788e 160 </head><body onload=\"init()\">";
254e0e4b
AD
161
162 print "<ul class=\"feedList\" id=\"feedList\">";
163
4356293a
AD
164 $owner_uid = $_SESSION["uid"];
165
8143ae1f 166 if (!$tags) {
254e0e4b 167
8143ae1f 168 /* virtual feeds */
254e0e4b 169
8143ae1f 170 $result = db_query($link, "SELECT count(id) as num_starred
4356293a 171 FROM ttrss_entries WHERE marked = true AND unread = true AND owner_uid = '$owner_uid'");
8143ae1f 172 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 173
3745788e 174 $class = "virt";
8add756a
AD
175
176 if ($num_starred > 0) $class .= "Unread";
177
178 printFeedEntry(-1, $class, "Starred articles", $num_starred,
4668523d 179 "images/mark_set.png", $link);
48f0adb0 180
4769ddaf 181 if (get_pref($link, 'ENABLE_LABELS')) {
8143ae1f
AD
182
183 $result = db_query($link, "SELECT id,sql_exp,description FROM
4356293a 184 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
8143ae1f
AD
185
186 if (db_num_rows($result) > 0) {
187 print "<li><hr></li>";
188 }
189
190 while ($line = db_fetch_assoc($result)) {
48f0adb0 191
8143ae1f
AD
192 error_reporting (0);
193
194 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
655be073
AD
195 WHERE (" . $line["sql_exp"] . ") AND unread = true
196 AND owner_uid = '$owner_uid'");
8143ae1f
AD
197
198 $count = db_fetch_result($tmp_result, 0, "count");
199
3745788e 200 $class = "label";
8143ae1f
AD
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,
4668523d 209 $class, $line["description"], $count, "images/label.png", $link);
8143ae1f
AD
210
211 }
48f0adb0
AD
212 }
213
8143ae1f
AD
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
4356293a 221 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
8143ae1f
AD
222
223 $actid = $_GET["actid"];
224
225 /* real feeds */
226
227 $lnum = 0;
228
229 $total_unread = 0;
230
48f0adb0 231 while ($line = db_fetch_assoc($result)) {
8143ae1f
AD
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";
48f0adb0 242
3745788e 243 $class = "feed";
8143ae1f
AD
244
245 if ($unread > 0) $class .= "Unread";
246
247 if ($actid == $feed_id) {
248 $class .= "Selected";
392d4563 249 }
48f0adb0 250
8143ae1f
AD
251 $total_unread += $unread;
252
4668523d 253 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
8143ae1f
AD
254
255 ++$lnum;
48f0adb0 256 }
8143ae1f 257 } else {
a1a8a2be 258
8143ae1f 259 // tags
a1a8a2be 260
8143ae1f
AD
261 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
262 FROM ttrss_tags,ttrss_entries WHERE
4356293a
AD
263 post_id = ttrss_entries.id AND unread = true
264 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
8143ae1f 265 UNION
4356293a 266 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'");
8143ae1f
AD
267
268 $tags = array();
269
270 while ($line = db_fetch_assoc($result)) {
271 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 272 }
8143ae1f
AD
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
4668523d 284 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
8143ae1f
AD
285
286 }
1a66d16e 287
e828e31e 288 }
82baad4a 289
dc33ec95 290 if (db_num_rows($result) == 0) {
4356293a 291 print "<li>No tags/feeds to display.</li>";
dc33ec95
AD
292 }
293
8143ae1f 294 print "</ul>";
1cd17194 295
caa4e57f
AD
296 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
297
c3b81db0
AD
298 }
299
300
301 if ($op == "rpc") {
302
303 $subop = $_GET["subop"];
304
090e250b 305 if ($subop == "getLabelCounters") {
8073cce7 306 $aid = $_GET["aid"];
090e250b
AD
307 print "<rpc-reply>";
308 getLabelCounters($link);
8073cce7
AD
309 if ($aid) {
310 getFeedCounter($link, $aid);
311 }
090e250b
AD
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);
8143ae1f 325 getTagCounters($link);
fc69e641 326 getGlobalCounters($link);
090e250b 327 print "</rpc-reply>";
090e250b
AD
328 }
329
f4c10d44
AD
330 if ($subop == "mark") {
331 $mark = $_GET["mark"];
648472a7 332 $id = db_escape_string($_GET["id"]);
f4c10d44
AD
333
334 if ($mark == "1") {
335 $mark = "true";
336 } else {
337 $mark = "false";
338 }
339
648472a7 340 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
f4c10d44
AD
341 WHERE id = '$id'");
342 }
343
caa4e57f 344 if ($subop == "updateFeed") {
648472a7 345 $feed_id = db_escape_string($_GET["feed"]);
9cfc649a 346
648472a7 347 $result = db_query($link,
caa4e57f 348 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
9cfc649a 349
648472a7
AD
350 if (db_num_rows($result) > 0) {
351 $feed_url = db_fetch_result($result, 0, "feed_url");
caa4e57f
AD
352// update_rss_feed($link, $feed_url, $feed_id);
353 }
9cfc649a 354
caa4e57f 355 print "DONE-$feed_id";
9cfc649a 356
caa4e57f 357 return;
9cfc649a
AD
358 }
359
090e250b 360 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
c5142cca 361
c3b81db0 362 update_all_feeds($link, true);
c3b81db0 363
ab3f3f72
AD
364 $omode = $_GET["omode"];
365
366 if (!$omode) $omode = "tfl";
367
090e250b 368 print "<rpc-reply>";
ab3f3f72
AD
369 if (strchr($omode, "l")) getLabelCounters($link);
370 if (strchr($omode, "f")) getFeedCounters($link);
371 if (strchr($omode, "t")) getTagCounters($link);
fc69e641 372 getGlobalCounters($link);
090e250b 373 print "</rpc-reply>";
c3b81db0
AD
374 }
375
376 if ($subop == "catchupPage") {
377
378 $ids = split(",", $_GET["ids"]);
379
380 foreach ($ids as $id) {
381
648472a7 382 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
c3b81db0
AD
383 WHERE id = '$id'");
384
385 }
386
387 print "Marked active page as read.";
388 }
295f9b42
AD
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 }
c3b81db0
AD
404 }
405
406 if ($op == "feeds") {
407
8143ae1f
AD
408 $tags = $_GET["tags"];
409
c3b81db0
AD
410 $subop = $_GET["subop"];
411
412 if ($subop == "catchupAll") {
648472a7 413 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
c3b81db0
AD
414 }
415
8143ae1f 416 outputFeedList($link, $tags);
c3b81db0 417
1cd17194
AD
418 }
419
420 if ($op == "view") {
421
d76a3b03 422 $id = $_GET["id"];
8073cce7 423 $feed_id = $_GET["feed"];
d76a3b03 424
648472a7 425 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
a1a8a2be 426
70830c87
AD
427 $addheader = $_GET["addheader"];
428
648472a7 429 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
b7f4bda2
AD
430 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
431 FROM ttrss_entries
d76a3b03 432 WHERE id = '$id'");
1cd17194 433
70830c87 434 if ($addheader) {
f0601b87 435 print "<html><head>
70830c87
AD
436 <title>Tiny Tiny RSS : Article $id</title>
437 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
c05608c2 438 <script type=\"text/javascript\" src=\"functions.js\"></script>
70830c87 439 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87 440 </head><body>";
70830c87
AD
441 }
442
d76a3b03 443 if ($result) {
1cd17194 444
648472a7 445 $line = db_fetch_assoc($result);
1cd17194 446
b7f4bda2
AD
447 if ($line["icon_url"]) {
448 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
449 } else {
450 $feed_icon = "&nbsp;";
451 }
d76a3b03 452
f7181e9b
AD
453 if ($line["comments"] && $line["link"] != $line["comments"]) {
454 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
455 } else {
456 $entry_comments = "";
457 }
458
e828e31e
AD
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>";
f7181e9b 465
e828e31e 466 print "<tr><td><b>Link:</b></td>
f7181e9b
AD
467 <td width='100%'>
468 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
469 $entry_comments</td></tr>";
e828e31e
AD
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
090e250b 478 print "<script type=\"text/javascript\">
8143ae1f 479 update_label_counters('$feed_id');
090e250b 480 </script>";
d76a3b03 481 }
70830c87
AD
482
483 if ($addheader) {
484 print "</body></html>";
485 }
1cd17194
AD
486 }
487
488 if ($op == "viewfeed") {
489
490 $feed = $_GET["feed"];
d76a3b03 491 $skip = $_GET["skip"];
476cac42 492 $subop = $_GET["subop"];
f175937c 493 $view_mode = $_GET["view"];
f0601b87 494 $addheader = $_GET["addheader"];
cb1083a1 495 $limit = $_GET["limit"];
a1a8a2be 496
8d7008c7
AD
497 if (!$feed) {
498 print "Error: no feed to display.";
499 return;
500 }
501
ac53063a
AD
502 if (!$skip) $skip = 0;
503
476cac42 504 if ($subop == "undefined") $subop = "";
1cd17194 505
f0601b87
AD
506 if ($addheader) {
507 print "<html><head>
ac43eba1 508 <title>Tiny Tiny RSS : Feed $feed</title>
430bf183
AD
509 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
510
4769ddaf 511 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
430bf183
AD
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\">
f0601b87
AD
520 <script type=\"text/javascript\" src=\"functions.js\"></script>
521 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
b623b3ed 522 </head><body onload='init()'>";
f0601b87
AD
523 }
524
dcee8f61
AD
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
0e32076b 536 if ($subop == "MarkAllRead") {
d76a3b03 537
0e32076b
AD
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()
254e0e4b 543 WHERE feed_id = '$feed'");
0e32076b
AD
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
7db95187 555 $label_id = -$feed - 11;
0e32076b 556
7db95187
AD
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 }
254e0e4b 567 }
0e32076b
AD
568 } else { // tag
569 // FIXME, implement catchup for tags
a1a8a2be 570 }
0e32076b 571
a1a8a2be 572 }
d76a3b03 573
175847de 574 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
ac53063a 575
c374a3fe
AD
576 $search = $_GET["search"];
577
52b51244
AD
578 $search_mode = $_GET["smode"];
579
f175937c 580 if ($search) {
ac53063a
AD
581 $search_query_part = "(upper(title) LIKE upper('%$search%')
582 OR content LIKE '%$search%') AND";
f175937c
AD
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 ";
ac53063a
AD
591 }
592
ac43eba1
AD
593 if ($view_mode == "Unread") {
594 $view_query_part = " unread = true AND ";
595 }
596
b5aa95e7
AD
597 if ($view_mode == "Unread or Starred") {
598 $view_query_part = " (unread = true OR marked = true) AND ";
599 }
600
bdd01d3f
AD
601 if ($view_mode == "Unread or Updated") {
602 $view_query_part = " (unread = true OR last_read is NULL) AND ";
603 }
604
254e0e4b 605/* $result = db_query($link, "SELECT count(id) AS total_entries
36bf7496
AD
606 FROM ttrss_entries WHERE
607 $search_query_part
608 feed_id = '$feed'");
e6d1c0a0 609
254e0e4b 610 $total_entries = db_fetch_result($result, 0, "total_entries"); */
e6d1c0a0 611
648472a7 612/* $result = db_query("SELECT count(id) AS unread_entries
ac43eba1
AD
613 FROM ttrss_entries WHERE
614 $search_query_part
615 unread = true AND
616 feed_id = '$feed'");
617
648472a7 618 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
ac43eba1 619
8d7008c7 620 if ($limit && $limit != "All") {
82c9223c 621 $limit_query_part = "LIMIT " . $limit;
ad3cb710 622 }
f0601b87 623
254e0e4b
AD
624 $vfeed_query_part = "";
625
52b51244
AD
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) {
8143ae1f
AD
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) {
254e0e4b 636 $query_strategy_part = "feed_id = '$feed'";
48f0adb0 637 } else if ($feed == -1) { // starred virtual feed
254e0e4b 638 $query_strategy_part = "marked = true";
48f0adb0
AD
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
254e0e4b
AD
649 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
650 id = feed_id) as feed_title,";
651 } else {
48f0adb0 652 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
653 }
654
52b51244 655
f99321a3
AD
656 $order_by = "updated DESC";
657
658// if ($feed < -10) {
659// $order_by = "feed_id,updated DESC";
660// }
661
48f0adb0
AD
662 if ($feed < -10) error_reporting (0);
663
8143ae1f
AD
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
aee86c2e 674 owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
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,
c05a19f3 686 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 687 $vfeed_query_part
c05a19f3 688 SUBSTRING(updated,1,19) as updated_noms
8143ae1f
AD
689 FROM
690 ttrss_entries,ttrss_tags
691 WHERE
aee86c2e 692 ttrss_entries.owner_uid = '".$_SESSION["uid"]."' AND
8143ae1f
AD
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 }
d76a3b03 699
48f0adb0
AD
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
a1a8a2be 706 $lnum = 0;
48f0adb0
AD
707
708 error_reporting (E_ERROR | E_WARNING | E_PARSE);
709
e1123aee 710 $num_unread = 0;
d76a3b03 711
648472a7 712 while ($line = db_fetch_assoc($result)) {
d76a3b03 713
a1a8a2be 714 $class = ($lnum % 2) ? "even" : "odd";
d76a3b03 715
ad99045e
AD
716 $id = $line["id"];
717 $feed_id = $line["feed_id"];
718
c43f77f5 719// printf("L %d (%s) &gt; U %d (%s) = %d<br>",
c05a19f3 720// strtotime($line["last_read_noms"]), $line["last_read_noms"],
c43f77f5
AD
721// strtotime($line["updated"]), $line["updated"],
722// strtotime($line["last_read"]) >= strtotime($line["updated"]));
723
ecb14114 724/* if ($line["last_read"] != "" && $line["updated"] != "" &&
c05a19f3 725 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
c43f77f5
AD
726
727 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
728 alt=\"Updated\">";
729
730 } else {
731
5bfef089 732 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
c43f77f5
AD
733 alt=\"Updated\">";
734
ecb14114
AD
735 } */
736
4cc6ea5e
AD
737 if ($line["last_read"] == "" &&
738 ($line["unread"] != "t" && $line["unread"] != "1")) {
739
ecb14114
AD
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\">";
c43f77f5 745 }
b197f117 746
8158c57a 747 if ($line["unread"] == "t" || $line["unread"] == "1") {
a1a8a2be 748 $class .= "Unread";
e1123aee
AD
749 ++$num_unread;
750 }
d76a3b03 751
8158c57a 752 if ($line["marked"] == "t" || $line["marked"] == "1") {
f4c10d44
AD
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
ac43eba1 760 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
b197f117
AD
761 $line["title"] . "</a>";
762
d5224f0d 763 print "<tr class='$class' id='RROW-$id'>";
5f89f780 764 // onclick=\"javascript:view($id,$feed_id)\">
b197f117 765
8d7008c7
AD
766 print "<td valign='center' align='center'>$update_pic</td>";
767 print "<td valign='center' align='center'>$marked_pic</td>";
b197f117 768
8d7008c7 769 print "<td width='25%'>
a3ee2a38 770 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
254e0e4b
AD
771
772 if ($line["feed_title"]) {
773 print "<td width='50%'>$content_link</td>";
2db4190c
AD
774 print "<td width='20%'>
775 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
254e0e4b
AD
776 } else {
777 print "<td width='70%'>$content_link</td>";
778 }
d76a3b03 779
a1a8a2be 780 print "</tr>";
d76a3b03 781
a1a8a2be
AD
782 ++$lnum;
783 }
d76a3b03 784
ac53063a 785 if ($lnum == 0) {
a82065a1 786 print "<tr><td align='center'>No articles found.</td></tr>";
047bae73 787 }
a2015351 788
a1a8a2be 789 print "</table>";
6113ef7d
AD
790
791 print "<script type=\"text/javascript\">
bb7cface 792 document.onkeydown = hotkey_handler;
8143ae1f 793 update_label_counters('$feed');
6113ef7d 794 </script>";
d76a3b03 795
f0601b87
AD
796 if ($addheader) {
797 print "</body></html>";
798 }
799
1cd17194
AD
800 }
801
0e091d38 802 if ($op == "pref-rpc") {
331900c6 803
0e091d38 804 $subop = $_GET["subop"];
331900c6 805
83fe4d6d
AD
806 if ($subop == "unread") {
807 $ids = split(",", $_GET["ids"]);
808 foreach ($ids as $id) {
648472a7 809 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
83fe4d6d 810 }
0e091d38
AD
811
812 print "Marked selected feeds as read.";
83fe4d6d
AD
813 }
814
815 if ($subop == "read") {
816 $ids = split(",", $_GET["ids"]);
817 foreach ($ids as $id) {
648472a7 818 db_query($link, "UPDATE ttrss_entries
b197f117 819 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
83fe4d6d 820 }
0e091d38
AD
821
822 print "Marked selected feeds as unread.";
823
824 }
825
826 }
827
828 if ($op == "pref-feeds") {
829
830 $subop = $_GET["subop"];
831
508a81e1 832 if ($subop == "editSave") {
648472a7
AD
833 $feed_title = db_escape_string($_GET["t"]);
834 $feed_link = db_escape_string($_GET["l"]);
d148926e 835 $upd_intl = db_escape_string($_GET["ui"]);
5d73494a 836 $purge_intl = db_escape_string($_GET["pi"]);
508a81e1
AD
837 $feed_id = $_GET["id"];
838
d148926e
AD
839 if (strtoupper($upd_intl) == "DEFAULT")
840 $upd_intl = 0;
841
5d73494a
AD
842 if (strtoupper($purge_intl) == "DEFAULT")
843 $purge_intl = 0;
844
140aae81
AD
845 if (strtoupper($purge_intl) == "DISABLED")
846 $purge_intl = -1;
847
648472a7 848 $result = db_query($link, "UPDATE ttrss_feeds SET
d148926e 849 title = '$feed_title', feed_url = '$feed_link',
5d73494a
AD
850 update_interval = '$upd_intl',
851 purge_interval = '$purge_intl'
852 WHERE id = '$feed_id'");
508a81e1 853
83fe4d6d
AD
854 }
855
331900c6 856 if ($subop == "remove") {
331900c6 857
b0b4abcf 858 if (!WEB_DEMO_MODE) {
331900c6 859
b0b4abcf
AD
860 $ids = split(",", $_GET["ids"]);
861
862 foreach ($ids as $id) {
648472a7 863 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
4769ddaf 864
273a2f6b 865 $icons_dir = ICONS_DIR;
d5caaae5 866
4769ddaf
AD
867 if (file_exists($icons_dir . "/$id.ico")) {
868 unlink($icons_dir . "/$id.ico");
d5caaae5 869 }
b0b4abcf 870 }
331900c6
AD
871 }
872 }
873
874 if ($subop == "add") {
b0b4abcf
AD
875
876 if (!WEB_DEMO_MODE) {
331900c6 877
648472a7 878 $feed_link = db_escape_string($_GET["link"]);
b0b4abcf 879
648472a7 880 $result = db_query($link,
4356293a 881 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
331900c6 882
648472a7 883 $result = db_query($link,
e9c54861 884 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
331900c6 885
648472a7 886 $feed_id = db_fetch_result($result, 0, "id");
331900c6 887
b0b4abcf
AD
888 if ($feed_id) {
889 update_rss_feed($link, $feed_link, $feed_id);
890 }
891 }
331900c6 892 }
a0d53889 893
ab3d0b99
AD
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
a0d53889
AD
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
648472a7 921 $result = db_query($link, "SELECT
d148926e 922 id,title,feed_url,substring(last_updated,1,16) as last_updated,
5d73494a 923 update_interval,purge_interval
c0e5a40e 924 FROM
4356293a 925 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
1cd17194 926
331900c6 927 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
007bda35 928 print "<tr class=\"title\">
5d73494a
AD
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>
d148926e 933 <td>Last updated</td></tr>";
007bda35
AD
934
935 $lnum = 0;
936
648472a7 937 while ($line = db_fetch_assoc($result)) {
007bda35
AD
938
939 $class = ($lnum % 2) ? "even" : "odd";
9b307248 940
331900c6 941 $feed_id = $line["id"];
603c27f8
AD
942
943 $edit_feed_id = $_GET["id"];
944
9b307248
AD
945 if ($subop == "edit" && $feed_id != $edit_feed_id) {
946 $class .= "Grayed";
947 }
948
331900c6 949 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
007bda35 950
273a2f6b 951 $icon_file = ICONS_DIR . "/$feed_id.ico";
c0e5a40e
AD
952
953 if (file_exists($icon_file) && filesize($icon_file) > 0) {
954 $feed_icon = "<img width=\"16\" height=\"16\"
273a2f6b 955 src=\"" . ICONS_URL . "/$feed_id.ico\">";
c0e5a40e
AD
956 } else {
957 $feed_icon = "&nbsp;";
958 }
959 print "<td align='center'>$feed_icon</td>";
960
6e0584e9
AD
961 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
962 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
963
9b307248 964 if (!$edit_feed_id || $subop != "edit") {
603c27f8
AD
965
966 print "<td><input onclick='toggleSelectRow(this);'
331900c6 967 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
603c27f8
AD
968
969 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
5d73494a 970 $edit_title . "</a></td>";
603c27f8 971 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
5d73494a 972 $edit_link . "</a></td>";
d148926e
AD
973
974 if ($line["update_interval"] == "0")
975 $line["update_interval"] = "Default";
976
5d73494a
AD
977 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
978 $line["update_interval"] . "</a></td>";
d148926e 979
5d73494a
AD
980 if ($line["purge_interval"] == "0")
981 $line["purge_interval"] = "Default";
982
140aae81
AD
983 if ($line["purge_interval"] < 0)
984 $line["purge_interval"] = "Disabled";
985
5d73494a
AD
986 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
987 $line["purge_interval"] . "</a></td>";
9b307248
AD
988
989 } else if ($feed_id != $edit_feed_id) {
990
e9c54861
AD
991 print "<td><input disabled=\"true\" type=\"checkbox\"
992 id=\"FRCHK-".$line["id"]."\"></td>";
9b307248 993
6e0584e9
AD
994 print "<td>$edit_title</td>";
995 print "<td>$edit_link</td>";
9b307248 996
d148926e
AD
997 if ($line["update_interval"] == "0")
998 $line["update_interval"] = "Default";
999
1000 print "<td>" . $line["update_interval"] . "</td>";
1001
5d73494a
AD
1002 if ($line["purge_interval"] == "0")
1003 $line["purge_interval"] = "Default";
1004
140aae81
AD
1005 if ($line["purge_interval"] < 0)
1006 $line["purge_interval"] = "Disabled";
1007
5d73494a
AD
1008 print "<td>" . $line["purge_interval"] . "</td>";
1009
603c27f8
AD
1010 } else {
1011
e6cb77a0 1012 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
603c27f8 1013
6e0584e9
AD
1014 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1015 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
d148926e 1016 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
5d73494a 1017 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
d148926e 1018
603c27f8 1019 }
0afbd851
AD
1020
1021 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1022
007bda35 1023 print "<td>" . $line["last_updated"] . "</td>";
603c27f8 1024
007bda35
AD
1025 print "</tr>";
1026
1027 ++$lnum;
1028 }
1029
0afbd851
AD
1030 if ($lnum == 0) {
1031 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1032 }
1033
007bda35
AD
1034 print "</table>";
1035
603c27f8
AD
1036 print "<p>";
1037
1038 if ($subop == "edit") {
1039 print "Edit feed:&nbsp;
e828e31e
AD
1040 <input type=\"submit\" class=\"button\"
1041 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1042 <input type=\"submit\" class=\"button\"
8158c57a 1043 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
603c27f8
AD
1044 } else {
1045
603c27f8
AD
1046 print "
1047 Selection:&nbsp;
e828e31e
AD
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
4769ddaf 1053 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
f92db4f5 1054 print "
e828e31e
AD
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;";
f92db4f5
AD
1059 }
1060 print "
e828e31e
AD
1061 All feeds:
1062 <input type=\"submit\"
8158c57a 1063 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
10c5820d 1064
603c27f8
AD
1065 }
1066
f5a50b25
AD
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
007bda35
AD
1074 }
1075
a0d53889
AD
1076 if ($op == "pref-filters") {
1077
1078 $subop = $_GET["subop"];
1079
1080 if ($subop == "editSave") {
a0d53889 1081
648472a7
AD
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"]);
0afbd851 1086
648472a7 1087 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1088 reg_exp = '$regexp',
0afbd851
AD
1089 description = '$descr',
1090 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1091 description = '$match')
1092 WHERE id = '$filter_id'");
a0d53889
AD
1093 }
1094
1095 if ($subop == "remove") {
1096
1097 if (!WEB_DEMO_MODE) {
1098
1099 $ids = split(",", $_GET["ids"]);
1100
1101 foreach ($ids as $id) {
648472a7 1102 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1103
1104 }
1105 }
1106 }
1107
1108 if ($subop == "add") {
1109
de435974 1110 if (!WEB_DEMO_MODE) {
a0d53889 1111
8158c57a 1112 $regexp = db_escape_string($_GET["regexp"]);
648472a7 1113 $match = db_escape_string($_GET["match"]);
a0d53889 1114
648472a7 1115 $result = db_query($link,
4356293a 1116 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
de435974 1117 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
4356293a 1118 description = '$match'),'".$_SESSION["uid"]."')");
de435974 1119 }
a0d53889
AD
1120 }
1121
648472a7 1122 $result = db_query($link, "SELECT description
a0d53889
AD
1123 FROM ttrss_filter_types ORDER BY description");
1124
1125 $filter_types = array();
1126
648472a7 1127 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1128 array_push($filter_types, $line["description"]);
1129 }
1130
1131 print "<table class=\"prefAddFeed\"><tr>
ea6774cf 1132 <td><input id=\"fadd_regexp\"></td>
a0d53889 1133 <td>";
bdc00fe0 1134 print_select("fadd_match", "Title", $filter_types);
a0d53889
AD
1135
1136 print"</td><td colspan=\"4\" align=\"right\">
1137 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1138 </table>";
1139
648472a7 1140 $result = db_query($link, "SELECT
4b3dff6e 1141 id,reg_exp,description,
a0d53889
AD
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
4356293a
AD
1147 ttrss_filters
1148 WHERE
1149 owner_uid = ".$_SESSION["uid"]."
1150 ORDER by reg_exp");
a0d53889
AD
1151
1152 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1153
1154 print "<tr class=\"title\">
0afbd851
AD
1155 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1156 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
a0d53889
AD
1157
1158 $lnum = 0;
1159
648472a7 1160 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
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
4b3dff6e 1173 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
ea6774cf
AD
1174 $line["description"] = htmlspecialchars($line["description"]);
1175
a0d53889
AD
1176 if (!$edit_filter_id || $subop != "edit") {
1177
0afbd851
AD
1178 if (!$line["description"]) $line["description"] = "[No description]";
1179
a0d53889
AD
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);\">" .
4b3dff6e 1184 $line["reg_exp"] . "</td>";
a0d53889
AD
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
0afbd851
AD
1193 if (!$line["description"]) $line["description"] = "[No description]";
1194
a0d53889
AD
1195 print "<td><input disabled=\"true\" type=\"checkbox\"
1196 id=\"FICHK-".$line["id"]."\"></td>";
1197
4b3dff6e 1198 print "<td>".$line["reg_exp"]."</td>";
a0d53889
AD
1199 print "<td>".$line["description"]."</td>";
1200 print "<td>".$line["filter_type_descr"]."</td>";
1201
1202 } else {
1203
e6cb77a0 1204 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
a0d53889 1205
4b3dff6e 1206 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
a0d53889
AD
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
0afbd851
AD
1224 if ($lnum == 0) {
1225 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1226 }
1227
a0d53889
AD
1228 print "</table>";
1229
1230 print "<p>";
1231
1232 if ($subop == "edit") {
e828e31e
AD
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\">";
a0d53889
AD
1238
1239 } else {
1240
1241 print "
e828e31e
AD
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\">";
a0d53889
AD
1247 }
1248 }
1249
48f0adb0
AD
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,
4356293a
AD
1288 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1289 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
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
4356293a
AD
1303 ttrss_labels
1304 WHERE
1305 owner_uid = ".$_SESSION["uid"]."
1306 ORDER by description");
48f0adb0
AD
1307
1308 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1309
1310 print "<tr class=\"title\">
7dc66a61
AD
1311 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1312 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1313 </td>
48f0adb0
AD
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
e6cb77a0 1359 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
48f0adb0
AD
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
e828e31e
AD
1401 if ($op == "error") {
1402 print "<div width=\"100%\" align='center'>";
1403 $msg = $_GET["msg"];
1404 print $msg;
1405 print "</div>";
1406 }
1407
7dc66a61
AD
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>
7dc66a61
AD
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
d1f948d1 1429 view feed query. You can match on ttrss_entries table fields
7dc66a61
AD
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
f84a97a3
AD
1459 if ($op == "dlg") {
1460 $id = $_GET["id"];
6de5d056 1461 $param = $_GET["param"];
f84a97a3
AD
1462
1463 if ($id == "quickAddFeed") {
033e47e0
AD
1464 print "Feed URL: <input
1465 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1466 id=\"qafInput\">
f84a97a3
AD
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 }
6de5d056
AD
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
033e47e0
AD
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
f84a97a3
AD
1515 }
1516
e65af9c1
AD
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
77e96719
AD
1529 if ($op == "pref-prefs") {
1530
b1895692 1531 $subop = $_REQUEST["subop"];
77e96719
AD
1532
1533 if ($subop == "Save configuration") {
1534
01d68cf9
AD
1535 if (WEB_DEMO_MODE) return;
1536
77e96719
AD
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
5da169d9
AD
1550// print "$pref_name : $type_name : $value<br>";
1551
77e96719 1552 if ($type_name == "bool") {
5da169d9 1553 if ($value == "1") {
77e96719
AD
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
ff485f1d
AD
1564 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1565 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
1566
1567 }
1568
1569 header("Location: prefs.php");
1570
1571 }
1572
b1895692
AD
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
1c7f75ed
AD
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
77e96719
AD
1615 } else if ($subop == "Reset to defaults") {
1616
01d68cf9
AD
1617 if (WEB_DEMO_MODE) return;
1618
e1aa0559
AD
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 }
5da169d9 1629
77e96719
AD
1630 header("Location: prefs.php");
1631
1632 } else {
1633
7d4c898a 1634 if (!SINGLE_USER_MODE) {
1c7f75ed 1635
7d4c898a
AD
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>";
1c7f75ed 1658
7d4c898a 1659 }
1c7f75ed 1660
77e96719 1661 $result = db_query($link, "SELECT
ff485f1d 1662 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 1663 section_name,def_value
ff485f1d 1664 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 1665 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 1666 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
1667 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1668 owner_uid = ".$_SESSION["uid"]."
650bc435 1669 ORDER BY section_id,short_desc");
77e96719
AD
1670
1671 print "<form action=\"backend.php\" method=\"POST\">";
1672
77e96719
AD
1673 $lnum = 0;
1674
1675 $active_section = "";
1676
1677 while ($line = db_fetch_assoc($result)) {
1678
1679 if ($active_section != $line["section_name"]) {
59a654ba
AD
1680
1681 if ($active_section != "") {
1c7f75ed 1682 print "</table>";
59a654ba 1683 }
1c7f75ed
AD
1684
1685 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
1686
1687 $active_section = $line["section_name"];
1688
77e96719 1689 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
1690// print "<tr class=\"title\">
1691// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
1692
1693 $lnum = 0;
77e96719
AD
1694 }
1695
650bc435 1696// $class = ($lnum % 2) ? "even" : "odd";
77e96719 1697
650bc435 1698 print "<tr>";
77e96719 1699
77e96719
AD
1700 $type_name = $line["type_name"];
1701 $pref_name = $line["pref_name"];
1702 $value = $line["value"];
1703 $def_value = $line["def_value"];
b1895692
AD
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>";
77e96719
AD
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
e6cb77a0
AD
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
f6f32198 1838 id,login,access_level,last_login
e6cb77a0
AD
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\">
f6f32198
AD
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>";
e6cb77a0
AD
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>";
e6cb77a0
AD
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
f6f32198
AD
1907 print "<td>".$line["last_login"]."</td>";
1908
e6cb77a0
AD
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
4b3dff6e 1939 db_close($link);
1cd17194 1940?>
406d9489
AD
1941
1942<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
1943