Commit e436bae2751c2b8a92104149ecd23d84e5fd9dca

Authored by Kevin Cyster
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 8 * Document Management Made Simple
9 9 * Copyright (C) 2008, 2009 KnowledgeTree Inc.
10 10 * Portions copyright The Jam Warehouse Software (Pty) Limited
11   - *
  11 + *
12 12 * This program is free software; you can redistribute it and/or modify it under
13 13 * the terms of the GNU General Public License version 3 as published by the
14 14 * Free Software Foundation.
15   - *
  15 + *
16 16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 19 * details.
20   - *
  20 + *
21 21 * You should have received a copy of the GNU General Public License
22 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 25 * California 94120-7775, or email info@knowledgetree.com.
26   - *
  26 + *
27 27 * The interactive user interfaces in modified source and object code versions
28 28 * of this program must display Appropriate Legal Notices, as required under
29 29 * Section 5 of the GNU General Public License version 3.
30   - *
  30 + *
31 31 * In accordance with Section 7(b) of the GNU General Public License version 3,
32 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 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 36 * copyright notice.
37 37 * Contributor( s): ______________________________________
38 38 */
... ... @@ -49,7 +49,7 @@ class Email {
49 49 * with default system information
50 50 *
51 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 54 function Email($sFromEmail = "", $sFromName = "") {
55 55 global $default;
... ... @@ -66,8 +66,8 @@ class Email {
66 66 $this->oMailer->IsHTML(true);
67 67 $this->oMailer->SetLanguage('en', KT_DIR . '/thirdparty/phpmailer/language/');
68 68 $this->bEmailDisabled = false;
69   -
70   - $oConfig =& KTConfig::getSingleton();
  69 +
  70 + $oConfig =& KTConfig::getSingleton();
71 71 $sEmailServer = $oConfig->get('email/emailServer');
72 72 if ($sEmailServer == 'none') {
73 73 $this->bEmailDisabled = true;
... ... @@ -90,7 +90,7 @@ class Email {
90 90 $this->oMailer->Password = $sEmailPass;
91 91 }
92 92 }
93   -
  93 +
94 94 /**
95 95 * Sends an email to a specified recipient.
96 96 *
... ... @@ -98,7 +98,7 @@ class Email {
98 98 * @param string the subject of the email
99 99 * @param string the body of the email
100 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 102 * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"]
103 103 */
104 104 function send($mToEmail, $sSubject, $sBody) {
... ... @@ -106,9 +106,9 @@ class Email {
106 106 return PEAR::raiseError(_kt("Email is not configured."));
107 107 }
108 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 113 $aEmailAddresses = array();
114 114 // just one email address, add it
... ... @@ -118,7 +118,7 @@ class Email {
118 118 // if we're passed an array, then use it
119 119 if (is_array($mToEmail)) {
120 120 $aEmailAddresses = $mToEmail;
121   - // if there are multiple addresses (; separated), explode it
  121 + // if there are multiple addresses (; separated), explode it
122 122 } elseif (strpos($mToEmail, ";") > 0) {
123 123 $aEmailAddresses = explode(";", $mToEmail);
124 124 }
... ... @@ -128,9 +128,11 @@ class Email {
128 128 }
129 129 }
130 130  
  131 + $body = $this->makeEmailTemplate(stripslashes($sBody));
131 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 136 //send the email
135 137 if(!$this->oMailer->Send()) {
136 138 $default->log->error("Error sending mail to $mToEmail; mailer error code=" . $this->oMailer->ErrorInfo);
... ... @@ -160,9 +162,9 @@ class Email {
160 162 return PEAR::raiseError(_kt("Email is not configured."));
161 163 }
162 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 169 // just one email address, add it
168 170 if (is_string($mToEmail) && (strpos($mToEmail, ";") === false)) {
... ... @@ -172,7 +174,7 @@ class Email {
172 174 // if we're passed an array, then use it
173 175 if (is_array($mToEmail)) {
174 176 $aEmailAddresses = $mToEmail;
175   - // if there are multiple addresses (; separated), explode it
  177 + // if there are multiple addresses (; separated), explode it
176 178 } elseif (strpos($mToEmail, ";") > 0) {
177 179 $aEmailAddresses = explode(";", $mToEmail);
178 180 }
... ... @@ -182,10 +184,12 @@ class Email {
182 184 }
183 185 }
184 186  
  187 + $body = $this->makeEmailTemplate(stripslashes($sBody));
185 188 $this->oMailer->Subject = stripslashes($sSubject);
186   - $this->oMailer->Body = stripslashes($sBody);
  189 +// $this->oMailer->Body = stripslashes($sBody);
  190 + $this->oMailer->Body = $body;
187 191 $this->oMailer->AddAttachment($sDocumentPath, $sDocumentName);
188   -
  192 +
189 193 //send the email
190 194 if(!$this->oMailer->Send()) {
191 195 $default->log->error("Error sending mail to $mToEmail; mailer error code=" . $this->oMailer->ErrorInfo);
... ... @@ -211,7 +215,7 @@ class Email {
211 215 * @param The hyperlink that should be sent
212 216 *
213 217 * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"]
214   - *
  218 + *
215 219 * @todo check for special characters (including encoding the link correctly???)
216 220 * @todo need to test this on multiple mail clients, not just Outlook
217 221 */
... ... @@ -221,12 +225,15 @@ class Email {
221 225 }
222 226 global $default;
223 227  
  228 + $body = $this->makeEmailTemplate(stripslashes($EmailBody).'<br /><br />'.$hyperlink);
  229 +
224 230 //get info from relevant fields.
225 231 $this->oMailer->From = $FromEmail;
226 232 $this->oMailer->FromName = $FromName;
227 233 $this->oMailer->AddAddress($ToEmail);
228 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 238 //send the email
232 239 if(!$this->oMailer->Send()) {
... ... @@ -236,7 +243,7 @@ class Email {
236 243 return true;
237 244 }
238 245 /**
239   - * Sends an email ment for administration,
  246 + * Sends an email ment for administration,
240 247 *
241 248 * @param The sender's email address
242 249 * @param The sender's Name
... ... @@ -246,7 +253,7 @@ class Email {
246 253 * @param The hyperlink that should be sent
247 254 *
248 255 * @return boolean true on email successfully sent, false otherwise and set $_SESSION["errorMessage"]
249   - *
  256 + *
250 257 * @todo check for special characters (including encoding the link correctly???)
251 258 * @todo need to test this on multiple mail clients, not just Outlook
252 259 */
... ... @@ -256,12 +263,15 @@ class Email {
256 263 }
257 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 268 //get info from relevant fields.
260 269 $this->oMailer->From = $FromEmail;
261 270 $this->oMailer->FromName = $FromName;
262 271 $this->oMailer->AddAddress($ToEmail);
263 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 276 //send the email
267 277 if(!$this->oMailer->Send()) {
... ... @@ -277,12 +287,14 @@ class Email {
277 287 }
278 288 global $default;
279 289  
  290 + $body = $this->makeEmailTemplate(stripslashes($EmailBody));
  291 +
280 292 //get info from relevant fields.
281 293 $this->oMailer->From = $FromEmail;
282 294 $this->oMailer->FromName = $FromName;
283 295 $this->oMailer->AddAddress($ToEmail);
284 296 $this->oMailer->Subject = stripslashes($Subj);
285   - $this->oMailer->Body = stripslashes($EmailBody);
  297 + $this->oMailer->Body = $body;
286 298  
287 299 //send the email
288 300 if(!$this->oMailer->Send()) {
... ... @@ -291,6 +303,48 @@ class Email {
291 303 }
292 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 351 \ No newline at end of file
... ...