Ejemplo n.º 1
0
 public function before()
 {
     $userAccess = new UserAccess();
     if (!$userAccess->isSupport()) {
         if ($this->request->isAjax()) {
             die('{ "ok" : false, "msg" : "Access denied" }');
         } else {
             Header::redirect(URL::baseUrl() . '/login');
         }
     }
     try {
         $pkSupportUserAccess = array('id_support_user' => $_SESSION['support_user']['id_user']);
         $supportUserAccess = $this->orm->support_user_access[$pkSupportUserAccess];
         if (!$supportUserAccess['maintain_user']) {
             $view = View::instance();
             $view->message = 'Access denied';
             $view->render('error');
             die;
         }
     } catch (Exception $e) {
         $view = View::instance();
         $view->message = 'Error occurred';
         $view->render('error');
         die;
     }
 }
Ejemplo n.º 2
0
 public function get_index()
 {
     $view = View::instance();
     try {
         if (isset($_SESSION['client_user'])) {
             $chat = $this->orm->chat[$_SESSION['client_user']['id_chat']];
             if ($chat['closed']) {
                 unset($_SESSION['client_user']);
             } elseif ($chat['id_support_user']) {
                 Header::redirect(URL::baseUrl() . '/conversation');
             } else {
                 Header::redirect(URL::baseUrl() . '/client/wait');
             }
         }
         $param = $this->orm->param();
         $param->select('value');
         $param->where('name', 'STATUS');
         $supportStatus = $param->fetch();
         $supportUser = $this->orm->support_user();
         $supportUser->where('active', 1);
         $supportUser->and('online', 1);
         $supportOnlineCount = $supportUser->count('id_support_user');
         if ($supportStatus['value'] == 1 && $supportOnlineCount > 0) {
             $view->render('form-client');
         } else {
             $view->render('offline');
         }
     } catch (Exception $e) {
         $view->render('offline');
     }
 }
Ejemplo n.º 3
0
 public function before()
 {
     $userAccess = new UserAccess();
     if (!$userAccess->isSupport()) {
         if ($this->request->isAjax()) {
             die('{ "ok" : false, "msg" : "Access denied" }');
         } else {
             Header::redirect(URL::baseUrl() . '/login');
         }
     }
 }
Ejemplo n.º 4
0
 public function get_signOut()
 {
     try {
         $idUser = @$_SESSION['support_user']['id_user'];
         if ($idUser) {
             $this->orm->support_user[$idUser]->update(array('online' => 0, 'typing' => 0, 'last_activity' => new NotORM_Literal('NOW()')));
         }
         if (isset($_SESSION['support_user']) && count($_SESSION) == 1) {
             unset($_SESSION['support_user']);
             session_unset();
             session_destroy();
         } else {
             unset($_SESSION['support_user']);
         }
         Header::redirect(URL::baseUrl() . '/login');
     } catch (Exception $e) {
         $view = View::instance();
         $view->render('error');
     }
 }
Ejemplo n.º 5
0
 public function get_index()
 {
     try {
         $idChat = @$this->request->get('id', FILTER_VALIDATE_INT);
         $userChat = new UserChat($this->orm, $idChat);
         if (!$userChat->isValid()) {
             if ($userChat->isSupport()) {
                 Header::redirect(URL::baseUrl() . '/login');
             } else {
                 Header::redirect(URL::baseUrl());
             }
         }
         $this->orm->{$userChat->table}[$userChat->idUser]->update(array('typing' => 0, 'last_activity' => new NotORM_Literal('NOW()')));
         $userChat->talkingTo()->sex = str_replace(array('M', 'F'), array('male', 'female'), $userChat->talkingTo()->sex);
         # Get the chat messages
         # ------------------------------------------------------------------
         $chatMessage = $this->orm->chat_message();
         $chatMessage->select('id_chat_message, created, message, sent_by');
         $chatMessage->where('id_chat', $userChat->idChat);
         $chatMessage->order('id_chat_message ASC');
         $messages = array();
         $format = new DateTimeFormat();
         $format->setSupHtmlSuffix(true);
         foreach ($chatMessage as $message) {
             $format->setValue($message['created']);
             $messages[] = array('who' => $userChat->type == $message['sent_by'] ? 'me' : 'you', 'id_chat_message' => $message['id_chat_message'], 'message' => nl2br(htmlspecialchars($message['message'])), 'datetime' => $format->format());
         }
         $view = View::instance();
         $view->idChat = $userChat->idChat;
         $view->messages = $messages;
         $view->talkingTo = $userChat->talkingTo();
         $view->render('conversation');
     } catch (Exception $e) {
         $view = View::instance();
         $view->render('error');
     }
 }
Ejemplo n.º 6
0
<?php

$this->layout = 'chat';
?>

<div class="error-page">
    
    <div class="info-bar">
        Sorry for the inconvenience
    </div>
    
    <div class="error-panel">
        
        <img src="<?php 
echo URL::baseUrl();
?>
/public/images/error-404.png" alt="" />
        
        <p>Page not found</p>
        
    </div>     
    
</div>
Ejemplo n.º 7
0
 /**
  * Validates the user session to allow or deny access
  *
  * @access private
  * @return void
  */
 private function validateSession()
 {
     if (!UserAccess::isClient()) {
         if ($this->request->isAjax()) {
             die('{ "ok" : false, "msg" : "Access denied" }');
         } else {
             Header::redirect(URL::baseUrl());
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Renderize a view
  * <b>Note:</b> if the layout is set inside a view it will
  * overrive the layout set as parameter
  *
  * @param string $view
  * @param string $layout = null
  * @param boolean $return = false
  * @access public
  * @return void | string
  */
 public function render($view, $layout = null, $return = false)
 {
     $view = preg_replace('/\\.php$/i', '', $view);
     if ($layout) {
         $this->layout = $layout;
     }
     ob_start();
     require_once "views/{$view}.php";
     $body = ob_get_contents();
     ob_clean();
     if ($this->layout) {
         if (file_exists("views/layout/{$this->layout}.php")) {
             $js = '';
             $css = '';
             $widgets = array();
             if ($this->js) {
                 $js = array_map(create_function('$path', 'return "<script src=\\"{$path}\\" type=\\"text/javascript\\"></script>";'), $this->js);
                 $js = implode(PHP_EOL, $js);
             }
             if ($this->css) {
                 $css = array_map(create_function('$path', 'return "<link href=\\"{$path}\\" rel=\\"stylesheet\\" type=\\"text/css\\" />";'), $this->css);
                 $css = implode(PHP_EOL, $css);
             }
             if (count($this->widget->getWidgets()) > 0) {
                 $widgets = array();
                 foreach ($this->widget->getWidgets() as $widget) {
                     foreach ($widget['files'] as $file) {
                         if (preg_match('/\\.js$/i', $file)) {
                             $widgets[] = '<script src="' . URL::baseUrl() . $file . '" type="text/javascript"></script>';
                         } elseif (preg_match('/\\.css$/i', $file)) {
                             $widgets[] = '<link href="' . URL::baseUrl() . $file . '" rel="stylesheet" type="text/css" />';
                         }
                     }
                 }
                 $widgets = implode(PHP_EOL, $widgets);
             } else {
                 $widgets = '';
             }
             require_once "views/layout/{$this->layout}.php";
             $body = ob_get_contents();
             ob_clean();
         }
     }
     if ($return) {
         ob_end_clean();
         return $body;
     } else {
         print $body;
         ob_end_flush();
     }
 }