Пример #1
0
/**
 * 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;
}
Пример #2
0
/**
 * This function is tightly coupled with ft_get_email_components and has gotten increasingly more awful as
 * time passed. It examines the content of an email template and detects any field and file attachments.
 * Field attachments are files that have been uploaded through a form field; file attachments are just files
 * on the server that want to be sent out. It then returns the updated email template (i.e. minus the
 * attachment string) and information about the attachment (file name, location, mimetype) for use by the
 * emailing function (only Swift Mailer module at this time).
 *
 * @param string $template_str the email template (HTML or text)
 * @param integer $form_id
 * @param array $submission_placeholders
 */
function _ft_extract_email_attachment_info($template_str, $form_id, $submission_placeholders)
{
    global $g_root_dir;
    // see if there are any filename placeholders (i.e. uploaded files in this submission)
    $file_field_name_to_filename_hash = array();
    while (list($placeholder, $value) = each($submission_placeholders)) {
        if (!preg_match("/^FILENAME_/", $placeholder)) {
            continue;
        }
        $field_name = preg_replace("/^FILENAME_/", "", $placeholder);
        $file_field_name_to_filename_hash[$field_name] = $value;
    }
    $attachment_info = array();
    if (!empty($file_field_name_to_filename_hash)) {
        // if there are any fields marked as attachments, store them and remove the attachment string
        $field_attachments_regexp = '/\\{\\$attachment\\s+field=("|\')(.+)("|\')\\}/';
        if (preg_match_all($field_attachments_regexp, $template_str, $matches)) {
            foreach ($matches[2] as $field_name) {
                $field_id = ft_get_form_field_id_by_field_name($field_name, $form_id);
                if (!empty($field_name) && array_key_exists($field_name, $file_field_name_to_filename_hash)) {
                    $field_settings = ft_get_field_settings($field_id);
                    $file_upload_dir = $field_settings["folder_path"];
                    $file_and_path = "{$file_upload_dir}/{$file_field_name_to_filename_hash[$field_name]}";
                    if (is_file($file_and_path)) {
                        $info = array("field_name" => $field_name, "file_and_path" => $file_and_path, "filename" => $file_field_name_to_filename_hash[$field_name], "mimetype" => mime_content_type($file_and_path));
                        $attachment_info[] = $info;
                    }
                }
            }
            $template_str = preg_replace($field_attachments_regexp, "", $template_str);
        }
    }
    $file_attachments_regexp = '/\\{\\$attachment\\s+file=("|\')(.+)("|\')\\}/';
    if (preg_match_all($file_attachments_regexp, $template_str, $matches)) {
        foreach ($matches[2] as $file_and_relative_path) {
            if (is_file("{$g_root_dir}/{$file_and_relative_path}")) {
                $pathinfo = pathinfo($file_and_relative_path);
                $file_name = $pathinfo["basename"];
                $info = array("file_and_path" => "{$g_root_dir}/{$file_and_relative_path}", "filename" => $file_name);
                $attachment_info[] = $info;
            }
        }
        $template_str = preg_replace($file_attachments_regexp, "", $template_str);
    }
    $file_attachments_regexp = '/\\{\\$attachment\\s+fieldvalue=("|\')(.+)("|\')\\}/';
    if (preg_match_all($file_attachments_regexp, $template_str, $matches)) {
        foreach ($matches[2] as $file_and_relative_path) {
            $file_and_relative_path = ft_eval_smarty_string("{\$" . $file_and_relative_path . "}", $submission_placeholders);
            if (is_file("{$g_root_dir}/{$file_and_relative_path}")) {
                $pathinfo = pathinfo($file_and_relative_path);
                $file_name = $pathinfo["basename"];
                $info = array("file_and_path" => "{$g_root_dir}/{$file_and_relative_path}", "filename" => $file_name);
                $attachment_info[] = $info;
            }
        }
        $template_str = preg_replace($file_attachments_regexp, "", $template_str);
    }
    return array($template_str, $attachment_info);
}
Пример #3
0
/**
 * This is the hook for the ft_get_uploaded_files core function. It returns an array of hashes;
 *
 * @param array $params
 */
function ft_file_get_uploaded_files_hook($params)
{
    global $g_table_prefix;
    $form_id = $params["form_id"];
    $field_ids = isset($params["field_ids"]) && is_array($params["field_ids"]) ? $params["field_ids"] : array();
    $module_field_type_id = ft_get_field_type_id_by_identifier("file");
    $data = array();
    foreach ($field_ids as $field_id) {
        $field_type_id = ft_get_field_type_id_by_field_id($field_id);
        if ($field_type_id != $module_field_type_id) {
            continue;
        }
        $result = ft_get_field_col_by_field_id($form_id, field_id);
        $col_name = $result[$field_id];
        if (empty($col_name)) {
            continue;
        }
        $query = mysql_query("SELECT submission_id, {$col_name} FROM {$g_table_prefix}form_{$form_id}");
        if (!$query) {
            continue;
        }
        $field_settings = ft_get_field_settings($field_id);
        while ($row = mysql_fetch_assoc($query)) {
            // here, nothing's been uploaded in the field
            if (empty($row[$col_name])) {
                continue;
            }
            $data[] = array("submission_id" => $row["submission_id"], "field_id" => $field_id, "field_type_id" => $module_field_type_id, "folder_path" => $field_settings["folder_path"], "folder_url" => $field_settings["folder_url"], "filename" => $row[$col_name]);
        }
    }
    return array("uploaded_files" => $data);
}