* complete task 223:send email to users when task has changed.

This commit is contained in:
fujia
2010-06-21 06:51:15 +00:00
parent b7430dd89b
commit 73e47e10a4
7 changed files with 111 additions and 4 deletions

View File

@@ -45,7 +45,8 @@ class task extends control
$taskID = $this->task->create($projectID);
if(dao::isError()) die(js::error(dao::getError()));
$this->loadModel('action');
$this->action->create('task', $taskID, 'Opened', '');
$actionID = $this->action->create('task', $taskID, 'Opened', '');
$this->sendmail($taskID, $actionID);
if($this->post->after == 'continueAdding')
{
echo js::alert($this->lang->task->successSaved . $this->lang->task->afterChoices['continueAdding']);
@@ -74,16 +75,17 @@ class task extends control
$this->assign('stories', $stories);
$this->assign('storyID', $storyID);
$this->assign('members', $members);
$this->assign('users', $this->loadModel('user')->getPairs('noletter'));
$this->display();
}
/* 公共的操作。*/
public function commonAction($taskID)
{
$this->view->task = $this->task->getById($taskID);
$this->view->task = $this->task->getByID($taskID);
$this->view->project = $this->project->getById($this->view->task->project);
$this->view->members = $this->project->getTeamMemberPairs($this->view->project->id);
$this->view->users = $this->view->members;
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->actions = $this->loadModel('action')->getList('task', $taskID);
/* 设置菜单。*/
@@ -112,6 +114,7 @@ class task extends control
if(!empty($files)) $fileAction = $this->lang->addFiles . join(',', $files) . "\n" ;
$actionID = $this->action->create('task', $taskID, $action, $fileAction . $this->post->comment);
$this->action->logHistory($actionID, $changes);
$this->sendmail($taskID, $actionID);
}
die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent'));
}
@@ -144,6 +147,7 @@ class task extends control
if(!empty($files)) $fileAction = $this->lang->addFiles . join(',', $files) . "\n" ;
$actionID = $this->action->create('task', $taskID, $action, $fileAction . $this->post->comment);
$this->action->logHistory($actionID, $changes);
$this->sendmail($taskID, $actionID);
}
die(js::locate($this->createLink('task', 'view', "taskID=$taskID"), 'parent'));
}
@@ -207,6 +211,45 @@ class task extends control
}
}
/* 发送邮件。*/
private function sendmail($taskID, $actionID)
{
/* 设定toList和ccList。*/
$task = $this->task->getByID($taskID);
$toList = $task->owner;
$ccList = trim($task->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);
}
}
/* 获得action信息。*/
$action = $this->action->getById($actionID);
$history = $this->action->getHistory($actionID);
$action->history = isset($history[$actionID]) ? $history[$actionID] : array();
/* 赋值,获得邮件内容。*/
$this->assign('task', $task);
$this->assign('action', $action);
$mailContent = $this->parse($this->moduleName, 'sendmail');
/* 发信。*/
$this->loadModel('mail')->send($toList, 'TASK#' . $task->id . $this->lang->colon . $task->name, $mailContent, $ccList);
if($this->mail->isError()) echo js::error($this->mail->getError());
}
/* Ajax请求 返回用户任务的下拉列表框。*/
public function ajaxGetUserTasks($account = '', $status = 'wait,doing')
{

View File

@@ -42,6 +42,7 @@ $lang->task->name = '任务名称';
$lang->task->type = '任务类型';
$lang->task->pri = '优先级';
$lang->task->owner = '指派给';
$lang->task->mailto = '抄送给';
$lang->task->estimate = '最初预计';
$lang->task->estimateAB = '预计';
$lang->task->left = '预计剩余';

View File

@@ -97,6 +97,13 @@ class taskModel extends model
->where('t1.id')->eq((int)$taskID)
->fetch();
if(!$task) return false;
if($task->mailto)
{
$task->mailto = ltrim(trim($task->mailto), ','); // 去掉开始的,。
$task->mailto = str_replace(' ', '', $task->mailto);
$task->mailto = rtrim($task->mailto, ',') . ',';
$task->mailto = str_replace(',', ', ', $task->mailto);
}
$task->files = $this->loadModel('file')->getByObject('task', $taskID);
return $this->processTask($task);
}

View File

@@ -32,7 +32,11 @@ function copyStoryTitle()
storyTitle = storyTitle.substr(storyTitle.lastIndexOf(':')+ 1);
$('#name').attr('value', storyTitle);
}
function sendMailTo()
{
var userList = "<?php echo join(',', array_keys($users));?>".split(',');
$("#mailto").autocomplete(userList, { multiple: true, mustMatch: true});
}
/* 设置预览的链接。*/
function setPreview()
{
@@ -84,6 +88,10 @@ $(document).ready(function()
<th class='rowhead'><?php echo $lang->task->owner;?></th>
<td><?php echo html::select('owner', $members, '', 'class=select-3');?>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->task->mailto;?></th>
<td> <?php echo html::input('mailto', '', 'class=text-1');?> </td>
</tr>
<tr>
<th class='rowhead'><?php echo $lang->task->story;?></th>
<td>

View File

@@ -24,6 +24,12 @@
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/datepicker.html.php';?>
<script language='Javascript'>
var userList = "<?php echo join(',', array_keys($users));?>".split(',');
$(function() {
$("#mailto").autocomplete(userList, { multiple: true, mustMatch: true});
})
</script>
<form method='post' enctype='multipart/form-data' target='hiddenwin'>
<div class='yui-d0'>
<div id='titlebar'>
@@ -83,6 +89,10 @@
<th class='rowhead'><?php echo $lang->task->pri;?></th>
<td><?php echo html::select('pri', $lang->task->priList, $task->pri, 'class=select-1');?>
</tr>
<tr>
<td class='rowhead'><?php echo $lang->task->mailto;?></td>
<td><?php echo html::input('mailto', $task->mailto, 'class="text-1"');?></td>
</tr>
</table>
</fieldset>
<fieldset>

View File

@@ -0,0 +1,34 @@
<?php
/**
* The mail file of task 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-2010 青岛易软天创网络科技有限公司(www.cnezsoft.com)
* @author Jia Fu <fujia@cnezsoft.com>
* @package task
* @version $Id: sendmail.html.php 867 2010-06-17 09:32:58Z yuren_@126.com $
* @link http://www.zentaoms.com
*/
?>
<table width='98%' align='center'>
<tr class='header'>
<td>
TASK #<?php echo $task->id . "=>$task->owner " . html::a(common::getSysURL() . $this->createLink('task', 'view', "taskID=$task->id"), $task->name);?>
</td>
</tr>
<tr>
<td><?php include '../../common/view/mail.html.php';?></td>
</tr>
</table>

View File

@@ -111,6 +111,10 @@
<th class='rowhead'><?php echo $lang->task->pri;?></th>
<td><?php $lang->show($lang->task->priList, $task->pri);?></td>
</tr>
<tr>
<td class='rowhead w-p20'><?php echo $lang->task->mailto;?></td>
<td><?php $mailto = explode(',', str_replace(' ', '', $task->mailto)); foreach($mailto as $account) echo ' ' . $users[$account]; ?></td>
</tr>
</table>
</fieldset>
<fieldset>