$submission_list_sortable_id = "submission_list"; // a form ID & view ID should always be set when visiting this page $view_id = ft_load_field("view_id", "form_{$form_id}_view_id"); // this updates all four sections of the view at once (since all may have been modified) if (isset($request["update_view"])) { $request["form_id"] = $form_id; $request["view_fields_sortable_id"] = $view_fields_sortable_id; $request["submission_list_sortable_id"] = $submission_list_sortable_id; list($g_success, $g_message) = ft_update_view($view_id, $request); } $form_info = ft_get_form($form_id); $form_fields = ft_get_form_fields($form_id, array("include_field_type_info" => true)); $view_info = ft_get_view($view_id); $form_database_column_info = ft_get_form_column_names($form_id); $view_clients = ft_get_view_clients($view_id); $view_tabs = ft_get_view_tabs($view_id); $grouped_fields = ft_get_grouped_view_fields($view_id); $field_types = ft_get_field_type_names(); $new_view_submission_defaults = ft_get_new_view_submission_defaults($view_id); // this returns ALL filters: standard and client map $standard_filters = ft_get_view_filters($view_id, "standard"); $client_map_filters = ft_get_view_filters($view_id, "client_map"); $num_standard_filters = count($standard_filters); $num_client_map_filters = count($client_map_filters); $edit_view_tab = isset($_SESSION["ft"]["inner_tabs"]["edit_view"]) ? $_SESSION["ft"]["inner_tabs"]["edit_view"] : 1; if (isset($request["edit_view_tab"])) { $edit_view_tab = $request["edit_view_tab"]; $_SESSION["ft"]["inner_tabs"]["edit_view"] = $edit_view_tab; } $view_omit_list = ft_get_public_view_omit_list($view_id); $num_clients_on_omit_list = count($view_omit_list);
$page_field_type_ids = array(); $page_has_required_fields = false; foreach ($grouped_fields as $group) { foreach ($group["fields"] as $field_info) { $page_field_ids[] = $field_info["field_id"]; if (!in_array($field_info["field_type_id"], $page_field_type_ids)) { $page_field_type_ids[] = $field_info["field_type_id"]; } if ($field_info["is_required"]) { $page_has_required_fields = true; } } } $page_field_types = ft_get_field_types(true, $page_field_type_ids); // construct the tab list $view_tabs = ft_get_view_tabs($view_id, true); $tabs = array(); $same_page = ft_get_clean_php_self(); while (list($key, $value) = each($view_tabs)) { $tabs[$key] = array("tab_label" => $value["tab_label"], "tab_link" => "{$same_page}?tab={$key}&form_id={$form_id}&submission_id={$submission_id}"); } // get a list of editable fields on this tab $editable_tab_fields = array_intersect($page_field_ids, $editable_field_ids); // if we're just coming here from the search results page, get a fresh list of every submission ID in this // search result set. This is used to build the internal "<< previous next >>" nav on this details page. // They need to exactly correspond to the ordering of the search results or they don't make sense $search = isset($_SESSION["ft"]["current_search"]) ? $_SESSION["ft"]["current_search"] : array(); if (isset($_SESSION["ft"]["new_search"]) && $_SESSION["ft"]["new_search"] == "yes") { $searchable_columns = ft_get_view_searchable_fields("", $view_info["fields"]); // extract the original search settings and get the list of IDs $submission_ids = ft_get_search_submission_ids($form_id, $view_id, $search["results_per_page"], $search["order"], $search["search_fields"], $searchable_columns);
/** * Returns all Views for a form, grouped appropriately. This function introduces a new way of handling * loads of optional params (should have implemented this a long time ago!). The second $custom_params * * @param integer $form_id * @param array a hash with any of the following keys: * account_id => if this is specified, the results will only return View groups * that have Views that a client account has access to * omit_empty_groups => (default: false) * omit_hidden_views => (default: false) * include_client => (default: false). If yes, returns assorted client information * for those that are mapped to the View * @param boolean $omit_empty_groups */ function ft_get_grouped_views($form_id, $custom_params = array()) { global $g_table_prefix; // figure out what settings $params = array("account_id" => isset($custom_params["account_id"]) ? $custom_params["account_id"] : "", "omit_empty_groups" => isset($custom_params["omit_empty_groups"]) ? $custom_params["omit_empty_groups"] : true, "omit_hidden_views" => isset($custom_params["omit_hidden_views"]) ? $custom_params["omit_hidden_views"] : false, "include_clients" => isset($custom_params["include_clients"]) ? $custom_params["include_clients"] : false); $group_query = mysql_query("\r\n SELECT group_id, group_name\r\n FROM {$g_table_prefix}list_groups lg\r\n WHERE group_type = 'form_{$form_id}_view_group'\r\n ORDER BY lg.list_order\r\n "); $info = array(); while ($row = mysql_fetch_assoc($group_query)) { $group_id = $row["group_id"]; $hidden_views_clause = $params["omit_hidden_views"] ? " AND v.access_type != 'hidden'" : ""; if (empty($params["account_id"])) { $view_query = mysql_query("\r\n SELECT *\r\n FROM {$g_table_prefix}views v\r\n WHERE v.group_id = {$group_id}\r\n {$hidden_views_clause}\r\n ORDER BY v.view_order\r\n "); } else { $view_query = mysql_query("\r\n SELECT v.*\r\n FROM {$g_table_prefix}views v\r\n WHERE v.form_id = {$form_id} AND\r\n v.group_id = {$group_id} AND\r\n (v.access_type = 'public' OR v.view_id IN (\r\n SELECT cv.view_id\r\n FROM {$g_table_prefix}client_views cv\r\n WHERE account_id = {$params["account_id"]}\r\n )) AND\r\n v.view_id NOT IN (\r\n SELECT view_id\r\n FROM {$g_table_prefix}public_view_omit_list\r\n WHERE account_id = {$params["account_id"]}\r\n )\r\n {$hidden_views_clause}\r\n ORDER BY v.view_order\r\n "); } $views = array(); while ($view_info = mysql_fetch_assoc($view_query)) { $view_id = $view_info["view_id"]; if ($params["include_clients"]) { $view_info["client_info"] = ft_get_view_clients($view_id); $view_info["client_omit_list"] = ft_get_public_view_omit_list($view_id); } $view_info["columns"] = ft_get_view_columns($view_id); $view_info["fields"] = ft_get_view_fields($view_id); $view_info["tabs"] = ft_get_view_tabs($view_id, true); $view_info["filters"] = ft_get_view_filters($view_id, "all"); $views[] = $view_info; } if (count($views) > 0 || !$params["omit_empty_groups"]) { $curr_group = array("group" => $row, "views" => $views); $info[] = $curr_group; } } return $info; }