* @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->app->loadModuleConfig($this->moduleName);//Finish task #5118.(Fix bug #2271) } /** * View a user. * * @param string $account * @access public * @return void */ public function view($account) { $this->locate($this->createLink('user', 'todo', "account=$account")); } /** * Todos of a user. * * @param string $account * @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($account, $type = 'today', $status = 'all', $orderBy='date,status,begin', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Set thie url to session. */ $uri = $this->app->getURI(true); $this->session->set('todoList', $uri); $this->session->set('bugList', $uri); $this->session->set('taskList', $uri); /* 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. */ $user = $this->user->getById($account); $account = $user->account; $todos = $this->todo->getList($type, $account, $status, 0, $pager, $sort); $date = (int)$type == 0 ? helper::today() : $type; /* set menus. */ $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclosed|nodeleted'), $account); $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->account = $account; $this->view->type = $type; $this->view->status = $status; $this->view->orderBy = $orderBy; $this->view->pager = $pager; $this->display(); } /** * Story of a user. * * @param string $account * @param string $type * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function story($account, $type = 'assignedTo', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save session. */ $this->session->set('storyList', $this->app->getURI(true)); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set menu. */ $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclosed|nodeleted'), $account); /* 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->loadModel('story')->getUserStories($account, $type, 'id_desc', $pager); $this->view->users = $this->user->getPairs('noletter'); $this->view->type = $type; $this->view->account = $account; $this->view->user = $this->user->getById($account); $this->view->pager = $pager; $this->display(); } /** * Tasks of a user. * * @param string $account * @param string $type * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function task($account, $type = 'assignedTo', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save the session. */ $this->session->set('taskList', $this->app->getURI(true)); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set the menu. */ $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclosed|nodeleted'), $account); /* 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); $this->view->type = $type; $this->view->account = $account; $this->view->user = $this->user->getById($account); $this->view->pager = $pager; $this->display(); } /** * User bugs. * * @param string $account * @param string $type * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function bug($account, $type = 'assignedTo', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save the session. */ $this->session->set('bugList', $this->app->getURI(true)); /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set menu. */ $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclosed|nodeleted'), $account); /* 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->account = $account; $this->view->type = $type; $this->view->user = $this->user->getById($account); $this->view->users = $this->user->getPairs('noletter'); $this->view->pager = $pager; $this->display(); } /** * User's testtask * * @param string $account * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function testtask($account, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = pager::init($recTotal, $recPerPage, $pageID); /* Set menu. */ $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclosed|nodeleted'), $account); /* Save session. */ $this->session->set('testtaskList', $this->app->getURI(true)); $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->account = $account; $this->view->user = $this->user->getById($account); $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 string $type * @param string $orderBy * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ public function testcase($account, $type = 'case2Him', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Save session, load lang. */ $this->session->set('caseList', $this->app->getURI(true)); $this->app->loadLang('testcase'); /* 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); /* Set menu. */ $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclosed|nodeleted'), $account); $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->account = $account; $this->view->user = $this->user->getById($account); $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->display(); } /** * User projects. * * @param string $account * @access public * @return void */ public function project($account) { /* Set the menus. */ $this->loadModel('project'); $this->lang->set('menugroup.user', 'company'); $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclose|nodeleted'), $account); $this->view->title = $this->lang->user->common . $this->lang->colon . $this->lang->user->project; $this->view->position[] = $this->lang->user->project; $this->view->tabID = 'project'; $this->view->projects = $this->user->getProjects($account); $this->view->account = $account; $this->view->user = $this->user->getById($account); $this->display(); } /** * The profile of a user. * * @param string $account * @access public * @return void */ public function profile($account = '') { if(empty($account)) $account = $this->app->user->account; /* Set menu. */ $this->view->userList = $this->user->setUserList($this->user->getPairs('noempty|noclose|nodeleted'), $account); $user = $this->user->getById($account); $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->account = $account; $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->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->set('menugroup.user', 'company'); $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->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->set('menugroup.user', 'company'); $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->customBatchCreateFields) 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->set('menugroup.user', 'company'); $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->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->set('menugroup.user', 'company'); $this->lang->user->menu = $this->lang->company->menu; $this->lang->user->menuOrder = $this->lang->company->menuOrder; /* Set custom. */ foreach(explode(',', $this->config->user->customBatchEditFields) 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 $account * @param string $confirm * @access public * @return void */ public function unlock($account, $confirm = 'no') { if($confirm == 'no') { die(js::confirm($this->lang->user->confirmUnlock, $this->createLink('user', 'unlock', "account=$account&confirm=yes"))); } else { $this->user->cleanLocked($account); die(js::locate($this->session->userList ? $this->session->userList : $this->createLink('company', 'browse'), 'parent')); } } /** * Unbind Ranzhi * * @param string $account * @param string $confirm * @access public * @return void */ public function unbind($account, $confirm = 'no') { if($confirm == 'no') { die(js::confirm($this->lang->user->confirmUnbind, $this->createLink('user', 'unbind', "account=$account&confirm=yes"))); } else { $this->user->unbind($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 = '') { if($this->user->checkTmp() === false) { echo "
"; echo "| ";
echo " 不能创建临时目录,请确认目录{$this->app->tmpRoot}是否存在并有操作权限。 ";
echo "Can't create tmp directory, make sure the directory {$this->app->tmpRoot} exists and has permission to operate. ";
die(" |