📄 hspmailnotification.php
字号:
* Get employee email address * @return string array empEmail if not available return null */ public function getEmployeeAddress($empId) { $empEmail = null; $empInfo = new EmpInfo(); $empDetial = $empInfo -> filterEmpContact($empId); if(isset($empDetial[0][10])) { $empEmail = array($empDetial[0][10]); } if(isset($empDetial[0][11])) { $empEmail[] = $empDetial[0][11]; } return $empEmail; } /** * Get email notification address from EmailNotificationConfiguration using notification type * * @param int $emailNotificationTypeId * @return string array of email addresses */ public function _getNotificationAddress($emailNotificationTypeId) { $notificationAddresses = $this -> emailNotificationConfig -> fetchMailNotifications($emailNotificationTypeId); if (is_array($notificationAddresses)) {
return $notificationAddresses; //implode(', ', $notificationAddresses);
}else { return $notificationAddresses; } } /** * Get subject for hsp payment request. Get template from template path replace employee name * @param string $employee name of the employee * @return string $subject */ public function _getPaymentRequestSubject($employee) { $subjectTemp = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_REQUEST_NOTIFICATION_TEMPLATE_SUBJECT); return $this -> _getMailSubject($subjectTemp, $employee); } /** * */ public function _getPaymentAcceptSubject() { $subject = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_ACCEPT_NOTIFICATION_TEMPLATE_SUBJECT); $subject = preg_replace('/\n/', '', $subject); return trim($subject); } /** * */ public function _getPaymentDenySubject() { $subject = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_DENY_NOTIFICATION_TEMPLATE_SUBJECT); $subject = preg_replace('/\n/', '', $subject); return trim($subject); } /** * */ public function _getPaymentRequestDeleteSubject() { $subject = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_REQUEST_DELETE_NOTIFICATION_TEMPLATE_SUBJECT); $subject = preg_replace('/\n/', '', $subject); return trim($subject); } private function _getAdminHaltePlanSubject() { $subject = file_get_contents(ROOT_PATH . self::HSP_ADMIN_HALTE_PALN_NOTIFICATION_TEMPLATE_SUBJECT); $subject = preg_replace('/\n/', '', $subject); return trim($subject); } private function _getEssHaltePlanSubject() { $subject = file_get_contents(ROOT_PATH . self::HSP_ESS_HALTE_PALN_NOTIFICATION_TEMPLATE_SUBJECT); $subject = preg_replace('/\n/', '', $subject); return trim($subject); } /**
* Get the mail subject from given template
*
* @param string $template Mail subject template file
* @param string $employee The name of the employee
*
* @return string Mail subject from the given file, with parameters replaced
*/
private function _getMailSubject($template, $employee) {
$pattern = array('/#'. self::HSP_PAYMENT_REQUEST_NOTIFICATION_VARIABLE_EMPLOYEE.'/', '/\n/'); if (!isset($employee) || !strcmp($employee, '')) { $employee = 'Employee'; }
$replace = array($employee, "");
$subject = preg_replace($pattern, $replace, $template);
return trim($subject);
} /** * get email message body for the hsp payment request. * @param string $empName combine of first and last name * @param string $dateInquired * @param string $expenceDescription * @return string $msg body of the email msg */ public function _getPaymentRequestMsg($empName, $link) { $msgTemp = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_REQUEST_NOTIFICATION_TEMPLATE_MESSAGE); $pattern = array('/#'.self::HSP_PAYMENT_REQUEST_NOTIFICATION_VARIABLE_EMPLOYEE.'/', '/#'.self::HSP_PAYMENT_REQUEST_NOTIFICATION_VARIABLE_LINK.'/'); $replace = array($empName, $link); $msg = preg_replace($pattern, $replace, $msgTemp); return trim($msg, "\n \t\r"); } /** * get email message body for the hsp payment accpected by hr admin. * @param string $empName combine of first and last name * @param string $dateInquired * @param string $expenceDescription * @param string $personInquring * @param int amount * @param string paidDate * @return string $msg body of the email msg */ public function _getPaymentAcceptMsg($empName, $dateInquired, $expenseDescription, $personInquring, $amount, $paidDate, $link) { $msgTemp = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_ACCEPT_NOTIFICATION_TEMPLATE_MESSAGE); $pattern = array('/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_FIRSTNAME.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_DATEINQUIRED.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_EMPLOYEE.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_DESC.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_PERSONINQ.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_AMOUNT.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_PAIDDATE.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_LINK.'/'); $empNameAry = explode(' ', $empName); if(isset($empNameAry) && is_array($empNameAry)) { $firstName = $empNameAry[0]; }else { $firstName = $empName; } $replace = array($firstName, $dateInquired, $empName, $expenseDescription, $personInquring, $amount, $paidDate, $link); $msg = preg_replace($pattern, $replace, $msgTemp); return trim($msg, "\n \t\r"); } /** * get email message body for the hsp payment accpected by hr admin. * @param string $empName combine of first and last name * @param string $dateInquired * @param string $expenceDescription * @param string $personInquring * @param int amount * @param string paidDate * @return string $msg body of the email msg */ public function _getPaymentDenyMsg($empName, $dateInquired, $expenseDescription, $personInquring, $amount) { $msgTemp = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_DENY_NOTIFICATION_TEMPLATE_MESSAGE); $pattern = array('/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_FIRSTNAME.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_DATEINQUIRED.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_EMPLOYEE.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_DESC.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_PERSONINQ.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_AMOUNT.'/'); $empNameAry = explode(' ', $empName); if(isset($empNameAry) && is_array($empNameAry)) { $firstName = $empNameAry[0]; }else { $firstName = $empName; } $replace = array($firstName, $dateInquired, $empName, $expenseDescription, $personInquring, $amount); $msg = preg_replace($pattern, $replace, $msgTemp); return trim($msg, "\n \t\r"); } /** * get email message body for the hsp payment accpected by hr admin. * @param string $empName combine of first and last name * @param string $dateInquired * @param string $expenceDescription * @param string $personInquring * @param int amount * @param string paidDate * @return string $msg body of the email msg */ public function _getPaymentDeleteRequestMsg($empName, $dateInquired, $expenseDescription, $personInquring, $amount) { $msgTemp = file_get_contents(ROOT_PATH . self::HSP_PAYMENT_REQUEST_DELETE_NOTIFICATION_TEMPLATE_MESSAGE); $pattern = array('/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_FIRSTNAME.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_DATEINQUIRED.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_EMPLOYEE.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_DESC.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_PERSONINQ.'/', '/#'.self::HSP_PAYMENT_ACCPTE_NOTIFICATION_VARIABLE_AMOUNT.'/'); $empNameAry = explode(' ', $empName); if(isset($empNameAry) && is_array($empNameAry)) { $firstName = $empNameAry[0]; }else { $firstName = $empName; } $replace = array($firstName, $dateInquired, $empName, $expenseDescription, $personInquring, $amount); $msg = preg_replace($pattern, $replace, $msgTemp); return trim($msg, "\n \t\r"); } private function _getAdminHaltedPlanMsg($empName, $haltedDate) { $msgTemp = file_get_contents(ROOT_PATH . self::HSP_ADMIN_HALT_PLAN_NOTIFICATION_TEMPLATE_MESSAGE); $pattern = array('/#'.self::HSP_ADMIN_HALT_PLAN_NOTIFICATION_EMPLOYEE.'/', '/#'.self::HSP_ADMIN_HALT_PLAN_NOTIFICATION_HALTED_DATE.'/'); $empNameAry = explode(' ', $empName); if(isset($empNameAry) && is_array($empNameAry)) { $firstName = $empNameAry[0]; }else { $firstName = $empName; } $replace = array($firstName, $haltedDate); $msg = preg_replace($pattern, $replace, $msgTemp); return trim($msg, "\n \t\r"); } private function _getEssHaltedPlanMsg($empName, $haltedDate, $link) { $msgTemp = file_get_contents(ROOT_PATH . self::HSP_ESS_HALT_PLAN_NOTIFICATION_TEMPLATE_MESSAGE); $pattern = array('/#'.self::HSP_ESS_HALT_PLAN_NOTIFICATION_EMPLOYEE.'/', '/#'.self::HSP_ESS_HALT_PLAN_NOTIFICATION_HALTED_DATE.'/', '/#'.self::HSP_ESS_HALT_PLAN_NOTIFICATION_LINK.'/'); $replace = array($empName, $haltedDate, $link); $msg = preg_replace($pattern, $replace, $msgTemp); return trim($msg, "\n \t\r"); } /** * Send email * @param string $msg message body * @param string $subject * @param string array $to * @param String array $cc * @return boolean $success */ private function _sendEmail($msg, $subject, $to, $cc = null) { $mailer = $this->mailer; $mailType = $this -> mailType; $mailer -> setText($msg); $mailer -> setSubject($subject); $success = true; $logMessage = date('r')." Sending {$subject} to"; if (isset($to) && is_array($to)) { foreach($to as $toAdd) { $logMessage .= "\r\n".$toAdd; } }else if(isset($to) && !is_array($to)) { $to = array($to); $logMessage .= "\r\n".$to[0]; } if(isset($cc) && is_array($cc)) { $mailer -> setCc(implode(', ', $cc)); } if ((!is_array($to)) || (!@$mailer->send($to, $mailType))) {
$logMessage .= " - FAILED \r\nReason(s):"; $success = false; if (isset($mailer->errors)) {
$logMessage .= "\r\n\t*\t".implode("\r\n\t*\t",$mailer->errors); }
} else {
$logMessage .= " - SUCCEEDED";
} //$logPath = $this -> _getLogPath(); //error_log($logMessage."\r\n", 3, $logPath."notification_mails.log"); return $success; } /** * Get email log file path from email configuration * If not set return default log path * @return String $logPaath */ /*public function _getLogPath() { $logPath = $this -> emailConfig ->getLogPath(); if (!empty($logPath) && isset($logPath)) {
return $logPath;
} else {
return ROOT_PATH.'/lib/logs/';
} }*/}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -