]> git.wh0rd.org - tt-rss.git/blob - modules/pref-labels.php
162592625df78b3deff732765c330644099f51fb
[tt-rss.git] / modules / pref-labels.php
1 <?php
2 function module_pref_labels($link) {
3
4 $subop = $_GET["subop"];
5
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"]);
10
11 foreach ($ids as $id) {
12 db_query($link, "UPDATE ttrss_labels2 SET
13 ${kind}_color = '$color' WHERE id = '$id'
14 AND owner_uid = " . $_SESSION["uid"]);
15 }
16
17 }
18
19 if ($subop == "save") {
20
21 $id = db_escape_string($_REQUEST["id"]);
22 $caption = db_escape_string(trim($_REQUEST["value"]));
23
24 db_query($link, "BEGIN");
25
26 $result = db_query($link, "SELECT caption FROM ttrss_labels2
27 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
28
29 if (db_num_rows($result) != 0) {
30 $old_caption = db_fetch_result($result, 0, "caption");
31
32 $result = db_query($link, "SELECT id FROM ttrss_labels2
33 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
34
35 if (db_num_rows($result) == 0) {
36 if ($caption) {
37 $result = db_query($link, "UPDATE ttrss_labels2 SET
38 caption = '$caption' WHERE id = '$id' AND
39 owner_uid = " . $_SESSION["uid"]);
40
41 /* Update filters that reference label being renamed */
42
43 db_query($link, "UPDATE ttrss_filters SET
44 action_param = '$caption' WHERE action_param = '$old_caption'
45 AND action_id = 7
46 AND owner_uid = " . $_SESSION["uid"]);
47
48 print $_REQUEST["value"];
49 } else {
50 print $old_caption;
51 }
52 } else {
53 print $old_caption;
54 }
55 }
56
57 db_query($link, "COMMIT");
58
59 return;
60 }
61
62 if ($subop == "remove") {
63
64 $ids = split(",", db_escape_string($_GET["ids"]));
65
66 foreach ($ids as $id) {
67 label_remove($link, $id, $_SESSION["uid"]);
68 }
69
70 }
71
72 if ($subop == "add") {
73
74 $caption = db_escape_string($_GET["caption"]);
75
76 if ($caption) {
77
78 if (label_create($link, $caption)) {
79 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
80 }
81
82 }
83
84 return;
85 }
86
87 set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
88
89 $sort = db_escape_string($_GET["sort"]);
90
91 if (!$sort || $sort == "undefined") {
92 $sort = "caption";
93 }
94
95 $label_search = db_escape_string($_GET["search"]);
96
97 if (array_key_exists("search", $_GET)) {
98 $_SESSION["prefs_label_search"] = $label_search;
99 } else {
100 $label_search = $_SESSION["prefs_label_search"];
101 }
102
103 print "<div id=\"colorPicker\" style=\"display : none\">";
104
105 $color_picker_pairs = array(
106 array('#063064', '#fff7d5'),
107 array('#ffffff', '#00ccff'),
108 array('#ffffff', '#cc00ff'),
109 array('#ffffff', '#00ffcc'),
110 array('#ffffff', '#0000ff'),
111 array('#ffffff', '#ff00ff'),
112 array('#ffffff', '#ff0000'),
113 array('#394f00', '#ccff00'));
114
115 foreach ($color_picker_pairs as $c) {
116 $fg_color = $c[0];
117 $bg_color = $c[1];
118
119 print "<div class='colorPickerEntry'
120 style='color : $fg_color; background-color : $bg_color;'
121 onclick=\"colorPickerDo('$fg_color', '$bg_color')\">z</div>";
122
123 }
124
125 print "<br clear='both'>";
126
127 print "</div>";
128
129 print "<div class=\"feedEditSearch\">
130 <input id=\"label_search\" size=\"20\" type=\"search\"
131 onfocus=\"javascript:disableHotkeys();\"
132 onblur=\"javascript:enableHotkeys();\"
133 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
134 <input type=\"submit\" class=\"button\"
135 onclick=\"javascript:updateLabelList()\" value=\"".__('Search')."\">
136 </div>";
137
138 print "<div class=\"prefGenericAddBox\">";
139
140 print"<input type=\"submit\" class=\"button\"
141 id=\"label_create_btn\"
142 onclick=\"return addLabel()\"
143 value=\"".__('Create label')."\"></div>";
144
145 if ($label_search) {
146 $label_search_query = "caption LIKE '%$label_search%' AND";
147 } else {
148 $label_search_query = "";
149 }
150
151 $result = db_query($link, "SELECT
152 *
153 FROM
154 ttrss_labels2
155 WHERE
156 $label_search_query
157 owner_uid = ".$_SESSION["uid"]."
158 ORDER BY $sort");
159
160 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
161
162 if (db_num_rows($result) != 0) {
163
164 print "<p><table width=\"100%\" cellspacing=\"0\"
165 class=\"prefLabelList\" id=\"prefLabelList\">";
166
167 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
168 ".__('Select:')."
169 <a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>,
170 <a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a>
171 </td</tr>";
172
173 /* print "<tr class=\"title\">
174 <td width=\"5%\">&nbsp;</td>
175 <td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
176 </td>
177 </tr>"; */
178
179 $lnum = 0;
180
181 while ($line = db_fetch_assoc($result)) {
182
183 $class = ($lnum % 2) ? "even" : "odd";
184
185 $label_id = $line["id"];
186 $this_row_id = "id=\"LILRR-$label_id\"";
187
188 print "<tr class=\"$class\" $this_row_id>";
189
190 $line["caption"] = htmlspecialchars($line["caption"]);
191
192 $fg_color = $line["fg_color"];
193 $bg_color = $line["bg_color"];
194
195 if (!$fg_color) $fg_color = "black";
196 if (!$bg_color) $bg_color = "transparent";
197
198 print "<td width='5%' align='center'><input
199 onclick='toggleSelectPrefRow(this, \"label\");'
200 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
201
202 $id = $line['id'];
203
204 /* print "<td width='30' align='center'>
205 <div class='labelColorIndicator'
206 style='color : $fg_color; background-color : $bg_color'
207 onclick=\"colorPicker(this, '$id', '$fg_color', '$bg_color')\">z</div>";
208
209 print "</td>"; */
210
211 print "<td><span class='prefsLabelEntry'
212 style='color : $fg_color; background-color : $bg_color'
213 id=\"LILT-".$line["id"]."\">" . $line["caption"] .
214 "</span>";
215
216 print "</td>";
217
218 print "</tr>";
219
220 ++$lnum;
221 }
222
223 print "</table>";
224
225 print "<p id=\"labelOpToolbar\">";
226
227 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
228 onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
229
230 print "&nbsp;&nbsp;";
231 print __("Color:");
232 print "&nbsp;<input type=\"submit\" class=\"button\" disabled=\"true\"
233 onclick=\"labelColorSet('fg')\" value=\"".__('Fg')."\">&nbsp;";
234 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
235 onclick=\"labelColorSet('bg')\" value=\"".__('Bg')."\">&nbsp;";
236 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
237 onclick=\"labelColorReset()\" value=\"".__('Clear')."\">";
238
239 print "</p>";
240
241 } else {
242 print "<p>";
243 if (!$label_search) {
244 print __('No labels defined.');
245 } else {
246 print __('No matching labels found.');
247 }
248 print "</p>";
249
250 }
251 }
252 ?>