]>
Commit | Line | Data |
---|---|---|
cbe50c80 | 1 | <?php |
46da73c2 | 2 | class Pref_Labels extends Protected_Handler { |
cbe50c80 AD |
3 | |
4 | function edit() { | |
5 | $label_id = db_escape_string($_REQUEST['id']); | |
6 | ||
7 | $result = db_query($this->link, "SELECT * FROM ttrss_labels2 WHERE | |
8 | id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); | |
9 | ||
10 | $line = db_fetch_assoc($result); | |
11 | ||
12 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$label_id\">"; | |
13 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-labels\">"; | |
14 | print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">"; | |
15 | ||
16 | print "<div class=\"dlgSec\">".__("Caption")."</div>"; | |
17 | ||
18 | print "<div class=\"dlgSecCont\">"; | |
19 | ||
20 | $fg_color = $line['fg_color']; | |
21 | $bg_color = $line['bg_color']; | |
22 | ||
23 | print "<span class=\"labelColorIndicator\" id=\"label-editor-indicator\" style='color : $fg_color; background-color : $bg_color; margin-bottom : 4px; margin-right : 4px'>α</span>"; | |
24 | ||
25 | print "<input style=\"font-size : 16px\" name=\"caption\" | |
26 | dojoType=\"dijit.form.ValidationTextBox\" | |
27 | required=\"true\" | |
28 | value=\"".htmlspecialchars($line['caption'])."\">"; | |
29 | ||
30 | print "</div>"; | |
31 | print "<div class=\"dlgSec\">" . __("Colors") . "</div>"; | |
32 | print "<div class=\"dlgSecCont\">"; | |
33 | ||
34 | print "<table cellspacing=\"0\">"; | |
35 | ||
36 | print "<tr><td>".__("Foreground:")."</td><td>".__("Background:"). | |
37 | "</td></tr>"; | |
38 | ||
39 | print "<tr><td style='padding-right : 10px'>"; | |
40 | ||
41 | print "<input dojoType=\"dijit.form.TextBox\" | |
42 | style=\"display : none\" id=\"labelEdit_fgColor\" | |
43 | name=\"fg_color\" value=\"$fg_color\">"; | |
44 | print "<input dojoType=\"dijit.form.TextBox\" | |
45 | style=\"display : none\" id=\"labelEdit_bgColor\" | |
46 | name=\"bg_color\" value=\"$bg_color\">"; | |
47 | ||
48 | print "<div dojoType=\"dijit.ColorPalette\"> | |
49 | <script type=\"dojo/method\" event=\"onChange\" args=\"fg_color\"> | |
50 | dijit.byId(\"labelEdit_fgColor\").attr('value', fg_color); | |
51 | $('label-editor-indicator').setStyle({color: fg_color}); | |
52 | </script> | |
53 | </div>"; | |
54 | print "</div>"; | |
55 | ||
56 | print "</td><td>"; | |
57 | ||
58 | print "<div dojoType=\"dijit.ColorPalette\"> | |
59 | <script type=\"dojo/method\" event=\"onChange\" args=\"bg_color\"> | |
60 | dijit.byId(\"labelEdit_bgColor\").attr('value', bg_color); | |
61 | $('label-editor-indicator').setStyle({backgroundColor: bg_color}); | |
62 | </script> | |
63 | </div>"; | |
64 | print "</div>"; | |
65 | ||
66 | print "</td></tr></table>"; | |
67 | print "</div>"; | |
68 | ||
69 | # print "</form>"; | |
70 | ||
71 | print "<div class=\"dlgButtons\">"; | |
72 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').execute()\">". | |
73 | __('Save')."</button>"; | |
74 | print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelEditDlg').hide()\">". | |
75 | __('Cancel')."</button>"; | |
76 | print "</div>"; | |
77 | ||
78 | return; | |
79 | } | |
80 | ||
81 | function getlabeltree() { | |
82 | $root = array(); | |
83 | $root['id'] = 'root'; | |
84 | $root['name'] = __('Labels'); | |
85 | $root['items'] = array(); | |
86 | ||
87 | $result = db_query($this->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 | ||
114 | function colorset() { | |
115 | $kind = db_escape_string($_REQUEST["kind"]); | |
116 | $ids = split(',', db_escape_string($_REQUEST["ids"])); | |
117 | $color = db_escape_string($_REQUEST["color"]); | |
118 | $fg = db_escape_string($_REQUEST["fg"]); | |
119 | $bg = db_escape_string($_REQUEST["bg"]); | |
120 | ||
121 | foreach ($ids as $id) { | |
122 | ||
123 | if ($kind == "fg" || $kind == "bg") { | |
124 | db_query($this->link, "UPDATE ttrss_labels2 SET | |
125 | ${kind}_color = '$color' WHERE id = '$id' | |
126 | AND owner_uid = " . $_SESSION["uid"]); | |
127 | } else { | |
128 | db_query($this->link, "UPDATE ttrss_labels2 SET | |
129 | fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' | |
130 | AND owner_uid = " . $_SESSION["uid"]); | |
131 | } | |
132 | ||
133 | $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); | |
134 | ||
135 | /* Remove cached data */ | |
136 | ||
137 | db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' | |
138 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
139 | ||
140 | } | |
141 | ||
142 | return; | |
143 | } | |
144 | ||
145 | function colorreset() { | |
146 | $ids = split(',', db_escape_string($_REQUEST["ids"])); | |
147 | ||
148 | foreach ($ids as $id) { | |
149 | db_query($this->link, "UPDATE ttrss_labels2 SET | |
150 | fg_color = '', bg_color = '' WHERE id = '$id' | |
151 | AND owner_uid = " . $_SESSION["uid"]); | |
152 | ||
153 | $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); | |
154 | ||
155 | /* Remove cached data */ | |
156 | ||
157 | db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' | |
158 | WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); | |
159 | } | |
160 | ||
161 | } | |
162 | ||
163 | function save() { | |
164 | ||
165 | $id = db_escape_string($_REQUEST["id"]); | |
166 | $caption = db_escape_string(trim($_REQUEST["caption"])); | |
167 | ||
168 | db_query($this->link, "BEGIN"); | |
169 | ||
170 | $result = db_query($this->link, "SELECT caption FROM ttrss_labels2 | |
171 | WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); | |
172 | ||
173 | if (db_num_rows($result) != 0) { | |
174 | $old_caption = db_fetch_result($result, 0, "caption"); | |
175 | ||
176 | $result = db_query($this->link, "SELECT id FROM ttrss_labels2 | |
177 | WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); | |
178 | ||
179 | if (db_num_rows($result) == 0) { | |
180 | if ($caption) { | |
181 | $result = db_query($this->link, "UPDATE ttrss_labels2 SET | |
182 | caption = '$caption' WHERE id = '$id' AND | |
183 | owner_uid = " . $_SESSION["uid"]); | |
184 | ||
185 | /* Update filters that reference label being renamed */ | |
186 | ||
187 | $old_caption = db_escape_string($old_caption); | |
188 | ||
189 | db_query($this->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"]); | |
193 | ||
194 | print $_REQUEST["value"]; | |
195 | } else { | |
196 | print $old_caption; | |
197 | } | |
198 | } else { | |
199 | print $old_caption; | |
200 | } | |
201 | } | |
202 | ||
203 | db_query($this->link, "COMMIT"); | |
204 | ||
205 | return; | |
206 | } | |
207 | ||
208 | function remove() { | |
209 | ||
210 | $ids = split(",", db_escape_string($_REQUEST["ids"])); | |
211 | ||
212 | foreach ($ids as $id) { | |
213 | label_remove($this->link, $id, $_SESSION["uid"]); | |
214 | } | |
215 | ||
216 | } | |
217 | ||
218 | function add() { | |
219 | $caption = db_escape_string($_REQUEST["caption"]); | |
220 | $output = db_escape_string($_REQUEST["output"]); | |
221 | ||
222 | if ($caption) { | |
223 | ||
224 | if (label_create($this->link, $caption)) { | |
225 | if (!$output) { | |
226 | print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption)); | |
227 | } | |
228 | } | |
229 | ||
230 | if ($output == "select") { | |
231 | header("Content-Type: text/xml"); | |
232 | ||
233 | print "<rpc-reply><payload>"; | |
234 | ||
235 | print_label_select($this->link, "select_label", | |
236 | $caption, ""); | |
237 | ||
238 | print "</payload></rpc-reply>"; | |
239 | } | |
240 | } | |
241 | ||
242 | return; | |
243 | } | |
244 | ||
245 | function index() { | |
246 | ||
247 | $sort = db_escape_string($_REQUEST["sort"]); | |
248 | ||
249 | if (!$sort || $sort == "undefined") { | |
250 | $sort = "caption"; | |
251 | } | |
252 | ||
253 | $label_search = db_escape_string($_REQUEST["search"]); | |
254 | ||
255 | if (array_key_exists("search", $_REQUEST)) { | |
256 | $_SESSION["prefs_label_search"] = $label_search; | |
257 | } else { | |
258 | $label_search = $_SESSION["prefs_label_search"]; | |
259 | } | |
260 | ||
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 | ||
265 | print "<div dojoType=\"dijit.form.DropDownButton\">". | |
266 | "<span>" . __('Select')."</span>"; | |
267 | print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; | |
268 | print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\" | |
269 | dojoType=\"dijit.MenuItem\">".__('All')."</div>"; | |
270 | print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\" | |
271 | dojoType=\"dijit.MenuItem\">".__('None')."</div>"; | |
272 | print "</div></div>"; | |
273 | ||
274 | print"<button dojoType=\"dijit.form.Button\" onclick=\"return addLabel()\">". | |
275 | __('Create label')."</button dojoType=\"dijit.form.Button\"> "; | |
276 | ||
277 | print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedLabels()\">". | |
278 | __('Remove')."</button dojoType=\"dijit.form.Button\"> "; | |
279 | ||
280 | print "<button dojoType=\"dijit.form.Button\" onclick=\"labelColorReset()\">". | |
281 | __('Clear colors')."</button dojoType=\"dijit.form.Button\">"; | |
282 | ||
283 | ||
284 | print "</div>"; #toolbar | |
285 | print "</div>"; #pane | |
286 | print "<div id=\"pref-label-content\" dojoType=\"dijit.layout.ContentPane\" region=\"center\">"; | |
287 | ||
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&method=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 | <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> | |
305 | var id = String(item.id); | |
306 | var bare_id = id.substr(id.indexOf(':')+1); | |
307 | ||
308 | if (id.match('LABEL:')) { | |
309 | editLabel(bare_id); | |
310 | } | |
311 | </script> | |
312 | </div>"; | |
313 | ||
314 | print "</div>"; #pane | |
315 | print "</div>"; #container | |
316 | ||
317 | } | |
318 | } | |
319 | ||
320 | ?> |