PHP Classes
elePHPant
Icontem

File: actions/get_messages.php

Recommend this page to a friend!
  Classes of Miguel Villaseņor  >  MKCS PHP Support Chat  >  actions/get_messages.php  >  Download  
File: actions/get_messages.php
Role: Example script
Content type: text/plain
Description: Example script
Class: MKCS PHP Support Chat
Chat with clients of a support site
Author: By
Last change:
Date: 2 years ago
Size: 1,123 bytes
 

Contents

Class file image Download
<?php
require_once "../classes/Client.php";
require_once
"../classes/Message.php";
require_once
"../classes/Chat.php";
session_start();
if(isset(
$_SESSION['client_id'])){
    if(isset(
$_POST['last_update'])){
       
$last_update=isset($_SESSION['last_update'])?$_SESSION['last_update']:$_SESSION['client_id'];
       
$response = array();
       
$client= Client::getClient($_SESSION['client_id']);
       
$chat= $client->getChat();
       
$messages=Message::getLatestMessages($last_update, $chat->id);
       
$last=end($messages);
        if(isset(
$last['date']))
           
$last_update=$last['date'];
      
       
$client_name = $chat->getClientName();
       
$user_name = $chat->getUserName();
       
       
$response['user_name']=$user_name;
       
$response['client_name']=$client_name;
       
$response['messages']=$messages;
       
$response['last_update']=$last_update;
       
$response['status']=200;
       
$_SESSION['last_update']=$last_update;
        echo
json_encode($response);
    }else{
        echo
"{status:400,message:$_POST[last_update]}";
    }
}else{
    echo
"{status:400}";
}

?>