$display_fields[] = $data_to_merge; } // determine the sort order if (isset($_GET["order"])) { $_SESSION["ft"]["view_{$view_id}_sort_order"] = $_GET["order"]; $order = $_GET["order"]; } else { if (isset($_SESSION["ft"]["view_{$view_id}_sort_order"])) { $order = $_SESSION["ft"]["view_{$view_id}_sort_order"]; } else { $order = "{$view_info['default_sort_field']}-{$view_info['default_sort_field_order']}"; } } $results_per_page = $view_info["num_submissions_per_page"]; // perform the almighty search query $results_info = ft_search_submissions($form_id, $view_id, $results_per_page, $current_page, $order, $db_columns, $search_fields, array(), $searchable_columns); $search_rows = $results_info["search_rows"]; $search_num_results = $results_info["search_num_results"]; $view_num_results = $results_info["view_num_results"]; // store the current search settings. This information is used on the item details page to provide // "<< previous next >>" links that only apply to the CURRENT search result set $_SESSION["ft"]["new_search"] = "yes"; $_SESSION["ft"]["current_search"] = array("form_id" => $form_id, "results_per_page" => $results_per_page, "order" => $order, "search_fields" => $search_fields); // check that the current page is stored in sessions is, in fact, a valid page. e.g. if the person // was having 10 submissions listed per page, had 11 submissions, and was on page 2 before deleting // the 11th, when they returned to this page, they'd have page 2 stored in sessions, although there // is no longer a second page. So for this fringe case, we update the session and refresh the page to // load the appropriate page $total_pages = ceil($search_num_results / $results_per_page); if (isset($_SESSION["ft"]["view_{$view_id}_page"]) && $_SESSION["ft"]["view_{$view_id}_page"] > $total_pages) { $_SESSION["ft"]["view_{$view_id}_page"] = $total_pages;
$order = isset($_SESSION["ft"]["current_search"]["order"]) ? $_SESSION["ft"]["current_search"]["order"] : ""; $search_fields = isset($_SESSION["ft"]["current_search"]["search_fields"]) ? $_SESSION["ft"]["current_search"]["search_fields"] : array(); $export_group_results = ft_load_module_field("export_manager", "export_group_{$export_group_id}_results", "export_group_{$export_group_id}_results"); // if any of the required fields weren't entered, just output a simple blank message if (empty($form_id) || empty($view_id) || empty($order) || empty($search_fields) || empty($export_group_id)) { echo $LANG["export_manager"]["notify_export_incomplete_fields"]; exit; } set_time_limit(300); // if the user only wants to display the currently selected rows, limit the query to those submission IDs $submission_ids = array(); if ($results == "selected") { $submission_ids = $_SESSION["ft"]["form_{$form_id}_selected_submissions"]; } // perform the almighty search query $results_info = ft_search_submissions($form_id, $view_id, "all", 1, $order, "all", $search_fields, $submission_ids); $search_rows = $results_info["search_rows"]; $search_num_results = $results_info["search_num_results"]; $view_num_results = $results_info["view_num_results"]; $form_info = ft_get_form($form_id); $view_info = ft_get_view($view_id); $form_fields = ft_get_form_fields($form_id, array("include_field_type_info" => true, "include_field_settings" => true)); $field_types = ft_get_field_types(true); // display_fields contains ALL the information we need for the fields in the template $display_fields = array(); foreach ($view_info["fields"] as $view_field_info) { $curr_field_id = $view_field_info["field_id"]; foreach ($form_fields as $form_field_info) { if ($form_field_info["field_id"] != $curr_field_id) { continue; }
/** * This function lets you display the content generated from an export type into a webpage. You can * use this function on any export type in the database - even the ones that have been marked as "hidden". Note: * this function requires the Export Manager to be installed and enabled. * * @param integer $form_id * @param integer $view_id * @param integer $export_type_id * @param integer $page_num (defaults to 1) * @param array $options optional parameter that lets you configure the appearance of the data in a variety of ways. * * num_per_page - (integer) by default, it returns the number of results per page specified by * the View. This setting overrides that. * submission_ids - (integer or array of integers) this limits the results returned to the submission ID * or submission IDs specified in this field * order - (string) the database column name with a -DESC or -ASC suffix (e.g. col_1-ASC). * page_num_identifier - (string) passed via the query string to denote what page it's on (default: "page") * show_columns_only - (boolean) limits the fields that are displayed to those fields marked as "Column" * in the View. Defaults to false. * return_as_string - (boolean) if this value is set to true, instead of outputting the result it returns * the HTML as a string. * pagination_theme - (string) the pagination links (<< 1 2 3 ...) HTML is generated by the pagination.tpl * template, found in each of the theme folders. Generally this file is the same for * all themes, but in case it isn't, this setting lets you choose the theme folder with * which to render the HTML. * pagination_location - (string) accepts the values "top" (the default), "bottom", "both" or "none". This * determines where (if anywhere) the pagination links should appear. By default it only * appears at the top of the page, but you can set this value to either "both" or "bottom" * to have it appear there instead / as well. * * @return mixed the return value of this function depends on the API settings & the options passed to it. Namely: * * If error: * if $g_api_debug == true, the error page will be displayed displaying the error code. * if $g_api_debug == false, it returns an array with two indexes: * [0] false * [1] the API error code * If successful: * if "return_as_string" option key is set, it returns an array with two indexes: * [0] true * [1] the HTML content * if "return_as_string" not set, it just prints the HTML to the page (the default behaviour) */ function ft_api_show_submissions($form_id, $view_id, $export_type_id, $page_num = 1, $options = array()) { global $g_table_prefix, $LANG, $g_api_debug, $g_smarty; // sanitize all incoming data $form_id = ft_sanitize($form_id); $view_id = ft_sanitize($view_id); $export_type_id = ft_sanitize($export_type_id); $page_num = ft_sanitize($page_num); $options = ft_sanitize($options); // check the Export Manager module is enabled if (ft_check_module_enabled("export_manager")) { ft_include_module("export_manager"); } else { if ($g_api_debug) { $page_vars = array("message_type" => "error", "error_code" => 400, "error_type" => "user"); ft_display_page("error.tpl", $page_vars); exit; } else { return array(false, 400); } } // check the form ID, View ID and export ID are valid $form_query = mysql_query("SELECT count(*) as c FROM {$g_table_prefix}forms WHERE form_id = {$form_id}"); $result = mysql_fetch_assoc($form_query); $form_found = $result["c"] == 1 ? true : false; if (!$form_found) { if ($g_api_debug) { $page_vars = array("message_type" => "error", "error_code" => 401, "error_type" => "user"); ft_display_page("error.tpl", $page_vars); exit; } else { return array(false, 401); } } $view_query = mysql_query("SELECT count(*) as c FROM {$g_table_prefix}views WHERE form_id = {$form_id} AND view_id = {$view_id}"); $result = mysql_fetch_assoc($view_query); $view_found = $result["c"] == 1 ? true : false; if (!$view_found) { if ($g_api_debug) { $page_vars = array("message_type" => "error", "error_code" => 402, "error_type" => "user"); ft_display_page("error.tpl", $page_vars); exit; } else { return array(false, 402); } } $export_type_query = mysql_query("SELECT count(*) as c FROM {$g_table_prefix}module_export_types WHERE export_type_id = {$export_type_id}"); $result = mysql_fetch_assoc($export_type_query); $export_type_found = $result["c"] == 1 ? true : false; if (!$export_type_found) { if ($g_api_debug) { $page_vars = array("message_type" => "error", "error_code" => 403, "error_type" => "user"); ft_display_page("error.tpl", $page_vars); exit; } else { return array(false, 403); } } // okay, now lets figure out what needs to be displayed & rendered $form_info = ft_get_form($form_id); $form_fields = ft_get_form_fields($form_id, array("include_field_type_info" => true, "include_field_settings" => true)); $view_info = ft_get_view($view_id); $export_type_info = exp_get_export_type($export_type_id); $export_group_id = $export_type_info["export_group_id"]; $export_group_info = exp_get_export_group($export_group_id); // number of submissions per page (an integer or "all") $num_per_page = $view_info["num_submissions_per_page"]; if (isset($options["num_per_page"])) { $num_per_page = $options["num_per_page"]; } $order = "{$view_info["default_sort_field"]}-{$view_info["default_sort_field_order"]}"; if (isset($options["order"])) { $order = $options["order"]; } $display_fields = array(); $columns = "all"; if (isset($options["show_columns_only"]) && $options["show_columns_only"]) { $columns = array(); foreach ($view_info["columns"] as $view_field_info) { $curr_field_id = $view_field_info["field_id"]; foreach ($form_fields as $form_field_info) { if ($form_field_info["field_id"] != $curr_field_id) { continue; } $display_fields[] = array_merge($form_field_info, $view_field_info); $columns[] = $form_field_info["col_name"]; } } } else { foreach ($view_info["fields"] as $view_field_info) { $curr_field_id = $view_field_info["field_id"]; foreach ($form_fields as $form_field_info) { if ($form_field_info["field_id"] != $curr_field_id) { continue; } $display_fields[] = array_merge($form_field_info, $view_field_info); } } } /* $columns = "all"; if (isset($options["show_columns_only"]) && $options["show_columns_only"]) { $columns = array(); foreach ($view_info["columns"] as $view_col_info) { foreach ($display_fields as $field_info) { if ($field_info["field_id"] == $view_col_info["field_id"]) { $columns[] = $field_info["col_name"]; } } } } */ $submission_ids = array(); if (isset($options["submission_ids"])) { if (is_numeric($options["submission_ids"])) { $submission_ids[] = $options["submission_ids"]; } else { if (is_array($submission_ids)) { $submission_ids = $options["submission_ids"]; } } } // perform the almighty search query $results_info = ft_search_submissions($form_id, $view_id, $num_per_page, $page_num, $order, $columns, array(), $submission_ids); $search_num_results = $results_info["search_num_results"]; $settings = ft_get_settings(); // now build the list of information we're going to send to the export type smarty template $placeholders = exp_get_export_filename_placeholder_hash(); $placeholders["export_group_id"] = $export_group_id; $placeholders["export_type_id"] = $export_type_id; $placeholders["export_group_results"] = "all"; $placeholders["same_page"] = ft_get_clean_php_self(); $placeholders["display_fields"] = $display_fields; $placeholders["submissions"] = $results_info["search_rows"]; $placeholders["num_results"] = $results_info["search_num_results"]; $placeholders["view_num_results"] = $results_info["view_num_results"]; $placeholders["form_info"] = $form_info; $placeholders["view_info"] = $view_info; $placeholders["field_types"] = ft_get_field_types(true); $placeholders["settings"] = $settings; // ... $placeholders["date_format"] = $settings["default_date_format"]; $placeholders["timezone_offset"] = $settings["timezone_offset"]; // pull out a few things into top level placeholders for easy use $placeholders["form_name"] = $form_info["form_name"]; $placeholders["form_id"] = $form_id; $placeholders["form_url"] = $form_info["form_url"]; $placeholders["view_name"] = $view_info["view_name"]; $placeholders["view_id"] = $view_id; $placeholders["export_group_name"] = ft_create_slug(ft_eval_smarty_string($export_group_info["group_name"])); $placeholders["export_group_type"] = ft_create_slug(ft_eval_smarty_string($export_type_info["export_type_name"])); $placeholders["filename"] = ft_eval_smarty_string($export_type_info["filename"], $placeholders, "", $g_smarty->plugins_dir); $template = $export_type_info["export_type_smarty_template"]; $placeholders["export_type_name"] = $export_type_info["export_type_name"]; $export_type_smarty_template = ft_eval_smarty_string($template, $placeholders, "", $g_smarty->plugins_dir); // if we're not displaying all results on the single page, generate the pagination HTML $pagination = ""; if ($num_per_page != "all") { $page_num_identifier = isset($options["page_num_identifier"]) ? $options["page_num_identifier"] : "page"; $theme = isset($options["pagination_theme"]) ? $options["pagination_theme"] : $settings["default_theme"]; $pagination = ft_get_page_nav($search_num_results, $num_per_page, $page_num, "", $page_num_identifier, $theme); } $pagination_location = isset($options["pagination_location"]) ? $options["pagination_location"] : "top"; switch ($pagination_location) { case "top": $html = $pagination . $export_type_smarty_template; break; case "both": $html = $pagination . $export_type_smarty_template . $pagination; break; case "bottom": $html = $export_type_smarty_template . $pagination; break; case "none": $html = $export_type_smarty_template; break; // this is in case the user entered an invalid value // this is in case the user entered an invalid value default: if ($g_api_debug) { $page_vars = array("message_type" => "error", "error_code" => 404, "error_type" => "user"); ft_display_page("error.tpl", $page_vars); exit; } else { return array(false, 404); } break; } if (isset($options["return_as_string"]) && $options["return_as_string"]) { return array(true, $html); } else { echo $html; } }