+ add the feature of mail to bug module.
This commit is contained in:
@@ -57,6 +57,14 @@ class actionModel extends model
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/* 获得action信息。*/
|
||||
public function getById($actionID)
|
||||
{
|
||||
$action = $this->dao->findById((int)$actionID)->from(TABLE_ACTION)->fetch();
|
||||
$action->date = date('Y-m-d H:i:s', $action->date);
|
||||
return $action;
|
||||
}
|
||||
|
||||
/* 返回某一个action所对应的字段修改记录。*/
|
||||
public function getHistory($actionID)
|
||||
{
|
||||
|
||||
@@ -132,7 +132,8 @@ class bug extends control
|
||||
{
|
||||
$bugID = $this->bug->create();
|
||||
if(dao::isError()) die(js::error(dao::getError()));
|
||||
$this->action->create('bug', $bugID, 'Opened');
|
||||
$actionID = $this->action->create('bug', $bugID, 'Opened');
|
||||
$this->sendmail($bugID, $actionID);
|
||||
die(js::locate($this->createLink('bug', 'browse', "productID={$this->post->product}&type=byModule¶m={$this->post->module}"), 'parent'));
|
||||
}
|
||||
|
||||
@@ -196,6 +197,7 @@ class bug extends control
|
||||
if(!empty($files)) $fileAction = "Add Files " . join(',', $files) . "\n" ;
|
||||
$actionID = $this->action->create('bug', $bugID, $action, $fileAction . $this->post->comment);
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
$this->sendmail($bugID, $actionID);
|
||||
}
|
||||
die(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent'));
|
||||
}
|
||||
@@ -241,6 +243,7 @@ class bug extends control
|
||||
$this->bug->resolve($bugID);
|
||||
if(dao::isError()) die(js::error(dao::getError()));
|
||||
$actionID = $this->action->create('bug', $bugID, 'Resolved', $this->post->comment);
|
||||
$this->sendmail($bugID, $actionID);
|
||||
die(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent'));
|
||||
}
|
||||
|
||||
@@ -268,7 +271,8 @@ class bug extends control
|
||||
if(dao::isError()) die(js::error(dao::getError()));
|
||||
$this->loadModel('file');
|
||||
$files = $this->file->saveUpload('files', 'bug', $bugID);
|
||||
$this->action->create('bug', $bugID, 'Activated', $this->post->comment);
|
||||
$actionID = $this->action->create('bug', $bugID, 'Activated', $this->post->comment);
|
||||
$this->sendmail($bugID, $actionID);
|
||||
die(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent'));
|
||||
}
|
||||
|
||||
@@ -296,7 +300,8 @@ class bug extends control
|
||||
{
|
||||
$this->bug->close($bugID);
|
||||
if(dao::isError()) die(js::error(dao::getError()));
|
||||
$this->action->create('bug', $bugID, 'Closed', $this->post->comment);
|
||||
$actionID = $this->action->create('bug', $bugID, 'Closed', $this->post->comment);
|
||||
$this->sendmail($bugID, $actionID);
|
||||
die(js::locate($this->createLink('bug', 'view', "bugID=$bugID"), 'parent'));
|
||||
}
|
||||
|
||||
@@ -321,4 +326,47 @@ class bug extends control
|
||||
$bugs = $this->bug->getUserBugPairs($account);
|
||||
die(html::select('bug', $bugs, '', 'class=select-1'));
|
||||
}
|
||||
|
||||
/* 发送变量。*/
|
||||
private function sendmail($bugID, $actionID)
|
||||
{
|
||||
/* 设定toList和ccList。*/
|
||||
$bug = $this->bug->getByID($bugID);
|
||||
$toList = $bug->assignedTo;
|
||||
$ccList = trim($bug->mailto, ',');
|
||||
if($toList == '')
|
||||
{
|
||||
if($ccList == '') return;
|
||||
if(strpos($ccList, ',') === false)
|
||||
{
|
||||
$toList = $ccList;
|
||||
$ccList = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$commaPos = strpos($ccList, ',');
|
||||
$toList = substr($ccList, 0, $commaPos);
|
||||
$ccList = substr($ccList, $commaPos + 1);
|
||||
}
|
||||
}
|
||||
elseif(strtolower($toList) == 'closed')
|
||||
{
|
||||
$toList = $bug->resolvedBy;
|
||||
}
|
||||
|
||||
/* 获得action信息。*/
|
||||
$action = $this->action->getById($actionID);
|
||||
$histories = $this->action->getHistory($actionID);
|
||||
if(strtolower($action->action) == 'opened') $action->comment = $bug->steps;
|
||||
|
||||
/* 赋值,获得邮件内容。*/
|
||||
$this->assign('bug', $bug);
|
||||
$this->assign('action', $action);
|
||||
$this->assign('histories', $histories);
|
||||
$mailContent = $this->fetch($this->moduleName, 'sendmail');
|
||||
|
||||
/* 发信。*/
|
||||
$this->loadModel('mail')->send($toList, 'BUG #' . $bug->id . $this->lang->colon . $bug->title, $mailContent, $ccList);
|
||||
if($this->mail->isError()) echo js::error($this->mail->getError());
|
||||
}
|
||||
}
|
||||
|
||||
34
trunk/module/bug/view/sendmail.html.php
Normal file
34
trunk/module/bug/view/sendmail.html.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* The mail file of bug module of ZenTaoMS.
|
||||
*
|
||||
* ZenTaoMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ZenTaoMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @copyright Copyright: 2009 Chunsheng Wang
|
||||
* @author Chunsheng Wang <wwccss@263.net>
|
||||
* @package bug
|
||||
* @version $Id$
|
||||
* @link http://www.zentao.cn
|
||||
*/
|
||||
?>
|
||||
<table width='98%' align='center'>
|
||||
<tr class='header'>
|
||||
<td>
|
||||
BUG #<?php echo $bug->id . "=>$bug->assignedTo " . html::a(common::getSysURL() . $this->createLink('bug', 'view', "bugID=$bug->id"), $bug->title);?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><?php include '../../common/mail.html.php';?></td>
|
||||
</tr>
|
||||
</table>
|
||||
30
trunk/module/common/mail.html.php
Normal file
30
trunk/module/common/mail.html.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<span><?php echo "$action->date, <strong>$action->action</strong> by <strong>$action->actor</strong>"; ?></span>
|
||||
<?php if(!empty($action->comment) or !empty($histories)):?>
|
||||
<div class='history'>
|
||||
<?php
|
||||
if(!empty($histories))
|
||||
{
|
||||
foreach($histories[$action->id] as $history)
|
||||
{
|
||||
if($history->diff != '')
|
||||
{
|
||||
echo "CHANGE <strong>$history->field</strong>, the diff is: <blockquote>" . nl2br($history->diff) . "</blockquote>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "CHANGE <strong>$history->field</strong> FROM '$history->old' TO '$history->new' . <br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo nl2br($action->comment);
|
||||
?>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
<style>
|
||||
del {background:#fcc}
|
||||
ins {background:#cfc; text-decoration:none}
|
||||
table, tr, th, td {border:1px solid gray; font-size:12px; border-collapse:collapse}
|
||||
tr, th, td {padding:5px}
|
||||
.history {border:1px solid gray; padding:10px; margin-top:10px; margin-bottom:10px}
|
||||
.header {background:#efefef}
|
||||
</style>
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
/* 是否打开邮件功能。*/
|
||||
$config->mail->trunon = false;
|
||||
|
||||
/* 设置发件人地址和名称。*/
|
||||
$config->mail->fromAddress = ''; // 发件人地址。
|
||||
$config->mail->fromName = ''; // 发件人名称。
|
||||
$config->mail->fromAddress = ''; // 发件人地址。
|
||||
$config->mail->fromName = ''; // 发件人名称。
|
||||
|
||||
/* 设置发信方式,目前支持mail|sendmail|smtp|gmail。*/
|
||||
$config->mail->mta = 'gmail';
|
||||
|
||||
@@ -28,6 +28,7 @@ class mailModel extends model
|
||||
private static $instance;
|
||||
private $mta;
|
||||
private $mtaType;
|
||||
private $errors = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -41,33 +42,12 @@ class mailModel extends model
|
||||
{
|
||||
if(self::$instance == null) self::$instance = new phpmailer(true);
|
||||
$this->mta = self::$instance;
|
||||
$this->mta->CharSet = $this->config->encoding;
|
||||
$funcName = "set{$this->config->mail->mta}";
|
||||
if(!method_exists($this, $funcName)) echo $this->app->error("The MTA {$this->config->mail->mta} not supported now.", __FILE__, __LINE__, $exit = false);
|
||||
$this->$funcName();
|
||||
}
|
||||
|
||||
/* 发送邮件。*/
|
||||
public function send($subject, $body, $toList, $ccList)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->mta->setFrom($this->config->mail->fromAddress, $this->config->mail->fromName);
|
||||
$this->setSubject($subject);
|
||||
$this->setTO($toList);
|
||||
$this->setCC($ccList);
|
||||
$this->setBody($body);
|
||||
$this->mta->send();
|
||||
}
|
||||
catch (phpmailerException $e)
|
||||
{
|
||||
echo $e->errorMessage();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/* SMTP方式。*/
|
||||
private function setSMTP()
|
||||
{
|
||||
@@ -105,17 +85,57 @@ class mailModel extends model
|
||||
$this->mta->Password = $this->config->mail->gmail->password;
|
||||
}
|
||||
|
||||
/* 设置发送地址。*/
|
||||
private function setTO($toList)
|
||||
/* 发送邮件。*/
|
||||
public function send($toList, $subject, $body = '', $ccList = '')
|
||||
{
|
||||
foreach($toList as $toName => $toAddress) $this->mta->addAddress($toAddress, $toName);
|
||||
if(!$this->config->mail->turnon) return;
|
||||
|
||||
/* 获得用户的真实姓名和email列表。*/
|
||||
$this->loadModel('user');
|
||||
$emails = $this->user->getRealNameAndEmails(str_replace(' ', '', $toList . ',' . $ccList));
|
||||
|
||||
try
|
||||
{
|
||||
$this->mta->setFrom($this->config->mail->fromAddress, $this->config->mail->fromName);
|
||||
$this->setSubject($subject);
|
||||
$this->setTO($toList, $emails);
|
||||
$this->setCC($ccList, $emails);
|
||||
$this->setBody($body);
|
||||
$this->mta->send();
|
||||
}
|
||||
catch (phpmailerException $e)
|
||||
{
|
||||
$this->errors[] = trim(strip_tags($e->errorMessage()));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->errors[] = trim(strip_tags($e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/* 设置发送地址。*/
|
||||
private function setTO($toList, $emails)
|
||||
{
|
||||
$toList = explode(',', str_replace(' ', '', $toList));
|
||||
foreach($toList as $account)
|
||||
{
|
||||
if(!isset($emails[$account]) or isset($emails[$account]->sended) or strpos($emails[$account]->email, '@') == false) continue;
|
||||
$this->mta->addAddress($emails[$account]->email, $emails[$account]->realname);
|
||||
$emails[$account]->sended = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* 设置抄送地址。*/
|
||||
private function setCC($ccList)
|
||||
private function setCC($ccList, $emails)
|
||||
{
|
||||
$ccList = explode(',', str_replace(' ', '', $ccList));
|
||||
if(!is_array($ccList)) return;
|
||||
foreach($ccList as $ccName => $ccAddress) $this->mta->addCC($ccAddress, $ccName);
|
||||
foreach($ccList as $account)
|
||||
{
|
||||
if(!isset($emails[$account]) or isset($emails[$account]->sended) or strpos($emails[$account]->email, '@') == false) continue;
|
||||
$this->mta->addCC($emails[$account]->email, $emails[$account]->realname);
|
||||
$emails[$account]->sended = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* 设置主题。*/
|
||||
@@ -127,7 +147,7 @@ class mailModel extends model
|
||||
/* 设置body。*/
|
||||
private function setBody($body)
|
||||
{
|
||||
$this->mta->msgHtml($body);
|
||||
$this->mta->msgHtml("$body");
|
||||
}
|
||||
|
||||
/* 清楚地址和附件。*/
|
||||
@@ -136,4 +156,18 @@ class mailModel extends model
|
||||
$this->mta->clearAddresses();
|
||||
$this->mta->cearAttachments();
|
||||
}
|
||||
|
||||
/* 判断是否有错!*/
|
||||
public function isError()
|
||||
{
|
||||
return !empty($this->errors);
|
||||
}
|
||||
|
||||
/* 获得错误。*/
|
||||
public function getError()
|
||||
{
|
||||
$errors = $this->errors;
|
||||
$this->errors = array();
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user