public function getTrackerStats() { $data = array('datasets' => array()); $start = Request::get('start', 'int') ?: -30; $end = Request::get('end', 'int') ?: 0; $sub_id = -1; $user_id = -1; $tracker = NULL; foreach ($_GET['sets'] as $set) { $tracker = isset($set['tracker']) ? intval($set['tracker']) : $tracker; $sub_id = isset($set['sub_id']) ? intval($set['sub_id']) : $sub_id; $user_id = isset($set['user_id']) ? intval($set['user_id']) : $user_id; if (empty($tracker)) { throw new \Exception('Invalid tracker'); } $data['datasets'][] = array('data' => array_values(Tracker::getHistory($tracker, $start, $end, $sub_id, $user_id)), 'label' => Tracker::getName($tracker)); } $data['labels'] = array(); $start += Time::today(); $end += Time::today(); for ($i = $start; $i <= $end; $i++) { $data['labels'][] = jdtogregorian($i); } Output::json($data); }
/** * Does not require encryption, uses token. */ public function post() { $user = ClientUser::getInstance()->id; // TODO: These can be spoofed. // A verification method is needed. $tracker = Request::post('tracker'); $sub = Request::post('id', 'int'); // Track. Tracker::trackEvent($tracker, $sub, $user); Output::json(Output::SUCCESS); }
public function getFields() { // TODO: REQUIRE ADMIN $cl = Request::get('criteria_list', 'explode', 'int'); $output = array(); if (!empty($cl)) { $fields = Database::getInstance()->select('message_criteria', array('message_criteria_id' => array('IN', $cl))); foreach ($fields as $f) { if (!empty($f['variables'])) { $values = Database::getInstance()->selectRow('message_message_criteria', array('message_id' => Request::get('message_id', 'int'), 'message_criteria_id' => $f['message_criteria_id'])); $output[] = array('criteria_id' => $f['message_criteria_id'], 'variables' => explode(',', $f['variables']), 'values' => json_decode($values['field_values'])); } } } Output::json(array('criteria' => $output)); }
public function postRegister() { $email = Request::post('email', 'email'); $pass = Request::post('password'); // Validate POST data if (!$this->validateData($email, $pass)) { // Immediately output all the errors Output::error("Invalid Data"); } // Register user $res = UserModel::register($email, $pass); if ($res['success']) { Output::json($res['data']); } else { Output::error($res['error']); } }
public function postUpdateDate() { if (ClientUser::getInstance()->isAdmin()) { $id = Request::post('id'); $key = Request::post('key'); $column = Request::post('column'); $table = Request::post('table'); $m = Request::post("date_m"); $d = Request::post("date_d"); $y = Request::post("date_y"); if ($m > 0 && $d > 0) { if ($y == 0) { $y = date("Y"); } $value = gregoriantojd($m, $d, $y); } else { $value = 0; } Database::getInstance()->update($table, array($column => $value), array($key => $id)); Output::json(Output::SUCCESS); } else { Output::json(Output::ACCESS_DENIED); } }
public function postSave() { $user = ClientUser::getInstance(); if (!$user->isAdmin()) { return $this->get(); } $page_id = Request::post('page_id', 'int'); $title = Request::post('title'); $url = Request::post('url', 'url'); // Create an array of the new values. $new_values = array('title' => $title, 'url' => !empty($url) ? $url : Scrub::url($title), 'keywords' => Request::post('keywords'), 'description' => Request::post('description'), 'site_map' => Request::post('sitemap', 'int'), 'body' => Request::post('page_body', 'html', '', '', true), 'last_update' => time(), 'layout' => Request::post('layout', 'int')); // Save the page. if ($page_id != 0) { Database::getInstance()->update('page', $new_values, array('page_id' => $page_id)); } else { $page_id = Database::getInstance()->insert('page', $new_values); } $output = array(); $output['url'] = $new_values['url']; $output['page_id'] = $page_id; $output['title'] = $title; Output::json($output); }
/** * Output the data. */ public function output() { Output::json(array('data' => $this->data, 'messages' => Messenger::getMessages(), 'errors' => Messenger::getErrors())); }
/** * Load and render the access denied page. */ public static function accessDenied() { Messenger::error('Access Denied'); // TODO : This can be simplified using the error function below. if (static::isJSONRequest()) { Output::json(); } else { Template::resetInstance(); $page = new Message(); $page->execute(); } exit; }
public function getAutocomplete() { // Initialize some variables. $this->loadMainFields(); $field = Request::get('field'); $string = Request::get('st'); $autocomplete = $this->fields[$field]['autocomplete']; $where = array(); if (!empty($autocomplete['search'])) { if (!is_array($autocomplete['search'])) { $autocomplete['search'] = array($autocomplete['search']); } $where = Database::getMultiFieldSearch($autocomplete['search'], explode(' ', $string)); } $results = Database::getInstance()->selectIndexed($this->fields[$field]['autocomplete']['table'], $autocomplete['field'], $where, array(), 'LIMIT 50'); if (!empty($autocomplete['display_value']) && is_callable($autocomplete['display_value'])) { array_walk($results, $autocomplete['display_value']); } Output::json(array('results' => $results)); }