]> git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
prefs: reorganize toolbar buttons
[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
97 $caption = db_escape_string($_REQUEST["caption"]);
98
99 if ($caption) {
100
101 if (label_create($link, $caption)) {
102 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
103 }
104
105 }
106
107 return;
108 }
109
110 set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
111
112 $sort = db_escape_string($_REQUEST["sort"]);
113
114 if (!$sort || $sort == "undefined") {
115 $sort = "caption";
116 }
117
118 $label_search = db_escape_string($_REQUEST["search"]);
119
120 if (array_key_exists("search", $_REQUEST)) {
121 $_SESSION["prefs_label_search"] = $label_search;
122 } else {
123 $label_search = $_SESSION["prefs_label_search"];
124 }
125
126 print "<div class=\"feedEditSearch\">
127 <input id=\"label_search\" size=\"20\" type=\"search\"
128 onfocus=\"javascript:disableHotkeys();\"
129 onblur=\"javascript:enableHotkeys();\"
130 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
131 <input type=\"submit\" class=\"button\"
132 onclick=\"javascript:updateLabelList()\" value=\"".__('Search')."\">
133 </div>";
134
135 print "<div class=\"prefGenericAddBox\">";
136
137 print"<input type=\"submit\" class=\"button\"
138 id=\"label_create_btn\"
139 onclick=\"return addLabel()\"
140 value=\"".__('Create label')."\"> ";
141
142 print "<input type=\"submit\" class=\"button\"
143 onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
144
145 print "&nbsp;";
146 /* print "&nbsp;<input type=\"submit\" class=\"button\" disabled=\"true\"
147 onclick=\"labelColorSet('fg')\" value=\"".__('Fg')."\">&nbsp;";
148 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
149 onclick=\"labelColorSet('bg')\" value=\"".__('Bg')."\">&nbsp;"; */
150 print "<input type=\"submit\" class=\"button\"
151 onclick=\"labelColorReset()\" value=\"".__('Clear colors')."\">";
152
153
154 print "</div>";
155
156 if ($label_search) {
157
158 $label_search = split(" ", $label_search);
159 $tokens = array();
160
161 foreach ($label_search as $token) {
162
163 $token = trim($token);
164 array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))");
165
166 }
167
168 $label_search_query = "(" . join($tokens, " AND ") . ") AND ";
169
170 } else {
171 $label_search_query = "";
172 }
173
174 $result = db_query($link, "SELECT
175 *
176 FROM
177 ttrss_labels2
178 WHERE
179 $label_search_query
180 owner_uid = ".$_SESSION["uid"]."
181 ORDER BY $sort");
182
183 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
184
185 if (db_num_rows($result) != 0) {
186
187 print "<p><table width=\"100%\" cellspacing=\"0\"
188 class=\"prefLabelList\" id=\"prefLabelList\">";
189
190 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
191 ".__('Select:')."
192 <a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>,
193 <a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a>
194 </td</tr>";
195
196 /* print "<tr class=\"title\">
197 <td width=\"5%\">&nbsp;</td>
198 <td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
199 </td>
200 </tr>"; */
201
202 $lnum = 0;
203
204 while ($line = db_fetch_assoc($result)) {
205
206 $class = ($lnum % 2) ? "even" : "odd";
207
208 $label_id = $line["id"];
209 $this_row_id = "id=\"LILRR-$label_id\"";
210
211 print "<tr class=\"$class\" $this_row_id>";
212
213 $line["caption"] = htmlspecialchars($line["caption"]);
214
215 $fg_color = $line["fg_color"];
216 $bg_color = $line["bg_color"];
217
218 if (!$fg_color) $fg_color = "";
219 if (!$bg_color) $bg_color = "";
220
221 print "<td width='5%' align='center'><input
222 onclick='toggleSelectPrefRow(this, \"label\");'
223 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
224
225 $id = $line['id'];
226
227 print "<td>";
228
229 print "<div class='labelColorIndicator' id='LICID-$id'
230 style='color : $fg_color; background-color : $bg_color'
231 title='".__('Click to change color')."'
232 onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">&alpha;";
233 print_color_picker($id);
234 print "</div>";
235
236
237 print "<span class='prefsLabelEntry'
238 id=\"LILT-".$line["id"]."\">" . $line["caption"] .
239 "</span>";
240
241 print "</td>";
242
243 print "</tr>";
244
245 ++$lnum;
246 }
247
248 print "</table>";
249
250
251 } else {
252 print "<p>";
253 if (!$label_search) {
254 print_warning(__('No labels defined.'));
255 } else {
256 print_warning(__('No matching labels found.'));
257 }
258 print "</p>";
259
260 }
261 }
262
263 function print_color_picker($id) {
264
265 print "<div id=\"colorPicker-$id\"
266 onmouseover=\"colorPickerActive(true)\"
267 onmouseout=\"colorPickerActive(false)\"
268 class=\"colorPicker\" style='display : none'>";
269
270 $color_picker_pairs = array(
271 array('#ff0000', '#ffffff'),
272 array('#009000', '#ffffff'),
273 array('#0000ff', '#ffffff'),
274 array('#ff00ff', '#ffffff'),
275 array('#009090', '#ffffff'),
276
277 array('#ffffff', '#ff0000'),
278 array('#000000', '#00ff00'),
279 array('#ffffff', '#0000ff'),
280 array('#ffffff', '#ff00ff'),
281 array('#000000', '#00ffff'),
282
283 array('#7b07e1', '#ffffff'),
284 array('#0091b4', '#ffffff'),
285 array('#00aa71', '#ffffff'),
286 array('#7d9e01', '#ffffff'),
287 array('#e14a00', '#ffffff'),
288
289 array('#ffffff', '#7b07e1'),
290 array('#ffffff', '#00b5e1'),
291 array('#ffffff', '#00e196'),
292 array('#ffffff', '#b3e100'),
293 array('#ffffff', '#e14a00'),
294
295 array('#000000', '#ffffff'),
296 array('#ffffff', '#000000'),
297 array('#ffffff', '#909000'),
298 array('#063064', '#fff7d5'),
299 array('#ffffff', '#4E4E90'),
300 );
301
302 foreach ($color_picker_pairs as $c) {
303 $fg_color = $c[0];
304 $bg_color = $c[1];
305
306 print "<div class='colorPickerEntry'
307 style='color : $fg_color; background-color : $bg_color;'
308 onclick=\"colorPickerDo('$id', '$fg_color', '$bg_color')\">&alpha;</div>";
309
310 }
311
312 print "<br clear='both'>";
313
314 print "<br/><b>".__('custom color:')."</b>";
315 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'fg')\">".__("foreground")."</div>";
316 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'bg')\">".__("background")."</div>";
317
318 print "</div>";
319 }
320
321 ?>