<?php
if (!function_exists('jobcareer_pb_gallery')) {

    function jobcareer_pb_gallery($die = 0) {
        global $jobcareer_node, $post, $jobcareer_html_fields, $jobcareer_form_fields;
        $shortcode_element = '';
        $filter_element = 'filterdrag';
        $shortcode_view = '';
        $output = array();
        $cs_counter = $_POST['counter'];
        $gallery_num = 0;
        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);
            $PREFIX = CS_SC_GALLERY . '|' . CS_SC_GALLERYITEM;
            $parseObject = new ShortcodeParse();
            $output = $parseObject->cs_shortcodes($output, $shortcode_str, true, $PREFIX);
        }
        $defaults = array(
            'cs_gallery_section_title' => '',
            'cs_gallery_margin_left' => '0',
            'cs_gallery_margin_right' => '0',
           
        );
        if (isset($output['0']['atts'])) {
            $atts = $output['0']['atts'];
        } else {
            $atts = array();
        }
        if (isset($output['0']['content'])) {
            $atts_content = $output['0']['content'];
        } else {
            $atts_content = array();
        }
        if (is_array($atts_content)) {
            $gallery_num = count($atts_content);
        }
        $gallery_element_size = '100';
        foreach ($defaults as $key => $values) {
            if (isset($atts[$key])) {
                $$key = $atts[$key];
            } else {
                $$key = $values;
            }
        }
        $name = 'jobcareer_pb_gallery';
        $coloumn_class = 'column_' . $gallery_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 = '';
        }
        $randD_id = rand(34, 453453);
        ?>
        <div id="<?php echo jobcareer_special_char($name . $cs_counter); ?>_del" class="column  parentdelete <?php echo jobcareer_special_char($coloumn_class); ?> <?php echo jobcareer_special_char($shortcode_view); ?>" item="gallery" data="<?php echo jobcareer_element_size_data_array_index($gallery_element_size) ?>" >
            <?php jobcareer_element_setting($name, $cs_counter, $gallery_element_size, '', 'weixin'); ?>
            <div class="cs-wrapp-class-<?php echo jobcareer_special_char($cs_counter) ?> <?php echo jobcareer_special_char($shortcode_element); ?>" id="<?php echo jobcareer_special_char($name . $cs_counter); ?>" style="display: none;">
                <div class="cs-heading-area">
                    <h5><?php esc_html_e('Gallery Options', 'jobcareer'); ?></h5>
                    <a href="javascript:removeoverlay('<?php echo jobcareer_special_char($name . $cs_counter) ?>','<?php echo jobcareer_special_char($filter_element); ?>')" class="cs-btnclose"><i class="icon-times"></i></a>
                </div>
                <div class="cs-clone-append cs-pbwp-content" >
                    <div class="cs-wrapp-tab-box">
                        <div id="shortcode-item-<?php echo esc_attr($cs_counter); ?>" data-shortcode-template="{{child_shortcode}} [/<?php echo esc_attr(CS_SC_GALLERY); ?>]" data-shortcode-child-template="[<?php echo esc_attr(CS_SC_GALLERYITEM); ?> {{attributes}}] {{content}} [/<?php echo esc_attr(CS_SC_GALLERYITEM); ?>]">
                            <div class="cs-wrapp-clone cs-shortcode-wrapp cs-disable-true" data-template="[<?php echo esc_attr(CS_SC_GALLERY); ?> {{attributes}}]">
                                <?php
                                $sh_code = '';
                                if (isset($_POST['shortcode_element']) && $_POST['shortcode_element'] == 'shortcode') {
                                    jobcareer_shortcode_element_size();
                                    $sh_code = 1;
                                }
                                ?>
                                <?php
                                $cs_opt_array = array(
                                    'name' => esc_html__('Element Title', 'jobcareer'),
                                    'desc' => '',
                                    'hint_text' => esc_html__("Enter Element title for Gallery.", 'jobcareer'),
                                    'echo' => true,
                                    'field_params' => array(
                                        'std' => jobcareer_special_char($cs_gallery_section_title),
                                        'cust_id' => '',
                                        'classes' => '',
                                        'cust_name' => 'cs_gallery_section_title[]',
                                        'return' => true,
                                    ),
                                );

                                $jobcareer_html_fields->cs_text_field($cs_opt_array);

                                $cs_opt_array = array(
                                    'name' => esc_html__('Margin Left', 'jobcareer'),
                                    'desc' => '',
                                    'hint_text' => esc_html__("Use this option if you want to use margin left for this element. (without px)", 'jobcareer'),
                                    'echo' => true,
                                    'field_params' => array(
                                        'std' => esc_attr($cs_gallery_margin_left),
                                        'cust_id' => '',
                                        'classes' => 'txtfield',
                                        'cust_name' => 'cs_gallery_margin_left[]',
                                        'return' => true,
                                    ),
                                );

                                $jobcareer_html_fields->cs_text_field($cs_opt_array);
                                $cs_opt_array = array(
                                    'name' => esc_html__('Margin Right', 'jobcareer'),
                                    'desc' => '',
                                    'hint_text' => esc_html__("Use this option if you want to use margin right for this element. (without px)", 'jobcareer'),
                                    'echo' => true,
                                    'field_params' => array(
                                        'std' => esc_attr($cs_gallery_margin_right),
                                        'cust_id' => '',
                                        'classes' => 'txtfield',
                                        'cust_name' => 'cs_gallery_margin_right[]',
                                        'return' => true,
                                    ),
                                );

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

                            </div>
                            <?php
                            if (isset($gallery_num) && $gallery_num <> '' && isset($atts_content) && is_array($atts_content)) {
                                $itemCounter = 0;
                                foreach ($atts_content as $gallery_items) {
                                    $itemCounter++;
                                    $rand_id = $cs_counter . '' . jobcareer_generate_random_string(3);
                                    $defaults = array('cs_website_url' => '', 'cs_gallery_title' => '', 'cs_gallery_logo' => '' ,  'cs_gallery_size' => '',);
                                    foreach ($defaults as $key => $values) {
                                        if (isset($gallery_items['atts'][$key])) {
                                            $$key = $gallery_items['atts'][$key];
                                        } else {
                                            $$key = $values;
                                        }
                                    }
                                    ?>
                                    <div class='cs-wrapp-clone cs-shortcode-wrapp'  id="cs_infobox_<?php echo jobcareer_special_char($rand_id); ?>">
                                        <header>
                                            <h4><i class='icon-arrows'></i><?php esc_html_e('Gallery', 'jobcareer'); ?></h4>
                                            <a href='#' class='deleteit_node'><i class='icon-minus-circle'></i><?php esc_html_e('Remove', 'jobcareer'); ?></a></header>
                                        <?php
                                        $cs_opt_array = array(
                                            'name' => esc_html__('Website Url', 'jobcareer'),
                                            'desc' => '',
                                            'hint_text' => esc_html__("Enter your gallery URL.", 'jobcareer'),
                                            'echo' => true,
                                            'field_params' => array(
                                                'std' => esc_url($cs_website_url),
                                                'cust_id' => '',
                                                'classes' => '',
                                                'cust_name' => 'cs_website_url[]',
                                                'return' => true,
                                            ),
                                        );

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



                                        $cs_opt_array = array(
                                            'name' => esc_html__('Gallery Size', 'jobcareer'),
                                            'desc' => '',
                                            'hint_text' => esc_html__("Select gallery size", 'jobcareer'),
                                            'echo' => true,
                                            'field_params' => array(
                                                'std' => $cs_gallery_size,
                                                'id' => '',
                                                'cust_id' => 'cs_gallery_size',
                                                'cust_name' => 'cs_gallery_size[]',
                                                'classes' => 'chosen-select-no-single',
                                                'options' => array(
                                                    '' => esc_html__('Please Select', 'jobcareer'),
                                                    'img-small' => esc_html__('Small', 'jobcareer'),
                                                    'img-larage' => esc_html__('Large', 'jobcareer'),
                                                ),
                                                'return' => true,
                                            ),
                                        );
                                        $jobcareer_html_fields->cs_select_field($cs_opt_array);
                                        ?>

                                        <?php
                                        $cs_opt_array = array(
                                            'std' => $cs_gallery_logo,
                                            'id' => 'gallery_logo',
                                            'name' => esc_html__('Choose Image', 'jobcareer'),
                                            'desc' => '',
                                            'hint_text' => esc_html__('Attach gallery image here from media.', 'jobcareer'),
                                            'echo' => true,
                                            'array' => true,
                                            'field_params' => array(
                                                'std' => $cs_gallery_logo,
                                                'cust_id' => '',
                                                'id' => 'gallery_logo',
                                                'return' => true,
                                                'array' => true,
                                                'array_txt' => false,
                                            ),
                                        );
                                        $jobcareer_html_fields->cs_upload_file_field($cs_opt_array);
                                        ?>
                                    </div>

                                    <script>
                                        /*
                                         
                                         
                                         /*
                                         * modern selection box function
                                         */
                                        jQuery(document).ready(function ($) {
                                            chosen_selectionbox();
                                            popup_over();
                                        });
                                        /*
                                         * modern selection box function
                                         */
                                    </script>   
                                    <?php
                                }
                            }
                            ?>
                        </div>
                        <div class="hidden-object">

                            <?php
                            $cs_opt_array = array(
                                'std' => (int) $gallery_num,
                                'id' => '',
                                'before' => '',
                                'after' => '',
                                'classes' => 'fieldCounter',
                                'extra_atr' => '',
                                'cust_id' => '',
                                'cust_name' => 'gallery_num[]',
                                'return' => true,
                                'required' => false
                            );
                            echo jobcareer_special_char($jobcareer_form_fields->cs_form_hidden_render($cs_opt_array));
                            ?>
                        </div>
                        <div class="wrapptabbox no-padding-lr">
                            <div class="opt-conts">
                                <ul class="form-elements noborder">

                                    <li class="to-field"> <a href="#" class="add_servicesss cs-main-btn" onclick="jobcareer_shortcode_element_ajax_call('gallery', 'shortcode-item-<?php echo jobcareer_special_char($cs_counter); ?>', '<?php echo jobcareer_special_char(admin_url('admin-ajax.php')); ?>', '<?php echo esc_html($sh_code); ?>')"><i class="icon-plus-circle"></i><?php esc_html_e('Add Gallery', 'jobcareer'); ?></a> </li>

                                    <div id="loading" class="shortcodeload"></div>
                                </ul>
                            </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 jobcareer_special_char(str_replace('jobcareer_pb_', '', $name)); ?>', 'shortcode-item-<?php echo jobcareer_special_char($cs_counter); ?>', '<?php echo jobcareer_special_char($filter_element); ?>')" ><?php esc_html_e('Insert', 'jobcareer'); ?></a> </li>
                                </ul>
                                <div id="results-shortocde"></div>
                            <?php } else { ?>

                                <?php
                                $cs_opt_array = array(
                                    'std' => 'gallery',
                                    '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 } ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>

            jQuery(document).ready(function ($) {
                chosen_selectionbox();
                popup_over();
            });


        </script>
        <?php
        if ($die <> 1) {
            die();
        }
    }

    add_action('wp_ajax_jobcareer_pb_gallery', 'jobcareer_pb_gallery');
}