public function indexAjax()
 {
     $input = Input::requireParams('username');
     $username = $input->username;
     $id = (int) $this->getUser('id');
     $validator = Validator::create(array('username' => "required|unique:\\User,username,{$id},id", 'first_name' => 'max:80', 'last_name' => 'max:160', 'password' => 'min:5|max:32', 'password2' => 'identical:password', 'timezone' => 'required|max:80'));
     if ($validator->failed()) {
         return BootstrapUI::formResponse()->failedOn($validator);
     }
     $input = $validator->getParamsObj();
     $user = User::fetchOne($this->getUser('id'));
     $userSessionData = Session::get('user');
     $refresh = $user->timezone != $input->timezone;
     $user->username = $input->username;
     $user->first_name = $input->first_name;
     $user->last_name = $input->last_name;
     $user->timezone = $input->timezone;
     if ($input->password !== null && strlen($input->password) >= 5) {
         $user->pass = md5($input->password);
     }
     $user->save();
     foreach ($user->getData() as $key => $value) {
         $userSessionData[$key] = $value;
     }
     Session::set('user', $userSessionData);
     if ($refresh) {
         return BootstrapUI::formResponse()->refresh();
     } else {
         return BootstrapUI::formResponse();
     }
 }
Esempio n. 2
0
 public function __construct()
 {
     parent::__construct();
     $this->remove('icon');
     $this->set('__field_name', Input::post('__field_name'));
     $this->set('__field_id', Input::post('__field_id'));
     $this->set('__form_id', Input::post('__form_id'));
 }
 public function findAnyAjax()
 {
     $stackTraceId = Input::post('stack_trace_id');
     $total = Crash\Archive::count(array('stack_trace_id' => $stackTraceId));
     if ($total > 0) {
         $random = rand(0, $total - 1);
         $records = Crash\Archive::query()->field('id')->where('stack_trace_id', $stackTraceId)->limit($random, 1)->fetchAllObj();
         $id = $records[0]->id;
         return BootstrapUI::buttonRemoteResponse()->redirect(\Koldy\Url::href('report', $id));
     } else {
         return BootstrapUI::buttonRemoteResponse()->disableButton()->text('No reports');
     }
 }
 public function indexAjax()
 {
     $input = Input::requireParams('username', 'pass', 'r');
     if (($user = User::auth($input->username, $input->pass)) !== false) {
         $sessionData = $user->getData();
         $sessionData['previous_login'] = $user->last_login;
         $user->updateLoginStats();
         $sessionData['last_login'] = gmdate('Y-m-d H:i:s');
         Cookie::set('username', $input->username, time() + 3600 * 24 * 30);
         Log::info("User {$input->username} logged in with " . Request::userAgent());
         // some stats
         $sessionData['stats'] = array('new_stack_traces' => \Stack\Trace::getNewCount($sessionData['previous_login']));
         Session::set('user', $sessionData);
         return BootstrapUI::formResponse()->redirect(base64_decode($input->r));
     } else {
         Log::info("Invalid auth for '{$input->username}' with '{$input->pass}'");
         return BootstrapUI::formResponse()->failed('Wrong username or password');
     }
 }
 public function searchAction()
 {
     $title = 'Search results';
     if (sizeof(Input::get()) == 1) {
         if (Input::hasGet('provider_id')) {
             $e = Provider::fetchOne(Input::get('provider_id'));
             $title = "Search results for internet provider <strong>{$e->name}</strong>";
         } else {
             if (Input::hasGet('brand_id')) {
                 $e = Brand::fetchOne(Input::get('brand_id'));
                 $title = "Search results for brand <strong>{$e->name}</strong>";
             } else {
                 if (Input::hasGet('package_id')) {
                     $e = Package::fetchOne(Input::get('package_id'));
                     $title = "Search results for package <strong>{$e->name}</strong>";
                 } else {
                     if (Input::hasGet('package_version_id')) {
                         $e = Package\Version::fetchOne(Input::get('package_version_id'));
                         $p = Package::fetchOne($e->package_id);
                         $title = "Search results for <strong>{$p->name}</strong> version {$e->value}";
                     }
                 }
             }
         }
     }
     $packageId = (int) Input::get('package_id');
     $packageVersionId = (int) Input::get('package_version_id');
     $brandId = (int) Input::get('brand_id');
     $osVersionId = (int) Input::get('os_version_id');
     $countryId = (int) Input::get('country_id');
     $providerId = (int) Input::get('provider_id');
     $productId = (int) Input::get('product_id');
     $modelId = (int) Input::get('model_id');
     $dateFrom = Input::get('date_from');
     $dateTo = Input::get('date_to');
     $stackTraceId = (int) Input::get('stack_trace_id');
     $table = BootstrapUI::tableRemote()->title($title)->extraParams(array('package_id' => $packageId, 'package_version_id' => $packageVersionId, 'brand_id' => $brandId, 'os_version_id' => $osVersionId, 'country_id' => $countryId, 'provider_id' => $providerId, 'product_id' => $productId, 'model_id' => $modelId, 'date_from' => $dateFrom, 'date_to' => $dateTo, 'stack_trace_id' => $stackTraceId))->column('country_name', '', 20)->column('created_at', 'time', 85)->column('package_name', 'package')->column('package_version', 'version')->column('brand_name', 'brand')->column('os_version_name', 'OS version', 105)->column('country', '')->column('action', '', 30)->sortableColumns(array('created_at', 'package_name', 'package_version', 'brand_name', 'os_version_name', 'cnt'))->sortField('created_at', 'desc');
     $table->panel()->addHeaderElement(Bootstrap::button('Back')->color('red')->size('xs')->setAttribute('onclick', 'window.history.back()'));
     return View::create('base')->with('title', $title)->with('content', Bootstrap::row()->add(12, $table));
 }
 public function versionsAjax()
 {
     $packageId = (int) Input::post('package_id');
     if ($packageId <= 0) {
         Application::throwError(400, 'Bad request');
     }
     $resultSet = new Package\ResultSet\Version();
     $resultSet->setPackageId($packageId, Input::post('last'));
     $timeFrom = $resultSet->getFromTime();
     return BootstrapUI::tableRemoteResponse()->primaryKey('package_version_id')->column('total', function ($value, $row) {
         return \Bootstrap::label($value)->color('red');
     })->column('name')->column('action', function ($value, $row) use($packageId, $timeFrom) {
         return \Bootstrap::anchor(\Bootstrap::icon('search'), \Koldy\Url::href('reports', 'search', array('package_version_id' => $row['package_version_id'], 'date_from' => \Misc::userDate('Y-m-d H:i:s', strtotime($timeFrom)))))->title('Find reports with this package version')->asButton()->size('xs')->color('red');
     })->resultSet($resultSet)->handle();
 }
 /**
  * Update user settings if needed
  */
 public function editUserAjax()
 {
     // TODO: Finish this
     $params = Input::requireParams('id');
     $id = (int) $params->id;
     $user = User::fetchOne($id);
     if ($user === false) {
         return BootstrapUI::formResponse()->failed('Invalid user');
     }
     $validator = Validator::create(array('id' => 'required|integer', 'username' => "required|min:2|max:32|unique:\\User,username,{$id},id", 'first_name' => 'max:255', 'last_name' => 'max:255', 'pass' => 'min:5|max:255', 'pass2' => 'identical:pass', 'account_type' => 'required', 'timezone' => 'required'));
     if ($validator->failed()) {
         return BootstrapUI::formResponse()->failedOn($validator);
     }
     $params = $validator->getParamsObj();
     $data = $validator->getParams();
     unset($data['id'], $data['pass'], $data['pass2']);
     if ($params->pass !== null && strlen($params->pass) >= 5) {
         $data['pass'] = md5($params->pass);
     }
     if ($user->save($data)) {
         Log::info("Updated user #{$id} {$params->username}");
     }
     return BootstrapUI::formResponse();
 }
 public function getStackTraceAjax()
 {
     $params = Input::requireParams('id');
     $id = (int) $params->id;
     if ($id <= 0) {
         throw new Exception('Invalid ID');
     }
     $submit = Crash\Submit::fetchOne('id', $id);
     if ($submit === false) {
         throw new Exception('Can not find stack trace');
     }
     return Json::create(array('success' => true, 'stack_trace' => $submit->stack_trace));
 }
