]> git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
c794e023ecd7d3ce635e9d4316169dd950e9a7e2
[tt-rss.git] / modules / pref-labels.php
1 <?php
2 function module_pref_labels($link) {
3
4 $subop = $_REQUEST["subop"];
5
6 if ($subop == "color-set") {
7 $kind = db_escape_string($_REQUEST["kind"]);
8 $ids = split(',', db_escape_string($_REQUEST["ids"]));
9 $color = db_escape_string($_REQUEST["color"]);
10 $fg = db_escape_string($_REQUEST["fg"]);
11 $bg = db_escape_string($_REQUEST["bg"]);
12
13 foreach ($ids as $id) {
14
15 if ($kind == "fg" || $kind == "bg") {
16 db_query($link, "UPDATE ttrss_labels2 SET
17 ${kind}_color = '$color' WHERE id = '$id'
18 AND owner_uid = " . $_SESSION["uid"]);
19 } else {
20 db_query($link, "UPDATE ttrss_labels2 SET
21 fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
22 AND owner_uid = " . $_SESSION["uid"]);
23 }
24
25 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
26
27 /* Remove cached data */
28
29 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
30 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
31
32 }
33
34 return;
35 }
36
37 if ($subop == "color-reset") {
38 $ids = split(',', db_escape_string($_REQUEST["ids"]));
39
40 foreach ($ids as $id) {
41 db_query($link, "UPDATE ttrss_labels2 SET
42 fg_color = '', bg_color = '' WHERE id = '$id'
43 AND owner_uid = " . $_SESSION["uid"]);
44
45 $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"]));
46
47 /* Remove cached data */
48
49 db_query($link, "UPDATE ttrss_user_entries SET label_cache = ''
50 WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
51 }
52
53 }
54
55 if ($subop == "save") {
56
57 $id = db_escape_string($_REQUEST["id"]);
58 $caption = db_escape_string(trim($_REQUEST["value"]));
59
60 db_query($link, "BEGIN");
61
62 $result = db_query($link, "SELECT caption FROM ttrss_labels2
63 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
64
65 if (db_num_rows($result) != 0) {
66 $old_caption = db_fetch_result($result, 0, "caption");
67
68 $result = db_query($link, "SELECT id FROM ttrss_labels2
69 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
70
71 if (db_num_rows($result) == 0) {
72 if ($caption) {
73 $result = db_query($link, "UPDATE ttrss_labels2 SET
74 caption = '$caption' WHERE id = '$id' AND
75 owner_uid = " . $_SESSION["uid"]);
76
77 /* Update filters that reference label being renamed */
78
79 $old_caption = db_escape_string($old_caption);
80
81 db_query($link, "UPDATE ttrss_filters SET
82 action_param = '$caption' WHERE action_param = '$old_caption'
83 AND action_id = 7
84 AND owner_uid = " . $_SESSION["uid"]);
85
86 print $_REQUEST["value"];
87 } else {
88 print $old_caption;
89 }
90 } else {
91 print $old_caption;
92 }
93 }
94
95 db_query($link, "COMMIT");
96
97 return;
98 }
99
100 if ($subop == "remove") {
101
102 $ids = split(",", db_escape_string($_REQUEST["ids"]));
103
104 foreach ($ids as $id) {
105 label_remove($link, $id, $_SESSION["uid"]);
106 }
107
108 }
109
110 if ($subop == "add") {
111 $caption = db_escape_string($_REQUEST["caption"]);
112 $output = db_escape_string($_REQUEST["output"]);
113
114 if ($caption) {
115
116 if (label_create($link, $caption)) {
117 if (!$output) {
118 //print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
119 }
120 }
121
122 if ($output == "select") {
123 header("Content-Type: text/xml");
124
125 print "<rpc-reply><payload>";
126
127 print_label_select($link, "select_label",
128 $caption, "");
129
130 print "</payload></rpc-reply>";
131 }
132 }
133
134 return;
135 }
136
137 set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
138
139 $sort = db_escape_string($_REQUEST["sort"]);
140
141 if (!$sort || $sort == "undefined") {
142 $sort = "caption";
143 }
144
145 $label_search = db_escape_string($_REQUEST["search"]);
146
147 if (array_key_exists("search", $_REQUEST)) {
148 $_SESSION["prefs_label_search"] = $label_search;
149 } else {
150 $label_search = $_SESSION["prefs_label_search"];
151 }
152
153 print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">";
154 print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">";
155 print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">";
156
157 print "<div style='float : right; padding-right : 4px'>
158 <input id=\"label_search\" size=\"20\" type=\"search\"
159 dojoType=\"dijit.form.TextBox\"
160 onfocus=\"javascript:disableHotkeys();\"
161 onblur=\"javascript:enableHotkeys();\"
162 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
163 <button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateLabelList()\">".__('Search')."</button>
164 </div>";
165
166 print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">".
167 __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
168
169 print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">".
170 __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
171
172 print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">".
173 __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
174
175
176 print "</div>"; #toolbar
177 print "</div>"; #pane
178 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
179
180 if ($label_search) {
181
182 $label_search = split(" ", $label_search);
183 $tokens = array();
184
185 foreach ($label_search as $token) {
186
187 $token = trim($token);
188 array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
189
190 }
191
192 $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
193
194 } else {
195 $label_search_query = "";
196 }
197
198 $result = db_query($link, "SELECT
199 *
200 FROM
201 ttrss_labels2
202 WHERE
203 $label_search_query
204 owner_uid = ".$_SESSION["uid"]."
205 ORDER BY $sort");
206
207 if (db_num_rows($result) != 0) {
208
209 print "<p><table width=\"100%\" cellspacing=\"0\"
210 class=\"prefLabelList\" id=\"prefLabelList\">";
211
212 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
213 ".__('Select:')."
214 <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'all')\">".__('All')."</a>,
215 <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'none')\">".__('None')."</a>
216 </td</tr>";
217
218 $lnum = 0;
219
220 while ($line = db_fetch_assoc($result)) {
221
222 $class = ($lnum % 2) ? "even" : "odd";
223
224 $label_id = $line["id"];
225 $this_row_id = "id=\"LILRR-$label_id\"";
226
227 print "<tr class=\"$class\" $this_row_id>";
228
229 $line["caption"] = htmlspecialchars($line["caption"]);
230
231 $fg_color = $line["fg_color"];
232 $bg_color = $line["bg_color"];
233
234 if (!$fg_color) $fg_color = "";
235 if (!$bg_color) $bg_color = "";
236
237 print "<td width='5%' align='center'><input
238 onclick='toggleSelectRow(this);'
239 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
240
241 $id = $line['id'];
242
243 print "<td>";
244
245 print "<div class='labelColorIndicator' id='LICID-$id'
246 style='color : $fg_color; background-color : $bg_color'
247 title='".__('Click to change color')."'
248 onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">&alpha;";
249 print_color_picker($id);
250 print "</div>";
251
252
253 print "<span class='prefsLabelEntry'
254 id=\"LILT-".$line["id"]."\">" . $line["caption"] .
255 "</span>";
256
257 print "</td>";
258
259 print "</tr>";
260
261 ++$lnum;
262 }
263
264 print "</table>";
265
266
267 } else {
268 print "<p>";
269 if (!$label_search) {
270 print_warning(__('No labels defined.'));
271 } else {
272 print_warning(__('No matching labels found.'));
273 }
274 print "</p>";
275
276 }
277
278 print "</div>"; #pane
279 print "</div>"; #container
280 }
281
282 function print_color_picker($id) {
283
284 print "<div id=\"colorPicker-$id\"
285 onmouseover=\"colorPickerActive(true)\"
286 onmouseout=\"colorPickerActive(false)\"
287 class=\"colorPicker\" style='display : none'>";
288
289 $color_picker_pairs = array(
290 array('#ff0000', '#ffffff'),
291 array('#009000', '#ffffff'),
292 array('#0000ff', '#ffffff'),
293 array('#ff00ff', '#ffffff'),
294 array('#009090', '#ffffff'),
295
296 array('#ffffff', '#ff0000'),
297 array('#000000', '#00ff00'),
298 array('#ffffff', '#0000ff'),
299 array('#ffffff', '#ff00ff'),
300 array('#000000', '#00ffff'),
301
302 array('#7b07e1', '#ffffff'),
303 array('#0091b4', '#ffffff'),
304 array('#00aa71', '#ffffff'),
305 array('#7d9e01', '#ffffff'),
306 array('#e14a00', '#ffffff'),
307
308 array('#ffffff', '#7b07e1'),
309 array('#ffffff', '#00b5e1'),
310 array('#ffffff', '#00e196'),
311 array('#ffffff', '#b3e100'),
312 array('#ffffff', '#e14a00'),
313
314 array('#000000', '#ffffff'),
315 array('#ffffff', '#000000'),
316 array('#ffffff', '#909000'),
317 array('#063064', '#fff7d5'),
318 array('#ffffff', '#4E4E90'),
319 );
320
321 foreach ($color_picker_pairs as $c) {
322 $fg_color = $c[0];
323 $bg_color = $c[1];
324
325 print "<div class='colorPickerEntry'
326 style='color : $fg_color; background-color : $bg_color;'
327 onclick=\"colorPickerDo('$id', '$fg_color', '$bg_color')\">&alpha;</div>";
328
329 }
330
331 print "<br clear='both'>";
332
333 print "<br/><b>".__('custom color:')."</b>";
334 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'fg')\">".__("foreground")."</div>";
335 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'bg')\">".__("background")."</div>";
336
337 print "</div>";
338 }
339
340 ?>