-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.php
1633 lines (1418 loc) · 56.8 KB
/
javascript.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (count(get_included_files()) == 1) {header('location: http://' . $_SERVER['HTTP_HOST']); exit();}
echo '
<script nonce="' . $GLOBALS['nonce'] . '">
var page = "' . $page . '";
var module = "' . $module . '";
var submodule = "' . $submodule . '";
var submit = "' . $submit_js . '";
document.addEventListener("DOMContentLoaded", function()
{
var mail_to_links = document.getElementsByClassName("mail_to_link");
for (i = 0; i < mail_to_links.length; i++)
{
var email = mail_to_links[i].innerHTML;
split1 = email.split("[at]");
split1 = split1.map(e => e.trim());
split2 = split1[1].split("[dot]");
split2 = split2.map(e => e.trim());
email = split1[0] + "@" + split2[0] + "." + split2[1];
mail_to_links[i].innerHTML = "<a href=\"mail" + "to:" + email + "\">" + email + "</a>";
}
var form_buttons = document.getElementsByClassName("form_button");
for (i = 0; i < form_buttons.length; i++)
{
(function()
{
var button_value = form_buttons[i].value;
form_buttons[i].addEventListener("click", function(event) { submit_clicked = button_value; });
})();
}
});
function email_check(email)
{
var AtSym = email.value.indexOf("@");
var Period = email.value.lastIndexOf(".");
var Space = email.value.indexOf(" ");
var Length = email.value.length - 1;
if (AtSym < 1 || Period <= AtSym + 1 || Period == Length || Space != -1) {alert("ERROR: Invalid email address\n\n" + email.value); return false;}
return true;
}
function password_check(password)
{
var password_length_min = ' . $password_length_min . ';
var password_length_max = ' . $password_length_max . ';
if (password.value.length < password_length_min || password.value.length > password_length_max) {alert("ERROR: Passwords must be " + password_length_min + "-" + password_length_max + " characters"); return false;}
if (password.value.indexOf(" ") >= 0) {alert("ERROR: Passwords cannot contain spaces"); return false;}
return true;
}
function disable_submit(arg)
{
// this must be triggered by "submit" (not "click") or else the form will not be submitted
var form_name = document.getElementById(arg).form.name;
var input_submit = document.createElement("input");
input_submit.setAttribute("type", "hidden");
input_submit.setAttribute("id", arg + "_hidden");
input_submit.setAttribute("name", "submit");
input_submit.setAttribute("value", submit_clicked);
document.getElementById(form_name).appendChild(input_submit);
var input_hash = document.createElement("input");
input_hash.setAttribute("type", "hidden");
input_hash.setAttribute("id", arg + "_hash");
input_hash.setAttribute("name", "form_hash");
input_hash.setAttribute("value", "' . $_SESSION['csrf_token'] . '");
document.getElementById(form_name).appendChild(input_hash);
var button_value = "please wait...";
document.getElementById(arg).disabled = true;
document.getElementById(arg).value = button_value;
document.getElementById(arg).textContent = button_value;
}
function event_listener(eventName, onElement, event_object)
{
document.addEventListener("DOMContentLoaded", function()
{
if (document.getElementById(onElement))
{
document.getElementById(onElement).addEventListener(eventName, event_object);
}
});
}
';
if ($display_login || $page == 'install')
{
echo '
function form_login_check()
{
var form_check = true;
var error = "";
document.getElementById("login_email").value = document.getElementById("login_email").value.trim();
if (document.getElementById("login_email").value == "")
{
document.getElementById("login_email").className = "error";
document.getElementById("label_login_email").className = "error";
error += "Please enter your email address.\n";
form_check = false;
}
else
{
document.getElementById("login_email").className = "";
document.getElementById("label_login_email").className = "";
}
if (document.getElementById("login_password").value == "")
{
document.getElementById("login_password").className = "error";
document.getElementById("label_login_password").className = "error";
error += "Please enter your password.";
form_check = false;
}
else
{
document.getElementById("login_password").className = "";
document.getElementById("label_login_password").className = "";
}
if (!form_check)
{
alert(error);
return false;
}
if (!email_check(document.getElementById("login_email")))
{
document.getElementById("login_email").className = "error";
document.getElementById("label_login_email").className = "error";
return false;
}
if (!password_check(document.getElementById("login_password")))
{
document.getElementById("login_password").className = "error";
document.getElementById("label_login_password").className = "error";
return false;
}
disable_submit("form_login_submit");
return true;
}
event_listener("submit", "form_login", function(event) { if (!form_login_check()) {event.preventDefault();} });
';
}
if ($page == 'install')
{
echo '
function form_install_check()
{
var form_check = true;
var error = "ERROR: Required fields missing";
for (i = 0; i < document.getElementById("form_install").length; i++)
{
id = document.getElementById("form_install").elements[i].id;
if (document.getElementById(id).name != "config_db[password]" && document.getElementById(id).name != "config_db[port]" && !document.getElementById(id).value)
{
document.getElementById(id).className = "error";
document.getElementById("label_" + id).className = "error";
form_check = false;
}
else if (document.getElementById(id).type == "text" || document.getElementById(id).type == "password")
{
document.getElementById(id).className = "";
document.getElementById("label_" + id).className = "";
}
}
if (!form_check)
{
alert(error);
return false;
}
if (document.getElementById("admin_email") && document.getElementById("admin_password"))
{
document.getElementById("admin_email").value = document.getElementById("admin_email").value.trim();
if (!email_check(document.getElementById("admin_email")))
{
document.getElementById("admin_email").className = "error";
document.getElementById("label_admin_email").className = "error";
return false;
}
if (!password_check(document.getElementById("admin_password")))
{
document.getElementById("admin_password").className = "error";
document.getElementById("label_admin_password").className = "error";
return false;
}
}
disable_submit("form_install_submit");
return true;
}
event_listener("submit", "form_install", function(event) { if (!form_install_check()) {event.preventDefault();} });
';
}
if ($page == 'help')
{
echo '
function form_reset_check()
{
document.getElementById("reset_email").value = document.getElementById("reset_email").value.trim();
if (!document.getElementById("reset_email").value)
{
document.getElementById("reset_email").className = "error";
document.getElementById("label_reset_email").className = "error";
alert("ERROR: Please enter email address");
return false;
}
else
{
if (!email_check(document.getElementById("reset_email")))
{
document.getElementById("reset_email").className = "error";
document.getElementById("label_reset_email").className = "error";
return false;
}
}
disable_submit("form_reset_submit");
return true;
}
event_listener("submit", "form_reset", function(event) { if (!form_reset_check()) {event.preventDefault();} });
';
}
if ($page == 'login' && isset($_SESSION['contact_reset'])) // needed here before $continue = false
{
echo '
function form_new_password_check()
{
var form_check = true;
var error = "";
if (!document.getElementById("password").value)
{
document.getElementById("password").className = "error";
document.getElementById("label_password").className = "error";
error += "ERROR: Please enter new password\n"
form_check = false;
}
else
{
document.getElementById("password").className = "";
document.getElementById("label_password").className = "";
}
if (!document.getElementById("password2").value)
{
document.getElementById("password2").className = "error";
document.getElementById("label_password2").className = "error";
error += "ERROR: Please confirm new password\n"
form_check = false;
}
else
{
document.getElementById("password2").className = "";
document.getElementById("label_password2").className = "";
}
if (!form_check)
{
alert(error);
return false;
}
if (document.getElementById("password").value && document.getElementById("password2").value)
{
if (!password_check(document.getElementById("password")))
{
document.getElementById("password").className = "error";
document.getElementById("label_password").className = "error";
return false;
}
if (!password_check(document.getElementById("password2")))
{
document.getElementById("password2").className = "error";
document.getElementById("label_password2").className = "error";
return false;
}
if (document.getElementById("password").value != document.getElementById("password2").value)
{
document.getElementById("password").className = "error";
document.getElementById("label_password").className = "error";
document.getElementById("password2").className = "error";
document.getElementById("label_password2").className = "error";
alert("ERROR: Passwords do not match");
return false;
}
}
disable_submit("form_new_password_submit");
return true;
}
event_listener("submit", "form_new_password", function(event) { if (!form_new_password_check()) {event.preventDefault();} });
';
}
if ($continue)
{
if ($page == 'home' || ($page == 'login' && ($module == 'submit' || $module == 'update' || $module == 'pay_submission')))
{
echo '
function form_main_check()
{
if (submit_clicked == "cancel")
{
document.getElementById("form_main").action = "' . $_SERVER['PHP_SELF'] . '?page=login&module=account";
return true;
}
var form_check = true;
var error = "ERROR: Required fields missing or incomplete:\n\n";
var fields = new Object();
';
if ($page == 'home' || ($page == 'login' && $module == 'submit'))
{
// only echo file validation if it's the first time hitting submit, otherwise "file" will always have to be revalidated
if (isset($_SESSION['file_upload']['filename']) || isset($_FILES['file']['name'])) {$fields['file']['required'] = '';}
}
if ($page == 'login' && $module == 'update')
{
$fields['password']['required'] = '';
$fields['password2']['required'] = '';
}
// build the fields object
foreach ($fields as $key => $value)
{
$value = array_map('json_encode', $value);
echo 'fields["' . $key . '"] = {name: ' . $value['name'] . ', type: ' . $value['type'] . ', required: ' . $value['required'] . '};' . "\n";
}
echo '
if (document.getElementById("country"))
{
if (document.getElementById("country").value == "USA")
{
if (document.getElementById("state")) {fields["state"]["required"] = "Y";}
if (document.getElementById("zip")) {fields["zip"]["required"] = "Y";}
}
else
{
if (document.getElementById("state")) {fields["state"]["required"] = "";}
if (document.getElementById("zip")) {fields["zip"]["required"] = "";}
}
}
if (typeof price != "undefined" && typeof show_payment_fields != "undefined")
{
if (price && show_payment_fields)
{
fields["cc_number"]["required"] = "Y";
fields["cc_exp_month"]["required"] = "Y";
fields["cc_exp_year"]["required"] = "Y";
fields["cc_csc"]["required"] = "Y";
}
else
{
fields["cc_number"]["required"] = "";
fields["cc_exp_month"]["required"] = "";
fields["cc_exp_year"]["required"] = "";
fields["cc_csc"]["required"] = "";
}
}
for (var key in fields)
{
if (document.getElementById(key) && document.getElementById(key).name != "password" && document.getElementById(key).name != "password2" && document.getElementById(key).name != "file") {document.getElementById(key).value = document.getElementById(key).value.trim();}
if (document.getElementById(key) && !document.getElementById(key).value && fields[key]["required"])
{
document.getElementById(key).className = "error";
document.getElementById("label_" + key).className = "error";
error += fields[key]["name"] + "\n";
form_check = false;
}
else if (document.getElementById(key))
{
document.getElementById(key).className = "";
document.getElementById("label_" + key).className = "";
}
}
if (!form_check)
{
alert(error);
return false;
}
if (document.getElementById("email") && document.getElementById("email").value && !email_check(document.getElementById("email")))
{
document.getElementById("email").className = "error";
document.getElementById("label_email").className = "error";
return false;
}
if (document.getElementById("password") && document.getElementById("password").value && !password_check(document.getElementById("password")))
{
document.getElementById("password").className = "error";
document.getElementById("label_password").className = "error";
return false;
}
if (document.getElementById("password2") && document.getElementById("password2").value && !password_check(document.getElementById("password2")))
{
document.getElementById("password2").className = "error";
document.getElementById("label_password2").className = "error";
return false;
}
if (document.getElementById("password") && document.getElementById("password2") && document.getElementById("password").value != document.getElementById("password2").value)
{
document.getElementById("password").className = "error";
document.getElementById("password2").className = "error";
document.getElementById("label_password").className = "error";
document.getElementById("label_password2").className = "error";
alert("ERROR: Passwords do not match");
return false;
}
if (document.getElementById("country") && document.getElementById("country").value == "USA")
{
if (document.getElementById("zip")) {document.getElementById("zip").value = document.getElementById("zip").value.replace(/[^0-9]/g, "");}
if (document.getElementById("zip") && document.getElementById("zip").value.length < 5)
{
document.getElementById("zip").className = "error";
document.getElementById("label_zip").className = "error";
alert("ERROR: Incomplete zip code");
return false;
}
}
if (document.getElementById("cc_exp_month") && document.getElementById("cc_exp_year"))
{
var cc_exp_year = parseInt(document.getElementById("cc_exp_year").value);
var cc_exp_month = parseInt(document.getElementById("cc_exp_month").value) - 1;
var cc_exp_date = new Date(cc_exp_year, cc_exp_month);
var current_date = new Date();
if (cc_exp_date < current_date)
{
document.getElementById("cc_exp_year").className = "error";
document.getElementById("cc_exp_month").className = "error";
document.getElementById("label_cc_exp_year").className = "error";
document.getElementById("label_cc_exp_month").className = "error";
alert("ERROR: Expiration Date entered indicates that your credit card has expired.");
return false;
}
}
disable_submit("form_main_submit");
return true;
}
event_listener("submit", "form_main", function(event) { if (!form_main_check()) {event.preventDefault();} });
function form_confirmation_check()
{
';
if (isset($use_captcha) && $use_captcha && isset($captcha_version) && $captcha_version == 2 && $submit == 'submit' && ($page == 'home' || ($page == 'login' && $module == 'submit')))
{
echo '
var captcha_response = grecaptcha.getResponse();
if (captcha_response.length == 0)
{
document.getElementById("g-recaptcha").style = "border: 2px solid red;";
alert("ERROR: Please verify that you are not a robot.");
return false;
}
else
{
disable_submit("form_confirmation_submit");
return true;
}
';
}
else
{
echo '
disable_submit("form_confirmation_submit");
return true;
';
}
echo '
}
event_listener("submit", "form_confirmation", function(event) { if (!form_confirmation_check()) {event.preventDefault();} });
event_listener("click", "form_main_show", function(event) { document.getElementById("form_main").style.display = "block"; event.preventDefault(); });
window.addEventListener("load", function() { if (document.getElementById("form_confirmation")) {document.getElementById("form_main").style.display = "none";} });
';
}
if ($page == 'home' || ($page == 'login' && $module == 'submit' || $module == 'pay_submission'))
{
if (isset($fields['comments']['maxlength']) && $fields['comments']['maxlength'])
{
echo '
function comments_limit()
{
if (document.getElementById("comments").value.length >= ' . $fields['comments']['maxlength'] . ') {alert("' . $fields['comments']['name'] . ' can only be ' . $fields['comments']['maxlength'] . ' characters long");}
}
event_listener("input", "comments", function(event) { comments_limit(); });
';
}
echo '
function cc_display()
{
var genres = new Object();
price = 0;
show_payment_fields = false;
';
if ($config['redirect_url'] && $config['submission_price'])
{
echo 'price = ' . $config['submission_price'] . ';' . "\n";
}
if (isset($fields['genre_id']['enabled']) && $fields['genre_id']['enabled'] && isset($genres['price']) && $genres['price'])
{
foreach ($genres['price'] as $value)
{
if ($genres['all'][$value]['redirect_url']) {$genre_url = $genres['all'][$value]['redirect_url'];} else {$genre_url = '';}
if ((float) $genres['all'][$value]['price']) {$genre_price = $genres['all'][$value]['price'];} else {$genre_price = 0.00;} // string "0.00" returns TRUE. cannot be empty string. must be zero decimal/float.
echo 'genres[' . $value . '] = {url: "' . $genre_url . '", price: ' . $genre_price . '};' . "\n";
}
}
if ($config['show_payment_fields'])
{
echo 'show_payment_fields = true;' . "\n";
}
if ($module == 'pay_submission')
{
if (isset($price) && (float) $price) {echo 'price = ' . $price . ';' . "\n";}
}
else
{
if (isset($fields['genre_id']['enabled']) && $fields['genre_id']['enabled'] && isset($genres['price']) && $genres['price'])
{
echo '
if (document.getElementById("genre_id"))
{
var selected_genre = document.getElementById("genre_id").value;
if (genres[selected_genre] && typeof genres[selected_genre]["url"] != "undefined" && typeof genres[selected_genre]["price"] != "undefined") {price = genres[selected_genre]["price"];}
}
';
}
}
echo '
if (price && show_payment_fields)
{
document.getElementById("header_payment").style.display = "";
document.getElementById("row_cc_number").style.display = "";
document.getElementById("row_cc_exp_month").style.display = "";
document.getElementById("row_cc_exp_year").style.display = "";
document.getElementById("row_cc_csc").style.display = "";
document.getElementById("cc_number").disabled = false;
document.getElementById("cc_exp_month").disabled = false;
document.getElementById("cc_exp_year").disabled = false;
document.getElementById("cc_csc").disabled = false;
document.getElementById("price_display").textContent = price.toFixed(2);
}
else
{
document.getElementById("header_payment").style.display = "none";
document.getElementById("row_cc_number").style.display = "none";
document.getElementById("row_cc_exp_month").style.display = "none";
document.getElementById("row_cc_exp_year").style.display = "none";
document.getElementById("row_cc_csc").style.display = "none";
document.getElementById("cc_number").disabled = true;
document.getElementById("cc_exp_month").disabled = true;
document.getElementById("cc_exp_year").disabled = true;
document.getElementById("cc_csc").disabled = true;
}
}
document.addEventListener("DOMContentLoaded", function()
{
if (document.getElementById("cc_number"))
{
cc_display();
if (document.getElementById("genre_id")) {document.getElementById("genre_id").addEventListener("change", function(event) { cc_display(); });}
}
});
';
}
if ($page == 'login')
{
echo '
function confirm_prompt(action, name, value)
{
var confirm_display = "CONFIRM: Are you sure you wish to " + action;
if (typeof name != "undefined") {confirm_display += " " + name;}
if (typeof value != "undefined")
{
if (isNaN(value)) {confirm_display += " " + value;} else {confirm_display += " #" + value;}
}
confirm_display += "?";
if (name == "genre") {confirm_display += "\n" + "All submissions tied to this genre will have now be under \"no genre\".";}
if (name == "payment variable presets") {confirm_display += "\n" + "WARNING: This will delete your current payment variables.";}
if (name == "sample data") {confirm_display += "\n" + "This will delete all @example.com contacts as well as all related submissions, actions, and files.";}
if (action == "reset") {confirm_display += "\n" + "WARNING: This will reset all " + name + " settings back the their defaults values." + "\n" + "All custom settings will be lost.";}
var confirmed = confirm(confirm_display);
if (confirmed) {return true;} else {return false;}
}
';
if (in_array($module, $modules_admin))
{
echo '
event_listener("change", "module", function(event) { document.getElementById("form_nav").submit(); });
// this function is needed because these form buttons will otherwise never get disabled as there are no form check functions
function form_submit(arg)
{
if (typeof submit_clicked == "undefined" || submit_clicked == "cancel") {return true;}
if (arg == "submissions")
{
if (submit_clicked == "send") {disable_submit("submit_send");}
if (submit_clicked == "confirm") {disable_submit("submit_confirm");}
}
if (arg == "contacts")
{
if (submit_clicked == "delete") {disable_submit("submit_contacts2");}
if (submit_clicked == "continue") {disable_submit("submit_continue");}
}
if (arg == "configuration")
{
if (submit_clicked == "update") {disable_submit("submit_update");}
if (submit_clicked == "reset defaults") {disable_submit("submit_reset_defaults");}
}
if (arg == "maintenance")
{
if (submit_clicked == "delete temp files") {disable_submit("submit_delete");}
if (submit_clicked == "insert sample data") {disable_submit("submit_insert_sample_data");}
if (submit_clicked == "delete sample data") {disable_submit("submit_delete_sample_data");}
if (submit_clicked == "purge") {disable_submit("submit_purge");}
if (submit_clicked == "test mail") {disable_submit("submit_test_mail");}
if (submit_clicked == "update data structure") {disable_submit("submit_update_data_structure");}
}
}
event_listener("submit", "form_" + module, function(event) { form_submit(module); });
';
}
if ($module == 'account' || $module == 'submissions' || $module == 'maintenance')
{
echo '
function lightbox(on_off, src, width, height, left, top)
{
if (on_off == "on")
{
document.getElementById("background").style.display = "block";
document.getElementById("foreground").style.display = "flex";
document.getElementById("popframe").src = src;
if (left) {document.getElementById("foreground").style.left = left + "px";}
if (top) {document.getElementById("foreground").style.top = top + "px";}
document.getElementById("popframe").addEventListener("load", function()
{
document.getElementById("popframe").style.minWidth = "auto";
document.getElementById("popframe").style.minHeight = "auto";
if (width) {document.getElementById("popframe").style.minWidth = width + "px";} else {document.getElementById("popframe").style.minWidth = (document.getElementById("popframe").contentWindow.document.body.scrollWidth + 80) + "px";}
if (height) {document.getElementById("popframe").style.minHeight = height + "px";} else {document.getElementById("popframe").style.minHeight = (document.getElementById("popframe").contentWindow.document.body.scrollHeight + 10) + "px";}
});
}
if (on_off == "off")
{
document.getElementById("background").style.display = "none";
document.getElementById("foreground").style.display = "none";
document.getElementById("foreground").style.width = "auto";
document.getElementById("foreground").style.height = "auto";
}
}
event_listener("click", "lightbox_off", function(event) { lightbox("off"); event.preventDefault(); });
event_listener("click", "background", function(event) { lightbox("off"); });
';
}
if ($module == 'submissions')
{
echo '
function form_tag_check()
{
if (!document.getElementById("tag_action_type_id").value)
{
document.getElementById("tag_action_type_id").className = "error";
document.getElementById("label_tag_action_type_id").className = "error";
alert("ERROR: Missing tag action type");
return false;
}
else
{
document.getElementById("tag_action_type_id").className = "";
document.getElementById("label_tag_action_type_id").className = "";
}
var action_text = document.getElementById("tag_action_type_id").options[document.getElementById("tag_action_type_id").selectedIndex].text;
if (action_text.indexOf("forward") >= 0 && !document.getElementById("tag_receiver_id").value)
{
document.getElementById("tag_receiver_id").className = "error";
document.getElementById("label_tag_receiver_id").className = "error";
alert("ERROR: Missing tag receiver (action type forward requires receiver)");
return false;
}
else
{
document.getElementById("tag_receiver_id").className = "";
document.getElementById("label_tag_receiver_id").className = "";
}
var checked = false;
for (i = 0; i < document.getElementById("form_submissions").length; i++)
{
if (document.getElementById("form_submissions").elements[i].name == "tag[]" && document.getElementById("form_submissions").elements[i].checked)
{
checked = true;
break;
}
}
if (!checked) {alert("ERROR: No submissions tagged"); return false;}
return true;
}
event_listener("click", "submit_apply_to_tagged", function(event) { if (!form_tag_check()) {event.preventDefault();} });
function tag_all(arg)
{
var i_tag = 1;
var tag_checked_count = 0;
for (i = 0; i < document.getElementById("form_submissions").length; i++)
{
if (document.getElementById("form_submissions").elements[i].name == "tag[]")
{
// must use incrementing integer for shift click to work
// submission_id = document.getElementById("form_submissions").elements[i].value;
if (arg == "tag")
{
document.getElementById("check_" + i_tag).checked = true;
document.getElementById("tr_" + i_tag).style.backgroundColor = "' . $config['color_foreground'] . '";
tag_checked_count++;
}
if (arg == "untag")
{
document.getElementById("check_" + i_tag).checked = false;
document.getElementById("tr_" + i_tag).style.backgroundColor = "";
}
i_tag++;
}
}
document.getElementById("checked_count").textContent = tag_checked_count;
}
document.addEventListener("DOMContentLoaded", function()
{
var tag_alls = document.getElementsByClassName("tag_all");
for (i = 0; i < tag_alls.length; i++)
{
(function()
{
var action = tag_alls[i].href.split("#").pop();
tag_alls[i].addEventListener("click", function(event) { tag_all(action); event.preventDefault(); });
})();
}
if (tag_alls.length)
{
if (submit == "apply to tagged") {tag_all("tag");}
if (submit == "cancel") {tag_all("untag");}
}
});
function tag_checked_count()
{
var tag_checked_count = 0;
for (i = 0; i < document.getElementById("form_submissions").length; i++)
{
if (document.getElementById("form_submissions").elements[i].name == "tag[]" && document.getElementById("form_submissions").elements[i].checked) {tag_checked_count++;}
}
document.getElementById("checked_count").textContent = tag_checked_count;
}
function change_row_color(i)
{
if (document.getElementById("check_" + i).checked)
{
document.getElementById("tr_" + i).style.backgroundColor = "' . $config['color_foreground'] . '";
}
else
{
document.getElementById("tr_" + i).style.backgroundColor = "";
}
}
var oldInp = 0;
function clickage(evt)
{
evt = (evt)?evt:event;
var target = (evt.target)?evt.target:evt.srcElement;
if (!evt.shiftKey)
{
oldInp = target.id.split("_").pop();
return false;
}
target.checked = 1;
var low = Math.min(target.id.split("_").pop(), oldInp);
var high = Math.max(target.id.split("_").pop(), oldInp);
var uncheck = 1;
for (var i = low; i <= high; i++)
{
uncheck &= document.getElementById("check_" + i).checked;
document.getElementById("check_" + i).checked = 1;
change_row_color(i);
}
if (uncheck)
{
for (i = low; i <= high; i++)
{
document.getElementById("check_" + i).checked = 0;
change_row_color(i);
}
}
return true;
}
function form_action_check()
{
if (!document.getElementById("new_action_type_id").value)
{
document.getElementById("new_action_type_id").className = "error";
document.getElementById("label_new_action_type_id").className = "error";
alert("ERROR: Missing new action type");
return false;
}
else
{
document.getElementById("new_action_type_id").className = "";
document.getElementById("label_new_action_type_id").className = "";
}
var action_text = document.getElementById("new_action_type_id").options[document.getElementById("new_action_type_id").selectedIndex].text;
if (action_text.indexOf("forward") >= 0 && !document.getElementById("new_receiver_id").value)
{
document.getElementById("new_receiver_id").className = "error";
document.getElementById("label_new_receiver_id").className = "error";
alert("ERROR: Missing new receiver (action forward requires receiver)");
return false;
}
else
{
document.getElementById("new_receiver_id").className = "";
document.getElementById("label_new_receiver_id").className = "";
}
return true;
}
event_listener("click", "submit_preview", function(event) { if (!form_action_check()) {event.preventDefault();} });
event_listener("mouseover", "tag_action_td", function(event) { tooltip_show(action_tooltip, tag_action_td, event, 400); });
event_listener("mouseout", "tag_action_td", function(event) { tooltip_hide(); });
function enable_disable()
{
// for search
if (document.getElementById("search_action_type_id"))
{
var action_text = document.getElementById("search_action_type_id").options[document.getElementById("search_action_type_id").selectedIndex].text;
if (action_text.indexOf("forward") >= 0)
{
document.getElementById("search_receiver_id").disabled = false;
document.getElementById("search_receiver_id").options[0].text = "anyone";
}
else
{
document.getElementById("search_receiver_id").disabled = true;
document.getElementById("search_receiver_id").options[0].selected = true;
document.getElementById("search_receiver_id").options[0].text = "only for forwards";
}
}
// for tag
if (document.getElementById("tag_action_type_id"))
{
var action_text = document.getElementById("tag_action_type_id").options[document.getElementById("tag_action_type_id").selectedIndex].text;
if (action_text.indexOf("forward") >= 0)
{
document.getElementById("tag_receiver_id").disabled = false;
document.getElementById("tag_receiver_id").options[0].text = "";
}
else
{
document.getElementById("tag_receiver_id").disabled = true;
document.getElementById("tag_receiver_id").options[0].selected = true;
document.getElementById("tag_receiver_id").options[0].text = "only for forwards";
}
}
// for new action
if (document.getElementById("new_action_type_id"))
{
var action_text = document.getElementById("new_action_type_id").options[document.getElementById("new_action_type_id").selectedIndex].text;
if (action_text.indexOf("forward") >= 0)
{
document.getElementById("new_receiver_id").disabled = false;
document.getElementById("new_receiver_id").options[0].text = "";
}
else
{
document.getElementById("new_receiver_id").disabled = true;
document.getElementById("new_receiver_id").options[0].selected = true;
document.getElementById("new_receiver_id").options[0].text = "only for forwards";
}
';
if ($action_types)
{
foreach ($action_types['all'] as $key => $value)
{
if (strpos($value['body'], '[message]') !== false) {$message_bodies[] = $key;}
}
}
if (isset($message_bodies))
{
echo '
var message_bodies = new Array(' . implode(',', $message_bodies) . ');
var message_warning = "only for message actions";
var message_enable = false;
for (i = 0; i < message_bodies.length; i++)
{
if (message_bodies[i] == parseInt(document.getElementById("new_action_type_id").value))
{
message_enable = true;
break;
}
}
if (message_enable)
{