Beispiel #1
0
/**
 * The main email function for Form Tools. This gets executed on particular events in a submissions life: when
 * first placed ("on_submission"), when edited ("on_edit") and when deleted ("on_delete"). This function does
 * the horrible job of figuring out precisely what the administrator wants, and sends the email(s) to the
 * appropriate recipients.
 *
 * @param string $event "on_submission", "on_edit", "on_delete"
 * @param integer $form_id
 * @param integer $submission_id
 */
function ft_send_emails($event, $form_id, $submission_id)
{
    $all_form_email_templates = ft_get_email_template_list($form_id);
    // filter out those templates that aren't for this event
    $email_templates = array();
    foreach ($all_form_email_templates as $template_info) {
        $events = explode(",", $template_info["email_event_trigger"]);
        if (!in_array($event, $events)) {
            continue;
        }
        if ($template_info["email_status"] == "disabled") {
            continue;
        }
        // if this email template has been mapped to or more particular View, make sure the View ID is
        // valid & that the submission can be seen in at least one of the Views
        if ($template_info["view_mapping_type"] == "specific") {
            $view_ids = $template_info["when_sent_view_ids"];
            $found = false;
            foreach ($view_ids as $view_id) {
                if (ft_check_view_contains_submission($form_id, $view_id, $submission_id)) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                continue;
            }
        }
        $email_templates[] = $template_info;
    }
    // now process each template individually
    foreach ($email_templates as $template_info) {
        $email_id = $template_info["email_id"];
        ft_process_email_template($form_id, $submission_id, $email_id);
    }
}
    session_write_close();
    header("Location: edit.php?page=edit_email&form_id={$form_id}&email_id={$email_id}");
    exit;
}
if (isset($request["delete"])) {
    list($g_success, $g_message) = ft_delete_email_template($request["delete"]);
}
$form_info = ft_get_form($form_id);
$emails_page = ft_load_field("emails_page", "form_{$form_id}_emails_page", 1);
$form_email_info = ft_get_email_templates($form_id, $emails_page);
$form_emails = $form_email_info["results"];
$num_form_emails = $form_email_info["num_results"];
$registered_form_emails = ft_get_email_fields($form_id);
$num_registered_form_emails = count($registered_form_emails);
// a little irksome, but we also need to retrieve ALL emails, for the "Create Email From Existing Email" dropdown
$all_form_emails = ft_get_email_template_list($form_id);
$php_self = ft_get_clean_php_self();
// compile the templates information
$page_vars["page"] = "emails";
$page_vars["page_url"] = ft_get_page_url("edit_form_emails", array("form_id" => $form_id));
$page_vars["form_emails"] = $form_emails;
$page_vars["all_form_emails"] = $all_form_emails;
$page_vars["num_form_emails"] = $num_form_emails;
$page_vars["head_title"] = "{$LANG["phrase_edit_form"]} - {$LANG["word_emails"]}";
$page_vars["form_info"] = $form_info;
$page_vars["js_messages"] = array("word_edit", "word_remove");
// build values to pass along in nav query string
$pass_along_str = "page=emails&form_id={$form_id}";
$page_vars["pagination"] = ft_get_page_nav($num_form_emails, $_SESSION["ft"]["settings"]["num_emails_per_page"], $emails_page, $pass_along_str, "emails_page");
$page_vars["num_registered_form_emails"] = $num_registered_form_emails;
$page_vars["head_js"] = <<<END
Beispiel #3
0
/**
 * Completely removes a form from the database. This includes deleting all form fields, emails, Views,
 * View fields, View tabs, View filters, client-form, client-view and public omit list (form & View),
 * and anything else !
 *
 * It also includes an optional parameter to remove all files that were uploaded through file fields in the
 * form; defaulted to FALSE.
 *
 * @param integer $form_id the unique form ID
 * @param boolean $remove_associated_files A boolean indicating whether or not all files that were
 *              uploaded via file fields in this form should be removed as well.
 */
function ft_delete_form($form_id, $remove_associated_files = false)
{
    global $g_table_prefix;
    extract(ft_process_hook_calls("start", compact("form_id"), array()), EXTR_OVERWRITE);
    $form_fields = ft_get_form_fields($form_id, array("include_field_type_info" => true));
    $success = true;
    $message = "";
    $file_delete_problems = array();
    if ($remove_associated_files) {
        $submission_id_query = mysql_query("SELECT submission_id FROM {$g_table_prefix}form_{$form_id}");
        $file_fields_to_delete = array();
        while ($row = mysql_fetch_assoc($submission_id_query)) {
            $submission_id = $row["submission_id"];
            foreach ($form_fields as $form_field_info) {
                if ($form_field_info["is_file_field"] == "no") {
                    continue;
                }
                // I really don't like this... what should be done is do a SINGLE query after this loop is complete
                // to return a map of field_id to values. That would then update $file_fields_to_delete
                // with a fraction of the cost
                $submission_info = ft_get_submission_info($form_id, $submission_id);
                $filename = $submission_info[$form_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" => $form_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_form");
        }
    }
    // remove the table
    $query = "DROP TABLE IF EXISTS {$g_table_prefix}form_{$form_id}";
    mysql_query($query) or ft_handle_error("Failed query in <b>" . __FUNCTION__ . "</b>, line " . __LINE__ . ": <i>{$query}</i>", mysql_error());
    // remove any reference to the form in form_fields
    mysql_query("DELETE FROM {$g_table_prefix}form_fields WHERE form_id = {$form_id}") or ft_handle_error("Failed query in <b>" . __FUNCTION__ . "</b>, line " . __LINE__ . ": <i>{$query}</i>", mysql_error());
    // remove any reference to the form in forms table
    mysql_query("DELETE FROM {$g_table_prefix}forms WHERE form_id = {$form_id}");
    mysql_query("DELETE FROM {$g_table_prefix}client_forms WHERE form_id = {$form_id}");
    mysql_query("DELETE FROM {$g_table_prefix}form_export_templates WHERE form_id = {$form_id}");
    mysql_query("DELETE FROM {$g_table_prefix}form_email_fields WHERE form_id = {$form_id}");
    mysql_query("DELETE FROM {$g_table_prefix}public_form_omit_list WHERE form_id = {$form_id}");
    mysql_query("DELETE FROM {$g_table_prefix}multi_page_form_urls WHERE form_id = {$form_id}");
    mysql_query("DELETE FROM {$g_table_prefix}list_groups WHERE group_type = 'form_{$form_id}_view_group'");
    // delete all email templates for the form
    $email_templates = ft_get_email_template_list($form_id);
    foreach ($email_templates as $email_template_info) {
        ft_delete_email_template($email_template_info["email_id"]);
    }
    // delete all form Views
    $views_result = mysql_query("SELECT view_id FROM {$g_table_prefix}views WHERE form_id = {$form_id}");
    while ($info = mysql_fetch_assoc($views_result)) {
        ft_delete_view($info["view_id"]);
    }
    // remove any field settings
    foreach ($form_fields as $field_info) {
        $field_id = $field_info["field_id"];
        mysql_query("DELETE FROM {$g_table_prefix}field_settings WHERE field_id = {$field_id}");
    }
    // as with many things in the script, potentially we need to return a vast range of information from this last function. But
    // we'l limit
    if (!$success) {
        $message = $file_delete_problems;
    }
    return array($success, $message);
}