]> git.wh0rd.org - tt-rss.git/blame - modules/pref-labels.php
tmp color-ops toolbar (2)
[tt-rss.git] / modules / pref-labels.php
CommitLineData
ef8be8ea 1<?php
ef8be8ea 2 function module_pref_labels($link) {
ef8be8ea
AD
3
4 $subop = $_GET["subop"];
5
b8776a07
AD
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
ceb30ba4 19 if ($subop == "save") {
071ec48f 20
ceb30ba4 21 $id = db_escape_string($_REQUEST["id"]);
9c5e85fe 22 $caption = db_escape_string(trim($_REQUEST["value"]));
071ec48f 23
ceb30ba4 24 db_query($link, "BEGIN");
10fa6615 25
ceb30ba4
AD
26 $result = db_query($link, "SELECT caption FROM ttrss_labels2
27 WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
ef8be8ea 28
ceb30ba4
AD
29 if (db_num_rows($result) != 0) {
30 $old_caption = db_fetch_result($result, 0, "caption");
a4919a16 31
ceb30ba4
AD
32 $result = db_query($link, "SELECT id FROM ttrss_labels2
33 WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
ef8be8ea 34
ceb30ba4
AD
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"]);
ef8be8ea 40
ceb30ba4 41 /* Update filters that reference label being renamed */
ef8be8ea 42
ceb30ba4
AD
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"]);
ef8be8ea 47
9c5e85fe 48 print $_REQUEST["value"];
625acd1c
AD
49 } else {
50 print $old_caption;
ceb30ba4
AD
51 }
52 } else {
53 print $old_caption;
ef8be8ea 54 }
ef8be8ea
AD
55 }
56
ceb30ba4 57 db_query($link, "COMMIT");
ef8be8ea
AD
58
59 return;
60 }
61
ef8be8ea
AD
62 if ($subop == "remove") {
63
ceb30ba4 64 $ids = split(",", db_escape_string($_GET["ids"]));
ef8be8ea 65
f6f7817d 66 foreach ($ids as $id) {
1380f8ee 67 label_remove($link, $id, $_SESSION["uid"]);
ef8be8ea 68 }
f6f7817d 69
ef8be8ea
AD
70 }
71
72 if ($subop == "add") {
ef8be8ea 73
ceb30ba4 74 $caption = db_escape_string($_GET["caption"]);
ef8be8ea 75
ceb30ba4 76 if ($caption) {
caf1f12f 77
6b2ee18d
AD
78 if (label_create($link, $caption)) {
79 print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
ceb30ba4 80 }
6b2ee18d 81
5e6f933a
AD
82 }
83
84 return;
ef8be8ea
AD
85 }
86
fe8d2059
AD
87 set_pref($link, "_PREFS_ACTIVE_TAB", "labelConfig");
88
ef8be8ea
AD
89 $sort = db_escape_string($_GET["sort"]);
90
91 if (!$sort || $sort == "undefined") {
ceb30ba4 92 $sort = "caption";
ef8be8ea
AD
93 }
94
112d2aec
AD
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
c17d514b
AD
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
112d2aec
AD
129 print "<div class=\"feedEditSearch\">
130 <input id=\"label_search\" size=\"20\" type=\"search\"
4cf6fc6a
AD
131 onfocus=\"javascript:disableHotkeys();\"
132 onblur=\"javascript:enableHotkeys();\"
112d2aec
AD
133 onchange=\"javascript:updateLabelList()\" value=\"$label_search\">
134 <input type=\"submit\" class=\"button\"
135 onclick=\"javascript:updateLabelList()\" value=\"".__('Search')."\">
112d2aec 136 </div>";
0d32b41e 137
ef8be8ea
AD
138 print "<div class=\"prefGenericAddBox\">";
139
140 print"<input type=\"submit\" class=\"button\"
141 id=\"label_create_btn\"
ceb30ba4 142 onclick=\"return addLabel()\"
a3c159c4 143 value=\"".__('Create label')."\"></div>";
ef8be8ea 144
112d2aec 145 if ($label_search) {
ceb30ba4 146 $label_search_query = "caption LIKE '%$label_search%' AND";
112d2aec
AD
147 } else {
148 $label_search_query = "";
149 }
150
ef8be8ea 151 $result = db_query($link, "SELECT
2eb9c95c 152 *
ef8be8ea 153 FROM
ceb30ba4 154 ttrss_labels2
ef8be8ea 155 WHERE
112d2aec 156 $label_search_query
ef8be8ea
AD
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
ef8be8ea
AD
164 print "<p><table width=\"100%\" cellspacing=\"0\"
165 class=\"prefLabelList\" id=\"prefLabelList\">";
166
167 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
e8d0177d
AD
168 ".__('Select:')."
169 <a href=\"javascript:selectPrefRows('label', true)\">".__('All')."</a>,
170 <a href=\"javascript:selectPrefRows('label', false)\">".__('None')."</a>
ef8be8ea
AD
171 </td</tr>";
172
4d23f96e 173/* print "<tr class=\"title\">
ef8be8ea 174 <td width=\"5%\">&nbsp;</td>
4d23f96e 175 <td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
ef8be8ea 176 </td>
4d23f96e 177 </tr>"; */
ef8be8ea
AD
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"];
ceb30ba4
AD
186 $this_row_id = "id=\"LILRR-$label_id\"";
187
ef8be8ea
AD
188 print "<tr class=\"$class\" $this_row_id>";
189
ceb30ba4 190 $line["caption"] = htmlspecialchars($line["caption"]);
2eb9c95c
AD
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
4d23f96e 198 print "<td width='5%' align='center'><input
ceb30ba4 199 onclick='toggleSelectPrefRow(this, \"label\");'
ef8be8ea
AD
200 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
201
76b2bc65 202 $id = $line['id'];
c17d514b 203
76b2bc65 204/* print "<td width='30' align='center'>
c17d514b 205 <div class='labelColorIndicator'
2eb9c95c 206 style='color : $fg_color; background-color : $bg_color'
c17d514b
AD
207 onclick=\"colorPicker(this, '$id', '$fg_color', '$bg_color')\">z</div>";
208
209 print "</td>"; */
210
211 print "<td><span class='prefsLabelEntry'
76b2bc65 212 style='color : $fg_color; background-color : $bg_color'
2eb9c95c 213 id=\"LILT-".$line["id"]."\">" . $line["caption"] .
c17d514b
AD
214 "</span>";
215
76b2bc65 216 print "</td>";
ef8be8ea
AD
217
218 print "</tr>";
219
220 ++$lnum;
221 }
a5bd7bf0 222
ef8be8ea 223 print "</table>";
ef8be8ea
AD
224
225 print "<p id=\"labelOpToolbar\">";
d86ad7bf 226
b8776a07
AD
227 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
228 onclick=\"javascript:removeSelectedLabels()\" value=\"".__('Remove')."\">";
229
230 print "&nbsp;&nbsp;";
d86ad7bf 231 print __("Color:");
b8776a07
AD
232 print "&nbsp;<input type=\"submit\" class=\"button\" disabled=\"true\"
233 onclick=\"labelColorSet('fg')\" value=\"".__('Fg')."\">&nbsp;";
d86ad7bf 234 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
b8776a07 235 onclick=\"labelColorSet('bg')\" value=\"".__('Bg')."\">&nbsp;";
d86ad7bf 236 print "<input type=\"submit\" class=\"button\" disabled=\"true\"
b8776a07 237 onclick=\"labelColorReset()\" value=\"".__('Clear')."\">";
d86ad7bf 238
ceb30ba4 239 print "</p>";
ef8be8ea
AD
240
241 } else {
a5bd7bf0
AD
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
ef8be8ea
AD
250 }
251 }
252?>