public function populateSlackUsers() { $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn || $user->role != USER_ROLE_ADMIN) { echo 'You are not authorized'; exit; } $helper = Lib::helper('slack'); $users = $helper->getUsers(); if ($users === false) { echo $helper->error; exit; } foreach ($users as $user) { $table = Lib::table('slackuser'); $table->load(array('slack_id' => $user->id)); $table->team_id = $user->team_id; $table->name = $user->name; $table->email = $user->email; $table->store(); } echo 'Imported ' . count($users) . ' users.'; exit; }
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 saveAssignees() { $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 || $user->role != USER_ROLE_ADMIN) { 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') { $projectAssignee = Lib::table('project_assignee'); $projectAssignee->load(array('user_id' => $setting->id, 'project_id' => $projectTable->id)); if ($setting->value) { $projectAssignee->store(); } else { $projectAssignee->delete(); } } return $this->success(); }
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 to($userid) { $userTable = Lib::table('user'); $userTable->load($userid); $table = Lib::table('slackuser'); if ($table->load(array('email' => $userTable->email))) { $this->channel = '@' . $table->name; } }
public static function send($data) { if (!$data['to'] || !$data['text']) { return false; } $slackTable = Lib::table('slackuser'); if ($slackTable->load(['email' => $data['to']])) { // Send slack $slackMessage = Lib::helper('slack')->newMessage(); $slackMessage->channel = '@' . $slackTable->name; $slackMessage->text = $data['text']; $messageKeys = ['username', 'icon_emoji']; foreach ($messageKeys as $mKey) { if (!empty($data[$mKey])) { $slackMessage->{$mKey} = $data[$mKey]; } } if (!empty($data['attachments'])) { $attachmentKeys = ['fallback', 'color', 'title', 'title_link', 'text']; foreach ($data['attachments'] as $attach) { $attachment = $slackMessage->newAttachment(); foreach ($attachmentKeys as $aKey) { if (!empty($attach[$aKey])) { $attachment->{$aKey} = $attach[$aKey]; } } if (!empty($attach['fields'])) { foreach ($attach['fields'] as $fieldKey => $fieldValue) { $attachment->newField($fieldKey, $fieldValue); } } } } $slackMessage->send(); } else { // Send email $mail = Lib::helper('mail')->newMessage(); $mail->recipientEmail = $data['to']; $mail->subject = 'Report Notification'; $mail->body = '<p>' . $data['text'] . '</p>'; $attachments = ''; foreach ($data['attachments'] as $attach) { if (empty($attach['title']) || empty($attach['title_link'])) { continue; } $attachments .= '<p><a href="' . $attach['title_link'] . '">' . $attach['title'] . '</a></p>'; } if (!empty($attachments)) { $mail->body .= '<p><strong><u>Attachments</u></strong></p>'; $mail->body .= $attachments; } $mail->body .= '<p style="font-size: 10px;">Do not reply to this email.</p>'; $mail->send(); } return true; }
public function attach($key, $file) { $fileObject = Lib::file($file['tmp_name'], $file['name']); $copiedFile = $fileObject->copy(Config::getBasePath() . '/' . Config::$attachmentFolder, $key . '-' . $file['name']); $attachmentTable = Lib::table('comment_attachment'); $attachmentTable->link($this); $attachmentTable->filename = $copiedFile->filename; $attachmentTable->name = $file['name']; $attachmentTable->store(); }
public function getCategory() { static $categories = []; if (!isset($categories[$this->category_id])) { $category = Lib::table('category'); $category->load($this->category_id); $categories[$this->category_id] = $category; } return $categories[$this->category_id]; }
public function main() { $key = Lib::hash(Config::$adminkey); $cookie = Lib::cookie(); $identifier = $cookie->get($key); $admin = Lib::table('admin'); $logged = !empty($identifier) && $admin->load(array('identifier' => $identifier)); $type = Req::get('type'); $ref = Req::get('ref'); if (!empty($ref)) { if ($logged) { $segments = explode('/', base64_decode($ref)); $base = array_shift($segments); $type = array_shift($segments); $subtype = array_shift($segments); $options = array(); if (!empty($type)) { $options['type'] = $type; } if (!empty($subtype)) { $options['subtype'] = $subtype; } Lib::redirect($base, $options); return; } return $this->form(); } if (!$logged) { if (empty($type)) { return $this->form(); } $options = array('view' => 'admin'); if (!empty($type)) { $options['type'] = $type; } $subtype = Req::get('subtype'); if (!empty($subtype)) { $options['subtype'] = $subtype; } $ref = Lib::url('admin', $options); return Lib::redirect('admin', array('view' => 'admin', 'ref' => base64_encode($ref))); } if (empty($type)) { $type = 'index'; } if (!is_callable(array($this, $type))) { return Lib::redirect('error'); } return $this->{$type}(); }
public function saveProjectTitle() { $keys = array('project-title', 'project-name'); $post = Req::post($keys); if (empty($post['project-name'])) { Lib::redirect('page', array('view' => 'embed')); } if (empty($post['project-title'])) { Lib::redirect('page', array('view' => 'embed', 'project' => $post['project-name'])); } $projectTable = Lib::table('project'); $projectTable->load(array('name' => $post['project-name'])); $projectTable->title = $post['project-title']; $projectTable->store(); Lib::redirect('page', array('view' => 'embed', 'project' => $post['project-name'])); }
public function update() { if (!Req::haspost(['id', 'name'])) { return $this->fail('Insufficient data.'); } $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(['identifier' => $identifier]); if (!$isLoggedIn || $user->role != USER_ROLE_ADMIN) { return $this->fail('You are not authorized.'); } $id = Req::post('id'); $name = Req::post('name'); $table = Lib::table('category'); if (!$table->load($id)) { return $this->false('Invalid data.'); } $table->name = $name; $table->store(); return $this->success(); }
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 getSettings($project = null) { $projectId = 0; if ($project instanceof ProjectTable) { $projectId = $project->id; } else { if (!empty($project) && $project !== 'all' && $project !== '-1') { $projectTable = Lib::table('project'); $projectTable->load(array('name' => $project)); $projectId = $projectTable->id; } if ($project === '-1') { $projectId = '-1'; } } $userSettingsTable = Lib::table('user_settings'); if (empty($project) || $project === 'all' || !$userSettingsTable->load(array('user_id' => $this->id, 'project_id' => $projectId))) { $userSettingsTable->load(array('user_id' => $this->id, 'project_id' => 0)); } return $userSettingsTable; }
public function css() { header('Content-Type: text/css'); $script = Req::get('script'); switch ($script) { case 'theme-custom': $identifier = Lib::cookie(Lib::hash(Config::$userkey)); $user = Lib::table('user'); $isLoggedIn = !empty($identifier) && $user->load(array('identifier' => $identifier)); if (!$isLoggedIn) { echo ''; return; } $project = Req::get('name'); $projectTable = Lib::table('project'); if ($project !== 'all' && $project !== '-1' && !$projectTable->load(array('name' => $project))) { echo ''; return; } $userSettingsTable = Lib::table('user_settings'); if ($project === '-1') { $projectTable->id = '-1'; } if (!$userSettingsTable->load(array('user_id' => $user->id, 'project_id' => $project === 'all' ? 0 : $projectTable->id)) && $project !== 'all') { $userSettingsTable->load(array('user_id' => $user->id, 'project_id' => 0)); } $userSettings = $userSettingsTable->getData(); $basecss = $this->output('css/theme-custom'); $keys = array(50, 100, 200, 300, 400, 500, 600, 700, 800, 900); $search = array(); $replace = array(); foreach ($keys as $key) { $search[] = '"@@color' . $key . '"'; $replace[] = '#' . $userSettings['color' . $key]; } $css = str_replace($search, $replace, $basecss); echo $css; break; } }
public function getRow($sql, $bindTable = true) { $result = $this->db->query($sql); if ($result === false) { throw new Exception($this->db->error); } if ($result->num_rows === 0) { return array(); } $tables = array(); if (!empty($this->tablename) && $bindTable) { while ($row = $result->fetch_object()) { $table = Lib::table($this->tablename); $table->bind($row); return $table; } } else { while ($row = $result->fetch_object()) { return $row; } } }
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); }
public function getItems($options = array()) { /* $options = array( 'project' => '', 'project_id' => '', 'user_id' => '', // or array() 'assignee_id' => '', // or array() 'state' => 0, 'order' => 'date', 'direction' => 'asc' ); */ $query = 'SELECT `a`.*, `c`.`filename`, `d`.`picture`, `d`.`nick`, `d`.`initial`, COUNT(`e`.`id`) AS `totalcomments` FROM ' . $this->db->qn($this->tablename) . ' AS `a`'; if (!empty($options['project'])) { $query = ' LEFT JOIN `project` AS `b` ON `a`.`project_id` = `b`.`id`'; } $query .= ' LEFT JOIN `screenshot` AS `c` ON `a`.`id` = `c`.`report_id`'; $query .= ' LEFT JOIN `user` AS `d` ON `a`.`user_id` = `d`.`id`'; $query .= ' LEFT JOIN `comment` AS `e` ON `a`.`id` = `e`.`report_id`'; $conditions = array(); if (!empty($options['project']) && $options['project'] !== 'all') { $conditions[] = '`b`.`name` = ' . $this->db->q($options['project']); } if (!empty($options['project_id']) && $options['project_id'] !== 'all') { $conditions[] = '`a`.`project_id` = ' . $this->db->q($options['project_id']); } if (!empty($options['user_id']) && $options['user_id'] !== 'all') { if (is_array($options['user_id'])) { $conditions[] = '`a`.`user_id` IN (' . implode(',', $this->db->q($options['user_id'])) . ')'; } else { $conditions[] = '`a`.`user_id` = ' . $this->db->q($options['user_id']); } } if (!empty($options['assignee_id']) && $options['assignee_id'] !== 'all') { if ($options['assignee_id'] === 'unassigned') { $options['assignee_id'] = 0; } if (is_array($options['assignee_id'])) { $conditions[] = '`a`.`assignee_id` IN (' . implode(',', $this->db->q($options['assignee_id'])) . ')'; } else { $conditions[] = '`a`.`assignee_id` = ' . $this->db->q($options['assignee_id']); } } if (isset($options['state']) && $options['state'] !== 'all') { $conditions[] = '`a`.`state` = ' . $this->db->q($options['state']); } $query .= $this->buildWhere($conditions); $query .= ' GROUP BY `c`.`id`, `a`.`id`'; $query .= $this->buildOrder($options, 'date', 'asc'); $result = $this->getResult($query, false); $reports = array(); foreach ($result as $row) { if (!isset($reports[$row->id])) { $reports[$row->id] = Lib::table('report'); $reports[$row->id]->bind($row, true); $reports[$row->id]->screenshots = array(); $reports[$row->id]->picture = $row->picture; $reports[$row->id]->nick = $row->nick; $reports[$row->id]->initial = $row->initial; $reports[$row->id]->totalcomments = $row->totalcomments; } if (!empty($row->filename)) { $reports[$row->id]->screenshots[] = $row->filename; } } return $reports; }
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 assign() { $keys = array('id', 'assigneeid'); 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); $reportTable = Lib::table('report'); if (!$reportTable->load($post['id'])) { return $this->fail('No such report.'); } $reportTable->assignee_id = $post['assigneeid']; $reportTable->store(); if (!empty($post['assigneeid']) && $post['assigneeid'] != $user->id) { $projectTable = Lib::table('project'); $projectTable->load($reportTable->project_id); $targetUser = Lib::table('user'); $targetUser->load($post['assigneeid']); $targetUserSettings = $targetUser->getSettings($projectTable)->getData(); if ($targetUserSettings['assign']) { $notificationData = ['to' => $targetUser->email, 'text' => $user->nick . ' assigned you a report ticket.', 'username' => 'Project Report Assignment', 'icon_emoji' => ':gift:', 'attachments' => [['fallback' => '<' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.', 'color' => '#00bcd4', 'title' => $projectTable->name, 'title_link' => $reportTable->getLink(), 'text' => $reportTable->content]]]; Lib::load('helper/notification'); NotificationHelper::send($notificationData); // $slackMessage = Lib::helper('slack')->newMessage(); // $slackMessage->to($post['assigneeid']); // $slackMessage->message($user->nick . ' assigned you a report ticket.'); // $slackMessage->username = '******'; // $slackMessage->icon_emoji = ':gift:'; // $attachment = $slackMessage->newAttachment(); // $attachment->fallback = '<' . $reportTable->getLink() . '|Report ticket ID ' . $reportTable->id . '>.'; // $attachment->color = '#00bcd4'; // $attachment->title = $projectTable->name; // $attachment->title_link = $reportTable->getLink(); // $attachment->text = $reportTable->content; // $slackMessage->send(); } } return $this->success(); }