diff --git a/db/update4.0.beta1.sql b/db/update4.0.beta1.sql index 38ddccdfc1..e7d9fa8e72 100644 --- a/db/update4.0.beta1.sql +++ b/db/update4.0.beta1.sql @@ -13,5 +13,9 @@ INSERT INTO `zt_groupPriv` (`company`, `group`, `module`, `method`) VALUES (1, 2, 'story', 'batchEdit'), (1, 3, 'story', 'batchEdit'), (1, 4, 'story', 'batchEdit'), -(1, 5, 'story', 'batchEdit'); - +(1, 5, 'story', 'batchEdit'), +(1, 1, 'todo', 'batchEdit'), +(1, 2, 'todo', 'batchEdit'), +(1, 3, 'todo', 'batchEdit'), +(1, 4, 'todo', 'batchEdit'), +(1, 5, 'todo', 'batchEdit'); diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 327ff9d76a..df4829460e 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -88,6 +88,7 @@ $lang->my->methodOrder[55] = 'changePassword'; $lang->resource->todo->create = 'create'; $lang->resource->todo->batchCreate = 'batchCreate'; $lang->resource->todo->edit = 'edit'; +$lang->resource->todo->batchEdit = 'batchEdit'; $lang->resource->todo->view = 'view'; $lang->resource->todo->delete = 'delete'; $lang->resource->todo->export = 'export'; diff --git a/module/my/view/todo.html.php b/module/my/view/todo.html.php index e8e1235d2b..1af6636c6a 100644 --- a/module/my/view/todo.html.php +++ b/module/my/view/todo.html.php @@ -17,20 +17,19 @@
' . html::a(inlink('todo', "date=today"), $lang->todo->todayTodos) . ''; - echo '' . html::a(inlink('todo', "date=yesterday"), $lang->todo->yesterdayTodos). ''; - echo '' . html::a(inlink('todo', "date=thisweek"), $lang->todo->thisWeekTodos) . ''; - echo '' . html::a(inlink('todo', "date=lastweek"), $lang->todo->lastWeekTodos) . ''; - echo '' . html::a(inlink('todo', "date=thismonth"), $lang->todo->thismonthTodos). ''; - echo '' . html::a(inlink('todo', "date=lastmonth"), $lang->todo->lastmonthTodos). ''; - echo '' . html::a(inlink('todo', "date=thisseason"),$lang->todo->thisseasonTodos).''; - echo '' . html::a(inlink('todo', "date=thisyear"), $lang->todo->thisyearTodos) . ''; - echo '' . html::a(inlink('todo', "date=future"), $lang->todo->futureTodos) . ''; - echo '' . html::a(inlink('todo', "date=all"), $lang->todo->allDaysTodos) . ''; - echo '' . html::a(inlink('todo', "date=before&account={$app->user->account}&status=undone"), $lang->todo->allUndone) . ''; - echo "" . html::input('date', $date, "class='w-date date' onchange=changeDate(this.value)") . ''; - ?> - ' . html::a(inlink('todo', "date=today"), $lang->todo->todayTodos) . ''; + echo ''. html::a(inlink('todo', "date=yesterday"), $lang->todo->yesterdayTodos). ''; + echo '' . html::a(inlink('todo', "date=thisweek"), $lang->todo->thisWeekTodos) . ''; + echo '' . html::a(inlink('todo', "date=lastweek"), $lang->todo->lastWeekTodos) . ''; + echo ''. html::a(inlink('todo', "date=thismonth"), $lang->todo->thismonthTodos). ''; + echo '' . html::a(inlink('todo', "date=lastmonth"), $lang->todo->lastmonthTodos). ''; + echo ''. html::a(inlink('todo', "date=thisseason"),$lang->todo->thisseasonTodos).''; + echo '' . html::a(inlink('todo', "date=thisyear"), $lang->todo->thisyearTodos) . ''; + echo '' . html::a(inlink('todo', "date=future"), $lang->todo->futureTodos) . ''; + echo '' . html::a(inlink('todo', "date=all"), $lang->todo->allDaysTodos) . ''; + echo '' . html::a(inlink('todo', "date=before&account={$app->user->account}&status=undone"), $lang->todo->allUndone) . ''; + echo "" . html::input('date', $date,"class='w-date date'") . ''; + if($type == 'bydate') { if($date == date('Y-m-d')) @@ -64,16 +63,16 @@ todo->beginAB;?> todo->endAB;?> todo->status;?> - actions;?> + actions;?> - + - + id; ?> date == '2030-01-01' ? $lang->todo->dayInFuture : $todo->date;?> @@ -83,7 +82,7 @@ begin;?> end;?> todo->statusList[$todo->status];?> - + createLink('todo', 'mark', "id=$todo->id&status=$todo->status"), $lang->todo->{'mark'.ucfirst($todo->status)}, 'hiddenwin'); common::printIcon('todo', 'edit', "id=$todo->id", '', 'list'); @@ -93,15 +92,24 @@ - +
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 + */ +?> + + +
'> + + + + + + + + + + + + + + + + + + + + + + + + +
todo->batchEdit . $lang->colon;?>
idAB;?>todo->date;?>todo->type;?>todo->pri;?>todo->name;?>todo->beginAndEnd;?>
id . html::hidden("todoIDList[$todo->id]", $todo->id);?>id]", $todo->date, "class='text-1 date'");?>id]", $lang->todo->typeList, $todo->type, "onchange=loadList(this.value,$todo->id) class='select-1'");?>id]", $lang->todo->priList, $todo->pri, 'class=select-1');?> + +
+ type == 'custom') + { + echo html::input("names[$todo->id]", $todo->name, "class='f-left text-1'"); echo "*"; + } + elseif($todo->type == 'task') + { + echo html::select("tasks[$todo->id]", $tasks, $todo->idvalue, 'class="select-1 f-left"'); + } + elseif($todo->type == 'bug') + { + echo html::select("bugs[$todo->id]", $bugs, $todo->idvalue, 'class="select-1 f-left"'); + } + ?> +
+
id]", $times, $todo->begin) . html::select("ends[$todo->id]", $times, $todo->end);?> +
+
+ +