]>
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 | } | |
b8776a07 AD |
24 | } |
25 | ||
aec9df48 AD |
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 | ||
b8776a07 AD |
38 | } |
39 | ||
ceb30ba4 | 40 | if ($subop == "save") { |
071ec48f | 41 | |
ceb30ba4 | 42 | $id = db_escape_string($_REQUEST["id"]); |
9c5e85fe | 43 | $caption = db_escape_string(trim($_REQUEST["value"])); |
071ec48f | 44 | |
ceb30ba4 | 45 | db_query($link, "BEGIN"); |
10fa6615 | 46 | |
ceb30ba4 AD |
47 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 |
48 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 49 | |
ceb30ba4 AD |
50 | if (db_num_rows($result) != 0) { |
51 | $old_caption = db_fetch_result($result, 0, "caption"); | |
a4919a16 | 52 | |
ceb30ba4 AD |
53 | $result = db_query($link, "SELECT id FROM ttrss_labels2 |
54 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 55 | |
ceb30ba4 AD |
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"]); | |
ef8be8ea | 61 | |
ceb30ba4 | 62 | /* Update filters that reference label being renamed */ |
ef8be8ea | 63 | |
7a13338b AD |
64 | $old_caption = db_escape_string($old_caption); |
65 | ||
ceb30ba4 AD |
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"]); | |
ef8be8ea | 70 | |
9c5e85fe | 71 | print $_REQUEST["value"]; |
625acd1c AD |
72 | } else { |
73 | print $old_caption; | |
ceb30ba4 AD |
74 | } |
75 | } else { | |
76 | print $old_caption; | |
ef8be8ea | 77 | } |
ef8be8ea AD |
78 | } |
79 | ||
ceb30ba4 | 80 | db_query($link, "COMMIT"); |
ef8be8ea AD |
81 | |
82 | return; | |
83 | } | |
84 | ||
ef8be8ea AD |
85 | if ($subop == "remove") { |
86 | ||
b4e75b2a | 87 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
ef8be8ea | 88 | |
f6f7817d | 89 | foreach ($ids as $id) { |
1380f8ee | 90 | label_remove($link, $id, $_SESSION["uid"]); |
ef8be8ea | 91 | } |
f6f7817d | 92 | |
ef8be8ea AD |
93 | } |
94 | ||
95 | if ($subop == "add") { | |
b4e75b2a | 96 | $caption = db_escape_string($_REQUEST["caption"]); |
1c31e190 | 97 | $output = db_escape_string($_REQUEST["output"]); |
ef8be8ea | 98 | |
ceb30ba4 | 99 | if ($caption) { |
caf1f12f | 100 | |
6b2ee18d | 101 | if (label_create($link, $caption)) { |
1c31e190 AD |
102 | if (!$output) { |
103 | print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); | |
104 | } | |
ceb30ba4 | 105 | } |
6b2ee18d | 106 | |
1c31e190 AD |
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 | } | |
5e6f933a AD |
117 | } |
118 | ||
119 | return; | |
ef8be8ea AD |
120 | } |
121 | ||
fe8d2059 AD |
122 | set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig"); |
123 | ||
b4e75b2a | 124 | $sort = db_escape_string($_REQUEST["sort"]); |
ef8be8ea AD |
125 | |
126 | if (!$sort || $sort == "undefined") { | |
ceb30ba4 | 127 | $sort = "caption"; |
ef8be8ea AD |
128 | } |
129 | ||
b4e75b2a | 130 | $label_search = db_escape_string($_REQUEST["search"]); |
112d2aec | 131 | |
b4e75b2a | 132 | if (array_key_exists("search", $_REQUEST)) { |
112d2aec AD |
133 | $_SESSION["prefs_label_search"] = $label_search; |
134 | } else { | |
135 | $label_search = $_SESSION["prefs_label_search"]; | |
136 | } | |
137 | ||
577399e8 | 138 | print "<div style='float : right'> |
112d2aec | 139 | <input id=\"label_search\" size=\"20\" type=\"search\" |
4cf6fc6a AD |
140 | onfocus=\"javascript:disableHotkeys();\" |
141 | onblur=\"javascript:enableHotkeys();\" | |
112d2aec | 142 | onchange=\"javascript:updateLabelList()\" value=\"$label_search\"> |
577399e8 | 143 | <button onclick=\"javascript:updateLabelList()\">".__('Search')."</button> |
112d2aec | 144 | </div>"; |
0d32b41e | 145 | |
ef8be8ea AD |
146 | print "<div class=\"prefGenericAddBox\">"; |
147 | ||
577399e8 AD |
148 | print"<button onclick=\"return addLabel()\">". |
149 | __('Create label')."</button> "; | |
1e5548db | 150 | |
577399e8 AD |
151 | print "<button onclick=\"javascript:removeSelectedLabels()\">". |
152 | __('Remove')."</button> "; | |
1e5548db | 153 | |
577399e8 AD |
154 | print "<button onclick=\"labelColorReset()\">". |
155 | __('Clear colors')."</button>"; | |
1e5548db AD |
156 | |
157 | ||
158 | print "</div>"; | |
ef8be8ea | 159 | |
112d2aec | 160 | if ($label_search) { |
1638fc4e AD |
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 | ||
112d2aec AD |
174 | } else { |
175 | $label_search_query = ""; | |
176 | } | |
177 | ||
ef8be8ea | 178 | $result = db_query($link, "SELECT |
2eb9c95c | 179 | * |
ef8be8ea | 180 | FROM |
ceb30ba4 | 181 | ttrss_labels2 |
ef8be8ea | 182 | WHERE |
112d2aec | 183 | $label_search_query |
ef8be8ea AD |
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 | ||
ef8be8ea AD |
191 | print "<p><table width=\"100%\" cellspacing=\"0\" |
192 | class=\"prefLabelList\" id=\"prefLabelList\">"; | |
193 | ||
194 | print "<tr><td class=\"selectPrompt\" colspan=\"8\"> | |
e8d0177d AD |
195 | ".__('Select:')." |
196 | <a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>, | |
197 | <a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a> | |
ef8be8ea AD |
198 | </td</tr>"; |
199 | ||
4d23f96e | 200 | /* print "<tr class=\"title\"> |
ef8be8ea | 201 | <td width=\"5%\"> </td> |
4d23f96e | 202 | <td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td> |
ef8be8ea | 203 | </td> |
4d23f96e | 204 | </tr>"; */ |
ef8be8ea AD |
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"]; | |
ceb30ba4 AD |
213 | $this_row_id = "id=\"LILRR-$label_id\""; |
214 | ||
ef8be8ea AD |
215 | print "<tr class=\"$class\" $this_row_id>"; |
216 | ||
ceb30ba4 | 217 | $line["caption"] = htmlspecialchars($line["caption"]); |
2eb9c95c AD |
218 | |
219 | $fg_color = $line["fg_color"]; | |
220 | $bg_color = $line["bg_color"]; | |
221 | ||
aec9df48 AD |
222 | if (!$fg_color) $fg_color = ""; |
223 | if (!$bg_color) $bg_color = ""; | |
2eb9c95c | 224 | |
4d23f96e | 225 | print "<td width='5%' align='center'><input |
ceb30ba4 | 226 | onclick='toggleSelectPrefRow(this, \"label\");' |
ef8be8ea AD |
227 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; |
228 | ||
76b2bc65 | 229 | $id = $line['id']; |
c17d514b | 230 | |
aec9df48 AD |
231 | print "<td>"; |
232 | ||
233 | print "<div class='labelColorIndicator' id='LICID-$id' | |
2eb9c95c | 234 | style='color : $fg_color; background-color : $bg_color' |
7daf349a | 235 | title='".__('Click to change color')."' |
b6ba48c1 AD |
236 | onclick=\"colorPicker('$id', '$fg_color', '$bg_color')\">α"; |
237 | print_color_picker($id); | |
238 | print "</div>"; | |
c17d514b | 239 | |
c17d514b | 240 | |
aec9df48 | 241 | print "<span class='prefsLabelEntry' |
2eb9c95c | 242 | id=\"LILT-".$line["id"]."\">" . $line["caption"] . |
c17d514b AD |
243 | "</span>"; |
244 | ||
76b2bc65 | 245 | print "</td>"; |
ef8be8ea AD |
246 | |
247 | print "</tr>"; | |
248 | ||
249 | ++$lnum; | |
250 | } | |
a5bd7bf0 | 251 | |
ef8be8ea | 252 | print "</table>"; |
ef8be8ea | 253 | |
ef8be8ea AD |
254 | |
255 | } else { | |
a5bd7bf0 AD |
256 | print "<p>"; |
257 | if (!$label_search) { | |
cea04d61 | 258 | print_warning(__('No labels defined.')); |
a5bd7bf0 | 259 | } else { |
cea04d61 | 260 | print_warning(__('No matching labels found.')); |
a5bd7bf0 AD |
261 | } |
262 | print "</p>"; | |
263 | ||
ef8be8ea AD |
264 | } |
265 | } | |
1d4a2918 AD |
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')\">α</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 | ||
ef8be8ea | 325 | ?> |