From b495e8edfa9230ae2c0f0006808d6b5c5c9687cf Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Wed, 4 May 2011 09:22:09 +0000 Subject: [PATCH] Mail template work. Quick-Add-User now has it's own template also. --- e107_admin/users.php | 37 ++++++++++++++++---- e107_handlers/mail.php | 28 +++++++++++++--- e107_languages/English/admin/lan_users.php | 2 +- e107_themes/templates/email_template.php | 39 ++++++++++++++++++---- 4 files changed, 88 insertions(+), 18 deletions(-) diff --git a/e107_admin/users.php b/e107_admin/users.php index e1c9ad83f..2c0217463 100644 --- a/e107_admin/users.php +++ b/e107_admin/users.php @@ -302,30 +302,43 @@ if (isset ($_POST['adduser'])) $message = ''; $user_data['user_password'] = $userMethods->HashPassword($savePassword,$user_data['user_login']); $user_data['user_join'] = time(); + if ($userMethods->needEmailPassword()) { // Save separate password encryption for use with email address $user_data['user_prefs'] = serialize(array('email_password' => $userMethods->HashPassword($savePassword,$user_data['user_email']))); } + $userMethods->userClassUpdate($allData['data'],'userall'); // Set any initial classes $userMethods->addNonDefaulted($user_data); validatorClass :: addFieldTypes($userMethods->userVettingInfo,$allData); //FIXME - (SecretR) there is a better way to fix this (missing default value, sql error in strict mode - user_realm is to be deleted from DB later) $allData['data']['user_realm'] = ''; + if ($sql->db_Insert('user',$allData)) { - // Add to admin log + // Add to admin log $admin_log->log_event('USET_02',"UName: {$user_data['user_name']}; Email: {$user_data['user_email']}",E_LOG_INFORMATIVE); + // Add to user audit trail $admin_log->user_audit(USER_AUDIT_ADD_ADMIN,$user_data,0,$user_data['user_loginname']); $e_event->trigger('userfull',$user_data); + // send everything available for user data - bit sparse compared with user-generated signup if (isset ($_POST['sendconfemail'])) { // Send confirmation email to user - require_once (e_HANDLER.'mail.php'); - $e_message = str_replace(array('--SITE--','--LOGIN--','--PASSWORD--'),array(SITEURL,$user_data['user_login'],$savePassword),USRLAN_185).USRLAN_186; + require_once(e_HANDLER.'mail.php'); + include_once(e107::coreTemplatePath('email','front')); //correct way to load a core template. + + if(!isset($QUICKADDUSER_TEMPLATE)) + { + $QUICKADDUSER_TEMPLATE = USRLAN_185.USRLAN_186; + } + + $e_message = str_replace(array('{SITEURL}','{LOGIN}','{USERNAME}','{PASSWORD}'),array(SITEURL,$user_data['user_name'],$user_data['user_login'],$savePassword),$QUICKADDUSER_TEMPLATE); + if (sendemail($user_data['user_email'],USRLAN_187.SITEURL,$e_message,$user_data['user_login'],'','')) { $message = USRLAN_188.'

'; @@ -335,17 +348,29 @@ if (isset ($_POST['adduser'])) $message = USRLAN_189.'

'; } } + $message .= str_replace('--NAME--',$user_data['user_name'],USRLAN_174); + if (isset ($_POST['generateloginname'])) - $message .= '

'.USRLAN_173.': '.$user_data['user_login']; + { + $message .= '

'.USRLAN_173.': '.$user_data['user_login']; + } + if (isset ($_POST['generatepassword'])) - $message .= '

'.USRLAN_172.': '.$savePassword; + { + $message .= '

