<?php
/*
 *
 * @File : Flex column
 * @retrun
 *
 */

if ( ! function_exists('jobcareer_pb_flex_column') ) {

    function jobcareer_pb_flex_column($die = 0) {
        global $jobcareer_node, $count_node, $post, $jobcareer_html_fields, $jobcareer_form_fields;
        $shortcode_element = '';
        $filter_element = 'filterdrag';
        $shortcode_view = '';
        $output = array();
        $PREFIX = CS_SC_COLUMN;
        $counter = $_POST['counter'];
        $cs_counter = $_POST['counter'];
        if ( isset($_POST['action']) && ! isset($_POST['shortcode_element_id']) ) {
            $POSTID = '';
            $shortcode_element_id = '';
        } else {
            $POSTID = $_POST['POSTID'];
            $shortcode_element_id = $_POST['shortcode_element_id'];
            $shortcode_str = stripslashes($shortcode_element_id);
            $parseObject = new ShortcodeParse();
            $output = $parseObject->cs_shortcodes($output, $shortcode_str, true, $PREFIX);
        }
        $defaults = array(
            'flex_column_section_title' => '',
            'cs_column_margin_left' => '0',
            'cs_column_margin_right' => '0',
            'cs_column_top_padding' => '',
            'cs_column_bottom_padding' => '',
            'cs_column_left_padding' => '',
            'cs_column_right_padding' => '',
            'cs_column_image_url' => '',
            'column_bg_color' => '',
            'content_title_color' => '',
            'cs_column_class' => ''
        );
        if ( isset($output['0']['atts']) ) {
            $atts = $output['0']['atts'];
        } else {
            $atts = array();
        }
        if ( isset($output['0']['content']) ) {
            $flex_column_text = $output['0']['content'];
        } else {
            $flex_column_text = '';
        }
        $flex_column_element_size = '25';
        foreach ( $defaults as $key => $values ) {
            if ( isset($atts[$key]) )
                $$key = $atts[$key];
            else
                $$key = $values;
        }
        $name = 'jobcareer_pb_flex_column';
        $coloumn_class = 'column_' . $flex_column_element_size;
        if ( isset($_POST['shortcode_element']) && $_POST['shortcode_element'] == 'shortcode' ) {
            $shortcode_element = 'shortcode_element_class';
            $shortcode_view = 'cs-pbwp-shortcode';
            $filter_element = 'ajax-drag';
            $coloumn_class = '';
        }
        ?>
        <div id="<?php echo esc_attr($name . $cs_counter) ?>_del" class="column  parentdelete <?php echo esc_attr($coloumn_class); ?>
             <?php echo esc_attr($shortcode_view); ?>" item="flex_column" data="<?php echo jobcareer_element_size_data_array_index($flex_column_element_size) ?>" >
                 <?php jobcareer_element_setting($name, $cs_counter, $flex_column_element_size) ?>
            <div class="cs-wrapp-class-<?php echo intval($cs_counter) ?>
                 <?php echo esc_attr($shortcode_element); ?>" id="<?php echo esc_attr($name . $cs_counter) ?>" data-shortcode-template="[<?php echo esc_attr(CS_SC_COLUMN); ?> {{attributes}}]{{content}}[/<?php echo esc_attr(CS_SC_COLUMN) ?>]" style="display: none;">
                <div class="cs-heading-area">
                    <h5><?php esc_html_e('COLUMN OPTIONS', 'jobcareer') ?></h5>
                    <a href="javascript:removeoverlay('<?php echo esc_js($name . $cs_counter) ?>','<?php echo esc_js($filter_element); ?>')"
                       class="cs-btnclose"><i class="icon-times"></i>
                    </a>
                </div>
                <div class="cs-pbwp-content">
                    <div class="cs-wrapp-clone cs-shortcode-wrapp">
                        <?php
                        if ( isset($_POST['shortcode_element']) && $_POST['shortcode_element'] == 'shortcode' ) {
                            jobcareer_shortcode_element_size();
                        }

                        $cs_opt_array = array(
                            'name' => esc_html__('Element Title', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__("Enter element here.", 'jobcareer'),
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($flex_column_section_title),
                                'cust_id' => '',
                                'classes' => '',
                                'cust_name' => 'flex_column_section_title[]',
                                'return' => true,
                            ),
                        );

                        $jobcareer_html_fields->cs_text_field($cs_opt_array);
                        /*
                         * code user for ins tag that is not supported in jqte
                         */
                        $a = jobcareer_custom_shortcode_decode($flex_column_text);
                        if ( strpos($a, '<ins') !== false ) {
                            $cs_editor_value = '';
                        } else {
                            $cs_editor_value = 'true';
                        }
                        /*
                         * end 
                         */

                        $cs_opt_array = array(
                            'name' => esc_html__('Content', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__("Enter content of the column.", 'jobcareer'),
                            'echo' => true,
                            'field_params' => array(
                                'std' => ($flex_column_text),
                                'cust_id' => '',
                                'classes' => 'textarea',
                                'cust_name' => 'flex_column_text[]',
                                'cs_editor' => $cs_editor_value,
                                'return' => true,
                                'extra_atr' => 'data-content-text="cs-shortcode-textarea"',
                            ),
                        );


                        $jobcareer_html_fields->cs_textarea_field($cs_opt_array);
                        $cs_opt_array = array(
                            'name' => esc_html__('Margin Left', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__('Enter margin left without px', 'jobcareer'),
                            'echo' => true,
                            'field_params' => array(
                                'std' => $cs_column_margin_left,
                                'id' => '',
                                'cust_id' => '',
                                'cust_name' => 'cs_column_margin_left[]',
                                'return' => true,
                                'extra_atr' => '',
                            ),
                        );
                        $jobcareer_html_fields->cs_text_field($cs_opt_array);
                        $cs_opt_array = array(
                            'name' => esc_html__('Margin Right', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__('Enter margin right without px', 'jobcareer'),
                            'echo' => true,
                            'field_params' => array(
                                'std' => $cs_column_margin_right,
                                'id' => '',
                                'cust_id' => '',
                                'cust_name' => 'cs_column_margin_right[]',
                                'return' => true,
                                'extra_atr' => '',
                            ),
                        );
                        $jobcareer_html_fields->cs_text_field($cs_opt_array);

                        $cs_opt_array = array(
                            'name' => esc_html__('Top Padding', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__("If you want to set top padding then set it.", "jobcareer"),
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($cs_column_top_padding),
                                'cust_id' => 'cs_column_top_padding' . $cs_counter,
                                'classes' => '',
                                'cust_name' => 'cs_column_top_padding[]',
                                'return' => true,
                            ),
                        );
                        $jobcareer_html_fields->cs_text_field($cs_opt_array);

                        $cs_opt_array = array(
                            'name' => esc_html__('Bottom Padding', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__("If you want to set bottom padding then set it.", "jobcareer"),
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($cs_column_bottom_padding),
                                'cust_id' => 'cs_column_bottom_padding' . $cs_counter,
                                'classes' => '',
                                'cust_name' => 'cs_column_bottom_padding[]',
                                'return' => true,
                            ),
                        );
                        $jobcareer_html_fields->cs_text_field($cs_opt_array);

                        $cs_opt_array = array(
                            'name' => esc_html__('Left Padding', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__("If you want to set left padding then set it.", "jobcareer"),
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($cs_column_left_padding),
                                'cust_id' => 'cs_column_left_padding' . $cs_counter,
                                'classes' => '',
                                'cust_name' => 'cs_column_left_padding[]',
                                'return' => true,
                            ),
                        );
                        $jobcareer_html_fields->cs_text_field($cs_opt_array);
                        $cs_opt_array = array(
                            'name' => esc_html__('Right Padding', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__("If you want to set bottom padding then set it.", "jobcareer"),
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($cs_column_right_padding),
                                'cust_id' => 'cs_column_right_padding' . $cs_counter,
                                'classes' => '',
                                'cust_name' => 'cs_column_right_padding[]',
                                'return' => true,
                            ),
                        );


                        $jobcareer_html_fields->cs_text_field($cs_opt_array);


                        $cs_opt_array = array(
                            'std' => $cs_column_image_url,
                            'id' => 'cs_column_image_url',
                            'name' => esc_html__('Background Image', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => esc_html__('Select Image for column background.', 'jobcareer'),
                            'echo' => true,
                            'array' => true,
                            'prefix' => '',
                            'field_params' => array(
                                'std' => $cs_column_image_url,
                                'id' => 'cs_column_image_url',
                                'return' => true,
                                'array' => true,
                                'array_txt' => false,
                                'prefix' => '',
                            ),
                        );

                        $jobcareer_html_fields->cs_upload_file_field($cs_opt_array);


                        $cs_opt_array = array(
                            'name' => esc_html__('Element Title Color', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => '',
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($content_title_color),
                                'cust_id' => '',
                                'classes' => 'bg_color',
                                'cust_name' => 'content_title_color[]',
                                'return' => true,
                            ),
                        );

                        $jobcareer_html_fields->cs_text_field($cs_opt_array);

                        $cs_opt_array = array(
                            'name' => esc_html__('Background Color', 'jobcareer'),
                            'desc' => '',
                            'hint_text' => '',
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_attr($column_bg_color),
                                'cust_id' => '',
                                'classes' => 'bg_color',
                                'cust_name' => 'column_bg_color[]',
                                'return' => true,
                            ),
                        );

                        $jobcareer_html_fields->cs_text_field($cs_opt_array);
                        ?>

                    </div>
                    <?php if ( isset($_POST['shortcode_element']) && $_POST['shortcode_element'] == 'shortcode' ) { ?>
                        <ul class="form-elements insert-bg">
                            <li class="to-field">
                                <a class="insert-btn cs-main-btn" onclick="javascript:Shortcode_tab_insert_editor('<?php echo str_replace('jobcareer_pb_', '', $name); ?>', '<?php echo esc_js($name . $cs_counter) ?>', '<?php echo esc_js($filter_element); ?>')" ><?php esc_html_e('Insert', 'jobcareer'); ?></a>
                            </li>
                        </ul>
                        <div id="results-shortocde"></div>
                    <?php } else { ?>

                        <?php
                        $cs_opt_array = array(
                            'std' => 'flex_column',
                            'id' => '',
                            'before' => '',
                            'after' => '',
                            'classes' => '',
                            'extra_atr' => '',
                            'cust_id' => '',
                            'cust_name' => 'cs_orderby[]',
                            'return' => true,
                            'required' => false
                        );
                        echo jobcareer_special_char($jobcareer_form_fields->cs_form_hidden_render($cs_opt_array));
                        ?>

                        <?php
                        $cs_opt_array = array(
                            'name' => '',
                            'desc' => '',
                            'hint_text' => '',
                            'echo' => true,
                            'field_params' => array(
                                'std' => esc_html__('Save', 'jobcareer'),
                                'cust_id' => '',
                                'cust_type' => 'button',
                                'classes' => 'cs-admin-btn',
                                'cust_name' => '',
                                'extra_atr' => 'onclick="javascript:_removerlay(jQuery(this))"',
                                'return' => true,
                            ),
                        );

                        $jobcareer_html_fields->cs_text_field($cs_opt_array);
                        ?>
                    <?php } ?>
                    <script>
                        /* modern selection box function */
                        jQuery(document).ready(function ($) {
                            chosen_selectionbox();
                            popup_over();
                        });
                        /* modern selection box function */
                    </script>
                </div>
            </div>
        </div>
        <?php
        if ( $die <> 1 ) {
            die();
        }
    }

    add_action('wp_ajax_jobcareer_pb_flex_column', 'jobcareer_pb_flex_column');
} 