]>
Commit | Line | Data |
---|---|---|
ef8be8ea | 1 | <?php |
ef8be8ea | 2 | function module_pref_labels($link) { |
ef8be8ea | 3 | |
b4e75b2a | 4 | $subop = $_REQUEST["subop"]; |
ef8be8ea | 5 | |
b8776a07 AD |
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"]); | |
b6ba48c1 AD |
10 | $fg = db_escape_string($_REQUEST["fg"]); |
11 | $bg = db_escape_string($_REQUEST["bg"]); | |
b8776a07 AD |
12 | |
13 | foreach ($ids as $id) { | |
b6ba48c1 AD |
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 | } | |
905ff52a AD |
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 | ||
b8776a07 AD |
32 | } |
33 | ||
aec9df48 AD |
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"]); | |
905ff52a AD |
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"]); | |
aec9df48 AD |
51 | } |
52 | ||
b8776a07 AD |
53 | } |
54 | ||
ceb30ba4 | 55 | if ($subop == "save") { |
071ec48f | 56 | |
ceb30ba4 | 57 | $id = db_escape_string($_REQUEST["id"]); |
9c5e85fe | 58 | $caption = db_escape_string(trim($_REQUEST["value"])); |
071ec48f | 59 | |
ceb30ba4 | 60 | db_query($link, "BEGIN"); |
10fa6615 | 61 | |
ceb30ba4 AD |
62 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 |
63 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 64 | |
ceb30ba4 AD |
65 | if (db_num_rows($result) != 0) { |
66 | $old_caption = db_fetch_result($result, 0, "caption"); | |
a4919a16 | 67 | |
ceb30ba4 AD |
68 | $result = db_query($link, "SELECT id FROM ttrss_labels2 |
69 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 70 | |
ceb30ba4 AD |
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"]); | |
ef8be8ea | 76 | |
ceb30ba4 | 77 | /* Update filters that reference label being renamed */ |
ef8be8ea | 78 | |
7a13338b AD |
79 | $old_caption = db_escape_string($old_caption); |
80 | ||
ceb30ba4 AD |
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"]); | |
ef8be8ea | 85 | |
9c5e85fe | 86 | print $_REQUEST["value"]; |
625acd1c AD |
87 | } else { |
88 | print $old_caption; | |
ceb30ba4 AD |
89 | } |
90 | } else { | |
91 | print $old_caption; | |
ef8be8ea | 92 | } |
ef8be8ea AD |
93 | } |
94 | ||
ceb30ba4 | 95 | db_query($link, "COMMIT"); |
ef8be8ea AD |
96 | |
97 | return; | |
98 | } | |
99 | ||
ef8be8ea AD |
100 | if ($subop == "remove") { |
101 | ||
b4e75b2a | 102 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
ef8be8ea | 103 | |
f6f7817d | 104 | foreach ($ids as $id) { |
1380f8ee | 105 | label_remove($link, $id, $_SESSION["uid"]); |
ef8be8ea | 106 | } |
f6f7817d | 107 | |
ef8be8ea AD |
108 | } |
109 | ||
110 | if ($subop == "add") { | |
b4e75b2a | 111 | $caption = db_escape_string($_REQUEST["caption"]); |
1c31e190 | 112 | $output = db_escape_string($_REQUEST["output"]); |
ef8be8ea | 113 | |
ceb30ba4 | 114 | if ($caption) { |
caf1f12f | 115 | |
6b2ee18d | 116 | if (label_create($link, $caption)) { |
1c31e190 | 117 | if (!$output) { |
1985a5e0 | 118 | //print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); |
1c31e190 | 119 | } |
ceb30ba4 | 120 | } |
6b2ee18d | 121 | |
1c31e190 AD |
122 | if ($output == "select") { |
123 | header("Content-Type: text/xml"); | |
124 | ||
10249c41 | 125 | print "<rpc-reply><payload>"; |
1c31e190 AD |
126 | |
127 | print_label_select($link, "select_label", | |
128 | $caption, ""); | |
129 | ||
10249c41 | 130 | print "</payload></rpc-reply>"; |
1c31e190 | 131 | } |
5e6f933a AD |
132 | } |
133 | ||
134 | return; | |
ef8be8ea AD |
135 | } |
136 | ||
fe8d2059 AD |
137 | set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig"); |
138 | ||
b4e75b2a | 139 | $sort = db_escape_string($_REQUEST["sort"]); |
ef8be8ea AD |
140 | |
141 | if (!$sort || $sort == "undefined") { | |
ceb30ba4 | 142 | $sort = "caption"; |
ef8be8ea AD |
143 | } |
144 | ||
b4e75b2a | 145 | $label_search = db_escape_string($_REQUEST["search"]); |
112d2aec | 146 | |
b4e75b2a | 147 | if (array_key_exists("search", $_REQUEST)) { |
112d2aec AD |
148 | $_SESSION["prefs_label_search"] = $label_search; |
149 | } else { | |
150 | $label_search = $_SESSION["prefs_label_search"]; | |
151 | } | |
152 | ||
8df7184c AD |
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'> | |
112d2aec | 158 | <input id=\"label_search\" size=\"20\" type=\"search\" |
1985a5e0 | 159 | dojoType=\"dijit.form.TextBox\" |
4cf6fc6a AD |
160 | onfocus=\"javascript:disableHotkeys();\" |
161 | onblur=\"javascript:enableHotkeys();\" | |
112d2aec | 162 | onchange=\"javascript:updateLabelList()\" value=\"$label_search\"> |
1985a5e0 | 163 | <button dojoType=\"dijit.form.Button\" onclick=\"javascript:updateLabelList()\">".__('Search')."</button> |
112d2aec | 164 | </div>"; |
0d32b41e | 165 | |
1985a5e0 AD |
166 | print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">". |
167 | __('Create label')."</button dojoType=\"dijit.form.Button\"> "; | |
1e5548db | 168 | |
1985a5e0 AD |
169 | print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">". |
170 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
1e5548db | 171 | |
1985a5e0 AD |
172 | print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">". |
173 | __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; | |
1e5548db AD |
174 | |
175 | ||
8df7184c AD |
176 | print "</div>"; #toolbar |
177 | print "</div>"; #pane | |
178 | print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
ef8be8ea | 179 | |
112d2aec | 180 | if ($label_search) { |
1638fc4e AD |
181 | |
182 | $label_search = split(" ", $label_search); | |
183 | $tokens = array(); | |
184 | ||
185 | foreach ($label_search as $token) { | |
186 | ||
187 | $token = trim($token); | |
188 | array_push($tokens, "(UPPER(caption) LIKE UPPER('%$token%'))"); | |
189 | ||
190 | } | |
191 | ||
192 | $label_search_query = "(" . join($tokens, " AND ") . ") AND "; | |
193 | ||
112d2aec AD |
194 | } else { |
195 | $label_search_query = ""; | |
196 | } | |
197 | ||
ef8be8ea | 198 | $result = db_query($link, "SELECT |
2eb9c95c | 199 | * |
ef8be8ea | 200 | FROM |
ceb30ba4 | 201 | ttrss_labels2 |
ef8be8ea | 202 | WHERE |
112d2aec | 203 | $label_search_query |
ef8be8ea AD |
204 | owner_uid = ".$_SESSION["uid"]." |
205 | ORDER BY $sort"); | |
206 | ||
ef8be8ea AD |
207 | if (db_num_rows($result) != 0) { |
208 | ||
ef8be8ea AD |
209 | print "<p><table width=\"100%\" cellspacing=\"0\" |
210 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
211 | ||
212 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
e8d0177d | 213 | ".__('Select:')." |
e69fb880 AD |
214 | <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'all')\">".__('All')."</a>, |
215 | <a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'none')\">".__('None')."</a> | |
ef8be8ea AD |
216 | </td</tr>"; |
217 | ||
ef8be8ea AD |
218 | $lnum = 0; |
219 | ||
220 | while ($line = db_fetch_assoc($result)) { | |
221 | ||
222 | $class = ($lnum % 2) ? "even" : "odd"; | |
223 | ||
224 | $label_id = $line["id"]; | |
ceb30ba4 AD |
225 | $this_row_id = "id=\"LILRR-$label_id\""; |
226 | ||
ef8be8ea AD |
227 | print "<tr class=\"$class\" $this_row_id>"; |
228 | ||
ceb30ba4 | 229 | $line["caption"] = htmlspecialchars($line["caption"]); |
2eb9c95c AD |
230 | |
231 | $fg_color = $line["fg_color"]; | |
232 | $bg_color = $line["bg_color"]; | |
233 | ||
aec9df48 AD |
234 | if (!$fg_color) $fg_color = ""; |
235 | if (!$bg_color) $bg_color = ""; | |
2eb9c95c | 236 | |
4d23f96e | 237 | print "<td width='5%' align='center'><input |
a998dbef | 238 | onclick='toggleSelectRow(this);' |
ef8be8ea AD |
239 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; |
240 | ||
76b2bc65 | 241 | $id = $line['id']; |
c17d514b | 242 | |
aec9df48 AD |
243 | print "<td>"; |
244 | ||
245 | print "<div class='labelColorIndicator' id='LICID-$id' | |
2eb9c95c | 246 | style='color : $fg_color; background-color : $bg_color' |
7daf349a | 247 | title='".__('Click to change color')."' |
b6ba48c1 AD |
248 | onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">α"; |
249 | print_color_picker($id); | |
250 | print "</div>"; | |
c17d514b | 251 | |
c17d514b | 252 | |
aec9df48 | 253 | print "<span class='prefsLabelEntry' |
2eb9c95c | 254 | id=\"LILT-".$line["id"]."\">" . $line["caption"] . |
c17d514b AD |
255 | "</span>"; |
256 | ||
76b2bc65 | 257 | print "</td>"; |
ef8be8ea AD |
258 | |
259 | print "</tr>"; | |
260 | ||
261 | ++$lnum; | |
262 | } | |
a5bd7bf0 | 263 | |
ef8be8ea | 264 | print "</table>"; |
ef8be8ea | 265 | |
ef8be8ea AD |
266 | |
267 | } else { | |
a5bd7bf0 AD |
268 | print "<p>"; |
269 | if (!$label_search) { | |
cea04d61 | 270 | print_warning(__('No labels defined.')); |
a5bd7bf0 | 271 | } else { |
cea04d61 | 272 | print_warning(__('No matching labels found.')); |
a5bd7bf0 AD |
273 | } |
274 | print "</p>"; | |
275 | ||
ef8be8ea | 276 | } |
8df7184c AD |
277 | |
278 | print "</div>"; #pane | |
279 | print "</div>"; #container | |
ef8be8ea | 280 | } |
1d4a2918 AD |
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')\">α</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 | ||
ef8be8ea | 340 | ?> |