Exemplo n.º 1
0
 public function post_list()
 {
     try {
         $name = $this->request->post('name');
         $email = $this->request->post('email');
         $activeYes = $this->request->post('active_yes', FILTER_VALIDATE_BOOLEAN);
         $activeNo = $this->request->post('active_no', FILTER_VALIDATE_BOOLEAN);
         $onlineYes = $this->request->post('online_yes', FILTER_VALIDATE_BOOLEAN);
         $onlineNo = $this->request->post('online_no', FILTER_VALIDATE_BOOLEAN);
         $name = str_replace(array('%', '_'), array('\\%', '\\_'), $name);
         $email = str_replace(array('%', '_'), array('\\%', '\\_'), $email);
         $supportUser = $this->orm->support_user();
         $supportUser->select('id_support_user, name, sex, email');
         $supportUser->select('online, active, last_activity');
         $supportUser->where('name LIKE ?', "%{$name}%");
         $supportUser->and('email LIKE ?', "%{$email}%");
         if ($activeYes xor $activeNo) {
             $supportUser->and('active', $activeYes ? 1 : 0);
         }
         if ($onlineYes xor $onlineNo) {
             $supportUser->and('online', $onlineYes ? 1 : 0);
         }
         $dataTimeFormat = new DateTimeFormat();
         $dataTimeFormat->setSupHtmlSuffix(true);
         $users = array();
         foreach ($supportUser as $row) {
             $dataTimeFormat->setValue($row['last_activity']);
             $users[] = array('id_support_user' => $row['id_support_user'], 'name' => $row['name'], 'sex' => str_replace(array('M', 'F'), array('male', 'female'), $row['sex']), 'email' => $row['email'], 'online' => $row['online'], 'active' => $row['active'], 'last_activity' => $dataTimeFormat->format());
         }
         $view = View::instance();
         $view->users = $users;
         $view->render('partial/users-list');
     } catch (Exception $e) {
         print '
             <tr>
                 <td colspan="7">
                     <div class="result-error">Error occurred</div>
                 </td>
             </tr>
         ';
     }
 }
Exemplo n.º 2
0
 public function post_messages()
 {
     try {
         $idChat = $this->request->post('chat_id', FILTER_VALIDATE_INT);
         $lastMessageId = $this->request->post('last_message_id', FILTER_VALIDATE_INT);
         $userChat = new UserChat($this->orm, $idChat);
         if (!$userChat->isValid()) {
             exit;
         }
         $chatMessage = $this->orm->chat_message();
         $chatMessage->select('id_chat_message, created, message');
         $chatMessage->where('id_chat', $idChat);
         $chatMessage->and('id_chat_message > ?', $lastMessageId);
         $chatMessage->and('sent_by', $userChat->talkingTo()->type);
         $chatMessage->and('sent_by_id', $userChat->talkingTo()->idUser);
         $chatMessage->order('id_chat_message ASC');
         $messages = array();
         $format = new DateTimeFormat();
         $format->setSupHtmlSuffix(true);
         foreach ($chatMessage as $message) {
             $format->setValue($message['created']);
             $messages[] = array('id_chat_message' => $message['id_chat_message'], 'message' => nl2br(htmlspecialchars($message['message'])), 'datetime' => $format->format());
         }
         $view = View::instance();
         $view->messages = $messages;
         $view->render('partial/chat-messages');
     } catch (Exception $e) {
     }
 }