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