/** * Strongly coupled with the ft_get_email_components function, this does the legwork to find out exactly what * text and HTML (Smarty) content should be in the emails. Returns BOTH, regardless of whether the template is * only using one. * * @param integer $form_id * @param integer $submission_id * @param array $email_template * @param boolean $is_test * @param array $test_settings */ function _ft_get_email_template_content($form_id, $submission_id, $email_template, $is_test, $test_settings) { global $LANG, $g_table_prefix; // if this is a test, find out what information the administrator wants $templates = array("text" => "", "html" => "", "submission_id" => $submission_id); if ($is_test) { $test_email_format = $test_settings["test_email_format"]; $test_email_recipient = $test_settings["test_email_recipient"]; $test_email_data_source = $test_settings["test_email_data_source"]; $test_email_submission_id = $test_settings["test_email_submission_id"]; // get the submission ID switch ($test_email_data_source) { case "random_submission": // if this email template has been mapped to only be sent for one or more Views, // find a submission that fits into the first in the list $where_clause = ""; if (!empty($email_template["when_sent_view_ids"])) { $sql_clauses = ft_get_view_filter_sql($email_template["when_sent_view_ids"][0]); if (!empty($sql_clauses)) { $where_clause = "WHERE (" . join(" AND ", $sql_clauses) . ") "; } } $result = mysql_query("\r\n SELECT submission_id\r\n FROM {$g_table_prefix}form_{$form_id}\r\n {$where_clause}\r\n ORDER BY rand() LIMIT 1\r\n "); $row = mysql_fetch_row($result); $submission_id = $row[0]; break; case "submission_id": $result = mysql_query("SELECT count(*) FROM {$g_table_prefix}form_{$form_id} WHERE submission_id={$test_email_submission_id}"); $row = mysql_fetch_row($result); if ($row[0] != 1) { return array(false, $LANG["notify_submission_id_not_found"]); } else { $submission_id = $test_email_submission_id; } break; } $templates["submission_id"] = $submission_id; // determine what templates to display switch ($test_email_format) { case "both": $templates["html"] = $email_template["html_template"]; $templates["text"] = $email_template["text_template"]; break; case "text": $templates["text"] = $email_template["text_template"]; break; case "html": $templates["html"] = $email_template["html_template"]; break; } } else { $templates["html"] = $email_template["html_template"]; $templates["text"] = $email_template["text_template"]; } return $templates; }
/** * This checks to see if a particular submission meets the criteria to belong in a particular View. * It only applies to those Views that have one or more filters set up, but it works on all Views * nonetheless. * * @param integer $view_id * @param integer $view_id * @param integer $submission_id */ function ft_check_view_contains_submission($form_id, $view_id, $submission_id) { global $g_table_prefix; $filter_sql = ft_get_view_filter_sql($view_id); if (empty($filter_sql)) { return true; } $filter_sql_clause = join(" AND ", $filter_sql); $query = @mysql_query("\n SELECT count(*) as c\n FROM {$g_table_prefix}form_{$form_id}\n WHERE submission_id = {$submission_id} AND\n ({$filter_sql_clause})\n "); $result = mysql_fetch_assoc($query); return $result["c"] == 1; }
/** * Caches the total number of (finalized) submissions in a particular form - or all forms - * in the $_SESSION["ft"]["form_{$form_id}_num_submissions"] key. That value is used on the administrators * main Forms page to list the form submission count. * * @param integer $form_id */ function _ft_cache_view_stats($form_id, $view_id = "") { global $g_table_prefix; $view_ids = array(); if (empty($view_id)) { $view_ids = ft_get_view_ids($form_id); } else { $view_ids[] = $view_id; } foreach ($view_ids as $view_id) { $filters = ft_get_view_filter_sql($view_id); // if there aren't any filters, just set the submission count & first submission date to the same // as the parent form if (empty($filters)) { $_SESSION["ft"]["view_{$view_id}_num_submissions"] = $_SESSION["ft"]["form_{$form_id}_num_submissions"]; } else { $filter_clause = join(" AND ", $filters); $count_query = mysql_query("\r\n SELECT count(*) as c\r\n FROM {$g_table_prefix}form_{$form_id}\r\n WHERE is_finalized = 'yes' AND\r\n {$filter_clause}\r\n ") or ft_handle_error("Failed query in <b>" . __FUNCTION__ . "</b>, line " . __LINE__, mysql_error()); $info = mysql_fetch_assoc($count_query); $_SESSION["ft"]["view_{$view_id}_num_submissions"] = $info["c"]; } } }