public function filter() { $keys = array('state', 'assignee', 'sort', 'project'); if (!Req::haspost($keys)) { return $this->fail('Insufficient data.'); } $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn) { return $this->fail('You are not authorized.'); } $post = Req::post($keys); $projectTable = Lib::table('project'); if ($post['project'] !== 'all' && !$projectTable->load(array('name' => $post['project']))) { return $this->fail('No such project.'); } $cookie = Lib::cookie(); foreach ($keys as $key) { $cookie->set('filter-' . $key, $post[$key]); } $reportModel = Lib::model('report'); $reports = $reportModel->getItems(array('state' => constant('STATE_' . strtoupper($post['state'])), 'assignee_id' => $post['assignee'], 'order' => 'date', 'direction' => $post['sort'], 'project_id' => $projectTable->id)); $userModel = Lib::model('user'); $assignees = $userModel->getProjectAssignees($projectTable->id); $html = ''; $view = Lib::view('embed'); foreach ($reports as $report) { $html .= $view->loadTemplate('report-item', array('report' => $report, 'assignees' => $assignees, 'user' => $user)); } return $this->success($html); }
public function main() { $this->meta[] = array('name' => 'google-signin-client_id', 'content' => Config::$googleClientId . '.apps.googleusercontent.com'); $cookie = Lib::cookie(); $identifier = $cookie->get(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); $this->set('user', $user); $this->set('isLoggedIn', $isLoggedIn); $this->js[] = $isLoggedIn ? 'inbox' : 'login'; if ($isLoggedIn) { array_shift($this->js); $id = Req::get('id'); if (empty($id)) { Lib::redirect('index'); } $report = Lib::table('report'); if (!$report->load($id)) { $this->template = 'no-report'; return; } $report->init(); $assignees = Lib::model('user')->getProjectAssignees($report->project_id); $projectTable = Lib::table('project'); $projectTable->load($report->project_id); $this->set('report', $report); $this->set('assignees', $assignees); $this->set('project', $projectTable); } }
public function main() { $filterProject = Req::get('project'); if (empty($filterProject)) { $this->template = 'empty-project'; return; } $projectTable = Lib::table('project'); if (!$projectTable->load(array('name' => $filterProject))) { $this->set('name', $filterProject); $this->template = 'new-project'; return; } $this->meta[] = array('name' => 'google-signin-client_id', 'content' => Config::$googleClientId . '.apps.googleusercontent.com'); $cookie = Lib::cookie(); $identifier = $cookie->get(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); $this->set('user', $user); $this->set('filterProject', $filterProject); $this->set('filterSettingsProject', $filterProject); $this->set('isLoggedIn', $isLoggedIn); if (!$isLoggedIn) { $this->js[] = 'login'; } if ($isLoggedIn) { $this->js[] = 'inbox'; $this->js[] = 'settings'; array_shift($this->js); $userModel = Lib::model('user'); $assignees = $userModel->getProjectAssignees($projectTable->id); $users = $userModel->getUsers(); $filterState = $cookie->get('filter-state', 'pending'); $filterAssignee = $cookie->get('filter-assignee', empty($assignees[$user->id]) ? 'all' : $user->id); $filterSort = $cookie->get('filter-sort', 'asc'); $reportModel = Lib::model('report'); $reports = $reportModel->getItems(array('state' => constant('STATE_' . strtoupper($filterState)), 'assignee_id' => $filterAssignee, 'order' => 'date', 'direction' => $filterSort, 'project_id' => $projectTable->id)); $userSettingsTable = Lib::table('user_settings'); if (!$userSettingsTable->load(array('user_id' => $user->id, 'project_id' => $projectTable->id))) { $userSettingsTable->load(array('user_id' => $user->id, 'project_id' => 0)); } $userSettings = $userSettingsTable->getData(); if ($userSettings['color'] !== 'cyan' && $userSettings['color'] !== 'custom') { $this->css[] = 'theme-' . str_replace(' ', '', $userSettings['color']); } $categories = Lib::model('category')->getCategories(['projectid' => $projectTable->id]); $this->set('filterState', $filterState); $this->set('filterAssignee', $filterAssignee); $this->set('filterSort', $filterSort); $this->set('reports', $reports); $this->set('assignees', $assignees); $this->set('userSettings', $userSettings); $this->set('users', $users); $this->set('projectTable', $projectTable); $this->set('categories', $categories); } }
public function form() { $ref = Req::get('ref'); $this->set('ref', $ref); $model = Lib::model('admin'); if (!$model->hasAdmins()) { $this->template = 'formcreate'; return; } $this->template = 'form'; }
public function init() { $owner = Lib::table('user'); $owner->load($this->user_id); $this->picture = $owner->picture; $this->nick = $owner->nick; $this->initial = $owner->initial; if (!empty($this->assignee_id)) { $assignee = Lib::table('user'); $assignee->load($this->assignee_id); $this->assignee = $assignee; } $screenshots = Lib::model('report')->getScreenshotsByReportId($this->id); $this->screenshots = array(); foreach ($screenshots as $screenshot) { $this->screenshots[] = $screenshot->filename; } $this->comments = Lib::model('comment')->getComments(array('report_id' => $this->id)); $this->totalcomments = count($this->comments); }
public function create() { $keys = array('username', 'password'); if (!Req::haspost($keys)) { return $this->fail(); } $referral = Req::post('referral'); if (empty($referral) && Lib::model('admin')->hasAdmins()) { return $this->fail(); } $post = Req::post($keys); extract($post); $admin = Lib::table('admin'); $admin->username = $username; $admin->setPassword($password); if (!$admin->store()) { return $this->fail(); } $admin->login(); return $this->success(); }
public function saveSettings() { $keys = array('project', 'setting'); if (!Req::haspost($keys)) { return $this->fail('Insufficient data.'); } $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn) { return $this->fail('You are not authorized.'); } $project = Req::post('project'); $setting = json_decode(Req::post('setting')); $projectTable = Lib::table('project'); if ($project !== 'all' && $project !== '-1' && !$projectTable->load(array('name' => $project))) { return $this->fail('No such project.'); } if ($project !== 'all') { $userSettings = Lib::table('user_settings'); if ($project === '-1') { $projectTable->id = '-1'; } if (!$userSettings->load(array('user_id' => $user->id, 'project_id' => $projectTable->id))) { $userSettings->load(array('user_id' => $user->id, 'project_id' => 0)); $userSettings->isNew = true; $userSettings->id = 0; $userSettings->project_id = $projectTable->id; } $data = $userSettings->getData(); $data[$setting->name] = $setting->value; $userSettings->data = $data; $userSettings->store(); } else { $settings = Lib::model('user_settings')->getSettings(array('user_id' => $user->id)); $userSettings = Lib::table('user_settings'); $userSettings->load(array('user_id' => $user->id, 'project_id' => 0)); $data = $userSettings->getData(); $data[$setting->name] = $setting->value; $userSettings->data = $data; $userSettings->store(); foreach ($settings as $row) { $data = $row->getData(); $data[$setting->name] = $setting->value; $row->data = $data; $row->store(); } } return $this->success(); }
public function sync() { if (!Req::haspost('reports', 'ids')) { return $this->fail('Insufficient data.'); } $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn) { return $this->fail('You are not authorized.'); } $reports = json_decode(Req::post('reports')); $ids = Req::post('ids'); $updated = array(); $commentModel = Lib::model('comment'); $comments = $commentModel->getComments(array('report_id' => $ids)); $commentsByReportId = array(); foreach ($comments as $comment) { $commentsByReportId[$comment->report_id][$comment->id] = $comment; } foreach ($reports as $id => $report) { $newTotalComments = empty($commentsByReportId[$id]) ? 0 : count($commentsByReportId[$id]); if ($report->totalComments == $newTotalComments) { continue; } $updated[$id] = array('totalComments' => $newTotalComments, 'comments' => array()); if (!$report->commentsLoaded) { continue; } $view = Lib::view('embed'); foreach ($commentsByReportId[$id] as $commentid => $newComment) { if (in_array($commentid, $report->comments)) { $updated[$id]['comments'][$commentid] = false; continue; } $updated[$id]['comments'][$commentid] = $view->loadTemplate('comment-item', array('comment' => $comment, 'user' => $user)); } } return $this->success($updated); }