PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/vfb-pro/admin/class-forms-edit-email.php

https://bitbucket.org/daniellbraun/wildernessatthesmokies
PHP | 355 lines | 293 code | 33 blank | 29 comment | 14 complexity | 38525a3c423008d2ab2a00ec5bf3df73 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-3.0, GPL-2.0, GPL-3.0, MIT
  1. <?php
  2. /**
  3. * Class that controls the Email Settings tab
  4. *
  5. * @since 3.0
  6. */
  7. class VFB_Pro_Forms_Edit_Email {
  8. /**
  9. * The form ID
  10. *
  11. * @var mixed
  12. * @access private
  13. */
  14. private $id;
  15. /**
  16. * Assign form ID when class is loaded
  17. *
  18. * @access public
  19. * @param mixed $id
  20. * @return void
  21. */
  22. public function __construct( $id ) {
  23. $this->id = (int) $id;
  24. }
  25. /**
  26. * display function.
  27. *
  28. * @access public
  29. * @return void
  30. */
  31. public function display() {
  32. // Double check permissions before display
  33. if ( !current_user_can( 'vfb_edit_forms' ) )
  34. return;
  35. $vfbdb = new VFB_Pro_Data();
  36. $data = $vfbdb->get_email_settings( $this->id );
  37. $vfb_settings = $vfbdb->get_vfb_settings();
  38. $from_name = isset( $data['from-name'] ) ? $data['from-name'] : '';
  39. $reply_to = isset( $data['reply-to'] ) ? $data['reply-to'] : '';
  40. $reply_to_user = isset( $data['reply-to-user-email'] ) ? $data['reply-to-user-email'] : '';
  41. $subject = isset( $data['subject'] ) ? $data['subject'] : '';
  42. $email_to = isset( $data['email-to'] ) ? $data['email-to'] : '';
  43. $from_email = isset( $data['from-email'] ) ? $data['from-email'] : '';
  44. $from_email_user = isset( $data['from-email-user'] ) ? $data['from-email-user'] : '';
  45. $cc = isset( $data['cc'] ) ? $data['cc'] : '';
  46. $bcc = isset( $data['bcc'] ) ? $data['bcc'] : '';
  47. $send_attachments = isset( $data['send-attachments'] ) ? $data['send-attachments'] : '';
  48. $notify_name = isset( $data['notify-name'] ) ? $data['notify-name'] : '';
  49. $notify_email = isset( $data['notify-email'] ) ? $data['notify-email'] : '';
  50. $notify_subject = isset( $data['notify-subject'] ) ? $data['notify-subject'] : '';
  51. $notify_email_to = isset( $data['notify-email-to'] ) ? $data['notify-email-to'] : '';
  52. $notify_message = isset( $data['notify-message'] ) ? $data['notify-message'] : '';
  53. $notify_entry_copy = isset( $data['notify-entry-copy'] ) ? $data['notify-entry-copy'] : '';
  54. $smtp_host = isset( $vfb_settings['smtp-host'] ) ? $vfb_settings['smtp-host'] : '';
  55. $smtp_port = isset( $vfb_settings['smtp-port'] ) ? $vfb_settings['smtp-port'] : '';
  56. $readonly = $disabled = '';
  57. if ( empty( $smtp_host ) && empty( $smtp_port ) ) {
  58. // Get the site domain and get rid of www.
  59. $sitename = strtolower( $_SERVER['SERVER_NAME'] );
  60. if ( substr( $sitename, 0, 4 ) == 'www.' ) {
  61. $sitename = substr( $sitename, 4 );
  62. }
  63. $from_email = 'no-reply@' . $sitename;
  64. // Can't change the From Email b/c SMTP isn't setup
  65. $readonly = ' readonly="readonly"';
  66. // Can't change the From Email User dropdown b/c SMTP isn't setup
  67. $disabled = ' disabled="disabled"';
  68. }
  69. // Get email fields to be used for $notify_email_to
  70. $email_fields = $vfbdb->get_fields( $this->id, "AND field_type = 'email' ORDER BY field_order ASC" );
  71. ?>
  72. <form method="post" id="vfbp-email-settings" action="" novalidate>
  73. <input name="_vfbp_action" type="hidden" value="save-email-settings" />
  74. <input name="_vfbp_form_id" type="hidden" value="<?php echo $this->id; ?>" />
  75. <?php
  76. wp_nonce_field( 'vfbp_email_settings' );
  77. ?>
  78. <div class="vfb-edit-section">
  79. <div class="vfb-edit-section-inside">
  80. <h3><?php _e( 'Notification', 'vfb-pro' ); ?></h3>
  81. <p><?php _e( 'Receive an email of the submitted data when someone completes the form.', 'vfb-pro' ); ?></p>
  82. <table class="form-table">
  83. <tbody>
  84. <tr valign="top">
  85. <th scope="row">
  86. <label for="from-name"><?php _e( 'Your Name' , 'vfb-pro'); ?></label>
  87. </th>
  88. <td>
  89. <input type="text" value="<?php esc_html_e( $from_name ); ?>" placeholder="" class="regular-text required" id="from-name" name="settings[from-name]" />
  90. <p class="description"><?php _e( 'This option sets the "From" display name of the email that is sent.' , 'vfb-pro'); ?></p>
  91. </td>
  92. </tr>
  93. <tr valign="top">
  94. <th scope="row">
  95. <label for="reply-to"><?php _e( 'Reply-To Email' , 'vfb-pro'); ?></label>
  96. </th>
  97. <td>
  98. <input type="email" value="<?php esc_html_e( $reply_to ); ?>" placeholder="" class="regular-text required" id="reply-to" name="settings[reply-to]" maxlength="255" />
  99. <?php _e( 'or', 'vfb-pro' ); ?>
  100. <select id="reply-to-user" name="settings[reply-to-user-email]">
  101. <option value=""<?php selected( '', $reply_to_user ); ?>></option>
  102. <?php
  103. if ( is_array( $email_fields ) && !empty( $email_fields ) ) {
  104. foreach ( $email_fields as $email ) {
  105. $label = isset( $email['data']['label'] ) ? $email['data']['label'] : '';
  106. $field_id = $email['id'];
  107. printf( '<option value="%1$d"%3$s>%1$d - %2$s</option>', $field_id, $label, selected( $field_id, $reply_to_user, false ) );
  108. }
  109. }
  110. else {
  111. printf( '<option>(%s)</option>', __( 'No Email Fields Found', 'vfb-pro' ) );
  112. }
  113. ?>
  114. </select>
  115. <p class="description"><?php _e( 'Replies to the submission email will go here.' , 'vfb-pro'); ?></p>
  116. </td>
  117. </tr>
  118. <tr valign="top">
  119. <th scope="row">
  120. <label for="subject"><?php _e( 'Email Subject' , 'vfb-pro'); ?></label>
  121. </th>
  122. <td>
  123. <input type="text" value="<?php esc_html_e( $subject ); ?>" placeholder="" class="regular-text" id="subject" name="settings[subject]" />
  124. <p class="description"><?php _e( 'This sets the subject of the email that is sent.' , 'vfb-pro'); ?></p>
  125. </td>
  126. </tr>
  127. <tr valign="top">
  128. <th scope="row">
  129. <label for="email-to"><?php _e( 'Email To' , 'vfb-pro'); ?></label>
  130. </th>
  131. <td>
  132. <input type="email" value="<?php esc_html_e( $email_to ); ?>" placeholder="" class="regular-text" id="email-to" name="settings[email-to]" />
  133. <p class="description"><?php _e( 'Who to send the submitted data to.' , 'vfb-pro'); ?></p>
  134. </td>
  135. </tr>
  136. </tbody>
  137. </table>
  138. <h4><?php _e( 'Advanced Settings', 'vfb-pro' ); ?></h4>
  139. <p><?php _e( 'These settings allow you to modify or include additional email headers.', 'vfb-pro' ); ?></p>
  140. <table class="form-table">
  141. <tbody>
  142. <tr valign="top">
  143. <th scope="row">
  144. <label for="from-email"><?php _e( 'From Email' , 'vfb-pro'); ?></label>
  145. </th>
  146. <td>
  147. <input type="email" value="<?php esc_html_e( $from_email ); ?>" placeholder=""<?php echo $readonly; ?> class="regular-text required" id="from-email" name="settings[from-email]" maxlength="255" />
  148. <?php _e( 'or', 'vfb-pro' ); ?>
  149. <select id="from-email-user" name="settings[from-email-user]"<?php echo $disabled; ?>>
  150. <option value=""<?php selected( '', $from_email_user ); ?>></option>
  151. <?php
  152. if ( is_array( $email_fields ) && !empty( $email_fields ) ) {
  153. foreach ( $email_fields as $email ) {
  154. $label = isset( $email['data']['label'] ) ? $email['data']['label'] : '';
  155. $field_id = $email['id'];
  156. printf( '<option value="%1$d"%3$s>%1$d - %2$s</option>', $field_id, $label, selected( $field_id, $from_email_user, false ) );
  157. }
  158. }
  159. else {
  160. printf( '<option>(%s)</option>', __( 'No Email Fields Found', 'vfb-pro' ) );
  161. }
  162. ?>
  163. </select>
  164. <p class="description"><?php printf( __( 'This option sets the "From" email and can only be customized if <a href="%s">SMTP settings</a> have been configured.', 'vfb-pro' ), esc_url( admin_url( 'admin.php?page=vfbp-settings' ) ) ); ?></p>
  165. </td>
  166. </tr>
  167. <tr valign="top">
  168. <th scope="row">
  169. <label for="cc"><?php _e( 'Cc' , 'vfb-pro'); ?></label>
  170. </th>
  171. <td>
  172. <input type="email" value="<?php esc_html_e( $cc ); ?>" placeholder="" class="regular-text" id="cc" name="settings[cc]" maxlength="255" />
  173. </td>
  174. </tr>
  175. <tr valign="top">
  176. <th scope="row">
  177. <label for="bcc"><?php _e( 'Bcc' , 'vfb-pro'); ?></label>
  178. </th>
  179. <td>
  180. <input type="email" value="<?php esc_html_e( $bcc ); ?>" placeholder="" class="regular-text" id="bcc" name="settings[bcc]" maxlength="255" />
  181. </td>
  182. </tr>
  183. <tr valign="top">
  184. <th scope="row">
  185. <label for="send-attachments"><?php esc_html_e( 'Include Attachments', 'vfb-pro' ); ?></label>
  186. </th>
  187. <td>
  188. <fieldset>
  189. <label>
  190. <input type="hidden" name="settings[send-attachments]" value="0" /> <!-- This sends an unchecked value to the meta table -->
  191. <input type="checkbox" name="settings[send-attachments]" id="send-attachments" value="1"<?php checked( $send_attachments, 1 ); ?> /> <?php _e( "If File Uploads are present, include the uploaded files with the email.", 'vfb-pro' ); ?>
  192. </label>
  193. </fieldset>
  194. <p class="description">
  195. <?php _e( 'NOTE: Many servers restrict email attachment size to 25MB or even smaller.', 'vfb-pro' ); ?><br/>
  196. <?php _e( 'If you experience trouble sending or receiving emails with this setting on, reduce the File Upload max file size.', 'vfb-pro' ); ?>
  197. </p>
  198. </td>
  199. </tr>
  200. <tr valign="top">
  201. <th scope="row">
  202. <label for="template-tags"><?php esc_html_e( 'Template Tags', 'vfb-pro' ); ?></label>
  203. </th>
  204. <td>
  205. <p><?php _e( 'Templating is a way to dynamically replace specially formatted variables with data submitted from the form.', 'vfb-pro' ); ?></p>
  206. <a href="#TB_inline?width=1000&height=600&inlineId=vfb-template-tags" class="button thickbox">
  207. <?php _e( ' View Template Options', 'vfb-pro' ); ?>
  208. </a>
  209. <div id="vfb-template-tags" style="display: none;">
  210. <?php $this->template_tags( $this->id ); ?>
  211. </div> <!-- #vfb-template-tags -->
  212. </td>
  213. </tr>
  214. </tbody>
  215. </table>
  216. </div> <!-- .vfb-edit-section-inside -->
  217. </div> <!-- .vfb-edit-section -->
  218. <div class="vfb-edit-section">
  219. <div class="vfb-edit-section-inside">
  220. <h3><?php _e( 'Autoresponder', 'vfb-pro' ); ?></h3>
  221. <p><?php _e( 'Send an email to the person who completed the form.', 'vfb-pro' ); ?></p>
  222. <table class="form-table">
  223. <tbody>
  224. <tr valign="top">
  225. <th scope="row">
  226. <label for="notify-name"><?php _e( 'Your Name' , 'vfb-pro'); ?></label>
  227. </th>
  228. <td>
  229. <input type="text" value="<?php esc_html_e( $notify_name ); ?>" placeholder="" class="regular-text required" id="notify-name" name="settings[notify-name]" />
  230. <p class="description"><?php _e( 'This option sets the "From" display name of the email that is sent.' , 'vfb-pro'); ?></p>
  231. </td>
  232. </tr>
  233. <tr valign="top">
  234. <th scope="row">
  235. <label for="notify-email"><?php _e( 'Reply-To Email' , 'vfb-pro'); ?></label>
  236. </th>
  237. <td>
  238. <input type="email" value="<?php esc_html_e( $notify_email ); ?>" placeholder="" class="regular-text required" id="notify-email" name="settings[notify-email]" maxlength="255" />
  239. <p class="description"><?php _e( 'Replies to the submission email will go here.' , 'vfb-pro'); ?></p>
  240. </td>
  241. </tr>
  242. <tr valign="top">
  243. <th scope="row">
  244. <label for="notify-subject"><?php _e( 'Email Subject' , 'vfb-pro'); ?></label>
  245. </th>
  246. <td>
  247. <input type="text" value="<?php esc_html_e( $notify_subject ); ?>" placeholder="" class="regular-text" id="notify-subject" name="settings[notify-subject]" />
  248. <p class="description"><?php _e( 'This sets the subject of the email that is sent.' , 'vfb-pro'); ?></p>
  249. </td>
  250. </tr>
  251. <tr valign="top">
  252. <th scope="row">
  253. <label for="notify-email-to"><?php _e( 'Email To' , 'vfb-pro'); ?></label>
  254. </th>
  255. <td>
  256. <select id="notify-email-to" name="settings[notify-email-to]">
  257. <option value=""<?php selected( '', $notify_email_to ); ?>></option>
  258. <?php
  259. if ( is_array( $email_fields ) && !empty( $email_fields ) ) {
  260. foreach ( $email_fields as $email ) {
  261. $label = isset( $email['data']['label'] ) ? $email['data']['label'] : '';
  262. $field_id = $email['id'];
  263. printf( '<option value="%1$d"%3$s>%1$d - %2$s</option>', $field_id, $label, selected( $field_id, $notify_email_to, false ) );
  264. }
  265. }
  266. else {
  267. printf( '<option>(%s)</option>', __( 'No Email Fields Found', 'vfb-pro' ) );
  268. }
  269. ?>
  270. </select>
  271. <p class="description"><?php _e( 'Who to send the submitted data to.' , 'vfb-pro'); ?></p>
  272. </td>
  273. </tr>
  274. <tr valign="top">
  275. <th scope="row">
  276. <label for="notify-message"><?php _e( 'Message' , 'vfb-pro'); ?></label>
  277. </th>
  278. <td>
  279. <textarea id="notify-message" name="settings[notify-message]" class="large-text" rows="10"><?php echo $notify_message; ?></textarea>
  280. </td>
  281. </tr>
  282. <tr valign="top">
  283. <th scope="row">
  284. <label for="notify-entry-copy"><?php esc_html_e( 'Append Entry', 'vfb-pro' ); ?></label>
  285. </th>
  286. <td>
  287. <fieldset>
  288. <label>
  289. <input type="hidden" name="settings[notify-entry-copy]" value="0" /> <!-- This sends an unchecked value to the meta table -->
  290. <input type="checkbox" name="settings[notify-entry-copy]" id="notify-entry-copy" value="1"<?php checked( $notify_entry_copy, 1 ); ?> /> <?php _e( "Include a Copy of the User's Entry", 'vfb-pro' ); ?>
  291. </label>
  292. </fieldset>
  293. </td>
  294. </tr>
  295. </tbody>
  296. </table>
  297. </div> <!-- .vfb-edit-section-inside -->
  298. </div> <!-- .vfb-edit-section -->
  299. <?php
  300. submit_button(
  301. __( 'Save Changes', 'vfb-pro' ),
  302. 'primary',
  303. '' // leave blank so "name" attribute will not be added
  304. );
  305. ?>
  306. </form>
  307. <?php
  308. }
  309. /**
  310. * template_tags function.
  311. *
  312. * @access private
  313. * @param mixed $form_id
  314. * @return void
  315. */
  316. private function template_tags( $form_id ) {
  317. $tags = new VFB_Pro_Template_Tags( $form_id );
  318. $tags->display();
  319. }
  320. }