From ef8be8ea8da90596d321bc25e88c48121715ed18 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 1 Oct 2006 11:05:20 +0100 Subject: split backend.php into modules, backend cleanups --- modules/pref-labels.php | 289 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100644 modules/pref-labels.php (limited to 'modules/pref-labels.php') diff --git a/modules/pref-labels.php b/modules/pref-labels.php new file mode 100644 index 000000000..8f1bab7af --- /dev/null +++ b/modules/pref-labels.php @@ -0,0 +1,289 @@ +Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.

"; + return; + } + + $subop = $_GET["subop"]; + + if ($subop == "edit") { + + $label_id = db_escape_string($_GET["id"]); + + $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE + owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description"); + + $line = db_fetch_assoc($result); + + $sql_exp = htmlspecialchars(db_unescape_string($line["sql_exp"])); + $description = htmlspecialchars(db_unescape_string($line["description"])); + + print "
Label editor
"; + print "
"; + + print "
"; + + print ""; + print ""; + print ""; + + print ""; + + print " + "; + + print "
Caption:"; + + print "
+

SQL Expression:

"; + + print ""; + + print "
"; + + print "
"; + + print "
"; + + print "
"; + + $is_disabled = (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) ? "disabled" : ""; + + print " + "; + + print " "; + + print ""; + + print "
"; + + return; + } + + if ($subop == "test") { + + $expr = db_unescape_string(trim($_GET["expr"])); + $descr = db_unescape_string(trim($_GET["descr"])); + + print "
"; + + error_reporting(0); + + + $result = db_query($link, + "SELECT count(ttrss_entries.id) AS num_matches + FROM ttrss_entries,ttrss_user_entries,ttrss_feeds + WHERE ($expr) AND + ttrss_user_entries.ref_id = ttrss_entries.id AND + ttrss_user_entries.feed_id = ttrss_feeds.id AND + ttrss_user_entries.owner_uid = " . $_SESSION["uid"], false); + + error_reporting (DEFAULT_ERROR_LEVEL); + + if (!$result) { + print "

" . db_last_error($link) . "

"; + print "
"; + return; + } + + $num_matches = db_fetch_result($result, 0, "num_matches");; + + if ($num_matches > 0) { + + if ($num_matches > 10) { + $showing_msg = ", showing first 10"; + } + + print "

Query returned $num_matches matches$showing_msg:

"; + + $result = db_query($link, + "SELECT ttrss_entries.title, + (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title + FROM ttrss_entries,ttrss_user_entries,ttrss_feeds + WHERE ($expr) AND + ttrss_user_entries.ref_id = ttrss_entries.id + AND ttrss_user_entries.feed_id = ttrss_feeds.id + AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . " + ORDER BY date_entered DESC LIMIT 10", false); + + print ""; + + } else { + print "

Query didn't return any matches.

"; + } + + print "
"; + + return; + } + + if ($subop == "editSave") { + + $sql_exp = trim($_GET["sql_exp"]); + $descr = db_escape_string(trim($_GET["description"])); + $label_id = db_escape_string($_GET["id"]); + + $result = db_query($link, "UPDATE ttrss_labels SET + sql_exp = '$sql_exp', + description = '$descr' + WHERE id = '$label_id'"); + } + + if ($subop == "remove") { + + if (!WEB_DEMO_MODE) { + + $ids = split(",", db_escape_string($_GET["ids"])); + + foreach ($ids as $id) { + db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); + + } + } + } + + if ($subop == "add") { + + if (!WEB_DEMO_MODE) { + + // no escaping is done here on purpose + $sql_exp = trim($_GET["sql_exp"]); + $description = db_escape_string($_GET["description"]); + + if (!$sql_exp || !$description) return; + + $result = db_query($link, + "INSERT INTO ttrss_labels (sql_exp,description,owner_uid) + VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')"); + } + } + + $sort = db_escape_string($_GET["sort"]); + + if (!$sort || $sort == "undefined") { + $sort = "description"; + } + + print "
"; + + print"
"; + + $result = db_query($link, "SELECT + id,sql_exp,description + FROM + ttrss_labels + WHERE + owner_uid = ".$_SESSION["uid"]." + ORDER BY $sort"); + +// print "
PLACEHOLDER
"; + + if (db_num_rows($result) != 0) { + + print "
"; + + print "

"; + + print " + + + + "; + + $lnum = 0; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + + $label_id = $line["id"]; + $edit_label_id = $_GET["id"]; + + if ($subop == "edit" && $label_id != $edit_label_id) { + $class .= "Grayed"; + $this_row_id = ""; + } else { + $this_row_id = "id=\"LILRR-$label_id\""; + } + + print ""; + + $line["sql_exp"] = htmlspecialchars(db_unescape_string($line["sql_exp"])); + $line["description"] = htmlspecialchars( + db_unescape_string($line["description"])); + + if (!$line["description"]) $line["description"] = "[No caption]"; + + print ""; + + print ""; + + print ""; + + print ""; + + ++$lnum; + } + + if ($lnum == 0) { + print ""; + } + + print "
+ Select: + All, + None + "; + + print "
 CaptionSQL Expression + (?) +
" . + $line["description"] . "" . + $line["sql_exp"] . "
No labels defined.
"; + + print "

"; + + print "

"; + + print " + Selection: + + "; + + } else { + print "

No labels defined.

"; + } + } +?> -- cgit v1.2.3