function smarty_function_display_custom_field($params, &$smarty) { // note that View ID is optional $required_params = array("form_id", "submission_id", "field_info", "field_types", "settings"); foreach ($required_params as $param) { if (!isset($params[$param])) { // $smarty->trigger_error("assign: missing '$param' parameter."); return; } } echo ft_generate_viewable_field($params); }
/** * Smarty plugin * ------------------------------------------------------------- * File: function.smart_display_field * Type: function * Name: smart_display_field * Purpose: This function functionally does the same as the Core dispay_custom_field Smarty function, * except that it's designed to display the field values in bulk. To speed things up, it caches * as much info as it can, to reduce DB queries etc. * ------------------------------------------------------------- */ function smarty_function_smart_display_field($params, &$smarty) { $value = ft_generate_viewable_field($params); // additional code for CSV encoding if (isset($params["escape"])) { if ($params["escape"] == "csv") { $value = preg_replace("/\"/", "\"\"", $value); if (strstr($value, ",")) { $value = "\"{$value}\""; } } if ($params["escape"] == "excel") { $value = preg_replace("/(\n\r|\n)/", "<br style=\"mso-data-placement:same-cell;\" />", $value); } } echo $value; }
/** * 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; }