<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals

if ( ! defined( 'ABSPATH' ) ) {
	 exit;
}

$dbhandler = new WPEFB_DBhandler();
?>

<div class="advrf-wrapper wrap wef-forms-modern wef-dashboard-modern wef-configure-modern">
    <div class="advrf-page-title">		 
        <h1 class="wpefb-page-heading">
             <?php esc_html_e( 'Email Configuration', 'vedrixa-forms-registration-builder' ); ?></h1>
        <ul class="advrf-nav">
            <li class="advrf-nav-item">
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpefb_global_settings' ) ); ?>">
                    <span class="dashicons dashicons-admin-generic"></span>
                    <?php esc_html_e( 'Global Settings', 'vedrixa-forms-registration-builder' ); ?></a>
            </li>
            <li class="advrf-nav-item">
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpefb_manage_forms' ) ); ?>">
                    <span class="dashicons dashicons-feedback"></span>
                    <?php esc_html_e( 'All Forms', 'vedrixa-forms-registration-builder' ); ?></a>
            </li>    
        </ul>

    </div>
    <div class="clearfix">
        <div class="advrf-form-conf-wrapper">
            <?php if ( absint( filter_input( INPUT_GET, 'updated', FILTER_SANITIZE_NUMBER_INT ) ) ) : ?>
                <div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Email configuration saved.', 'vedrixa-forms-registration-builder' ); ?></p></div>
            <?php endif; ?>
            <form action="" method="post" id="advrf_configuration_form">
                <fieldset class="advrf-config-wrap">
                    <div>

                        <div class="group-wrap">

                            
                            <div class="advrf-row">
                                <div class="advrf-control-label">
                                    <label><?php esc_html_e( 'Notify User about Submission Notes', 'vedrixa-forms-registration-builder' ); ?></label>
                                </div>
                                <div class="advrf-control advrf-has-child">
                                    <input class="advrf_toggle"  type="checkbox" value="1" id="wpefb_notify_user_submission" name="wpefb_notify_user_submission" data-has-child="1" <?php checked( $dbhandler->get_global_option_value( 'wpefb_notify_user_submission' ), '1' ); ?> />
                                    <label></label>
                                    <p class="description"><?php esc_html_e( 'Email notification will be send to the users if you add a User Note to one of their submissions.', 'vedrixa-forms-registration-builder' ); ?></p>
                                </div>  
                            </div>
                            
                            <div class="advrf-row">
                                <div class="advrf-control-label">
                                    <label><?php esc_html_e( 'Notify Site Admin', 'vedrixa-forms-registration-builder' ); ?></label>
                                </div>
                                <div class="advrf-control advrf-has-child">
                                    <input class="advrf_toggle"  type="checkbox" value="1" id="wpefb_notify_site_admin" name="wpefb_notify_site_admin" data-has-child="1" <?php checked( $dbhandler->get_global_option_value( 'wpefb_notify_site_admin' ), '1' ); ?> onclick="wef_show_hide(this, 'wpefb_notify_site_admin_html')" />
                                    <label></label>
                                    <p class="description"><?php esc_html_e( 'An email notification will be sent to Admin of this site for every form submission.', 'vedrixa-forms-registration-builder' ); ?></p>
                                </div>  
                            </div>

                            <div class="advrf-child-rows" id="wpefb_notify_site_admin_html" style="<?php echo !empty( $dbhandler->get_global_option_value( 'wpefb_notify_site_admin' ) ) ? '' : 'display:none'; ?>">

                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Define Recipients Manually', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="email" class="advrf-input-field" id="wpefb_define_recipients" name="wpefb_define_recipients" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_define_recipients' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'Add people who you want to receive notifications for form submissions.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>


                            </div>
                            
                            <div class="advrf-row">
							<div class="advrf-control-label">
								<label><?php esc_html_e( 'Outgoing Emails Handler', 'vedrixa-forms-registration-builder' ); ?></label>
							</div>
							<div class="advrf-control advrf-has-child">
                                <div class="wef-radio-group">
                                    <label class="wef-radio-option">
                                        <input type="radio" value="smtp" name="wpefb_outgoing_emails" data-child-index="-1" <?php checked( $dbhandler->get_global_option_value( 'wpefb_outgoing_emails' ), 'smtp' ); ?> onclick="wef_show_hide(this,'wpefb_outgoing_emails_smtp_html','wpefb_outgoing_emails_wordpress_html')" />
                                        <span><?php esc_html_e( 'External SMTP', 'vedrixa-forms-registration-builder' ); ?></span>
                                    </label>
                                    <label class="wef-radio-option">
                                        <input type="radio" value="WordPress" name="wpefb_outgoing_emails"  data-child-index="1" <?php checked( $dbhandler->get_global_option_value( 'wpefb_outgoing_emails', 'WordPress' ), 'WordPress' ); ?> onclick="wef_show_hide(this,'wpefb_outgoing_emails_wordpress_html','wpefb_outgoing_emails_smtp_html')"/>
                                        <span><?php esc_html_e( 'WordPress Default', 'vedrixa-forms-registration-builder' ); ?></span>
                                    </label>
                                </div>
							</div>  
						</div>
                            
                            <div class="advrf-child-rows" id="wpefb_outgoing_emails_smtp_html" style="<?php echo ( $dbhandler->get_global_option_value( 'wpefb_outgoing_emails', 'WordPress' )== 'smtp' ) ? '' : 'display:none'; ?>">
                                
                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'SMTP Host', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="text" class="advrf-input-field" id="wpefb_smtp_host" name="wpefb_smtp_host" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_smtp_host' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'Specify host address for SMTP. For example, smtp.gmail.com .', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>
                                
                                <div class="advrf-row">
                                <div class="advrf-control-label">
                                    <label><?php esc_html_e( 'Encryption Type', 'vedrixa-forms-registration-builder' ); ?></label>
                                </div>
                                <div class="advrf-control">
                                    <select name="wpefb_encryption_type" id="wpefb_encryption_type" class="advrf-input-field">
                                        <option value="none"><?php esc_html_e( 'None', 'vedrixa-forms-registration-builder' ); ?></option>
                                        <option value="enc_tls" <?php selected( $dbhandler->get_global_option_value( 'wpefb_encryption_type' ), 'enc_tls' ); ?>><?php esc_html_e( 'TLS', 'vedrixa-forms-registration-builder' ); ?></option>
                                        <option value="enc_ssl" <?php selected( $dbhandler->get_global_option_value( 'wpefb_encryption_type' ), 'enc_ssl' ); ?>><?php esc_html_e( 'SSL', 'vedrixa-forms-registration-builder' ); ?></option>
                                        </select>
                                    <p class="description"><?php echo esc_html__( 'Specify the type of encryption used by your SMTP service provider. ', 'vedrixa-forms-registration-builder' ); ?></p>
                                </div>
                            </div>
                                
                                <div class="advrf-row">
                                <div class="advrf-control-label">
                                    <label><?php esc_html_e( 'SMTP Port', 'vedrixa-forms-registration-builder' ); ?></label>
                                </div>
                                <div class="advrf-control">
                                    <input class="advrf-input-field" type="number" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_smtp_port' ) ); ?>" min="0" id="wpefb_smtp_port" name="wpefb_smtp_port" />
                                    <p class="description">
                                        <?php esc_html_e( 'Specify port number for SMTP.', 'vedrixa-forms-registration-builder' ); ?>
                                    </p>
                                </div>
                            </div>
                                
                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Sender\'s Email', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="email" class="advrf-input-field" id="wpefb_smtp_sender_email" name="wpefb_smtp_sender_email" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_smtp_sender_email' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'The sender\'s email address in the message header that the user will receive.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>
                                
                                <div class="advrf-row">
                                <div class="advrf-control-label">
                                    <label><?php esc_html_e( 'Authentication', 'vedrixa-forms-registration-builder' ); ?></label>
                                </div>
                                <div class="advrf-control advrf-has-child">
                                    <input class="advrf_toggle"  type="checkbox" value="1" id="wpefb_smtp_authentication" name="wpefb_smtp_authentication" data-has-child="1" <?php checked( $dbhandler->get_global_option_value( 'wpefb_smtp_authentication' ), '1' ); ?> onclick="wef_show_hide(this, 'wpefb_smtp_authentication_html')" />
                                    <label></label>
                                    <p class="description"><?php esc_html_e( 'Please check this if authentication is required at SMTP server. Also, provide credential in the following fields.', 'vedrixa-forms-registration-builder' ); ?></p>
                                </div>  
                            </div>

                            <div class="advrf-child-rows" id="wpefb_smtp_authentication_html" style="<?php echo ( $dbhandler->get_global_option_value( 'wpefb_smtp_authentication', '0' )=='1' ) ? '' : 'display:none'; ?>">

                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Username', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="text" class="advrf-input-field" id="wpefb_smtp_username" name="wpefb_smtp_username" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_smtp_username' ) ); ?>">
                                    </div>
                                </div>
                                
                                <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Password', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="password" class="advrf-input-field" id="wpefb_smtp_password" name="wpefb_smtp_password" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_smtp_password' ) ); ?>">
                                    </div>
                                </div>


                            </div>
                        </div>
                            
                        <div class="advrf-child-rows" id="wpefb_outgoing_emails_wordpress_html" style="<?php echo ( $dbhandler->get_global_option_value( 'wpefb_outgoing_emails', 'WordPress' )== 'WordPress' ) ? '' : 'display:none'; ?>">
                            <div class="group-title"><?php esc_html_e( 'Submission Notification for User', 'vedrixa-forms-registration-builder' ); ?></div>
                            
                            <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Sender\'s Name', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="text" class="advrf-input-field" id="wpefb_senders_display_name" name="wpefb_senders_display_name" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_senders_display_name' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'A name to identify the sender. It will be shown as "From: MY Blog <me@myblog.com>".Use tag {{user}} to dynamically pick name from the form, if it has profile fields for name; or if the user is already registered, from his/ her WP Profile.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>
                            
                            <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Sender\'s Email', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="email" class="advrf-input-field" id="wpefb_senders_email" name="wpefb_senders_email" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_senders_email' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'The sender\'s email address in the message header that the user will receive.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>
                            
                           <div class="group-title"><?php esc_html_e( 'Submission Notification for Admin', 'vedrixa-forms-registration-builder' ); ?></div>
                           
                           <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Sender\'s Name', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="text" class="advrf-input-field" id="wpefb_admin_senders_display_name" name="wpefb_admin_senders_display_name" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_admin_senders_display_name' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'A name to identify the sender. It will be shown as "From: MY Blog <me@myblog.com>".Use tag {{user}} to dynamically pick name from the form, if it has profile fields for name; or if the user is already registered, from his/ her WP Profile.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>
                            
                            <div class="advrf-row">
                                    <div class="advrf-control-label">
                                        <label><?php esc_html_e( 'Sender\'s Email', 'vedrixa-forms-registration-builder' ); ?></label>
                                    </div>
                                    <div class="advrf-control">
                                        <input type="text" class="advrf-input-field" id="wpefb_admin_senders_email" name="wpefb_admin_senders_email" value="<?php echo esc_attr( $dbhandler->get_global_option_value( 'wpefb_admin_senders_email' ) ); ?>">
                                        <p class="description"><?php esc_html_e( 'The sender\'s email address in the message header that the admin will receive. You can also set this dynamically to the email of the user submitting the form by using tag {{useremail}}. This can be useful if you wish to forward submissions to a helpdesk or ticketing software.', 'vedrixa-forms-registration-builder' ); ?></p>
                                    </div>
                                </div>
                        </div>
                            
                            </div>
                    </div>



                </fieldset>

                <p class="submit">
                    <?php wp_nonce_field( 'save_wpefb_global_settings' ); ?>
                    <input type="submit" value="<?php esc_attr_e( 'Save', 'vedrixa-forms-registration-builder' ); ?>" class="button button-primary" name="submit_settings" id="submit_settings" onClick="return advrf_global_settings_validation('security')"/>
                    <a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=wpefb_global_settings' ) ); ?>"><?php esc_html_e( 'Cancel', 'vedrixa-forms-registration-builder' ); ?></a>
                    <div class="all_error_text" style="display:none;"></div>
                </p>
            </form>  
        </div>    

    </div>    
</div>

                            
