From cbe50c800d4846be184673e623063abee7101a0c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 13:34:43 +0400 Subject: add pref_labels class --- classes/pref_labels.php | 320 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 classes/pref_labels.php (limited to 'classes/pref_labels.php') diff --git a/classes/pref_labels.php b/classes/pref_labels.php new file mode 100644 index 000000000..5de4443f7 --- /dev/null +++ b/classes/pref_labels.php @@ -0,0 +1,320 @@ +link, "SELECT * FROM ttrss_labels2 WHERE + id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); + + $line = db_fetch_assoc($result); + + print ""; + print ""; + print ""; + + print "
".__("Caption")."
"; + + print "
"; + + $fg_color = $line['fg_color']; + $bg_color = $line['bg_color']; + + print "α"; + + print ""; + + print "
"; + print "
" . __("Colors") . "
"; + print "
"; + + print ""; + + print ""; + + print "
".__("Foreground:")."".__("Background:"). + "
"; + + print ""; + print ""; + + print "
+ +
"; + print ""; + + print "
"; + + print "
+ +
"; + print ""; + + print "
"; + print "
"; + +# print ""; + + print "
"; + print ""; + print ""; + print "
"; + + return; + } + + function getlabeltree() { + $root = array(); + $root['id'] = 'root'; + $root['name'] = __('Labels'); + $root['items'] = array(); + + $result = db_query($this->link, "SELECT * + FROM ttrss_labels2 + WHERE owner_uid = ".$_SESSION["uid"]." + ORDER BY caption"); + + while ($line = db_fetch_assoc($result)) { + $label = array(); + $label['id'] = 'LABEL:' . $line['id']; + $label['bare_id'] = $line['id']; + $label['name'] = $line['caption']; + $label['fg_color'] = $line['fg_color']; + $label['bg_color'] = $line['bg_color']; + $label['type'] = 'label'; + $label['checkbox'] = false; + + array_push($root['items'], $label); + } + + $fl = array(); + $fl['identifier'] = 'id'; + $fl['label'] = 'name'; + $fl['items'] = array($root); + + print json_encode($fl); + return; + } + + function colorset() { + $kind = db_escape_string($_REQUEST["kind"]); + $ids = split(',', db_escape_string($_REQUEST["ids"])); + $color = db_escape_string($_REQUEST["color"]); + $fg = db_escape_string($_REQUEST["fg"]); + $bg = db_escape_string($_REQUEST["bg"]); + + foreach ($ids as $id) { + + if ($kind == "fg" || $kind == "bg") { + db_query($this->link, "UPDATE ttrss_labels2 SET + ${kind}_color = '$color' WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + } else { + db_query($this->link, "UPDATE ttrss_labels2 SET + fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + } + + $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); + + /* Remove cached data */ + + db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' + WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); + + } + + return; + } + + function colorreset() { + $ids = split(',', db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + db_query($this->link, "UPDATE ttrss_labels2 SET + fg_color = '', bg_color = '' WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + + $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); + + /* Remove cached data */ + + db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' + WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); + } + + } + + function save() { + + $id = db_escape_string($_REQUEST["id"]); + $caption = db_escape_string(trim($_REQUEST["caption"])); + + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT caption FROM ttrss_labels2 + WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $old_caption = db_fetch_result($result, 0, "caption"); + + $result = db_query($this->link, "SELECT id FROM ttrss_labels2 + WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + if ($caption) { + $result = db_query($this->link, "UPDATE ttrss_labels2 SET + caption = '$caption' WHERE id = '$id' AND + owner_uid = " . $_SESSION["uid"]); + + /* Update filters that reference label being renamed */ + + $old_caption = db_escape_string($old_caption); + + db_query($this->link, "UPDATE ttrss_filters SET + action_param = '$caption' WHERE action_param = '$old_caption' + AND action_id = 7 + AND owner_uid = " . $_SESSION["uid"]); + + print $_REQUEST["value"]; + } else { + print $old_caption; + } + } else { + print $old_caption; + } + } + + db_query($this->link, "COMMIT"); + + return; + } + + function remove() { + + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + label_remove($this->link, $id, $_SESSION["uid"]); + } + + } + + function add() { + $caption = db_escape_string($_REQUEST["caption"]); + $output = db_escape_string($_REQUEST["output"]); + + if ($caption) { + + if (label_create($this->link, $caption)) { + if (!$output) { + print T_sprintf("Created label %s", htmlspecialchars($caption)); + } + } + + if ($output == "select") { + header("Content-Type: text/xml"); + + print ""; + + print_label_select($this->link, "select_label", + $caption, ""); + + print ""; + } + } + + return; + } + + function index() { + + $sort = db_escape_string($_REQUEST["sort"]); + + if (!$sort || $sort == "undefined") { + $sort = "caption"; + } + + $label_search = db_escape_string($_REQUEST["search"]); + + if (array_key_exists("search", $_REQUEST)) { + $_SESSION["prefs_label_search"] = $label_search; + } else { + $label_search = $_SESSION["prefs_label_search"]; + } + + print "
"; + print "
"; + print "
"; + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print" "; + + print " "; + + print ""; + + + print "
"; #toolbar + print "
"; #pane + print "
"; + + print "
+ ". + __("Loading, please wait...")."
"; + + print "
+
+
+
+
+ + +
"; + + print "
"; #pane + print "
"; #container + + } +} + +?> -- cgit v1.2.3