/wp-content/plugins/wp-responder-email-autoresponder-and-newsletter-plugin/forms.php
PHP | 1395 lines | 1010 code | 371 blank | 14 comment | 98 complexity | 777f25c6a7fe8b5bb5f3c9f87145952f MD5 | raw file
1<?php
2
3include "forms.lib.php";
4
5function wpr_subscriptionforms()
6{
7 if (_wpr_no_newsletters("To create subscription forms"))
8 return;
9 switch ($_GET['action'])
10 {
11 case 'create':
12 _wpr_subscriptionforms_create();
13 break;
14 case 'form':
15 $id = $_GET['fid'];
16 $form = _wpr_subscriptionform_get($id);
17 _wpr_subscriptionform_getcode($form,"'".$form->name."' Form HTML Code");
18 return;
19 break;
20
21
22 case 'delete':
23
24 if (isset($_POST['forms']))
25 {
26 $formsToDelete = $_POST['forms'];
27 if (count($formsToDelete) >0)
28 {
29 _wpr_subscriptionforms_delete($formsToDelete);
30 _wpr_subscriptionform_delete_done();
31 }
32 else
33 {
34 _wpr_subscriptionform_delete_notfound();
35 }
36 }
37 else
38 {
39 _wpr_subscriptionform_delete_notfound();
40
41 }
42
43
44 break;
45
46 case 'edit':
47 $id = (int) $_GET['fid'];
48 do_action("_wpr_subscriptionform_edit_form_controller",$id);
49 $form = _wpr_subscriptionform_get($id);
50
51
52 $form->confirm_subject = stripslashes($form->confirm_subject);
53 $form->confirm_body = stripslashes($form->confirm_body);
54 $form->confirmed_subject = stripslashes($form->confirmed_subject);
55 $form->confirmed_body = stripslashes($form->confirmed_body);
56
57 if (isset($_POST['fid']))
58 {
59 $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");
60 $errors = array();
61 foreach ($checkList as $field=>$errorMessage)
62 {
63 $theValue = $_POST[$field];
64 $theValue = trim($theValue);
65 if (empty($theValue))
66 {
67 $errors[] = $checkList[$field];
68 }
69 }
70 $errors = apply_filters("_wpr_subscriptionform_edit_handler_validate",$errors);
71 if (count($errors) == 0)
72 {
73 $info['id'] = $_GET['fid'];
74 $info['name'] = $_POST['name'];
75 $info['return_url'] = $_POST['return_url'];
76 if (!preg_match("@postseries_[0-9]+@",$_POST['followup']) && !preg_match("@autoresponder_[0-9]+@",$_POST['followup']))
77 {
78 $info['followup_id'] = 0;
79 $info['followup_type'] = "none";
80 }
81 else
82 {
83 if (preg_match("@autoresponder_[0-9]+@",$_POST['followup']))
84 {
85 $followup = "autoresponder";
86 $followupid = str_replace("autoresponder_","",$_POST['followup']);
87 }
88 else if (preg_match("@postseries_[0-9]+@",$_POST['followup']))
89 {
90 $followup = "postseries";
91 $followupid = str_replace("postseries_","",$_POST['followup']);
92 }
93 else
94 {
95 $followup = "none";
96 $followupid = 0;
97 }
98 }
99 $info['followup_type'] = $followup;
100
101 $info['followup_id'] = $followupid;
102 //if it is a unknown follow-up type its probably an extended one.
103
104 switch ($_POST['blogsubscription'])
105 {
106 case 'none':
107 case 'all':
108 $blogSubscription = $_POST['blogsubscription'];
109 break;
110 default:
111 if (preg_match("@category_[0-9]+@",$_POST['blogsubscription']))
112 {
113 $blogSubscription = "cat";
114 $blogCategory = str_replace("category_","",$_POST['blogsubscription']);
115 }
116
117 }
118
119 $info['blogsubscription_type'] = $blogSubscription;
120
121 $info['blogsubscription_id'] = $blogCategory;
122
123 $info['submit_button'] = $_POST['submit_value'];
124
125 $info['custom_fields'] = (isset($_POST['custom_fields']) && is_array($_POST['custom_fields']))?implode(",",$_POST['custom_fields']):"";
126
127 $info['confirm_subject'] = $_POST['confirm_subject'];
128
129 $info['confirm_body'] = $_POST['confirm_body'];
130
131 $info['nid'] = $_POST['newsletter'];
132
133 $info['confirmed_subject'] = $_POST['confirmed_subject'];
134
135 $info['confirmed_body'] = $_POST['confirmed_body'];
136 _wpr_subscriptionform_update($info);
137 do_action("_wpr_subscriptionform_edit_handler_save",$info['id']);
138 $form = _wpr_subscriptionform_get($info['id']);
139 _wpr_subscriptionform_getcode($form,"Form Saved");
140 return;
141
142 }
143
144 else
145
146 $form = (object) $_POST;
147
148 }
149
150 _wpr_subscriptionform_form($form,$errors);
151
152 break;
153
154 default:
155
156 _wpr_subscriptionforms_list();
157
158 }
159
160}
161
162function _wpr_subscriptionform_delete_notfound()
163{
164 ?>
165
166<div class="wrap">
167 <h2>Invalid Input: No forms were specified.</h2>
168 Did you visit this page directly? Click on the button below to go to the subscription forms list.<br />
169 <input type="button" onclick="window.location='admin.php?page=wpresponder/subscriptionforms.php';" class="button-primary" value="« Back To Subscription Forms List">
170</div>
171<?php
172}
173function _wpr_subscriptionform_delete_done()
174{
175 ?>
176<div class="wrap">
177 <h2>The Selected Subscription Forms Have Been Deleted</h2>
178 <br />
179 <br />
180 <a href="admin.php?page=wpresponder/subscriptionforms.php" class="button-primary">« Back To Subscription Forms List</a> </div>
181<?php
182}
183
184function _wpr_subscriptionforms_delete($list)
185{
186 global $wpdb;
187 $formItems = implode(",",$list);
188 $formItems = "($formItems)";
189 $query = "DELETE FROM ".$wpdb->prefix."wpr_subscription_form where id in $formItems;";
190 $wpdb->query($query);
191
192}
193
194function _wpr_subscriptionforms_list()
195{
196 global $wpdb;
197 $tprefix = $wpdb->prefix;
198 $query = "SELECT a.* FROM ".$tprefix."wpr_subscription_form a, ".$tprefix."wpr_newsletters b where a.nid=b.id;";
199 $forms = $wpdb->get_results($query);
200
201 ?>
202<div class="wrap">
203 <h2>Subscription Forms</h2>
204</div>
205<script>
206function selectAllFormsCheckBox(state)
207{
208 jQuery(".forms_check").attr({ checked: state});
209}
210</script>
211<ul style="padding:20px;">
212 <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.
213</ul>
214<form name="formslist" action="admin.php?page=wpresponder/subscriptionforms.php&action=delete" method="post">
215 <table class="widefat" style="margin: 10px; margin:10px 0px;;">
216 <thead> <tr>
217 <th><input type="checkbox" name="selectall" value="1" onclick="selectAllFormsCheckBox(this.checked);" /></th>
218 <th scope="col">Name</th>
219 <th>Newsletter</th>
220 <th>Follow-Up</th>
221 <th>Blog Subscription</th>
222 <th scope="col">Actions</th>
223
224 </tr> </thead>
225 <?php
226
227 if (count($forms) > 0 )
228 {
229 foreach ($forms as $form)
230 {
231
232 ?>
233 <tr>
234 <td align="center"width="20"><input type="checkbox" name="forms[]" class="forms_check" value="<?php echo $form->id ?>" /></td>
235 <td><?php echo $form->name ?></td>
236 <td><a href="admin.php?page=wpresponder/subscribers.php&action=nmanage&nid=<?php echo $form->nid ?>">
237 <?php
238 $newsletter = _wpr_newsletter_get($form->nid);
239 echo $newsletter->name;
240 ?>
241 </a></td>
242 <td><?php
243
244 switch ($form->followup_type)
245 {
246 case 'postseries':
247 $postseries = _wpr_postseries_get($form->followup_id);
248 echo "Subscribe to the '".$postseries->name."' post series";
249 break;
250
251 case 'autoresponder':
252 $autoresponder = Autoresponder::getAutoresponder((int) $form->followup_id);
253 echo sprintf("Subscribe to the '%s' autoresponder.", $autoresponder->getName());
254 break;
255
256 case 'none':
257 echo "None";
258 break;
259 }
260 ?></td>
261 <td><?php
262 switch ($form->blogsubscription_type)
263 {
264 case 'cat':
265
266 $category = get_category($form->blogsubscription_id);
267 echo "Posts in the ".$category->name." category";
268 break;
269
270 case 'all':
271 echo "All Blog Posts ";
272 break;
273 case 'none':
274 echo "No blog subscription";
275 break;
276
277 }
278
279 ?>
280 <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>
281 </tr>
282 <?php
283
284 }
285 }
286 else
287 {
288 ?>
289 <tr>
290 <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>
291 </div></td>
292 </tr>
293 <?php
294
295 }
296
297?>
298</td></td>
299 </table>
300 <input type="submit" name="submit" value="Delete Forms" class="button" onclick="return confirm('Are you sure you want to delete the selected subscription forms?');" />
301 <input type="button" onclick="window.location='admin.php?page=wpresponder/subscriptionforms.php&action=create';" class="button" value="Create New Form">
302</form>
303<?php
304
305}
306
307
308
309function _wpr_subscriptionform_getcode($form,$title)
310
311{
312 ?>
313<div class="wrap">
314 <h2><?php echo $title ?></h2>
315
316The form has been saved.
317
318<h3>Now place the subscription form in the sidebar to start gathering subscribers.</h3>
319
320<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>
321
322<h3>Click on image to go to Widgets Section</h3>
323
324<h2>Alternatively...</h2>
325
326Copy and paste the code in the box below on the page where you want the subscription form to appear.
327
328<h3>Form Code:</h3>
329<?php $code = _wpr_subscriptionform_code($form); ?>
330<textarea rows="20" cols="70" id="wpr_code"><?php echo $code ?></textarea>
331<br />
332<div style="display:none" id="preview"> <?php echo $code ?> </div>
333<script>
334
335var preview;
336
337function preview()
338
339{
340
341 preview = window.open('about:blank','previewWindow','top=20,left=20,width=300,height=500');
342
343 preview.document.write(document.getElementById('preview').innerHTML);
344
345}
346
347</script>
348<a href="admin.php?page=wpresponder/subscriptionforms.php" class="button">« Back To Forms</a>
349<input type="button" value="Select All" onclick="document.getElementById('wpr_code').select();" class="button"/>
350<input type="button" onclick="preview();" value="Preview" class="button" />
351</div>
352<?php
353}
354
355
356
357function _wpr_subscriptionform_code($form,$enableForm=false)
358{
359 $url = home_url();
360 ob_start();
361 ?>
362<form action="<?php echo $url?>/?wpr-optin=1" method="post">
363 <span class="wpr-subform-hidden-fields">
364 <input type="hidden" name="blogsubscription" value="<?php echo $form->blogsubscription_type ?>" />
365 <?php if ($form->blogsubscription_type == "cat") { ?>
366 <input type="hidden" name="cat" value="<?php echo $form->blogsubscription_id ?>" />
367 <?php
368
369}
370
371if (!empty($form->followup_type) && $form->followup_type != "none")
372
373{
374
375?>
376 <input type="hidden" name="followup" value="<?php echo $form->followup_type ?>" />
377 <input type="hidden" name="responder" value="<?php echo $form->followup_id ?>" />
378 <input type="hidden" name="comment" value="" style="display:none" />
379 <?php
380
381} ?>
382<?php do_action("_wpr_subscription_form_code_generate",$form); ?>
383 <input type="hidden" name="newsletter" value="<?php echo $form->nid ?>" />
384 <?php if (isset($form->id)) { ?>
385 <input type="hidden" name="fid" value="<?php echo $form->id ?>" />
386 <?php } ?>
387 </span>
388 <table>
389 <tr>
390 <td><span class="wprsfl wprsfl-name"><?php _e('Name','wpr_autoresponder'); ?>:</span></td>
391 <td><span class="wprsftf wpr-subform-textfield-name">
392 <input type="text" name="name" /></td>
393 </tr>
394 <tr>
395 <td><span class="wprsfl wprsfl-email"><?php _e('E-Mail','wpr_autoresponder'); ?>:</span></td>
396 <td><span class="wprsftf wpsftf-email">
397 <input type="text" name="email" />
398 </span>
399 </tr>
400 <?php
401 if (!empty($form->custom_fields))
402
403 {
404
405 $formItems = array();
406
407 $formItems = explode(",",$form->custom_fields);
408
409 foreach ($formItems as $field)
410
411 {
412
413 $theField = _wpr_newsletter_custom_fields_get($field);
414
415
416 $fieldName = str_replace('"','',$theField->id);
417
418 switch ($theField->type)
419
420 {
421
422 case 'enum':
423
424 $choices = explode(",",$theField->enum);
425
426 ?>
427 <tr>
428 <td><span class="wprsfl wprsfl-<?php echo $fieldName ?> wprsfl-<?php echo $fieldName ?>-<?php echo $form->id ?>"><?php echo $theField->label ?></span></td>
429 <td><span class="wprsfsf wprsf-<?php echo $fieldName ?>">
430 <select name="cus_<?php echo base64_encode($theField->name) ?>">
431 <?php
432foreach ($choices as $choice)
433{
434?>
435 <option><?php echo $choice ?></option>
436 <?php
437}
438
439 ?>
440 </select>
441 </span></td>
442 </tr>
443 <?php
444
445 break;
446
447 case 'text':
448
449 ?>
450 <tr>
451 <td><span class="wprsfl wprsfl-<?php echo $fieldName ?> wprsfl-<?php echo $fieldName ?>-<?php echo $form->id ?>"><?php echo $theField->label ?></td>
452 <td><span class="wprsftf wprsftf-<?php echo $fieldName ?> wprsftf-<?php echo $fieldName ?>-<?php echo $form->id ?>">
453 <input type="text" name="cus_<?php echo base64_encode($theField->name) ?>" />
454 </tr>
455 <?php
456
457
458
459 break;
460
461 case 'hidden':
462
463 ?>
464 <input type="hidden" class="wprsfhf wprsfhf-<?php echo $fieldName ?> wprsfhf-<?php echo $fieldName ?>-<?php echo $form->id ?>">
465 " name="cus_<?php echo base64_encode($theField->name); ?>" value="<?php echo $_POST['field_'.$theField->id."_value"] ?>" />
466 <?php
467
468 break;
469
470 }
471 }
472 }
473
474 ?>
475 <?php do_action("_wpr_subscriptionform_code",$form->id); ?>
476 <tr>
477 <td colspan="2" align="center"><input type="submit" value="<?php echo (empty($form->submit_button))?__("Subscribe",'wpr_autoresponder'):$form->submit_button; ?>" /></td>
478 </tr>
479 <tr>
480 <td colspan="2" align="center"><?php if ($enableForm) { ?>
481 <a href="http://www.wpresponder.com"><?php _e('Email Marketing by WP Autoresponder','wpr_autoresponder'); ?></a>
482 <?php } ?></td>
483 </tr>
484 </table>
485</form>
486<?php
487
488 $form = ob_get_clean();
489
490 return $form;
491
492}
493
494
495
496function _wpr_subscriptionforms_create()
497
498{
499
500 global $wpdb;
501
502 $fieldsToSelect = array(); //just initializing the custom fields to be selected when the form loads..
503
504 if (isset($_POST['newsletter']))
505 {
506
507
508
509 $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");
510
511 $errors = array();
512
513 foreach ($checkList as $field=>$errorMessage)
514
515 {
516
517
518 $theValue = trim($_POST[$field]);
519
520 if (empty($theValue))
521 {
522 $errors[] = $checkList[$field];
523 }
524
525
526
527 }
528
529 $info['name'] = $_POST['name'];
530
531 $info['return_url'] = $_POST['return_url'];
532
533
534 if (preg_match("@autoresponder_[0-9]+@",$_POST['followup']))
535 {
536 $followup = "autoresponder";
537 $followupid = str_replace("autoresponder_","",$_POST['followup']);
538 }
539 else if (preg_match("@postseries_[0-9]+@",$_POST['followup']))
540 {
541 $followup = "postseries";
542 $followupid = str_replace("postseries_","",$_POST['followup']);
543 }
544 else
545 {
546 $followup = "none";
547 $followupid = 0;
548 }
549
550 $info['followup_type'] = $followup;
551 $info['followup_id'] = $followupid;
552
553
554 switch ($_POST['blogsubscription'])
555 {
556 case 'none':
557 case 'all':
558 $blogSubscription = $_POST['blogsubscription'];
559 break;
560 default:
561 if (preg_match("@category_[0-9]+@",$_POST['blogsubscription']))
562 {
563 $blogSubscription = "cat";
564 $blogCategory = str_replace("category_","",$_POST['blogsubscription']);
565 }
566
567 }
568
569 $info['submit_button'] = $_POST['submit_value'];
570
571
572
573 $info['blogsubscription_type'] = $blogSubscription;
574
575 $info['blogsubscription_id'] = $blogCategory;
576
577 $info['custom_fields'] = (is_array($_POST['custom_fields']))?implode(",",$_POST['custom_fields']):"";
578
579 $info['confirm_subject'] = $_POST['confirm_subject'];
580
581 $info['confirm_body'] = $_POST['confirm_body'];
582
583 $info['nid'] = $_POST['newsletter'];
584
585 $info['confirmed_subject'] = $_POST['confirmed_subject'];
586
587 $info['confirmed_body'] = $_POST['confirmed_body'];
588
589 $errors = apply_filters("_wpr_subscriptionform_created_handler_validate",$errors);
590
591 if (count($errors) == 0)
592 {
593 _wpr_subscriptionform_create($info);
594
595 $query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpr_subscription_form WHERE name=%s;",$info['name']);
596 $form = $wpdb->get_results($query);
597 $form = $form[0];
598 do_action("_wpr_subscriptionform_created_handler_save",$form->id);
599 _wpr_subscriptionform_getcode($form,"Form Created");
600 return;
601
602 }
603 $params = (object) $info;
604 }
605
606
607
608 _wpr_subscriptionform_form($params,$errors);
609
610}
611
612
613
614function _wpr_subscriptionform_form($parameters=array(),$errors=array())
615
616{
617
618 $parameters = (object)$parameters;
619
620
621 if (!empty($parameters->custom_fields))
622
623 $fieldsToSelect = explode(",",$parameters->custom_fields);
624
625 global $wpdb;
626
627
628
629 ?>
630<div class="wrap">
631 <h2>Create Subscription Form</h2>
632</div>
633<script>
634
635
636
637/*
638
639
640The function is used to ensure that only valid inputs can be given to the autoresponder
641selection field.
642
643
644*/
645function Autoresponder(id,name)
646{
647 this.id=id;
648 this.name=name;
649}
650var AutorespondersOfNewsletters=new Array();
651
652<?php
653
654$listOfAutorespondersOfNewsletters = _wpr_get_newsletters();
655foreach ($listOfAutorespondersOfNewsletters as $count=>$news)
656{
657 ?>
658AutorespondersOfNewsletters['<?php echo $news->id; ?>'] = new Array();
659 <?php
660 $autoresponders = Autoresponder::getAutorespondersOfNewsletter($news->id);
661 foreach ($autoresponders as $autoresponder)
662 {
663 $aid = $autoresponder->getId();
664 $name = $autoresponder->getName();
665
666 if ($aid==0 || empty($name))
667 {
668 continue;
669 }
670 ?>
671AutorespondersOfNewsletters['<?php echo $news->id ?>'].push(new Autoresponder(<?php echo $aid?>,"<?php echo $name ?>"));
672 <?php
673 }
674}
675
676?>
677function autoresponderDropDownBox()
678{
679 return document.getElementById('autoresponders_list');
680}
681
682
683
684function updateAutorespondersOption(currentNid)
685{
686 if (AutorespondersOfNewsletters[currentNid]!=undefined)
687 {
688
689 var listOfResponders = AutorespondersOfNewsletters[currentNid];
690
691 if (listOfResponders.length!=0)
692 {
693 //remove the options in the autoresponder series drop down box.
694 emptyAutoresponderFields();
695
696 var countOfOptions=0;
697 for (var newopt in listOfResponders)
698 {
699 var theOpt = document.createElement("option");
700 theOpt.setAttribute("value","autoresponder_"+listOfResponders[newopt].id);
701 theOpt.innerHTML = listOfResponders[newopt].name;
702 autoresponderDropDownBox().appendChild(theOpt);
703 }
704 }
705 else
706 {
707 emptyAutoresponderFields();
708 }
709
710 }
711 else
712 {
713 emptyAutoresponderFields();
714 return false;
715 }
716}
717
718
719function _wpr_validate_subform_form_fields()
720{
721 var titleField =document.getElementById('formnamefield');
722 if (titleField.value.length==0)
723 {
724 alert("A name is required for this form. Please enter a name.");
725 titleField.focus();
726 return false;
727 }
728
729
730 var newsletterField = document.getElementById('newsletterlist');
731 if (newsletterField.value=="")
732 {
733 alert("You must select a newsletter to which this subscription form will add subscribers.");
734 newsletterField.focus();
735 return false;
736 }
737
738 var confirmS = document.getElementById('confirms');
739 if (jQuery.trim(confirmS.value).length==0)
740 {
741 alert("You must enter a subject for the confirm subscription e-mail.");
742 confirmS.value='';
743 confirmS.focus();
744 return false;
745 }
746
747
748 var confirmB = document.getElementById('confirmb');
749 if (jQuery.trim(confirmB.value).length==0)
750 {
751 alert("You must enter a body for the confirm subscription e-mail.");
752 confirmB.value='';
753 confirmB.focus();
754 return false;
755 }
756
757 var confirmedS = document.getElementById('confirmeds');
758 if (jQuery.trim(confirmedS.value).length==0)
759 {
760 alert("You must enter a subject for the confirmed subscription e-mail.");
761 confirmedS.value='';
762 confirmedS.focus();
763 return false;
764 }
765
766 var confirmedB = document.getElementById('confirmedb');
767 if (jQuery.trim(confirmedB.value).length==0)
768 {
769 alert("You must enter a body for the confirmed subscription e-mail.");
770 confirmedB.value='';
771 confirmedB.focus();
772 return false;
773 }
774
775 var returnurlf = document.getElementById('returnurlfield');
776 returnurl = returnurlf.value;
777 if (jQuery.trim(returnurl).length !=0 && !checkURL(returnurl))
778 {
779 alert("The value in the return URL field should be a HTTP url. Please correct it or leave the field empty.");
780 returnurlf.value='';
781 returnurlf.focus();
782 return false;
783 }
784
785 return true;
786
787
788
789
790}
791
792
793function checkURL(value)
794{
795 var urlregex = new RegExp(
796 "^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/){1}([0-9A-Za-z]+\.)");
797 if(urlregex.test(value))
798 {
799 return(true);
800 }
801 return(false);
802}
803
804
805function emptyAutoresponderFields()
806{
807 jQuery("#autoresponders_list").children().each( function ()
808 {
809 jQuery(this).remove();
810
811 });
812}
813
814function Field(id,name,type,label,choices)
815
816{
817
818 this.name = name;
819 this.id = id;
820 this.type = type;
821 this.label = label;
822 this.choices = choices;
823
824}
825
826
827
828
829var Fields = new Array();
830
831<?php
832
833$query ="SELECT * FROM ".$wpdb->prefix."wpr_custom_fields";
834
835$customfields = $wpdb->get_results($query);
836
837$count=0;
838
839
840$newsletterlist = array();
841
842foreach ($customfields as $field)
843{
844 $newsletterlist[] = $field->nid;
845}
846
847if (count($newsletterlist))
848 $newsletterlist = array_unique($newsletterlist);
849?>
850var NewsletterFields = Array();
851 <?php
852 foreach ($newsletterlist as $newsletter)
853 { ?>
854NewsletterFields['<?php echo $newsletter; ?>'] = new Array();
855 <?php
856 }
857
858 foreach ($customfields as $field)
859 {
860 ?>
861NewsletterFields['<?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) ?>'));
862<?php
863
864 }
865?>
866var customFieldList = new Array();
867function showFields(elements)
868{
869 var fieldsCode;
870 if (elements && elements.length > 0)
871 document.getElementById('customfields').innerHTML = '';
872 else
873 return;
874 for (element in elements)
875 {
876 field = elements[element];
877 var element = document.createElement("div");
878 customFieldList.push(element);
879 element.setAttribute("style","border: 1px solid #ccc; padding: 10px;");
880
881
882
883 var formelement;
884
885 var check = document.createElement("input");
886
887 check.setAttribute("type","checkbox");
888
889 check.setAttribute("name","custom_fields[]");
890
891 check.setAttribute("value",field.id);
892
893 check.setAttribute("id","custom_"+field.id);
894
895 element.appendChild(check);
896
897 element.innerHTML += " "+field.name+"<br />";
898
899 preview = document.createElement("div");
900
901 preview.innerHTML += field.label +":";
902
903 preview.setAttribute("style","background-color: #ddd; border: 1px solid #eee; padding: 10px;");
904
905 if (field.type == "text")
906
907 {
908
909 element.innerHTML += "Type: One Line Text <br /><strong>Preview: <br />";
910
911 formelement = document.createElement("input");
912
913 formelement.setAttribute("type","text");
914
915 }
916
917 else
918
919 {
920
921 formelement = document.createElement("select");
922
923
924
925 var choices = field.choices.split(",");
926
927 element.innerHTML += "Type: Multiple Choice<br /><strong>Preview: <br />";
928
929 for (option in choices)
930
931 {
932
933 optionElement = document.createElement("option");
934
935 optionElement.text = choices[option];
936
937 formelement.add(optionElement,null);
938
939 }
940
941 }
942
943 preview.appendChild(formelement);
944
945 element.appendChild(preview);
946
947 element.innerHTML += "<br>";
948
949
950
951 document.getElementById('customfields').appendChild(element);
952
953 }
954
955
956
957}
958
959var autoresponderToBeSelected = '<?php echo ($parameters->followup_type == "postseries")?"postseries_":"autoresponder_";
960echo $parameters->followup_id; ?>';
961
962
963function setValueOfAutoresponderField()
964{
965 document.getElementById('followup_field').value=autoresponderToBeSelected;
966}
967function load(id)
968{
969 document.getElementById('customfields').innerHTML="<div align=\"center\">--None--</div>";
970 showFields(NewsletterFields[id]);
971}
972
973var toSelect = new Array(); //custom field ids to select.
974
975<?php
976
977
978if (count($fieldsToSelect) > 0)
979
980{
981
982 ?> <?php
983
984 foreach ($fieldsToSelect as $num=>$field)
985
986 {
987
988?>
989
990toSelect[<?php echo $num; ?>] = <?php echo $field; ?>;
991
992
993
994<?php
995
996 }
997
998
999
1000}
1001
1002function loadFollowUpAutoresponderList()
1003{
1004
1005}
1006
1007?>jQuery(document).ready(function() {
1008
1009
1010
1011 var selectedNewsletter = document.getElementById('newsletterlist').options[document.getElementById('newsletterlist').selectedIndex].value;
1012
1013 showFields(NewsletterFields[selectedNewsletter]);
1014 updateAutorespondersOption(selectedNewsletter);
1015 setValueOfAutoresponderField();
1016
1017 //if this form is being used to edit, then select the fields that were saved..
1018 for (var i in toSelect)
1019 {
1020 document.getElementById('custom_'+toSelect[i]).checked=true;
1021 }
1022
1023});
1024
1025</script>
1026<?php if (count($errors) >0)
1027
1028{
1029
1030 ?>
1031<div class="updated fade">
1032 <ul>
1033 <?php
1034
1035 foreach ($errors as $error)
1036 {
1037 echo '<li>'.$error.'</li>';
1038 }
1039
1040 ?>
1041 </ul>
1042</div>
1043<?php
1044
1045}
1046
1047?>
1048<div style="display:none">
1049 <?php
1050
1051$query = "SELECT id from ".$prefix."wpr_newsletters";
1052
1053$newsletters = $wpdb->get_results($query);
1054
1055foreach ($newsletters as $newsletter)
1056{
1057 $nid = $newsletter->id;
1058 ?>
1059 <div id="fields-<?php echo $nid?>">
1060 <?php
1061
1062 $query = "SELECT * FROM ".$prefix."wpr_custom_fields where nid=$nid";
1063
1064 $customFields = $wpdb->get_results($query);
1065
1066 foreach ($customFields as $field)
1067
1068 {
1069
1070?>
1071 <div class="field"> Name Of Field: <?php echo $field->name ?><br />
1072 Field Label: <?php echo $field->label ?><br />
1073 <?php
1074
1075
1076
1077 switch ($field->type)
1078
1079 {
1080
1081 case 'text':
1082
1083?>
1084 Type: One Line Text
1085
1086 Preview:
1087 <input type="text" size="30" />
1088 <?php
1089
1090 break;
1091
1092 case 'enum':
1093
1094 $choices = $field->enum;
1095
1096 $choices = explode(",",$choices);
1097
1098?>
1099 Type: Multiple Choice<br />
1100 Preview:
1101 <select>
1102 <?php
1103
1104 foreach ($choices as $choice)
1105
1106 {
1107
1108 ?>
1109 <option><?php echo $choice ?></option>
1110 <?php
1111
1112 }
1113
1114 ?>
1115 </select>
1116 <?php
1117
1118 break;
1119
1120 case 'hidden':
1121
1122 ?>
1123 Type: Hidden<br />
1124 Preview: Hidden fields aren't visible on the page.
1125 <?php
1126
1127 break;
1128
1129 }
1130
1131 ?>
1132 </div>
1133 <?php
1134
1135 }
1136
1137 ?>
1138 </div>
1139 <?php
1140
1141}
1142
1143?>
1144</div>
1145<form action="<?php print $_SERVER['REQUEST_URI'] ?>" method="post">
1146 <input type="hidden" value="<?php echo $parameters->id ?>" name="fid"/>
1147 <table width="700">
1148 <tr>
1149 <td><strong>Name:</strong>
1150 <p><small>This form's settings will be saved. This name will be used to identify the settings.</small></p></td>
1151 <td><input type="text" id="formnamefield" name="name" size="60" value="<?php echo $parameters->name ?>" /></td>
1152 </tr>
1153 <tr>
1154 <td><strong>Newsletter:</strong>
1155 <p><small>Select the newsletter to which subscribers will be subscribed when filling this form.</small></p></td>
1156 <td><select name="newsletter" id="newsletterlist" onchange="load(this.options[this.selectedIndex].value);updateAutorespondersOption(this.options[this.selectedIndex].value);">
1157 <?php
1158
1159 $query = "SELECT * FROM ".$wpdb->prefix."wpr_newsletters";
1160
1161 $newsletters = $wpdb->get_results($query);
1162
1163 if (count($newsletters)>0)
1164 {
1165 ?>
1166 <option></option>
1167 <?php
1168
1169 foreach ($newsletters as $newsletter)
1170 {
1171
1172 ?>
1173 <option value="<?php echo $newsletter->id; ?>" <?php
1174
1175 if ($parameters->nid == $newsletter->id)
1176
1177 {
1178
1179 echo 'selected="selected"';
1180
1181 } ?>><?php echo $newsletter->name; ?></option>
1182 <?php
1183
1184 }
1185 }
1186
1187 ?>
1188 </select>
1189 </tr>
1190 <tr>
1191 <td width="300"><strong>Return URL:</strong>
1192 <p><small> The subscriber is sent to this url after entering their name and email address in the subscription form. </small></p></td>
1193 <td><input type="text" id="returnurlfield" name="return_url" size="60" value="<?php echo $parameters->return_url ?>" /></td>
1194 </tr>
1195 <tr>
1196 <td><strong>Blog Subscription</strong>:
1197 <p> <small> Specify what kind of blog subscription will those who use this form will have:</small></p></td>
1198 <td>
1199 <select name="blogsubscription">
1200 <option value="none" <?php if ($parameters->blogsubscription_type=="none") { echo 'selected="selected"'; } ?>>None</option>
1201 <option value="all" <?php if ($parameters->blogsubscription_type=="all") { echo 'selected="selected"'; } ?>>Subscribe to all new posts on
1202 <?php bloginfo("name") ?>
1203 </option>
1204 <optgroup label="Particular Blog Category:">
1205 <?php
1206 $args = array(
1207 'type' => 'post',
1208 'child_of' => 0,
1209 'orderby' => 'name',
1210 'order' => 'ASC',
1211 'hide_empty' => false,
1212 'hierarchical' => 0);
1213
1214 $categories = get_categories($args);
1215
1216 foreach ($categories as $category)
1217 {
1218 ?>
1219 <option value="category_<?php echo $category->term_id; ?>" <?php if ($parameters->blogsubscription_type=="cat" && $parameters->blogsubscription_id == $category->term_id) echo 'selected="selected"'; ?>><?php echo $category->name ?></option>
1220 <?php
1221 }
1222 ?>
1223 </optgroup>
1224 </select></td>
1225 </tr>
1226 <tr>
1227 <td><strong>Follow Up Subscription:</strong>
1228 <p> <small>Select what content should follow-up a successful subscription.</small></p></td>
1229 <?php
1230 //construction of options for the followup subscriptions field.
1231
1232 $types['Autoresponders'] = array();
1233 $types['Selected'] = null;
1234
1235 //repeat the same with post series
1236 $getPostSeriesList = sprintf("SELECT * FROM %swpr_blog_series",$wpdb->prefix);
1237 $listOfPostSeries = $wpdb->get_results($getPostSeriesList);
1238 $types['Post Series'] = array();
1239 foreach ($listOfPostSeries as $post_series)
1240 {
1241 $item = array("name"=> $post_series->name,
1242 "id"=>"postseries_".$post_series->id);
1243 $types['Post Series'][] = $item;
1244 if ($parameters->followup_type = "postseries" && $parameters->followup_id == $post_series->id)
1245 {
1246 $indexOfThisItem = count($types['Post Series'])-1;
1247 $types['Post Series'][$indexOfThisItem]['selected'] = true;
1248 $types['Selected'] = &$types['Post Series'][$indexOfThisItem];
1249 }
1250 }
1251
1252 $types = apply_filters("_wpr_subscription_form_followup_options",$types);
1253 $whetherInvalidFollowupSeries = false;
1254
1255 if ($parameters->followup_id != 0 && $types['Selected'] == null)
1256 {
1257 $whetherInvalidFollowupSeries = true;
1258 }
1259 ?>
1260 <td><select name="followup" id="followup_field">
1261 <?php
1262 //if the selected option is a null then set the none option as the selected item
1263 ?>
1264 <option value="0" <?php if ($types['Selected'] == null) { ?> selected="selected" <?php } ?>>None</option>
1265 <optgroup id="autoresponders_list" label="Autoresponders"></optgroup>
1266 <?php
1267
1268 foreach ($types as $group=>$options)
1269 {
1270 if ($group == "Selected" || $group == "Autoresponders")
1271 continue;
1272 ?>
1273 <optgroup label="<?php echo $group ?>">
1274 <?php
1275 if (count($options))
1276 {
1277 foreach ($options as $option)
1278 {
1279 ?><option <?php if ($types['Selected'] == $option) { ?>selected="selected" <?php } ?> value="<?php echo $option['id'] ?>"><?php echo $option['name'] ?></option>
1280 <?php
1281 }
1282 }
1283 else
1284 {
1285 ?>
1286 <option disabled="disabled">None defined</option><?php
1287 }
1288
1289 ?>
1290 </optgroup>
1291 <?php
1292 }
1293
1294 ?>
1295 </select></td>
1296 </tr>
1297 <tr>
1298 <td><strong>Submit Button Text:</strong>
1299 <p>
1300 <small>The label that will be used for the subscription form submit button</small></p>
1301 </td>
1302 <td><input type="text" size="60" name="submit_value" value="<?php echo ($parameters->submit_button)?$parameters->submit_button:"Subscribe"; ?>" ></td>
1303 </tr>
1304 <?php
1305 if (!$parameters->id)
1306 do_action("_wpr_subscriptionform_form_field","");
1307 else
1308 do_action("_wpr_subscriptionform_form_field",$parameters->id); ?>
1309 <tr>
1310 <td colspan="2"><div class="wrap">
1311 <h3>More Form Fields</h3>
1312 <hr size="1" color="black">
1313 <p>Select the custom fields that should be added to the in the opt-in form.</p>
1314 </div>
1315 <div id="customfields"> </div></td>
1316 </tr>
1317 <tr>
1318 <td><h3> Confirmation E-Mail:</h3>
1319 <table>
1320 <tr>
1321 <td>Subject:</td>
1322 <td><input type="text" id="confirms" name="confirm_subject" size="70" value="<?php
1323
1324
1325
1326 if (!$parameters->confirm_subject)
1327
1328 {
1329
1330 $confirm_subject = get_option('wpr_confirm_subject');
1331
1332 echo $confirm_subject;
1333
1334 }
1335
1336 else
1337
1338 {
1339
1340 echo $parameters->confirm_subject;
1341
1342 }
1343
1344 ?>" /></td>
1345 </tr>
1346 <tr>
1347 <td colspan="2"> Message Body:<br />
1348 <textarea id="confirmb" name="confirm_body" rows="10" cols="60" wrap="hard"><?php
1349
1350if (!$parameters->confirm_body)
1351
1352{
1353
1354 $confirm_email = get_option('wpr_confirm_body');
1355
1356 echo $confirm_email;
1357
1358}
1359
1360else
1361
1362{
1363
1364 echo $parameters->confirm_body;
1365
1366}
1367
1368 ?>
1369</textarea></td>
1370 </tr>
1371 </table>
1372 <h3>Subscription Confirmed E-Mail:</h3>
1373 <table>
1374 <tr>
1375 <td>Subject:</td>
1376 <td><input id="confirmeds" type="text" name="confirmed_subject" value="<?php echo ($parameters->confirmed_subject)?$parameters->confirmed_subject:get_option("wpr_confirmed_subject"); ?>" size="60" /></td>
1377 </tr>
1378 <tr>
1379 <td colspan="2"> Message Body:<br />
1380 <textarea id="confirmedb" name="confirmed_body" rows="10" cols="60"><?php echo ($parameters->confirmed_body)?$parameters->confirmed_body:get_option("wpr_confirmed_body"); ?></textarea></td>
1381 </tr>
1382 </table></td>
1383 </tr>
1384 <tr>
1385 <td colspan="2"><input class="button" type="submit" onclick="return _wpr_validate_subform_form_fields()" value="Create Form And Get Code" />
1386 <a class="button" href="admin.php?page=wpresponder/subscriptionforms.php">Cancel</a></td>
1387 </tr>
1388 </table>
1389</form>
1390<?php
1391
1392
1393
1394}
1395