<?php

// Block direct access.
defined('ABSPATH') or die("Play nice!");

if( isset(  $_POST['_axs_settings_nonce'] )  ):
 
   
    // Security Check
    if( ! wp_verify_nonce( sanitize_text_field( $_POST['_axs_settings_nonce'] ), '_save_axs_settings' ) ):
        
        // Display Error
        add_settings_error( 'axs_settings_options', 'axs_security_error', 'Security check failed.', 'error' ); // $setting, $code, $message, $type
    
        // Die
        wp_die( __('Security Check Failed. Click <a href="' . get_bloginfo('url'). '/wp-admin/options-general.php?page=secure_axs">here</a> to try again.', 'Secure AXS Settings'), array('response' => '500') );
        
    else:

         self::validate_settings( $_POST['secure_axs'] );

    endif;

 
endif;
 
    // Retrieve saved settings
    $secure_axs = self::retrieve_settings('secure_axs');
    $perma_link = self::retrieve_settings('permalink_structure');
        
    if( $perma_link != NULL): $perma_link = NULL; else: $perma_link = '?'; endif;


?>


<div class="wrap">
    <?php    echo "<h2>" . __( 'Access Settings', 'Secure_Axs' ) . "</h2>"; ?>
    <form name="secure_axs" id="secure_axs" method="post" action="">
        <?php wp_nonce_field( '_save_axs_settings', '_axs_settings_nonce' ) ?>
        <table class="form-table">		
            

            <tbody>
                
                <tr valign="top"><th scope="row"><h4><?php _e( 'Security Options', 'Secure_Axs' ); ?></h4></tr>
                
            	<tr valign="top">
				<th scope="row">
                                    <label for="secure_axs[axs_url]">
                                        <?php _e("Access URL (i.e axs-login):", "Secure_Axs"  ); ?>
                                    </label></th>
                                    <td>
                                        <input name="secure_axs[axs_url]" type="text" id="axs_url" value="<?php echo $secure_axs['axs_url']; ?>" class="regular-text">
                                        <p class="description">Alphanumeric and dash "-" are only allowed.</p>
                                        <p class="description">Your current secured access login is: <a href="<?php echo get_bloginfo('url') . '/' . $perma_link . $secure_axs['axs_url']; ?>" target="_blank"><?php echo get_bloginfo('url') . '/' . $perma_link . $secure_axs['axs_url']; ?></p>
                                    </td>
                </tr>
                
                <tr valign="top" style="display: none">
		<th scope="row"><label for="secure_axs[after_login_url]"><?php _e("URL redirect after login: ", "Secure_Axs"  ); ?></label></th>
                <td>
                    <input name="secure_axs[after_login_url]" type="text" 
                           placeholder="<?php echo get_bloginfo('url') . '/wp-admin/'; ?>" 
                           value="<?php echo ( $secure_axs['after_login_url'] == NULL ? NULL : $secure_axs['after_login_url'] ); ?>"
                           class="regular-text">
                    <p class="description">Please enter full URL (i.e <?php echo get_bloginfo('url') . '/custom-page/'; ?>), leave blank to go to dashboard.</p>
                </td>
		</tr>
                           
            	<tr valign="top">
				<th scope="row"><label for="secure_axs[allow_editors]"><?php _e("Allow Editors to edit settings:", "Secure_Axs"  ); ?></label></th>
                                <td><input name="secure_axs[allow_editors]" type="checkbox" id="allow_editors" <?php if( $secure_axs['allow_editors'] == 'on' ): echo 'checked'; endif;?>>
                                    <p class="description">When Checked, Editors are able to access/change plugin settings.</p>
                                </td>
                </tr>
            </tbody>
            

            <tbody>
                
                <tr valign="top"><th scope="row"><h4><?php _e( 'Branding Options', 'Secure_Axs' ); ?></h4></tr>
                
            	<tr valign="top">
				<th scope="row">
                                    <label for="secure_axs[bg_color]">
                                        <?php _e("Background Color", "Secure_Axs" ); ?>
                                    </label></th>
                                    <td>
                                        <input name="secure_axs[bg_color]" type="text" id="bg_color" value="<?php echo $secure_axs['bg_color']; ?>" class="regular-text axs-colors">
                                    </td>
		</tr>
            	<tr valign="top">
				<th scope="row">
                                    <label for="secure_axs[text_color]">
                                        <?php _e("Text Color" , "Secure_Axs" ); ?>
                                    </label></th>
                                    <td>
                                        <input name="secure_axs[text_color]" type="text" id="text_color" value="<?php echo $secure_axs['text_color']; ?>" class="regular-text axs-colors">
                                    </td>
		</tr>
                <tr valign="top">
				<th scope="row">
                                    <label for="secure_axs[brand_logo]">
                                        <?php _e("Custom Logo" , "Secure_Axs" ); ?>
                                    </label></th>
                                    <td>
                                        
                                        <div id="axs_image_thumb">
										<?php if($secure_axs['axs_image'] != NULL): ?>
                                        <img src="<?php echo $secure_axs['axs_image']; ?>" style="max-height: 50px; width: auto;"><br>
                                        <?php endif; ?>
                                        </div>
                                     
                                        <input name="secure_axs[axs_image]" id="axs_image" type="text" size="36" value="<?php echo $secure_axs['axs_image']; ?>" class="regular-text logo">
                                        <input type="button" id="axs_image_button" class="button-secondary" value="Select Image">
                                    </td>
		</tr>
		</tr>
                <tr valign="top">
				<th scope="row">
                                    <label for="secure_axs[brand_bg]">
                                        <?php _e("Custom Background Image" , "Secure_Axs" ); ?>
                                    </label></th>
                                    <td>
                                        <div id="brand_bg_thumb">
										<?php if($secure_axs['brand_bg'] != NULL): ?>
                                        <img src="<?php echo $secure_axs['brand_bg']; ?>" style="max-height: 50px; width: auto;"><br>
                                        <?php endif; ?>
                                        </div>
                                        
                                        <input name="secure_axs[brand_bg]" id="brand_bg" type="text" size="36" value="<?php echo $secure_axs['brand_bg']; ?>" class="regular-text">
                                        <input type="button" id="brand_bg_button" class="button-secondary" value="Select Image">
                                    </td>
		</tr>
            </tbody>
            
        </table>
             <?php submit_button(); ?>
    </form>
