PluginProbe
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar / 2.1.22
Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar v2.1.22
2.1.22 2.1.21 2.1.20 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 trunk 1.1 2.0 2.0.1 2.0.10.2 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.2 2.0.20 2.0.21 All 56 releases
booking-manager / core / admin / exmpl-page-email-link-user.php

exmpl-page-email-link-user.php in Booking Manager – Sync WP Booking Calendar – Import Events, Export Bookings to ICS Calendar 2.1.22, at core/admin/exmpl-page-email-link-user.php

962 lines 54.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @version 1.0
4 * @package Content
5 * @category Menu
6 * @author wpdevelop
7 *
8 * @web-site https://oplugins.com/
9 * @email [email protected]
10 *
11 * @modified 2015-04-09
12 */
13
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15
16 /** Replace:
17 1. LinkUser -> LinkUser
18 2. LINK_USER -> LINK_USER
19 3. link_user -> link_user
20 4. Check in api-emails.php 'db_prefix_option' => '...' option, have to be the same as WPBM_EMAIL_LINK_USER_PREFIX here
21 5. Configure Fields in init_settings_fields.
22 */
23
24 if ( ! defined( 'WPBM_EMAIL_LINK_USER_PREFIX' ) ) define( 'WPBM_EMAIL_LINK_USER_PREFIX', 'wpbm_email_' ); // Its defined in api-emails.php file & its same for all emails, here its used only for easy coding...
25
26 if ( ! defined( 'WPBM_EMAIL_LINK_USER_ID' ) ) define( 'WPBM_EMAIL_LINK_USER_ID', 'link_user' ); /* Define Name of Email Template.
27 Note. Prefix "wpbm_email_" defined in api-emails.php file.
28 Full name of option is - "wpbm_email_link_user"
29 Other email templates names:
30 - 'link_user' - send email with download link to user
31 - 'link_admin' - send copy of email to admin with download link
32 - 'download_admin' - send email about downloads happend
33 */
34
35 require_once( WPBM_PLUGIN_DIR . '/core/any/api-emails.php' ); // API
36
37
38 /** Email F i e l d s */
39 class WPBM_Emails_API_LinkUser extends WPBM_Emails_API { // O v e r r i d i n g "WPBM_Emails_API" ClASS
40
41 /** Overrided functions - define Email Fields & Values */
42 public function init_settings_fields() {
43
44 $this->fields = array();
45
46 $this->fields['enabled'] = array(
47 'type' => 'checkbox'
48 , 'default' => 'On'
49 , 'title' => __('Enable / Disable', 'booking-manager')
50 , 'label' => __('Enable this email notification', 'booking-manager')
51 , 'description' => ''
52 , 'group' => 'general'
53
54 );
55
56 $this->fields['copy_to_admin'] = array(
57 'type' => 'checkbox'
58 , 'default' => 'On'
59 , 'title' => __('Copy to admin', 'booking-manager')
60 , 'label' => __('Enable / disable sending copy of this email notification to admin', 'booking-manager')
61 , 'description' => ''
62 , 'group' => 'general'
63
64 );
65
66 $this->fields['enabled_hr'] = array( 'type' => 'hr' );
67
68 $user_info = array( 'name' => '' );
69 if ( is_user_logged_in() ) {
70 $user_data = get_userdata( get_current_user_id() );
71 $user_info['name'] = ( $user_data ) ? $user_data->display_name : '';
72 }
73
74 /*
75 $this->fields['to_html_prefix'] = array(
76 'type' => 'pure_html'
77 , 'group' => 'general'
78 , 'html' => '<tr valign="top">
79 <th scope="row">
80 <label class="wpbm-form-email" for="'
81 . esc_attr( 'link_user_to' )
82 . '">' . wp_kses_post( __('To' , 'booking-manager') )
83 . '</label>
84 </th>
85 <td><fieldset style="float:left;width:50%;margin-right:5%;">'
86 );
87 $this->fields['to'] = array(
88 'type' => 'text' // We are using here 'text' and not 'email', for ability to save several comma seperated emails.
89 , 'default' => get_option( 'admin_email' )
90 //, 'placeholder' => ''
91 , 'title' => ''
92 , 'description' => __('Email Address', 'booking-manager') . '. ' . __('Required', 'booking-manager') . '.'
93 , 'description_tag' => ''
94 , 'css' => 'width:100%'
95 , 'group' => 'general'
96 , 'tr_class' => ''
97 , 'only_field' => true
98 , 'validate_as' => array( 'required' )
99 );
100 $this->fields['to_html_middle'] = array(
101 'type' => 'pure_html'
102 , 'group' => 'general'
103 , 'html' => '</fieldset><fieldset style="float:left;width:45%;">'
104 );
105 $this->fields['to_name'] = array(
106 'type' => 'text'
107 , 'default' => '' // $user_info['name']
108 //, 'placeholder' => ''
109 , 'title' => ''
110 , 'description' => __('Title', 'booking-manager') . ' (' . __('optional', 'booking-manager') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking-manager')
111 , 'description_tag' => ''
112 , 'css' => 'width:100%'
113 , 'group' => 'general'
114 , 'tr_class' => ''
115 , 'only_field' => true
116 );
117 $this->fields['to_html_sufix'] = array(
118 'type' => 'pure_html'
119 , 'group' => 'general'
120 , 'html' => ' </fieldset>
121 </td>
122 </tr>'
123 );
124 */
125
126
127 $this->fields['from_html_prefix'] = array(
128 'type' => 'pure_html'
129 , 'group' => 'general'
130 , 'html' => '<tr valign="top">
131 <th scope="row">
132 <label class="wpbm-form-email" for="'
133 . esc_attr( 'link_user_from' )
134 . '">' . wp_kses_post( __('From' , 'booking-manager') )
135 . '</label>
136 </th>
137 <td><fieldset style="float:left;width:50%;margin-right:5%;">'
138 );
139 $this->fields['from'] = array(
140 'type' => 'email' // Its can be only 1 email, so check it as Email field.
141 , 'default' => get_option( 'admin_email' )
142 //, 'placeholder' => ''
143 , 'title' => ''
144 , 'description' => __('Email Address', 'booking-manager') . '. ' . __('Required', 'booking-manager') . '.'
145 , 'description_tag' => ''
146 , 'css' => 'width:100%'
147 , 'group' => 'general'
148 , 'tr_class' => ''
149 , 'only_field' => true
150 , 'validate_as' => array( 'required' )
151 );
152 $this->fields['from_html_middle'] = array(
153 'type' => 'pure_html'
154 , 'group' => 'general'
155 , 'html' => '</fieldset><fieldset style="float:left;width:45%;">'
156 );
157 $this->fields['from_name'] = array(
158 'type' => 'text'
159 , 'default' => $user_info['name']
160 //, 'placeholder' => ''
161 , 'title' => ''
162 , 'description' => __('Title', 'booking-manager') . ' (' . __('optional', 'booking-manager') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking-manager')
163 , 'description_tag' => ''
164 , 'css' => 'width:100%'
165 , 'group' => 'general'
166 , 'tr_class' => ''
167 , 'only_field' => true
168 );
169 $this->fields['from_html_sufix'] = array(
170 'type' => 'pure_html'
171 , 'group' => 'general'
172 , 'html' => ' </fieldset>
173 </td>
174 </tr>'
175 );
176
177 $this->fields['from_hr'] = array( 'type' => 'hr' );
178
179
180 $this->fields['subject'] = array(
181 'type' => 'text'
182 // , 'default' => sprintf( __( 'Update of %s', 'booking-manager'), '[product_title]' )
183 , 'default' => sprintf( __( 'Delivery of %s', 'booking-manager'), '[product_title] [product_version]' )
184 //, 'placeholder' => ''
185 , 'title' => __('Subject', 'booking-manager')
186 , 'description' => sprintf(__('Type your email %ssubject%s.' , 'booking-manager'),'<b>','</b>') . ' ' . __('Required', 'booking-manager') . '.'
187 , 'description_tag' => ''
188 , 'css' => 'width:100%'
189 , 'group' => 'general'
190 , 'tr_class' => ''
191 , 'validate_as' => array( 'required' )
192 );
193
194 $blg_title = get_option( 'blogname' );
195 $blg_title = str_replace( array( '"', "'" ), '', $blg_title );
196
197 $this->fields['content'] = array(
198 'type' => 'wp_textarea'
199 // , 'default' => sprintf( __( 'Hello.%sTo download %s click the link below:%s (%s) ~ Download link will expire in %sThank you, %s', 'booking-manager')
200 // , '<br/><br/>', '[product_title]', '<br/>[product_link]', '[product_size]', '[product_expire_after]<br/><br/>', '[site_title]<br>[siteurl]' )
201 , 'default' => sprintf( __( 'Hello. %sThank you for requesting %s To download %s click the link below: %s Thank you, %s', 'booking-manager' )
202 , '<br/>'
203 , '[product_title] [product_version]<br/><br/>'
204 , '<strong>[product_description]</strong>'
205 , '<br/> --- <br/> [product_summary] - [product_expire_date] <br/> --- <br/> <br/> '
206 , '[siteurl]<br/> [current_date] [current_time]' )
207 //, 'placeholder' => ''
208 , 'title' => __('Content', 'booking-manager')
209 , 'description' => __('Type your email message content.', 'booking-manager')
210 , 'description_tag' => ''
211 , 'css' => ''
212 , 'group' => 'general'
213 , 'tr_class' => ''
214 , 'rows' => 10
215 , 'show_in_2_cols' => true
216 );
217 // $this->fields['content'] = htmlspecialchars( $this->fields['content'] );// Convert > to &gt;
218 // $this->fields['content'] = html_entity_decode( $this->fields['content'] );// Convert &gt; to >
219
220
221
222 ////////////////////////////////////////////////////////////////////
223 // Style
224 ////////////////////////////////////////////////////////////////////
225
226
227 $this->fields['header_content'] = array(
228 'type' => 'textarea'
229 , 'default' => ''
230 , 'title' => __('Email Heading', 'booking-manager')
231 , 'description' => __('Enter main heading contained within the email notification.', 'booking-manager')
232 //, 'placeholder' => ''
233 , 'rows' => 2
234 , 'css' => "width:100%;"
235 , 'group' => 'parts'
236 );
237 $this->fields['footer_content'] = array(
238 'type' => 'textarea'
239 , 'default' => ''
240 , 'title' => __('Email Footer Text', 'booking-manager')
241 , 'description' => __('Enter text contained within footer of the email notification', 'booking-manager')
242 //, 'placeholder' => ''
243 , 'rows' => 2
244 , 'css' => 'width:100%;'
245 , 'group' => 'parts'
246 );
247
248 $this->fields['template_file'] = array(
249 'type' => 'select'
250 , 'default' => 'plain'
251 , 'title' => __('Email template', 'booking-manager')
252 , 'description' => __('Choose email template.', 'booking-manager')
253 , 'description_tag' => 'span'
254 , 'css' => ''
255 , 'options' => array(
256 'plain' => __('Plain (without styles)', 'booking-manager')
257 , 'standard' => __('Standard 1 column', 'booking-manager')
258 )
259 , 'group' => 'style'
260 );
261
262 $this->fields['template_file_help'] = array(
263 'type' => 'help'
264 , 'value' => array( sprintf( __('You can override this email template in this folder %s', 'booking-manager')
265 , '<code>' . realpath( dirname(__FILE__) . '/../any/emails_tpl/' ) . '</code>' )
266 )
267 , 'cols' => 2
268 , 'group' => 'style'
269 );
270
271 $this->fields['base_color'] = array(
272 'type' => 'color'
273 , 'default' => '#557da1'
274 , 'title' => __('Base Color', 'booking-manager')
275 , 'description' => __('The base color for email templates.', 'booking-manager')
276 . ' ' . __('Default color', 'booking-manager') .': <code>#557da1</code>.'
277 , 'group' => 'style'
278 , 'tr_class' => 'template_colors'
279 );
280 $this->fields['background_color'] = array(
281 'type' => 'color'
282 , 'default' => '#f5f5f5'
283 , 'title' => __('Background Color', 'booking-manager')
284 , 'description' => __('The background color for email templates.', 'booking-manager')
285 . ' ' . __('Default color', 'booking-manager') .': <code>#f5f5f5</code>.'
286 , 'group' => 'style'
287 , 'tr_class' => 'template_colors'
288 );
289 $this->fields['body_color'] = array(
290 'type' => 'color'
291 , 'default' => '#fdfdfd'
292 , 'title' => __('Email Body Background Color', 'booking-manager')
293 , 'description' => __('The main body background color for email templates.', 'booking-manager')
294 . ' ' . __('Default color', 'booking-manager') .': <code>#fdfdfd</code>.'
295 , 'group' => 'style'
296 , 'tr_class' => 'template_colors'
297 );
298 $this->fields['text_color'] = array(
299 'type' => 'color'
300 , 'default' => '#505050'
301 , 'title' => __('Email Body Text Colour', 'booking-manager')
302 , 'description' => __('The main body text color for email templates.', 'booking-manager')
303 . ' ' . __('Default color', 'booking-manager') .': <code>#505050</code>.'
304 , 'group' => 'style'
305 , 'tr_class' => 'template_colors'
306 );
307
308
309 ////////////////////////////////////////////////////////////////////
310 // Email format: Plain, HTML, MultiPart
311 ////////////////////////////////////////////////////////////////////
312
313
314 $this->fields['email_content_type'] = array(
315 'type' => 'select'
316 , 'default' => 'plain'
317 , 'title' => __('Email format', 'booking-manager')
318 , 'description' => __('Choose which format of email to send.', 'booking-manager')
319 , 'description_tag' => 'p'
320 , 'css' => 'width:100%;'
321 , 'options' => array(
322 'plain' => __('Plain text', 'booking-manager')
323 // , 'html' => __('HTML', 'booking-manager')
324 // , 'multipart' => __('Multipart', 'booking-manager')
325 )
326 , 'group' => 'email_content_type'
327 );
328 if ( class_exists( 'DOMDocument' ) ) {
329 $this->fields['email_content_type']['options']['html'] = __('HTML', 'booking-manager');
330 $this->fields['email_content_type']['options']['multipart'] = __('Multipart', 'booking-manager');
331
332 $this->fields['email_content_type']['default'] = 'html';
333 }
334
335
336
337 ////////////////////////////////////////////////////////////////////
338 // Help
339 ////////////////////////////////////////////////////////////////////
340
341 $this->fields['content_help'] = array(
342 'type' => 'help'
343 , 'value' => array()
344 , 'cols' => 2
345 , 'group' => 'help'
346 );
347
348 $skip_shortcodes = array(
349 'denyreason'
350 , 'paymentreason'
351 , 'visitorediturl'
352 , 'visitorcancelurl'
353 , 'visitorpayurl'
354 );
355 $email_example = sprintf(__('For example: "You have a new reservation %s on the following date(s): %s Contact information: %s You can approve or cancel this item at: %s Thank you, Reservation service."' , 'booking-manager'),'','[dates]&lt;br/&gt;&lt;br/&gt;','&lt;br/&gt; [content]&lt;br/&gt;&lt;br/&gt;', htmlentities( ' <a href="[moderatelink]">'.__('here' , 'booking-manager').'</a> ') . '&lt;br/&gt;&lt;br/&gt; ');
356
357 // $help_fields = wpbm_get_email_help_shortcodes( $skip_shortcodes, $email_example );
358 //
359 // foreach ( $help_fields as $help_fields_key => $help_fields_value ) {
360 // $this->fields['content_help']['value'][] = $help_fields_value;
361 // }
362
363 }
364
365 }
366
367
368
369 /** Settings Emails P a g e */
370 class WPBM_Settings_Page_Email_LinkUser extends WPBM_Page_Structure {
371
372 public $email_settings_api = false;
373
374
375 /** Define interface for Email API
376 *
377 * @param string $selected_email_name - name of Email template
378 * @param array $init_fields_values - array of init form fields data
379 * @return object Email API
380 */
381 public function mail_api( $selected_email_name ='', $init_fields_values = array() ){
382
383 if ( $this->email_settings_api === false ) {
384 $this->email_settings_api = new WPBM_Emails_API_LinkUser( $selected_email_name , $init_fields_values );
385 }
386
387 return $this->email_settings_api;
388 }
389
390
391 public function in_page() { // P a g e t a g
392 return 'wpbm-settings';
393 }
394
395
396 public function tabs() { // T a b s A r r a y
397
398 $tabs = array();
399
400 $tabs[ 'email' ] = array(
401 'title' => __( 'Emails', 'booking-manager') // Title of TAB
402 , 'page_title'=> __( 'Emails Settings', 'booking-manager') // Title of Page
403 , 'hint' => __( 'Emails Settings', 'booking-manager') // Hint
404 //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
405 //, 'position' => '' // 'left' || 'right' || ''
406 //, 'css_classes'=> '' // CSS class(es)
407 //, 'icon' => '' // Icon - link to the real PNG img
408 , 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of forn Icon
409 //, 'default' => false // Is this tab activated by default or not: true || false.
410 //, 'disabled' => false // Is this tab disbaled: true || false.
411 //, 'hided' => false // Is this tab hided: true || false.
412 , 'subtabs' => array()
413 );
414
415 $subtabs = array();
416
417
418 $is_data_exist = get_wpbm_option( WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID ); // ''wpbm_email_' - defined in api-emails.php file.
419 if ( ( ! empty( $is_data_exist ) ) && ( isset( $is_data_exist['enabled'] ) ) && ( $is_data_exist['enabled'] == 'On' ) )
420 $icon = '<i class="menu_icon icon-1x glyphicon glyphicon-check"></i> &nbsp; ';
421 else
422 $icon = '<i class="menu_icon icon-1x glyphicon glyphicon-unchecked"></i> &nbsp; ';
423
424 $subtabs['link-user'] = array(
425 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
426 , 'title' => $icon . __('To User' , 'booking-manager') // Title of TAB
427 , 'page_title' => __('Emails Settings', 'booking-manager') // Title of Page
428 , 'hint' => __('Email with download link, which is sending to user' , 'booking-manager') // Hint
429 , 'link' => '' // link
430 , 'position' => '' // 'left' || 'right' || ''
431 , 'css_classes' => '' // CSS class(es)
432 //, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
433 //, 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of Font Icon
434 , 'default' => true // Is this sub tab activated by default or not: true || false.
435 , 'disabled' => false // Is this sub tab deactivated: true || false.
436 , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
437 , 'content' => 'content' // Function to load as conten of this TAB
438 );
439
440 $tabs[ 'email' ]['subtabs'] = $subtabs;
441
442 return $tabs;
443 }
444
445
446 /** Show Content of Settings page */
447 public function content() {
448 //debuge( 'WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID, get_wpbm_option( WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID )', WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID, get_wpbm_option( WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID ) );
449
450 $this->css();
451
452 ////////////////////////////////////////////////////////////////////////
453 // Checking
454 ////////////////////////////////////////////////////////////////////////
455
456 do_action( 'wpbm_hook_settings_page_header', array( 'page' => $this->in_page(), 'subpage' => 'emails_settings' ) ); // Define Notices Section and show some static messages, if needed.
457
458
459
460 ////////////////////////////////////////////////////////////////////////
461 // Load Data
462 ////////////////////////////////////////////////////////////////////////
463
464 /** Its will load DATA from DB, during creattion mail_api CLASS
465 * during initial activation of the API its try to get option from DB
466 * We need to define this API before checking POST, to know all available fields
467 * Define Email Name & define field values from DB, if not exist, then default values.
468 Array (
469 [wpbm_email_link_user] => Array
470 (
471 [enabled] => On
472 [to] => [email protected]
473 [to_name] => 'Some name'
474 [from] => [email protected]
475 [from_name] =>
476 [subject] => New item
477 [content] => You need to approve [shortcodetype] for: [dates]...
478 [header_content] =>
479 [footer_content] =>
480 [template_file] => plain
481 [base_color] => #557da1
482 [background_color] => #f5f5f5
483 [body_color] => #fdfdfd
484 [text_color] => #505050
485 [email_content_type] => html
486 )
487 )
488
489 // $mail_api->save_to_db( $fields_values );
490 */
491 $init_fields_values = array();
492
493 $this->mail_api( WPBM_EMAIL_LINK_USER_ID, $init_fields_values );
494
495
496 ////////////////////////////////////////////////////////////////////////
497 // S u b m i t Actions - S e n d
498 ////////////////////////////////////////////////////////////////////////
499
500 $submit_form_name_action = 'wpbm_form_action'; // Define form name
501 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name_action ] ) ) {
502
503 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
504 $nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name_action ); // Its stop show anything on submiting, if its not refear to the original page
505
506 // Save Changes
507 $this->update_actions();
508 }
509 ?>
510 <form name="<?php echo $submit_form_name_action; ?>" id="<?php echo $submit_form_name_action; ?>" action="" method="post" autocomplete="off">
511 <?php
512 // N o n c e field, and key for checking S u b m i t
513 wp_nonce_field( 'wpbm_settings_page_' . $submit_form_name_action );
514 ?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name_action; ?>" id="is_form_sbmitted_<?php echo $submit_form_name_action; ?>" value="1" />
515 <input type="hidden" name="form_action" id="form_action" value="" />
516 </form>
517 <?php
518
519
520 ////////////////////////////////////////////////////////////////////////
521 // S u b m i t Main Form
522 ////////////////////////////////////////////////////////////////////////
523
524 $submit_form_name = 'wpbm_emails_template'; // Define form name
525
526 $this->mail_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields before submit.
527
528 if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
529
530 // Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
531 $nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page
532
533 // Save Changes
534 $this->update();
535 }
536
537
538 ////////////////////////////////////////////////////////////////////////
539 // JavaScript: Tooltips, Popover, Datepick (js & css)
540 ////////////////////////////////////////////////////////////////////////
541
542 echo '<span class="wpdevelop">';
543
544 wpbm_js_for_items_page();
545
546 echo '</span>';
547
548
549 ////////////////////////////////////////////////////////////////////////
550 // Content
551 ////////////////////////////////////////////////////////////////////////
552 ?>
553 <div class="clear" style="margin-bottom:10px;"></div>
554
555 <span class="metabox-holder">
556
557 <form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post" autocomplete="off">
558 <?php
559 // N o n c e field, and key for checking S u b m i t
560 wp_nonce_field( 'wpbm_settings_page_' . $submit_form_name );
561 ?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" />
562
563
564 <div class="clear"></div>
565 <div class="metabox-holder">
566
567 <div class="wpbm_settings_row wpbm_settings_row_left" >
568 <?php
569
570 wpbm_open_meta_box_section( $submit_form_name . 'general', __('Email with download link, which is sending to user', 'booking-manager') );
571
572 $this->mail_api()->show( 'general' );
573
574 wpbm_close_meta_box_section();
575
576
577 wpbm_open_meta_box_section( $submit_form_name . 'parts' , __('Header / Footer', 'booking-manager') );
578
579 $this->mail_api()->show( 'parts' );
580
581 wpbm_close_meta_box_section();
582
583
584 wpbm_open_meta_box_section( $submit_form_name . 'style' , __('Email Styles', 'booking-manager') );
585
586 $this->mail_api()->show( 'style' );
587
588 wpbm_close_meta_box_section();
589
590 ?>
591 </div>
592
593 <div class="wpbm_settings_row wpbm_settings_row_right">
594 <?php
595
596 wpbm_open_meta_box_section( $submit_form_name . 'actions', __('Actions', 'booking-manager') );
597
598 ?><a class="button button-secondary" style="margin:0 0 5px;" href="javascript:void(0)"
599 onclick="javascript: jQuery('#form_action').val('test_send'); jQuery('form#<?php echo $submit_form_name_action; ?>').trigger( 'submit' );"
600 ><?php _e('Send Test Email', 'booking-manager'); ?></a><?php
601
602 ?><input type="submit" value="<?php _e('Save Changes', 'booking-manager'); ?>" class="button button-primary right" style="margin:0 0 5px 5px;" /><?php
603
604 /* ?>
605 <a class="button button-secondary" href="javascript:void(0)" ><?php _e('Preview Email', 'booking-manager'); ?></a>
606 <hr />
607 <a class="button button-secondary right"
608 href="javascript:void(0)"
609 onclick="javascript: if ( wpbm_are_you_sure('<?php echo esc_js(__('Do you really want to delete this item?', 'booking-manager')); ?>') ){
610 jQuery('#form_action').val('delete');
611 jQuery('form#<?php echo $submit_form_name_action; ?>').trigger( 'submit' );
612 }"
613 ><?php _e('Delete Email', 'booking-manager'); ?></a>
614 <?php */
615
616 ?><div class="clear"></div><?php
617
618 wpbm_close_meta_box_section();
619
620 wpbm_open_meta_box_section( $submit_form_name . 'email_content_type', __('Type', 'booking-manager') );
621
622 $this->mail_api()->show( 'email_content_type' );
623
624 wpbm_close_meta_box_section();
625
626
627 wpbm_open_meta_box_section( $submit_form_name . 'help', __('Help', 'booking-manager') );
628
629 $this->mail_api()->show( 'help' );
630
631 wpbm_close_meta_box_section();
632
633 ?>
634 </div>
635 <div class="clear"></div>
636 </div>
637
638 <input type="submit" value="<?php _e('Save Changes', 'booking-manager'); ?>" class="button button-primary" />
639 </form>
640 </span>
641 <?php
642
643 $this->enqueue_js();
644 }
645
646
647 /**
648 * Update form from Toolbar - create / delete/ load email templates
649 *
650 * @return boolean
651 */
652 public function update_actions( ) {
653
654
655 if ( $_POST['form_action'] == 'test_send' ) { // Sending test email
656
657 /*
658 $this->email_settings_api = false;
659 $selected_email_name = 'standard';
660 $email_fields = get_wpbm_option( 'wpbm_email_' . $selected_email_name );
661 $this->mail_api( $selected_email_name, $email_fields );
662 */
663
664
665 //$to = sanitize_email( $this->mail_api()->fields_values['to'] );
666
667 $replace = array();
668 $replace[ 'product_id' ] = '<strong>99</strong>';
669 $replace[ 'product_title' ] = '<strong>Product ZZZ</strong>';
670 $replace[ 'product_version' ] = '<strong>1.0</strong>';
671 $replace[ 'product_description' ] = 'Product ZZZ Info';
672 $replace[ 'product_filename' ] = 'zzz_product.zip';
673 $replace[ 'product_link' ] = home_url();
674 $replace[ 'product_size' ] = '3 Mb';
675 $replace[ 'product_expire_after' ] = '1 day';
676 $replace[ 'product_expire_date' ] = date_i18n( get_wpbm_option( 'wpbm_date_format' ) . ' ' . get_wpbm_option( 'wpbm_time_format' ), strtotime( '+1 day' ) );
677 $replace[ 'product_summary' ] = '<a href="">' . $replace[ 'product_filename' ] . '</a> (' . $replace[ 'product_size' ] . ') ~ expire in ' . $replace[ 'product_expire_after' ];
678
679 $replace[ 'link_sent_to' ] = $this->mail_api()->get_from__email_address();
680
681 $replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . home_url() . '">' . home_url() . '</a>' );
682 $replace[ 'remote_ip' ] = wpbm_get_user_ip(); // The IP address from which the user is viewing the current page.
683 $replace[ 'user_agent' ] = $_SERVER[ 'HTTP_USER_AGENT' ]; // Contents of the User-Agent: header from the current request, if there is one.
684 $replace[ 'request_url' ] = $_SERVER[ 'HTTP_REFERER' ]; // The address of the page (if any) where action was occured. Because we are sending it in Ajax request, we need to use the REFERER HTTP
685 $replace[ 'current_date' ] = date_i18n( get_wpbm_option( 'wpbm_date_format' ) );
686 $replace[ 'current_time' ] = date_i18n( get_wpbm_option( 'wpbm_time_format' ) );
687
688
689
690 $to = $this->mail_api()->get_from__email_address();
691 $to_name = $this->mail_api()->get_from__name();
692 $to = trim( $to_name ) . ' <' . $to . '> ';
693
694 $email_result = $this->mail_api()->send( $to , $replace );
695
696 if ( $email_result )
697 wpbm_show_message ( __('Email sent to ', 'booking-manager') . ' ' . $this->mail_api()->get_from__email_address() , 5 );
698 else
699 wpbm_show_message ( __('Email was not sent. An error occurred.', 'booking-manager'), 5 ,'error' );
700 }
701
702 /*
703 if ( $_POST['form_action'] == 'create' ) { // Create
704
705 $email_title = esc_attr( $_POST['create_email_template'] );
706 $email_name = wpbm_get_slug_format_4_option_name( $email_title );
707
708 $wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' );
709 if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array();
710
711
712 if ( empty($email_name) || isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error
713 wpbm_show_message ( __('Email template has not added.', 'booking-manager'), 5 , 'error' );
714 return false;
715 }
716
717 $wpbm_email_tpl_names[ $email_name ]= stripslashes( $email_title );
718
719 update_wpbm_option( 'wpbm_email_tpl_names', $wpbm_email_tpl_names );
720
721 wpbm_show_message ( __('Email template added successfully', 'booking-manager'), 5 ); // Show Save message
722
723 $redir = esc_url( add_query_arg( array('email_template' => $email_name ), html_entity_decode( $this->getUrl() ) ) );
724
725 wpbm_reload_page_by_js( $redir );
726
727 return true;
728 }
729
730 if ( $_POST['form_action'] == 'delete' ) { // Delete
731 $email_name = esc_attr( $_POST['select_email_template'] );
732
733 $wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' );
734 if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array();
735
736 if ( ! isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error
737 wpbm_show_message ( __('Email template does not exist.', 'booking-manager'), 5 , 'error' );
738 return false;
739 }
740
741 unset($wpbm_email_tpl_names[ $email_name ]); // Remove Email name from list of email names
742 update_wpbm_option( 'wpbm_email_tpl_names', $wpbm_email_tpl_names );
743
744 delete_wpbm_option( 'wpbm_email_' . $email_name ); // Delete Email Template
745
746 wpbm_show_message ( __('Email template deleted successfully', 'booking-manager'), 5 ); // Show Save message
747
748
749 $redir = esc_url( remove_query_arg( array( 'email_template' ), html_entity_decode( $this->getUrl() ) ) ); // Load standard email template
750
751 wpbm_reload_page_by_js( $redir );
752
753 return true;
754
755 }
756
757 if ( $_POST['form_action'] == 'load' ) { // Load
758 $email_name = $_POST['select_email_template'];
759
760 $wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' );
761 if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array();
762
763 if ( ! isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error
764 wpbm_show_message ( __('Email template does not exist.', 'booking-manager'), 5 , 'error' );
765 return false;
766 }
767
768 }
769 */
770 }
771
772
773 /** Update Email template to DB */
774 public function update() {
775
776 // Get Validated Email fields
777 $validated_fields = $this->mail_api()->validate_post();
778
779 // Remove <p> at begining and </p> at END of email template.
780 if (
781 ( substr( $validated_fields['content'], 0, 3) === '<p>' )
782 && ( substr( $validated_fields['content'], -4 ) === '</p>' )
783 ) {
784 $validated_fields['content'] = substr ( $validated_fields['content'], 3, ( strlen ( $validated_fields['content'] ) - 7 ) );
785 }
786
787 $this->mail_api()->save_to_db( $validated_fields );
788
789 wpbm_show_message ( __('Settings saved.', 'booking-manager'), 5 ); // Show Save message
790 }
791
792 // <editor-fold defaultstate="collapsed" desc=" CSS & JS " >
793
794 /** CSS for this page */
795 private function css() {
796 ?>
797 <style type="text/css">
798 .wpbm-help-message {
799 border:none;
800 margin:0 !important;
801 padding:0 !important;
802 }
803
804 @media (max-width: 399px) {
805 }
806 </style>
807 <?php
808 }
809
810
811
812 /** Add Custon JavaScript - for some specific settings options
813 * Executed After post content, after initial definition of settings, and possible definition after POST request.
814 *
815 * @param type $menu_slug
816 *
817 */
818 private function enqueue_js(){ // $page_tag, $active_page_tab, $active_page_subtab ) {
819
820
821
822 // Check if this correct page /////////////////////////////////////////////
823
824 // if ( !(
825 // ( $page_tag == 'wpbm-settings') // Load only at 'wpbm-settings' menu
826 // && ( $_GET['tab'] == 'email' ) // At ''general' tab
827 // && ( ( ! isset( $_GET['subtab'] ) ) || ( $_GET['subtab'] == 'new-admin' ) )
828 // )
829 // ) return;
830
831 // JavaScript //////////////////////////////////////////////////////////////
832
833 $js_script = '';
834 //Show or hide colors section in settings page depend form selected email template.
835 $js_script .= " jQuery('select[name=\"link_user_template_file\"]').on( 'change', function(){
836 if ( jQuery('select[name=\"link_user_template_file\"] option:selected').val() == 'plain' ) {
837 jQuery('.template_colors').hide();
838 } else {
839 jQuery('.template_colors').show();
840 }
841 } ); ";
842 $js_script .= "\n"; //New Line
843 $js_script .= " if ( jQuery('select[name=\"link_user_template_file\"] option:selected').val() == 'plain' ) {
844 jQuery('.template_colors').hide();
845 } ";
846
847 // Show Warning messages if Title (optional) is empty - title of email will be "WordPress
848 $js_script .= " jQuery(document).ready(function(){ ";
849 $js_script .= " if ( jQuery('#link_user_to_name').val() == '' ) {";
850 $js_script .= " jQuery('#link_user_to_name').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('If empty then title defined as WordPress', 'booking-manager'))."</div>')";
851 $js_script .= " }";
852 $js_script .= " if ( jQuery('#link_user_from_name').val() == '' ) {";
853 $js_script .= " jQuery('#link_user_from_name').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('If empty then title defined as WordPress', 'booking-manager'))."</div>')";
854 $js_script .= " }";
855 $js_script .= " }); ";
856 // Show Warning messages if "From" Email DNS different from current website DNS
857 $js_script .= " jQuery(document).ready(function(){ ";
858
859 $js_script .= " var wpbm_email_from = jQuery('#link_user_from').val();"; // [email protected]
860 $js_script .= " wpbm_email_from = wpbm_email_from.split('@');"; // ['from', 'oplugins.com']
861 $js_script .= " wpbm_email_from.shift();"; // ['oplugins.com']
862 $js_script .= " wpbm_email_from = wpbm_email_from.join('');"; // 'oplugins.com'
863
864 $js_script .= " var wpbm_website_dns = jQuery(location).attr('hostname');"; // server.com
865 $js_script .= " if ( wpbm_email_from != wpbm_website_dns ) {";
866 $js_script .= " jQuery('#link_user_from').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('Email different from website DNS, its can be a reason of not delivery emails. Please use the email withing the same domain as your website!', 'booking-manager'))."</div>')";
867 $js_script .= " }";
868
869 $js_script .= " }); ";
870
871
872
873 // Eneque JS to the footer of the page
874 wpbm_enqueue_js( $js_script );
875 }
876
877
878 // </editor-fold>
879 }
880 add_action('wpbm_menu_created', array( new WPBM_Settings_Page_Email_LinkUser() , '__construct') ); // Executed after creation of Menu
881
882
883
884 // <editor-fold defaultstate="collapsed" desc=" Emails Sending After New item " >
885
886 function wpbm_send_email_to_user_notification( $replace = array(), $email_to = '', $send_copy_to_admin = 'Off' ) {
887
888
889 ////////////////////////////////////////////////////////////////////////
890 // Load Data
891 ////////////////////////////////////////////////////////////////////////
892
893 /* Check if New Email Template Exist or NOT
894 * Exist - return empty array in format: array( OPTION_NAME => array() )
895 * Its will load DATA from DB, during creattion mail_api CLASS
896 * during initial activation of the API its try to get option from DB
897 * We need to define this API before checking POST, to know all available fields
898 * Define Email Name & define field values from DB, if not exist, then default values.
899 * Not Exist - import Old Data from DB
900 * or get "default" data from settings and return array with this data
901 * This data its initial parameters for definition fields in mail_api CLASS
902 *
903 */
904
905 $init_fields_values = array();//wpbm_import6_email__link_user__get_fields_array_for_activation();
906
907 // Get Value of first element - array of default or imported OLD data, because need only array of values without key - name of options for wp_options table
908 //$init_fields_values = array_shift( array_values( $init_fields_values ) );
909
910 $mail_api = new WPBM_Emails_API_LinkUser( WPBM_EMAIL_LINK_USER_ID, $init_fields_values );
911
912 ////////////////////////////////////////////////////////////////////////////
913
914 if ( $mail_api->fields_values['enabled'] == 'Off' ) return false; // Email template deactivated - exit.
915
916 add_filter( 'wpbm_email_api_is_allow_send_copy' , 'wpbm_email_api_is_allow_send_copy_block' , 10, 3);
917
918
919 if ( ! empty( $replace['to'] ) )
920 $valid_email = sanitize_email( $replace['to'] );
921
922 if ( ! empty( $email_to ) )
923 $valid_email = sanitize_email( $email_to );
924
925 if ( empty( $valid_email ) ) return $mail_api; //return false;
926
927 if ( ! empty( $replace['to_name'] ) )
928 $email_to_name = trim( wp_specialchars_decode( esc_html( stripslashes( $replace['to_name'] ) ), ENT_QUOTES ) );
929 else
930 $email_to_name = '';
931
932 $to = $email_to_name . ' <' . $valid_email . '> ';
933
934 $email_result = $mail_api->send( $to , $replace );
935
936 // Send copy of email to admin also to "From" email address
937 if ( $send_copy_to_admin == 'On') {
938 $subject = $mail_api->get_field_value('subject');
939 $mail_api->set_field_value('subject', __('Email copy to', 'booking-manager') . ': ' . $valid_email . ' ' . $subject );
940 $email_result = $mail_api->send( $mail_api->get_from__email_address() , $replace );
941 $mail_api->set_field_value('subject', $subject );
942 }
943
944 //debuge( (int) $email_result, $to , $replace);
945
946 return $mail_api;
947
948 }
949
950
951 /** Block Sending copy of email to Admin, based on WPBM_Emails_API interface, instead of that we will sent it manually from wpbm_send_email_to_user_notification function
952 *
953 * @param boolean $is_send_email
954 * @param type $id
955 * @param type $fields_values
956 * @return boolean
957 */
958 function wpbm_email_api_is_allow_send_copy_block( $is_send_email, $id, $fields_values ) {
959 $is_send_email = false;
960 return $is_send_email;
961 }
962 // </editor-fold>