* @package user * @version $Id: control.php 5005 2013-07-03 08:39:11Z chencongzhi520@gmail.com $ * @link http://www.zentao.net */ class user extends control { public $referer; /** * Construct * * @access public * @return void */ public function __construct($module = '', $method = '') { parent::__construct($module, $method); $this->loadModel('company')->setMenu(); $this->loadModel('dept'); $this->loadModel('todo'); $this->loadModel('execution'); $this->app->loadLang('project'); $this->app->loadModuleConfig($this->moduleName);//Finish task #5118.(Fix bug #2271) } /** * View a user. * * @param string $userID * @access public * @return void */ public function view($userID) { $userID = (int)$userID; $this->locate($this->createLink('user', 'todo', "userID=$userID&type=all")); } /** * Todos of a user. * * @param string $userID * @param string $type the todo type, today|lastweek|thisweek|all|undone, or a date. * @param string $status * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function todo($userID, $type = 'today', $status = 'all', $orderBy = 'date,status,begin', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $userID = (int)$userID; $user = $this->user->getById($userID, 'id'); if(empty($user)) die(js::error($this->lang->notFound) . js::locate('back')); /* Set thie url to session. */ $uri = $this->app->getURI(true); $this->session->set('todoList', $uri, 'my'); $this->session->set('bugList', $uri, 'qa'); $this->session->set('taskList', $uri, 'execution'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Append id for secend sort. */ $sort = $this->loadModel('common')->appendOrder($orderBy); /* Get user, totos. */ $account = $user->account; $todos = $this->todo->getList($type, $account, $status, 0, $pager, $sort); $date = (int)$type == 0 ? helper::today() : $type; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); if(!isset($users[$userID])) die(js::error($this->lang->user->error->noAccess) . js::locate('back')); /* set menus. */ $this->view->userList = $this->user->setUserList($users, $userID); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->todo; $this->view->position[] = $this->lang->user->todo; $this->view->tabID = 'todo'; $this->view->date = $date; $this->view->todos = $todos; $this->view->user = $user; $this->view->type = $type; $this->view->status = $status; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); } /** * Story of a user. * * @param int $userID * @param string $storyType * @param string $type * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function story($userID, $storyType = 'story', $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save session. */ $this->session->set('storyList', $this->app->getURI(true), 'product'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Modify story title. */ $this->loadModel('story'); if($storyType == 'requirement') $this->lang->story->title = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->title); /* Assign. */ $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->story; $this->view->position[] = $this->lang->user->story; $this->view->stories = $this->story->getUserStories($account, $type, $orderBy, $pager, $storyType); $this->view->users = $this->user->getPairs('noletter'); $this->view->storyType = $storyType; $this->view->orderBy = $orderBy; $this->view->type = $type; $this->view->user = $user; $this->view->pager = $pager; $this->view->userList = $this->user->setUserList($users, $userID); $this->display(); } /** * Tasks of a user. * * @param int $userID * @param string $type * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function task($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save the session. */ $this->session->set('taskList', $this->app->getURI(true), 'execution'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Set the menu. */ $this->view->userList = $this->user->setUserList($users, $userID); /* Assign. */ $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->task; $this->view->position[] = $this->lang->user->task; $this->view->tabID = 'task'; $this->view->tasks = $this->loadModel('task')->getUserTasks($account, $type, 0, $pager, $orderBy); $this->view->type = $type; $this->view->orderBy = $orderBy; $this->view->user = $user; $this->view->pager = $pager; $this->display(); } /** * User bugs. * * @param int $userID * @param string $type * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function bug($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save the session. */ $this->session->set('bugList', $this->app->getURI(true), 'qa'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Set menu. */ $this->view->userList = $this->user->setUserList($users, $userID); /* Load the lang of bug module. */ $this->app->loadLang('bug'); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->bug; $this->view->position[] = $this->lang->user->bug; $this->view->tabID = 'bug'; $this->view->bugs = $this->loadModel('bug')->getUserBugs($account, $type, $orderBy, 0, $pager); $this->view->type = $type; $this->view->user = $user; $this->view->orderBy = $orderBy; $this->view->users = $this->user->getPairs('noletter'); $this->view->pager = $pager; $this->display(); } /** * User's testtask * * @param int $userID * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function testtask($userID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Set menu. */ $this->view->userList = $this->user->setUserList($users, $userID); /* Save session. */ $this->session->set('testtaskList', $this->app->getURI(true), 'qa'); $this->session->set('buildList', $this->app->getURI(true), 'execution'); $this->app->loadLang('testcase'); /* Append id for secend sort. */ $sort = $this->loadModel('common')->appendOrder($orderBy); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->testTask; $this->view->position[] = $this->lang->user->testTask; $this->view->tasks = $this->loadModel('testtask')->getByUser($account, $pager, $sort); $this->view->users = $this->user->getPairs('noletter'); $this->view->user = $user; $this->view->recTotal = $recTotal; $this->view->recPerPage = $recPerPage; $this->view->pageID = $pageID; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); } /** * User's test case. * * @param int $userID * @param string $type * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function testcase($userID, $type = 'case2Him', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save session, load lang. */ $this->session->set('caseList', $this->app->getURI(true), 'qa'); $this->app->loadLang('testcase'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Append id for secend sort. */ $sort = $this->loadModel('common')->appendOrder($orderBy); $cases = array(); if($type == 'case2Him') { $cases = $this->loadModel('testcase')->getByAssignedTo($account, $sort, $pager); } elseif($type == 'caseByHim') { $cases = $this->loadModel('testcase')->getByOpenedBy($account, $sort, $pager); } $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', $type == 'case2Him' ? false : true); /* Assign. */ $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->testCase; $this->view->position[] = $this->lang->user->testCase; $this->view->user = $user; $this->view->cases = $cases; $this->view->users = $this->user->getPairs('noletter'); $this->view->tabID = 'test'; $this->view->type = $type; $this->view->recTotal = $recTotal; $this->view->recPerPage = $recPerPage; $this->view->pageID = $pageID; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->view->userList = $this->user->setUserList($users, $userID); $this->display(); } /** * User executions. * * @param int $userID * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function execution($userID, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $uri = $this->app->getURI(true); $this->session->set('executionList', $uri, 'execution'); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set the menus. */ $this->loadModel('project'); $this->view->userList = $this->user->setUserList($users, $userID); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->execution; $this->view->position[] = $this->lang->user->execution; $this->view->tabID = 'project'; $this->view->executions = $this->user->getExecutions($account, 'execution', 'all', $orderBy, $pager); $this->view->user = $user; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); } /** * User issues. * * @param int $userID * @param string $type * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function issue($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $uri = $this->app->getURI(true); $this->session->set('issueList', $uri, 'project'); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set the menus. */ $this->view->userList = $this->user->setUserList($users, $userID); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->issue; $this->view->position[] = $this->lang->user->issue; $this->view->issues = $this->loadModel('issue')->getUserIssues($type, $account, $orderBy, $pager); $this->view->user = $user; $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->view->type = $type; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); } /** * User risks. * * @param int $userID * @param string $type * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function risk($userID, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { $uri = $this->app->getURI(true); $this->session->set('riskList', $uri, 'project'); $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set the menus. */ $this->view->userList = $this->user->setUserList($users, $userID); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->risk; $this->view->position[] = $this->lang->user->risk; $this->view->risks = $this->loadModel('risk')->getUserRisks($type, $account, $orderBy, $pager); $this->view->user = $user; $this->view->type = $type; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); } /** * The profile of a user. * * @param int $userID * @access public * @return void */ public function profile($userID = '') { if(empty($userID)) $userID = $this->app->user->id; $user = $this->user->getById($userID, 'id'); $account = $user->account; $users = $this->loadModel('dept')->getDeptUserPairs($this->app->user->dept, 'useid'); $this->view->title = "USER #$user->id $user->account/" . $this->lang->user->profile; $this->view->position[] = $this->lang->user->common; $this->view->position[] = $this->lang->user->profile; $this->view->user = $user; $this->view->groups = $this->loadModel('group')->getByAccount($account); $this->view->deptPath = $this->dept->getParents($user->dept); $this->view->personalData = $this->user->getPersonalData($user->account); $this->view->userList = $this->user->setUserList($users, $userID); $this->display(); } /** * Set the rerferer. * * @param string $referer * @access public * @return void */ public function setReferer($referer = '') { $this->referer = $this->server->http_referer ? $this->server->http_referer: ''; if(!empty($referer)) $this->referer = helper::safe64Decode($referer); /* Build zentao link regular. */ $webRoot = $this->config->webRoot; $linkReg = $webRoot . 'index.php?' . $this->config->moduleVar . '=\w+&' . $this->config->methodVar . '=\w+'; if($this->config->requestType == 'PATH_INFO') $linkReg = $webRoot . '\w+' . $this->config->requestFix . '\w+'; $linkReg = str_replace(array('/', '.', '?', '-'), array('\/', '\.', '\?', '\-'), $linkReg); /* Check zentao link by regular. */ $this->referer = preg_match('/^' . $linkReg . '/', $this->referer) ? $this->referer : $webRoot; } /** * Create a suer. * * @param int $deptID * @access public * @return void */ public function create($deptID = 0) { $this->lang->user->menu = $this->lang->company->menu; $this->lang->user->menuOrder = $this->lang->company->menuOrder; if(!empty($_POST)) { if(strtolower($_POST['account']) == 'guest') { $this->send(array('result' => 'fail', 'message' => str_replace('ID ', '', sprintf($this->lang->user->error->reserved, $_POST['account'])))); } $this->user->create(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('company', 'browse'))); } $groups = $this->dao->select('id, name, role')->from(TABLE_GROUP)->fetchAll(); $groupList = array('' => ''); $roleGroup = array(); foreach($groups as $group) { $groupList[$group->id] = $group->name; if($group->role) $roleGroup[$group->role] = $group->id; } $title = $this->lang->company->common . $this->lang->colon . $this->lang->user->create; $position[] = $this->lang->user->create; $this->view->title = $title; $this->view->position = $position; $this->view->depts = $this->dept->getOptionMenu(); $this->view->groupList = $groupList; $this->view->roleGroup = $roleGroup; $this->view->deptID = $deptID; $this->view->rand = $this->user->updateSessionRandom(); $this->view->companies = $this->loadModel('company')->getOutsideCompanies(); $this->display(); } /** * Batch create users. * * @param int $deptID * @access public * @return void */ public function batchCreate($deptID = 0) { $groups = $this->dao->select('id, name, role')->from(TABLE_GROUP)->fetchAll(); $groupList = array('' => ''); $roleGroup = array(); foreach($groups as $group) { $groupList[$group->id] = $group->name; if($group->role) $roleGroup[$group->role] = $group->id; } $this->lang->user->menu = $this->lang->company->menu; $this->lang->user->menuOrder = $this->lang->company->menuOrder; if(!empty($_POST)) { $this->user->batchCreate(); die(js::locate($this->createLink('company', 'browse'), 'parent')); } /* Set custom. */ foreach(explode(',', $this->config->user->availableBatchCreateFields) as $field) { if(!isset($this->lang->user->contactFieldList[$field]) or strpos($this->config->user->contactField, $field) !== false) $customFields[$field] = $this->lang->user->$field; } foreach(explode(',', $this->config->user->custom->batchCreateFields) as $field) { if(!isset($this->lang->user->contactFieldList[$field]) or strpos($this->config->user->contactField, $field) !== false) $showFields[$field] = $field; } $this->view->customFields = $customFields; $this->view->showFields = join(',', $showFields); $title = $this->lang->company->common . $this->lang->colon . $this->lang->user->batchCreate; $position[] = $this->lang->user->batchCreate; $this->view->title = $title; $this->view->position = $position; $this->view->depts = $this->dept->getOptionMenu(); $this->view->deptID = $deptID; $this->view->groupList = $groupList; $this->view->roleGroup = $roleGroup; $this->view->rand = $this->user->updateSessionRandom(); $this->display(); } /** * Edit a user. * * @param string|int $userID the int user id or account * @access public * @return void */ public function edit($userID) { $this->lang->user->menu = $this->lang->company->menu; $this->lang->user->menuOrder = $this->lang->company->menuOrder; if(!empty($_POST)) { $this->user->update($userID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $link = $this->session->userList ? $this->session->userList : $this->createLink('company', 'browse'); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $link)); } $user = $this->user->getById($userID, 'id'); $userGroups = $this->loadModel('group')->getByAccount($user->account); $title = $this->lang->company->common . $this->lang->colon . $this->lang->user->edit; $position[] = $this->lang->user->edit; $this->view->title = $title; $this->view->position = $position; $this->view->user = $user; $this->view->depts = $this->dept->getOptionMenu(); $this->view->userGroups = implode(',', array_keys($userGroups)); $this->view->companies = $this->loadModel('company')->getOutsideCompanies(); $this->view->groups = $this->dao->select('id, name')->from(TABLE_GROUP)->fetchPairs('id', 'name'); $this->view->rand = $this->user->updateSessionRandom(); $this->display(); } /** * Batch edit user. * * @param int $deptID * @access public * @return void */ public function batchEdit($deptID = 0) { if(isset($_POST['users'])) { $this->view->users = $this->dao->select('*')->from(TABLE_USER)->where('account')->in($this->post->users)->orderBy('id')->fetchAll('id'); } elseif($_POST) { if($this->post->account) $this->user->batchEdit(); die(js::locate($this->session->userList ? $this->session->userList : $this->createLink('company', 'browse', "deptID=$deptID"), 'parent')); } $this->lang->user->menu = $this->lang->company->menu; $this->lang->user->menuOrder = $this->lang->company->menuOrder; /* Set custom. */ foreach(explode(',', $this->config->user->availableBatchEditFields) as $field) { if(!isset($this->lang->user->contactFieldList[$field]) or strpos($this->config->user->contactField, $field) !== false) $customFields[$field] = $this->lang->user->$field; } foreach(explode(',', $this->config->user->custom->batchEditFields) as $field) { if(!isset($this->lang->user->contactFieldList[$field]) or strpos($this->config->user->contactField, $field) !== false) $showFields[$field] = $field; } $this->view->customFields = $customFields; $this->view->showFields = join(',', $showFields); $this->view->title = $this->lang->company->common . $this->lang->colon . $this->lang->user->batchEdit; $this->view->position[] = $this->lang->user->batchEdit; $this->view->depts = $this->dept->getOptionMenu(); $this->view->rand = $this->user->updateSessionRandom(); $this->display(); } /** * Delete a user. * * @param int $userID * @param string $confirm yes|no * @access public * @return void */ public function delete($userID) { $user = $this->user->getByID($userID, 'id'); if($this->app->user->admin and $this->app->user->account == $user->account) return; if($_POST) { if($this->post->verifyPassword != md5($this->app->user->password . $this->session->rand)) die(js::alert($this->lang->user->error->verifyPassword)); $this->user->delete(TABLE_USER, $userID); if(!dao::isError()) { $this->loadModel('mail'); if($this->config->mail->mta == 'sendcloud' and !empty($user->email)) $this->mail->syncSendCloud('delete', $user->email); } /* if ajax request, send result. */ if($this->server->ajax) { if(dao::isError()) { $response['result'] = 'fail'; $response['message'] = dao::getError(); } else { $response['result'] = 'success'; $response['message'] = ''; } $this->send($response); } die(js::locate($this->session->userList, 'parent.parent')); } $this->view->rand = $this->user->updateSessionRandom(); $this->display(); } /** * Unlock a user. * * @param int $userID * @param string $confirm * @access public * @return void */ public function unlock($userID, $confirm = 'no') { if($confirm == 'no') die(js::confirm($this->lang->user->confirmUnlock, $this->createLink('user', 'unlock', "userID=$userID&confirm=yes"))); $user = $this->user->getById($userID, 'id'); $this->user->cleanLocked($user->account); die(js::locate($this->session->userList ? $this->session->userList : $this->createLink('company', 'browse'), 'parent')); } /** * Unbind Ranzhi * * @param string $userID * @param string $confirm * @access public * @return void */ public function unbind($userID, $confirm = 'no') { if($confirm == 'no') die(js::confirm($this->lang->user->confirmUnbind, $this->createLink('user', 'unbind', "userID=$userID&confirm=yes"))); $user = $this->user->getById($userID, 'id'); $this->user->unbind($user->account); die(js::locate($this->session->userList ? $this->session->userList : $this->createLink('company', 'browse'), 'parent')); } /** * User login, identify him and authorize him. * * @param string $referer * @param string $from * * @access public * @return void */ public function login($referer = '', $from = '') { /* Check if you can operating on the folder. */ $canModifyDIR = true; if($this->user->checkTmp() === false) { $canModifyDIR = false; $floderPath = $this->app->tmpRoot; } elseif(!is_dir($this->app->dataRoot) or substr(base_convert(@fileperms($this->app->dataRoot),10,8),-4) != '0777') { $canModifyDIR = false; $floderPath = $this->app->dataRoot; } if(!$canModifyDIR) { echo "
"; echo "| ";
echo " 不能创建临时目录,请确认目录{$floderPath}是否存在并有操作权限。 ";
echo "Can't create tmp directory, make sure the directory {$floderPath} exists and has permission to operate. ";
die(" |