]> git.wh0rd.org Git - tt-rss.git/blob - modules/popup-dialog.php
tweak filter add/edit dialogs
[tt-rss.git] / modules / popup-dialog.php
1 <?php
2         function module_popup_dialog($link) {
3                 $id = $_GET["id"];
4                 $param = db_escape_string($_GET["param"]);
5
6                 if ($id == "explainError") {
7
8                         print "<div id=\"infoBoxTitle\">Notice</div>";
9                         print "<div class=\"infoBoxContents\">";
10
11                         if ($param == 1) {
12                                 print _("Update daemon is enabled in configuration, but daemon
13                                         process is not running, which prevents all feeds from updating. Please
14                                         start the daemon process or contact instance owner.");
15                         }
16
17                         if ($param == 2) {
18                                 $msg = check_for_update($link, false);
19
20                                 if (!$msg) {
21                                         print _("You are running the latest version of Tiny Tiny RSS. The
22                                                 fact that you are seeing this dialog is probably a bug.");
23                                 } else {
24                                         print $msg;
25                                 }
26
27                         }
28
29                         print "</div>";
30
31                         print "<div align='center'>";
32
33                         print "<input class=\"button\"
34                                 type=\"submit\" onclick=\"return closeInfoBox()\" 
35                                 value=\"Close this window\">";
36
37                         print "</div>";
38
39                 }
40
41                 if ($id == "quickAddFeed") {
42
43                         print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
44                         print "<div class=\"infoBoxContents\">";
45
46                         print "<form id='feed_add_form'>";
47
48                         print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
49                         print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
50                         print "<input type=\"hidden\" name=\"subop\" value=\"add\">"; 
51
52                         print "<table width='100%'>
53                         <tr><td>Feed URL:</td><td>
54                                 <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\" 
55                                         onkeypress=\"return filterCR(event, qafAdd)\"
56                                         onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
57                                         onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
58                 
59                         if (get_pref($link, 'ENABLE_FEED_CATS')) {
60                                 print "<tr><td>Category:</td><td>";
61                                 print_feed_cat_select($link, "cat_id");                 
62                                 print "</td></tr>";
63                         }
64
65                         print "</table>";
66                         print "</form>";
67
68                         print "<div align='right'>
69                                 <input class=\"button\"
70                                         id=\"fadd_submit_btn\" disabled=\"true\"
71                                         type=\"submit\" onclick=\"return qafAdd()\" value=\"Subscribe\">
72                                 <input class=\"button\"
73                                         type=\"submit\" onclick=\"return closeInfoBox()\" 
74                                         value=\"Cancel\"></div>";
75                 }
76
77                 if ($id == "search") {
78
79                         print "<div id=\"infoBoxTitle\">Search</div>";
80                         print "<div class=\"infoBoxContents\">";
81
82                         print "<form id='search_form'>";
83
84                         #$active_feed_id = db_escape_string($_GET["param"]);
85
86                         $params = split(":", db_escape_string($_GET["param"]));
87
88                         $active_feed_id = sprintf("%d", $params[0]);
89                         $is_cat = $params[1] == "true";
90
91                         print "<table width='100%'><tr><td>Search:</td><td>";
92                         
93                         print "<input name=\"query\" class=\"iedit\" 
94                                 onkeypress=\"return filterCR(event, search)\"
95                                 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
96                                 value=\"\">
97                         </td></tr>";
98                         
99                         print "<tr><td>Where:</td><td>";
100                         
101                         print "<select name=\"search_mode\">
102                                 <option value=\"all_feeds\">All feeds</option>";
103                         
104                         $feed_title = getFeedTitle($link, $active_feed_id);
105
106                         if (!$is_cat) {
107                                 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
108                         } else {
109                                 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
110                         }
111                         
112                         if ($active_feed_id && !$is_cat) {                              
113                                 print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
114                         } else {
115                                 print "<option disabled>This feed</option>";
116                         }
117
118                         if ($is_cat) {
119                                 $cat_preselected = "selected";
120                         }
121
122                         if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
123                                 print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
124                         } else {
125                                 print "<option disabled>This category</option>";
126                         }
127
128                         print "</select></td></tr>"; 
129
130                         print "<tr><td>Match on:</td><td>";
131
132                         $search_fields = array(
133                                 "title" => "Title",
134                                 "content" => "Content",
135                                 "both" => "Title or content");
136
137                         print_select_hash("match_on", 3, $search_fields); 
138                                 
139                         print "</td></tr></table>";
140
141                         print "</form>";
142
143                         print "<div align=\"right\">
144                         <input type=\"submit\" 
145                                 class=\"button\" onclick=\"javascript:search()\" 
146                                 id=\"search_submit_btn\" disabled=\"true\"
147                                 value=\"Search\">
148                         <input class=\"button\"
149                                 type=\"submit\" onclick=\"javascript:searchCancel()\" 
150                                 value=\"Cancel\"></div>";
151
152                         print "</div>";
153
154                 }
155
156                 if ($id == "quickAddLabel") {
157                         print "<div id=\"infoBoxTitle\">Create label</div>";
158                         print "<div class=\"infoBoxContents\">";
159
160                         print "<form id=\"label_edit_form\">";
161
162                         print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
163                         print "<input type=\"hidden\" name=\"subop\" value=\"add\">"; 
164
165                         print "<table width='100%'>";
166
167                         print "<tr><td>Caption:</td>
168                                 <td><input onkeypress=\"return filterCR(event, addLabel)\"
169                                          onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
170                                          name=\"description\" class=\"iedit\">";
171
172                         print "</td></tr>";
173
174                         print "<tr><td colspan=\"2\">
175                                 <p>SQL Expression:</p>";
176
177                         print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
178                                          rows=\"4\" name=\"sql_exp\" class=\"iedit\"></textarea>";
179
180                         print "</td></tr></table>";
181
182                         print "</form>";
183
184                         print "<div style=\"display : none\" id=\"label_test_result\"></div>";
185
186                         print "<div align='right'>";
187
188                         print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
189                                 ";
190
191                         print "<input type=\"submit\" 
192                                 id=\"infobox_submit\"
193                                 disabled=\"true\"
194                                 class=\"button\" onclick=\"return addLabel()\" 
195                                 value=\"Create\"> ";
196
197                         print "<input class=\"button\"
198                                 type=\"submit\" onclick=\"return labelEditCancel()\" 
199                                 value=\"Cancel\">";
200                 }
201
202                 if ($id == "quickAddFilter") {
203
204                         $active_feed_id = db_escape_string($_GET["param"]);
205
206                         print "<div id=\"infoBoxTitle\">Create filter</div>";
207                         print "<div class=\"infoBoxContents\">";
208
209                         print "<form id=\"filter_add_form\">";
210
211                         print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
212                         print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
213                         print "<input type=\"hidden\" name=\"subop\" value=\"add\">"; 
214
215 //                      print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
216                 
217                         $result = db_query($link, "SELECT id,description 
218                                 FROM ttrss_filter_types ORDER BY description");
219         
220                         $filter_types = array();
221         
222                         while ($line = db_fetch_assoc($result)) {
223                                 //array_push($filter_types, $line["description"]);
224                                 $filter_types[$line["id"]] = $line["description"];
225                         }
226
227                         print "<table width='100%'>";
228
229                         print "<tr><td>Match:</td>
230                                 <td><input onkeypress=\"return filterCR(event, qaddFilter)\"
231                                          onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
232                                          name=\"reg_exp\" class=\"iedit\">";            
233
234                         print "</td></tr><tr><td>On field:</td><td>";
235
236                         print_select_hash("filter_type", 1, $filter_types, "class=\"_iedit\""); 
237         
238                         print "</td></tr>";
239                         print "<tr><td>Feed:</td><td colspan='2'>";
240
241                         print_feed_select($link, "feed_id", $active_feed_id);
242                         
243                         print "</td></tr>";
244         
245                         print "<tr><td>Action:</td>";
246         
247                         print "<td colspan='2'><select name=\"action_id\" 
248                                 onchange=\"filterDlgCheckAction(this)\">";
249         
250                         $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions 
251                                 ORDER BY name");
252
253                         while ($line = db_fetch_assoc($result)) {
254                                 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
255                         }
256         
257                         print "</select>";
258
259                         print "</td></tr>";
260
261                         print "<tr><td>Params:</td>";
262
263                         print "<td><input disabled class='iedit' name='action_param'></td></tr>";
264
265                         print "</table>";
266
267                         print "</form>";
268
269                         print "<div align='right'>";
270
271                         print "<input type=\"submit\" 
272                                 id=\"infobox_submit\"
273                                 class=\"button\" onclick=\"return qaddFilter()\" 
274                                 disabled=\"true\" value=\"Create\"> ";
275
276                         print "<input class=\"button\"
277                                 type=\"submit\" onclick=\"return closeInfoBox()\" 
278                                 value=\"Cancel\">";
279
280                         print "</div>";
281
282 //                      print "</td></tr></table>"; 
283
284                 }
285
286                 if ($id == "feedUpdateErrors") {
287
288                         print "<div id=\"infoBoxTitle\">Update Errors</div>";
289                         print "<div class=\"infoBoxContents\">";
290
291                         print "These feeds have not been updated because of errors:";
292
293                         $result = db_query($link, "SELECT id,title,feed_url,last_error
294                         FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
295
296                         print "<ul class='feedErrorsList'>";
297
298                         while ($line = db_fetch_assoc($result)) {
299                                 print "<li><b>" . $line["title"] . "</b> (" . $line["feed_url"] . "): " . 
300                                         "<em>" . $line["last_error"] . "</em>";
301                         }
302
303                         print "</ul>";
304                         print "</div>";
305
306                         print "<div align='center'>";
307
308                         print "<input class=\"button\"
309                                 type=\"submit\" onclick=\"return closeInfoBox()\" 
310                                 value=\"Close\">";
311
312                         print "</div>";
313
314                 }
315
316                 if ($id == "editArticleTags") {
317
318                         print "<div id=\"infoBoxTitle\">Edit Tags</div>";
319                         print "<div class=\"infoBoxContents\">";
320
321                         print "<form id=\"tag_edit_form\">";
322
323                         print "Tags for this article (separated by commas):<br>";
324
325                         $tags = get_article_tags($link, $param);
326
327                         $tags_str = join(", ", $tags);
328
329                         print "<table width='100%'>";
330
331                         print "<tr><td colspan='2'><input type=\"hidden\" name=\"id\" value=\"$param\"></td></tr>";
332
333                         print "<tr><td colspan='2'><textarea rows='4' class='iedit' name='tags_str'>$tags_str</textarea></td></tr>";
334
335                         print "<tr><td>Add existing tag:</td>";
336
337                         $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags 
338                                 WHERE owner_uid = '".$_SESSION["uid"]."' ORDER BY tag_name");
339
340                         $found_tags = array();
341
342                         array_push($found_tags, '');
343
344                         while ($line = db_fetch_assoc($result)) {
345                                 array_push($found_tags, truncate_string($line["tag_name"], 20));
346                         }
347
348                         print "<td align='right'>";
349
350                         print_select("found_tags", '', $found_tags, "onchange=\"javascript:editTagsInsert()\"");
351
352                         print "</td>";
353
354                         print "</tr>";
355
356                         print "</table>";
357
358                         print "</form>";
359
360                         print "<div align='right'>";
361
362                         print "<input class=\"button\"
363                                 type=\"submit\" onclick=\"return editTagsSave()\" 
364                                 value=\"Save\"> ";
365
366                         print "<input class=\"button\"
367                                 type=\"submit\" onclick=\"return closeInfoBox()\" 
368                                 value=\"Cancel\">";
369
370
371                         print "</div>";
372
373                 }
374
375                 print "</div>";
376         }
377 ?>