'.USRLAN_172.': '.$savePassword; + } + unset ($user_data); // Don't recycle the data once the user's been accepted without error } } + if (isset ($message)) - $user->show_message($message); + { + $user->show_message($message); + } + } // ------- Bounce --> Unverified -------------- if (isset ($_POST['useraction']) && $_POST['useraction'] == "reqverify") diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 86335c2aa..bde505b89 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -152,10 +152,11 @@ class e107Email extends PHPMailer private $TotalErrors = 0; // Count errors in sending emails private $pause_amount = 10; // Number of emails to send before pausing/resetting (or closing if SMTPkeepAlive set) private $pause_time = 1; // Time to pause after sending a block of emails - + private $templateOption = array(); public $legacyBody = FALSE; // TRUE enables legacy conversion of plain text body to HTML in HTML emails - - /** + public $template = "email"; // Choice of email, notify or mailout + +/** * Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed * * @var array $overrides - array of values which override mail-related prefs. Key is the same as the corresponding pref. @@ -167,7 +168,13 @@ class e107Email extends PHPMailer $e107 = e107::getInstance(); global $pref; - + + //Load up Email Templates + include(e107::coreTemplatePath('email','front')); + $this->templateOption['email'] = array('header'=>$EMAIL_HEADER,'footer'=>$EMAIL_FOOTER); + $this->templateOption['notify'] = array('header'=>$NOTIFY_HEADER,'footer'=>$NOTIFY_FOOTER); + $this->templateOption['mailout'] = array('header'=>$MAILOUT_HEADER,'footer'=>$MAILOUT_FOOTER); + $this->CharSet = 'utf-8'; $this->SetLanguage(CORE_LC); @@ -709,6 +716,16 @@ class e107Email extends PHPMailer */ public function MsgHTML($message, $basedir = '') { + + $tp = e107::getParser(); + + $EMAIL_HEADER = $tp->parseTemplate($this->templateOption[$this->template]['header']); + $EMAIL_FOOTER = $tp->parseTemplate($this->templateOption[$this->template]['footer']); + + $message = $EMAIL_HEADER.$message.$EMAIL_FOOTER; + + + preg_match_all("/(src|background)=([\"\'])(.*)\\2/Ui", $message, $images); // Modified to accept single quotes as well if(isset($images[3])) { @@ -745,8 +762,11 @@ class e107Email extends PHPMailer } } } + + $this->IsHTML(true); $this->Body = $message; + // print_a($message); $textMsg = str_replace(array('
', '
'), "\n", $message); // Modified to make sure newlines carried through $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$textMsg))); diff --git a/e107_languages/English/admin/lan_users.php b/e107_languages/English/admin/lan_users.php index 79ad0425f..1f27810f5 100644 --- a/e107_languages/English/admin/lan_users.php +++ b/e107_languages/English/admin/lan_users.php @@ -185,7 +185,7 @@ define('USRLAN_181', 'Send confirmation email with password to new user'); define('USRLAN_182', 'Invalid characters in login name'); define('USRLAN_183', 'That login name already in use'); define('USRLAN_184', 'Length of login name outside limits'); -define('USRLAN_185', 'A user account has been created for you at --SITE-- with the following login:
Login Name: --LOGIN--
Password: --PASSWORD--

'); +define('USRLAN_185', 'A user account has been created for you at {SITEURL} with the following login:
Login Name: {LOGIN}
Password: {PASSWORD}

'); define('USRLAN_186', 'Please go to the site as soon as possible and log in, then change your password using the \'Settings\' option.

You can also change other settings at the same time.

Note that your password cannot be recovered if you lose it.'); define('USRLAN_187', 'Access to website: '); diff --git a/e107_themes/templates/email_template.php b/e107_themes/templates/email_template.php index 9b74361c2..923755f37 100644 --- a/e107_themes/templates/email_template.php +++ b/e107_themes/templates/email_template.php @@ -44,19 +44,22 @@ $EMAIL_OVERRIDES = array( ); */ -// Not used in signup email +/** + * Default HEADER for all emails + */ $EMAIL_HEADER = " -{STYLESHEET}
"; -// Not used in signup email +/** + * Default FOOTER for all emails + */ $EMAIL_FOOTER = "

{SITENAME=link} @@ -65,18 +68,22 @@ $EMAIL_FOOTER = " "; -//TODO - integrate into mailout routine +/** + * Mass-Mailing HEADER (admin->mailout) + */ $MAILOUT_HEADER = " -{STYLESHEET}
"; +/** + * Mass-Mailing FOOTER (admin->mailout) + */ $MAILOUT_FOOTER = "

{SITENAME=link} @@ -85,17 +92,22 @@ $MAILOUT_FOOTER = " "; +/** + * Notification Email HEADER (admin->notify) + */ //TODO - integrate into notification routine $NOTIFY_HEADER = " -{STYLESHEET}
"; +/** + * Notification Email FOOTER (admin->notify) + */ $NOTIFY_FOOTER = "

{SITENAME=link} @@ -104,7 +116,9 @@ $NOTIFY_FOOTER = " "; - +/* + * SIGNUP EMAIL TEMPLATE - BODY. +*/ $SIGNUPEMAIL_TEMPLATE = "
@@ -135,4 +149,15 @@ LAN_SIGNUP_97." {SITENAME}
"; +/* + * QUICK ADD USER EMAIL TEMPLATE - BODY. + * This is the email that is sent when an admin creates a user account in admin. "Quick Add User" + USRLAN_185 = A user account has been created for you at {SITEURL} with the following login:
Login Name: {LOGIN}
Password: {PASSWORD}

+ USRLAN_186 = Please go to the site as soon as possible and log in, then change your password using the \'Settings\' option.

+ You can also change other settings at the same time.

Note that your password cannot be recovered if you lose it. +*/ + +$QUICKADDUSER_TEMPLATE = "
".USRLAN_185.USRLAN_186."
"; + + ?> \ No newline at end of file