<?php
global $arfieldhelper, $arformhelper, $MdlDb, $fields_with_external_js, $bootstraped_fields_array,$arformcontroller, $arffield;
$frm_class = 'arf_standard_form';
if( $newarr['arfinputstyle'] == 'rounded' ){
    $frm_class = 'arf_rounded_form';
} else if ($newarr['arfinputstyle'] == 'material' ){
    $frm_class = 'arf_materialize_form';
}

if($_GET['arfaction'] == 'new' || $_GET['arfaction'] =='duplicate'){
    if($define_template < 100){
        $values['name'] = isset($_GET['form_name']) ? stripslashes_deep($arformcontroller->arfHtmlEntities($_GET['form_name'],true)) : '';
        $values['description'] = isset($_GET['form_desc']) ? stripslashes_deep($arformcontroller->arfHtmlEntities($_GET['form_desc'],true)) : '';
    }
}
?>
<div id="arfmainformeditorcontainer" class="arf_form arf_form_outer_wrapper arf_main_tabs active_tabs arf_form ar_main_div_<?php echo $id; ?>">
    <div class="allfields">
        <div id="arf_fieldset_<?php echo $id; ?>" class="arf_fieldset <?php echo $frm_class; ?>">
            <div id="success_message" class="arf_success_message">
                <div class="message_descripiton">
                    <div style="float: left; margin-right: 15px;"><?php echo addslashes(esc_html__('Form is successfully updated', 'ARForms')); ?></div>
                    <div class="message_svg_icon">
                        <svg style="height: 14px;width: 14px;"><path fill-rule="evenodd" clip-rule="evenodd" fill="#FFFFFF" d="M6.075,14.407l-5.852-5.84l1.616-1.613l4.394,4.385L17.181,0.411 l1.616,1.613L6.392,14.407H6.075z"></path></svg>
                    </div>
                </div>
            </div>
            <div id="error_message" class="arf_error_message">
                <div class="message_descripiton">
                    <div style="float: left; margin-right: 15px;"><?php echo addslashes(esc_html__('Form is not successfully updated','ARForms')); ?></div>
                    <div class="message_svg_icon">
                            <svg style="height: 14px;width: 14px;"><path fill-rule="evenodd" clip-rule="evenodd" fill="#ffffff" d="M10.702,10.909L6.453,6.66l-4.249,4.249L1.143,9.848l4.249-4.249L1.154,1.361l1.062-1.061l4.237,4.237l4.238-4.237l1.061,1.061L7.513,5.599l4.249,4.249L10.702,10.909z"></path></svg>
                    </div>
                </div>
            </div>            
            <div id="titlediv" class="arftitlediv" <?php echo (isset($newarr['display_title_form']) && $newarr['display_title_form'] == 0 ) ? 'style="display:none;"' : '';?>>
                <input type="hidden" value="<?php echo ARFURL . '/images'; ?>" id="plugin_image_path" />

                <div id="form_desc" class="edit_form_item arffieldbox frm_head_box">

                    <div class="arfformnamediv">
                        <div class="arfformedit arftitlecontainer">
                            <span class="arfeditorformname formtitle_style arf_edit_in_place" id="frmform_<?php echo $id; ?>">
                                <input type="text" name="name" id="form_name" class="arf_edit_in_place_input inplace_field" value="<?php echo stripslashes_deep($values['name']); ?>" data-default-value="<?php echo stripslashes_deep($values['name']); ?>" data-ajax="false" data-action="arfupdateformname" placeholder="<?php echo addslashes(esc_html__('Click here to enter form title', 'ARForms'));?>"/>
                            </span>
                        </div>
                        <div class="arfformeditpencil" style="margin-top:3px;"></div>
                    </div>
                    <div style="clear:both;"></div>
                    <div class="arfformdescriptiondiv">
                        <div class="arfdescriptionedit">

                            <div class="arfeditorformdescription arf_edit_in_place formdescription_style"><input type="text" data-default-value="<?php echo ($values['description'] != '') ? stripslashes_deep($values['description']) : addslashes(esc_html__('Click here to enter form description', 'ARForms')); ?>" class="arf_edit_in_place_input inplace_field" data-ajax="false" name="description" data-action="arfupdateformdescription" value="<?php echo ($values['description'] != '') ? stripslashes_deep($values['description']) : ""; ?>" placeholder="<?php echo addslashes(esc_html__('Click here to enter form description', 'ARForms'));?>"/></div>
                        </div>
                        <div class="arfdescriptioneditpencil"></div>    
                    </div>
                    <div style="clear:both;"></div>
                </div>
                <div style="clear:both;"></div>

            </div>




            <div id="new_fields" data-flag="1" class="newfield_div">


                <?php
                $index_arf_fields = 0;
                global $index_repeater_fields;
                $index_repeater_fields = 0;
                if (isset($values['fields']) && !empty($values['fields'])) {
                    $arf_load_password = array();
                    $arf_load_confirm_email = array();
                    $totalpass = 0;
                    foreach ($values['fields'] as $arrkey => $field) {
                        if ($field['type'] == 'password') {
                            $field['id'] = $arfieldhelper->get_actual_id($field['id']);
                            if (isset($field['confirm_password']) and $field['confirm_password'] == 1 and isset($arf_load_password['confirm_pass_field']) and $arf_load_password['confirm_pass_field'] == $field['id'])
                                $values['confirm_password_arr'][$field['id']] = isset($field['confirm_password_field']) ? $field['confirm_password_field'] : "";
                            else
                                $arf_load_password['confirm_pass_field'] = isset($field['confirm_password_field']) ? $field['confirm_password_field'] : "";
                        }

                        if ($field['type'] == 'email') {
                            $field['id'] = $arfieldhelper->get_actual_id($field['id']);

                            if (isset($field['confirm_email']) and $field['confirm_email'] == 1 and isset($arf_load_confirm_email['confirm_email_field']) and $arf_load_confirm_email['confirm_email_field'] == $field['id'])
                                $values['confirm_email_arr'][$field['id']] = isset($field['confirm_email_field']) ? $field['confirm_email_field'] : "";
                            else
                                $arf_load_confirm_email['confirm_email_field'] = isset($field['confirm_email_field']) ? $field['confirm_email_field'] : "";
                        }



                        if ($field['type'] == 'email' && isset($field['confirm_email']) && $field['confirm_email'] == 1) {
                            if (isset($field['confirm_email']) and $field['confirm_email'] == 1 and isset($arf_load_confirm_email['confirm_email_field']) and $arf_load_confirm_email['confirm_email_field'] == $field['id']) {
                                $values['confirm_email_arr'][$field['id']] = isset($field['confirm_email_field']) ? $field['confirm_email_field'] : "";
                            } else {
                                $arf_load_confirm_email['confirm_email_field'] = isset($field['confirm_email_field']) ? $field['confirm_email_field'] : "";
                            }
                            $confirm_email_field = $arfieldhelper->get_confirm_email_field($field);
                            $values['fields'] = $arfieldhelper->array_push_after($values['fields'], array($confirm_email_field), $arrkey + $totalpass);
                            $totalpass++;
                        }

                        if ($field['type'] == 'password' && $field['confirm_password']) {
                            if (isset($field['confirm_password']) and $field['confirm_password'] == 1 and isset($arf_load_password['confirm_pass_field']) and $arf_load_password['confirm_pass_field'] == $field['id']) {
                                $values['confirm_password_arr'][$field['id']] = isset($field['confirm_password_field']) ? $field['confirm_password_field'] : "";
                            } else {
                                $arf_load_password['confirm_pass_field'] = isset($field['confirm_password_field']) ? $field['confirm_password_field'] : "";
                            }
                            $confirm_password_field = $arfieldhelper->get_confirm_password_field($field);
                            $values['fields'] = $arfieldhelper->array_push_after($values['fields'], array($confirm_password_field), $arrkey + $totalpass);
                            $totalpass++;
                        }
                    }
                    $arf_fields = array();
                    
                    if($arfaction == 'duplicate')
                    {
                        $arf_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $MdlDb->fields . "` WHERE `form_id` = %d", $define_template), ARRAY_A);
                    }
                    else if($arfaction == 'edit')
                    {
                        $arf_fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $MdlDb->fields . "` WHERE `form_id` = %d", $id), ARRAY_A);
                    }

                    $arf_is_page_break_no = 0;

                    $frm_opts = maybe_unserialize($data['options']);
                    
                    $frm_css = maybe_unserialize($data['form_css']);

                    $field_order = $frm_opts['arf_field_order'];

                    $inner_field_order = isset( $frm_opts['arf_inner_field_order'] ) ? $frm_opts['arf_inner_field_order'] : json_encode(array());

                    $inner_f_order_arr = arf_json_decode( $inner_field_order, true );

                    $temp_inner_order_arr = array();

                    if( !empty( $inner_f_order_arr ) ){
                        foreach( $inner_f_order_arr as $ifkey => $inner_ord ){
                            $pre_fid = array();
                            $icnt = 1;
                            $temp_inner_order_arr[$ifkey] = array();
                            foreach( $inner_ord as $infkey => $infval ){
                                $exploded_data = explode('|', $infval);
                                $temp_fid = $exploded_data[0];
                                if( !empty( $pre_fid ) && in_array( $temp_fid, $pre_fid ) ){
                                    continue;
                                }
                                if( empty( $pre_fid ) || !in_array( $temp_fid, $pre_fid) ){
                                    array_push($pre_fid, $temp_fid );
                                }
                                $temp_inner_order_arr[$ifkey][] = $temp_fid.'|'.$icnt;
                                $icnt++;
                            }
                        }
                    }

                    $inner_field_order = json_encode( $temp_inner_order_arr );

                    $field_resize_width = isset($frm_opts['arf_field_resize_width']) ? $frm_opts['arf_field_resize_width'] : '';

                    $inner_field_resize_width = isset( $frm_opts['arf_inner_field_resize_width'] ) ? $frm_opts['arf_inner_field_resize_width'] : '';

                    $field_temp_fields = maybe_unserialize($data['temp_fields']);

                    $arf_field_counter = 1;
                    if ($field_resize_width != '') {
                        $field_resize_width = json_decode($field_resize_width, true);
                    }

                    if( $inner_field_resize_width != '' ){
                        $inner_field_resize_width = json_decode( $inner_field_resize_width, true );
                    }

                    $arf_sorted_fields = array();
                    $arf_temp_sorted_fields = array();
                    if ($field_order != '') {
                        $field_order = json_decode($field_order, true);

                        asort($field_order);

                        $updated_field_order = array();

                        $ficnt = 1;
                        foreach( $field_order as $tmpfkey => $tmpfva ){
                            $current_fval = current( $field_order );
                            $current_fkey = key( $field_order );
                            $next_fval = next( $field_order );
                            $next_fkey = key( $field_order );

                            $current_exp_data = explode( '|', $current_fkey );
                            $next_exp_data = explode( '|', $next_fkey );

                            if( 'arf21colclass' == $current_exp_data[0] && 'arf_2col' != $next_exp_data[0] && !preg_match( '/_confirm/', $next_exp_data[0] ) ){
                                $updated_field_order[ $current_exp_data[0] .'|'.$ficnt] = $ficnt;
                                $updated_field_order[ 'arf_2col|' . ( $ficnt + 1 ) ] = ( $ficnt + 1 );
                                $ficnt++;
                            } else if( 'arf_23col' == $current_exp_data[0] && 'arf_3col' != $next_exp_data[0] && !preg_match( '/_confirm/', $next_exp_data[0] ) ){
                                $updated_field_order[ $current_exp_data[0] .'|'.$ficnt] = $ficnt;
                                $updated_field_order[ 'arf_3col|' . ( $ficnt + 1 ) ] = ( $ficnt + 1 );
                                $ficnt++;
                            } else if( 'arf43colclass' == $current_exp_data[0] && 'arf_4col' != $next_exp_data[0] && !preg_match( '/_confirm/', $next_exp_data[0] ) ) {
                                $updated_field_order[ $current_exp_data[0] .'|'.$ficnt] = $ficnt;
                                $updated_field_order[ 'arf_4col|' . ( $ficnt + 1 ) ] = ( $ficnt + 1 );
                                $ficnt++;
                            } else if ( 'arf54colclass' == $current_exp_data[0] && 'arf_5col' != $next_exp_data[0] && !preg_match( '/_confirm/', $next_exp_data[0] ) ) {
                                $updated_field_order[ $current_exp_data[0] .'|'.$ficnt] = $ficnt;
                                $updated_field_order[ 'arf_5col|' . ( $ficnt + 1 ) ] = ( $ficnt + 1 );
                                $ficnt++;
                            } else if (  'arf65colclass' == $current_exp_data[0] && 'arf_6col' != $next_exp_data[0] && !preg_match( '/_confirm/', $next_exp_data[0] )  ){
                                $updated_field_order[ $current_exp_data[0] .'|'.$ficnt] = $ficnt;
                                $updated_field_order[ 'arf_6col|' . ( $ficnt + 1 ) ] = ( $ficnt + 1 );
                                $ficnt++;
                            } else {
                                $updated_field_order[ $tmpfkey] = $ficnt;
                            }

                            $ficnt++;
                        }

                        $field_order = $updated_field_order;
                        $sorted_counter = 0;
                        foreach ($field_order as $field_id => $order) {
                            if(is_int($field_id)){
                                foreach ($arf_fields as $field) {
                                    if ($field_id == $field['id']) {
                                        $arf_sorted_fields[] = $field;
                                        $temp_field_opts = arf_json_decode( $field['field_options'],true );
                                        $arf_temp_sorted_fields[ $sorted_counter ] = !empty( $temp_field_opts['inner_class'] ) ? $temp_field_opts['inner_class'] : 'arf_1col';
                                    }
                                }
                            } else {
                                $exploded_fid = explode( '|', $field_id );
                                $temp_fid = $exploded_fid[0];
                                $prev_sorted_counter = $sorted_counter - 1;

                                if( !empty( $arf_temp_sorted_fields[ $prev_sorted_counter ] ) ){
                                    $prev_inner_class = $arf_temp_sorted_fields[ $prev_sorted_counter ];
                                    if( $temp_fid == 'arf_2col' && !preg_match( '/(arf21colclass)/', $prev_inner_class ) ){
                                        continue;
                                    } else if( $temp_fid == 'arf_3col' && !preg_match( '/(arf_23col)/', $prev_inner_class ) ){
                                        continue;
                                    } else if( $temp_fid == 'arf_4col' && !preg_match( '/(arf43colclass)/', $prev_inner_class ) ){
                                        continue;
                                    } else if( $temp_fid == 'arf_5col' && !preg_match( '/(arf54colclass)/', $prev_inner_class ) ){
                                        continue;
                                    } else if( $temp_fid == 'arf_6col' && !preg_match( '/(arf65colclass)/', $prev_inner_class ) ){
                                        continue;
                                    }
                                }

                                $arf_sorted_fields[] = $field_id;
                                $arf_temp_sorted_fields[ $sorted_counter ] = $field_id;
                            }
                            $sorted_counter++;
                        }
                    }
                    
                    if (isset($arf_sorted_fields) && !empty($arf_sorted_fields)) {
                        $arf_fields = $arf_sorted_fields;
                    }

                    $class_array = array();
                    $conut_arf_fields = count($arf_fields);

                    $repeater_fields = array();
                    $inner_field_count = 0;
                    $field_classes = array();
                    $field_classes2 = array();
                    $ncounter = 0;
                    foreach( $arf_fields as $field_key => $field ){

                        $display_field_in_editor_from_outside = apply_filters( 'arf_display_field_in_editor_outside', false, $field);
                        if( is_array( $field ) ){
                            if( 'hidden' == $field['type'] ){
                                continue;
                            }
                            $field_opt = json_decode($field['field_options'], true);
                            
                            if (json_last_error() != JSON_ERROR_NONE) {
                                $field_opt = maybe_unserialize($field['field_options']);
                            }

                            $class = (isset($field_opt['inner_class']) && $field_opt['inner_class']) ? $field_opt['inner_class'] : 'arf_1col';
                            if( false == $display_field_in_editor_from_outside ){
                                $field_classes2[ $field['id'] ] = $class;
                            } else {
                                if( isset( $_REQUEST['arfaction'] ) && $_REQUEST['arfaction'] == 'duplicate' ){
                                    $get_all_inner_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `".$MdlDb->fields."` WHERE form_id = %d AND (field_options LIKE '%\"parent_field\":\"%d\"%' OR field_options LIKE '%\"parent_field\":%d%') ", $_REQUEST['id'], $field['id'], $field['id'] ), ARRAY_A );
                                } else {
                                    $get_all_inner_fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `".$MdlDb->fields."` WHERE form_id = %d AND (field_options LIKE '%\"parent_field\":\"%d\"%' OR field_options LIKE '%\"parent_field\":%d%') ", $id, $field['id'], $field['id'] ), ARRAY_A );
                                }
                                $inner_field_order_obj = arf_json_decode( $inner_field_order, true );

                                if( !empty( $inner_field_order_obj[$field['id']] ) ){
                                    
                                    $inner_fields = $inner_field_order_obj[$field['id']];
                                    $pre_field_id = array();
                                    foreach( $inner_fields as $ikey => $ifield_order ){
                                        $ifeld_data = explode('|', $ifield_order);
                                        $temp_fid = $ifeld_data[0];
                                        if( !empty( $pre_field_id ) && in_array( $temp_fid, $pre_field_id ) ){
                                            continue;
                                        }

                                        if( empty( $pre_field_id ) || !in_array( $temp_fid, $pre_field_id) ){
                                            array_push($pre_field_id, $temp_fid );
                                        }
                                        if( preg_match('/^(\d+)$/',$temp_fid ) ){
                                            $ifobj = $arffield->getOne( $temp_fid );
                                            $ifobj_opts = $ifobj->field_options;

                                            $iclass = (isset($ifobj_opts['inner_class']) && $ifobj_opts['inner_class']) ? $ifobj_opts['inner_class'] : 'arf_1col';
                                            if( ! isset( $field_classes2[ $field['id'] ] )){
                                                $field_classes2[ $field['id'] ] = array();
                                            }
                                            $field_classes2[ $field['id'] ][ $temp_fid ] = $iclass;
                                        } else {
                                            $field_classes2[ $field['id'] ][ $temp_fid ] = $temp_fid;
                                        }

                                    }
                                }
                            }
                        } else {
                            $field_classes2[ $field ] = $field;
                        }
                        $ncounter++;
                    }
                    $ar2col_keys = array();
                    
                    if( !empty( $field_classes2 ) ){
                        foreach( $field_classes2 as $fckey => $fcval ){
                            if( is_array( $fcval ) ){
                                foreach( $fcval as $fcikey => $fcival ){
                                    $current_val = current( $fcval );
                                    $next_val = next( $fcval );
                                    $next_key = key( $fcval );

                                    if( 'arf21colclass' == $current_val && 'arf_2col' != $next_val && !preg_match( '/_confirm/', $next_val ) ){
                                        $temp_inner_fields = !empty( $temp_inner_order_arr[ $fckey ] ) ? $temp_inner_order_arr[ $fckey ] : array();

                                        if( !empty( $temp_inner_fields ) ){
                                            foreach( $temp_inner_fields as $tikey => $tival ){
                                                $temp_exploded_data = explode( '|', $tival );

                                                $tempinfid = $temp_exploded_data[0];

                                                if( $fcikey == $tempinfid ){
                                                    array_splice( $temp_inner_order_arr[$fckey], ($tikey + 1), 0, 'arf_2col|'. ($temp_exploded_data[1] + 1) );
                                                }

                                            }
                                        }
                                    } else if( 'arf_23col' == $current_val && 'arf_3col' != $next_val && !preg_match( '/_confirm/', $next_val ) ){
                                        $temp_inner_fields = !empty( $temp_inner_order_arr[ $fckey ] ) ? $temp_inner_order_arr[ $fckey ] : array();

                                        if( !empty( $temp_inner_fields ) ){
                                            foreach( $temp_inner_fields as $tikey => $tival ){
                                                $temp_exploded_data = explode( '|', $tival );

                                                $tempinfid = $temp_exploded_data[0];

                                                if( $fcikey == $tempinfid ){
                                                    array_splice( $temp_inner_order_arr[$fckey], ($tikey + 1), 0, 'arf_3col|'. ($temp_exploded_data[1] + 1) );
                                                }

                                            }
                                        }
                                    } else if( 'arf43colclass' == $current_val && 'arf_4col' != $next_val && !preg_match( '/_confirm/', $next_val ) ){
                                        $temp_inner_fields = !empty( $temp_inner_order_arr[ $fckey ] ) ? $temp_inner_order_arr[ $fckey ] : array();

                                        if( !empty( $temp_inner_fields ) ){
                                            foreach( $temp_inner_fields as $tikey => $tival ){
                                                $temp_exploded_data = explode( '|', $tival );

                                                $tempinfid = $temp_exploded_data[0];

                                                if( $fcikey == $tempinfid ){
                                                    array_splice( $temp_inner_order_arr[$fckey], ($tikey + 1), 0, 'arf_4col|'. ($temp_exploded_data[1] + 1) );
                                                }

                                            }
                                        }
                                    } else if ( 'arf54colclass' == $current_val && 'arf_5col' != $next_val && !preg_match( '/_confirm/', $next_val ) ){
                                        if( !empty( $temp_inner_fields ) ){
                                            foreach( $temp_inner_fields as $tikey => $tival ){
                                                $temp_exploded_data = explode( '|', $tival );

                                                $tempinfid = $temp_exploded_data[0];

                                                if( $fcikey == $tempinfid ){
                                                    array_splice( $temp_inner_order_arr[$fckey], ($tikey + 1), 0, 'arf_4col|'. ($temp_exploded_data[1] + 1) );
                                                }

                                            }
                                        }
                                    } else if( 'arf65colclass' == $current_val && 'arf_6col' != $next_val && !preg_match( '/_confirm/', $next_val ) ){
                                        if( !empty( $temp_inner_fields ) ){
                                            foreach( $temp_inner_fields as $tikey => $tival ){
                                                $temp_exploded_data = explode( '|', $tival );

                                                $tempinfid = $temp_exploded_data[0];

                                                if( $fcikey == $tempinfid ){
                                                    array_splice( $temp_inner_order_arr[$fckey], ($tikey + 1), 0, 'arf_6col|'. ($temp_exploded_data[1] + 1) );
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    $inner_field_order = json_encode( $temp_inner_order_arr );
                    foreach ($arf_fields as $field_key => $field) {
                        $display_field_in_editor_from_outside = apply_filters( 'arf_display_field_in_editor_outside', false, $field);

                        if(is_array($field)){
			                if( $field['type'] == 'hidden'){
                                continue;
                            }
                            if ($field['type'] == 'break' && $arf_is_page_break_no == 0) {
                                $field['page_break_first_use'] = 1;
                                $arf_is_page_break_no++;
                            }
                            if ($field['type'] == 'arf_multiselect') {
                                $field_name = "item_meta[" . $field['id'] . "][]";   
                            }else{
                                $field_name = "item_meta[" . $field['id'] . "]";
                            }
                            
                            $has_field_opt = false;
                            if (isset($field['options']) && $field['options'] != '' && !empty($field['options'])) {
                                $has_field_opt = true;
                                $field_options_db = json_decode($field['options'], true);
                                if (json_last_error() != JSON_ERROR_NONE) {
                                    $field_options_db = maybe_unserialize($field['options'], true);
                                }
                            }
                            
                            $field_opt = json_decode($field['field_options'], true);
                            
                            if (json_last_error() != JSON_ERROR_NONE) {
                                $field_opt = maybe_unserialize($field['field_options']);
                            }

                            $class = (isset($field_opt['inner_class']) && $field_opt['inner_class']) ? $field_opt['inner_class'] : 'arf_1col';
                            $field_classes[] = $class;
                            array_push($class_array,$class);

                            if (isset($field_opt) && !empty($field_opt) && is_array($field_opt) ) {
                                foreach ($field_opt as $k => $field_opt_val) {
                                    if ($k != 'options') {
                                        $field[$k] = $arformcontroller->arf_html_entity_decode($field_opt_val);
                                    } else {
                                        if ($has_field_opt == true && $k == 'options') {
                                            $field[$k] = $field_options_db;
                                        }
                                    }
                                }
                            }
                            if (in_array($field['type'], $bootstraped_fields_array)) {
                                array_push($fields_with_external_js, $field['type']);
                            }
                        } else {
                            $field_classes[] = $field;
                        }

                        if( !$display_field_in_editor_from_outside ){
                            require(VIEWS_PATH . '/arf_field_editor.php');
                        } else {
                            global $index_repeater_fields;
                            do_action( 'arf_render_field_in_editor_outside', $field, $field_data_obj, $field_order,$inner_field_order, $index_arf_fields, $frm_css, $data, $id, $inner_field_resize_width, array(), false, $newarr );
                            global $index_repeater_fields;
                            $index_arf_fields = $index_repeater_fields;
                        }
                        
                        unset($field);


                        unset($field_name);

                        $arf_field_counter++;
                    }
                }
                
                ?>

            </div>

            <?php
            echo "<label class='arf_main_label arf_width_counter_label'></label>";            
            echo "<label class='arf_main_label arf_width_counter_label_section'></label>";           
            $newarr['arfsubmitbuttontext'] = isset($newarr['arfsubmitbuttontext']) ? $newarr['arfsubmitbuttontext'] : '';
            if ($newarr['arfsubmitbuttontext'] == '') {
                $arf_option = get_option('arf_options');
                $submit_value = $arf_option->submit_value;
            } else {
                $submit_value = esc_attr($newarr['arfsubmitbuttontext']);
            }

            $submit_buttonwidth = isset($newarr['arfsubmitbuttonwidthsetting']) ? $newarr['arfsubmitbuttonwidthsetting'] : '';
            ?>
            <div style="clear:both;"></div>
            <div class="arfeditorsubmitdiv arf_submit_div top_container">
                <div class="arfsubmitedit arfsubmitbutton">
                    <div class="arf_greensave_button_wrapper">
                        <?php 
                        $arfsubmitbuttonstyleclass = '';

                        if(isset($newarr['arfsubmitbuttonstyle']) && $newarr['arfsubmitbuttonstyle'] == 'flat'){
                            $arfsubmitbuttonstyleclass= 'arf_submit_btn_flat';
                        } else if(isset($newarr['arfsubmitbuttonstyle']) &&  $newarr['arfsubmitbuttonstyle'] == 'border'){
                            $arfsubmitbuttonstyleclass= 'arf_submit_btn_border';
                        } else if(isset($newarr['arfsubmitbuttonstyle']) && $newarr['arfsubmitbuttonstyle'] == 'reverse border'){
                            $arfsubmitbuttonstyleclass= 'arf_submit_btn_reverse_border';
                        }
                        ?>
                        <div class="greensavebtn arf_submit_btn btn btn-info arfstyle-button waves-effect waves-light <?php echo $arfsubmitbuttonstyleclass;?>" data-auto="<?php
                        if ($submit_buttonwidth != '') {
                            echo '1';
                        } else {
                            echo '0';
                        }
                        ?>" <?php
                                if ($submit_buttonwidth != '') {
                                    echo 'style="width:' . $submit_buttonwidth . 'px;"';
                                }
                                ?> data-style="zoom-in" data-width="<?php echo $submit_buttonwidth; ?>">
                            <div class="arfsubmitbtn arf_edit_in_place" id="arfeditorsubmit">
                                <input type='text' class='arf_edit_in_place_input inplace_field arf_submit_button_textbox' data-id="arf_form_submit_button" data-ajax='false' value="<?php echo $submit_value; ?>" />
                            </div>
                        </div>
                        <span class="arf_submit_button_edit_icon"><svg width='18' height='18' fill='rgb(255, 255, 255)' xmlns='http://www.w3.org/2000/svg' data-name='Layer 1' viewBox='0 0 512 512' x='0px' y='0px'><title>Edit</title><path d='M318.37,85.45L422.53,190.11,158.89,455,54.79,350.38ZM501.56,60.2L455.11,13.53a45.93,45.93,0,0,0-65.11,0L345.51,58.24,449.66,162.9l51.9-52.15A35.8,35.8,0,0,0,501.56,60.2ZM0.29,497.49a11.88,11.88,0,0,0,14.34,14.17l116.06-28.28L26.59,378.72Z'/></svg></span>
                    </div>
                </div>
                <div class="arfsubmiteditpencil arfhelptip" title="<?php echo addslashes(esc_html__('Edit Text', 'ARForms')); ?>"></div>
                <div class="arfsubmitsettingpencil arfhelptip" title="<?php echo addslashes(esc_html__('Settings', 'ARForms')); ?>" id="field-setting-button-arfsubmit" onclick="arfshowfieldoptions('arfsubmit')" data-lower="false"></div>
            </div>
        </div>
    </div>
    <?php
    $key = isset($values['form_key']) ? $values['form_key'] : '';

    $width = isset($_COOKIE['width']) ? $_COOKIE['width'] * 0.80 : 0;

    $width_new = '&width=' . $width;
    ?>
    <?php
    $delete_modal_width = isset($_COOKIE['width']) ? ($_COOKIE['width'] - 850) / 2 : 'auto';
    $delete_modal_height = isset($_COOKIE['height']) ? ($_COOKIE['height'] - 500) / 2 : 'auto';
    ?>
    <div style="clear:both;"></div>

</div>




<?php
$widthmaincontent = isset($_COOKIE['width']) ? $_COOKIE['width'] - 650 : 0;
$extra_width = "0";

$left_width = ( ($widthmaincontent) / 2 + $extra_width) . 'px';
if (is_rtl()) {
    $iframediv_loader_style = 'right:' . $left_width . ';top:180px;';
} else {
    $iframediv_loader_style = 'left:' . $left_width . ';top:180px;';
}

$delete_modal_width = isset($_COOKIE['width']) ? ($_COOKIE['width'] - 350) / 2 : 'auto';
$delete_modal_height = isset($_COOKIE['height']) ? ($_COOKIE['height'] - 180) / 2 : 'auto';

$key = isset($values['form_key']) ? $values['form_key'] : '';
?>
<div style="left:-999px; position:fixed; visibility:hidden;">
    <div class="greensavebtn" style="float:left;min-width: 105px;" id="arfsubmitbuttontext2"><?php echo $submit_value; ?></div>
</div>
<input type="hidden" name="arf_editor_total_rows" id="arf_editor_total_rows" value="<?php echo $index_arf_fields;?>" />