diff --git a/module/program/config.php b/module/program/config.php index 96c7144e8e..296bc728b4 100644 --- a/module/program/config.php +++ b/module/program/config.php @@ -11,3 +11,8 @@ $config->program->editor->suspend = array('id' => 'comment', 'tools' => 'simple $config->program->list = new stdclass(); $config->program->list->exportFields = 'id,name,code,template,category,status,begin,end,budget,PM,end,desc'; + +$config->program->create = new stdclass(); +$config->program->edit = new stdclass(); +$config->program->create->requiredFields = 'name,code,begin,end'; +$config->program->edit->requiredFields = 'name,code,begin,end'; diff --git a/module/program/control.php b/module/program/control.php index f96d352206..8924926101 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -44,6 +44,8 @@ class program extends control { if(common::hasPriv('program', 'createGuide')) $this->lang->pageActions = html::a($this->createLink('program', 'createGuide'), " " . $this->lang->program->create, '', "class='btn btn-primary' data-toggle=modal"); + $this->app->session->set('programList', $this->app->getURI(true)); + $programType = $this->cookie->programType ? $this->cookie->programType : 'bylist'; $this->app->loadClass('pager', $static = true); @@ -155,30 +157,33 @@ class program extends control /** * Edit a program. * - * @param int $projectID + * @param int $programID * @access public * @return void */ - public function edit($projectID = 0) + public function edit($programID = 0) { - $project = $this->project->getByID($projectID); + $program = $this->project->getByID($programID); if($_POST) { - $changes = $this->project->update($projectID); + $changes = $this->program->update($programID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => $this->processErrors(dao::getError()))); if($changes) { - $actionID = $this->loadModel('action')->create('project', $projectID, 'edited'); + $actionID = $this->loadModel('action')->create('program', $programID, 'edited'); $this->action->logHistory($actionID, $changes); } - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); + + $url = $this->session->programList ? $this->session->programList : inlink('browse'); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $url)); } - $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst', $project->PM); - $this->view->title = $this->lang->project->edit; - $this->view->position[] = $this->lang->project->edit; - $this->view->project = $project; + $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst', $program->PM); + $this->view->title = $this->lang->program->edit; + $this->view->position[] = $this->lang->program->edit; + $this->view->program = $program; + $this->view->parents = $this->program->getParentPairs(); $this->view->groups = $this->loadModel('group')->getPairs(); $this->display(); } diff --git a/module/program/model.php b/module/program/model.php index 21c21923ae..1a54b53d30 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -75,7 +75,6 @@ class programModel extends model public function create() { - $this->lang->project->team = $this->lang->project->teamname; $project = fixer::input('post') ->setDefault('status', 'wait') ->add('type', 'program') @@ -85,14 +84,14 @@ class programModel extends model ->setDefault('team', substr($this->post->name,0, 30)) ->join('whitelist', ',') ->cleanInt('budget') - ->stripTags($this->config->project->editor->create['id'], $this->config->allowedTags) + ->stripTags($this->config->program->editor->create['id'], $this->config->allowedTags) ->remove('products, workDays, delta, branch, uid, plans') ->get(); - $project = $this->loadModel('file')->processImgURL($project, $this->config->project->editor->create['id'], $this->post->uid); + $project = $this->loadModel('file')->processImgURL($project, $this->config->program->editor->create['id'], $this->post->uid); $this->dao->insert(TABLE_PROJECT)->data($project) ->autoCheck() - ->batchcheck($this->config->project->create->requiredFields, 'notempty') + ->batchcheck($this->config->program->create->requiredFields, 'notempty') ->check('name', 'unique', "deleted='0'") ->check('code', 'unique', "deleted='0'") ->exec(); @@ -156,6 +155,56 @@ class programModel extends model } } + /** + * Update program. + * + * @param int $programID + * @access public + * @return array + */ + public function update($programID) + { + $programID = (int)$programID; + $oldProgram = $this->dao->findById($programID)->from(TABLE_PROJECT)->fetch(); + + $program = fixer::input('post') + ->setIF($this->post->begin == '0000-00-00', 'begin', '') + ->setIF($this->post->end == '0000-00-00', 'end', '') + ->setIF($this->post->acl != 'custom', 'whitelist', '') + ->setIF($this->post->acl == 'custom' and !isset($_POST['whitelist']), 'whitelist', '') + ->setDefault('team', $this->post->name) + ->join('whitelist', ',') + ->stripTags($this->config->program->editor->edit['id'], $this->config->allowedTags) + ->remove('products, branch, uid, plans') + ->get(); + $program = $this->loadModel('file')->processImgURL($program, $this->config->program->editor->edit['id'], $this->post->uid); + + $this->dao->update(TABLE_PROJECT)->data($program) + ->autoCheck($skipFields = 'begin,end') + ->batchcheck($this->config->program->edit->requiredFields, 'notempty') + ->checkIF($program->begin != '', 'begin', 'date') + ->checkIF($program->end != '', 'end', 'date') + ->checkIF($program->end != '', 'end', 'gt', $program->begin) + ->check('name', 'unique', "id!=$programID and deleted='0'") + ->check('code', 'unique', "id!=$programID and deleted='0'") + ->where('id')->eq($programID) + ->limit(1) + ->exec(); + + if(!dao::isError()) + { + $this->file->updateObjectID($this->post->uid, $programID, 'project'); + if($program->acl != 'open' and ($program->acl != $oldProject->acl or $program->whitelist != $oldProgram->whitelist)) + { + $this->loadModel('user')->updateUserView($programID, 'program'); + } + + if($oldProgram->parent != $program->parent) $this->moveNode($programID, $program->parent, $oldProgram->path, $oldProgram->grade); + + return common::createChanges($oldProgram, $program); + } + } + public function getSwapper($programs, $programID, $currentModule, $currentMethod, $extra = '') { $this->loadModel('project'); @@ -177,6 +226,14 @@ class programModel extends model return $output; } + /** + * Judge an action is clickable or not. + * + * @param object $project + * @param string $action + * @access public + * @return bool + */ public static function isClickable($project, $action) { $action = strtolower($action); @@ -190,11 +247,25 @@ class programModel extends model return true; } + /** + * Get program products + * + * @param int $program + * @access public + * @return array + */ public function getProducts($program) { return $this->dao->select('*')->from(TABLE_PRODUCT)->where('project')->eq($program)->fetchAll('id'); } + /** + * Check has content for program + * + * @param int $programID + * @access public + * @return bool + */ public function checkHasContent($programID) { $count = 0; @@ -219,6 +290,13 @@ class programModel extends model return $count > 0; } + /** + * Set program tree path. + * + * @param int $programID + * @access public + * @return bool + */ public function setTreePath($programID) { $program = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($programID)->fetch(); @@ -234,5 +312,69 @@ class programModel extends model $path['grade'] = $parent->grade + 1; } $this->dao->update(TABLE_PROJECT)->set('path')->eq($path['path'])->set('grade')->eq($path['grade'])->where('id')->eq($program->id)->exec(); + return !dao::isError(); + } + + /** + * Get program parent pairs + * + * @access public + * @return array + */ + public function getParentPairs() + { + $stmt = $this->dao->select('id,name,parent,path,grade')->from(TABLE_PROJECT)->where('isCat')->eq(1)->andWhere('deleted')->eq(0)->orderBy('grade, `order`')->query(); + + $pairs = array(); + $pairs[0] = '/'; + while($program = $stmt->fetch()) + { + if($program->grade == 1) + { + $pairs[$program->id] = '/' . $program->name; + continue; + } + + $programName = '/' . $program->name; + $pairs[$program->id] = isset($pairs[$program->parent]) ? $pairs[$program->parent] . $programName : $programName; + } + + return $pairs; + } + + /** + * Move project node. + * + * @param int $programID + * @param int $parentID + * @param string $oldPath + * @param int $oldGrade + * @access public + * @return bool + */ + public function moveNode($programID, $parentID, $oldPath, $oldGrade) + { + $parent = $this->dao->select('id,parent,path,grade')->from(TABLE_PROJECT)->where('id')->eq($parentID)->fetch(); + + $childNodes = $this->dao->select('id,parent,path,grade')->from(TABLE_PROJECT) + ->where('path')->like("{$oldPath}%") + ->andWhere('deleted')->eq(0) + ->andWhere('template')->ne('') + ->orderBy('grade') + ->fetchAll(); + /* Process child node path and grade field. */ + foreach($childNodes as $childNode) + { + $path = substr($childNode->path, strpos($childNode->path, ",{$programID},")); + $grade = $oldGrade - $childNode->grade + 1; + if($parent) + { + $path = rtrim($parent->path, ',') . $path; + $grade = $parent->grade + $grade; + } + $this->dao->update(TABLE_PROJECT)->set('path')->eq($path)->set('grade')->eq($grade)->where('id')->eq($childNode->id)->exec(); + } + + return !dao::isError(); } } diff --git a/module/program/view/edit.html.php b/module/program/view/edit.html.php index 52c5b9df39..5b05eeb5b9 100644 --- a/module/program/view/edit.html.php +++ b/module/program/view/edit.html.php @@ -1,11 +1,11 @@ - * @package project + * @package program * @version $Id: create.html.php 4728 2013-05-03 06:14:34Z chencongzhi520@gmail.com $ * @link http://www.zentao.net */ @@ -20,47 +20,52 @@