forked from nodesman/wp-autoresponder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms.php
1363 lines (964 loc) · 33.3 KB
/
forms.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
include "forms.lib.php";
function wpr_subscriptionforms()
{
if (_wpr_no_newsletters("To create subscription forms"))
return;
switch ($_GET['action'])
{
case 'create':
_wpr_subscriptionforms_create();
break;
case 'form':
$id = $_GET['fid'];
$form = _wpr_subscriptionform_get($id);
_wpr_subscriptionform_getcode($form,"'".$form->name."' Form HTML Code");
return;
break;
case 'delete':
if (isset($_POST['forms']))
{
$formsToDelete = $_POST['forms'];
if (count($formsToDelete) >0)
{
_wpr_subscriptionforms_delete($formsToDelete);
_wpr_subscriptionform_delete_done();
}
else
{
_wpr_subscriptionform_delete_notfound();
}
}
else
{
_wpr_subscriptionform_delete_notfound();
}
break;
case 'edit':
$id = (int) $_GET['fid'];
do_action("_wpr_subscriptionform_edit_form_controller",$id);
$form = _wpr_subscriptionform_get($id);
if (isset($_POST['fid']))
{
$checkList = array("name"=>"Name field is required","confirm_subject"=>"E-Mail Confirmation Subject Field is required","confirm_body"=>"E-Mail Confirmation Body field","confirmed_subject"=>"Confirmed Subscription subject field is required","confirmed_body"=>"Confirmed subscription body field is required");
$errors = array();
foreach ($checkList as $field=>$errorMessage)
{
$theValue = $_POST[$field];
$theValue = trim($theValue);
if (empty($theValue))
{
$errors[] = $checkList[$field];
}
}
$errors = apply_filters("_wpr_subscriptionform_edit_handler_validate",$errors);
if (count($errors) == 0)
{
$info['id'] = $_GET['fid'];
$info['name'] = $_POST['name'];
$info['return_url'] = $_POST['return_url'];
if (preg_match("@autoresponder_[0-9]+@",$_POST['followup']))
{
$followup = "autoresponder";
$followupid = str_replace("autoresponder_","",$_POST['followup']);
}
else if (preg_match("@postseries_[0-9]+@",$_POST['followup']))
{
$followup = "postseries";
$followupid = str_replace("postseries_","",$_POST['followup']);
}
else
{
$followup = "none";
$followupid = 0;
}
$info['followup_type'] = $followup;
$info['followup_id'] = $followupid;
switch ($_POST['blogsubscription'])
{
case 'none':
case 'all':
$blogSubscription = $_POST['blogsubscription'];
break;
default:
if (preg_match("@category_[0-9]+@",$_POST['blogsubscription']))
{
$blogSubscription = "cat";
$blogCategory = str_replace("category_","",$_POST['blogsubscription']);
}
}
$info['blogsubscription_type'] = $blogSubscription;
$info['blogsubscription_id'] = $blogCategory;
$info['submit_button'] = $_POST['submit_value'];
$info['custom_fields'] = (isset($_POST['custom_fields']) && is_array($_POST['custom_fields']))?implode(",",$_POST['custom_fields']):"";
$info['confirm_subject'] = $_POST['confirm_subject'];
$info['confirm_body'] = $_POST['confirm_body'];
$info['nid'] = $_POST['newsletter'];
$info['confirmed_subject'] = $_POST['confirmed_subject'];
$info['confirmed_body'] = $_POST['confirmed_body'];
_wpr_subscriptionform_update($info);
do_action("_wpr_subscriptionform_edit_handler_save",$info['id']);
$form = _wpr_subscriptionform_get($info['id']);
_wpr_subscriptionform_getcode($form,"Form Saved");
return;
}
else
$form = (object) $_POST;
}
_wpr_subscriptionform_form($form,$errors);
break;
default:
_wpr_subscriptionforms_list();
}
}
function _wpr_subscriptionform_delete_notfound()
{
?>
<div class="wrap">
<h2>Invalid Input: No forms were specified.</h2>
Did you visit this page directly? Click on the button below to go to the subscription forms list.<br />
<input type="button" onclick="window.location='admin.php?page=wpresponder/subscriptionforms.php';" class="button-primary" value="« Back To Subscription Forms List">
</div>
<?php
}
function _wpr_subscriptionform_delete_done()
{
?>
<div class="wrap">
<h2>The Selected Subscription Forms Have Been Deleted</h2>
<br />
<br />
<a href="admin.php?page=wpresponder/subscriptionforms.php" class="button-primary">« Back To Subscription Forms List</a> </div>
<?php
}
function _wpr_subscriptionforms_delete($list)
{
global $wpdb;
$formItems = implode(",",$list);
$formItems = "($formItems)";
$query = "DELETE FROM ".$wpdb->prefix."wpr_subscription_form where id in $formItems;";
$wpdb->query($query);
}
function _wpr_subscriptionforms_list()
{
global $wpdb;
$tprefix = $wpdb->prefix;
$query = "SELECT a.* FROM ".$tprefix."wpr_subscription_form a, ".$tprefix."wpr_newsletters b where a.nid=b.id;";
$forms = $wpdb->get_results($query);
?>
<div class="wrap">
<h2>Subscription Forms</h2>
</div>
<script>
function selectAllFormsCheckBox(state)
{
jQuery(".forms_check").attr({ checked: state});
}
</script>
<ul style="padding:20px;">
<li>Click on <em>Create New Form</em> button below to create a new subscription form. To place the newly created subscription form in the sidebar of your blog, go to the <a href="widgets.php">Widgets section</a>. To place the subscription form in a separate page or another website, copy the generated HTML code for the form and paste the code it in your own HTML page.
</ul>
<form name="formslist" action="admin.php?page=wpresponder/subscriptionforms.php&action=delete" method="post">
<table class="widefat" style="margin: 10px; margin:10px 0px;;">
<thead> <tr>
<th><input type="checkbox" name="selectall" value="1" onclick="selectAllFormsCheckBox(this.checked);" /></th>
<th scope="col">Name</th>
<th>Newsletter</th>
<th>Follow-Up</th>
<th>Blog Subscription</th>
<th scope="col">Actions</th>
</tr> </thead>
<?php
if (count($forms) > 0 )
{
foreach ($forms as $form)
{
?>
<tr>
<td align="center"width="20"><input type="checkbox" name="forms[]" class="forms_check" value="<?php echo $form->id ?>" /></td>
<td><?php echo $form->name ?></td>
<td><a href="admin.php?page=wpresponder/subscribers.php&action=nmanage&nid=<?php echo $form->nid ?>">
<?php
$newsletter = _wpr_newsletter_get($form->nid);
echo $newsletter->name;
?>
</a></td>
<td><?php
switch ($form->followup_type)
{
case 'postseries':
$postseries = _wpr_postseries_get($form->followup_id);
echo "Subscribe to the '".$postseries->name."' post series";
break;
case 'autoresponder':
$autoresponder = _wpr_autoresponder_get($form->followup_id);
echo "Subscribe to the '".$autoresponder->name."' autoresponder.";
break;
case 'none':
echo "None";
break;
}
?></td>
<td><?php
switch ($form->blogsubscription_type)
{
case 'cat':
$category = get_category($form->blogsubscription_id);
echo "Posts in the ".$category->name." category";
break;
case 'all':
echo "All Blog Posts ";
break;
case 'none':
echo "No blog subscription";
break;
}
?>
<td><a href="admin.php?page=wpresponder/subscriptionforms.php&action=edit&fid=<?php echo $form->id ?>" class="button">Edit</a> <a href="admin.php?page=wpresponder/subscriptionforms.php&action=form&fid=<?php echo $form->id ?>" class="button">Get Form HTML</a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="10"><div align="center"><big>--No subscription forms defined. <a href="admin.php?page=wpresponder/subscriptionforms.php&action=create">Click here</a> to create one now--</big>
</div></td>
</tr>
<?php
}
?>
</td></td>
</table>
<input type="submit" name="submit" value="Delete Forms" class="button" onclick="return confirm('Are you sure you want to delete the selected subscription forms?');" />
<input type="button" onclick="window.location='admin.php?page=wpresponder/subscriptionforms.php&action=create';" class="button" value="Create New Form">
</form>
<?php
}
function _wpr_subscriptionform_getcode($form,$title)
{
?>
<div class="wrap">
<h2><?php echo $title ?></h2>
The form has been saved.
<h3>Now place the subscription form in the sidebar to start gathering subscribers.</h3>
<a href="widgets.php"><img src="<?php echo get_bloginfo("url"); ?>/?wpr-file=widget-help.png" title="Click to go to Widgets Section" border="0"/></a>
<h3>Click on image to go to Widgets Section</h3>
<h2>Alternatively...</h2>
Copy and paste the code in the box below on the page where you want the subscription form to appear.
<h3>Form Code:</h3>
<?php $code = _wpr_subscriptionform_code($form); ?>
<textarea rows="20" cols="70" id="wpr_code"><?php echo $code ?></textarea>
<br />
<div style="display:none" id="preview"> <?php echo $code ?> </div>
<script>
var preview;
function preview()
{
preview = window.open('about:blank','previewWindow','top=20,left=20,width=300,height=500');
preview.document.write(document.getElementById('preview').innerHTML);
}
</script>
<a href="admin.php?page=wpresponder/subscriptionforms.php" class="button">« Back To Forms</a>
<input type="button" value="Select All" onclick="document.getElementById('wpr_code').select();" class="button"/>
<input type="button" onclick="preview();" value="Preview" class="button" />
</div>
<?php
}
function _wpr_subscriptionform_code($form,$enableForm=false)
{
$url = get_bloginfo('home');
ob_start();
?>
<form action="<?php echo $url?>/?wpr-optin=1" method="post">
<span class="wpr-subform-hidden-fields">
<input type="hidden" name="blogsubscription" value="<?php echo $form->blogsubscription_type ?>" />
<?php if ($form->blogsubscription_type == "cat") { ?>
<input type="hidden" name="cat" value="<?php echo $form->blogsubscription_id ?>" />
<?php
}
if (!empty($form->followup_type) && $form->followup_type != "none")
{
?>
<input type="hidden" name="followup" value="<?php echo $form->followup_type ?>" />
<input type="hidden" name="responder" value="<?php echo $form->followup_id ?>" />
<input type="hidden" name="comment" value="" style="display:none" />
<?php
} ?>
<input type="hidden" name="newsletter" value="<?php echo $form->nid ?>" />
<?php if (isset($form->id)) { ?>
<input type="hidden" name="fid" value="<?php echo $form->id ?>" />
<?php } ?>
</span>
<table>
<tr>
<td><span class="wprsfl wprsfl-name">Name:</span></td>
<td><span class="wprsftf wpr-subform-textfield-name">
<input type="text" name="name" /></td>
</tr>
<tr>
<td><span class="wprsfl wprsfl-email">E-Mail Address:</span></td>
<td><span class="wprsftf wpsftf-email">
<input type="text" name="email" />
</span>
</tr>
<?php
if (!empty($form->custom_fields))
{
$formItems = array();
$formItems = explode(",",$form->custom_fields);
foreach ($formItems as $field)
{
$theField = _wpr_newsletter_custom_fields_get($field);
$fieldName = str_replace('"','',$theField->id);
switch ($theField->type)
{
case 'enum':
$choices = explode(",",$theField->enum);
?>
<tr>
<td><span class="wprsfl wprsfl-<?php echo $fieldName ?> wprsfl-<?php echo $fieldName ?>-<?php echo $form->id ?>"><?php echo $theField->label ?></span></td>
<td><span class="wprsfsf wprsf-<?php echo $fieldName ?>">
<select name="cus_<?php echo base64_encode($theField->name) ?>">
<?php
foreach ($choices as $choice)
{
?>
<option><?php echo $choice ?></option>
<?php
}
?>
</select>
</span></td>
</tr>
<?php
break;
case 'text':
?>
<tr>
<td><span class="wprsfl wprsfl-<?php echo $fieldName ?> wprsfl-<?php echo $fieldName ?>-<?php echo $form->id ?>"><?php echo $theField->label ?></td>
<td><span class="wprsftf wprsftf-<?php echo $fieldName ?> wprsftf-<?php echo $fieldName ?>-<?php echo $form->id ?>">
<input type="text" name="cus_<?php echo base64_encode($theField->name) ?>" />
</tr>
<?php
break;
case 'hidden':
?>
<input type="hidden" class="wprsfhf wprsfhf-<?php echo $fieldName ?> wprsfhf-<?php echo $fieldName ?>-<?php echo $form->id ?>">
" name="cus_<?php echo base64_encode($theField->name); ?>" value="<?php echo $_POST['field_'.$theField->id."_value"] ?>" />
<?php
break;
}
}
}
?>
<?php do_action("_wpr_subscriptionform_code",$form->id); ?>
<tr>
<td colspan="2" align="center"><input type="submit" value="<?php echo (empty($form->submit_button))?"Subscribe":$form->submit_button; ?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><?php if ($enableForm) { echo base64_decode("PGEgc3R5bGU9ImZvbnQtZmFtaWx5OlZlcmRhbmEsIEdlbmV2YSwgc2Fucy1zZXJpZjtmb250LXNpemU6IDlweDsiIGhyZWY9Imh0dHA6Ly93d3cud3ByZXNwb25kZXIuY29tIj5FbWFpbCBNYXJrZXRpbmcgYnkgV1AgQXV0b3Jlc3BvbmRlcjwvYT4="); } ?></td>
</tr>
</table>
</form>
<?php
$form = ob_get_clean();
return $form;
}
function _wpr_subscriptionforms_create()
{
global $wpdb;
$fieldsToSelect = array(); //just initializing the custom fields to be selected when the form loads..
if (isset($_POST['newsletter']))
{
$checkList = array("name"=>"Name field is required","confirm_subject"=>"E-Mail Confirmation Subject Field is required","confirm_body"=>"E-Mail Confirmation Body field","confirmed_subject"=>"Confirmed Subscription subject field is required","confirmed_body"=>"Confirmed subscription body field is required");
$errors = array();
foreach ($checkList as $field=>$errorMessage)
{
$theValue = trim($_POST[$field]);
if (empty($theValue))
{
$errors[] = $checkList[$field];
}
}
$info['name'] = $_POST['name'];
$info['return_url'] = $_POST['return_url'];
if (preg_match("@autoresponder_[0-9]+@",$_POST['followup']))
{
$followup = "autoresponder";
$followupid = str_replace("autoresponder_","",$_POST['followup']);
}
else if (preg_match("@postseries_[0-9]+@",$_POST['followup']))
{
$followup = "postseries";
$followupid = str_replace("postseries_","",$_POST['followup']);
}
else
{
$followup = "none";
$followupid = 0;
}
$info['followup_type'] = $followup;
$info['followup_id'] = $followupid;
switch ($_POST['blogsubscription'])
{
case 'none':
case 'all':
$blogSubscription = $_POST['blogsubscription'];
break;
default:
if (preg_match("@category_[0-9]+@",$_POST['blogsubscription']))
{
$blogSubscription = "cat";
$blogCategory = str_replace("category_","",$_POST['blogsubscription']);
}
}
$info['submit_button'] = $_POST['submit_value'];
$info['blogsubscription_type'] = $blogSubscription;
$info['blogsubscription_id'] = $blogCategory;
$info['custom_fields'] = (is_array($_POST['custom_fields']))?implode(",",$_POST['custom_fields']):"";
$info['confirm_subject'] = $_POST['confirm_subject'];
$info['confirm_body'] = $_POST['confirm_body'];
$info['nid'] = $_POST['newsletter'];
$info['confirmed_subject'] = $_POST['confirmed_subject'];
$info['confirmed_body'] = $_POST['confirmed_body'];
$errors = apply_filters("_wpr_subscriptionform_created_handler_validate",$errors);
if (count($errors) == 0)
{
_wpr_subscriptionform_create($info);
$query = "SELECT * FROM ".$wpdb->prefix."wpr_subscription_form where name='".$info['name']."';";
$form = $wpdb->get_results($query);
$form = $form[0];
do_action("_wpr_subscriptionform_created_handler_save",$form->id);
_wpr_subscriptionform_getcode($form,"Form Created");
return;
}
$params = (object) $info;
}
_wpr_subscriptionform_form($params,$errors);
}
function _wpr_subscriptionform_form($parameters=array(),$errors=array())
{
$parameters = (object)$parameters;
if (!empty($parameters->custom_fields))
$fieldsToSelect = explode(",",$parameters->custom_fields);
global $wpdb;
?>
<div class="wrap">
<h2>Create Subscription Form</h2>
</div>
<script>
/*
The function is used to ensure that only valid inputs can be given to the autoresponder
selection field.
*/
function Autoresponder(id,name)
{
this.id=id;
this.name=name;
}
var AutorespondersOfNewsletters=new Array();
<?php
$listOfAutorespondersOfNewsletters = _wpr_get_newsletters();
foreach ($listOfAutorespondersOfNewsletters as $count=>$news)
{
?>
AutorespondersOfNewsletters['<?php echo $news->id; ?>'] = new Array();
<?php
$autoresponders = _wpr_get_autoresponders_of_newsletter($news->id);
foreach ($autoresponders as $autoresponder)
{
$aid = intval($autoresponder->id);
$name = $autoresponder->name;
if ($aid==0 || empty($name))
{
continue;
}
?>
AutorespondersOfNewsletters['<?php echo $news->id ?>'].push(new Autoresponder(<?php echo $aid?>,"<?php echo $name ?>"));
<?php
}
}
?>
function autoresponderDropDownBox()
{
return document.getElementById('autoresponders_list');
}
function updateAutorespondersOption(currentNid)
{
if (AutorespondersOfNewsletters[currentNid]!=undefined)
{
var listOfResponders = AutorespondersOfNewsletters[currentNid];
if (listOfResponders.length!=0)
{
//remove the options in the autoresponder series drop down box.
emptyAutoresponderFields();
var countOfOptions=0;
for (var newopt in listOfResponders)
{
var theOpt = document.createElement("option");
theOpt.setAttribute("value","autoresponder_"+listOfResponders[newopt].id);
theOpt.innerHTML = listOfResponders[newopt].name;
autoresponderDropDownBox().appendChild(theOpt);
}
}
else
{
emptyAutoresponderFields();
}
}
else
{
emptyAutoresponderFields();
return false;
}
}
function _wpr_validate_subform_form_fields()
{
var titleField =document.getElementById('formnamefield');
if (titleField.value.length==0)
{
alert("A name is required for this form. Please enter a name.");
titleField.focus();
return false;
}
var newsletterField = document.getElementById('newsletterlist');
if (newsletterField.value=="")
{
alert("You must select a newsletter to which this subscription form will add subscribers.");
newsletterField.focus();
return false;
}
var confirmS = document.getElementById('confirms');
if (jQuery.trim(confirmS.value).length==0)
{
alert("You must enter a subject for the confirm subscription e-mail.");
confirmS.value='';
confirmS.focus();
return false;
}
var confirmB = document.getElementById('confirmb');
if (jQuery.trim(confirmB.value).length==0)
{
alert("You must enter a body for the confirm subscription e-mail.");
confirmB.value='';
confirmB.focus();
return false;
}
var confirmedS = document.getElementById('confirmeds');
if (jQuery.trim(confirmedS.value).length==0)
{
alert("You must enter a subject for the confirmed subscription e-mail.");
confirmedS.value='';
confirmedS.focus();
return false;
}
var confirmedB = document.getElementById('confirmedb');
if (jQuery.trim(confirmedB.value).length==0)
{
alert("You must enter a body for the confirmed subscription e-mail.");
confirmedB.value='';
confirmedB.focus();
return false;
}
var returnurlf = document.getElementById('returnurlfield');
returnurl = returnurlf.value;
if (jQuery.trim(returnurl).length !=0 && !checkURL(returnurl))
{
alert("The value in the return URL field should be a HTTP url. Please correct it or leave the field empty.");
returnurlf.value='';
returnurlf.focus();
return false;
}
return true;
}
function checkURL(value)
{
var urlregex = new RegExp(
"^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/){1}([0-9A-Za-z]+\.)");
if(urlregex.test(value))
{
return(true);
}
return(false);
}
function emptyAutoresponderFields()
{
jQuery("#autoresponders_list").children().each( function ()
{
jQuery(this).remove();
});
}
function Field(id,name,type,label,choices)
{
this.name = name;
this.id = id;
this.type = type;
this.label = label;
this.choices = choices;
}
var Fields = new Array();
<?php
$query ="SELECT * FROM ".$wpdb->prefix."wpr_custom_fields";
$customfields = $wpdb->get_results($query);
$count=0;
$newsletterlist = array();
foreach ($customfields as $field)
{
$newsletterlist[] = $field->nid;
}
if (count($newsletterlist))
$newsletterlist = array_unique($newsletterlist);
?>
var NewsletterFields = Array();
<?php
foreach ($newsletterlist as $newsletter)
{ ?>
NewsletterFields['<?php echo $newsletter; ?>'] = new Array();
<?php
}
foreach ($customfields as $field)
{
?>
NewsletterFields['<?php echo $field->nid ?>'].push(new Field('<?php echo $field->id ?>','<?php echo addslashes($field->name) ?>','<?php echo addslashes($field->type); ?>','<?php echo addslashes($field->label); ?>','<?php echo addslashes($field->enum) ?>'));
<?php
}
?>
var customFieldList = new Array();
function showFields(elements)
{
var fieldsCode;
if (elements && elements.length > 0)
document.getElementById('customfields').innerHTML = '';
else
return;
for (element in elements)
{
field = elements[element];
var element = document.createElement("div");
customFieldList.push(element);
element.setAttribute("style","border: 1px solid #ccc; padding: 10px;");
var formelement;
var check = document.createElement("input");
check.setAttribute("type","checkbox");
check.setAttribute("name","custom_fields[]");
check.setAttribute("value",field.id);
check.setAttribute("id","custom_"+field.id);
element.appendChild(check);
element.innerHTML += " "+field.name+"<br />";
preview = document.createElement("div");
preview.innerHTML += field.label +":";
preview.setAttribute("style","background-color: #ddd; border: 1px solid #eee; padding: 10px;");
if (field.type == "text")
{
element.innerHTML += "Type: One Line Text <br /><strong>Preview: <br />";
formelement = document.createElement("input");
formelement.setAttribute("type","text");
}
else
{
formelement = document.createElement("select");
var choices = field.choices.split(",");
element.innerHTML += "Type: Multiple Choice<br /><strong>Preview: <br />";
for (option in choices)
{
optionElement = document.createElement("option");
optionElement.text = choices[option];
formelement.add(optionElement,null);
}
}
preview.appendChild(formelement);
element.appendChild(preview);
element.innerHTML += "<br>";
document.getElementById('customfields').appendChild(element);
}
}
var autoresponderToBeSelected = '<?php echo ($parameters->followup_type == "postseries")?"postseries_":"autoresponder_";
echo $parameters->followup_id; ?>';
function setValueOfAutoresponderField()
{
document.getElementById('followup_field').value=autoresponderToBeSelected;
}
function load(id)
{
document.getElementById('customfields').innerHTML="<div align=\"center\">--None--</div>";
showFields(NewsletterFields[id]);
}
var toSelect = new Array(); //custom field ids to select.
<?php
if (count($fieldsToSelect) > 0)
{
?> <?php
foreach ($fieldsToSelect as $num=>$field)
{
?>
toSelect[<?php echo $num; ?>] = <?php echo $field; ?>;
<?php
}
}
function loadFollowUpAutoresponderList()
{
}