]>
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 $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE
10 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
12 $line = db_fetch_assoc($result);
14 # print "<form id=\"label_edit_form\" name=\"label_edit_form\"
15 # onsubmit=\"return false;\">";
17 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$label_id\">";
18 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">";
19 print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"subop\" value=\"save\">";
21 print "<div class=\"dlgSec\">".__("Caption")."</div>";
23 print "<div class=\"dlgSecCont\">";
25 $fg_color = $line['fg_color'];
26 $bg_color = $line['bg_color'];
28 print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>";
30 print "<input style=\"font-size : 16px\" name=\"caption\"
31 dojoType=\"dijit.form.ValidationTextBox\"
33 value=\"".htmlspecialchars($line['caption'])."\">";
36 print "<div class=\"dlgSec\">" . __("Colors") . "</div>";
37 print "<div class=\"dlgSecCont\">";
39 print "<table cellspacing=\"0\">";
41 print "<tr><td>".__("Foreground:")."</td><td>".__("Background:").
44 print "<tr><td style='padding-right : 10px'>";
46 print "<input dojoType=\"dijit.form.TextBox\"
47 style=\"display : none\" id=\"labelEdit_fgColor\"
48 name=\"fg_color\" value=\"$fg_color\">";
49 print "<input dojoType=\"dijit.form.TextBox\"
50 style=\"display : none\" id=\"labelEdit_bgColor\"
51 name=\"bg_color\" value=\"$bg_color\">";
53 print "<div dojoType=\"dijit.ColorPalette\">
54 <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\">
55 dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color);
56 $('label-editor-indicator').setStyle({color: fg_color});
63 print "<div dojoType=\"dijit.ColorPalette\">
64 <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\">
65 dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color);
66 $('label-editor-indicator').setStyle({backgroundColor: bg_color});
71 print "</td></tr></table>";
76 print "<div class=\"dlgButtons\">";
77 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">".
78 __('Save')."</button>";
79 print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">".
80 __('Cancel')."</button>";
86 if ($subop == "getlabeltree") {
89 $root['name'] = __('Labels');
90 $root['items'] = array();
92 $result = db_query($link, "SELECT *
94 WHERE owner_uid = ".$_SESSION["uid"]."
97 while ($line = db_fetch_assoc($result)) {
99 $label['id'] = 'LABEL:' . $line['id'];
100 $label['bare_id'] = $line['id'];
101 $label['name'] = $line['caption'];
102 $label['fg_color'] = $line['fg_color'];
103 $label['bg_color'] = $line['bg_color'];
104 $label['type'] = 'label';
105 $label['checkbox'] = false;
107 array_push($root['items'], $label);
111 $fl['identifier'] = 'id';
112 $fl['label'] = 'name';
113 $fl['items'] = array($root);
115 print json_encode($fl);
119 if ($subop == "color-set") {
120 $kind = db_escape_string($_REQUEST["kind"]);
121 $ids = split(',', db_escape_string($_REQUEST["ids"]));
122 $color = db_escape_string($_REQUEST["color"]);
123 $fg = db_escape_string($_REQUEST["fg"]);
124 $bg = db_escape_string($_REQUEST["bg"]);
126 foreach ($ids as $id) {
128 if ($kind == "fg" ||
$kind == "bg") {
129 db_query($link, "UPDATE ttrss_labels2 SET
130 ${kind}_color = '$color' WHERE id = '$id'
131 AND owner_uid = " . $_SESSION["uid"]);
133 db_query($link, "UPDATE ttrss_labels2 SET
134 fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
135 AND owner_uid = " . $_SESSION["uid"]);
138 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
140 /* Remove cached data */
142 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
143 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
150 if ($subop == "color-reset") {
151 $ids = split(',', db_escape_string($_REQUEST["ids"]));
153 foreach ($ids as $id) {
154 db_query($link, "UPDATE ttrss_labels2 SET
155 fg_color = '', bg_color = '' WHERE id = '$id'
156 AND owner_uid = " . $_SESSION["uid"]);
158 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
160 /* Remove cached data */
162 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
163 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
168 if ($subop == "save") {
170 $id = db_escape_string($_REQUEST["id"]);
171 $caption = db_escape_string(trim($_REQUEST["caption"]));
173 db_query($link, "BEGIN");
175 $result = db_query($link, "SELECT caption FROM ttrss_labels2
176 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
178 if (db_num_rows($result) != 0) {
179 $old_caption = db_fetch_result($result, 0, "caption");
181 $result = db_query($link, "SELECT id FROM ttrss_labels2
182 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
184 if (db_num_rows($result) == 0) {
186 $result = db_query($link, "UPDATE ttrss_labels2 SET
187 caption = '$caption' WHERE id = '$id' AND
188 owner_uid = " . $_SESSION["uid"]);
190 /* Update filters that reference label being renamed */
192 $old_caption = db_escape_string($old_caption);
194 db_query($link, "UPDATE ttrss_filters SET
195 action_param = '$caption' WHERE action_param = '$old_caption'
197 AND owner_uid = " . $_SESSION["uid"]);
199 print $_REQUEST["value"];
208 db_query($link, "COMMIT");
213 if ($subop == "remove") {
215 $ids = split(",", db_escape_string($_REQUEST["ids"]));
217 foreach ($ids as $id) {
218 label_remove($link, $id, $_SESSION["uid"]);
223 if ($subop == "add") {
224 $caption = db_escape_string($_REQUEST["caption"]);
225 $output = db_escape_string($_REQUEST["output"]);
229 if (label_create($link, $caption)) {
231 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
235 if ($output == "select") {
236 header("Content-Type: text/xml");
238 print "<rpc-reply><payload>";
240 print_label_select($link, "select_label",
243 print "</payload></rpc-reply>";
250 $sort = db_escape_string($_REQUEST["sort"]);
252 if (!$sort ||
$sort == "undefined") {
256 $label_search = db_escape_string($_REQUEST["search"]);
258 if (array_key_exists("search", $_REQUEST)) {
259 $_SESSION["prefs_label_search"] = $label_search;
261 $label_search = $_SESSION["prefs_label_search"];
264 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
265 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
266 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
268 print "<div dojoType=\"dijit.form.DropDownButton\">".
269 "<span>" . __('Select')."</span>";
270 print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
271 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
272 dojoType=\"dijit.MenuItem\">".__('All')."</div>";
273 print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
274 dojoType=\"dijit.MenuItem\">".__('None')."</div>";
275 print "</div></div>";
277 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
278 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
280 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
281 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
283 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
284 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
287 print "</div>"; #toolbar
288 print "</div>"; #pane
289 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
291 print "<div id=\"labellistLoading\">
292 <img src='images/indicator_tiny.gif'>".
293 __("Loading, please wait...")."</div>";
295 print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
296 url=\"backend.php?op=pref-labels&subop=getlabeltree\">
298 <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
299 query=\"{id:'root'}\" rootId=\"root\"
300 childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
302 <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
303 model=\"labelModel\" openOnClick=\"true\">
304 <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
305 Element.hide(\"labellistLoading\");
307 <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
308 var id = String(item.id);
309 var bare_id = id.substr(id.indexOf(':')+1);
311 if (id.match('LABEL:')) {
317 print "</div>"; #pane
318 print "</div>"; #container