]>
Commit | Line | Data |
---|---|---|
ef8be8ea | 1 | <?php |
ef8be8ea | 2 | function module_pref_labels($link) { |
ef8be8ea | 3 | |
b4e75b2a | 4 | $subop = $_REQUEST["subop"]; |
ef8be8ea | 5 | |
fb8b2153 AD |
6 | if ($subop == "edit") { |
7 | $label_id = db_escape_string($_REQUEST['id']); | |
8 | ||
9 | header("Content-Type: text/xml"); | |
10 | print "<dlg id=\"$subop\">"; | |
11 | print "<title>" . __("Label Editor") . "</title>"; | |
12 | print "<content><![CDATA["; | |
13 | ||
14 | $result = db_query($link, "SELECT * FROM ttrss_labels2 WHERE | |
15 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
16 | ||
17 | $line = db_fetch_assoc($result); | |
18 | ||
018caf6f AD |
19 | print "<form id=\"label_edit_form\" name=\"label_edit_form\" |
20 | onsubmit=\"return false;\">"; | |
21 | ||
22 | print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">"; | |
23 | print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">"; | |
24 | print "<input type=\"hidden\" name=\"subop\" value=\"save\">"; | |
25 | ||
fb8b2153 AD |
26 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; |
27 | ||
28 | print "<div class=\"dlgSecCont\">"; | |
29 | ||
018caf6f AD |
30 | print "<input style=\"font-size : 18px\" name=\"caption\" |
31 | onkeypress=\"return filterCR(event, editLabelSave)\" | |
32 | value=\"".htmlspecialchars($line['caption'])."\">"; | |
fb8b2153 AD |
33 | |
34 | print "</div>"; | |
018caf6f | 35 | print "<div class=\"dlgSec\">" . __("Colors") . "</div>"; |
fb8b2153 AD |
36 | print "<div class=\"dlgSecCont\">"; |
37 | ||
38 | print "<table cellspacing=\"5\"><th>"; | |
39 | ||
018caf6f | 40 | print "<tr><td>".__("Foreground:")."</td><td>".__("Background:"). |
fb8b2153 AD |
41 | "</td></tr>"; |
42 | ||
43 | print "</th><tr><td>"; | |
44 | ||
018caf6f AD |
45 | $fg_color = $line['fg_color']; |
46 | $bg_color = $line['bg_color']; | |
47 | ||
48 | print "<input type=\"hidden\" name=\"fg_color\" value=\"$fg_color\">"; | |
49 | print "<input type=\"hidden\" name=\"bg_color\" value=\"$bg_color\">"; | |
50 | ||
fb8b2153 AD |
51 | print "<div dojoType=\"dijit.ColorPalette\"> |
52 | <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\"> | |
018caf6f | 53 | document.forms['label_edit_form'].fg_color.value = fg_color; |
fb8b2153 AD |
54 | </script> |
55 | </div>"; | |
56 | print "</div>"; | |
57 | ||
58 | print "</td><td>"; | |
59 | ||
60 | print "<div dojoType=\"dijit.ColorPalette\"> | |
61 | <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\"> | |
018caf6f | 62 | document.forms['label_edit_form'].bg_color.value = bg_color; |
fb8b2153 AD |
63 | </script> |
64 | </div>"; | |
65 | print "</div>"; | |
66 | ||
67 | print "</td></tr></table>"; | |
68 | print "</div>"; | |
69 | ||
018caf6f AD |
70 | print "</form>"; |
71 | ||
72 | print "<div class=\"dlgButtons\">"; | |
73 | print "<button onclick=\"return editLabelSave()\">". | |
74 | __('Save')."</button>"; | |
fb8b2153 | 75 | print "<button onclick=\"return closeInfoBox()\">". |
018caf6f | 76 | __('Cancel')."</button>"; |
fb8b2153 AD |
77 | print "</div>"; |
78 | ||
79 | print "]]></content></dlg>"; | |
80 | return; | |
81 | } | |
82 | ||
83 | if ($subop == "getlabeltree") { | |
84 | $root = array(); | |
85 | $root['id'] = 'root'; | |
86 | $root['name'] = __('Labels'); | |
87 | $root['items'] = array(); | |
88 | ||
89 | $result = db_query($link, "SELECT * | |
90 | FROM ttrss_labels2 | |
91 | WHERE owner_uid = ".$_SESSION["uid"]." | |
92 | ORDER BY caption"); | |
93 | ||
94 | while ($line = db_fetch_assoc($result)) { | |
95 | $label = array(); | |
96 | $label['id'] = 'LABEL:' . $line['id']; | |
97 | $label['bare_id'] = $line['id']; | |
98 | $label['name'] = $line['caption']; | |
99 | $label['fg_color'] = $line['fg_color']; | |
100 | $label['bg_color'] = $line['bg_color']; | |
101 | $label['type'] = 'label'; | |
102 | $label['checkbox'] = false; | |
103 | ||
104 | array_push($root['items'], $label); | |
105 | } | |
106 | ||
107 | $fl = array(); | |
108 | $fl['identifier'] = 'id'; | |
109 | $fl['label'] = 'name'; | |
110 | $fl['items'] = array($root); | |
111 | ||
112 | print json_encode($fl); | |
113 | return; | |
114 | } | |
115 | ||
b8776a07 AD |
116 | if ($subop == "color-set") { |
117 | $kind = db_escape_string($_REQUEST["kind"]); | |
118 | $ids = split(',', db_escape_string($_REQUEST["ids"])); | |
119 | $color = db_escape_string($_REQUEST["color"]); | |
b6ba48c1 AD |
120 | $fg = db_escape_string($_REQUEST["fg"]); |
121 | $bg = db_escape_string($_REQUEST["bg"]); | |
b8776a07 AD |
122 | |
123 | foreach ($ids as $id) { | |
b6ba48c1 AD |
124 | |
125 | if ($kind == "fg" || $kind == "bg") { | |
126 | db_query($link, "UPDATE ttrss_labels2 SET | |
127 | ${kind}_color = '$color' WHERE id = '$id' | |
128 | AND owner_uid = " . $_SESSION["uid"]); | |
129 | } else { | |
130 | db_query($link, "UPDATE ttrss_labels2 SET | |
131 | fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' | |
132 | AND owner_uid = " . $_SESSION["uid"]); | |
133 | } | |
905ff52a AD |
134 | |
135 | $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); | |
136 | ||
137 | /* Remove cached data */ | |
138 | ||
139 | db_query($link, "UPDATE ttrss_user_entries SET label_cache = '' | |
140 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
141 | ||
b8776a07 AD |
142 | } |
143 | ||
aec9df48 AD |
144 | return; |
145 | } | |
146 | ||
147 | if ($subop == "color-reset") { | |
148 | $ids = split(',', db_escape_string($_REQUEST["ids"])); | |
149 | ||
150 | foreach ($ids as $id) { | |
151 | db_query($link, "UPDATE ttrss_labels2 SET | |
152 | fg_color = '', bg_color = '' WHERE id = '$id' | |
153 | AND owner_uid = " . $_SESSION["uid"]); | |
905ff52a AD |
154 | |
155 | $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); | |
156 | ||
157 | /* Remove cached data */ | |
158 | ||
159 | db_query($link, "UPDATE ttrss_user_entries SET label_cache = '' | |
160 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
aec9df48 AD |
161 | } |
162 | ||
b8776a07 AD |
163 | } |
164 | ||
ceb30ba4 | 165 | if ($subop == "save") { |
071ec48f | 166 | |
ceb30ba4 | 167 | $id = db_escape_string($_REQUEST["id"]); |
018caf6f | 168 | $caption = db_escape_string(trim($_REQUEST["caption"])); |
071ec48f | 169 | |
ceb30ba4 | 170 | db_query($link, "BEGIN"); |
10fa6615 | 171 | |
ceb30ba4 AD |
172 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 |
173 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 174 | |
ceb30ba4 AD |
175 | if (db_num_rows($result) != 0) { |
176 | $old_caption = db_fetch_result($result, 0, "caption"); | |
a4919a16 | 177 | |
ceb30ba4 AD |
178 | $result = db_query($link, "SELECT id FROM ttrss_labels2 |
179 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 180 | |
ceb30ba4 AD |
181 | if (db_num_rows($result) == 0) { |
182 | if ($caption) { | |
183 | $result = db_query($link, "UPDATE ttrss_labels2 SET | |
184 | caption = '$caption' WHERE id = '$id' AND | |
185 | owner_uid = " . $_SESSION["uid"]); | |
ef8be8ea | 186 | |
ceb30ba4 | 187 | /* Update filters that reference label being renamed */ |
ef8be8ea | 188 | |
7a13338b AD |
189 | $old_caption = db_escape_string($old_caption); |
190 | ||
ceb30ba4 AD |
191 | db_query($link, "UPDATE ttrss_filters SET |
192 | action_param = '$caption' WHERE action_param = '$old_caption' | |
193 | AND action_id = 7 | |
194 | AND owner_uid = " . $_SESSION["uid"]); | |
ef8be8ea | 195 | |
9c5e85fe | 196 | print $_REQUEST["value"]; |
625acd1c AD |
197 | } else { |
198 | print $old_caption; | |
ceb30ba4 AD |
199 | } |
200 | } else { | |
201 | print $old_caption; | |
ef8be8ea | 202 | } |
ef8be8ea AD |
203 | } |
204 | ||
ceb30ba4 | 205 | db_query($link, "COMMIT"); |
ef8be8ea AD |
206 | |
207 | return; | |
208 | } | |
209 | ||
ef8be8ea AD |
210 | if ($subop == "remove") { |
211 | ||
b4e75b2a | 212 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
ef8be8ea | 213 | |
f6f7817d | 214 | foreach ($ids as $id) { |
1380f8ee | 215 | label_remove($link, $id, $_SESSION["uid"]); |
ef8be8ea | 216 | } |
f6f7817d | 217 | |
ef8be8ea AD |
218 | } |
219 | ||
220 | if ($subop == "add") { | |
b4e75b2a | 221 | $caption = db_escape_string($_REQUEST["caption"]); |
1c31e190 | 222 | $output = db_escape_string($_REQUEST["output"]); |
ef8be8ea | 223 | |
ceb30ba4 | 224 | if ($caption) { |
caf1f12f | 225 | |
6b2ee18d | 226 | if (label_create($link, $caption)) { |
1c31e190 | 227 | if (!$output) { |
d69fa6d6 | 228 | print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); |
1c31e190 | 229 | } |
ceb30ba4 | 230 | } |
6b2ee18d | 231 | |
1c31e190 AD |
232 | if ($output == "select") { |
233 | header("Content-Type: text/xml"); | |
234 | ||
10249c41 | 235 | print "<rpc-reply><payload>"; |
1c31e190 AD |
236 | |
237 | print_label_select($link, "select_label", | |
238 | $caption, ""); | |
239 | ||
10249c41 | 240 | print "</payload></rpc-reply>"; |
1c31e190 | 241 | } |
5e6f933a AD |
242 | } |
243 | ||
244 | return; | |
ef8be8ea AD |
245 | } |
246 | ||
b4e75b2a | 247 | $sort = db_escape_string($_REQUEST["sort"]); |
ef8be8ea AD |
248 | |
249 | if (!$sort || $sort == "undefined") { | |
ceb30ba4 | 250 | $sort = "caption"; |
ef8be8ea AD |
251 | } |
252 | ||
b4e75b2a | 253 | $label_search = db_escape_string($_REQUEST["search"]); |
112d2aec | 254 | |
b4e75b2a | 255 | if (array_key_exists("search", $_REQUEST)) { |
112d2aec AD |
256 | $_SESSION["prefs_label_search"] = $label_search; |
257 | } else { | |
258 | $label_search = $_SESSION["prefs_label_search"]; | |
259 | } | |
260 | ||
8df7184c AD |
261 | print "<div id=\"pref-label-wrap\" dojoType=\"dijit.layout.BorderContainer\" gutters=\"false\">"; |
262 | print "<div id=\"pref-label-header\" dojoType=\"dijit.layout.ContentPane\" region=\"top\">"; | |
263 | print "<div id=\"pref-label-toolbar\" dojoType=\"dijit.Toolbar\">"; | |
264 | ||
d69fa6d6 AD |
265 | print "<div dojoType=\"dijit.form.DropDownButton\">". |
266 | "<span>" . __('Select')."</span>"; | |
267 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
fb8b2153 | 268 | print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" |
d69fa6d6 | 269 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; |
fb8b2153 | 270 | print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" |
d69fa6d6 AD |
271 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; |
272 | print "</div></div>"; | |
273 | ||
1985a5e0 AD |
274 | print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">". |
275 | __('Create label')."</button dojoType=\"dijit.form.Button\"> "; | |
1e5548db | 276 | |
1985a5e0 AD |
277 | print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">". |
278 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
1e5548db | 279 | |
1985a5e0 AD |
280 | print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">". |
281 | __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; | |
1e5548db AD |
282 | |
283 | ||
8df7184c AD |
284 | print "</div>"; #toolbar |
285 | print "</div>"; #pane | |
286 | print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
ef8be8ea | 287 | |
fb8b2153 AD |
288 | print "<div id=\"labellistLoading\"> |
289 | <img src='images/indicator_tiny.gif'>". | |
290 | __("Loading, please wait...")."</div>"; | |
291 | ||
292 | print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\" | |
293 | url=\"backend.php?op=pref-labels&subop=getlabeltree\"> | |
294 | </div> | |
295 | <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\" | |
296 | query=\"{id:'root'}\" rootId=\"root\" | |
297 | childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> | |
298 | </div> | |
299 | <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\" | |
300 | model=\"labelModel\" openOnClick=\"true\"> | |
301 | <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> | |
302 | Element.hide(\"labellistLoading\"); | |
303 | </script> | |
304 | </div>"; | |
8df7184c AD |
305 | |
306 | print "</div>"; #pane | |
307 | print "</div>"; #container | |
ef8be8ea | 308 | } |
1d4a2918 | 309 | |
ef8be8ea | 310 | ?> |