require "../../global/session_start.php"; ft_check_permission("client"); require dirname(__FILE__) . "/edit_submission__code.php"; $account_id = $_SESSION["ft"]["account"]["account_id"]; // blur the GET and POST variables into a single variable for easy reference $request = array_merge($_GET, $_POST); $form_id = ft_load_field("form_id", "curr_form_id"); $view_id = ft_load_field("view_id", "form_{$form_id}_view_id"); $submission_id = isset($request["submission_id"]) ? $request["submission_id"] : ""; if (empty($submission_id)) { header("location: index.php"); exit; } $tab_number = ft_load_field("tab", "view_{$view_id}_current_tab", 1); $grouped_views = ft_get_grouped_views($form_id, array("omit_hidden_views" => true, "omit_empty_groups" => true, "account_id" => $account_id)); // check the current client is permitted to view this information! ft_check_client_may_view($account_id, $form_id, $view_id); if (!ft_check_view_contains_submission($form_id, $view_id, $submission_id)) { header("location: index.php"); exit; } // store this submission ID $_SESSION["ft"]["last_submission_id"] = $submission_id; // get a list of all editable fields in the View. This is used both for security purposes // for the update function and to determine whether the page contains any editable fields $editable_field_ids = _ft_get_editable_view_fields($view_id); // handle POST requests $failed_validation = false; if (isset($_POST) && !empty($_POST)) { // add the view ID to the request hash, for use by the ft_update_submission function
function smarty_function_views_dropdown($params, &$smarty) { global $LANG; if (empty($params["form_id"])) { $smarty->trigger_error("assign: missing 'form_id' parameter."); return; } $form_id = $params["form_id"]; $name_id = isset($params["name_id"]) ? $params["name_id"] : ""; $show_empty_label = isset($params["show_empty_label"]) ? $params["show_empty_label"] : false; $empty_label = isset($params["empty_label"]) ? $params["empty_label"] : $LANG["phrase_please_select"]; $selected = isset($params["selected"]) ? $params["selected"] : ""; $onchange = isset($params["onchange"]) ? $params["onchange"] : ""; $submission_id = isset($params["submission_id"]) ? $params["submission_id"] : ""; $omit_hidden_views = isset($params["omit_hidden_views"]) ? $params["omit_hidden_views"] : false; $create_view_dropdown = isset($params["create_view_dropdown"]) ? $params["create_view_dropdown"] : false; $class = isset($params["class"]) ? $params["class"] : ""; $open_html = isset($params["open_html"]) ? $params["open_html"] : ""; $close_html = isset($params["close_html"]) ? $params["close_html"] : ""; $hide_single_view = isset($params["hide_single_view"]) ? $params["hide_single_view"] : false; // if the calling page has the view information already calculated, it can pass it to this function to // reduce the amount of work it needs to do. Otherwise, it will just do a separate request for the data $grouped_views = isset($params["grouped_views"]) ? $params["grouped_views"] : ft_get_grouped_views($form_id, array("omit_hidden_views" => $omit_hidden_views)); $attributes = array("id" => $name_id, "name" => $name_id, "onchange" => $onchange, "class" => $class); $attribute_str = ""; while (list($key, $value) = each($attributes)) { if (!empty($value)) { $attribute_str .= " {$key}=\"{$value}\""; } } $num_views = 0; $class_str = empty($class) ? "" : " class=\"{$class}\""; $dd = "<select {$attribute_str}{$class_str}>"; if ($show_empty_label) { $dd .= "<option value=\"\">{$empty_label}</option>"; } if ($create_view_dropdown) { $dd .= "<option value=\"blank_view_all_fields\">{$LANG["phrase_new_view_all_fields"]}</option>"; $dd .= "<option value=\"blank_view_no_fields\">{$LANG["phrase_new_blank_view"]}</option>"; } foreach ($grouped_views as $curr_group) { $group_name = $curr_group["group"]["group_name"]; $view_options = ""; foreach ($curr_group["views"] as $view_info) { $curr_view_id = $view_info["view_id"]; $view_name = $view_info["view_name"]; $is_selected = $curr_view_id == $selected ? "selected" : ""; if (empty($submission_id)) { $view_options .= "<option value=\"{$curr_view_id}\" {$is_selected}>{$view_name}</option>\n"; $num_views++; } else { if (ft_check_view_contains_submission($form_id, $curr_view_id, $submission_id)) { $view_options .= "<option value=\"{$curr_view_id}\" {$is_selected}>{$view_name}</option>"; $num_views++; } } } if (!empty($view_options)) { if (!empty($group_name)) { $dd .= "<optgroup label=\"{$group_name}\">"; } $dd .= $view_options; if (!empty($group_name)) { $dd .= "</optgroup>"; } } } $dd .= "</select>"; if ($num_views <= 1 && $hide_single_view) { // do nothing! $dd = ""; } else { $dd = $open_html . $dd . $close_html; } return $dd; }
$sortable_id = "view_list"; $form_info = ft_get_form($form_id); // this is called when the user clicks Update OR deletes a group. The delete group first updates the // view order to ensure that whatever group is being deleted actually has the View that the user expects if (isset($request["update_views"]) || isset($request["{$sortable_id}_sortable__delete_group"])) { $request["sortable_id"] = $sortable_id; list($g_success, $g_message) = ft_update_views($form_id, $request); if (isset($request["{$sortable_id}_sortable__delete_group"])) { list($g_success, $g_message) = ft_delete_view_group($request["{$sortable_id}_sortable__delete_group"]); } } // if the user deleted all their Views & View Groups, a special "add default view" option appears if (isset($request["recreate_initial_view"])) { list($g_success, $g_message) = ft_add_default_view($form_id); } $grouped_views = ft_get_grouped_views($form_id, array("omit_empty_groups" => false, "include_clients" => true)); // figure out how many Views we're dealing with $num_views = 0; foreach ($grouped_views as $curr_group) { $num_views += count($curr_group["views"]); } // ------------------------------------------------------------------------------------------------ // compile the template information $page_vars["page"] = "views"; $page_vars["page_url"] = ft_get_page_url("edit_form_views", array("form_id" => $form_id)); $page_vars["grouped_views"] = $grouped_views; $page_vars["head_title"] = "{$LANG["phrase_edit_form"]} - {$LANG["word_views"]}"; $page_vars["form_info"] = $form_info; $page_vars["sortable_id"] = $sortable_id; $page_vars["js_messages"] = array("phrase_remove_row", "phrase_create_group", "word_cancel", "phrase_delete_view", "word_yes", "word_no", "confirm_delete_view", "notify_view_deleted", "phrase_please_confirm", "confirm_delete_group", "phrase_create_new_view"); $page_vars["num_views"] = $num_views;
if (empty($form_id) || !is_numeric($form_id)) { session_write_close(); header("location: index.php"); exit; } // check this is a valid form if (!ft_check_form_exists($form_id)) { ft_handle_error($LANG["notify_form_does_not_exist"]); exit; } // next, get the View. If it's not defined, the user has just arrives at the page. We grab the first View in // (ordered) list of Views for this form. If THAT doesn't exist, the user has deleted all Views (doh!), so // there's nothing to show. In that case, just redirect them to the Views tab, where an error / warning message // will appear in the page $view_id = ft_load_field("view_id", "form_{$form_id}_view_id"); $grouped_views = ft_get_grouped_views($form_id, array("omit_hidden_views" => true, "omit_empty_groups" => true)); if (empty($view_id) || !ft_check_view_exists($view_id, true)) { // here, we know that the first View group has at least one item. [hmm...] if (count($grouped_views[0]["views"]) == 0) { // no Views defined for this form! redirect to the Views page and display a message header("location: edit.php?page=views&form_id={$form_id}&message=no_views"); exit; } else { $view_id = $grouped_views[0]["views"][0]["view_id"]; } } $_SESSION["ft"]["form_{$form_id}_view_id"] = $view_id; $_SESSION["ft"]["last_link_page_{$form_id}"] = "submissions"; $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);