]>
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 | ||
19 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; | |
20 | ||
21 | print "<div class=\"dlgSecCont\">"; | |
22 | ||
23 | print "<span dojoType=\"dijit.InlineEditBox\" style=\"font-size : 18px;\" | |
24 | width=\"150px\" autoSave=\"false\" | |
25 | label-id=\"$label_id\">" . $line["caption"] . | |
26 | "<script type=\"dojo/method\" event=\"onChange\" args=\"item\"> | |
27 | var elem = this; | |
28 | dojo.xhrPost({ | |
29 | url: 'backend.php', | |
30 | content: {op: 'pref-labels', subop: 'save', | |
31 | value: this.value, | |
32 | id: this.srcNodeRef.getAttribute('label-id')}, | |
33 | load: function(response) { | |
34 | elem.attr('value', response); | |
35 | dijit.byId('labelTree').setNameById($label_id, response); | |
36 | updateFilterList(); | |
37 | } | |
38 | }); | |
39 | </script> | |
40 | </span>"; | |
41 | ||
42 | print "</div>"; | |
43 | print "<div class=\"dlgSec\">" . __("Change colors") . "</div>"; | |
44 | print "<div class=\"dlgSecCont\">"; | |
45 | ||
46 | print "<table cellspacing=\"5\"><th>"; | |
47 | ||
48 | print "<tr><td>".__("Foreground color:")."</td><td>".__("Background color:"). | |
49 | "</td></tr>"; | |
50 | ||
51 | print "</th><tr><td>"; | |
52 | ||
53 | print "<div dojoType=\"dijit.ColorPalette\"> | |
54 | <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\"> | |
55 | setLabelColor('$label_id', fg_color, null); | |
56 | </script> | |
57 | </div>"; | |
58 | print "</div>"; | |
59 | ||
60 | print "</td><td>"; | |
61 | ||
62 | print "<div dojoType=\"dijit.ColorPalette\"> | |
63 | <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\"> | |
64 | setLabelColor('$label_id', null, bg_color); | |
65 | </script> | |
66 | </div>"; | |
67 | print "</div>"; | |
68 | ||
69 | print "</td></tr></table>"; | |
70 | print "</div>"; | |
71 | ||
72 | print "<div class=\"dlgButtons\" style=\"text-align : center\">"; | |
73 | print "<button onclick=\"return closeInfoBox()\">". | |
74 | __('Close this window')."</button>"; | |
75 | print "</div>"; | |
76 | ||
77 | print "]]></content></dlg>"; | |
78 | return; | |
79 | } | |
80 | ||
81 | if ($subop == "getlabeltree") { | |
82 | $root = array(); | |
83 | $root['id'] = 'root'; | |
84 | $root['name'] = __('Labels'); | |
85 | $root['items'] = array(); | |
86 | ||
87 | $result = db_query($link, "SELECT * | |
88 | FROM ttrss_labels2 | |
89 | WHERE owner_uid = ".$_SESSION["uid"]." | |
90 | ORDER BY caption"); | |
91 | ||
92 | while ($line = db_fetch_assoc($result)) { | |
93 | $label = array(); | |
94 | $label['id'] = 'LABEL:' . $line['id']; | |
95 | $label['bare_id'] = $line['id']; | |
96 | $label['name'] = $line['caption']; | |
97 | $label['fg_color'] = $line['fg_color']; | |
98 | $label['bg_color'] = $line['bg_color']; | |
99 | $label['type'] = 'label'; | |
100 | $label['checkbox'] = false; | |
101 | ||
102 | array_push($root['items'], $label); | |
103 | } | |
104 | ||
105 | $fl = array(); | |
106 | $fl['identifier'] = 'id'; | |
107 | $fl['label'] = 'name'; | |
108 | $fl['items'] = array($root); | |
109 | ||
110 | print json_encode($fl); | |
111 | return; | |
112 | } | |
113 | ||
b8776a07 AD |
114 | if ($subop == "color-set") { |
115 | $kind = db_escape_string($_REQUEST["kind"]); | |
116 | $ids = split(',', db_escape_string($_REQUEST["ids"])); | |
117 | $color = db_escape_string($_REQUEST["color"]); | |
b6ba48c1 AD |
118 | $fg = db_escape_string($_REQUEST["fg"]); |
119 | $bg = db_escape_string($_REQUEST["bg"]); | |
b8776a07 AD |
120 | |
121 | foreach ($ids as $id) { | |
b6ba48c1 AD |
122 | |
123 | if ($kind == "fg" || $kind == "bg") { | |
124 | db_query($link, "UPDATE ttrss_labels2 SET | |
125 | ${kind}_color = '$color' WHERE id = '$id' | |
126 | AND owner_uid = " . $_SESSION["uid"]); | |
127 | } else { | |
128 | db_query($link, "UPDATE ttrss_labels2 SET | |
129 | fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' | |
130 | AND owner_uid = " . $_SESSION["uid"]); | |
131 | } | |
905ff52a AD |
132 | |
133 | $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); | |
134 | ||
135 | /* Remove cached data */ | |
136 | ||
137 | db_query($link, "UPDATE ttrss_user_entries SET label_cache = '' | |
138 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
139 | ||
b8776a07 AD |
140 | } |
141 | ||
aec9df48 AD |
142 | return; |
143 | } | |
144 | ||
145 | if ($subop == "color-reset") { | |
146 | $ids = split(',', db_escape_string($_REQUEST["ids"])); | |
147 | ||
148 | foreach ($ids as $id) { | |
149 | db_query($link, "UPDATE ttrss_labels2 SET | |
150 | fg_color = '', bg_color = '' WHERE id = '$id' | |
151 | AND owner_uid = " . $_SESSION["uid"]); | |
905ff52a AD |
152 | |
153 | $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); | |
154 | ||
155 | /* Remove cached data */ | |
156 | ||
157 | db_query($link, "UPDATE ttrss_user_entries SET label_cache = '' | |
158 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
aec9df48 AD |
159 | } |
160 | ||
b8776a07 AD |
161 | } |
162 | ||
ceb30ba4 | 163 | if ($subop == "save") { |
071ec48f | 164 | |
ceb30ba4 | 165 | $id = db_escape_string($_REQUEST["id"]); |
9c5e85fe | 166 | $caption = db_escape_string(trim($_REQUEST["value"])); |
071ec48f | 167 | |
ceb30ba4 | 168 | db_query($link, "BEGIN"); |
10fa6615 | 169 | |
ceb30ba4 AD |
170 | $result = db_query($link, "SELECT caption FROM ttrss_labels2 |
171 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 172 | |
ceb30ba4 AD |
173 | if (db_num_rows($result) != 0) { |
174 | $old_caption = db_fetch_result($result, 0, "caption"); | |
a4919a16 | 175 | |
ceb30ba4 AD |
176 | $result = db_query($link, "SELECT id FROM ttrss_labels2 |
177 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
ef8be8ea | 178 | |
ceb30ba4 AD |
179 | if (db_num_rows($result) == 0) { |
180 | if ($caption) { | |
181 | $result = db_query($link, "UPDATE ttrss_labels2 SET | |
182 | caption = '$caption' WHERE id = '$id' AND | |
183 | owner_uid = " . $_SESSION["uid"]); | |
ef8be8ea | 184 | |
ceb30ba4 | 185 | /* Update filters that reference label being renamed */ |
ef8be8ea | 186 | |
7a13338b AD |
187 | $old_caption = db_escape_string($old_caption); |
188 | ||
ceb30ba4 AD |
189 | db_query($link, "UPDATE ttrss_filters SET |
190 | action_param = '$caption' WHERE action_param = '$old_caption' | |
191 | AND action_id = 7 | |
192 | AND owner_uid = " . $_SESSION["uid"]); | |
ef8be8ea | 193 | |
9c5e85fe | 194 | print $_REQUEST["value"]; |
625acd1c AD |
195 | } else { |
196 | print $old_caption; | |
ceb30ba4 AD |
197 | } |
198 | } else { | |
199 | print $old_caption; | |
ef8be8ea | 200 | } |
ef8be8ea AD |
201 | } |
202 | ||
ceb30ba4 | 203 | db_query($link, "COMMIT"); |
ef8be8ea AD |
204 | |
205 | return; | |
206 | } | |
207 | ||
ef8be8ea AD |
208 | if ($subop == "remove") { |
209 | ||
b4e75b2a | 210 | $ids = split(",", db_escape_string($_REQUEST["ids"])); |
ef8be8ea | 211 | |
f6f7817d | 212 | foreach ($ids as $id) { |
1380f8ee | 213 | label_remove($link, $id, $_SESSION["uid"]); |
ef8be8ea | 214 | } |
f6f7817d | 215 | |
ef8be8ea AD |
216 | } |
217 | ||
218 | if ($subop == "add") { | |
b4e75b2a | 219 | $caption = db_escape_string($_REQUEST["caption"]); |
1c31e190 | 220 | $output = db_escape_string($_REQUEST["output"]); |
ef8be8ea | 221 | |
ceb30ba4 | 222 | if ($caption) { |
caf1f12f | 223 | |
6b2ee18d | 224 | if (label_create($link, $caption)) { |
1c31e190 | 225 | if (!$output) { |
d69fa6d6 | 226 | print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); |
1c31e190 | 227 | } |
ceb30ba4 | 228 | } |
6b2ee18d | 229 | |
1c31e190 AD |
230 | if ($output == "select") { |
231 | header("Content-Type: text/xml"); | |
232 | ||
10249c41 | 233 | print "<rpc-reply><payload>"; |
1c31e190 AD |
234 | |
235 | print_label_select($link, "select_label", | |
236 | $caption, ""); | |
237 | ||
10249c41 | 238 | print "</payload></rpc-reply>"; |
1c31e190 | 239 | } |
5e6f933a AD |
240 | } |
241 | ||
242 | return; | |
ef8be8ea AD |
243 | } |
244 | ||
fe8d2059 AD |
245 | set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig"); |
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 | ?> |