/**
     * Generic function to render rows and columns of active areas for widgets & fields
     * @param  string $template_id The current slug of the selected View template
     * @param  string $type   Either 'widget' or 'field'
     * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
     * @param  array $rows    The layout structure: rows, columns and areas
     * @param  array $values  Saved objects
     * @return void
     */
    function render_active_areas($template_id, $type, $zone, $rows, $values)
    {
        global $post;
        if ($type === 'widget') {
            $button_label = __('Add Widget', 'gravityview');
        } else {
            $button_label = __('Add Field', 'gravityview');
        }
        $available_items = array();
        // if saved values, get available fields to label everyone
        if (!empty($values) && (!empty($post->ID) || !empty($_POST['template_id']))) {
            if (!empty($_POST['template_id'])) {
                $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']);
            } else {
                $form = gravityview_get_form_id($post->ID);
            }
            if ('field' === $type) {
                $available_items = $this->get_available_fields($form, $zone);
            } else {
                $available_items = $this->get_registered_widgets();
            }
        }
        foreach ($rows as $row) {
            foreach ($row as $col => $areas) {
                $column = $col == '2-2' ? '1-2' : $col;
                ?>

				<div class="gv-grid-col-<?php 
                echo esc_attr($column);
                ?>
">

					<?php 
                foreach ($areas as $area) {
                    ?>

						<div class="gv-droppable-area">
							<div class="active-drop active-drop-<?php 
                    echo esc_attr($type);
                    ?>
" data-areaid="<?php 
                    echo esc_attr($zone . '_' . $area['areaid']);
                    ?>
">

								<?php 
                    // render saved fields
                    if (!empty($values[$zone . '_' . $area['areaid']])) {
                        foreach ($values[$zone . '_' . $area['areaid']] as $uniqid => $field) {
                            $input_type = NULL;
                            $original_item = isset($available_items[$field['id']]) ? $available_items[$field['id']] : false;
                            if (!$original_item) {
                                do_action('gravityview_log_error', 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array('available_items' => $available_items, 'field' => $field));
                                $original_item = $field;
                            } else {
                                $input_type = isset($original_item['type']) ? $original_item['type'] : NULL;
                            }
                            // Field options dialog box
                            $field_options = GravityView_Render_Settings::render_field_options($type, $template_id, $field['id'], $original_item['label'], $zone . '_' . $area['areaid'], $input_type, $uniqid, $field, $zone, $original_item);
                            $item = array('input_type' => $input_type, 'settings_html' => $field_options, 'label_type' => $type);
                            // Merge the values with the current item to pass things like widget descriptions and original field names
                            if ($original_item) {
                                $item = wp_parse_args($item, $original_item);
                            }
                            switch ($type) {
                                case 'widget':
                                    echo new GravityView_Admin_View_Widget($item['label'], $field['id'], $item, $field);
                                    break;
                                default:
                                    echo new GravityView_Admin_View_Field($item['label'], $field['id'], $item, $field);
                            }
                            //endif;
                        }
                    }
                    // End if zone is not empty
                    ?>

								<span class="drop-message"><?php 
                    echo sprintf(esc_attr__('"+ %s" or drag existing %ss here.', 'gravityview'), $button_label, $type);
                    ?>
</span>
							</div>
							<div class="gv-droppable-area-action">
								<a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php 
                    echo esc_attr($type);
                    ?>
" data-areaid="<?php 
                    echo esc_attr($zone . '_' . $area['areaid']);
                    ?>
" data-context="<?php 
                    echo esc_attr($zone);
                    ?>
"><?php 
                    echo '+ ' . esc_html($button_label);
                    ?>
</a>
								<p class="gv-droppable-area-title"><strong><?php 
                    echo esc_html($area['title']);
                    ?>
</strong><?php 
                    if (!empty($area['subtitle'])) {
                        ?>
<span class="gv-droppable-area-subtitle"> &ndash; <?php 
                        echo esc_html($area['subtitle']);
                        ?>
</span><?php 
                    }
                    ?>
</p>
							</div>
						</div>

					<?php 
                }
                ?>

				</div>
			<?php 
            }
        }
    }
 /**
  * Returns field options - called by ajax when dropping fields into active areas
  * AJAX callback
  *
  * @access public
  * @return void
  */
 function get_field_options()
 {
     $this->check_ajax_nonce();
     if (empty($_POST['template']) || empty($_POST['area']) || empty($_POST['field_id']) || empty($_POST['field_type'])) {
         do_action('gravityview_log_error', '[get_field_options] Required fields were not set in the $_POST request. ');
         exit(false);
     }
     // Fix apostrophes added by JSON response
     $post = array_map('stripslashes_deep', $_POST);
     // Sanitize
     $post = array_map('esc_attr', $post);
     // The GF type of field: `product`, `name`, `creditcard`, `id`, `text`
     $input_type = isset($post['input_type']) ? esc_attr($post['input_type']) : NULL;
     $context = isset($post['context']) ? esc_attr($post['context']) : NULL;
     $response = GravityView_Render_Settings::render_field_options($post['field_type'], $post['template'], $post['field_id'], $post['field_label'], $post['area'], $input_type, '', '', $context);
     $response = gravityview_strip_whitespace($response);
     exit($response);
 }