function smarty_function_display_view_name($params, &$smarty) { $view_id = isset($params["view_id"]) ? $params["view_id"] : ""; if (empty($view_id)) { return; } $view_info = ft_get_view($view_id); return $view_info["view_name"]; }
$editable_field_ids = _ft_get_editable_view_fields($view_id); // update the submission $failed_validation = false; if (isset($_POST) && !empty($_POST)) { $_SESSION["ft"]["new_search"] = "yes"; $request["view_id"] = $view_id; $request["editable_field_ids"] = $editable_field_ids; list($g_success, $g_message) = ft_update_submission($form_id, $submission_id, $request); // if there was any problem udpating this submission, make a special note of it: we'll use that info to merge the current POST request // info with the original field values to ensure the page contains the latest data (i.e. for cases where they fail server-side validation) if (!$g_success) { $failed_validation = true; } } $form_info = ft_get_form($form_id); $view_info = ft_get_view($view_id); // this is crumby $has_tabs = false; foreach ($view_info["tabs"] as $tab_info) { if (!empty($tab_info["tab_label"])) { $has_tabs = true; break; } } if ($has_tabs) { $tab_number = ft_load_field("tab", "view_{$view_id}_current_tab", 1); } else { $tab_number = ""; } $grouped_fields = ft_get_grouped_view_fields($view_id, $tab_number, $form_id, $submission_id); if ($failed_validation) {
/** * 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; } }
/** * Deletes a View and updates the list order of the Views in the same View group. * * @param integer $view_id the unique view ID * @return array Returns array with indexes:<br/> * [0]: true/false (success / failure)<br/> * [1]: message string<br/> */ function ft_delete_view($view_id) { global $g_table_prefix, $LANG; $view_info = ft_get_view($view_id); mysql_query("DELETE FROM {$g_table_prefix}client_views WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}view_columns WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}view_fields WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}view_filters WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}view_tabs WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}public_view_omit_list WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}list_groups WHERE group_type = 'view_fields_{$view_id}'"); mysql_query("DELETE FROM {$g_table_prefix}email_template_edit_submission_views WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}email_template_when_sent_views WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}new_view_submission_defaults WHERE view_id = {$view_id}"); mysql_query("DELETE FROM {$g_table_prefix}views WHERE view_id = {$view_id}"); // hmm... This should be handled better: the user needs to be notified prior to deleting a View to describe all the dependencies mysql_query("UPDATE {$g_table_prefix}email_templates SET limit_email_content_to_fields_in_view = NULL WHERE limit_email_content_to_fields_in_view = {$view_id}"); $success = true; $message = $LANG["notify_view_deleted"]; extract(ft_process_hook_calls("end", compact("view_id"), array("success", "message")), EXTR_OVERWRITE); return array($success, $message); }