function cmsms_settings_page_header()
{
    $settings_output = cmsms_get_settings();
    $tabs = $settings_output['cmsms_page_tabs'];
    $current_tab = cmsms_get_the_tab();
    echo '<div id="icon-options-general" class="icon32">' . '<br />' . '</div>' . '<h2 style="padding-top:12px;">' . $settings_output['cmsms_page_title'] . '</h2>';
    if ($tabs != '') {
        $links = array();
        foreach ($tabs as $tab => $name) {
            $class = $tab == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab';
            $page = $_GET['page'];
            $links[] = '<a class="' . $class . '" href="?page=' . $page . '&tab=' . $tab . '"' . ($tab == 'recaptcha' ? ' style="background-color:#fdffc6;' . ($class == 'nav-tab nav-tab-active' ? ' border-bottom-color:#fdffc6;' : '') . '"' : '') . '>' . $name . '</a>';
        }
        echo '<h3 class="nav-tab-wrapper">';
        foreach ($links as $link) {
            echo $link;
        }
        echo '</h3>';
    }
}
function cmsms_validate_options($input)
{
    $valid_input = array();
    $settings_output = cmsms_get_settings();
    $options = $settings_output['cmsms_page_fields'];
    foreach ($options as $option) {
        switch ($option['type']) {
            case 'text':
                switch ($option['class']) {
                    case 'numeric':
                        $input[$option['id']] = trim($input[$option['id']]);
                        $valid_input[$option['id']] = is_numeric($input[$option['id']]) ? $input[$option['id']] : __('Expecting a Numeric value!', 'cmsmasters');
                        if (is_numeric($input[$option['id']]) == false) {
                            add_settings_error($option['id'], CMSMS_SHORTNAME . '_txt_numeric_error', __('Expecting a Numeric value! Please fix.', 'cmsmasters'), 'error');
                        }
                        break;
                    case 'multinumeric':
                        $input[$option['id']] = trim($input[$option['id']]);
                        if ($input[$option['id']] != '') {
                            $valid_input[$option['id']] = preg_match('/^-?\\d+(?:,\\s?-?\\d+)*$/', $input[$option['id']]) == 1 ? $input[$option['id']] : __('Expecting comma separated numeric values', 'cmsmasters');
                        } else {
                            $valid_input[$option['id']] = $input[$option['id']];
                        }
                        if ($input[$option['id']] != '' && preg_match('/^-?\\d+(?:,\\s?-?\\d+)*$/', $input[$option['id']]) != 1) {
                            add_settings_error($option['id'], CMSMS_SHORTNAME . '_txt_multinumeric_error', __('Expecting comma separated numeric values! Please fix.', 'cmsmasters'), 'error');
                        }
                        break;
                    case 'nohtml':
                        $input[$option['id']] = sanitize_text_field($input[$option['id']]);
                        $valid_input[$option['id']] = addslashes($input[$option['id']]);
                        break;
                    case 'url':
                        $input[$option['id']] = trim($input[$option['id']]);
                        $valid_input[$option['id']] = esc_url_raw($input[$option['id']]);
                        break;
                    case 'email':
                        $input[$option['id']] = trim($input[$option['id']]);
                        if ($input[$option['id']] != '') {
                            $valid_input[$option['id']] = is_email($input[$option['id']]) !== false ? $input[$option['id']] : __('Invalid email! Please re-enter!', 'cmsmasters');
                        } elseif ($input[$option['id']] == '') {
                            $valid_input[$option['id']] = __('This setting field cannot be empty! Please enter a valid email address.', 'cmsmasters');
                        }
                        if (is_email($input[$option['id']]) == false || $input[$option['id']] == '') {
                            add_settings_error($option['id'], CMSMS_SHORTNAME . '_txt_email_error', __('Please enter a valid email address.', 'cmsmasters'), 'error');
                        }
                        break;
                    default:
                        $allowed_html = array('a' => array('href' => array(), 'title' => array()), 'b' => array(), 'em' => array(), 'i' => array(), 'strong' => array());
                        $input[$option['id']] = trim($input[$option['id']]);
                        $input[$option['id']] = force_balance_tags($input[$option['id']]);
                        $input[$option['id']] = wp_kses($input[$option['id']], $allowed_html);
                        $valid_input[$option['id']] = addslashes($input[$option['id']]);
                        break;
                }
                break;
            case 'multi-text':
                $textarray = array();
                $text_values = array();
                foreach ($option['choices'] as $k => $v) {
                    $pieces = explode('|', $v);
                    $text_values[] = $pieces[1];
                }
                foreach ($text_values as $v) {
                    if (!empty($input[$option['id'] . '|' . $v])) {
                        switch ($option['class']) {
                            case 'numeric':
                                $input[$option['id'] . '|' . $v] = trim($input[$option['id'] . '|' . $v]);
                                $input[$option['id'] . '|' . $v] = is_numeric($input[$option['id'] . '|' . $v]) ? $input[$option['id'] . '|' . $v] : '';
                                break;
                            default:
                                $input[$option['id'] . '|' . $v] = sanitize_text_field($input[$option['id'] . '|' . $v]);
                                $input[$option['id'] . '|' . $v] = addslashes($input[$option['id'] . '|' . $v]);
                                break;
                        }
                        $textarray[$v] = $input[$option['id'] . '|' . $v];
                    } else {
                        $textarray[$v] = '';
                    }
                }
                if (!empty($textarray)) {
                    $valid_input[$option['id']] = $textarray;
                }
                break;
            case 'textarea':
                switch ($option['class']) {
                    case 'inlinehtml':
                        $input[$option['id']] = trim($input[$option['id']]);
                        $input[$option['id']] = force_balance_tags($input[$option['id']]);
                        $input[$option['id']] = addslashes($input[$option['id']]);
                        $valid_input[$option['id']] = wp_filter_kses($input[$option['id']]);
                        break;
                    case 'nohtml':
                        $input[$option['id']] = sanitize_text_field($input[$option['id']]);
                        $valid_input[$option['id']] = addslashes($input[$option['id']]);
                        break;
                    case 'allowlinebreaks':
                        $input[$option['id']] = wp_strip_all_tags($input[$option['id']]);
                        $valid_input[$option['id']] = addslashes($input[$option['id']]);
                        break;
                    default:
                        $allowed_html = array('script' => array('type' => array()), 'style' => array('type' => array(), 'media' => array()), 'a' => array('style' => array(), 'href' => array(), 'title' => array()), 'b' => array(), 'blockquote' => array('cite' => array()), 'br' => array(), 'dd' => array(), 'dl' => array(), 'dt' => array(), 'em' => array(), 'i' => array(), 'li' => array(), 'ol' => array(), 'p' => array(), 'span' => array(), 'div' => array(), 'q' => array('cite' => array()), 'strong' => array(), 'ul' => array(), 'h1' => array('align' => array(), 'class' => array(), 'id' => array(), 'style' => array()), 'h2' => array('align' => array(), 'class' => array(), 'id' => array(), 'style' => array()), 'h3' => array('align' => array(), 'class' => array(), 'id' => array(), 'style' => array()), 'h4' => array('align' => array(), 'class' => array(), 'id' => array(), 'style' => array()), 'h5' => array('align' => array(), 'class' => array(), 'id' => array(), 'style' => array()), 'h6' => array('align' => array(), 'class' => array(), 'id' => array(), 'style' => array()));
                        $input[$option['id']] = trim($input[$option['id']]);
                        $input[$option['id']] = force_balance_tags($input[$option['id']]);
                        $input[$option['id']] = wp_kses($input[$option['id']], $allowed_html);
                        $valid_input[$option['id']] = addslashes($input[$option['id']]);
                        break;
                }
                break;
            case 'select':
                $select_values = array();
                foreach ($option['choices'] as $k => $v) {
                    $pieces = explode('|', $v);
                    $select_values[] = $pieces[1];
                }
                $valid_input[$option['id']] = in_array($input[$option['id']], $select_values) ? $input[$option['id']] : '';
                break;
            case 'checkbox':
                if (!isset($input[$option['id']])) {
                    $input[$option['id']] = null;
                }
                $valid_input[$option['id']] = $input[$option['id']] == 1 ? 1 : 0;
                break;
            case 'multi-checkbox':
                $checkboxarray = array();
                $check_values = array();
                foreach ($option['choices'] as $k => $v) {
                    $pieces = explode('|', $v);
                    $check_values[] = $pieces[1];
                }
                foreach ($check_values as $v) {
                    if (!empty($input[$option['id'] . '|' . $v])) {
                        $checkboxarray[$v] = 'true';
                    } else {
                        $checkboxarray[$v] = 'false';
                    }
                }
                if (!empty($checkboxarray)) {
                    $valid_input[$option['id']] = $checkboxarray;
                }
                break;
            case 'number':
                $input[$option['id']] = trim($input[$option['id']]);
                $valid_input[$option['id']] = is_numeric($input[$option['id']]) ? $input[$option['id']] : __('Number!', 'cmsmasters');
                if (is_numeric($input[$option['id']]) == false) {
                    add_settings_error($option['id'], CMSMS_SHORTNAME . '_txt_numeric_error', __('Expecting a Numeric value! Please fix.', 'cmsmasters'), 'error');
                }
                break;
            case 'radio':
                $select_values = array();
                foreach ($option['choices'] as $k => $v) {
                    $pieces = explode('|', $v);
                    $select_values[] = $pieces[1];
                }
                $valid_input[$option['id']] = in_array($input[$option['id']], $select_values) ? $input[$option['id']] : '';
                break;
            case 'radio_img':
                $select_values = array();
                foreach ($option['choices'] as $k => $v) {
                    $pieces = explode('|', $v);
                    $select_values[] = $pieces[2];
                }
                $valid_input[$option['id']] = in_array($input[$option['id']], $select_values) ? $input[$option['id']] : '';
                break;
            case 'typorgaphy':
                foreach ($option['choices'] as $v) {
                    if (!empty($input[$option['id'] . '_' . $v])) {
                        $valid_input[$option['id'] . '_' . $v] = $input[$option['id'] . '_' . $v];
                    } else {
                        $valid_input[$option['id'] . '_' . $v] = '';
                    }
                }
                break;
            case 'sidebar':
                $valid_vals = array();
                for ($n = 1, $i = $input[$option['id'] . '_number']; $n <= $i; $n++) {
                    $valid_vals[] = $input[$option['id'] . '_-_' . $n];
                }
                if (!empty($valid_vals)) {
                    $valid_input[$option['id']] = $valid_vals;
                }
                break;
            case 'heading':
                $valid_vals = array();
                for ($n = 1, $i = $input[$option['id'] . '_number']; $n <= $i; $n++) {
                    $valid_vals[] = $input[$option['id'] . '_-_' . $n];
                }
                if (!empty($valid_vals)) {
                    $valid_input[$option['id']] = $valid_vals;
                }
                break;
            case 'social':
                $valid_vals = array();
                for ($n = 1, $i = $input[$option['id'] . '_number']; $n <= $i; $n++) {
                    $valid_vals[] = $input[$option['id'] . '_-_' . $n];
                }
                if (!empty($valid_vals)) {
                    $valid_input[$option['id']] = $valid_vals;
                }
                break;
            default:
                $valid_input[$option['id']] = $input[$option['id']];
                break;
        }
    }
    return $valid_input;
}