2010-11-30 12:23:46 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of notifation system using email
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package LetoDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Include parent class
|
|
|
|
*/
|
2010-11-12 22:47:41 +00:00
|
|
|
require_once("inc.ClassNotify.php");
|
|
|
|
|
2010-11-30 12:23:46 +00:00
|
|
|
/**
|
|
|
|
* Class to send email notifications to individuals or groups
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package LetoDMS
|
|
|
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class LetoDMS_Email extends LetoDMS_Notify {
|
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
function toIndividual($sender, $recipient, $subject, $message) {
|
|
|
|
|
|
|
|
global $settings;
|
|
|
|
if ($settings->_enableEmail==FALSE) return 0;
|
|
|
|
|
2010-11-30 12:23:46 +00:00
|
|
|
if ($recipient->getEmail()=="") return 0;
|
|
|
|
|
2011-01-20 08:18:37 +00:00
|
|
|
if ((!is_object($sender) && strcasecmp(get_class($sender), "LetoDMS_Core_User")) ||
|
|
|
|
(!is_object($recipient) && strcasecmp(get_class($recipient), "LetoDMS_Core_User"))) {
|
2010-11-30 12:23:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = "From: ". $sender->getFullName() ." <". $sender->getEmail() .">\r\n" .
|
2010-10-29 13:19:51 +00:00
|
|
|
"Reply-To: ". $sender->getFullName() ." <". $sender->getEmail() .">\r\n";
|
|
|
|
|
|
|
|
$message = getMLText("email_header")."\r\n\r\n".$message;
|
2010-11-30 12:23:46 +00:00
|
|
|
$message .= "\r\n\r\n".getMLText("email_footer");
|
|
|
|
|
|
|
|
return (mail($recipient->getEmail(), $this->replaceMarker($subject), $this->replaceMarker($message), $header) ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
function toGroup($sender, $groupRecipient, $subject, $message) {
|
|
|
|
|
|
|
|
global $settings;
|
2010-11-30 12:23:46 +00:00
|
|
|
if (!$settings->_enableEmail) return 0;
|
|
|
|
|
2011-01-20 08:18:37 +00:00
|
|
|
if ((!is_object($sender) && strcasecmp(get_class($sender), "LetoDMS_Core_User")) ||
|
|
|
|
(!is_object($groupRecipient) && strcasecmp(get_class($groupRecipient), "LetoDMS_Core_Group"))) {
|
2010-11-30 12:23:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = "From: ". $sender->getFullName() ." <". $sender->getEmail() .">\r\n" .
|
|
|
|
"Reply-To: ". $sender->getFullName() ." <". $sender->getEmail() .">\r\n";
|
|
|
|
|
|
|
|
$toList = "";
|
2010-10-29 13:19:51 +00:00
|
|
|
foreach ($groupRecipient->getUsers() as $recipient) {
|
|
|
|
|
2010-11-30 12:23:46 +00:00
|
|
|
if ($recipient->getEmail()!="")
|
|
|
|
$toList .= (strlen($toList)==0 ? "" : ", ") . $recipient->getEmail();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($toList)==0) {
|
|
|
|
return -1;
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
2010-11-30 12:23:46 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$message = getMLText("email_header")."\r\n\r\n".$message;
|
2010-11-30 12:23:46 +00:00
|
|
|
$message .= "\r\n\r\n".getMLText("email_footer");
|
|
|
|
|
|
|
|
return (mail($toList, parent::replaceMarker($subject), parent::replaceMarker($message), $header) ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
function toList($sender, $recipients, $subject, $message) {
|
|
|
|
|
|
|
|
global $settings;
|
2010-11-30 12:23:46 +00:00
|
|
|
if (!$settings->_enableEmail) return 0;
|
|
|
|
|
2011-01-20 08:18:37 +00:00
|
|
|
if ((!is_object($sender) && strcasecmp(get_class($sender), "LetoDMS_Core_User")) ||
|
2010-11-30 12:23:46 +00:00
|
|
|
(!is_array($recipients) && count($recipients)==0)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = "From: ". $sender->getFullName() ." <". $sender->getEmail() .">\r\n" .
|
|
|
|
"Reply-To: ". $sender->getFullName() ." <". $sender->getEmail() .">\r\n";
|
|
|
|
|
|
|
|
$toList = "";
|
|
|
|
foreach ($recipients as $recipient) {
|
2011-01-20 08:18:37 +00:00
|
|
|
if (is_object($recipient) && !strcasecmp(get_class($recipient), "LetoDMS_Core_User")) {
|
2010-10-29 13:19:51 +00:00
|
|
|
|
2010-11-30 12:23:46 +00:00
|
|
|
if ($recipient->getEmail()!="")
|
|
|
|
$toList .= (strlen($toList)==0 ? "" : ", ") . $recipient->getEmail();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($toList)==0) {
|
|
|
|
return -1;
|
2010-10-29 13:19:51 +00:00
|
|
|
}
|
2010-11-30 12:23:46 +00:00
|
|
|
|
2010-10-29 13:19:51 +00:00
|
|
|
$message = getMLText("email_header")."\r\n\r\n".$message;
|
2010-11-30 12:23:46 +00:00
|
|
|
$message .= "\r\n\r\n".getMLText("email_footer");
|
|
|
|
|
|
|
|
return (mail($toList, $this->replaceMarker($subject), $this->replaceMarker($message), $header) ? 0 : -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|