Commit e436bae2751c2b8a92104149ecd23d84e5fd9dca
1 parent
6fa7e67d
Added function to create standard email template
Committed By: Kevin Cyster Reviewed By: Megan Watson
Showing
1 changed file
with
88 additions
and
34 deletions
lib/email/Email.inc
| @@ -8,31 +8,31 @@ | @@ -8,31 +8,31 @@ | ||
| 8 | * Document Management Made Simple | 8 | * Document Management Made Simple |
| 9 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. | 9 | * Copyright (C) 2008, 2009 KnowledgeTree Inc. |
| 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 10 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 11 | - * | 11 | + * |
| 12 | * This program is free software; you can redistribute it and/or modify it under | 12 | * This program is free software; you can redistribute it and/or modify it under |
| 13 | * the terms of the GNU General Public License version 3 as published by the | 13 | * the terms of the GNU General Public License version 3 as published by the |
| 14 | * Free Software Foundation. | 14 | * Free Software Foundation. |
| 15 | - * | 15 | + * |
| 16 | * This program is distributed in the hope that it will be useful, but WITHOUT | 16 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 18 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 19 | * details. | 19 | * details. |
| 20 | - * | 20 | + * |
| 21 | * You should have received a copy of the GNU General Public License | 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 22 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | - * | ||
| 24 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | 23 | + * |
| 24 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | ||
| 25 | * California 94120-7775, or email info@knowledgetree.com. | 25 | * California 94120-7775, or email info@knowledgetree.com. |
| 26 | - * | 26 | + * |
| 27 | * The interactive user interfaces in modified source and object code versions | 27 | * The interactive user interfaces in modified source and object code versions |
| 28 | * of this program must display Appropriate Legal Notices, as required under | 28 | * of this program must display Appropriate Legal Notices, as required under |
| 29 | * Section 5 of the GNU General Public License version 3. | 29 | * Section 5 of the GNU General Public License version 3. |
| 30 | - * | 30 | + * |
| 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 31 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 32 | * these Appropriate Legal Notices must retain the display of the "Powered by | 32 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 33 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 33 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 34 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 34 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 35 | - * must display the words "Powered by KnowledgeTree" and retain the original | 35 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 36 | * copyright notice. | 36 | * copyright notice. |
| 37 | * Contributor( s): ______________________________________ | 37 | * Contributor( s): ______________________________________ |
| 38 | */ | 38 | */ |
| @@ -49,7 +49,7 @@ class Email { | @@ -49,7 +49,7 @@ class Email { | ||
| 49 | * with default system information | 49 | * with default system information |
| 50 | * | 50 | * |
| 51 | * @param string the sender's email address (optional) | 51 | * @param string the sender's email address (optional) |
| 52 | - * @param string the sender's name (optional) | 52 | + * @param string the sender's name (optional) |
| 53 | */ | 53 | */ |
| 54 | function Email($sFromEmail = "", $sFromName = "") { | 54 | function Email($sFromEmail = "", $sFromName = "") { |
| 55 | global $default; | 55 | global $default; |
| @@ -66,8 +66,8 @@ class Email { | @@ -66,8 +66,8 @@ class Email { | ||
| 66 | $this->oMailer->IsHTML(true); | 66 | $this->oMailer->IsHTML(true); |
| 67 | $this->oMailer->SetLanguage('en', KT_DIR . '/thirdparty/phpmailer/language/'); | 67 | $this->oMailer->SetLanguage('en', KT_DIR . '/thirdparty/phpmailer/language/'); |
| 68 | $this->bEmailDisabled = false; | 68 | $this->bEmailDisabled = false; |
| 69 | - | ||
| 70 | - $oConfig =& KTConfig::getSingleton(); | 69 | + |
| 70 | + $oConfig =& KTConfig::getSingleton(); | ||
| 71 | $sEmailServer = $oConfig->get('email/emailServer'); | 71 | $sEmailServer = $oConfig->get('email/emailServer'); |
| 72 | if ($sEmailServer == 'none') { | 72 | if ($sEmailServer == 'none') { |
| 73 | $this->bEmailDisabled = true; | 73 | $this->bEmailDisabled = true; |
| @@ -90,7 +90,7 @@ class Email { | @@ -90,7 +90,7 @@ class Email { | ||
| 90 | $this->oMailer->Password = $sEmailPass; | 90 | $this->oMailer->Password = $sEmailPass; |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | - | 93 | + |
| 94 | /** | 94 | /** |
| 95 | * Sends an email to a specified recipient. | 95 | * Sends an email to a specified recipient. |
| 96 | * | 96 | * |
| @@ -98,7 +98,7 @@ class Email { | @@ -98,7 +98,7 @@ class Email { | ||
| 98 | * @param string the subject of the email | 98 | * @param string the subject of the email |
| 99 | * @param string the body of the email | 99 | * @param string the body of the email |
| 100 | * @param string the sender's email address (optional) | 100 | * @param string the sender's email address (optional) |
| 101 | - * @param string the sender's name (optional) | 101 | + * @param string the sender's name (optional) |
| 102 | * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | 102 | * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] |
| 103 | */ | 103 | */ |
| 104 | function send($mToEmail, $sSubject, $sBody) { | 104 | function send($mToEmail, $sSubject, $sBody) { |
| @@ -106,9 +106,9 @@ class Email { | @@ -106,9 +106,9 @@ class Email { | ||
| 106 | return PEAR::raiseError(_kt("Email is not configured.")); | 106 | return PEAR::raiseError(_kt("Email is not configured.")); |
| 107 | } | 107 | } |
| 108 | global $default; | 108 | global $default; |
| 109 | - | ||
| 110 | - if ( (is_string($mToEmail) && (strlen($mToEmail) > 0)) || | ||
| 111 | - (is_array($mToEmail) && (count($mToEmail) > 0)) ) { | 109 | + |
| 110 | + if ( (is_string($mToEmail) && (strlen($mToEmail) > 0)) || | ||
| 111 | + (is_array($mToEmail) && (count($mToEmail) > 0)) ) { | ||
| 112 | 112 | ||
| 113 | $aEmailAddresses = array(); | 113 | $aEmailAddresses = array(); |
| 114 | // just one email address, add it | 114 | // just one email address, add it |
| @@ -118,7 +118,7 @@ class Email { | @@ -118,7 +118,7 @@ class Email { | ||
| 118 | // if we're passed an array, then use it | 118 | // if we're passed an array, then use it |
| 119 | if (is_array($mToEmail)) { | 119 | if (is_array($mToEmail)) { |
| 120 | $aEmailAddresses = $mToEmail; | 120 | $aEmailAddresses = $mToEmail; |
| 121 | - // if there are multiple addresses (; separated), explode it | 121 | + // if there are multiple addresses (; separated), explode it |
| 122 | } elseif (strpos($mToEmail, ";") > 0) { | 122 | } elseif (strpos($mToEmail, ";") > 0) { |
| 123 | $aEmailAddresses = explode(";", $mToEmail); | 123 | $aEmailAddresses = explode(";", $mToEmail); |
| 124 | } | 124 | } |
| @@ -128,9 +128,11 @@ class Email { | @@ -128,9 +128,11 @@ class Email { | ||
| 128 | } | 128 | } |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | + $body = $this->makeEmailTemplate(stripslashes($sBody)); | ||
| 131 | $this->oMailer->Subject = stripslashes($sSubject); | 132 | $this->oMailer->Subject = stripslashes($sSubject); |
| 132 | - $this->oMailer->Body = stripslashes($sBody); | ||
| 133 | - | 133 | +// $this->oMailer->Body = stripslashes($sBody); |
| 134 | + $this->oMailer->Body = $body; | ||
| 135 | + | ||
| 134 | //send the email | 136 | //send the email |
| 135 | if(!$this->oMailer->Send()) { | 137 | if(!$this->oMailer->Send()) { |
| 136 | $default->log->error("Error sending mail to $mToEmail; mailer error code=" . $this->oMailer->ErrorInfo); | 138 | $default->log->error("Error sending mail to $mToEmail; mailer error code=" . $this->oMailer->ErrorInfo); |
| @@ -160,9 +162,9 @@ class Email { | @@ -160,9 +162,9 @@ class Email { | ||
| 160 | return PEAR::raiseError(_kt("Email is not configured.")); | 162 | return PEAR::raiseError(_kt("Email is not configured.")); |
| 161 | } | 163 | } |
| 162 | global $default; | 164 | global $default; |
| 163 | - | ||
| 164 | - if ( (is_string($mToEmail) && (strlen($mToEmail) > 0)) || | ||
| 165 | - (is_array($mToEmail) && (count($mToEmail) > 0)) ) { | 165 | + |
| 166 | + if ( (is_string($mToEmail) && (strlen($mToEmail) > 0)) || | ||
| 167 | + (is_array($mToEmail) && (count($mToEmail) > 0)) ) { | ||
| 166 | 168 | ||
| 167 | // just one email address, add it | 169 | // just one email address, add it |
| 168 | if (is_string($mToEmail) && (strpos($mToEmail, ";") === false)) { | 170 | if (is_string($mToEmail) && (strpos($mToEmail, ";") === false)) { |
| @@ -172,7 +174,7 @@ class Email { | @@ -172,7 +174,7 @@ class Email { | ||
| 172 | // if we're passed an array, then use it | 174 | // if we're passed an array, then use it |
| 173 | if (is_array($mToEmail)) { | 175 | if (is_array($mToEmail)) { |
| 174 | $aEmailAddresses = $mToEmail; | 176 | $aEmailAddresses = $mToEmail; |
| 175 | - // if there are multiple addresses (; separated), explode it | 177 | + // if there are multiple addresses (; separated), explode it |
| 176 | } elseif (strpos($mToEmail, ";") > 0) { | 178 | } elseif (strpos($mToEmail, ";") > 0) { |
| 177 | $aEmailAddresses = explode(";", $mToEmail); | 179 | $aEmailAddresses = explode(";", $mToEmail); |
| 178 | } | 180 | } |
| @@ -182,10 +184,12 @@ class Email { | @@ -182,10 +184,12 @@ class Email { | ||
| 182 | } | 184 | } |
| 183 | } | 185 | } |
| 184 | 186 | ||
| 187 | + $body = $this->makeEmailTemplate(stripslashes($sBody)); | ||
| 185 | $this->oMailer->Subject = stripslashes($sSubject); | 188 | $this->oMailer->Subject = stripslashes($sSubject); |
| 186 | - $this->oMailer->Body = stripslashes($sBody); | 189 | +// $this->oMailer->Body = stripslashes($sBody); |
| 190 | + $this->oMailer->Body = $body; | ||
| 187 | $this->oMailer->AddAttachment($sDocumentPath, $sDocumentName); | 191 | $this->oMailer->AddAttachment($sDocumentPath, $sDocumentName); |
| 188 | - | 192 | + |
| 189 | //send the email | 193 | //send the email |
| 190 | if(!$this->oMailer->Send()) { | 194 | if(!$this->oMailer->Send()) { |
| 191 | $default->log->error("Error sending mail to $mToEmail; mailer error code=" . $this->oMailer->ErrorInfo); | 195 | $default->log->error("Error sending mail to $mToEmail; mailer error code=" . $this->oMailer->ErrorInfo); |
| @@ -211,7 +215,7 @@ class Email { | @@ -211,7 +215,7 @@ class Email { | ||
| 211 | * @param The hyperlink that should be sent | 215 | * @param The hyperlink that should be sent |
| 212 | * | 216 | * |
| 213 | * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | 217 | * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] |
| 214 | - * | 218 | + * |
| 215 | * @todo check for special characters (including encoding the link correctly???) | 219 | * @todo check for special characters (including encoding the link correctly???) |
| 216 | * @todo need to test this on multiple mail clients, not just Outlook | 220 | * @todo need to test this on multiple mail clients, not just Outlook |
| 217 | */ | 221 | */ |
| @@ -221,12 +225,15 @@ class Email { | @@ -221,12 +225,15 @@ class Email { | ||
| 221 | } | 225 | } |
| 222 | global $default; | 226 | global $default; |
| 223 | 227 | ||
| 228 | + $body = $this->makeEmailTemplate(stripslashes($EmailBody).'<br /><br />'.$hyperlink); | ||
| 229 | + | ||
| 224 | //get info from relevant fields. | 230 | //get info from relevant fields. |
| 225 | $this->oMailer->From = $FromEmail; | 231 | $this->oMailer->From = $FromEmail; |
| 226 | $this->oMailer->FromName = $FromName; | 232 | $this->oMailer->FromName = $FromName; |
| 227 | $this->oMailer->AddAddress($ToEmail); | 233 | $this->oMailer->AddAddress($ToEmail); |
| 228 | $this->oMailer->Subject = stripslashes($Subj); | 234 | $this->oMailer->Subject = stripslashes($Subj); |
| 229 | - $this->oMailer->Body = stripslashes($EmailBody) . ' ' . $hyperlink; | 235 | +// $this->oMailer->Body = stripslashes($EmailBody) . ' ' . $hyperlink; |
| 236 | + $this->oMailer->Body = $body; | ||
| 230 | 237 | ||
| 231 | //send the email | 238 | //send the email |
| 232 | if(!$this->oMailer->Send()) { | 239 | if(!$this->oMailer->Send()) { |
| @@ -236,7 +243,7 @@ class Email { | @@ -236,7 +243,7 @@ class Email { | ||
| 236 | return true; | 243 | return true; |
| 237 | } | 244 | } |
| 238 | /** | 245 | /** |
| 239 | - * Sends an email ment for administration, | 246 | + * Sends an email ment for administration, |
| 240 | * | 247 | * |
| 241 | * @param The sender's email address | 248 | * @param The sender's email address |
| 242 | * @param The sender's Name | 249 | * @param The sender's Name |
| @@ -246,7 +253,7 @@ class Email { | @@ -246,7 +253,7 @@ class Email { | ||
| 246 | * @param The hyperlink that should be sent | 253 | * @param The hyperlink that should be sent |
| 247 | * | 254 | * |
| 248 | * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] | 255 | * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"] |
| 249 | - * | 256 | + * |
| 250 | * @todo check for special characters (including encoding the link correctly???) | 257 | * @todo check for special characters (including encoding the link correctly???) |
| 251 | * @todo need to test this on multiple mail clients, not just Outlook | 258 | * @todo need to test this on multiple mail clients, not just Outlook |
| 252 | */ | 259 | */ |
| @@ -256,12 +263,15 @@ class Email { | @@ -256,12 +263,15 @@ class Email { | ||
| 256 | } | 263 | } |
| 257 | global $default; | 264 | global $default; |
| 258 | 265 | ||
| 266 | + $body = $this->makeEmailTemplate(stripslashes($EmailBody) . " <br />" . _kt("This bug can be found on this page") . ": " . "<a href = ". $hyperlink .">". $hyperlink ."</a>"); | ||
| 267 | + | ||
| 259 | //get info from relevant fields. | 268 | //get info from relevant fields. |
| 260 | $this->oMailer->From = $FromEmail; | 269 | $this->oMailer->From = $FromEmail; |
| 261 | $this->oMailer->FromName = $FromName; | 270 | $this->oMailer->FromName = $FromName; |
| 262 | $this->oMailer->AddAddress($ToEmail); | 271 | $this->oMailer->AddAddress($ToEmail); |
| 263 | $this->oMailer->Subject = stripslashes($Subj) . ' ' . $hyperlink; //only difference from above | 272 | $this->oMailer->Subject = stripslashes($Subj) . ' ' . $hyperlink; //only difference from above |
| 264 | - $this->oMailer->Body = stripslashes($EmailBody) . " <br>" . _kt("This bug can be found on this page") . ": " . "<a href = ". $hyperlink .">". $hyperlink ."</a>"; | 273 | +// $this->oMailer->Body = stripslashes($EmailBody) . " <br>" . _kt("This bug can be found on this page") . ": " . "<a href = ". $hyperlink .">". $hyperlink ."</a>"; |
| 274 | + $this->oMailer->Body = $body; | ||
| 265 | 275 | ||
| 266 | //send the email | 276 | //send the email |
| 267 | if(!$this->oMailer->Send()) { | 277 | if(!$this->oMailer->Send()) { |
| @@ -277,12 +287,14 @@ class Email { | @@ -277,12 +287,14 @@ class Email { | ||
| 277 | } | 287 | } |
| 278 | global $default; | 288 | global $default; |
| 279 | 289 | ||
| 290 | + $body = $this->makeEmailTemplate(stripslashes($EmailBody)); | ||
| 291 | + | ||
| 280 | //get info from relevant fields. | 292 | //get info from relevant fields. |
| 281 | $this->oMailer->From = $FromEmail; | 293 | $this->oMailer->From = $FromEmail; |
| 282 | $this->oMailer->FromName = $FromName; | 294 | $this->oMailer->FromName = $FromName; |
| 283 | $this->oMailer->AddAddress($ToEmail); | 295 | $this->oMailer->AddAddress($ToEmail); |
| 284 | $this->oMailer->Subject = stripslashes($Subj); | 296 | $this->oMailer->Subject = stripslashes($Subj); |
| 285 | - $this->oMailer->Body = stripslashes($EmailBody); | 297 | + $this->oMailer->Body = $body; |
| 286 | 298 | ||
| 287 | //send the email | 299 | //send the email |
| 288 | if(!$this->oMailer->Send()) { | 300 | if(!$this->oMailer->Send()) { |
| @@ -291,6 +303,48 @@ class Email { | @@ -291,6 +303,48 @@ class Email { | ||
| 291 | } | 303 | } |
| 292 | return true; | 304 | return true; |
| 293 | } | 305 | } |
| 294 | -} | ||
| 295 | 306 | ||
| 296 | -?> | 307 | + /* |
| 308 | + * This method builds the email template | ||
| 309 | + * | ||
| 310 | + * @author KnowledgeTree Team | ||
| 311 | + * @access public | ||
| 312 | + * @param string $email The email to be sent | ||
| 313 | + * @return string $str The html string that will be sent via email | ||
| 314 | + */ | ||
| 315 | + public function makeEmailTemplate($email) | ||
| 316 | + { | ||
| 317 | + $rootUrl = KTUtil::kt_url(); | ||
| 318 | + | ||
| 319 | + $oKTConfig =& KTConfig::getSingleton(); | ||
| 320 | + $mainLogo = $oKTConfig->get('mainLogo'); | ||
| 321 | + $appName = $oKTConfig->get('appName'); | ||
| 322 | + $companyLogoTitle = $oKTConfig->get('companyLogoTitle'); | ||
| 323 | + $mainLogoTitle = $oKTConfig->get('mainLogoTitle'); | ||
| 324 | + | ||
| 325 | + if($mainLogo != ''){ | ||
| 326 | + $logo = '<img src="'.$mainLogo.'" class="primary" alt="'.$companyLogoTitle.'" title="'.$mainLogoTitle.'"/>'; | ||
| 327 | + }else{ | ||
| 328 | + $logo = '<img src="'.$rootUrl.'/resources/graphics/ktlogo-topbar-right-transparent.png" class="primary" title="'.$appName.'" height="44" width="252"/>'; | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + $str = '<html> | ||
| 332 | + <body> | ||
| 333 | + <table border="1" cellpadding="5" width="100%" height="100"> | ||
| 334 | + <tr style="background-color:LightGrey"> | ||
| 335 | + <td> | ||
| 336 | + '.$logo.' | ||
| 337 | + </td> | ||
| 338 | + </tr> | ||
| 339 | + <tr> | ||
| 340 | + <td> | ||
| 341 | + '.$email.' | ||
| 342 | + </td> | ||
| 343 | + </tr> | ||
| 344 | + </table> | ||
| 345 | + </body> | ||
| 346 | + </html>'; | ||
| 347 | + return $str; | ||
| 348 | + } | ||
| 349 | +} | ||
| 350 | +?> | ||
| 297 | \ No newline at end of file | 351 | \ No newline at end of file |