Example #1
0
 /**
  * Register page.
  */
 public function registerAction()
 {
     $user = new User();
     if (Request::method() == 'post') {
         $user->set(['name' => Request::$post['name'], 'password' => Request::$post['password'], 'email' => Request::$post['email']]);
         if ($user->save()) {
             Request::redirectTo('/login');
         }
     }
     $this->set(compact('user'));
 }
Example #2
0
 /**
  * Edit status.
  */
 public function editAction($id)
 {
     $status = Status::find($id);
     // Make sure the status exists
     if (!$status) {
         return $this->show404();
     }
     // Check if the form has been submitted
     if (Request::method() == 'post') {
         $this->save($status);
     }
     $this->set(compact('status'));
 }
Example #3
0
 /**
  * Edit department.
  */
 public function editAction($id)
 {
     $department = Department::find($id);
     // Make sure the department exists
     if (!$department) {
         return $this->show404();
     }
     // Check if the form has been submitted
     if (Request::method() == 'post') {
         $this->save($department);
     }
     $this->set(compact('department'));
 }
Example #4
0
 /**
  * Edit user
  *
  * @param integer $id
  */
 public function editAction($id)
 {
     $user = User::find($id);
     // Make sure the user exists
     if (!$user) {
         return $this->show404();
     }
     // Check if the form has been submitted
     if (Request::method() == 'post') {
         $user->set(['name' => Request::$post['name'], 'email' => Request::$post['email'], 'group_id' => Request::$post['group']]);
         if ($user->save()) {
             Request::redirectTo('/admin/users');
         }
     }
     $this->set(compact('user'));
 }
Example #5
0
 public function indexAction()
 {
     // Check if the form has been submitted
     if (Request::method() == 'post') {
         foreach (Request::$post['settings'] as $setting => $value) {
             // Get setting
             $setting = Setting::find('setting', $setting);
             // If found, set value and save
             if ($setting) {
                 $setting->value = $value;
                 $setting->save();
             }
         }
         // Redirect
         Request::redirectTo('/admin/settings');
     }
 }
Example #6
0
 /**
  * Password page.
  */
 public function passwordAction()
 {
     // Check if form has been submitted
     if (Request::method() == 'post') {
         // Verify current password
         if ($this->user->verifyPassword(Request::$post['current_password'])) {
             // Update users password
             $this->user->updatePassword(Request::$post['new_password']);
             // Save and redirect
             if ($this->user->save()) {
                 Request::redirectTo('/account/password');
             }
         } else {
             $this->user->addError('password', l('errors.current_password_is_invalid'));
         }
     }
 }
Example #7
0
 /**
  * Update ticket.
  *
  * @param integer $id
  */
 public function updateAction($id)
 {
     if (Request::method() != 'post') {
         Request::redirectTo('/');
     }
     // Get the ticket
     $ticket = Ticket::find($id);
     // Ticket changes
     $changes = [];
     foreach (['department', 'status', 'priority'] as $property) {
         if ($ticket->{$property . '_id'} != Request::$post[$property]) {
             $change = ['property' => $property];
             switch ($property) {
                 case 'department':
                 case 'status':
                     $class = "\\Ticketer\\Models\\" . Inflector::classify($property);
                     $change['from'] = $class::find($ticket->{"{$property}_id"})->name;
                     $change['to'] = $class::find(Request::$post[$property])->name;
                     break;
                 case 'priority':
                     $change['from'] = getPriorityName($ticket->priority_id);
                     $change['to'] = getPriorityName(Request::$post['priority']);
                     break;
             }
             $changes[] = $change;
         }
     }
     // Update ticket properties
     $ticket->set(['department_id' => Request::$post['department'], 'status_id' => Request::$post['status'], 'priority_id' => Request::$post['priority']]);
     // Ticket reply
     $reply = new TicketReply(['message' => Request::$post['message'], 'user_id' => $this->currentUser->id, 'ticket_id' => $ticket->id, 'changes' => json_encode($changes)]);
     if (count($changes) or Request::$post['message'] != '') {
         if ($reply->save() and $ticket->save()) {
             Request::redirectTo($ticket->href());
         }
     } else {
         Request::redirectTo($ticket->href());
     }
     $this->set(compact('ticket', 'reply'));
     $this->render['view'] = 'tickets/view';
 }
Example #8
0
 /**
  * Routes the request to the controller.
  *
  * @param Request $request
  */
 public static function process(Request $request)
 {
     $uri = "/" . trim($request->pathInfo(), '/');
     // Check if this is root page
     if (isset(static::$routes['root']) and $request->pathInfo() == '/') {
         return static::setRoute(static::$routes['root']);
     }
     // The fun begins
     foreach (static::$routes as $route) {
         // Replace tokens
         $route->route = str_replace(array_keys(static::$tokens), array_values(static::$tokens), $route->route);
         // Does the route match the request?
         $pattern = "#^{$route->route}" . '(?<extension>' . implode('|', static::$extensions) . ")?\$#";
         if (preg_match($pattern, $uri, $params)) {
             unset($params[0]);
             $route->params = array_merge($route->params, $params);
             $route->destination = preg_replace($pattern, $route->destination, $uri);
             // Merge params with defaults
             $route->params = array_merge($route->defaults, $route->params);
             if (in_array(strtolower($request->method()), $route->method)) {
                 return static::setRoute($route);
             }
         }
     }
     // No matches, try 404 route
     if (isset(static::$routes['404'])) {
         return static::set404();
     } else {
         throw new Exception("No routes found for '{$uri}'");
     }
 }