]> git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
misc code cleanup, allow ctrl-key selection in prefs
[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 style='float : right'>
154 <input id=\"label_search\" size=\"20\" type=\"search\"
155 onfocus=\"javascript:disableHotkeys();\"
156 onblur=\"javascript:enableHotkeys();\"
157 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
158 <button onclick=\"javascript:updateLabelList()\">".__('Search')."</button>
159 </div>";
160
161 print "<div class=\"prefGenericAddBox\">";
162
163 print"<button onclick=\"return addLabel()\">".
164 __('Create label')."</button> ";
165
166 print "<button onclick=\"javascript:removeSelectedLabels()\">".
167 __('Remove')."</button> ";
168
169 print "<button onclick=\"labelColorReset()\">".
170 __('Clear colors')."</button>";
171
172
173 print "</div>";
174
175 if ($label_search) {
176
177 $label_search = split(" ", $label_search);
178 $tokens = array();
179
180 foreach ($label_search as $token) {
181
182 $token = trim($token);
183 array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
184
185 }
186
187 $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
188
189 } else {
190 $label_search_query = "";
191 }
192
193 $result = db_query($link, "SELECT
194 *
195 FROM
196 ttrss_labels2
197 WHERE
198 $label_search_query
199 owner_uid = ".$_SESSION["uid"]."
200 ORDER BY $sort");
201
202 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
203
204 if (db_num_rows($result) != 0) {
205
206 print "<p><table width=\"100%\" cellspacing=\"0\"
207 class=\"prefLabelList\" id=\"prefLabelList\">";
208
209 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
210 ".__('Select:')."
211 <a href=\"#\" onclick=\"selectPrefRows('label', true)\">".__('All')."</a>,
212 <a href=\"#\" onclick=\"selectPrefRows('label', false)\">".__('None')."</a>
213 </td</tr>";
214
215 /* print "<tr class=\"title\">
216 <td width=\"5%\">&nbsp;</td>
217 <td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
218 </td>
219 </tr>"; */
220
221 $lnum = 0;
222
223 while ($line = db_fetch_assoc($result)) {
224
225 $class = ($lnum % 2) ? "even" : "odd";
226
227 $label_id = $line["id"];
228 $this_row_id = "id=\"LILRR-$label_id\"";
229
230 print "<tr class=\"$class\" $this_row_id>";
231
232 $line["caption"] = htmlspecialchars($line["caption"]);
233
234 $fg_color = $line["fg_color"];
235 $bg_color = $line["bg_color"];
236
237 if (!$fg_color) $fg_color = "";
238 if (!$bg_color) $bg_color = "";
239
240 print "<td width='5%' align='center'><input
241 onclick='toggleSelectRow(this);'
242 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
243
244 $id = $line['id'];
245
246 print "<td>";
247
248 print "<div class='labelColorIndicator' id='LICID-$id'
249 style='color : $fg_color; background-color : $bg_color'
250 title='".__('Click to change color')."'
251 onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">&alpha;";
252 print_color_picker($id);
253 print "</div>";
254
255
256 print "<span class='prefsLabelEntry'
257 id=\"LILT-".$line["id"]."\">" . $line["caption"] .
258 "</span>";
259
260 print "</td>";
261
262 print "</tr>";
263
264 ++$lnum;
265 }
266
267 print "</table>";
268
269
270 } else {
271 print "<p>";
272 if (!$label_search) {
273 print_warning(__('No labels defined.'));
274 } else {
275 print_warning(__('No matching labels found.'));
276 }
277 print "</p>";
278
279 }
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 ?>