function make_directory($atts)
    {
        global $wpdb, $wp_rewrite, $post, $wpdb, $directory_shown, $kws_gf_scripts, $kws_gf_styles;
        if (!class_exists('GFEntryDetail')) {
            @(require_once GFCommon::get_base_path() . "/entry_detail.php");
        }
        if (!class_exists('GFCommon')) {
            @(require_once WP_PLUGIN_DIR . "/gravityforms/common.php");
        }
        if (!class_exists('RGFormsModel')) {
            @(require_once WP_PLUGIN_DIR . "/gravityforms/forms_model.php");
        }
        //quit if version of wp is not supported
        if (!class_exists('GFCommon') || !GFCommon::ensure_wp_version()) {
            return;
        }
        ob_start();
        // Using ob_start() allows us to use echo instead of $output .=
        foreach ($atts as $key => $att) {
            if (strtolower($att) == 'false') {
                $atts[$key] = false;
            }
            if (strtolower($att) == 'true') {
                $atts[$key] = true;
            }
        }
        $atts['approved'] = isset($atts['approved']) ? $atts['approved'] : -1;
        if (!empty($atts['lightboxsettings']) && is_string($atts['lightboxsettings'])) {
            $atts['lightboxsettings'] = explode(',', $atts['lightboxsettings']);
        }
        $options = self::directory_defaults($atts);
        // Make sure everything is on the same page.
        if (is_array($options['lightboxsettings'])) {
            foreach ($options['lightboxsettings'] as $key => $value) {
                if (is_numeric($key)) {
                    $options['lightboxsettings']["{$value}"] = $value;
                    unset($options['lightboxsettings']["{$key}"]);
                }
            }
        }
        extract($options);
        $form_id = $form;
        $form = RGFormsModel::get_form_meta($form_id);
        if (empty($form)) {
            return;
        }
        $sort_field = empty($_GET["sort"]) ? $sort : $_GET["sort"];
        $sort_direction = empty($_GET["dir"]) ? $dir : $_GET["dir"];
        $search_query = !empty($_GET["gf_search"]) ? $_GET["gf_search"] : null;
        $start_date = !empty($_GET["start_date"]) ? $_GET["start_date"] : $start_date;
        $end_date = !empty($_GET["end_date"]) ? $_GET["end_date"] : $end_date;
        $page_index = empty($_GET["page"]) ? $startpage - 1 : intval($_GET["page"]) - 1;
        $star = isset($_GET["star"]) && is_numeric($_GET["star"]) ? intval($_GET["star"]) : null;
        $read = isset($_GET["read"]) && is_numeric($_GET["read"]) ? intval($_GET["read"]) : null;
        $first_item_index = $page_index * $page_size;
        $link_params = array();
        if (!empty($page_index)) {
            $link_params['page'] = $page_index;
        }
        $formaction = remove_query_arg(array('gf_search', 'sort', 'dir', 'page', 'edit'), add_query_arg($link_params));
        $tableclass .= !empty($jstable) ? ' tablesorter' : '';
        $title = $form["title"];
        $sort_field_meta = RGFormsModel::get_field($form, $sort_field);
        $is_numeric = $sort_field_meta["type"] == "number";
        $columns = RGFormsModel::get_grid_columns($form_id, true);
        $approvedcolumn = false;
        if ($approved || !empty($smartapproval) && $approved === -1) {
            $approvedcolumn = self::get_approved_column($form);
        }
        if (!empty($smartapproval) && $approved === -1 && !empty($approvedcolumn)) {
            $approved = true;
            // If there is an approved column, turn on approval
        } else {
            $approved = false;
            // Otherwise, show entries as normal.
        }
        $entrylinkcolumns = self::get_entrylink_column($form, $entry);
        $adminonlycolumns = self::get_admin_only($form);
        //
        // Show only a single entry
        //
        if (!empty($entry) && ($detail = self::process_lead_detail(true, $entryback, $showadminonly, $adminonlycolumns, $approvedcolumn, $options, $entryonly))) {
            echo $detail;
            if (!empty($entryonly)) {
                do_action('kws_gf_after_directory', do_action('kws_gf_after_directory_form_' . $form_id, $form, compact($approved, $sort_field, $sort_direction, $search_query, $first_item_index, $page_size, $star, $read, $is_numeric, $start_date, $end_date)));
                $content = ob_get_contents();
                // Get the output
                ob_end_clean();
                // Clear the cache
                // If the form is form #2, two filters are applied: `kws_gf_directory_output_2` and `kws_gf_directory_output`
                $content = apply_filters('kws_gf_directory_output', apply_filters('kws_gf_directory_output_' . $form_id, self::pseudo_filter($content, $directoryview)));
                return $content;
            }
        }
        //
        // Or start to generate the directory
        //
        $leads = GFDirectory::get_leads($form_id, $sort_field, $sort_direction, $search_query, $first_item_index, $page_size, $star, $read, $is_numeric, $start_date, $end_date, 'active', $approvedcolumn, $limituser);
        #			if(!$showadminonly)	 {
        $columns = self::remove_admin_only($columns, $adminonlycolumns, $approvedcolumn, false, false, $form);
        $leads = self::remove_admin_only($leads, $adminonlycolumns, $approvedcolumn, true, false, $form);
        #			}
        // Allow lightbox to determine whether showadminonly is valid without passing a query string in URL
        if ($entry === true && !empty($lightboxsettings['entry'])) {
            if (get_transient('gf_form_' . $form_id . '_post_' . $post->ID . '_showadminonly') != $showadminonly) {
                set_transient('gf_form_' . $form_id . '_post_' . $post->ID . '_showadminonly', $showadminonly, 60 * 60);
            }
        } else {
            delete_transient('gf_form_' . $form_id . '_post_' . $post->ID . '_showadminonly');
        }
        // Get a list of query args for the pagination links
        if (!empty($search_query)) {
            $args["gf_search"] = urlencode($search_query);
        }
        if (!empty($sort_field)) {
            $args["sort"] = $sort_field;
        }
        if (!empty($sort_direction)) {
            $args["dir"] = $sort_direction;
        }
        if (!empty($star)) {
            $args["star"] = $star;
        }
        if ($page_size > 0) {
            $lead_count = self::get_lead_count($form_id, $search_query, $star, $read, $approvedcolumn, $approved, $leads, $start_date, $end_date, $limituser);
            $page_links = array('base' => @add_query_arg('page', '%#%'), 'format' => '&page=%#%', 'add_args' => $args, 'prev_text' => $prev_text, 'next_text' => $next_text, 'total' => ceil($lead_count / $page_size), 'current' => $page_index + 1, 'show_all' => $pagelinksshowall);
            $page_links = apply_filters('kws_gf_results_pagination', $page_links);
            $page_links = paginate_links($page_links);
        } else {
            // Showing all results
            $page_links = false;
            $lead_count = sizeof($leads);
        }
        if (!isset($directory_shown)) {
            $directory_shown = true;
            if (!empty($lightboxsettings['images']) || !empty($lightboxsettings['entry'])) {
                if (!is_array($kws_gf_scripts) || !in_array('colorbox', $kws_gf_scripts)) {
                    wp_print_scripts(array("colorbox"));
                }
                if (!is_array($kws_gf_styles) || !in_array('colorbox', $kws_gf_styles)) {
                    wp_print_styles(array("colorbox"));
                }
            }
            if (!empty($jstable)) {
                ?>
				<?php 
                if (!in_array('tablesorter-blue', $kws_gf_styles)) {
                    ?>
					<link href="<?php 
                    echo WP_PLUGIN_URL . "/" . basename(dirname(__FILE__));
                    ?>
/tablesorter/themes/blue/style.css" rel="stylesheet" />
				<?php 
                }
                if (!in_array('tablesorter-min', $kws_gf_scripts)) {
                    ?>
					<script type="text/javascript" src="<?php 
                    echo WP_PLUGIN_URL . "/" . basename(dirname(__FILE__));
                    ?>
/tablesorter/jquery.tablesorter.min.js"></script>				
				<?php 
                }
            }
            ?>
				
				<script type="text/javascript">
					<?php 
            if (!empty($lightboxsettings['images']) || !empty($lightboxsettings['entry'])) {
                ?>
		
					var tb_pathToImage = "<?php 
                echo site_url('/wp-includes/js/thickbox/loadingAnimation.gif');
                ?>
";
					var tb_closeImage = "<?php 
                echo site_url('/wp-includes/js/thickbox/tb-close.png');
                ?>
";
					var tb_height = 600;
					<?php 
            }
            ?>
					function not_empty(variable) { 
						if(variable == '' || variable == null || variable == 'undefined' || typeof(variable) == 'undefined') {
							return false;
						} else { 
							return true;
						}
					}
				
				<?php 
            if (!empty($jstable)) {
                ?>
					jQuery(document).ready(function($) {
						jQuery('.tablesorter').each(function() { 
							$(this).tablesorter(<?php 
                echo apply_filters('kws_gf_directory_tablesorter_options', '');
                ?>
); 
						});
					});
				<?php 
            } else {
                if (isset($jssearch) && $jssearch) {
                    ?>
					function Search(search, sort_field_id, sort_direction){
						if(not_empty(search)) { var search = "&gf_search=" + encodeURIComponent(search); } else {  var search = ''; }
						if(not_empty(sort_field_id)) { var sort = "&sort=" + sort_field_id; } else {  var sort = ''; }
						if(not_empty(sort_direction)) { var dir = "&dir=" + sort_direction; } else {  var dir = ''; }
						var page = '<?php 
                    if ($wp_rewrite->using_permalinks()) {
                        echo '?';
                    } else {
                        echo '&';
                    }
                    ?>
page='+<?php 
                    echo isset($_GET['page']) ? intval($_GET['page']) : '"1"';
                    ?>
;
						var location = "<?php 
                    echo get_permalink($post->ID);
                    ?>
"+page+search+sort+dir;
						document.location = location;
					}
				<?php 
                }
            }
            ?>
				</script>
				<link rel="stylesheet" href="<?php 
            echo GFCommon::get_base_url();
            ?>
/css/admin.css" type="text/css" />
			<?php 
        }
        ?>
			
			<div class="wrap">
				<?php 
        if ($icon) {
            ?>
<img alt="<?php 
            _e("Gravity Forms", "gravity-forms-addons");
            ?>
" src="<?php 
            echo GFCommon::get_base_url();
            ?>
/images/gravity-title-icon-32.png" style="float:left; margin:15px 7px 0 0;"/><?php 
        }
        ?>
				<?php 
        if ($titleshow) {
            ?>
<h2><?php 
            echo $titleprefix . $title;
            ?>
 </h2><?php 
        }
        ?>
				<?php 
        if ($search && ($lead_count > 0 || !empty($_GET['gf_search']))) {
            ?>
				<form id="lead_form" method="get" action="<?php 
            echo $formaction;
            ?>
">
					<p class="search-box">
						<label class="hidden" for="lead_search"><?php 
            _e("Search Entries:", "gravity-forms-addons");
            ?>
</label>
						<input type="text" name="gf_search" id="lead_search" value="<?php 
            echo $search_query;
            ?>
"<?php 
            if ($searchtabindex) {
                echo ' tabindex="' . intval($searchtabindex) . '"';
            }
            ?>
 />
						<?php 
            if (!empty($_GET['p'])) {
                ?>
							<input name="p" type="hidden" value="<?php 
                echo esc_html($_GET['p']);
                ?>
" />
						<?php 
            }
            ?>
						<input type="submit" class="button" id="lead_search_button" value="<?php 
            _e("Search", "gravity-forms-addons");
            ?>
"<?php 
            if ($searchtabindex) {
                echo ' tabindex="' . intval($searchtabindex++) . '"';
            }
            ?>
 />
					</p>
				</form>
				<?php 
        }
        //Displaying paging links if appropriate
        if ($lead_count > 0 && $showcount || $page_links) {
            if ($lead_count == 0) {
                $first_item_index--;
            }
            ?>
					<div class="tablenav">
						<div class="tablenav-pages">
							<?php 
            if ($showcount) {
                if ($first_item_index + $page_size > $lead_count || $page_size <= 0) {
                    $second_part = $lead_count;
                } else {
                    $second_part = $first_item_index + $page_size;
                }
                ?>
							<span class="displaying-num"><?php 
                printf(__("Displaying %d - %d of %d", "gravity-forms-addons"), $first_item_index + 1, $second_part, $lead_count);
                ?>
</span>
							<?php 
            }
            if ($page_links) {
                echo $page_links;
            }
            ?>
						</div>
						<div class="clear"></div>
					</div>
						<?php 
        }
        do_action('kws_gf_before_directory_after_nav', do_action('kws_gf_before_directory_after_nav_form_' . $form_id, $form, $leads, compact($approved, $sort_field, $sort_direction, $search_query, $first_item_index, $page_size, $star, $read, $is_numeric, $start_date, $end_date)));
        ?>
					
					<table class="<?php 
        echo $tableclass;
        ?>
" cellspacing="0"<?php 
        if (!empty($tablewidth)) {
            echo ' width="' . $tablewidth . '"';
        }
        echo $tablestyle ? ' style="' . $tablestyle . '"' : '';
        ?>
>
					<?php 
        if ($thead) {
            ?>
					<thead>
						<tr>
							<?php 
            $addressesExist = false;
            foreach ($columns as $field_id => $field_info) {
                $dir = $field_id == 0 ? "DESC" : "ASC";
                //default every field so ascending sorting except date_created (id=0)
                if ($field_id == $sort_field) {
                    //reverting direction if clicking on the currently sorted field
                    $dir = $sort_direction == "ASC" ? "DESC" : "ASC";
                }
                if (is_array($adminonlycolumns) && !in_array($field_id, $adminonlycolumns) || is_array($adminonlycolumns) && in_array($field_id, $adminonlycolumns) && $showadminonly || !$showadminonly) {
                    if ($field_info['type'] == 'address' && $appendaddress && $hideaddresspieces) {
                        $addressesExist = true;
                        continue;
                    }
                    ?>
								<?php 
                    if (isset($jssearch) && $jssearch && !isset($jstable)) {
                        ?>
								<th scope="col" class="manage-column" onclick="Search('<?php 
                        echo $search_query;
                        ?>
', '<?php 
                        echo $field_id;
                        ?>
', '<?php 
                        echo $dir;
                        ?>
');" style="cursor:pointer;"><?php 
                    } elseif (isset($jstable) && $jstable) {
                        ?>
									<th scope="col" class="manage-column">
								<?php 
                    } else {
                        ?>
								<th scope="col" class="manage-column">
								<a href="<?php 
                        $searchpage = isset($_GET['page']) ? intval($_GET['page']) : 1;
                        echo add_query_arg(array('gf_search' => $search_query, 'sort' => $field_id, 'dir' => $dir, 'page' => $searchpage), get_permalink($post->ID));
                        ?>
"><?php 
                    }
                    if ($field_info['type'] == 'id' && $entry) {
                        $label = $entryth;
                    } else {
                        $label = $field_info["label"];
                    }
                    $label = apply_filters('kws_gf_directory_th', apply_filters('kws_gf_directory_th_' . $field_id, apply_filters('kws_gf_directory_th_' . sanitize_title($label), $label)));
                    echo esc_html($label);
                    if (!isset($jssearch) || !$jssearch && empty($jstable)) {
                        ?>
							   </a>
							   <?php 
                    }
                    ?>
							   </th>
								<?php 
                }
            }
            if ($appendaddress && $addressesExist) {
                ?>
								<th scope="col" class="manage-column" onclick="Search('<?php 
                echo $search_query;
                ?>
', '<?php 
                echo $field_id;
                ?>
', '<?php 
                echo $dir;
                ?>
');" style="cursor:pointer;"><?php 
                $label = apply_filters('kws_gf_directory_th', apply_filters('kws_gf_directory_th_address', 'Address'));
                echo esc_html($label);
                ?>
</th>
								<?php 
            }
            ?>
						</tr>
					</thead>
					<?php 
        }
        ?>
					<tbody class="list:user user-list">
						<?php 
        if (sizeof($leads) > 0 && $lead_count > 0) {
            $field_ids = array_keys($columns);
            $evenodd = '';
            foreach ($leads as $lead) {
                flush();
                echo "\n\t\t\t\t\t\t";
                $address = array();
                $celltitle = '';
                if ($approved) {
                    $leadapproved = self::check_approval($lead, $approvedcolumn);
                }
                if (isset($leadapproved) && $leadapproved && $approved || !$approved) {
                    $target = '';
                    if ($linknewwindow && empty($lightboxsettings['images'])) {
                        $target = ' target="_blank"';
                    }
                    $valignattr = '';
                    if ($valign && $directoryview == 'table') {
                        $valignattr = ' valign="' . $valign . '"';
                    }
                    $nofollow = '';
                    if ($nofollowlinks) {
                        $nofollow = ' rel="nofollow"';
                    }
                    $evenodd = $evenodd == ' odd' ? ' even' : ' odd';
                    $evenodd = apply_filters('kws_gf_directory_evenodd', $evenodd);
                    ?>
<tr<?php 
                    if ($showrowids) {
                        ?>
 id="lead_row_<?php 
                        echo $lead["id"];
                        ?>
" <?php 
                    }
                    ?>
 class='<?php 
                    echo trim($rowclass . $evenodd);
                    echo $lead["is_starred"] ? " featured" : "";
                    ?>
'<?php 
                    echo $rowstyle ? ' style="' . $rowstyle . '"' : '';
                    echo $valignattr;
                    ?>
><?php 
                    $class = "";
                    $is_first_column = true;
                    $full_address = '';
                    foreach ($field_ids as $field_id) {
                        $lightboxclass = '';
                        if (!empty($lightboxsettings['images'])) {
                            $lightboxclass = ' class="thickbox colorbox lightbox"';
                        }
                        $value = isset($lead[$field_id]) ? $lead[$field_id] : '';
                        $input_type = !empty($columns[$field_id]["inputType"]) ? $columns[$field_id]["inputType"] : $columns[$field_id]["type"];
                        switch ($input_type) {
                            case "address":
                                $address['id'] = floor((int) $field_id);
                                $address[$field_id] = $value;
                                if ($hideaddresspieces) {
                                    $value = NULL;
                                    break;
                                }
                                break;
                            case "checkbox":
                                $value = "";
                                //looping through lead detail values trying to find an item identical to the column label. Mark with a tick if found.
                                $lead_field_keys = array_keys($lead);
                                foreach ($lead_field_keys as $input_id) {
                                    //mark as a tick if input label (from form meta) is equal to submitted value (from lead)
                                    if (is_numeric($input_id) && absint($input_id) == absint($field_id) && $lead[$input_id] == $columns[$field_id]["label"]) {
                                        $value = "<img src='" . GFCommon::get_base_url() . "/images/tick.png'/>";
                                    }
                                }
                                break;
                            case "fileupload":
                            case "post_image":
                                $valueArray = explode("|:|", $value);
                                @(list($url, $title, $caption, $description) = $valueArray);
                                $size = '';
                                if (!empty($url)) {
                                    //displaying thumbnail (if file is an image) or an icon based on the extension
                                    $icon = self::get_icon_url($url);
                                    if (!preg_match('/icon\\_image\\.gif/ism', $icon)) {
                                        $src = $icon;
                                        if (!empty($getimagesize)) {
                                            $size = @getimagesize($src);
                                            $img = "<img src='{$src}' {$size[3]}/>";
                                        } else {
                                            $size = false;
                                            $img = "<img src='{$src}' />";
                                        }
                                    } else {
                                        // No thickbox for non-images please
                                        switch (strtolower(trim($postimage))) {
                                            case 'image':
                                                $src = $url;
                                                break;
                                            case 'icon':
                                            default:
                                                $src = $icon;
                                                break;
                                        }
                                        if (!empty($getimagesize)) {
                                            $size = @getimagesize($src);
                                        } else {
                                            $size = false;
                                        }
                                    }
                                    $img = array('src' => $src, 'size' => $size, 'title' => $title, 'caption' => $caption, 'description' => $description, 'url' => esc_attr($url), 'code' => isset($size[3]) ? "<img src='{$src}' {$size[3]} />" : "<img src='{$src}' />");
                                    $img = apply_filters('kws_gf_directory_lead_image', apply_filters('kws_gf_directory_lead_image_' . $postimage, apply_filters('kws_gf_directory_lead_image_' . $lead['id'], $img)));
                                    if (in_array('images', $lightboxsettings) || !empty($lightboxsettings['images'])) {
                                        $lightboxclass .= ' rel="directory_all directory_images"';
                                    }
                                    $value = "<a href='{$url}'{$target}{$lightboxclass}>{$img['code']}</a>";
                                }
                                break;
                            case "source_url":
                                if (in_array('urls', $lightboxsettings) || !empty($lightboxsettings['urls'])) {
                                    $lightboxclass .= ' rel="directory_all directory_urls"';
                                }
                                if ($linkwebsite) {
                                    $value = "<a href='" . esc_attr($lead["source_url"]) . "'{$target}{$lightboxclass} title='" . esc_attr($lead["source_url"]) . "'{$nofollow}>.../" . esc_attr(GFCommon::truncate_url($lead["source_url"])) . "</a>";
                                } else {
                                    $value = esc_attr(GFCommon::truncate_url($lead["source_url"]));
                                }
                                break;
                            case "textarea":
                            case "post_content":
                            case "post_excerpt":
                                if ($fulltext) {
                                    $long_text = $value = "";
                                    if (isset($lead[$field_id]) && strlen($lead[$field_id]) >= GFORMS_MAX_FIELD_LENGTH) {
                                        $long_text = get_gf_field_value_long($lead["id"], $field_id);
                                    }
                                    if (isset($lead[$field_id])) {
                                        $value = !empty($long_text) ? $long_text : $lead[$field_id];
                                    }
                                    if ($wpautop) {
                                        $value = wpautop($value);
                                    }
                                } else {
                                    $value = esc_html($value);
                                }
                                break;
                            case "date_created":
                                $value = GFCommon::format_date($value, false, $datecreatedformat);
                                break;
                            case "date":
                                $field = RGFormsModel::get_field($form, $field_id);
                                if ($dateformat) {
                                    $value = GFCommon::date_display($value, $dateformat);
                                } else {
                                    $value = GFCommon::date_display($value, $field["dateFormat"]);
                                }
                                break;
                            case "id":
                                $linkClass = '';
                                break;
                            case "list":
                                $field = RGFormsModel::get_field($form, $field_id);
                                $value = GFCommon::get_lead_field_display($field, $value);
                                break;
                            default:
                                $input_type = 'text';
                                if (is_email($value) && $linkemail) {
                                    $value = "<a href='mailto:{$value}'{$nofollow}>{$value}</a>";
                                } elseif (preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $value) && $linkwebsite) {
                                    $href = $value;
                                    if (!empty($lightboxsettings['images'])) {
                                        if (in_array('urls', $lightboxsettings) || !empty($lightboxsettings['urls'])) {
                                            $lightboxclass .= ' rel="directory_all directory_urls"';
                                        }
                                        $linkClass = $lightboxclass;
                                    } else {
                                        $linkClass = isset($linkClass) ? $linkClass : '';
                                    }
                                    if ($truncatelink) {
                                        $value = apply_filters('kws_gf_directory_anchor_text', $value);
                                    }
                                    $value = "<a href='{$href}'{$nofollow}{$target}{$linkClass}>{$value}</a>";
                                } else {
                                    $value = esc_html($value);
                                }
                        }
                        if ($is_first_column) {
                            echo "\n";
                        }
                        if ($value !== NULL) {
                            if (isset($columns["{$field_id}"]['label']) && $hovertitle || $directoryview !== 'table') {
                                $celltitle = ' title="' . esc_html(apply_filters('kws_gf_directory_th', apply_filters('kws_gf_directory_th_' . $field_id, apply_filters('kws_gf_directory_th_' . sanitize_title($columns["{$field_id}"]['label']), $columns["{$field_id}"]['label'])))) . '"';
                            } else {
                                $celltitle = '';
                            }
                            echo "\t\t\t\t\t\t\t";
                            ?>
<td<?php 
                            echo empty($class) ? ' class="' . $input_type . '"' : ' class="' . $input_type . ' ' . $class . '"';
                            echo $valignattr;
                            echo $celltitle;
                            ?>
><?php 
                            $value = empty($value) ? '&nbsp;' : $value;
                            if (isset($entrylinkcolumns[floor($field_id)])) {
                                $type = $entrylinkcolumns[floor($field_id)];
                                if ($input_type == 'id' && $entry) {
                                    $linkvalue = $entrylink;
                                } elseif ($type === 'label') {
                                    $linkvalue = $columns["{$field_id}"]['label'];
                                } elseif (!empty($type) && $type !== 'on') {
                                    $linkvalue = str_replace('%value%', $value, $type);
                                } else {
                                    $linkvalue = $value;
                                }
                                $value = self::make_entry_link($options, $linkvalue, $lead['id'], $form_id, $field_id);
                            }
                            $value = apply_filters('kws_gf_directory_value', apply_filters('kws_gf_directory_value_' . $input_type, apply_filters('kws_gf_directory_value_' . $field_id, $value)));
                            echo $value;
                            ?>
</td><?php 
                            echo "\n";
                            $is_first_column = false;
                        }
                    }
                    if (is_array($address) && !empty($address) && $appendaddress) {
                        $address = apply_filters('kws_gf_directory_td_address', $address, $linknewwindow);
                        if (!is_array($address)) {
                            echo "\t\t\t\t\t\t\t" . '<td class="address" title="' . esc_html(apply_filters('kws_gf_directory_th', apply_filters('kws_gf_directory_th_address', 'Address'))) . '">' . $address . '</td>';
                        }
                    }
                    ?>
							</tr>
								<?php 
                }
            }
        } else {
            ?>
							<tr>
								<td colspan="<?php 
            echo sizeof($columns);
            ?>
" style="padding:20px;"><?php 
            if ($search_query) {
                _e("This search returned no results.", "gravity-forms-addons");
            } elseif ($limituser) {
                _e("This form does not have any visible entries.", "gravity-forms-addons");
            } else {
                _e("This form does not have any entries yet.", "gravity-forms-addons");
            }
            ?>
</td>
							</tr>
							<?php 
        }
        ?>
					</tbody>
					<?php 
        if ($tfoot) {
            if (isset($jssearch) && $jssearch && !isset($jstable)) {
                $th = '<th scope="col" class="manage-column" onclick="Search(\'' . $search_query . '\', \'' . $field_id . '\', \'' . $dir . '\');" style="cursor:pointer;">';
            } else {
                $th = '<th scope="col" class="manage-column">';
            }
            ?>
					<tfoot>
						<tr>
							<?php 
            $addressesExist = false;
            foreach ($columns as $field_id => $field_info) {
                $dir = $field_id == 0 ? "DESC" : "ASC";
                //default every field so ascending sorting except date_created (id=0)
                if ($field_id == $sort_field) {
                    //reverting direction if clicking on the currently sorted field
                    $dir = $sort_direction == "ASC" ? "DESC" : "ASC";
                }
                if (is_array($adminonlycolumns) && !in_array($field_id, $adminonlycolumns) || is_array($adminonlycolumns) && in_array($field_id, $adminonlycolumns) && $showadminonly || !$showadminonly) {
                    if ($field_info['type'] == 'address' && $appendaddress && $hideaddresspieces) {
                        $addressesExist = true;
                        continue;
                    }
                    echo $th;
                    if ($field_info['type'] == 'id' && $entry) {
                        $label = $entryth;
                    } else {
                        $label = $field_info["label"];
                    }
                    $label = apply_filters('kws_gf_directory_th', apply_filters('kws_gf_directory_th_' . $field_id, apply_filters('kws_gf_directory_th_' . sanitize_title($label), $label)));
                    echo esc_html($label);
                    ?>
</th>
								<?php 
                }
            }
            if ($appendaddress && $addressesExist) {
                ?>
								<th scope="col" class="manage-column" onclick="Search('<?php 
                echo $search_query;
                ?>
', '<?php 
                echo $field_id;
                ?>
', '<?php 
                echo $dir;
                ?>
');" style="cursor:pointer;"><?php 
                $label = apply_filters('kws_gf_directory_th', apply_filters('kws_gf_directory_th_address', 'Address'));
                echo esc_html($label);
                ?>
</th>
								<?php 
            }
            ?>
						</tr>
						<?php 
            if (!empty($credit)) {
                self::get_credit_link(sizeof($columns));
            }
            ?>
					</tfoot>
					<?php 
        }
        ?>
					</table>
					<?php 
        do_action('kws_gf_after_directory_before_nav', do_action('kws_gf_after_directory_before_nav_form_' . $form_id, $form, $leads, compact($approved, $sort_field, $sort_direction, $search_query, $first_item_index, $page_size, $star, $read, $is_numeric, $start_date, $end_date)));
        //Displaying paging links if appropriate
        if ($lead_count > 0 && $showcount || $page_links) {
            if ($lead_count == 0) {
                $first_item_index--;
            }
            ?>
					<div class="tablenav">
						<div class="tablenav-pages">
							<?php 
            if ($showcount) {
                if ($first_item_index + $page_size > $lead_count || $page_size <= 0) {
                    $second_part = $lead_count;
                } else {
                    $second_part = $first_item_index + $page_size;
                }
                ?>
							<span class="displaying-num"><?php 
                printf(__("Displaying %d - %d of %d", "gravity-forms-addons"), $first_item_index + 1, $second_part, $lead_count);
                ?>
</span>
							<?php 
            }
            if ($page_links) {
                echo $page_links;
            }
            ?>
						</div>
						<div class="clear"></div>
					</div>
						<?php 
        }
        ?>
 
			</div>
			<?php 
        if (empty($credit)) {
            echo "\n" . '<!-- Directory generated by Gravity Forms Directory & Addons : http://wordpress.org/extend/plugins/gravity-forms-addons/ -->' . "\n";
        }
        do_action('kws_gf_after_directory', do_action('kws_gf_after_directory_form_' . $form_id, $form, $leads, compact($approved, $sort_field, $sort_direction, $search_query, $first_item_index, $page_size, $star, $read, $is_numeric, $start_date, $end_date)));
        $content = ob_get_contents();
        // Get the output
        ob_end_clean();
        // Clear the cache
        // If the form is form #2, two filters are applied: `kws_gf_directory_output_2` and `kws_gf_directory_output`
        $content = apply_filters('kws_gf_directory_output', apply_filters('kws_gf_directory_output_' . $form_id, self::pseudo_filter($content, $directoryview)));
        return $content;
        // Return it!
    }
 function gf_field_value_long($leadid, $fieldid, $form = array())
 {
     echo get_gf_field_value_long($leadid, $fieldid, $form);
 }