]> git.wh0rd.org - tt-rss.git/blame - prefs.js
security fixes in filter editor
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
1var xmlhttp = false;
2
91ff844a 3var active_feed_cat = false;
48f0adb0 4var active_label = false;
f5a50b25 5var active_tab = false;
c6232e43 6var feed_to_expand = false;
f5a50b25 7
1cac3c31
AD
8var piggie_top = -400;
9var piggie_fwd = true;
10
a58069db 11var xmlhttp = Ajax.getTransport();
007bda35 12
c6232e43
AD
13function expand_feed_callback() {
14 if (xmlhttp.readyState == 4) {
15 try {
16 var container = document.getElementById("BRDET-" + feed_to_expand);
17 container.innerHTML=xmlhttp.responseText;
18 container.style.display = "block";
4d4200a8 19// p_notify("");
c6232e43
AD
20 } catch (e) {
21 exception_error("expand_feed_callback", e);
22 }
23 }
24}
25
007bda35 26function feedlist_callback() {
007bda35 27 if (xmlhttp.readyState == 4) {
47c6c988
AD
28 try {
29 var container = document.getElementById('prefContent');
30 container.innerHTML=xmlhttp.responseText;
a7f22b70
AD
31 selectTab("feedConfig", true);
32
3c5783b7
AD
33 if (active_feed_cat) {
34 var row = document.getElementById("FCATR-" + active_feed_cat);
47c6c988
AD
35 if (row) {
36 if (!row.className.match("Selected")) {
37 row.className = row.className + "Selected";
38 }
39 }
3c5783b7 40 var checkbox = document.getElementById("FCCHK-" + active_feed_cat);
47c6c988
AD
41 if (checkbox) {
42 checkbox.checked = true;
43 }
961513a3 44 }
3c5783b7 45
7f74a9da 46 notify("");
47c6c988
AD
47 } catch (e) {
48 exception_error("feedlist_callback", e);
961513a3 49 }
007bda35
AD
50 }
51}
52
a0d53889 53function filterlist_callback() {
f5a50b25 54 var container = document.getElementById('prefContent');
a0d53889
AD
55 if (xmlhttp.readyState == 4) {
56 container.innerHTML=xmlhttp.responseText;
7f74a9da 57 notify("");
a0d53889
AD
58 }
59}
60
48f0adb0 61function labellist_callback() {
f5a50b25 62 var container = document.getElementById('prefContent');
48f0adb0
AD
63 if (xmlhttp.readyState == 4) {
64 container.innerHTML=xmlhttp.responseText;
65
967955b7 66 if (active_label) {
48f0adb0
AD
67 var row = document.getElementById("LILRR-" + active_label);
68 if (row) {
69 if (!row.className.match("Selected")) {
70 row.className = row.className + "Selected";
71 }
72 }
73 var checkbox = document.getElementById("LICHK-" + active_label);
74
75 if (checkbox) {
76 checkbox.checked = true;
77 }
78 }
7f74a9da 79 notify("");
48f0adb0
AD
80 }
81}
4255b24c 82
c6232e43
AD
83function feed_browser_callback() {
84 var container = document.getElementById('prefContent');
85 if (xmlhttp.readyState == 4) {
86 container.innerHTML=xmlhttp.responseText;
7f74a9da 87 notify("");
c6232e43
AD
88 }
89}
90
e6cb77a0
AD
91function userlist_callback() {
92 var container = document.getElementById('prefContent');
93 if (xmlhttp.readyState == 4) {
94 container.innerHTML=xmlhttp.responseText;
7f74a9da 95 notify("");
e6cb77a0
AD
96 }
97}
98
4255b24c
AD
99function prefslist_callback() {
100 var container = document.getElementById('prefContent');
101 if (xmlhttp.readyState == 4) {
102
103 container.innerHTML=xmlhttp.responseText;
7f74a9da
AD
104
105 notify("");
4255b24c
AD
106 }
107}
108
b1895692
AD
109function gethelp_callback() {
110 var container = document.getElementById('prefHelpBox');
111 if (xmlhttp.readyState == 4) {
112
113 container.innerHTML = xmlhttp.responseText;
114 container.style.display = "block";
115
116 }
117}
4255b24c
AD
118
119
0e091d38
AD
120function notify_callback() {
121 var container = document.getElementById('notify');
122 if (xmlhttp.readyState == 4) {
123 container.innerHTML=xmlhttp.responseText;
124 }
125}
126
b83c7545 127function updateFeedList(sort_key) {
007bda35 128
c0e5a40e 129 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
130 printLockingError();
131 return
132 }
133
f5a50b25
AD
134// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
135
ce3bf408 136// p_notify("Loading, please wait...");
007bda35 137
f932bc9f
AD
138 var feed_search = document.getElementById("feed_search");
139 var search = "";
140 if (feed_search) { search = feed_search.value; }
141
b83c7545 142 xmlhttp.open("GET", "backend.php?op=pref-feeds" +
f932bc9f
AD
143 "&sort=" + param_escape(sort_key) +
144 "&search=" + param_escape(search), true);
007bda35
AD
145 xmlhttp.onreadystatechange=feedlist_callback;
146 xmlhttp.send(null);
147
148}
149
e6cb77a0
AD
150function updateUsersList() {
151
152 if (!xmlhttp_ready(xmlhttp)) {
153 printLockingError();
154 return
155 }
156
157// document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
158
ce3bf408 159// p_notify("Loading, please wait...");
e6cb77a0
AD
160
161 xmlhttp.open("GET", "backend.php?op=pref-users", true);
162 xmlhttp.onreadystatechange=userlist_callback;
163 xmlhttp.send(null);
164
165}
166
48f0adb0
AD
167function addLabel() {
168
169 if (!xmlhttp_ready(xmlhttp)) {
170 printLockingError();
171 return
172 }
173
174 var sqlexp = document.getElementById("ladd_expr");
175
176 if (sqlexp.value.length == 0) {
01b3e191 177 alert("Can't add label: missing SQL expression.");
48f0adb0
AD
178 } else {
179 notify("Adding label...");
180
181 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&exp=" +
182 param_escape(sqlexp.value), true);
183
184 xmlhttp.onreadystatechange=labellist_callback;
185 xmlhttp.send(null);
186
187 sqlexp.value = "";
188 }
189
190}
191
de435974
AD
192function addFilter() {
193
194 if (!xmlhttp_ready(xmlhttp)) {
195 printLockingError();
196 return
197 }
198
199 var regexp = document.getElementById("fadd_regexp");
200 var match = document.getElementById("fadd_match");
ead60402 201 var feed = document.getElementById("fadd_feed");
19c9cb11 202 var action = document.getElementById("fadd_action");
de435974
AD
203
204 if (regexp.value.length == 0) {
01b3e191 205 alert("Can't add filter: missing filter expression.");
de435974
AD
206 } else {
207 notify("Adding filter...");
208
25cb5736 209 var v_match = match[match.selectedIndex].text;
ead60402 210 var feed_id = feed[feed.selectedIndex].id;
19c9cb11 211 var action_id = action[action.selectedIndex].id;
ead60402 212
de435974 213 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=add&regexp=" +
ead60402 214 param_escape(regexp.value) + "&match=" + v_match +
19c9cb11 215 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
de435974
AD
216
217 xmlhttp.onreadystatechange=filterlist_callback;
218 xmlhttp.send(null);
219
220 regexp.value = "";
221 }
222
223}
48f0adb0 224
71ad3959
AD
225function addFeed() {
226
c0e5a40e 227 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
228 printLockingError();
229 return
230 }
231
331900c6
AD
232 var link = document.getElementById("fadd_link");
233
83fe4d6d 234 if (link.value.length == 0) {
0ceded7a 235 alert("Error: No feed URL given.");
605f7d46 236 } else if (!isValidURL(link.value)) {
2371c520 237 alert("Error: Invalid feed URL.");
331900c6
AD
238 } else {
239 notify("Adding feed...");
240
07eb9178 241 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&feed_url=" +
331900c6
AD
242 param_escape(link.value), true);
243 xmlhttp.onreadystatechange=feedlist_callback;
244 xmlhttp.send(null);
245
246 link.value = "";
247
248 }
249
250}
251
91ff844a
AD
252function addFeedCat() {
253
254 if (!xmlhttp_ready(xmlhttp)) {
255 printLockingError();
256 return
257 }
258
259 var cat = document.getElementById("fadd_cat");
260
261 if (cat.value.length == 0) {
01b3e191 262 alert("Can't add category: no name specified.");
91ff844a
AD
263 } else {
264 notify("Adding feed category...");
265
266 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=addCat&cat=" +
267 param_escape(cat.value), true);
268 xmlhttp.onreadystatechange=feedlist_callback;
269 xmlhttp.send(null);
270
271 link.value = "";
272
273 }
274
275}
e6cb77a0
AD
276function addUser() {
277
278 if (!xmlhttp_ready(xmlhttp)) {
279 printLockingError();
280 return
281 }
282
283 var sqlexp = document.getElementById("uadd_box");
284
285 if (sqlexp.value.length == 0) {
01b3e191 286 alert("Can't add user: no login specified.");
e6cb77a0
AD
287 } else {
288 notify("Adding user...");
289
290 xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
291 param_escape(sqlexp.value), true);
292
293 xmlhttp.onreadystatechange=userlist_callback;
294 xmlhttp.send(null);
295
296 sqlexp.value = "";
297 }
298
299}
300
48f0adb0
AD
301function editLabel(id) {
302
303 if (!xmlhttp_ready(xmlhttp)) {
304 printLockingError();
305 return
306 }
307
308 active_label = id;
309
310 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
311 param_escape(id), true);
312 xmlhttp.onreadystatechange=labellist_callback;
313 xmlhttp.send(null);
314
315}
316
e6cb77a0
AD
317function editUser(id) {
318
319 if (!xmlhttp_ready(xmlhttp)) {
320 printLockingError();
321 return
322 }
323
3c5783b7
AD
324 selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
325 selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
e6cb77a0
AD
326
327 xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
328 param_escape(id), true);
3c5783b7 329 xmlhttp.onreadystatechange=infobox_callback;
e6cb77a0
AD
330 xmlhttp.send(null);
331
332}
333
a0d53889
AD
334function editFilter(id) {
335
336 if (!xmlhttp_ready(xmlhttp)) {
337 printLockingError();
338 return
339 }
340
4220b0bd
AD
341 document.getElementById("create_filter_btn").disabled = true;
342
07164479
AD
343 selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
344 selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
a0d53889 345
07164479
AD
346 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
347 xmlhttp.onreadystatechange=infobox_callback;
a0d53889 348 xmlhttp.send(null);
a0d53889
AD
349}
350
331900c6
AD
351function editFeed(feed) {
352
508a81e1
AD
353// notify("Editing feed...");
354
c0e5a40e 355 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
356 printLockingError();
357 return
358 }
331900c6 359
673d54ca 360 // clean selection from all rows & select row being edited
0ea4fb50 361 selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
6c12c809 362 selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
0ea4fb50
AD
363
364 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
3c5783b7 365 param_escape(feed), true);
0ea4fb50
AD
366
367 xmlhttp.onreadystatechange=infobox_callback;
331900c6
AD
368 xmlhttp.send(null);
369
370}
371
91ff844a 372function editFeedCat(cat) {
48f0adb0 373
91ff844a
AD
374 if (!xmlhttp_ready(xmlhttp)) {
375 printLockingError();
376 return
48f0adb0
AD
377 }
378
91ff844a 379 active_feed_cat = cat;
e6cb77a0 380
91ff844a
AD
381 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCat&id=" +
382 param_escape(cat), true);
383 xmlhttp.onreadystatechange=feedlist_callback;
384 xmlhttp.send(null);
e6cb77a0 385
e6cb77a0
AD
386}
387
91ff844a
AD
388function getSelectedLabels() {
389 return getSelectedTableRowIds("prefLabelList", "LILRR");
390}
48f0adb0 391
91ff844a
AD
392function getSelectedUsers() {
393 return getSelectedTableRowIds("prefUserList", "UMRR");
a0d53889
AD
394}
395
83fe4d6d 396function getSelectedFeeds() {
91ff844a
AD
397 return getSelectedTableRowIds("prefFeedList", "FEEDR");
398}
331900c6 399
91ff844a
AD
400function getSelectedFilters() {
401 return getSelectedTableRowIds("prefFilterList", "FILRR");
402}
331900c6 403
91ff844a
AD
404function getSelectedFeedCats() {
405 return getSelectedTableRowIds("prefFeedCatList", "FCATR");
83fe4d6d
AD
406}
407
c0ae0fdb
AD
408function getSelectedFeedsFromBrowser() {
409
410 var list = document.getElementById("browseFeedList");
411 if (!list) list = document.getElementById("browseBigFeedList");
412
413 var selected = new Array();
414
415 for (i = 0; i < list.childNodes.length; i++) {
416 var child = list.childNodes[i];
417 if (child.id && child.id.match("FBROW-")) {
418 var id = child.id.replace("FBROW-", "");
419
420 var cb = document.getElementById("FBCHK-" + id);
421
422 if (cb.checked) {
423 selected.push(id);
424 }
425 }
426 }
427
428 return selected;
429}
430
48f0adb0
AD
431function removeSelectedLabels() {
432
433 if (!xmlhttp_ready(xmlhttp)) {
434 printLockingError();
435 return
436 }
437
438 var sel_rows = getSelectedLabels();
439
440 if (sel_rows.length > 0) {
441
69668465 442 var ok = confirm("Remove selected labels?");
48f0adb0 443
69668465
AD
444 if (ok) {
445 notify("Removing selected labels...");
446
447 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
448 param_escape(sel_rows.toString()), true);
449 xmlhttp.onreadystatechange=labellist_callback;
450 xmlhttp.send(null);
451 }
48f0adb0 452 } else {
01b3e191 453 alert("No labels are selected.");
48f0adb0
AD
454 }
455}
456
e6cb77a0
AD
457function removeSelectedUsers() {
458
459 if (!xmlhttp_ready(xmlhttp)) {
460 printLockingError();
461 return
462 }
463
464 var sel_rows = getSelectedUsers();
465
466 if (sel_rows.length > 0) {
467
69668465 468 var ok = confirm("Remove selected users?");
e6cb77a0 469
69668465
AD
470 if (ok) {
471 notify("Removing selected users...");
472
473 xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
474 param_escape(sel_rows.toString()), true);
475 xmlhttp.onreadystatechange=userlist_callback;
476 xmlhttp.send(null);
477 }
e6cb77a0
AD
478
479 } else {
01b3e191 480 alert("No users are selected.");
e6cb77a0
AD
481 }
482}
483
48f0adb0
AD
484function removeSelectedFilters() {
485
486 if (!xmlhttp_ready(xmlhttp)) {
487 printLockingError();
488 return
489 }
490
491 var sel_rows = getSelectedFilters();
492
493 if (sel_rows.length > 0) {
494
69668465 495 var ok = confirm("Remove selected filters?");
48f0adb0 496
69668465
AD
497 if (ok) {
498 notify("Removing selected filters...");
499
500 xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
501 param_escape(sel_rows.toString()), true);
502 xmlhttp.onreadystatechange=filterlist_callback;
503 xmlhttp.send(null);
504 }
48f0adb0 505 } else {
01b3e191 506 alert("No filters are selected.");
48f0adb0
AD
507 }
508}
509
510
83fe4d6d
AD
511function removeSelectedFeeds() {
512
c0e5a40e 513 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
514 printLockingError();
515 return
516 }
517
83fe4d6d
AD
518 var sel_rows = getSelectedFeeds();
519
331900c6
AD
520 if (sel_rows.length > 0) {
521
1d7bf5a0 522 var ok = confirm("Unsubscribe from selected feeds?");
331900c6 523
69668465
AD
524 if (ok) {
525
1d7bf5a0 526 notify("Unsubscribing from selected feeds...");
69668465
AD
527
528 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
529 param_escape(sel_rows.toString()), true);
530 xmlhttp.onreadystatechange=feedlist_callback;
531 xmlhttp.send(null);
532 }
71ad3959 533
71ad3959 534 } else {
331900c6 535
01b3e191 536 alert("No feeds are selected.");
331900c6 537
71ad3959
AD
538 }
539
540}
007bda35 541
91ff844a
AD
542function removeSelectedFeedCats() {
543
544 if (!xmlhttp_ready(xmlhttp)) {
545 printLockingError();
546 return
547 }
548
549 var sel_rows = getSelectedFeedCats();
550
551 if (sel_rows.length > 0) {
552
69668465 553 var ok = confirm("Remove selected categories?");
91ff844a 554
69668465
AD
555 if (ok) {
556 notify("Removing selected categories...");
557
558 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=removeCats&ids="+
559 param_escape(sel_rows.toString()), true);
560 xmlhttp.onreadystatechange=feedlist_callback;
561 xmlhttp.send(null);
562 }
91ff844a
AD
563
564 } else {
565
01b3e191 566 alert("No categories are selected.");
91ff844a
AD
567
568 }
569
570}
571
508a81e1
AD
572function feedEditCancel() {
573
c0e5a40e 574 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
575 printLockingError();
576 return
577 }
578
327a3bbe
AD
579 closeInfoBox();
580
673d54ca 581 selectPrefRows('feed', false); // cleanup feed selection
508a81e1
AD
582
583}
584
91ff844a
AD
585function feedCatEditCancel() {
586
587 if (!xmlhttp_ready(xmlhttp)) {
588 printLockingError();
589 return
590 }
591
592 active_feed_cat = false;
593
0ceded7a 594// notify("Operation cancelled.");
91ff844a
AD
595
596 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
597 xmlhttp.onreadystatechange=feedlist_callback;
598 xmlhttp.send(null);
599
600}
601
603c27f8
AD
602function feedEditSave() {
603
47c6c988 604 try {
47c6c988
AD
605
606 if (!xmlhttp_ready(xmlhttp)) {
607 printLockingError();
608 return
609 }
ad815c71 610
14f69488 611 // FIXME: add parameter validation
e3c99f3b 612
14f69488 613 var query = Form.serialize("edit_feed_form");
b0da3a7b 614
14f69488 615 notify("Saving feed...");
673d54ca 616
47c6c988
AD
617 xmlhttp.open("POST", "backend.php", true);
618 xmlhttp.onreadystatechange=feedlist_callback;
619 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
14f69488
AD
620 xmlhttp.send(query);
621
59a543f0
AD
622 closeInfoBox();
623
c14b5566
AD
624 return false;
625
47c6c988
AD
626 } catch (e) {
627 exception_error("feedEditSave", e);
b0da3a7b 628 }
508a81e1
AD
629}
630
5ddadb4c
AD
631function feedCatEditSave() {
632
633 if (!xmlhttp_ready(xmlhttp)) {
634 printLockingError();
635 return
636 }
637
f0e81ffe 638 notify("Saving category...");
5ddadb4c 639
0666e120
AD
640 var query = Form.serialize("feed_cat_edit_form");
641
642 xmlhttp.open("GET", "backend.php?" + query, true);
5ddadb4c
AD
643 xmlhttp.onreadystatechange=feedlist_callback;
644 xmlhttp.send(null);
645
646 active_feed_cat = false;
647
648}
649
650
d9dde1d6
AD
651function labelTest() {
652
f3120e5a
AD
653 var form = document.forms['label_edit_form'];
654
655 var sql_exp = form.sql_exp.value;
656 var description = form.description.value;
d9dde1d6
AD
657
658 xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
f3120e5a 659 param_escape(sql_exp) + "&descr=" + param_escape(description), true);
d9dde1d6
AD
660
661 xmlhttp.onreadystatechange=infobox_callback;
662 xmlhttp.send(null);
663
664}
665
01c9c74a
AD
666function displayHelpInfobox(topic_id) {
667
668 xmlhttp.open("GET", "backend.php?op=help&tid=" +
669 param_escape(topic_id) + "&noheaders=1", true);
670
671 xmlhttp.onreadystatechange=infobox_callback;
672 xmlhttp.send(null);
673
674}
675
48f0adb0
AD
676function labelEditCancel() {
677
678 if (!xmlhttp_ready(xmlhttp)) {
679 printLockingError();
680 return
681 }
682
683 active_label = false;
684
0ceded7a 685// notify("Operation cancelled.");
48f0adb0
AD
686
687 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
688 xmlhttp.onreadystatechange=labellist_callback;
689 xmlhttp.send(null);
690
691}
692
e6cb77a0
AD
693function userEditCancel() {
694
695 if (!xmlhttp_ready(xmlhttp)) {
696 printLockingError();
697 return
698 }
699
3c5783b7 700 selectPrefRows('user', false); // cleanup feed selection
3c5783b7 701 closeInfoBox();
e6cb77a0 702}
48f0adb0 703
a0d53889
AD
704function filterEditCancel() {
705
706 if (!xmlhttp_ready(xmlhttp)) {
707 printLockingError();
708 return
709 }
4220b0bd
AD
710
711 document.getElementById("create_filter_btn").disabled = false;
07164479
AD
712
713 selectPrefRows('filter', false); // cleanup feed selection
714 closeInfoBox();
a0d53889
AD
715}
716
48f0adb0
AD
717function labelEditSave() {
718
719 var label = active_label;
720
721 if (!xmlhttp_ready(xmlhttp)) {
722 printLockingError();
723 return
724 }
725
3c5783b7
AD
726 var sql_exp = document.forms["label_edit_form"].sql_exp.value;
727 var description = document.forms["label_edit_form"].description.value;
48f0adb0 728
3c5783b7
AD
729 if (sql_exp.length == 0) {
730 alert("SQL Expression cannot be blank.");
48f0adb0
AD
731 return;
732 }
733
3c5783b7
AD
734 if (description.length == 0) {
735 alert("Caption field cannot be blank.");
48f0adb0 736 return;
3c5783b7 737 }
48f0adb0 738
f0e81ffe 739 notify("Saving label...");
dbd9e2f1 740
48f0adb0
AD
741 active_label = false;
742
f3120e5a
AD
743 query = Form.serialize("label_edit_form");
744
745 xmlhttp.open("GET", "backend.php?" + query, true);
48f0adb0
AD
746
747 xmlhttp.onreadystatechange=labellist_callback;
748 xmlhttp.send(null);
749
750}
751
e6cb77a0
AD
752function userEditSave() {
753
e6cb77a0
AD
754 if (!xmlhttp_ready(xmlhttp)) {
755 printLockingError();
756 return
757 }
758
3c5783b7 759 var login = document.forms["user_edit_form"].login.value;
e6cb77a0
AD
760
761 if (login.length == 0) {
3c5783b7 762 alert("Login field cannot be blank.");
e6cb77a0
AD
763 return;
764 }
3c5783b7 765
f0e81ffe 766 notify("Saving user...");
4220b0bd
AD
767
768 closeInfoBox();
769
3c5783b7
AD
770 var query = Form.serialize("user_edit_form");
771
772 xmlhttp.open("GET", "backend.php?" + query, true);
dbd9e2f1 773 xmlhttp.onreadystatechange=userlist_callback;
e6cb77a0 774 xmlhttp.send(null);
e6cb77a0
AD
775}
776
777
a0d53889
AD
778function filterEditSave() {
779
a0d53889
AD
780 if (!xmlhttp_ready(xmlhttp)) {
781 printLockingError();
782 return
783 }
784
3c5783b7
AD
785 var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
786
787 if (reg_exp.length == 0) {
788 alert("Filter expression field cannot be blank.");
789 return;
790 }
a0d53889 791
7e939457 792 notify("Saving filter...");
a0d53889 793
7e939457 794 var query = Form.serialize("filter_edit_form");
dbd9e2f1 795
07164479
AD
796 closeInfoBox();
797
4220b0bd
AD
798 document.getElementById("create_filter_btn").disabled = false;
799
7e939457 800 xmlhttp.open("GET", "backend.php?" + query, true);
a0d53889 801 xmlhttp.onreadystatechange=filterlist_callback;
7e939457 802 xmlhttp.send(null);
a0d53889
AD
803
804}
805
48f0adb0
AD
806function editSelectedLabel() {
807 var rows = getSelectedLabels();
a0d53889 808
48f0adb0 809 if (rows.length == 0) {
01b3e191 810 alert("No labels are selected.");
48f0adb0 811 return;
a0d53889
AD
812 }
813
48f0adb0 814 if (rows.length > 1) {
01b3e191 815 alert("Please select only one label.");
48f0adb0
AD
816 return;
817 }
a0d53889 818
dbd9e2f1
AD
819 notify("");
820
48f0adb0 821 editLabel(rows[0]);
a0d53889 822
a0d53889
AD
823}
824
e6cb77a0
AD
825function editSelectedUser() {
826 var rows = getSelectedUsers();
827
828 if (rows.length == 0) {
01b3e191 829 alert("No users are selected.");
e6cb77a0
AD
830 return;
831 }
832
833 if (rows.length > 1) {
01b3e191 834 alert("Please select only one user.");
e6cb77a0
AD
835 return;
836 }
837
dbd9e2f1
AD
838 notify("");
839
e6cb77a0
AD
840 editUser(rows[0]);
841}
842
843function resetSelectedUserPass() {
844 var rows = getSelectedUsers();
845
846 if (rows.length == 0) {
01b3e191 847 alert("No users are selected.");
e6cb77a0
AD
848 return;
849 }
850
851 if (rows.length > 1) {
01b3e191 852 alert("Please select only one user.");
e6cb77a0
AD
853 return;
854 }
855
69668465 856 var ok = confirm("Reset password of selected user?");
e6cb77a0 857
69668465
AD
858 if (ok) {
859 notify("Resetting password for selected user...");
860
861 var id = rows[0];
862
863 xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
864 param_escape(id), true);
865 xmlhttp.onreadystatechange=userlist_callback;
866 xmlhttp.send(null);
867 }
e6cb77a0
AD
868}
869
717f5e64 870function selectedUserDetails() {
e6cb77a0 871
1a7572cb
AD
872 if (!xmlhttp_ready(xmlhttp)) {
873 printLockingError();
874 return
875 }
876
717f5e64
AD
877 var rows = getSelectedUsers();
878
879 if (rows.length == 0) {
01b3e191 880 alert("No users are selected.");
717f5e64
AD
881 return;
882 }
883
884 if (rows.length > 1) {
01b3e191 885 alert("Please select only one user.");
717f5e64
AD
886 return;
887 }
888
889 var id = rows[0];
890
dbd9e2f1
AD
891 notify("");
892
1a7572cb 893 xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
c6c3a07f
AD
894 xmlhttp.onreadystatechange=infobox_callback;
895 xmlhttp.send(null);
896
897}
898
899function selectedFeedDetails() {
900
901 if (!xmlhttp_ready(xmlhttp)) {
902 printLockingError();
903 return
904 }
905
906 var rows = getSelectedFeeds();
907
908 if (rows.length == 0) {
01b3e191 909 alert("No feeds are selected.");
c6c3a07f
AD
910 return;
911 }
912
01b3e191
AD
913 if (rows.length > 1) {
914 notify("Please select only one feed.");
915 return;
916 }
c6c3a07f 917
df268d47 918// var id = rows[0];
c6c3a07f 919
dbd9e2f1
AD
920 notify("");
921
df268d47
AD
922 xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
923 param_escape(rows.toString()), true);
c6c3a07f 924 xmlhttp.onreadystatechange=infobox_callback;
1a7572cb 925 xmlhttp.send(null);
717f5e64
AD
926
927}
a0d53889
AD
928
929function editSelectedFilter() {
930 var rows = getSelectedFilters();
931
932 if (rows.length == 0) {
01b3e191 933 alert("No filters are selected.");
a0d53889
AD
934 return;
935 }
936
937 if (rows.length > 1) {
01b3e191 938 alert("Please select only one filter.");
a0d53889
AD
939 return;
940 }
941
dbd9e2f1
AD
942 notify("");
943
a0d53889
AD
944 editFilter(rows[0]);
945
946}
947
948
508a81e1
AD
949function editSelectedFeed() {
950 var rows = getSelectedFeeds();
951
952 if (rows.length == 0) {
953 notify("No feeds are selected.");
954 return;
955 }
956
957 if (rows.length > 1) {
958 notify("Please select one feed.");
959 return;
960 }
961
dbd9e2f1
AD
962 notify("");
963
508a81e1 964 editFeed(rows[0]);
91ff844a
AD
965
966}
967
968function editSelectedFeedCat() {
969 var rows = getSelectedFeedCats();
970
971 if (rows.length == 0) {
01b3e191 972 alert("No categories are selected.");
91ff844a
AD
973 return;
974 }
975
976 if (rows.length > 1) {
01b3e191 977 alert("Please select only one category.");
91ff844a
AD
978 return;
979 }
980
981 notify("");
982
983 editFeedCat(rows[0]);
508a81e1
AD
984
985}
986
1cac3c31
AD
987function piggie_callback() {
988 var piggie = document.getElementById("piggie");
989
990 piggie.style.top = piggie_top;
e0b6a737
AD
991 piggie.style.backgroundColor = "white";
992 piggie.style.borderWidth = "1px";
1cac3c31
AD
993
994 if (piggie_fwd && piggie_top < 0) {
995 setTimeout("piggie_callback()", 50);
996 piggie_top = piggie_top + 10;
997 } else if (piggie_fwd && piggie_top >= 0) {
998 piggie_fwd = false;
999 setTimeout("piggie_callback()", 50);
1000 } else if (!piggie_fwd && piggie_top > -400) {
1001 setTimeout("piggie_callback()", 50);
1002 piggie_top = piggie_top - 10;
1003 } else if (!piggie_fwd && piggie_top <= -400) {
1004 piggie.style.display = "none";
1005 piggie_fwd = true;
1006 }
1007}
1008
33377ef3
AD
1009var piggie_opacity = 0;
1010
1011function piggie2_callback() {
1012 var piggie = document.getElementById("piggie");
1013 piggie.style.top = 0;
1014 piggie.style.opacity = piggie_opacity;
e0b6a737
AD
1015 piggie.style.backgroundColor = "transparent";
1016 piggie.style.borderWidth = "0px";
33377ef3
AD
1017
1018 if (piggie_fwd && piggie_opacity < 1) {
1019 setTimeout("piggie2_callback()", 50);
1020 piggie_opacity = piggie_opacity + 0.03;
1021 } else if (piggie_fwd && piggie_opacity >= 1) {
1022 piggie_fwd = false;
1023 setTimeout("piggie2_callback()", 50);
1024 } else if (!piggie_fwd && piggie_opacity > 0) {
1025 setTimeout("piggie2_callback()", 50);
1026 piggie_opacity = piggie_opacity - 0.03;
1027 } else if (!piggie_fwd && piggie_opacity <= 0) {
1028 piggie.style.display = "none";
1029 piggie_fwd = true;
1030 }
1031}
1032
13ad9102
AD
1033function localPiggieFunction(enable) {
1034 if (enable) {
1cac3c31 1035 var piggie = document.getElementById("piggie");
508a81e1 1036 piggie.style.display = "block";
33377ef3 1037
292a8a12 1038 if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
33377ef3
AD
1039 piggie2_callback();
1040 } else {
1041 piggie_callback();
1042 }
508a81e1 1043 }
508a81e1
AD
1044}
1045
9f311df6
AD
1046function validateOpmlImport() {
1047
1048 var opml_file = document.getElementById("opml_file");
1049
1050 if (opml_file.value.length == 0) {
01b3e191 1051 alert("No OPML file to upload.");
9f311df6
AD
1052 return false;
1053 } else {
1054 return true;
1055 }
1056}
1057
a0d53889
AD
1058function updateFilterList() {
1059
1060 if (!xmlhttp_ready(xmlhttp)) {
1061 printLockingError();
1062 return
1063 }
1064
f5a50b25
AD
1065// document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
1066
ce3bf408 1067// p_notify("Loading, please wait...");
a0d53889
AD
1068
1069 xmlhttp.open("GET", "backend.php?op=pref-filters", true);
1070 xmlhttp.onreadystatechange=filterlist_callback;
1071 xmlhttp.send(null);
1072
1073}
1074
48f0adb0
AD
1075function updateLabelList() {
1076
1077 if (!xmlhttp_ready(xmlhttp)) {
1078 printLockingError();
1079 return
1080 }
1081
ce3bf408 1082// p_notify("Loading, please wait...");
f5a50b25
AD
1083
1084// document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
48f0adb0
AD
1085
1086 xmlhttp.open("GET", "backend.php?op=pref-labels", true);
1087 xmlhttp.onreadystatechange=labellist_callback;
1088 xmlhttp.send(null);
48f0adb0
AD
1089}
1090
4255b24c
AD
1091function updatePrefsList() {
1092
1093 if (!xmlhttp_ready(xmlhttp)) {
1094 printLockingError();
1095 return
1096 }
1097
ce3bf408 1098// p_notify("Loading, please wait...");
4255b24c
AD
1099
1100 xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
1101 xmlhttp.onreadystatechange=prefslist_callback;
1102 xmlhttp.send(null);
1103
1104}
1105
a7f22b70
AD
1106function selectTab(id, noupdate) {
1107
1108// alert(id);
48f0adb0 1109
c6c3a07f
AD
1110 if (!xmlhttp_ready(xmlhttp)) {
1111 printLockingError();
1112 return
1113 }
1114
a7f22b70
AD
1115 if (!noupdate) {
1116
7f74a9da
AD
1117 notify("Loading, please wait...", true);
1118
59a543f0
AD
1119 // close active infobox if needed
1120 closeInfoBox();
1121
673d54ca 1122 // clean up all current selections, just in case
673d54ca 1123 active_feed_cat = false;
673d54ca 1124 active_label = false;
673d54ca 1125
a7f22b70
AD
1126 if (id == "feedConfig") {
1127 updateFeedList();
1128 } else if (id == "filterConfig") {
1129 updateFilterList();
1130 } else if (id == "labelConfig") {
1131 updateLabelList();
1132 } else if (id == "genConfig") {
1133 updatePrefsList();
1134 } else if (id == "userConfig") {
1135 updateUsersList();
1136 } else if (id == "feedBrowser") {
1137 updateBigFeedBrowser();
1138 }
a0d53889 1139 }
f5a50b25
AD
1140
1141 var tab = document.getElementById(active_tab + "Tab");
1142
1143 if (tab) {
1144 if (tab.className.match("Selected")) {
1145 tab.className = "prefsTab";
1146 }
1147 }
1148
1149 tab = document.getElementById(id + "Tab");
1150
1151 if (tab) {
1152 if (!tab.className.match("Selected")) {
1153 tab.className = tab.className + "Selected";
1154 }
1155 }
1156
1157 active_tab = id;
1158
4da47970
AD
1159 setCookie('ttrss_pref_acttab', active_tab);
1160
a0d53889
AD
1161}
1162
007bda35 1163function init() {
e2ec66a8 1164
7719618b
AD
1165 try {
1166
97dcd654
AD
1167 if (arguments.callee.done) return;
1168 arguments.callee.done = true;
1169
7719618b
AD
1170 // IE kludge
1171 if (!xmlhttp) {
1172 document.getElementById("prefContent").innerHTML =
1173 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
1174 "to function properly. Your browser doesn't seem to support it.";
1175 return;
1176 }
4da47970
AD
1177
1178 active_tab = getCookie("ttrss_pref_acttab");
1179 if (!active_tab) active_tab = "genConfig";
1180 selectTab(active_tab);
7719618b
AD
1181
1182 document.onkeydown = hotkey_handler;
1183 notify("");
1184 } catch (e) {
1185 exception_error("init", e);
e2ec66a8 1186 }
007bda35 1187}
b1895692 1188
f932bc9f
AD
1189function categorizeSelectedFeeds() {
1190
1191 if (!xmlhttp_ready(xmlhttp)) {
1192 printLockingError();
1193 return
1194 }
1195
1196 var sel_rows = getSelectedFeeds();
1197
1198 var cat_sel = document.getElementById("sfeed_set_fcat");
79f3553b 1199 var cat_id = cat_sel[cat_sel.selectedIndex].value;
f932bc9f
AD
1200
1201 if (sel_rows.length > 0) {
1202
1203 notify("Changing category of selected feeds...");
1204
1205 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
1206 param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
1207 xmlhttp.onreadystatechange=feedlist_callback;
1208 xmlhttp.send(null);
1209
1210 } else {
1211
01b3e191 1212 alert("No feeds are selected.");
f932bc9f
AD
1213
1214 }
1215
1216}
69668465
AD
1217
1218function validatePrefsReset() {
1219 return confirm("Reset to defaults?");
1220}
f9cb39ac 1221
6311acbe 1222function browseFeeds(limit) {
f9cb39ac
AD
1223
1224 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
1225 xmlhttp.onreadystatechange=infobox_callback;
1226 xmlhttp.send(null);
1227
1228}
a0476535
AD
1229
1230function feedBrowserSubscribe() {
1231 try {
a0476535 1232
c0ae0fdb 1233 var selected = getSelectedFeedsFromBrowser();
a0476535
AD
1234
1235 if (selected.length > 0) {
1236 closeInfoBox();
1237 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
1238 param_escape(selected.toString()), true);
1239 xmlhttp.onreadystatechange=feedlist_callback;
1240 xmlhttp.send(null);
1241 } else {
1242 alert("No feeds are selected.");
1243 }
1244
1245 } catch (e) {
1246 exception_error("feedBrowserSubscribe", e);
1247 }
1248}
c6232e43 1249
6311acbe 1250function updateBigFeedBrowser(limit) {
c6232e43
AD
1251
1252 if (!xmlhttp_ready(xmlhttp)) {
1253 printLockingError();
1254 return
1255 }
1256
ce3bf408 1257// p_notify("Loading, please wait...");
c6232e43 1258
6311acbe
AD
1259 var query = "backend.php?op=pref-feed-browser";
1260
1261 var limit_sel = document.getElementById("feedBrowserLimit");
1262
1263 if (limit_sel) {
1264 var limit = limit_sel[limit_sel.selectedIndex].value;
1265 query = query + "&limit=" + param_escape(limit);
1266 }
1267
1268 xmlhttp.open("GET", query, true);
c6232e43
AD
1269 xmlhttp.onreadystatechange=feed_browser_callback;
1270 xmlhttp.send(null);
c6232e43
AD
1271}
1272
c2b2aee0 1273function browserToggleExpand(id) {
c6232e43
AD
1274 try {
1275/* if (feed_to_expand && feed_to_expand != id) {
1276 var d = document.getElementById("BRDET-" + feed_to_expand);
1277 d.style.display = "none";
1278 } */
c2b2aee0 1279
ff725e9b
AD
1280 if (!xmlhttp_ready(xmlhttp)) {
1281 printLockingError();
1282 return
1283 }
1284
c2b2aee0
AD
1285 var d = document.getElementById("BRDET-" + id);
1286
1287 if (d.style.display == "block") {
1288 d.style.display = "none";
1289
1290 } else {
c6232e43 1291
c2b2aee0 1292 feed_to_expand = id;
c6232e43 1293
ff725e9b
AD
1294 d.style.display = "block";
1295 d.innerHTML = "Loading, please wait...";
1296
c2b2aee0
AD
1297 xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
1298 + param_escape(id), true);
1299 xmlhttp.onreadystatechange=expand_feed_callback;
1300 xmlhttp.send(null);
1301 }
c6232e43
AD
1302
1303 } catch (e) {
1304 exception_error("browserExpand", e);
1305 }
1306}
64dc5976
AD
1307
1308function validateNewPassword(form) {
1309 if (form.OLD_PASSWORD.value == "") {
88103301 1310 alert("Old password cannot be blank");
64dc5976
AD
1311 return false;
1312 }
1313 if (form.NEW_PASSWORD.value == "") {
1314 alert("New password cannot be blank");
1315 return false;
1316 }
1317 return true;
1318}
ce3bf408
AD
1319
1320function selectPrefRows(kind, select) {
1321
1322 if (kind) {
1323 var opbarid = false;
1324 var nchk = false;
1325 var nrow = false;
1326 var lname = false;
1327
1328 if (kind == "feed") {
1329 opbarid = "feedOpToolbar";
1330 nrow = "FEEDR-";
1331 nchk = "FRCHK-";
1332 lname = "prefFeedList";
1333 } else if (kind == "fcat") {
1334 opbarid = "catOpToolbar";
1335 nrow = "FCATR-";
1336 nchk = "FCHK-";
1337 lname = "prefFeedCatList";
1338 } else if (kind == "filter") {
1339 opbarid = "filterOpToolbar";
1340 nrow = "FILRR-";
1341 nchk = "FICHK-";
1342 lname = "prefFilterList";
1343 } else if (kind == "label") {
1344 opbarid = "labelOpToolbar";
1345 nrow = "LILRR-";
1346 nchk = "LCHK-";
1347 lname = "prefLabelList";
1348 } else if (kind == "user") {
1349 opbarid = "userOpToolbar";
1350 nrow = "UMRR-";
1351 nchk = "UMCHK-";
1352 lname = "prefUserList";
1353 }
1354
1355 if (opbarid) {
1356 selectTableRowsByIdPrefix(lname, nrow, nchk, select);
1357 disableContainerChildren(opbarid, !select);
1358 }
1359
1360 }
1361}
1362
1363
1364function toggleSelectPrefRow(sender, kind) {
1365
1366 toggleSelectRow(sender);
1367
1368 if (kind) {
1369 var opbarid = false;
1370 var nsel = -1;
1371
1372 if (kind == "feed") {
1373 opbarid = "feedOpToolbar";
1374 nsel = getSelectedFeeds();
1375 } else if (kind == "fcat") {
1376 opbarid = "catOpToolbar";
1377 nsel = getSelectedFeedCats();
1378 } else if (kind == "filter") {
1379 opbarid = "filterOpToolbar";
1380 nsel = getSelectedFilters();
1381 } else if (kind == "label") {
1382 opbarid = "labelOpToolbar";
1383 nsel = getSelectedLabels();
1384 } else if (kind == "user") {
1385 opbarid = "userOpToolbar";
1386 nsel = getSelectedUsers();
1387 }
1388
1389 if (opbarid && nsel != -1) {
1390 disableContainerChildren(opbarid, nsel == false);
1391 }
1392
1393 }
1394}
1395
c0ae0fdb
AD
1396function toggleSelectFBListRow(sender) {
1397 toggleSelectListRow(sender);
1398 disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
1399}