]> git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
e683ab6154491206b56f9c1a09bd7f4fed9daae5
[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 onfocus=\"javascript:disableHotkeys();\"
160 onblur=\"javascript:enableHotkeys();\"
161 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
162 <button onclick=\"javascript:updateLabelList()\">".__('Search')."</button>
163 </div>";
164
165 print"<button onclick=\"return addLabel()\">".
166 __('Create label')."</button> ";
167
168 print "<button onclick=\"removeSelectedLabels()\">".
169 __('Remove')."</button> ";
170
171 print "<button onclick=\"labelColorReset()\">".
172 __('Clear colors')."</button>";
173
174
175 print "</div>"; #toolbar
176 print "</div>"; #pane
177 print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
178
179 if ($label_search) {
180
181 $label_search = split(" ", $label_search);
182 $tokens = array();
183
184 foreach ($label_search as $token) {
185
186 $token = trim($token);
187 array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
188
189 }
190
191 $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
192
193 } else {
194 $label_search_query = "";
195 }
196
197 $result = db_query($link, "SELECT
198 *
199 FROM
200 ttrss_labels2
201 WHERE
202 $label_search_query
203 owner_uid = ".$_SESSION["uid"]."
204 ORDER BY $sort");
205
206 if (db_num_rows($result) != 0) {
207
208 print "<p><table width=\"100%\" cellspacing=\"0\"
209 class=\"prefLabelList\" id=\"prefLabelList\">";
210
211 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
212 ".__('Select:')."
213 <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'all')\">".__('All')."</a>,
214 <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'none')\">".__('None')."</a>
215 </td</tr>";
216
217 $lnum = 0;
218
219 while ($line = db_fetch_assoc($result)) {
220
221 $class = ($lnum % 2) ? "even" : "odd";
222
223 $label_id = $line["id"];
224 $this_row_id = "id=\"LILRR-$label_id\"";
225
226 print "<tr class=\"$class\" $this_row_id>";
227
228 $line["caption"] = htmlspecialchars($line["caption"]);
229
230 $fg_color = $line["fg_color"];
231 $bg_color = $line["bg_color"];
232
233 if (!$fg_color) $fg_color = "";
234 if (!$bg_color) $bg_color = "";
235
236 print "<td width='5%' align='center'><input
237 onclick='toggleSelectRow(this);'
238 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
239
240 $id = $line['id'];
241
242 print "<td>";
243
244 print "<div class='labelColorIndicator' id='LICID-$id'
245 style='color : $fg_color; background-color : $bg_color'
246 title='".__('Click to change color')."'
247 onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">&alpha;";
248 print_color_picker($id);
249 print "</div>";
250
251
252 print "<span class='prefsLabelEntry'
253 id=\"LILT-".$line["id"]."\">" . $line["caption"] .
254 "</span>";
255
256 print "</td>";
257
258 print "</tr>";
259
260 ++$lnum;
261 }
262
263 print "</table>";
264
265
266 } else {
267 print "<p>";
268 if (!$label_search) {
269 print_warning(__('No labels defined.'));
270 } else {
271 print_warning(__('No matching labels found.'));
272 }
273 print "</p>";
274
275 }
276
277 print "</div>"; #pane
278 print "</div>"; #container
279 }
280
281 function print_color_picker($id) {
282
283 print "<div id=\"colorPicker-$id\"
284 onmouseover=\"colorPickerActive(true)\"
285 onmouseout=\"colorPickerActive(false)\"
286 class=\"colorPicker\" style='display : none'>";
287
288 $color_picker_pairs = array(
289 array('#ff0000', '#ffffff'),
290 array('#009000', '#ffffff'),
291 array('#0000ff', '#ffffff'),
292 array('#ff00ff', '#ffffff'),
293 array('#009090', '#ffffff'),
294
295 array('#ffffff', '#ff0000'),
296 array('#000000', '#00ff00'),
297 array('#ffffff', '#0000ff'),
298 array('#ffffff', '#ff00ff'),
299 array('#000000', '#00ffff'),
300
301 array('#7b07e1', '#ffffff'),
302 array('#0091b4', '#ffffff'),
303 array('#00aa71', '#ffffff'),
304 array('#7d9e01', '#ffffff'),
305 array('#e14a00', '#ffffff'),
306
307 array('#ffffff', '#7b07e1'),
308 array('#ffffff', '#00b5e1'),
309 array('#ffffff', '#00e196'),
310 array('#ffffff', '#b3e100'),
311 array('#ffffff', '#e14a00'),
312
313 array('#000000', '#ffffff'),
314 array('#ffffff', '#000000'),
315 array('#ffffff', '#909000'),
316 array('#063064', '#fff7d5'),
317 array('#ffffff', '#4E4E90'),
318 );
319
320 foreach ($color_picker_pairs as $c) {
321 $fg_color = $c[0];
322 $bg_color = $c[1];
323
324 print "<div class='colorPickerEntry'
325 style='color : $fg_color; background-color : $bg_color;'
326 onclick=\"colorPickerDo('$id', '$fg_color', '$bg_color')\">&alpha;</div>";
327
328 }
329
330 print "<br clear='both'>";
331
332 print "<br/><b>".__('custom color:')."</b>";
333 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'fg')\">".__("foreground")."</div>";
334 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'bg')\">".__("background")."</div>";
335
336 print "</div>";
337 }
338
339 ?>