Пример #1
0
 /**
  * Gets pending chats
  */
 public static function getInstance($identifier = 'default', $chathash = '')
 {
     if ($identifier == '' || $identifier == 'default') {
         $identifier = 'default';
         $items = self::getList(array('filter' => array('identifier' => $identifier)));
         if (empty($items)) {
             $chatboxData = erLhcoreClassModelChatConfig::fetch('chatbox_data');
             $data = (array) $chatboxData->data;
             $chatbox = new erLhcoreClassModelChatbox();
             $chatbox->identifier = $identifier;
             $chatbox->name = $data['chatbox_default_name'];
             $chat = new erLhcoreClassModelChat();
             $chat->status = erLhcoreClassModelChat::STATUS_CHATBOX_CHAT;
             $chat->time = time();
             $chat->setIP();
             $chat->hash = erLhcoreClassChat::generateHash();
             $chat->nick = $data['chatbox_default_opname'];
             $chat->referrer = isset($_GET['URLReferer']) ? $_GET['URLReferer'] : '';
             // Assign default department
             $departments = erLhcoreClassModelDepartament::getList(array('filter' => array('disabled' => 0)));
             $ids = array_keys($departments);
             $id = array_shift($ids);
             $chat->dep_id = $id;
             // Store chat
             erLhcoreClassChat::getSession()->save($chat);
             $chatbox->chat_id = $chat->id;
             $chatbox->saveThis();
             return $chatbox;
         } else {
             return array_shift($items);
         }
     } else {
         $chatboxData = erLhcoreClassModelChatConfig::fetch('chatbox_data');
         $data = (array) $chatboxData->data;
         $canCreate = $data['chatbox_auto_enabled'] == 1 ? true : false;
         if ($canCreate == false) {
             if (sha1($data['chatbox_secret_hash'] . sha1($data['chatbox_secret_hash'] . $identifier)) == $chathash) {
                 $canCreate = true;
             }
         }
         if ($canCreate == true) {
             $items = self::getList(array('filter' => array('identifier' => $identifier)));
             if (empty($items)) {
                 $chatbox = new erLhcoreClassModelChatbox();
                 $chatbox->identifier = $identifier;
                 $chatbox->name = $data['chatbox_default_name'];
                 $chat = new erLhcoreClassModelChat();
                 $chat->status = erLhcoreClassModelChat::STATUS_CHATBOX_CHAT;
                 $chat->time = time();
                 $chat->setIP();
                 $chat->hash = erLhcoreClassChat::generateHash();
                 $chat->nick = $data['chatbox_default_opname'];
                 $chat->referrer = isset($_GET['URLReferer']) ? $_GET['URLReferer'] : '';
                 // Assign default department
                 $departments = erLhcoreClassModelDepartament::getList();
                 $ids = array_keys($departments);
                 $id = array_shift($ids);
                 $chat->dep_id = $id;
                 // Store chat
                 erLhcoreClassChat::getSession()->save($chat);
                 $chatbox->chat_id = $chat->id;
                 $chatbox->saveThis();
                 return $chatbox;
             } else {
                 return array_shift($items);
             }
         } else {
             $items = self::getList(array('filter' => array('identifier' => $identifier)));
             if (!empty($items)) {
                 return array_shift($items);
             }
         }
         return false;
     }
 }
Пример #2
0
<?php

if (!$currentUser->validateCSFRToken($Params['user_parameters_unordered']['csfr'])) {
    die('Invalid CSFR Token');
    exit;
}
$chatbox = erLhcoreClassModelChatbox::fetch($Params['user_parameters']['id']);
$chatbox->removeThis();
erLhcoreClassModule::redirect('chatbox/list');
exit;