]>
git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
2 function module_pref_labels($link) {
4 $subop = $_REQUEST["subop"];
6 if ($subop == "edit") {
7 $label_id = db_escape_string($_REQUEST['id']);
9 header("Content-Type: text/xml");
10 print "<dlg id=\"$subop\">";
11 print "<title>" . __("Label Editor") . "</title>";
12 print "<content><![CDATA[";
14 $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE
15 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
17 $line = db_fetch_assoc($result);
19 print "<form id=\"label_edit_form\" name=\"label_edit_form\"
20 onsubmit=\"return false;\">";
22 print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
23 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
24 print "<input type=\"hidden\" name=\"subop\" value=\"save\">";
26 print "<div class=\"dlgSec\">".__("Caption")."</div>";
28 print "<div class=\"dlgSecCont\">";
30 print "<input style=\"font-size : 18px\" name=\"caption\"
31 onkeypress=\"return filterCR(event, editLabelSave)\"
32 value=\"".htmlspecialchars($line['caption'])."\">";
35 print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
36 print "<div class=\"dlgSecCont\">";
38 print "<table cellspacing=\"5\"><th>";
40 print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
43 print "</th><tr><td>";
45 $fg_color = $line['fg_color'];
46 $bg_color = $line['bg_color'];
48 print "<input type=\"hidden\" name=\"fg_color\" value=\"$fg_color\">";
49 print "<input type=\"hidden\" name=\"bg_color\" value=\"$bg_color\">";
51 print "<div dojoType=\"dijit.ColorPalette\">
52 <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
53 document.forms['label_edit_form'].fg_color.value = fg_color;
60 print "<div dojoType=\"dijit.ColorPalette\">
61 <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
62 document.forms['label_edit_form'].bg_color.value = bg_color;
67 print "</td></tr></table>";
72 print "<div class=\"dlgButtons\">";
73 print "<button onclick=\"return editLabelSave()\">".
74 __('Save')."</button>";
75 print "<button onclick=\"return closeInfoBox()\">".
76 __('Cancel')."</button>";
79 print "]]></content></dlg>";
83 if ($subop == "getlabeltree") {
86 $root['name'] = __('Labels');
87 $root['items'] = array();
89 $result = db_query($link, "SELECT *
91 WHERE owner_uid = ".$_SESSION["uid"]."
94 while ($line = db_fetch_assoc($result)) {
96 $label['id'] = 'LABEL:' . $line['id'];
97 $label['bare_id'] = $line['id'];
98 $label['name'] = $line['caption'];
99 $label['fg_color'] = $line['fg_color'];
100 $label['bg_color'] = $line['bg_color'];
101 $label['type'] = 'label';
102 $label['checkbox'] = false;
104 array_push($root['items'], $label);
108 $fl['identifier'] = 'id';
109 $fl['label'] = 'name';
110 $fl['items'] = array($root);
112 print json_encode($fl);
116 if ($subop == "color-set") {
117 $kind = db_escape_string($_REQUEST["kind"]);
118 $ids = split(',', db_escape_string($_REQUEST["ids"]));
119 $color = db_escape_string($_REQUEST["color"]);
120 $fg = db_escape_string($_REQUEST["fg"]);
121 $bg = db_escape_string($_REQUEST["bg"]);
123 foreach ($ids as $id) {
125 if ($kind == "fg" ||
$kind == "bg") {
126 db_query($link, "UPDATE ttrss_labels2 SET
127 ${kind}_color = '$color' WHERE id = '$id'
128 AND owner_uid = " . $_SESSION["uid"]);
130 db_query($link, "UPDATE ttrss_labels2 SET
131 fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
132 AND owner_uid = " . $_SESSION["uid"]);
135 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
137 /* Remove cached data */
139 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
140 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
147 if ($subop == "color-reset") {
148 $ids = split(',', db_escape_string($_REQUEST["ids"]));
150 foreach ($ids as $id) {
151 db_query($link, "UPDATE ttrss_labels2 SET
152 fg_color = '', bg_color = '' WHERE id = '$id'
153 AND owner_uid = " . $_SESSION["uid"]);
155 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
157 /* Remove cached data */
159 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
160 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
165 if ($subop == "save") {
167 $id = db_escape_string($_REQUEST["id"]);
168 $caption = db_escape_string(trim($_REQUEST["caption"]));
170 db_query($link, "BEGIN");
172 $result = db_query($link, "SELECT caption FROM ttrss_labels2
173 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
175 if (db_num_rows($result) != 0) {
176 $old_caption = db_fetch_result($result, 0, "caption");
178 $result = db_query($link, "SELECT id FROM ttrss_labels2
179 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
181 if (db_num_rows($result) == 0) {
183 $result = db_query($link, "UPDATE ttrss_labels2 SET
184 caption = '$caption' WHERE id = '$id' AND
185 owner_uid = " . $_SESSION["uid"]);
187 /* Update filters that reference label being renamed */
189 $old_caption = db_escape_string($old_caption);
191 db_query($link, "UPDATE ttrss_filters SET
192 action_param = '$caption' WHERE action_param = '$old_caption'
194 AND owner_uid = " . $_SESSION["uid"]);
196 print $_REQUEST["value"];
205 db_query($link, "COMMIT");
210 if ($subop == "remove") {
212 $ids = split(",", db_escape_string($_REQUEST["ids"]));
214 foreach ($ids as $id) {
215 label_remove($link, $id, $_SESSION["uid"]);
220 if ($subop == "add") {
221 $caption = db_escape_string($_REQUEST["caption"]);
222 $output = db_escape_string($_REQUEST["output"]);
226 if (label_create($link, $caption)) {
228 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
232 if ($output == "select") {
233 header("Content-Type: text/xml");
235 print "<rpc-reply><payload>";
237 print_label_select($link, "select_label",
240 print "</payload></rpc-reply>";
247 $sort = db_escape_string($_REQUEST["sort"]);
249 if (!$sort ||
$sort == "undefined") {
253 $label_search = db_escape_string($_REQUEST["search"]);
255 if (array_key_exists("search", $_REQUEST)) {
256 $_SESSION["prefs_label_search"] = $label_search;
258 $label_search = $_SESSION["prefs_label_search"];
261 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
262 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
263 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
265 print "<div dojoType=\"dijit.form.DropDownButton\">".
266 "<span>" . __('Select')."</span>";
267 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
268 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
269 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
270 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
271 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
272 print "</div></div>";
274 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
275 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
277 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
278 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
280 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
281 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
284 print "</div>"; #toolbar
285 print "</div>"; #pane
286 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
288 print "<div id=\"labellistLoading\">
289 <img src='images/indicator_tiny.gif'>".
290 __("Loading, please wait...")."</div>";
292 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
293 url=\"backend.php?op=pref-labels&subop=getlabeltree\">
295 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
296 query=\"{id:'root'}\" rootId=\"root\"
297 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
299 <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
300 model=\"labelModel\" openOnClick=\"true\">
301 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
302 Element.hide(\"labellistLoading\");
306 print "</div>"; #pane
307 print "</div>"; #container