<?php 
/**
	Admin Page Framework v3.8.34 by Michael Uno 
	Generated by PHP Class Files Script Generator <https://github.com/michaeluno/PHP-Class-Files-Script-Generator>
	<http://en.michaeluno.jp/index-wp-mysql-for-speed>
	Copyright (c) 2013-2021, Michael Uno; Licensed under MIT <http://opensource.org/licenses/MIT> */
class Imfs_AdminPageFramework_FieldType_submit extends Imfs_AdminPageFramework_FieldType {
    public $aFieldTypeSlugs = array('submit',);
    protected $aDefaultKeys = array('redirect_url' => null, 'href' => null, 'reset' => null, 'email' => null, 'confirm' => '', 'skip_confirmation' => false, 'attributes' => array('class' => 'button button-primary',),);
    protected function getStyles() {
        return ".index-wp-mysql-for-speed-field input[type='submit'] {margin-bottom: 0.5em;}.index-wp-mysql-for-speed-field-submit .submit-confirm-container {display: inline-block;margin-left: 1em;vertical-align: middle;}.index-wp-mysql-for-speed-field-submit .field-error.submit-confirmation-warning {float: none;}";
    }
    protected function getScripts() {
        return <<<JAVASCRIPTS
jQuery( document ).ready( function(){
    jQuery( '.index-wp-mysql-for-speed-field-submit .submit-confirm-container input[type=checkbox]' ).each( function( index, value ){
        jQuery( this ).closest( '.index-wp-mysql-for-speed-field-submit' ).find( 'input[type=submit]' ).on( 'click', function( event ){
            var _fieldSubmit = jQuery( this ).closest( '.index-wp-mysql-for-speed-field-submit' );  
            _fieldSubmit.find( '.submit-confirmation-warning' ).remove(); // previous error message
            var _confirmCheckbox = jQuery( this ).closest( '.index-wp-mysql-for-speed-field-submit' ).find( '.submit-confirm-container input[type=checkbox]' );
            if ( ! _confirmCheckbox.length ) {
                return true;
            }
            if ( _confirmCheckbox.is( ':checked' ) ) {
                return true;
            }           
            // At this point, the checkbox is not checked.
            var _sErrorTag = "<p class='field-error submit-confirmation-warning'><span>* " + _confirmCheckbox.attr( 'data-error-message' ) + "</span></p>";
            _fieldSubmit.find( '.submit-confirm-container' ).append( _sErrorTag );
            return false;        
        } );     
    });            
});
JAVASCRIPTS;
        
    }
    protected function getField($aField) {
        $aField = $this->___getFormattedFieldArray($aField);
        $_aInputAttributes = $this->_getInputAttributes($aField);
        $_aLabelAttributes = $this->_getLabelAttributes($aField, $_aInputAttributes);
        $_aLabelContainerAttributes = $this->_getLabelContainerAttributes($aField);
        return $aField['before_label'] . "<div " . $this->getAttributes($_aLabelContainerAttributes) . ">" . $this->_getExtraFieldsBeforeLabel($aField) . "<label " . $this->getAttributes($_aLabelAttributes) . ">" . $aField['before_input'] . $this->_getExtraInputFields($aField) . "<input " . $this->getAttributes($_aInputAttributes) . " />" . $aField['after_input'] . "</label>" . $this->___getConfirmationCheckbox($aField) . "</div>" . $aField['after_label'];
    }
    private function ___getConfirmationCheckbox($aField) {
        if (empty($aField['confirm'])) {
            return '';
        }
        $_aConfirm = is_string($aField['confirm']) ? array('label' => $aField['confirm']) : $this->getAsArray($aField['confirm']);
        $_aConfirm = $_aConfirm + array('label' => $this->oMsg->get('submit_confirmation_label'), 'error' => $this->oMsg->get('submit_confirmation_error'),);
        $_aAttributes = $this->getElementAsArray($aField, array('attributes', 'confirm'));
        $_sInput = $this->getHTMLTag('input', array('type' => 'checkbox', 'name' => "{$aField['input_id']}[confirm]", 'class' => 'confirm-submit', 'value' => 0, 'data-error-message' => $_aConfirm['error'],) + $_aAttributes);
        return "<p class='submit-confirm-container'><label>" . $_sInput . "<span>{$_aConfirm['label']}</span>" . "</label></p>";
    }
    private function ___getFormattedFieldArray(array $aField) {
        $aField['label'] = $aField['label'] ? $aField['label'] : $this->oMsg->get('submit');
        if (isset($aField['attributes']['src'])) {
            $aField['attributes']['src'] = esc_url($this->getResolvedSRC($aField['attributes']['src']));
        }
        return $aField;
    }
    private function _getLabelAttributes(array $aField, array $aInputAttributes) {
        return array('style' => $aField['label_min_width'] ? "min-width:" . $this->getLengthSanitized($aField['label_min_width']) . ";" : null, 'for' => $aInputAttributes['id'], 'class' => $aInputAttributes['disabled'] ? 'disabled' : null,);
    }
    private function _getLabelContainerAttributes(array $aField) {
        return array('style' => $aField['label_min_width'] || '0' === ( string )$aField['label_min_width'] ? "min-width:" . $this->getLengthSanitized($aField['label_min_width']) . ";" : null, 'class' => 'index-wp-mysql-for-speed-input-label-container' . ' index-wp-mysql-for-speed-input-button-container' . ' index-wp-mysql-for-speed-input-container',);
    }
    private function _getInputAttributes(array $aField) {
        $_bIsImageButton = isset($aField['attributes']['src']) && filter_var($aField['attributes']['src'], FILTER_VALIDATE_URL);
        $_sValue = $this->_getInputFieldValueFromLabel($aField);
        return array('type' => $_bIsImageButton ? 'image' : 'submit', 'value' => $_sValue,) + $aField['attributes'] + array('title' => $_sValue, 'alt' => $_bIsImageButton ? 'submit' : '',);
    }
    protected function _getExtraFieldsBeforeLabel(&$aField) {
        return '';
    }
    protected function _getExtraInputFields(&$aField) {
        $_aOutput = array();
        $_aOutput[] = $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][input_id]", 'value' => $aField['input_id'],));
        $_aOutput[] = $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][field_id]", 'value' => $aField['field_id'],));
        $_aOutput[] = $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][name]", 'value' => $aField['_input_name_flat'],));
        $_aOutput[] = $this->_getHiddenInput_SectionID($aField);
        $_aOutput[] = $this->_getHiddenInputByKey($aField, 'redirect_url');
        $_aOutput[] = $this->_getHiddenInputByKey($aField, 'href');
        $_aOutput[] = $this->_getHiddenInput_Reset($aField);
        $_aOutput[] = $this->_getHiddenInput_Email($aField);
        return implode(PHP_EOL, array_filter($_aOutput));
    }
    private function _getHiddenInput_SectionID(array $aField) {
        return $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][section_id]", 'value' => isset($aField['section_id']) && '_default' !== $aField['section_id'] ? $aField['section_id'] : '',));
    }
    private function _getHiddenInputByKey(array $aField, $sKey) {
        return isset($aField[$sKey]) ? $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][{$sKey}]", 'value' => $aField[$sKey],)) : '';
    }
    private function _getHiddenInput_Reset(array $aField) {
        if (!$aField['reset']) {
            return '';
        }
        return !$this->_checkConfirmationDisplayed($aField, $aField['_input_name_flat'], 'reset') ? $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][is_reset]", 'value' => '1',)) : $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][reset_key]", 'value' => is_array($aField['reset']) ? implode('|', $aField['reset']) : $aField['reset'],));
    }
    private function _getHiddenInput_Email(array $aField) {
        if (empty($aField['email'])) {
            return '';
        }
        $this->setTransient('apf_em_' . md5($aField['_input_name_flat'] . get_current_user_id()), array('nonce' => $this->getNonceCreated('apf_email_nonce_' . md5(( string )site_url()), 86400),) + $this->getAsArray($aField['email']));
        return !$this->_checkConfirmationDisplayed($aField, $aField['_input_name_flat'], 'email') ? $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][confirming_sending_email]", 'value' => '1',)) : $this->getHTMLTag('input', array('type' => 'hidden', 'name' => "__submit[{$aField['input_id']}][confirmed_sending_email]", 'value' => '1',));
    }
    private function _checkConfirmationDisplayed($aField, $sFlatFieldName, $sType = 'reset') {
        switch ($sType) {
            default:
            case 'reset':
                $_sTransientKey = 'apf_rc_' . md5($sFlatFieldName . get_current_user_id());
            break;
            case 'email':
                $_sTransientKey = 'apf_ec_' . md5($sFlatFieldName . get_current_user_id());
            break;
        }
        $_bConfirmed = false === $this->getTransient($_sTransientKey) && !$aField['skip_confirmation'] ? false : true;
        if ($_bConfirmed) {
            $this->deleteTransient($_sTransientKey);
        }
        return $_bConfirmed;
    }
    protected function _getInputFieldValueFromLabel($aField) {
        if (isset($aField['value']) && $aField['value'] != '') {
            return $aField['value'];
        }
        if (isset($aField['label'])) {
            return $aField['label'];
        }
        if (isset($aField['default'])) {
            return $aField['default'];
        }
    }
    }
    class Imfs_AdminPageFramework_FieldType_export extends Imfs_AdminPageFramework_FieldType_submit {
        public $aFieldTypeSlugs = array('export',);
        protected $aDefaultKeys = array('data' => null, 'format' => 'json', 'file_name' => null, 'attributes' => array('class' => 'button button-primary',),);
        protected function setUp() {
        }
        protected function getScripts() {
            return "";
        }
        protected function getStyles() {
            return "";
        }
        protected function getField($aField) {
            if (isset($aField['data'])) {
                $this->setTransient(md5("{$aField['class_name']}_{$aField['input_id']}"), $aField['data'], 60 * 2);
            }
            $aField['attributes']['name'] = "__export[submit][{$aField['input_id']}]";
            $aField['file_name'] = $aField['file_name'] ? $aField['file_name'] : $this->_generateExportFileName($aField['option_key'] ? $aField['option_key'] : $aField['class_name'], $aField['format']);
            $aField['label'] = $aField['label'] ? $aField['label'] : $this->oMsg->get('export');
            return parent::getField($aField);
        }
        protected function _getExtraInputFields(&$aField) {
            $_aAttributes = array('type' => 'hidden');
            return "<input " . $this->getAttributes(array('name' => "__export[{$aField['input_id']}][input_id]", 'value' => $aField['input_id'],) + $_aAttributes) . "/>" . "<input " . $this->getAttributes(array('name' => "__export[{$aField['input_id']}][field_id]", 'value' => $aField['field_id'],) + $_aAttributes) . "/>" . "<input " . $this->getAttributes(array('name' => "__export[{$aField['input_id']}][section_id]", 'value' => isset($aField['section_id']) && $aField['section_id'] != '_default' ? $aField['section_id'] : '',) + $_aAttributes) . "/>" . "<input " . $this->getAttributes(array('name' => "__export[{$aField['input_id']}][file_name]", 'value' => $aField['file_name'],) + $_aAttributes) . "/>" . "<input " . $this->getAttributes(array('name' => "__export[{$aField['input_id']}][format]", 'value' => $aField['format'],) + $_aAttributes) . "/>" . "<input " . $this->getAttributes(array('name' => "__export[{$aField['input_id']}][transient]", 'value' => isset($aField['data']),) + $_aAttributes) . "/>";
        }
        private function _generateExportFileName($sOptionKey, $sExportFormat = 'json') {
            switch (trim(strtolower($sExportFormat))) {
                case 'text':
                    $sExt = "txt";
                break;
                case 'json':
                    $sExt = "json";
                break;
                case 'array':
                default:
                    $sExt = "txt";
                break;
            }
            return $sOptionKey . '_' . date("Ymd") . '.' . $sExt;
        }
    }
    