/** * Called on the Settings page. Updates the generated file folder information. * * @param array $info * @return array [0] T/F [1] Error / notification message */ function exp_update_settings($info) { global $g_table_prefix, $L; $old_settings = ft_get_module_settings(); $info = ft_sanitize($info); $settings = array(); $settings["file_upload_dir"] = $info["file_upload_dir"]; $settings["file_upload_url"] = $info["file_upload_url"]; //$settings["cache_multi_select_fields"] = (isset($info["cache_multi_select_fields"]) && !empty($info["cache_multi_select_fields"])) ? // $info["cache_multi_select_fields"] : "no"; ft_set_module_settings($settings); // $_SESSION["ft"]["export_manager"]["cache_multi_select_fields"] = $settings["cache_multi_select_fields"]; return array(true, $L["notify_settings_updated"]); }
<?php require "../../global/library.php"; $folder = dirname(__FILE__); require_once "{$folder}/library.php"; ft_init_module_page(); if (isset($_POST["update"])) { list($g_success, $g_message) = pg_update_settings($_POST); } $page_vars = array(); $page_vars["head_title"] = "{$L["word_pages"]} - {$LANG["word_settings"]}"; $page_vars["num_pages_per_page"] = ft_get_module_settings("num_pages_per_page"); ft_display_module_page("templates/settings.tpl", $page_vars);
/** * This constructs and sends the email from an individual email template for a single form * submission. * * @param integer $form_id * @param integer $submission_id * @param integer $email_id */ function ft_process_email_template($form_id, $submission_id, $email_id) { list($success, $email_components) = ft_get_email_components($form_id, $submission_id, $email_id); if (!$success) { return array(false, "Email components not returned properly (ft_get_email_components)."); } extract(ft_process_hook_calls("start", compact("form_id", "submission_id", "email_id", "email_components"), array("email_components")), EXTR_OVERWRITE); // if Swift Mailer is enabled, send the emails with that $continue = true; if (ft_check_module_enabled("swift_mailer")) { $sm_settings = ft_get_module_settings("", "swift_mailer"); if (isset($sm_settings["swiftmailer_enabled"]) && $sm_settings["swiftmailer_enabled"] == "yes") { ft_include_module("swift_mailer"); list($success, $message) = swift_send_email($email_components); $continue = false; } } // if it was sent (or was attempted to have been sent) by the Swift Mailer module, stop here if (!$continue) { return array($success, $message); } $eol = _ft_get_email_eol_char(); $recipient_list = array(); foreach ($email_components["to"] as $to_info) { $recipient_list[] = $to_info["recipient_line"]; } $to = join(", ", $recipient_list); $to = htmlspecialchars_decode($to); if (empty($to)) { return array(false, "No main recipient specified."); } $headers = "MIME-Version: 1.0{$eol}"; if (!empty($email_components["from"])) { $from = htmlspecialchars_decode($email_components["from"]["recipient_line"]); $headers .= "From: {$from}{$eol}"; } if (!empty($email_components["reply_to"])) { $reply_to = htmlspecialchars_decode($email_components["reply_to"]["recipient_line"]); $headers .= "Reply-to: {$reply_to}{$eol}"; } if (!empty($email_components["cc"])) { $cc_list = array(); foreach ($email_components["cc"] as $cc_info) { $cc_list[] = $cc_info["recipient_line"]; } $cc = join(", ", $cc_list); $cc = htmlspecialchars_decode($cc); $headers .= "Cc: {$cc}{$eol}"; } if (!empty($email_components["bcc"])) { $bcc_list = array(); foreach ($email_components["bcc"] as $bcc_info) { $bcc_list[] = $bcc_info["recipient_line"]; } $bcc = join(", ", $bcc_list); $bcc = htmlspecialchars_decode($bcc); $headers .= "Bcc: {$bcc}{$eol}"; } $message = ""; $html_content = isset($email_components["html_content"]) ? $email_components["html_content"] : ""; $text_content = isset($email_components["text_content"]) ? $email_components["text_content"] : ""; $html_content = trim($html_content); $text_content = trim($text_content); // if there's no TO line or there's no email content for either types, we can't send the email if (empty($html_content) && empty($text_content)) { return array(false, "No text or HTML email content specified"); } if (!empty($html_content) && !empty($text_content)) { $headers .= _ft_get_multipart_message($html_content, $text_content, $eol); } else { if (!empty($html_content)) { $message = $html_content; $headers .= "Content-type: text/html; charset=UTF-8"; } else { if (!empty($text_content)) { $message = $text_content; $headers .= "Content-type: text/plain; charset=UTF-8"; } } } $subject = $email_components["subject"]; // send the email $email_sent = @mail("{$to}", $subject, $message, $headers); if ($email_sent) { return array(true, ""); } else { return array(false, "The mail() function failed to send the email."); } }
<?php require "../../global/library.php"; ft_init_module_page(); require_once "library.php"; $request = array_merge($_POST, $_GET); if (isset($request["update"])) { list($g_success, $g_message) = exp_update_settings($request); } $module_settings = ft_get_module_settings(); $module_id = ft_get_module_id_from_module_folder("export_manager"); $module_info = ft_get_module($module_id); // ------------------------------------------------------------------------------------------------ $page_vars = array(); $page_vars["head_title"] = "{$L["module_name"]} - {$LANG["word_settings"]}"; $page_vars["module_settings"] = $module_settings; $page_vars["module_version"] = $module_info["version"]; $page_vars["allow_url_fopen"] = ini_get("allow_url_fopen") == "1"; ft_display_module_page("templates/settings.tpl", $page_vars);
/** * Sends an email with the Swift Mailer module. * * @param array $email_components * @return array */ function swift_send_email($email_components) { global $g_table_prefix; // find out what version of PHP we're running $version = phpversion(); $version_parts = explode(".", $version); $main_version = $version_parts[0]; if ($main_version == "5") { $php_version_folder = "php5"; } else { if ($main_version == "4") { $php_version_folder = "php4"; } else { return array(false, $L["notify_php_version_not_found_or_invalid"]); } } // include the main files $current_folder = dirname(__FILE__); require_once "{$current_folder}/{$php_version_folder}/ft_library.php"; require_once "{$current_folder}/{$php_version_folder}/Swift.php"; require_once "{$current_folder}/{$php_version_folder}/Swift/Connection/SMTP.php"; $settings = ft_get_module_settings("", "swift_mailer"); $use_anti_flooding = isset($settings["use_anti_flooding"]) && $settings["use_anti_flooding"] == "yes"; // if the user has requested anti-flooding, include the plugin if ($use_anti_flooding) { require_once "{$current_folder}/{$php_version_folder}/Swift/Plugin/AntiFlood.php"; } // if we're requiring authentication, include the appropriate authenticator file if ($settings["requires_authentication"] == "yes") { switch ($settings["authentication_procedure"]) { case "LOGIN": require_once "{$current_folder}/{$php_version_folder}/Swift/Authenticator/LOGIN.php"; break; case "PLAIN": require_once "{$current_folder}/{$php_version_folder}/Swift/Authenticator/PLAIN.php"; break; case "CRAMMD5": require_once "{$current_folder}/{$php_version_folder}/Swift/Authenticator/CRAMMD5.php"; break; } } $success = true; $message = "The email was successfully sent."; // make the SMTP connection (this is PHP-version specific) $smtp = swift_make_smtp_connection($settings); // if required, set the server timeout (Swift Mailer default == 15 seconds) if (isset($settings["server_connection_timeout"]) && !empty($settings["server_connection_timeout"])) { $smtp->setTimeout($settings["server_connection_timeout"]); } if ($settings["requires_authentication"] == "yes") { $smtp->setUsername($settings["username"]); $smtp->setPassword($settings["password"]); } $swift =& new Swift($smtp); // apply the anti-flood settings if ($use_anti_flooding) { $anti_flooding_email_batch_size = $settings["anti_flooding_email_batch_size"]; $anti_flooding_email_batch_wait_time = $settings["anti_flooding_email_batch_wait_time"]; if (is_numeric($anti_flooding_email_batch_size) && is_numeric($anti_flooding_email_batch_wait_time)) { $swift->attachPlugin(new Swift_Plugin_AntiFlood($anti_flooding_email_batch_size, $anti_flooding_email_batch_wait_time), "anti-flood"); } } // now send the appropriate email if (!empty($email_components["text_content"]) && !empty($email_components["html_content"])) { $email =& new Swift_Message($email_components["subject"]); $email->attach(new Swift_Message_Part($email_components["text_content"])); $email->attach(new Swift_Message_Part($email_components["html_content"], "text/html")); } else { if (!empty($email_components["text_content"])) { $email =& new Swift_Message($email_components["subject"]); $email->attach(new Swift_Message_Part($email_components["text_content"])); } else { if (!empty($email_components["html_content"])) { $email =& new Swift_Message($email_components["subject"]); $email->attach(new Swift_Message_Part($email_components["html_content"], "text/html")); } } } // add the return path, if it's defined if (isset($email_components["email_id"])) { $email_id = $email_components["email_id"]; $query = mysql_query("SELECT * FROM {$g_table_prefix}module_swift_mailer_email_template_fields WHERE email_template_id = {$email_id}"); $extended_field_info = mysql_fetch_assoc($query); if (isset($extended_field_info["return_path"]) && !empty($extended_field_info["return_path"])) { $email->setReturnPath($extended_field_info["return_path"]); } } if (isset($settings["charset"]) && !empty($settings["charset"])) { $email->setCharset($settings["charset"]); } // now compile the recipient list $recipients =& new Swift_RecipientList(); foreach ($email_components["to"] as $to) { if (!empty($to["name"]) && !empty($to["email"])) { $recipients->addTo($to["email"], $to["name"]); } else { if (!empty($to["email"])) { $recipients->addTo($to["email"]); } } } if (!empty($email_components["cc"]) && is_array($email_components["cc"])) { foreach ($email_components["cc"] as $cc) { if (!empty($cc["name"]) && !empty($cc["email"])) { $recipients->addCc($cc["email"], $cc["name"]); } else { if (!empty($cc["email"])) { $recipients->addCc($cc["email"]); } } } } if (!empty($email_components["bcc"]) && is_array($email_components["bcc"])) { foreach ($email_components["bcc"] as $bcc) { if (!empty($bcc["name"]) && !empty($bcc["email"])) { $recipients->addBcc($bcc["email"], $bcc["name"]); } else { if (!empty($bcc["email"])) { $recipients->addBcc($bcc["email"]); } } } } if (!empty($email_components["reply_to"]["name"]) && !empty($email_components["reply_to"]["email"])) { $email->setReplyTo($email_components["reply_to"]["name"] . "<" . $email_components["reply_to"]["email"] . ">"); } else { if (!empty($email_components["reply_to"]["email"])) { $email->setReplyTo($email_components["reply_to"]["email"]); } } if (!empty($email_components["from"]["name"]) && !empty($email_components["from"]["email"])) { $from = new Swift_Address($email_components["from"]["email"], $email_components["from"]["name"]); } else { if (!empty($email_components["from"]["email"])) { $from = new Swift_Address($email_components["from"]["email"]); } } // finally, if there are any attachments, attach 'em if (isset($email_components["attachments"])) { foreach ($email_components["attachments"] as $attachment_info) { $filename = $attachment_info["filename"]; $file_and_path = $attachment_info["file_and_path"]; if (!empty($attachment_info["mimetype"])) { $email->attach(new Swift_Message_Attachment(new Swift_File($file_and_path), $filename, $attachment_info["mimetype"])); } else { $email->attach(new Swift_Message_Attachment(new Swift_File($file_and_path), $filename)); } } } if ($use_anti_flooding) { $swift->batchSend($email, $recipients, $from); } else { $swift->send($email, $recipients, $from); } return array($success, $message); }
/** * Used by the "forget password?" page to have a client's login information sent to them. * * @param array $info the $_POST containing a "username" key. That value is used to find the user * account information to email them. * @return array [0]: true/false (success / failure) * [1]: message string */ function ft_send_password($info) { global $g_root_url, $g_root_dir, $g_table_prefix, $LANG; $info = ft_sanitize($info); extract(ft_process_hook_calls("start", compact("info"), array("info")), EXTR_OVERWRITE); $success = true; $message = $LANG["notify_login_info_emailed"]; if (!isset($info["username"]) || empty($info["username"])) { $success = false; $message = $LANG["validation_no_username_or_js"]; return array($success, $message); } $username = $info["username"]; $query = mysql_query("\r\n SELECT *\r\n FROM {$g_table_prefix}accounts\r\n WHERE username = '******'\r\n "); // not found if (!mysql_num_rows($query)) { $success = false; $message = $LANG["validation_account_not_recognized_info"]; return array($success, $message); } $account_info = mysql_fetch_assoc($query); $email = $account_info["email"]; // one final check: confirm the email is defined & valid if (empty($email) || !ft_is_valid_email($email)) { $success = false; $message = $LANG["validation_email_not_found_or_invalid"]; return array($success, $message); } $account_id = $account_info["account_id"]; $username = $account_info["username"]; $new_password = ft_generate_password(); $encrypted_password = md5(md5($new_password)); // update the database with the new password (encrypted). As of 2.1.0 there's a second field to store the // temporary generated password, leaving the original password intact. This prevents a situation arising when // someone other than the admin / client uses the "Forget Password" feature and invalidates a valid, known password. // Any time the user successfully logs in, mysql_query("\r\n UPDATE {$g_table_prefix}accounts\r\n SET temp_reset_password = '******'\r\n WHERE account_id = {$account_id}\r\n "); // now build and sent the email // 1. build the email content $placeholders = array("login_url" => "{$g_root_url}/?id={$account_id}", "email" => $email, "username" => $username, "new_password" => $new_password); $smarty_template_email_content = file_get_contents("{$g_root_dir}/global/emails/forget_password.tpl"); $email_content = ft_eval_smarty_string($smarty_template_email_content, $placeholders); // 2. build the email subject line $placeholders = array("program_name" => ft_get_settings("program_name")); $smarty_template_email_subject = file_get_contents("{$g_root_dir}/global/emails/forget_password_subject.tpl"); $email_subject = trim(ft_eval_smarty_string($smarty_template_email_subject, $placeholders)); // if Swift Mailer is enabled, send the emails with that. In case there's a problem sending the message with // Swift, it falls back the default mail() function. $swift_mail_error = false; $swift_mail_enabled = ft_check_module_enabled("swift_mailer"); if ($swift_mail_enabled) { $sm_settings = ft_get_module_settings("", "swift_mailer"); if ($sm_settings["swiftmailer_enabled"] == "yes") { ft_include_module("swift_mailer"); // get the admin info. We'll use that info for the "from" and "reply-to" values. Note // that we DON'T use that info for the regular mail() function. This is because retrieving // the password is important functionality and we don't want to cause problems that could // prevent the email being sent. Many servers don't all the 4th headers parameter of the mail() // function $admin_info = ft_get_admin_info(); $admin_email = $admin_info["email"]; $email_info = array(); $email_info["to"] = array(); $email_info["to"][] = array("email" => $email); $email_info["from"] = array(); $email_info["from"]["email"] = $admin_email; $email_info["subject"] = $email_subject; $email_info["text_content"] = $email_content; list($success, $sm_message) = swift_send_email($email_info); // if the email couldn't be sent, display the appropriate error message. Otherwise // the default success message is used if (!$success) { $swift_mail_error = true; $message = $sm_message; } } } // if there was an error sending with Swift, or if it wasn't installed, send it by mail() if (!$swift_mail_enabled || $swift_mail_error) { // send email [note: the double quotes around the email recipient and content are intentional: some systems fail without it] if (!@mail("{$email}", $email_subject, $email_content)) { $success = false; $message = $LANG["notify_email_not_sent"]; return array($success, $message); } } extract(ft_process_hook_calls("end", compact("success", "message", "info"), array("success", "message")), EXTR_OVERWRITE); return array($success, $message); }
<?php require_once "../../global/library.php"; ft_init_module_page(); $folder = dirname(__FILE__); require_once "{$folder}/library.php"; if (isset($_GET["delete"])) { list($g_success, $g_message) = pg_delete_page($_GET["delete"]); } $page = ft_load_module_field("pages", "page", "module_pages_page", 1); $num_pages_per_page = ft_get_module_settings("num_pages_per_page"); $pages_info = pg_get_pages($num_pages_per_page, $page); $results = $pages_info["results"]; $num_results = $pages_info["num_results"]; $text_intro_para_2 = ft_eval_smarty_string($L["text_intro_para_2"], array("url" => "../../admin/settings/index.php?page=menus")); // ------------------------------------------------------------------------------------------------ $page_vars = array(); $page_vars["pages"] = $results; $page_vars["head_title"] = $L["module_name"]; $page_vars["pagination"] = ft_get_page_nav($num_results, $num_pages_per_page, $page, ""); $page_vars["js_messages"] = array("word_edit", "phrase_please_confirm", "word_yes", "word_no"); $page_vars["module_js_messages"] = array("confirm_delete_page"); $page_vars["text_intro_para_2"] = $text_intro_para_2; $page_vars["head_string"] = <<<EOF <script type="text/javascript" src="scripts/pages.js"></script> EOF; ft_display_module_page("templates/index.tpl", $page_vars);