PageRenderTime 176ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-responder-email-autoresponder-and-newsletter-plugin/forms.php

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