if (!isset($form_id)) { session_write_close(); header("location: {$g_root_url}/admin/forms/"); exit; } $form_info = ft_get_form($form_id); if (empty($form_info)) { session_write_close(); header("location: {$g_root_url}/admin/forms/"); exit; } $form_name = $form_info["form_name"]; $auto_delete_submission_files = $form_info["auto_delete_submission_files"]; // get the names and URLs of all uploaded files. These are displayed in the page for the user // so there's no doubt about exactly what they're deleting $file_field_type_ids = ft_get_file_field_type_ids(); $form_fields = ft_get_form_fields($form_id); $file_field_ids = array(); foreach ($form_fields as $field) { if (!in_array($field["field_type_id"], $file_field_type_ids)) { continue; } $file_field_ids[] = $field["field_id"]; } $uploaded_files = ft_get_uploaded_files($form_id, $file_field_ids); // delete the form if (isset($_POST["delete_form"]) && $_POST["delete_form"] == "yes") { $delete_files = isset($_POST['delete_files']) && $_POST['delete_files'] == "yes" ? true : false; list($g_success, $g_message) = ft_delete_form($form_id, $delete_files); // redirect back to the form list page header("location: {$g_root_url}/admin/forms/");
/** * Deletes multiple form submissions at once. * * If required, deletes any files that were uploaded along with the original submissions. If one or * more files associated with this submission couldn't be deleted (either because they didn't exist * or because they didn't have permissions) the submission IS deleted, but it returns an error * indicating which files caused problems. * * @param integer $form_id the unique form ID * @param mixed $delete_ids a single submission ID / an array of submission IDs / "all". This column * determines which submissions will be deleted * @param integer $view_id (optional) this is only needed if $delete_ids is set to "all". With the advent * of Views, it needs to know which submissions to delete. * @return array returns array with indexes:<br/> * [0]: true/false (success / failure)<br/> * [1]: message string<br/> */ function ft_delete_submissions($form_id, $view_id, $submissions_to_delete, $omit_list, $search_fields, $is_admin) { global $g_table_prefix, $LANG; $submission_ids = array(); if ($submissions_to_delete == "all") { // get the list of searchable columns for this View. This is needed to ensure that ft_get_search_submission_ids receives // the correct info to determine what submission IDs are appearing in this current search. $searchable_columns = ft_get_view_searchable_fields($view_id); $submission_ids = ft_get_search_submission_ids($form_id, $view_id, "all", "submission_id-ASC", $search_fields, $searchable_columns); $submission_ids = array_diff($submission_ids, $omit_list); } else { $submission_ids = $submissions_to_delete; } $submissions_to_delete = $submission_ids; extract(ft_process_hook_calls("start", compact("form_id", "view_id", "submissions_to_delete", "omit_list", "search_fields", "is_admin"), array("submission_ids")), EXTR_OVERWRITE); $form_info = ft_get_form($form_id); $form_fields = ft_get_form_fields($form_id); $auto_delete_submission_files = $form_info["auto_delete_submission_files"]; $submission_ids_qry = array(); foreach ($submission_ids as $submission_id) { $submission_ids_qry[] = "submission_id = {$submission_id}"; } $where_clause = "WHERE " . join(" OR ", $submission_ids_qry); // loop the form templates to find out if there are any file fields. If there are - and the user // configured it - delete any associated files $file_delete_problems = array(); $form_has_file_field = false; if ($auto_delete_submission_files == "yes") { $file_field_type_ids = ft_get_file_field_type_ids(); $file_fields_to_delete = array(); foreach ($submissions_to_delete as $submission_id) { foreach ($form_fields as $field_info) { $field_type_id = $field_info["field_type_id"]; if (!in_array($field_type_id, $file_field_type_ids)) { continue; } $form_has_file_field = true; $submission_info = ft_get_submission_info($form_id, $submission_id); $filename = $submission_info[$field_info['col_name']]; // if no filename was stored, it was empty - just continue if (empty($filename)) { continue; } $file_fields_to_delete[] = array("submission_id" => $submission_id, "field_id" => $field_info["field_id"], "field_type_id" => $field_type_id, "filename" => $filename); } } if (!empty($file_fields_to_delete)) { list($success, $file_delete_problems) = ft_delete_submission_files($form_id, $file_fields_to_delete, "ft_delete_submissions"); } } // now delete the submission mysql_query("DELETE FROM {$g_table_prefix}form_{$form_id} {$where_clause}"); if ($auto_delete_submission_files == "yes") { if (empty($file_delete_problems)) { $success = true; if (count($submission_ids) > 1) { $message = $form_has_file_field ? $LANG["notify_submissions_and_files_deleted"] : $LANG["notify_submissions_deleted"]; } else { $message = $form_has_file_field ? $LANG["notify_submission_and_files_deleted"] : $LANG["notify_submission_deleted"]; } } else { $success = false; if (count($submission_ids) > 1) { $message = $LANG["notify_submissions_deleted_with_problems"] . "<br /><br />"; } else { $message = $LANG["notify_submission_deleted_with_problems"] . "<br /><br />"; } foreach ($file_delete_problems as $problem) { $message .= "• <b>{$problem["filename"]}</b>: {$problem["error"]}<br />\n"; } } } else { $success = true; if (count($submission_ids) > 1) { $message = $LANG["notify_submissions_deleted"]; } else { $message = $LANG["notify_submission_deleted"]; } } // TODO update sessions to ensure the first submission date and num submissions for this form View are correct _ft_cache_form_stats($form_id); _ft_cache_view_stats($form_id, $view_id); $_SESSION["ft"]["form_{$form_id}_select_all_submissions"] = ""; $_SESSION["ft"]["form_{$form_id}_selected_submissions"] = array(); $_SESSION["ft"]["form_{$form_id}_all_submissions_selected_omit_list"] = array(); // loop through all submissions deleted and send any emails reset($submission_ids); foreach ($submission_ids as $submission_id) { ft_send_emails("on_delete", $form_id, $submission_id); } $submissions_to_delete = $submission_ids; extract(ft_process_hook_calls("end", compact("form_id", "view_id", "submissions_to_delete", "omit_list", "search_fields", "is_admin"), array("success", "message")), EXTR_OVERWRITE); return array($success, $message); }
/** * Generates the placeholders for a particular form submission. This is used in the email templates, and here and there * for providing placeholder functionality to fields (like the "Edit Submission Label" textfield for a form, where they can * enter placeholders populated here). * * This returns ALL available placeholders for a form, regardless of View. * * @param integer $form_id * @param integer $submission_id * @param array $client_info a hash of information about the appropriate user (optional) * @return array a hash of placeholders and their replacement values (e.g. $arr["FORMURL"] => 17) */ function ft_get_submission_placeholders($form_id, $submission_id, $client_info = "") { global $g_root_url; $placeholders = array(); $settings = ft_get_settings(); $form_info = ft_get_form($form_id); $submission_info = ft_get_submission($form_id, $submission_id); $admin_info = ft_get_admin_info(); $file_field_type_ids = ft_get_file_field_type_ids(); $field_types = ft_get_field_types(true); // now loop through the info stored for this particular submission and for this particular field, // add the custom submission responses to the placeholder hash $form_field_params = array("include_field_type_info" => true, "include_field_settings" => true, "evaluate_dynamic_settings" => true); $form_fields = ft_get_form_fields($form_id, $form_field_params); foreach ($submission_info as $field_info) { $field_id = $field_info["field_id"]; $field_name = $field_info["field_name"]; $field_type_id = $field_info["field_type_id"]; if ($field_info["is_system_field"] == "no") { $placeholders["QUESTION_{$field_name}"] = $field_info["field_title"]; } if (in_array($field_type_id, $file_field_type_ids)) { $field_settings = ft_get_field_settings($field_id); $placeholders["FILENAME_{$field_name}"] = $field_info["content"]; $placeholders["FILEURL_{$field_name}"] = "{$field_settings["folder_url"]}/{$field_info["content"]}"; } else { $detailed_field_info = array(); foreach ($form_fields as $curr_field_info) { if ($curr_field_info["field_id"] != $field_id) { continue; } $detailed_field_info = $curr_field_info; break; } $params = array("form_id" => $form_id, "submission_id" => $submission_id, "value" => $field_info["content"], "field_info" => $detailed_field_info, "field_types" => $field_types, "settings" => $settings, "context" => "email_template"); $value = ft_generate_viewable_field($params); $placeholders["ANSWER_{$field_name}"] = $value; // for backward compatibility if ($field_name == "core__submission_date") { $placeholders["SUBMISSIONDATE"] = $value; } else { if ($field_name == "core__last_modified") { $placeholders["LASTMODIFIEDDATE"] = $value; } else { if ($field_name == "core__ip_address") { $placeholders["IPADDRESS"] = $value; } } } } } // other misc placeholders $placeholders["ADMINEMAIL"] = $admin_info["email"]; $placeholders["FORMNAME"] = $form_info["form_name"]; $placeholders["FORMURL"] = $form_info["form_url"]; $placeholders["SUBMISSIONID"] = $submission_id; $placeholders["LOGINURL"] = $g_root_url . "/index.php"; if (!empty($client_info)) { $placeholders["EMAIL"] = $client_info["email"]; $placeholders["FIRSTNAME"] = $client_info["first_name"]; $placeholders["LASTNAME"] = $client_info["last_name"]; $placeholders["COMPANYNAME"] = $client_info["company_name"]; } extract(ft_process_hook_calls("end", compact("placeholders"), array("placeholders")), EXTR_OVERWRITE); return $placeholders; }