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