Esempio n. 9
0
 /**
  * Handle the request
  * @return \Bootstrap\Response\TableRemote
  */
 public function handle()
 {
     $this->params = Input::requireParams('page', 'limit', 'field', 'dir');
     $page = (int) $this->params->page;
     if ($page < 1) {
         $page = 1;
     }
     $limitPerPage = (int) $this->params->limit;
     $field = (string) trim($this->params->field);
     $this->resultSet->page($page, $limitPerPage)->orderBy($field, $this->params->dir);
     // check if this is request with search
     $search = trim((string) \Koldy\Input::post('search'));
     if ($search != '') {
         $fields = $this->searchFields !== null ? $this->searchFields : $this->columns;
         foreach ($fields as $field) {
             $this->resultSet->orWhere($field, "%{$search}%", null, 'LIKE');
         }
     }
     \Log::debug($this->resultSet);
     // get the rows of data
     $this->data = $this->resultSet->fetch();
     if (is_array($this->data)) {
         $this->tbody = array();
         foreach ($this->data as $row) {
             $this->tbody[] = "<tr data-id=\"{$row[$this->primaryKey]}\">";
             foreach ($this->columns as $column) {
                 $value = isset($row[$column]) ? $row[$column] : null;
                 if (isset($this->columnValueModifier[$column])) {
                     $fn = $this->columnValueModifier[$column];
                     $fnResult = $fn($value, $row);
                     $this->tbody[] = "<td>{$fnResult}</td>";
                 } else {
                     $value = strip_tags(stripslashes($value));
                     $this->tbody[] = "<td>{$value}</td>";
                 }
             }
             $this->tbody[] = '</tr>';
         }
         $this->tbody = implode("\n", $this->tbody);
     }
     // get the totals
     $total = (int) $this->resultSet->count();
     // get the info
     if ($total > 0) {
         $start = ($this->params->page - 1) * $this->params->limit + 1;
         $end = $start + $this->params->limit;
         if ($end > $total) {
             $end = $total;
         }
         /*$this->info = __('table.records.info', 'Showing {from} - {to} of {total}',
         			'The info below remote table about how many rows are visible. Variables are {from}, {to} and {total}',
         			array('from' => $start, 'to' => $end, 'total' => $total)
         		);*/
         $this->info = "Showing {$start} - {$end} of {$total}";
     } else {
         $this->info = 'No results';
     }
     // create pagination
     $this->pagination = new \Koldy\Pagination($this->params->page, $total);
     $this->pagination->setItemsPerPage(10)->setCssDefault('btn btn-primary btn-xs')->setCssSelected('btn-info');
     return $this;
 }