]> git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
proper color editor for labels
[tt-rss.git] / modules / pref-labels.php
1 <?php
2 function module_pref_labels($link) {
3
4 $subop = $_GET["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 db_query($link, "UPDATE ttrss_filters SET
65 action_param = '$caption' WHERE action_param = '$old_caption'
66 AND action_id = 7
67 AND owner_uid = " . $_SESSION["uid"]);
68
69 print $_REQUEST["value"];
70 } else {
71 print $old_caption;
72 }
73 } else {
74 print $old_caption;
75 }
76 }
77
78 db_query($link, "COMMIT");
79
80 return;
81 }
82
83 if ($subop == "remove") {
84
85 $ids = split(",", db_escape_string($_GET["ids"]));
86
87 foreach ($ids as $id) {
88 label_remove($link, $id, $_SESSION["uid"]);
89 }
90
91 }
92
93 if ($subop == "add") {
94
95 $caption = db_escape_string($_GET["caption"]);
96
97 if ($caption) {
98
99 if (label_create($link, $caption)) {
100 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
101 }
102
103 }
104
105 return;
106 }
107
108 set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
109
110 $sort = db_escape_string($_GET["sort"]);
111
112 if (!$sort || $sort == "undefined") {
113 $sort = "caption";
114 }
115
116 $label_search = db_escape_string($_GET["search"]);
117
118 if (array_key_exists("search", $_GET)) {
119 $_SESSION["prefs_label_search"] = $label_search;
120 } else {
121 $label_search = $_SESSION["prefs_label_search"];
122 }
123
124 function print_color_picker($id) {
125
126 print "<div id=\"colorPicker-$id\"
127 onmouseover=\"colorPickerActive(true)\"
128 onmouseout=\"colorPickerActive(false)\"
129 class=\"colorPicker\" style='display : none'>";
130
131 $color_picker_pairs = array(
132 array('#ff0000', '#ffffff'),
133 array('#009000', '#ffffff'),
134 array('#0000ff', '#ffffff'),
135 array('#ff00ff', '#ffffff'),
136 array('#009090', '#ffffff'),
137 array('#ffffff', '#ff0000'),
138 array('#000000', '#00ff00'),
139 array('#ffffff', '#0000ff'),
140 array('#ffffff', '#ff00ff'),
141 array('#000000', '#00ffff'),
142 array('#000000', '#ffffff'),
143 array('#ffffff', '#000000'),
144 array('#ffffff', '#909000'),
145 array('#063064', '#fff7d5'),
146 array('#ffffff', '#4E4E90'),
147 );
148
149 foreach ($color_picker_pairs as $c) {
150 $fg_color = $c[0];
151 $bg_color = $c[1];
152
153 print "<div class='colorPickerEntry'
154 style='color : $fg_color; background-color : $bg_color;'
155 onclick=\"colorPickerDo('$id', '$fg_color', '$bg_color')\">&alpha;</div>";
156
157 }
158
159 print "<br clear='both'>";
160
161 print "<br/><b>".__('custom color:')."</b>";
162 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'fg')\">".__("foreground")."</div>";
163 print "<div class=\"ccPrompt\" onclick=\"labelColorAsk('$id', 'bg')\">".__("background")."</div>";
164
165 print "</div>";
166 }
167
168 print "<div class=\"feedEditSearch\">
169 <input id=\"label_search\" size=\"20\" type=\"search\"
170 onfocus=\"javascript:disableHotkeys();\"
171 onblur=\"javascript:enableHotkeys();\"
172 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
173 <input type=\"submit\" class=\"button\"
174 onclick=\"javascript:updateLabelList()\" value=\"".__('Search')."\">
175 </div>";
176
177 print "<div class=\"prefGenericAddBox\">";
178
179 print"<input type=\"submit\" class=\"button\"
180 id=\"label_create_btn\"
181 onclick=\"return addLabel()\"
182 value=\"".__('Create label')."\"></div>";
183
184 if ($label_search) {
185 $label_search_query = "caption LIKE '%$label_search%' AND";
186 } else {
187 $label_search_query = "";
188 }
189
190 $result = db_query($link, "SELECT
191 *
192 FROM
193 ttrss_labels2
194 WHERE
195 $label_search_query
196 owner_uid = ".$_SESSION["uid"]."
197 ORDER BY $sort");
198
199 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
200
201 if (db_num_rows($result) != 0) {
202
203 print "<p><table width=\"100%\" cellspacing=\"0\"
204 class=\"prefLabelList\" id=\"prefLabelList\">";
205
206 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
207 ".__('Select:')."
208 <a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>,
209 <a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a>
210 </td</tr>";
211
212 /* print "<tr class=\"title\">
213 <td width=\"5%\">&nbsp;</td>
214 <td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
215 </td>
216 </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='toggleSelectPrefRow(this, \"label\");'
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 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 print "<p id=\"labelOpToolbar\">";
266
267 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
268 onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
269
270 print "&nbsp;";
271 /* print "&nbsp;<input type=\"submit\" class=\"button\" disabled=\"true\"
272 onclick=\"labelColorSet('fg')\" value=\"".__('Fg')."\">&nbsp;";
273 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
274 onclick=\"labelColorSet('bg')\" value=\"".__('Bg')."\">&nbsp;"; */
275 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
276 onclick=\"labelColorReset()\" value=\"".__('Clear colors')."\">";
277
278 print "</p>";
279
280 } else {
281 print "<p>";
282 if (!$label_search) {
283 print __('No labels defined.');
284 } else {
285 print __('No matching labels found.');
286 }
287 print "</p>";
288
289 }
290 }
291 ?>