/** * Post a thread. * * @param int $boardID * @access public * @return void */ public function post($boardID = 0) { $this->loadModel('forum'); if ($this->app->user->account == 'guest') { die(js::locate($this->createLink('user', 'login', "referer=" . helper::safe64Encode($this->app->getURI())))); } /* Get the board. */ $board = $this->loadModel('tree')->getById($boardID); /* Checking the board exist or not. */ if (!$board) { die(js::error($this->lang->forum->notExist) . js::locate('back')); } /* Checking current user can post to the board or not. */ if (!$this->forum->canPost($board)) { die(js::error($this->lang->forum->readonly) . js::locate('back')); } /* Set editor for current user. */ $this->thread->setEditor($board->id, 'post'); /* User posted a thread, try to save it to database. */ if ($_POST) { $threadID = $this->thread->post($boardID); if (dao::isError()) { $this->send(array('result' => 'fail', 'message' => dao::getError())); } $locate = inlink('view', "threadID={$threadID}"); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locate)); } $this->view->title = $board->name . $this->lang->minus . $this->lang->thread->post; $this->view->board = $board; $this->view->boards = $this->forum->getBoards(); $this->view->canManage = $this->thread->canManage($boardID); $this->display(); }
/** * Change password , if use default password ,go to change * * @access public * @return void */ public function changePassword() { if ($this->app->user->account == 'guest') { die(js::alert('guest') . js::locate('back')); } if (!empty($_POST)) { $password1 = $_POST['password1']; if (!$password1) { die(js::error('Please input password!')); } $isDefult = $this->dao->select('password')->from(TABLE_DEFAULTPASSWORD)->Where('password')->eq($this->post->password1)->fetchAll(); //如果用户使用默认密码则跳到修改密码界面 if ($isDefult) { die(js::error('Password can not in default list!') . js::locate($this->createLink('my', 'changePassword', 'type=forbidden'), 'parent')); } $this->user->updatePassword($this->app->user->id); if (dao::isError()) { die(js::error(dao::getError())); } die(js::locate($this->createLink('my', 'profile'), 'parent')); } $this->view->title = $this->lang->my->common . $this->lang->colon . $this->lang->my->changePassword; $this->view->position[] = $this->lang->my->changePassword; $this->view->user = $this->user->getById($this->app->user->id); $this->display(); }
/** * Create a batch case. * * @access public * @return void */ function batchCreate($productID) { $now = helper::now(); $cases = fixer::input('post')->get(); for ($i = 0; $i < $this->config->testcase->batchCreate; $i++) { if ($cases->type[$i] != '' and $cases->title[$i] != '') { $data[$i]->product = $productID; $data[$i]->module = $cases->module[$i] == 'same' ? $i == 0 ? 0 : $data[$i - 1]->module : $cases->module[$i]; $data[$i]->type = $cases->type[$i] == 'same' ? $i == 0 ? '' : $data[$i - 1]->type : $cases->type[$i]; $data[$i]->story = $cases->story[$i] == 'same' ? $i == 0 ? 0 : $data[$i - 1]->story : $cases->story[$i]; $data[$i]->title = $cases->title[$i]; $data[$i]->openedBy = $this->app->user->account; $data[$i]->openedDate = $now; $data[$i]->status = 'normal'; $data[$i]->version = 1; if ($data[$i]->story != 0) { $data[$i]->storyVersion = $this->loadModel('story')->getVersion($this->post->story); } $this->dao->insert(TABLE_CASE)->data($data[$i])->autoCheck()->batchCheck($this->config->testcase->create->requiredFields, 'notempty')->exec(); if (dao::isError()) { echo js::error(dao::getError()); die(js::reload('parent')); } $caseID = $this->dao->lastInsertID(); $actionID = $this->loadModel('action')->create('case', $caseID, 'Opened'); } else { unset($cases->module[$i]); unset($cases->type[$i]); unset($cases->story[$i]); unset($cases->title[$i]); } } }
/** * Save search query. * * @access public * @return void */ public function saveQuery() { $this->search->saveQuery(); if (dao::isError()) { die(js::error(dao::getError())); } die('success'); }
/** * Post a thread. * * @param int $boardID * @access public * @return void */ public function post($boardID = 0) { $this->loadModel('forum'); if ($this->app->user->account == 'guest') { die(js::locate($this->createLink('user', 'login', "referer=" . helper::safe64Encode($this->app->getURI())))); } /* Get the board. */ $board = $this->loadModel('tree')->getById($boardID); /* Checking the board exist or not. */ if (!$board) { die(js::error($this->lang->forum->notExist) . js::locate('back')); } /* Checking current user can post to the board or not. */ if (!$this->forum->canPost($board)) { die(js::error($this->lang->forum->readonly) . js::locate('back')); } /* Set editor for current user. */ $this->thread->setEditor($board->id, 'post'); /* User posted a thread, try to save it to database. */ if ($_POST) { $captchaConfig = isset($this->config->site->captcha) ? $this->config->site->captcha : 'auto'; $needCaptcha = false; if ($captchaConfig == 'auto' and $this->loadModel('guarder')->isEvil($this->post->{$this->session->contentInput})) { $needCaptcha = true; } if ($captchaConfig == 'open') { $needCaptcha = true; } if ($captchaConfig == 'close') { $needCaptcha = false; } /* If no captcha but is garbage, return the error info. */ $captchaInput = $this->session->captchaInput; if ($this->post->{$captchaInput} === false and $needCaptcha) { $this->send(array('result' => 'fail', 'reason' => 'needChecking', 'captcha' => $this->loadModel('guarder')->create4Thread())); } $result = $this->thread->post($boardID); $this->send($result); } $titleInput = helper::createRandomStr(6, $skip = 'A-Z'); $contentInput = helper::createRandomStr(7, $skip = 'A-Z'); $this->session->set('titleInput', $titleInput); $this->session->set('contentInput', $contentInput); $this->config->thread->require->post = "{$this->session->titleInput}, {$this->session->contentInput}"; $this->config->thread->editor->post = array('id' => $this->session->contentInput, 'tools' => 'simple'); $this->view->title = $board->name . $this->lang->minus . $this->lang->thread->post; $this->view->board = $board; $this->view->canManage = $this->thread->canManage($boardID); $this->view->titleInput = $titleInput; $this->view->contentInput = $contentInput; $this->view->board = $board; $this->view->mobileURL = helper::createLink('thread', 'post', "boardID={$boardID}", '', 'mhtml'); $this->view->desktopURL = helper::createLink('thread', 'post', "boardID={$boardID}", '', 'html'); $this->display(); }
/** * Create an article. * * @access public * @return void */ public function create() { if (!empty($_POST)) { $blogID = $this->blog->create(); if (dao::isError()) { die(js::error(dao::getError()) . js::locate('back')); } die(js::locate(inlink('index'))); } $this->view->title = $this->lang->blog->add; $this->display(); }
/** * Post a thread. * * @param int $boardID * @access public * @return void */ public function post($boardID = 0) { $this->loadModel('forum'); if ($this->app->user->account == 'guest') { die(js::locate($this->createLink('user', 'login', "referer=" . helper::safe64Encode($this->app->getURI())))); } /* Get the board. */ $board = $this->loadModel('tree')->getById($boardID); /* Checking the board exist or not. */ if (!$board) { die(js::error($this->lang->forum->notExist) . js::locate('back')); } /* Checking current user can post to the board or not. */ if (!$this->forum->canPost($board)) { die(js::error($this->lang->forum->readonly) . js::locate('back')); } /* Set editor for current user. */ $this->thread->setEditor($board->id, 'post'); /* User posted a thread, try to save it to database. */ if ($_POST) { $captchaConfig = isset($this->config->site->captcha) ? $this->config->site->captcha : 'auto'; $needCaptcha = false; if ($captchaConfig == 'auto' and $this->loadModel('captcha')->isEvil($this->post->content)) { $needCaptcha = true; } if ($captchaConfig == 'open') { $needCaptcha = true; } if ($captchaConfig == 'close') { $needCaptcha = false; } /* If no captcha but is garbage, return the error info. */ if ($this->post->captcha === false and $needCaptcha) { $this->send(array('result' => 'fail', 'reason' => 'needChecking', 'captcha' => $this->loadModel('captcha')->create4Thread())); } $threadID = $this->thread->post($boardID); if (is_array($threadID)) { $this->send($threadID); } if (dao::isError()) { $this->send(array('result' => 'fail', 'message' => dao::getError())); } $locate = inlink('view', "threadID={$threadID}"); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $locate)); } $this->view->title = $board->name . $this->lang->minus . $this->lang->thread->post; $this->view->board = $board; $this->view->canManage = $this->thread->canManage($boardID); $this->display(); }
/** * Custom * * @param string $module * @param string $field * @access public * @return void */ public function set($module = 'story', $field = 'priList') { if ($module == 'user' and $field == 'priList') { $field = 'roleList'; } $currentLang = $this->app->getClientLang(); $this->app->loadLang($module); $this->app->loadConfig('story'); $fieldList = $this->lang->{$module}->{$field}; if ($module == 'bug' and $field == 'typeList') { unset($fieldList['designchange']); unset($fieldList['newfeature']); unset($fieldList['trackthings']); } if (!empty($_POST)) { if ($module == 'story' && $field == 'review') { $this->loadModel('setting')->setItem('system.story.needReview', fixer::input('post')->get()->needReview); } else { $lang = $_POST['lang']; $this->custom->deleteItems("lang={$lang}&module={$module}§ion={$field}"); foreach ($_POST['keys'] as $index => $key) { $value = $_POST['values'][$index]; if (!$value or !$key) { continue; } $system = $_POST['systems'][$index]; /* the length of role is 20, check it when save. */ if ($module == 'user' and $field == 'roleList' and strlen($key) > 20) { die(js::alert($this->lang->custom->notice->userRole)); } $this->custom->setItem("{$lang}.{$module}.{$field}.{$key}.{$system}", $value); } } if (dao::isError()) { die(js::error(dao::getError())); } die(js::reload('parent')); } $this->view->title = $this->lang->custom->common . $this->lang->colon . $this->lang->{$module}->common; $this->view->position[] = $this->lang->custom->common; $this->view->position[] = $this->lang->{$module}->common; $this->view->needReview = $this->config->story->needReview; $this->view->fieldList = $fieldList; $this->view->dbFields = $this->custom->getItems("lang={$currentLang},all&module={$module}§ion={$field}"); $this->view->field = $field; $this->view->module = $module; $this->view->currentLang = $currentLang; $this->view->canAdd = strpos($this->config->custom->canAdd[$module], $field) !== false; $this->display(); }
/** * Edit cron. * * @param int $cronID * @access public * @return void */ public function edit($cronID) { if ($_POST) { $this->cron->update($cronID); if (dao::isError()) { die(js::error(dao::getError())); } die(js::locate(inlink('index'), 'parent')); } $this->view->title = $this->lang->cron->edit . $this->lang->cron->common; $this->view->position[] = html::a(inlink('index'), $this->lang->cron->common); $this->view->position[] = $this->lang->cron->edit; $this->view->cron = $this->cron->getById($cronID); $this->display(); }
/** * Create batch todo * * @access public * @return void */ public function batchCreate() { $todos = fixer::input('post')->cleanInt('date')->get(); for ($i = 0; $i < $this->config->todo->batchCreate; $i++) { if ($todos->names[$i] != '' || isset($todos->bugs[$i + 1]) || isset($todos->tasks[$i + 1])) { $todo->account = $this->app->user->account; if ($this->post->date == false) { $todo->date = '2030-01-01'; } else { $todo->date = $this->post->date; } $todo->type = $todos->types[$i]; $todo->pri = $todos->pris[$i]; $todo->name = isset($todos->names[$i]) ? $todos->names[$i] : ''; $todo->desc = $todos->descs[$i]; $todo->begin = $todos->begins[$i]; $todo->end = $todos->ends[$i]; $todo->status = "wait"; $todo->private = 0; $todo->idvalue = 0; if ($todo->type == 'bug') { $todo->idvalue = isset($todos->bugs[$i + 1]) ? $todos->bugs[$i + 1] : 0; } if ($todo->type == 'task') { $todo->idvalue = isset($todos->tasks[$i + 1]) ? $todos->tasks[$i + 1] : 0; } $this->dao->insert(TABLE_TODO)->data($todo)->autoCheck()->exec(); if (dao::isError()) { echo js::error(dao::getError()); die(js::reload('parent')); } } else { unset($todos->types[$i]); unset($todos->pris[$i]); unset($todos->names[$i]); unset($todos->descs[$i]); unset($todos->begins[$i]); unset($todos->ends[$i]); } } }
public function sync2db($config) { $ldapUsers = $this->getUsers($config); $user = new stdclass(); $account = ''; $i = 0; for (; $i < $ldapUsers['count']; $i++) { $user->account = $ldapUsers[$i][$config->uid][0]; $user->email = $ldapUsers[$i][$config->mail][0]; $user->realname = $ldapUsers[$i][$config->name][0]; $account = $this->dao->select('*')->from(TABLE_USER)->where('account')->eq($user->account)->fetch('account'); if ($account == $user->account) { $this->dao->update(TABLE_USER)->data($user)->where('account')->eq($user->account)->autoCheck()->exec(); } else { $this->dao->insert(TABLE_USER)->data($user)->autoCheck()->exec(); } if (dao::isError()) { echo js::error(dao::getError()); die(js::reload('parent')); } } return $i; }
public function updateDefaultPwd() { $data = fixer::input('post')->get(); $pwdList = $this->post->pwdList ? $this->post->pwdList : array(); if (!empty($pwdList)) { /* Initialize todos from the post data. */ foreach ($pwdList as $pwdID) { $pwd = $data->password[$pwdID]; if ('' === $pwd) { continue; } if ($pwdID > 0) { $this->updatePwd($pwdID, $pwd); } else { $this->setdefaultpwd($pwd); } } } if (dao::isError()) { echo js::error(dao::getError()); die(js::reload('parent')); } }
/** * User login, identify him and authorize him. * * @access public * @return void */ public function login($referer = '', $from = '') { $this->setReferer($referer); $loginLink = $this->createLink('user', 'login'); $denyLink = $this->createLink('user', 'deny'); /* Reload lang by lang of get when viewType is json. */ if ($this->app->getViewType() == 'json' and $this->get->lang and $this->get->lang != $this->app->getClientLang()) { $this->app->setClientLang($this->get->lang); $this->app->loadLang('user'); } /* If user is logon, back to the rerferer. */ if ($this->user->isLogon()) { if ($this->app->getViewType() == 'json') { $data = $this->user->getDataInJSON($this->app->user); die(helper::removeUTF8Bom(json_encode(array('status' => 'success') + $data))); } if (strpos($this->referer, $loginLink) === false and strpos($this->referer, $denyLink) === false and $this->referer) { die(js::locate($this->referer, 'parent')); } else { die(js::locate($this->createLink($this->config->default->module), 'parent')); } } /* Passed account and password by post or get. */ if (!empty($_POST) or isset($_GET['account']) and isset($_GET['password'])) { $account = ''; $password = ''; if ($this->post->account) { $account = $this->post->account; } if ($this->get->account) { $account = $this->get->account; } if ($this->post->password) { $password = $this->post->password; } if ($this->get->password) { $password = $this->get->password; } if ($this->user->checkLocked($account)) { $failReason = sprintf($this->lang->user->loginLocked, $this->config->user->lockMinutes); if ($this->app->getViewType() == 'json') { die(helper::removeUTF8Bom(json_encode(array('status' => 'failed', 'reason' => $failReason)))); } die(js::error($failReason)); } $user = $this->user->identify($account, $password); if ($user) { $this->user->cleanLocked($account); /* Authorize him and save to session. */ $user->rights = $this->user->authorize($account); $user->groups = $this->user->getGroups($account); $this->session->set('user', $user); $this->app->user = $this->session->user; $this->loadModel('action')->create('user', $user->id, 'login'); /* Keep login. */ if ($this->post->keepLogin) { $this->user->keepLogin($user); } /* Check password. */ if (isset($this->config->safe->mode) and $this->user->computePasswordStrength($password) < $this->config->safe->mode) { echo js::alert($this->lang->user->weakPassword); } /* Go to the referer. */ if ($this->post->referer and strpos($this->post->referer, $loginLink) === false and strpos($this->post->referer, $denyLink) === false) { if ($this->app->getViewType() == 'json') { $data = $this->user->getDataInJSON($user); die(helper::removeUTF8Bom(json_encode(array('status' => 'success') + $data))); } /* Get the module and method of the referer. */ if ($this->config->requestType == 'PATH_INFO') { $path = substr($this->post->referer, strrpos($this->post->referer, '/') + 1); $path = rtrim($path, '.html'); if (empty($path)) { $path = $this->config->requestFix; } list($module, $method) = explode($this->config->requestFix, $path); } else { $url = html_entity_decode($this->post->referer); $param = substr($url, strrpos($url, '?') + 1); list($module, $method) = explode('&', $param); $module = str_replace('m=', '', $module); $method = str_replace('f=', '', $method); } if (common::hasPriv($module, $method)) { die(js::locate($this->post->referer, 'parent')); } else { die(js::locate($this->createLink($this->config->default->module), 'parent')); } } else { if ($this->app->getViewType() == 'json') { $data = $this->user->getDataInJSON($user); die(helper::removeUTF8Bom(json_encode(array('status' => 'success') + $data))); } die(js::locate($this->createLink($this->config->default->module), 'parent')); } } else { $fails = $this->user->failPlus($account); if ($this->app->getViewType() == 'json') { die(helper::removeUTF8Bom(json_encode(array('status' => 'failed', 'reason' => $this->lang->user->loginFailed)))); } $remainTimes = $this->config->user->failTimes - $fails; if ($remainTimes <= 0) { die(js::error(sprintf($this->lang->user->loginLocked, $this->config->user->lockMinutes))); } else { if ($remainTimes <= 3) { die(js::error(sprintf($this->lang->user->lockWarning, $remainTimes))); } } die(js::error($this->lang->user->loginFailed)); } } else { if (!empty($this->config->global->showDemoUsers)) { $demoUsers = $this->user->getPairs('nodeleted, noletter, noempty, noclosed'); $this->view->demoUsers = $demoUsers; } $this->app->loadLang('misc'); $this->view->noGDLib = sprintf($this->lang->misc->noGDLib, common::getSysURL() . $this->config->webRoot); $this->view->title = $this->lang->user->login; $this->view->referer = $this->referer; $this->view->s = zget($this->config->global, 'sn'); $this->view->keepLogin = $this->cookie->keepLogin ? $this->cookie->keepLogin : '******'; $this->display(); } }
/** * Create a user. * * @access public * @return void */ public function create() { $this->checkPassword(); $user = fixer::input('post')->setForce('join', date('Y-m-d H:i:s'))->setForce('last', helper::now())->setForce('visits', 1)->setIF($this->post->password1 == false, 'password', '')->setIF($this->cookie->referer != '', 'referer', $this->cookie->referer)->setIF($this->cookie->referer == '', 'referer', '')->remove('admin, ip, fingerprint')->get(); $user->password = $this->createPassword($this->post->password1, $user->account); $this->dao->insert(TABLE_USER)->data($user, $skip = 'password1,password2')->autoCheck()->batchCheck($this->config->user->require->register, 'notempty')->check('account', 'unique')->check('account', 'account')->check('email', 'email')->check('email', 'unique')->exec(); if (commonModel::isAvailable('score')) { $viewType = $this->app->getViewType(); if (!dao::isError()) { $this->app->user->account = $this->post->account; $this->loadModel('score')->earn('register', '', '', 'REGISTER'); if ($viewType == 'json') { die('success'); } } else { if ($viewType == 'json' and dao::isError()) { die(js::error(dao::getError())); } } } }
/** * Batch edit user. * * @access public * @return void */ public function batchEdit() { if (empty($_POST['verifyPassword']) or md5($this->post->verifyPassword) != $this->app->user->password) { die(js::alert($this->lang->user->error->verifyPassword)); } $oldUsers = $this->dao->select('id, account')->from(TABLE_USER)->where('id')->in(array_keys($this->post->account))->fetchPairs('id', 'account'); $accountGroup = $this->dao->select('id, account')->from(TABLE_USER)->where('account')->in($this->post->account)->fetchGroup('account', 'id'); $accounts = array(); foreach ($this->post->account as $id => $account) { $users[$id]['account'] = $account; $users[$id]['realname'] = $this->post->realname[$id]; $users[$id]['commiter'] = $this->post->commiter[$id]; $users[$id]['email'] = $this->post->email[$id]; $users[$id]['join'] = $this->post->join[$id]; $users[$id]['dept'] = $this->post->dept[$id] == 'ditto' ? isset($prev['dept']) ? $prev['dept'] : 0 : $this->post->dept[$id]; $users[$id]['role'] = $this->post->role[$id] == 'ditto' ? isset($prev['role']) ? $prev['role'] : 0 : $this->post->role[$id]; if (isset($accountGroup[$account]) and count($accountGroup[$account]) > 1) { die(js::error(sprintf($this->lang->user->error->accountDupl, $id))); } if (in_array($account, $accounts)) { die(js::error(sprintf($this->lang->user->error->accountDupl, $id))); } if (!validater::checkAccount($users[$id]['account'])) { die(js::error(sprintf($this->lang->user->error->account, $id))); } if ($users[$id]['realname'] == '') { die(js::error(sprintf($this->lang->user->error->realname, $id))); } if ($users[$id]['email'] and !validater::checkEmail($users[$id]['email'])) { die(js::error(sprintf($this->lang->user->error->mail, $id))); } if (empty($users[$id]['role'])) { die(js::error(sprintf($this->lang->user->error->role, $id))); } $accounts[$id] = $account; $prev['dept'] = $users[$id]['dept']; $prev['role'] = $users[$id]['role']; } foreach ($users as $id => $user) { $this->dao->update(TABLE_USER)->data($user)->where('id')->eq((int) $id)->exec(); if ($user['account'] != $oldUsers[$id]) { $oldAccount = $oldUsers[$id]; $this->dao->update(TABLE_USERGROUP)->set('account')->eq($user['account'])->where('account')->eq($oldAccount)->exec(); if (strpos($this->app->company->admins, ',' . $oldAccount . ',') !== false) { $admins = str_replace(',' . $oldAccount . ',', ',' . $user['account'] . ',', $this->app->company->admins); $this->dao->update(TABLE_COMPANY)->set('admins')->eq($admins)->where('id')->eq($this->app->company->id)->exec(); } if (!dao::isError() and $this->app->user->account == $oldAccount) { $this->app->user->account = $users['account']; } } } }
/** * Batch update products. * * @access public * @return void */ public function batchUpdate() { $products = array(); $allChanges = array(); $oldProducts = $this->getByIdList($this->post->productIDList); foreach ($this->post->productIDList as $productID) { $products[$productID] = new stdClass(); $products[$productID]->name = $this->post->names[$productID]; $products[$productID]->code = $this->post->codes[$productID]; $products[$productID]->PO = $this->post->POs[$productID]; $products[$productID]->QD = $this->post->QDs[$productID]; $products[$productID]->RD = $this->post->RDs[$productID]; $products[$productID]->status = $this->post->statuses[$productID]; $products[$productID]->order = $this->post->orders[$productID]; } foreach ($products as $productID => $product) { $oldProduct = $oldProducts[$productID]; $this->dao->update(TABLE_PRODUCT)->data($product)->autoCheck()->batchCheck($this->config->product->edit->requiredFields, 'notempty')->check('name', 'unique', "id != {$productID} and deleted = '0'")->check('code', 'unique', "id != {$productID} and deleted = '0'")->where('id')->eq($productID)->exec(); if (dao::isError()) { die(js::error('product#' . $productID . dao::getError(true))); } $allChanges[$productID] = common::createChanges($oldProduct, $product); } $this->fixOrder(); return $allChanges; }
/** * Batch close story. * * @access public * @return void */ public function batchClose() { /* Init vars. */ $stories = array(); $allChanges = array(); $now = helper::now(); $storyIDList = $this->post->storyIDList ? $this->post->storyIDList : array(); /* Adjust whether the post data is complete, if not, remove the last element of $storyIDList. */ if ($this->session->showSuhosinInfo) { array_pop($storyIDList); } if (!empty($storyIDList)) { foreach ($storyIDList as $storyID) { $oldStory = $this->getById($storyID); $story->lastEditedBy = $this->app->user->account; $story->lastEditedDate = $now; $story->closedBy = $this->app->user->account; $story->closedDate = $now; $story->assignedTo = 'closed'; $story->assignedDate = $now; $story->status = 'closed'; $story->closedReason = $this->post->closedReasons[$storyID]; $story->duplicateStory = $this->post->duplicateStoryIDList[$storyID] ? $this->post->duplicateStoryIDList[$storyID] : $oldStory->duplicateStory; $story->childStories = $this->post->childStoriesIDList[$storyID] ? $this->post->childStoriesIDList[$storyID] : $oldStory->childStories; if ($story->closedReason == 'done') { $story->stage = 'released'; } if ($story->closedReason != 'done') { $story->plan = 0; } $stories[$storyID] = $story; unset($story); } foreach ($stories as $storyID => $story) { if (!$story->closedReason) { continue; } $oldStory = $this->getById($storyID); $this->dao->update(TABLE_STORY)->data($story)->autoCheck()->checkIF($story->closedReason == 'duplicate', 'duplicateStory', 'notempty')->checkIF($story->closedReason == 'subdivided', 'childStories', 'notempty')->where('id')->eq($storyID)->exec(); if (!dao::isError()) { $allChanges[$storyID] = common::createChanges($oldStory, $story); } else { die(js::error('story#' . $storyID . dao::getError(true))); } } } return $allChanges; }
/** * View a todo. * * @param int $todoID * @param string $from my|company * @access public * @return void */ public function view($todoID, $from = 'company') { $todo = $this->todo->getById($todoID, true); if (!$todo) { die(js::error($this->lang->notFound) . js::locate('back')); } /* Save the session. */ $this->session->set('taskList', $this->app->getURI(true)); $this->session->set('bugList', $this->app->getURI(true)); /* Set menus. */ $this->lang->todo->menu = $this->lang->user->menu; $this->lang->todo->menuOrder = $this->lang->user->menuOrder; $this->loadModel('user')->setMenu($this->user->getPairs(), $todo->account); $this->lang->company->menu->browseUser['subModule'] = 'todo'; $this->lang->set('menugroup.todo', $from); $this->view->title = "{$this->lang->todo->common} #{$todo->id} {$todo->name}"; $this->view->position[] = $this->lang->todo->view; $this->view->todo = $todo; $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); $this->view->users = $this->user->getPairs('noletter'); $this->view->actions = $this->loadModel('action')->getList('todo', $todoID); $this->view->from = $from; $this->display(); }
/** * View a release. * * @param int $releaseID * @access public * @return void */ public function view($releaseID, $type = 'story', $link = 'false', $param = '') { if ($type == 'story') { $this->session->set('storyList', $this->app->getURI(true)); } if ($type == 'bug') { $this->session->set('bugList', $this->app->getURI(true)); } $this->loadModel('story'); $this->loadModel('bug'); $release = $this->release->getById((int) $releaseID, true); if (!$release) { die(js::error($this->lang->notFound) . js::locate('back')); } $stories = $this->dao->select('*')->from(TABLE_STORY)->where('id')->in($release->stories)->andWhere('deleted')->eq(0)->fetchAll(); $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story'); $bugs = $this->dao->select('*')->from(TABLE_BUG)->where('id')->in($release->bugs)->andWhere('deleted')->eq(0)->fetchAll(); $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'linkedBug'); $build = $this->loadModel('build')->getById($release->build); $generatedBugs = array(); if ($build->project) { $generatedBugs = $this->dao->select('*')->from(TABLE_BUG)->where('deleted')->eq(0)->andWhere('product')->eq($release->product)->andWhere("(project = '" . (int) $build->project . "'" . (empty($build->id) ? '' : " OR CONCAT(',', openedBuild, ',') like '%,{$build->id},%'") . ")")->andWhere('status')->eq('active')->andWhere('toStory')->eq(0)->orderBy('id_desc')->fetchAll(); $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'newBugs'); } $this->commonAction($release->product); $products = $this->product->getPairs(); $this->view->title = "RELEASE #{$release->id} {$release->name}/" . $products[$release->product]; $this->view->position[] = $this->lang->release->view; $this->view->release = $release; $this->view->stories = $stories; $this->view->bugs = $bugs; $this->view->generatedBugs = $generatedBugs; $this->view->actions = $this->loadModel('action')->getList('release', $releaseID); $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->view->type = $type; $this->view->link = $link; $this->view->param = $param; $this->display(); }
public function editplan($todoID) { if (!empty($_POST)) { $changes = $this->todo->update($todoID); if (dao::isError()) { die(js::error(dao::getError())); } if ($changes) { $actionID = $this->loadModel('action')->create('todo', $todoID, 'edited'); $this->action->logHistory($actionID, $changes); } die(js::locate(inlink('view', "todoID={$todoID}"), 'parent')); } /* Judge a private todo or not, If private, die. */ $todo = $this->todo->getById($todoID); if ($todo->private and $this->app->user->account != $todo->account) { die('private'); } $header['title'] = $this->lang->my->common . $this->lang->colon . $this->lang->todo->edit; $position[] = $this->lang->todo->edit; $this->view->header = $header; $this->view->position = $position; $this->view->times = $this->todo->buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); $this->view->todo = $todo; $this->display(); }
/** * View a product. * * @param int $productID * @access public * @return void */ public function view($productID) { $this->product->setMenu($this->products, $productID); $product = $this->product->getStatByID($productID); $product->desc = $this->loadModel('file')->setImgSize($product->desc); if (!$product) { die(js::error($this->lang->notFound) . js::locate('back')); } $this->view->title = $product->name . $this->lang->colon . $this->lang->product->view; $this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name); $this->view->position[] = $this->lang->product->view; $this->view->product = $product; $this->view->actions = $this->loadModel('action')->getList('product', $productID); $this->view->users = $this->user->getPairs('noletter'); $this->view->groups = $this->loadModel('group')->getPairs(); $this->display(); }
/** * Send email. * * @param int $taskID * @param int $actionID * @access public * @return void */ public function sendmail($taskID, $actionID) { /* Set toList and ccList. */ $task = $this->task->getById($taskID); $projectName = $this->project->getById($task->project)->name; $toList = $task->assignedTo; $ccList = trim($task->mailto, ','); if ($toList == '') { if ($ccList == '') { return; } if (strpos($ccList, ',') === false) { $toList = $ccList; $ccList = ''; } else { $commaPos = strpos($ccList, ','); $toList = substr($ccList, 0, $commaPos); $ccList = substr($ccList, $commaPos + 1); } } elseif (strtolower($toList) == 'closed') { $toList = $task->finishedBy; } /* Get action info. */ $action = $this->loadModel('action')->getById($actionID); $history = $this->action->getHistory($actionID); $action->history = isset($history[$actionID]) ? $history[$actionID] : array(); /* Create the email content. */ $this->view->task = $task; $this->view->action = $action; $this->clear(); $mailContent = $this->parse($this->moduleName, 'sendmail'); /* Send emails. */ $this->loadModel('mail')->send($toList, $projectName . ':' . 'TASK#' . $task->id . $this->lang->colon . $task->name, $mailContent, $ccList); if ($this->mail->isError()) { echo js::error($this->mail->getError()); } }
/** * Import task from Bug. * * @param int $projectID * @access public * @return void */ public function importBug($projectID) { $this->loadModel('bug'); $this->loadModel('task'); $this->loadModel('story'); $now = helper::now(); $modules = $this->loadModel('tree')->getTaskOptionMenu($projectID); $bugToTasks = fixer::input('post')->get(); $bugs = $this->bug->getByList(array_keys($bugToTasks->import)); foreach ($bugToTasks->import as $key => $value) { $bug = $bugs[$key]; $task = new stdClass(); $task->project = $projectID; $task->story = $bug->story; $task->storyVersion = $bug->storyVersion; $task->module = isset($modules[$bug->module]) ? $bug->module : 0; $task->fromBug = $key; $task->name = $bug->title; $task->type = 'devel'; $task->pri = $bugToTasks->pri[$key]; $task->consumed = 0; $task->status = 'wait'; $task->desc = $this->lang->bug->resolve . ':' . '#' . html::a(helper::createLink('bug', 'view', "bugID={$key}"), sprintf('%03d', $key)); $task->openedDate = $now; $task->openedBy = $this->app->user->account; if (!empty($bugToTasks->estimate[$key])) { $task->estimate = $bugToTasks->estimate[$key]; $task->left = $task->estimate; } if (!empty($bugToTasks->assignedTo[$key])) { $task->assignedTo = $bugToTasks->assignedTo[$key]; $task->assignedDate = $now; } if (!$bug->confirmed) { $this->dao->update(TABLE_BUG)->set('confirmed')->eq(1)->where('id')->eq($bug->id)->exec(); } $this->dao->insert(TABLE_TASK)->data($task)->checkIF($bugToTasks->estimate[$key] != '', 'estimate', 'float')->exec(); if (dao::isError()) { echo js::error(dao::getError()); die(js::reload('parent')); } $taskID = $this->dao->lastInsertID(); if ($task->story != false) { $this->story->setStage($task->story); } $actionID = $this->loadModel('action')->create('task', $taskID, 'Opened', ''); $mails[$key] = new stdClass(); $mails[$key]->taskID = $taskID; $mails[$key]->actionID = $actionID; $this->action->create('bug', $key, 'Totask', '', $taskID); $this->dao->update(TABLE_BUG)->set('toTask')->eq($taskID)->where('id')->eq($key)->exec(); /* activate bug if bug postponed. */ if ($bug->status == 'resolved' && $bug->resolution == 'postponed') { $newBug = new stdclass(); $newBug->lastEditedBy = $this->app->user->account; $newBug->lastEditedDate = $now; $newBug->assignedDate = $now; $newBug->status = 'active'; $newBug->resolvedDate = '0000-00-00'; $newBug->resolution = ''; $newBug->resolvedBy = ''; $newBug->resolvedBuild = ''; $newBug->closedBy = ''; $newBug->closedDate = '0000-00-00'; $newBug->duplicateBug = '0'; $this->dao->update(TABLE_BUG)->data($newBug)->autoCheck()->where('id')->eq($key)->exec(); $this->dao->update(TABLE_BUG)->set('activatedCount = activatedCount + 1')->where('id')->eq($key)->exec(); $actionID = $this->action->create('bug', $key, 'Activated'); $changes = common::createChanges($bug, $newBug); $this->action->logHistory($actionID, $changes); } if (isset($task->assignedTo) and $task->assignedTo and $task->assignedTo != $bug->assignedTo) { $newBug = new stdClass(); $newBug->lastEditedBy = $this->app->user->account; $newBug->lastEditedDate = $now; $newBug->assignedTo = $task->assignedTo; $newBug->assignedDate = $now; $this->dao->update(TABLE_BUG)->data($newBug)->where('id')->eq($key)->exec(); if (dao::isError()) { die(js::error(dao::getError())); } $changes = common::createChanges($bug, $newBug); $actionID = $this->action->create('bug', $key, 'Assigned', '', $newBug->assignedTo); $this->action->logHistory($actionID, $changes); } } return $mails; }
/** * Edit a case. * * @param int $caseID * @access public * @return void */ public function edit($caseID, $comment = false) { $this->loadModel('story'); if (!empty($_POST)) { $changes = array(); $files = array(); if ($comment == false) { $changes = $this->testcase->update($caseID); if (dao::isError()) { die(js::error(dao::getError())); } $files = $this->loadModel('file')->saveUpload('testcase', $caseID); } if ($this->post->comment != '' or !empty($changes) or !empty($files)) { $this->loadModel('action'); $action = !empty($changes) ? 'Edited' : 'Commented'; $fileAction = ''; if (!empty($files)) { $fileAction = $this->lang->addFiles . join(',', $files) . "\n"; } $actionID = $this->action->create('case', $caseID, $action, $fileAction . $this->post->comment); $this->action->logHistory($actionID, $changes); } die(js::locate($this->createLink('testcase', 'view', "caseID={$caseID}"), 'parent')); } $case = $this->testcase->getById($caseID); if (empty($case->steps)) { $step = new stdclass(); $step->desc = ''; $step->expect = ''; $case->steps[] = $step; } $productID = $case->product; $currentModuleID = $case->module; $title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->edit; $position[] = html::a($this->createLink('testcase', 'browse', "productID={$productID}"), $this->products[$productID]); $position[] = $this->lang->testcase->common; $position[] = $this->lang->testcase->edit; /* Set menu. */ $this->testcase->setMenu($this->products, $productID); $this->view->title = $title; $this->view->position = $position; $this->view->productID = $productID; $this->view->productName = $this->products[$productID]; $this->view->moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0); $this->view->currentModuleID = $currentModuleID; $this->view->users = $this->user->getPairs('noletter'); $this->view->stories = $this->story->getProductStoryPairs($productID); $this->view->case = $case; $this->view->actions = $this->loadModel('action')->getList('case', $caseID); $this->display(); }
/** * Create a comapny, set admin. * * @access public * @return void */ public function grantPriv() { if ($this->post->password == '') { die(js::error($this->lang->install->errorEmptyPassword)); } /* Insert a company. */ $company = new stdclass(); $company->name = $this->post->company; $company->admins = ",{$this->post->account},"; $this->dao->insert(TABLE_COMPANY)->data($company)->autoCheck()->batchCheck('name', 'notempty')->exec(); if (!dao::isError()) { /* Set admin. */ $admin = new stdclass(); $admin->account = $this->post->account; $admin->realname = $this->post->account; $admin->password = md5($this->post->password); $admin->gender = ''; $this->dao->insert(TABLE_USER)->data($admin)->check('account', 'notempty')->exec(); /* Update group name and desc on dafault lang. */ $groups = $this->dao->select('*')->from(TABLE_GROUP)->orderBy('id')->fetchAll(); foreach ($groups as $group) { $data = zget($this->lang->install->groupList, $group->name, ''); if ($data) { $this->dao->update(TABLE_GROUP)->data($data)->where('id')->eq($group->id)->exec(); } } } }
/** * Save the email config. * * @access public * @return void */ public function save() { if (!empty($_POST)) { $mailConfig = new stdclass(); $mailConfig->smtp = new stdclass(); $mailConfig->turnon = $this->post->turnon; $mailConfig->mta = 'smtp'; $mailConfig->fromAddress = trim($this->post->fromAddress); $mailConfig->fromName = trim($this->post->fromName); $mailConfig->smtp->host = trim($this->post->host); $mailConfig->smtp->port = trim($this->post->port); $mailConfig->smtp->auth = $this->post->auth; $mailConfig->smtp->username = trim($this->post->username); $mailConfig->smtp->password = $this->post->password; $mailConfig->smtp->secure = $this->post->secure; $mailConfig->smtp->debug = $this->post->debug; $mailConfig->smtp->charset = $this->post->charset; /* The mail need openssl and curl extension when secure is tls. */ if ($mailConfig->smtp->secure == 'tls') { if (!extension_loaded('openssl')) { echo js::alert($this->lang->mail->noOpenssl); die(js::locate('back')); } if (!extension_loaded('curl')) { echo js::alert($this->lang->mail->noCurl); die(js::locate('back')); } } $this->loadModel('setting')->setItems('system.mail', $mailConfig); if (dao::isError()) { die(js::error(dao::getError())); } $this->session->set('mailConfig', ''); $this->view->title = $this->lang->mail->common . $this->lang->colon . $this->lang->mail->save; $this->view->position[] = html::a(inlink('index'), $this->lang->mail->common); $this->view->position[] = $this->lang->mail->save; $this->view->mailExist = $this->mail->mailExist(); $this->display(); } }
/** * Batch change the stage of story. * * @param string $stage * @access public * @return void */ public function batchChangeStage($stage) { $storyIDList = $this->post->storyIDList ? $this->post->storyIDList : die(js::locate($this->session->storyList, 'parent')); $allChanges = $this->story->batchChangeStage($storyIDList, $stage); if (dao::isError()) { die(js::error(dao::getError())); } foreach ($allChanges as $storyID => $changes) { $actionID = $this->action->create('story', $storyID, 'Edited'); $this->action->logHistory($actionID, $changes); $this->sendmail($storyID, $actionID); } die(js::locate($this->session->storyList, 'parent')); }
/** * Batch update bugs. * * @access public * @return array */ public function batchUpdate() { $bugs = array(); $allChanges = array(); $now = helper::now(); $data = fixer::input('post')->get(); $bugIDList = $this->post->bugIDList ? $this->post->bugIDList : array(); /* Adjust whether the post data is complete, if not, remove the last element of $bugIDList. */ if ($this->session->showSuhosinInfo) { array_pop($bugIDList); } if (!empty($bugIDList)) { /* Initialize bugs from the post data.*/ foreach ($bugIDList as $bugID) { $oldBug = $this->getByID($bugID); $bug = new stdclass(); $bug->lastEditedBy = $this->app->user->account; $bug->lastEditedDate = $now; $bug->type = $data->types[$bugID]; $bug->severity = $data->severities[$bugID]; $bug->pri = $data->pris[$bugID]; $bug->status = $data->statuses[$bugID]; $bug->title = $data->titles[$bugID]; $bug->assignedTo = $data->assignedTos[$bugID]; $bug->resolvedBy = $data->resolvedBys[$bugID]; $bug->resolution = $data->resolutions[$bugID]; $bug->duplicateBug = $data->duplicateBugs[$bugID] ? $data->duplicateBugs[$bugID] : $oldBug->duplicateBug; if ($bug->assignedTo != $oldBug->assignedTo) { $bug->assignedDate = $now; } if (($bug->resolvedBy != '' or $bug->resolution != '') and $oldBug->status != 'resolved') { $bug->resolvedDate = $now; } if ($bug->resolution != '' and $bug->resolvedBy == '') { $bug->resolvedBy = $this->app->user->account; } if ($bug->resolution != '' and $bug->status != 'closed') { $bug->status = 'resolved'; $bug->confirmed = 1; } if ($bug->resolution != '' and $bug->assignedTo == '') { $bug->assignedTo = $oldBug->openedBy; $bug->assignedDate = $now; } $bugs[$bugID] = $bug; unset($bug); } /* Update bugs. */ foreach ($bugs as $bugID => $bug) { $oldBug = $this->getByID($bugID); $this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->edit->requiredFields, 'notempty')->checkIF($bug->resolvedBy, 'resolution', 'notempty')->checkIF($bug->resolution == 'duplicate', 'duplicateBug', 'notempty')->where('id')->eq((int) $bugID)->exec(); if (!dao::isError()) { $allChanges[$bugID] = common::createChanges($oldBug, $bug); } else { die(js::error('bug#' . $bugID . dao::getError(true))); } } } return $allChanges; }
/** * Manage products. * * @param int $projectID * @access public * @return void */ public function manageProducts($projectID) { /* use first project if projectID does not exist. */ if (!isset($this->projects[$projectID])) { $projectID = key($this->projects); } $browseProjectLink = $this->createLink('project', 'browse', "projectID={$projectID}"); if (!empty($_POST)) { $this->project->updateProducts($projectID); if (dao::isError()) { dis(js::error(dao::getError())); } die(js::locate($browseProjectLink)); } $this->loadModel('product'); $project = $this->project->getById($projectID); /* Set menu. */ $this->project->setMenu($this->projects, $project->id); /* Title and position. */ $title = $this->lang->project->manageProducts . $this->lang->colon . $project->name; $position[] = html::a($browseProjectLink, $project->name); $position[] = $this->lang->project->manageProducts; $allProducts = $this->product->getPairs('noclosed|nocode'); $linkedProducts = $this->project->getProducts($project->id); // Merge allProducts and linkedProducts for closed product. $allProducts += $linkedProducts; $linkedProducts = join(',', array_keys($linkedProducts)); /* Assign. */ $this->view->title = $title; $this->view->position = $position; $this->view->allProducts = $allProducts; $this->view->linkedProducts = $linkedProducts; $this->display(); }
/** * Manage products. * * @param int $projectID * @access public * @return void */ public function manageProducts($projectID) { $browseProjectLink = $this->createLink('project', 'browse', "projectID={$projectID}"); if (!empty($_POST)) { $this->project->updateProducts($projectID); if (dao::isError()) { dis(js::error(dao::getError())); } die(js::locate($browseProjectLink)); } $this->loadModel('product'); $project = $this->project->getById($projectID); /* Set menu. */ $this->project->setMenu($this->projects, $project->id); /* Title and position. */ $header['title'] = $this->lang->project->manageProducts . $this->lang->colon . $project->name; $position[] = html::a($browseProjectLink, $project->name); $position[] = $this->lang->project->manageProducts; $allProducts = $this->product->getPairs(); $linkedProducts = $this->project->getProducts($project->id); $linkedProducts = join(',', array_keys($linkedProducts)); /* Assign. */ $this->view->header = $header; $this->view->position = $position; $this->view->allProducts = $allProducts; $this->view->linkedProducts = $linkedProducts; $this->display(); }