createLink('todo', 'batchEdit', "from=myTodo&type=$type&account=$account&status=$status");
+ echo html::commonButton($lang->todo->batchEdit, "onclick=\"changeAction('todoform', 'batchEdit', '$actionLink')\"");
+
+ }
+ if(common::hasPriv('todo', 'import2Today') and $importFuture)
+ {
$actionLink = $this->createLink('todo', 'import2Today');
echo html::commonButton($lang->todo->import2Today, "onclick=\"changeAction('todoform', 'import2Today', '$actionLink')\"");
}
diff --git a/module/todo/control.php b/module/todo/control.php
index c20b6cf3ec..f4baba9a9b 100644
--- a/module/todo/control.php
+++ b/module/todo/control.php
@@ -125,6 +125,89 @@ class todo extends control
$this->display();
}
+ /**
+ * Batch edit todo.
+ *
+ * @param string $from example:myTodo, todoBatchEdit.
+ * @param string $type
+ * @param string $account
+ * @param string $status
+ * @access public
+ * @return void
+ */
+ public function batchEdit($from = '', $type = 'today', $account = '', $status = 'all')
+ {
+ /* Get form data for my-todo. */
+ if($from == 'myTodo')
+ {
+ /* Initialize vars. */
+ $editedTodos = array();
+ $todoIDList = array();
+ $columns = 7;
+ $showSuhosinInfo = false;
+
+ if($account == '') $account = $this->app->user->account;
+ $bugs = $this->bug->getUserBugPairs($account);
+ $tasks = $this->task->getUserTaskPairs($account, $status);
+ $allTodos = $this->todo->getList($type, $account, $status);
+ if($this->post->todoIDList) $todoIDList = $this->post->todoIDList;
+
+ /* Initialize todos whose need to edited. */
+ foreach($allTodos as $todo)
+ {
+ if(in_array($todo->id, $todoIDList))
+ {
+ $editedTodos[$todo->id] = $todo;
+ }
+ }
+ foreach($editedTodos as $todo)
+ {
+ if($todo->type == 'task') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name');
+ if($todo->type == 'bug') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_BUG)->fetch('title');
+ $todo->date = str_replace('-', '', $todo->date);
+ $todo->begin = str_replace(':', '', $todo->begin);
+ $todo->end = str_replace(':', '', $todo->end);
+ }
+
+ /* Judge whether the edited todos is too large. */
+ $showSuhosinInfo = $this->loadModel('common')->judgeSuhosinSetting(count($editedTodos), $columns);
+
+ /* Set the sessions. */
+ $this->app->session->set('showSuhosinInfo', $showSuhosinInfo);
+
+ /* Assign. */
+ $header['title'] = $this->lang->my->common . $this->lang->colon . $this->lang->todo->batchEdit;
+ $position[] = $this->lang->todo->common;
+ $position[] = $this->lang->todo->batchEdit;
+
+ if($showSuhosinInfo) $this->view->suhosinInfo = $this->lang->suhosinInfo;
+ $this->view->bugs = $bugs;
+ $this->view->tasks = $tasks;
+ $this->view->editedTodos = $editedTodos;
+ $this->view->times = $this->todo->buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta);
+ $this->view->time = $this->todo->now();
+ $this->view->header = $header;
+ $this->view->position = $position;
+
+ $this->display();
+ }
+ /* Get form data from todo-batchEdit. */
+ elseif($from == 'todoBatchEdit')
+ {
+ $allChanges = $this->todo->batchUpdate();
+ foreach($allChanges as $todoID => $changes)
+ {
+ if(!empty($changes))
+ {
+ $actionID = $this->loadModel('action')->create('todo', $todoID, 'edited');
+ $this->action->logHistory($actionID, $changes);
+ }
+ }
+
+ die(js::locate($this->session->todoList, 'parent'));
+ }
+ }
+
/**
* View a todo.
*
diff --git a/module/todo/lang/en.php b/module/todo/lang/en.php
index d3ae3159a3..d21311fa7d 100644
--- a/module/todo/lang/en.php
+++ b/module/todo/lang/en.php
@@ -14,6 +14,7 @@ $lang->todo->index = "Index";
$lang->todo->create = "Create";
$lang->todo->batchCreate = "Batch create";
$lang->todo->edit = "Edit";
+$lang->todo->batchEdit = "Batch edit";
$lang->todo->view = "Info";
$lang->todo->viewAB = "Info";
$lang->todo->markDone = "Undone";
diff --git a/module/todo/lang/zh-cn.php b/module/todo/lang/zh-cn.php
index 4957b27040..5be58b2a8f 100644
--- a/module/todo/lang/zh-cn.php
+++ b/module/todo/lang/zh-cn.php
@@ -14,6 +14,7 @@ $lang->todo->index = "todo一览";
$lang->todo->create = "新增";
$lang->todo->batchCreate = "批量添加";
$lang->todo->edit = "更新TODO";
+$lang->todo->batchEdit = "批量编辑";
$lang->todo->view = "TODO详情";
$lang->todo->viewAB = "详情";
$lang->todo->markDone = "未完成";
diff --git a/module/todo/model.php b/module/todo/model.php
index b61372f198..283065b3e1 100644
--- a/module/todo/model.php
+++ b/module/todo/model.php
@@ -127,6 +127,65 @@ class todoModel extends model
if(!dao::isError()) return common::createChanges($oldTodo, $todo);
}
+ /**
+ * Batch update todos.
+ *
+ * @access public
+ * @return array
+ */
+ public function batchUpdate()
+ {
+ $todos = array();
+ $allChanges = array();
+ $todoIDList = $this->post->todoIDList ? $this->post->todoIDList : array();
+
+ /* Adjust whether the post data is complete, if not, remove the last element of $todoIDList. */
+ if($this->session->showSuhosinInfo) array_pop($taskIDList);
+
+ if(!empty($todoIDList))
+ {
+ /* Initialize todos from the post data. */
+ foreach($todoIDList as $todoID)
+ {
+ $todo->date = $this->post->dates[$todoID];
+ $todo->type = $this->post->types[$todoID];
+ $todo->pri = $this->post->pris[$todoID];
+ $todo->name = $todo->type == 'custom' ? htmlspecialchars($this->post->names[$todoID]) : '';
+ $todo->begin = $this->post->begins[$todoID];
+ $todo->end = $this->post->ends[$todoID];
+ if($todo->type == 'task') $todo->idvalue = isset($this->post->tasks[$todoID]) ? $this->post->tasks[$todoID] : 0;
+ if($todo->type == 'bug') $todo->idvalue = isset($this->post->bugs[$todoID]) ? $this->post->bugs[$todoID] : 0;
+
+ $todos[$todoID] = $todo;
+ unset($todo);
+ }
+
+ foreach($todos as $todoID => $todo)
+ {
+ $oldTodo = $this->getById($todoID);
+ if($oldTodo->type != 'custom') $oldTodo->name = '';
+ $this->dao->update(TABLE_TODO)->data($todo)
+ ->autoCheck()
+ ->checkIF($todo->type == 'custom', $this->config->todo->edit->requiredFields, 'notempty')
+ ->checkIF($todo->type == 'bug', 'idvalue', 'notempty')
+ ->checkIF($todo->type == 'task', 'idvalue', 'notempty')
+ ->where('id')->eq($todoID)
+ ->exec();
+
+ if(!dao::isError())
+ {
+ $allChanges[$todoID] = common::createChanges($oldTodo, $todo);
+ }
+ else
+ {
+ die(js::error('todo#' . $todoID . dao::getError(true)));
+ }
+ }
+ }
+
+ return $allChanges;
+ }
+
/**
* Change the status of a todo.
*
diff --git a/module/todo/view/batchedit.html.php b/module/todo/view/batchedit.html.php
new file mode 100644
index 0000000000..89fdf481be
--- /dev/null
+++ b/module/todo/view/batchedit.html.php
@@ -0,0 +1,62 @@
+
+ * @package todo
+ * @version $Id: create.html.php 2741 2012-04-07 07:24:21Z areyou123456 $
+ * @link http://www.zentao.net
+ */
+?>
+
+
+
+
+
|