protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null) { $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $type, $matches)) { $name = $uploadFileName = 'clipboard.' . $matches[1]; } else { $uploadFileName = $name; } if (!preg_match($this->options['accept_file_types_lhc'], $uploadFileName)) { $file->error = $this->get_error_message('accept_file_types'); return false; } $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range); if (empty($file->error)) { $fileUpload = new erLhcoreClassModelChatFile(); $fileUpload->size = $file->size; $fileUpload->type = $file->type; $fileUpload->name = $file->name; $fileUpload->date = time(); $fileUpload->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0; $fileUpload->upload_name = $name; $fileUpload->file_path = $this->options['upload_dir']; if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) { $fileUpload->chat_id = $this->options['chat']->id; } elseif (isset($this->options['online_user']) && $this->options['online_user'] instanceof erLhcoreClassModelChatOnlineUser) { $fileUpload->online_user_id = $this->options['online_user']->id; } $matches = array(); if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) { $fileUpload->extension = $matches[1]; } else { $partsFile = explode('.', $fileUpload->upload_name); $fileUpload->extension = end($partsFile); } $fileUpload->saveThis(); $file->id = $fileUpload->id; if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) { // Chat assign $chat = $this->options['chat']; // Format message $msg = new erLhcoreClassModelmsg(); $msg->msg = '[file=' . $file->id . '_' . md5($fileUpload->name . '_' . $fileUpload->chat_id) . ']'; $msg->chat_id = $chat->id; $msg->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0; if ($msg->user_id > 0 && isset($this->options['name_support'])) { $msg->name_support = (string) $this->options['name_support']; } $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); // Set last message ID if ($chat->last_msg_id < $msg->id) { $chat->last_msg_id = $msg->id; } $chat->has_unread_messages = 1; $chat->updateThis(); } $this->uploadedFile = $fileUpload; } return $file; }
public static function getList($paramsSearch = array()) { $paramsDefault = array('limit' => 32, 'offset' => 0); $params = array_merge($paramsDefault, $paramsSearch); $session = erLhcoreClassChat::getSession(); $q = $session->createFindQuery('erLhcoreClassModelmsg'); $conditions = array(); if (isset($params['filter']) && count($params['filter']) > 0) { foreach ($params['filter'] as $field => $fieldValue) { $conditions[] = $q->expr->eq($field, $q->bindValue($fieldValue)); } } if (isset($params['filterin']) && count($params['filterin']) > 0) { foreach ($params['filterin'] as $field => $fieldValue) { $conditions[] = $q->expr->in($field, $fieldValue); } } if (isset($params['filterlt']) && count($params['filterlt']) > 0) { foreach ($params['filterlt'] as $field => $fieldValue) { $conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue)); } } if (isset($params['filtergt']) && count($params['filtergt']) > 0) { foreach ($params['filtergt'] as $field => $fieldValue) { $conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue)); } } if (count($conditions) > 0) { $q->where($conditions); } $q->limit($params['limit'], $params['offset']); $q->orderBy(isset($params['sort']) ? $params['sort'] : 'id ASC'); $objects = $session->find($q); return $objects; }
public function saveThis() { if ($this->first_visit == 0) { $this->first_visit = time(); } if ($this->last_visit == 0) { $this->last_visit = time(); } erLhcoreClassChat::getSession()->saveOrUpdate($this); }
$definition = array('msg' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'unsafe_raw'), 'msgid' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'int', array('min_range' => 1))); $form = new ezcInputForm(INPUT_POST, $definition); if ($form->hasValidData('msg') && trim($form->msg) != '' && mb_strlen($form->msg) < (int) erLhcoreClassModelChatConfig::fetch('max_message_length')->current_value) { $db = ezcDbInstance::get(); $db->beginTransaction(); try { $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']); if ($chat->hash == $Params['user_parameters']['hash'] && ($chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT)) { $msg = erLhcoreClassModelmsg::fetch($form->msgid); if ($msg->chat_id == $chat->id && $msg->user_id == 0) { $msg->msg = trim($form->msg); if ($chat->chat_locale != '' && $chat->chat_locale_to != '') { erLhcoreClassTranslate::translateChatMsgVisitor($chat, $msg); } erLhcoreClassChat::getSession()->update($msg); $tpl = erLhcoreClassTemplate::getInstance('lhchat/syncuser.tpl.php'); $tpl->set('messages', array((array) $msg)); $tpl->set('chat', $chat); $tpl->set('sync_mode', isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : ''); $chat->operation_admin .= "lhinst.updateMessageRowAdmin({$chat->id},{$msg->id});\n"; $chat->user_typing = time(); $chat->user_typing_txt = htmlspecialchars_decode(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/updatemsguser', 'User has edited his last message'), ENT_QUOTES); $chat->updateThis(); echo json_encode(array('error' => 'f', 'msg' => trim($tpl->fetch()))); } } $db->commit(); } catch (Exception $e) { $db->rollback(); }
public static function getCount($params = array(), $table = 'lh_chat', $operation = 'COUNT(id)') { $session = erLhcoreClassChat::getSession(); $q = $session->database->createSelectQuery(); $q->select($operation)->from($table); $conditions = array(); if (isset($params['filter']) && count($params['filter']) > 0) { foreach ($params['filter'] as $field => $fieldValue) { $conditions[] = $q->expr->eq($field, $q->bindValue($fieldValue)); } } if (isset($params['filterin']) && count($params['filterin']) > 0) { foreach ($params['filterin'] as $field => $fieldValue) { $conditions[] = $q->expr->in($field, $fieldValue); } } if (isset($params['filterlt']) && count($params['filterlt']) > 0) { foreach ($params['filterlt'] as $field => $fieldValue) { $conditions[] = $q->expr->lt($field, $q->bindValue($fieldValue)); } } if (isset($params['filtergt']) && count($params['filtergt']) > 0) { foreach ($params['filtergt'] as $field => $fieldValue) { $conditions[] = $q->expr->gt($field, $q->bindValue($fieldValue)); } } if (isset($params['filterlte']) && count($params['filterlte']) > 0) { foreach ($params['filterlte'] as $field => $fieldValue) { $conditions[] = $q->expr->lte($field, $q->bindValue($fieldValue)); } } if (isset($params['filtergte']) && count($params['filtergte']) > 0) { foreach ($params['filtergte'] as $field => $fieldValue) { $conditions[] = $q->expr->gte($field, $q->bindValue($fieldValue)); } } if (isset($params['filterlike']) && count($params['filterlike']) > 0) { foreach ($params['filterlike'] as $field => $fieldValue) { $conditions[] = $q->expr->like($field, $q->bindValue('%' . $fieldValue . '%')); } } if (isset($params['customfilter']) && count($params['customfilter']) > 0) { foreach ($params['customfilter'] as $fieldValue) { $conditions[] = $fieldValue; } } if (count($conditions) > 0) { $q->where($conditions); } if (isset($params['use_index'])) { $q->useIndex($params['use_index']); } $stmt = $q->prepare(); $stmt->execute(); $result = $stmt->fetchColumn(); return $result; }
public static function fetch($msg_id) { $msg = erLhcoreClassChat::getSession()->load('erLhcoreClassModelmsg', (int) $msg_id); return $msg; }
<?php if (is_numeric($Params['user_parameters']['chat_id'])) { /* * If online user mode we have to make different check * */ $browse = false; if ($Params['user_parameters_unordered']['cobrowsemode'] == 'onlineuser') { $onlineUser = erLhcoreClassModelChatOnlineUser::fetch($Params['user_parameters']['chat_id']); $browse = erLhcoreClassCoBrowse::getBrowseInstanceByOnlineUser($onlineUser); } else { $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']); if (erLhcoreClassChat::hasAccessToRead($chat)) { $browse = erLhcoreClassCoBrowse::getBrowseInstance($chat); } } if ($browse instanceof erLhcoreClassModelCoBrowse) { if ($browse->modifications != '') { $changes = json_decode($browse->modifications); $changes[] = array('url' => $browse->url); $changes[] = array('lmsg' => $browse->mtime > 0 ? $browse->mtime_front : ''); $changes[] = array('finished' => array('status' => !$browse->is_sharing, 'text' => $browse->is_sharing == 0 ? erTranslationClassLhTranslation::getInstance()->getTranslation('cobrowse/browse', 'Screen sharing session has finished') : erTranslationClassLhTranslation::getInstance()->getTranslation('cobrowse/browse', 'Screen is shared'))); if ($browse->finished == 1) { $changes[] = array('clear' => true); } array_unshift($changes, array('base' => $browse->url)); echo json_encode($changes); $browse->modifications = ''; $browse->saveThis(); } else { $changes = array();
<?php // Set new chat owner $currentUser = erLhcoreClassUser::instance(); $currentUser->getUserID(); $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']); // Chat can be closed only by owner if ($chat->user_id == $currentUser->getUserID() || $currentUser->hasAccessTo('lhchat', 'allowcloseremote')) { if (!$currentUser->validateCSFRToken($Params['user_parameters_unordered']['csfr'])) { die('Invalid CSRF Token'); exit; } if ($chat->status != erLhcoreClassModelChat::STATUS_CLOSED_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_CLOSED_CHAT; $chat->chat_duration = erLhcoreClassChat::getChatDurationToUpdateChatID($chat->id); $userData = $currentUser->getUserData(true); $msg = new erLhcoreClassModelmsg(); $msg->msg = (string) $userData . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/closechatadmin', 'has closed the chat!'); $msg->chat_id = $chat->id; $msg->user_id = -1; $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); $chat->updateThis(); erLhcoreClassChat::updateActiveChats($chat->user_id); // Execute callback for close chat erLhcoreClassChat::closeChatCallback($chat, $userData); } } CSCacheAPC::getMem()->removeFromArray('lhc_open_chats', (int) $Params['user_parameters']['chat_id']); header('Location: ' . $_SERVER['HTTP_REFERER']); exit;
/** * 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; } }
<?php if (!isset($_SERVER['HTTP_X_CSRFTOKEN']) || !$currentUser->validateCSFRToken($_SERVER['HTTP_X_CSRFTOKEN'])) { echo json_encode(array('error' => 'true', 'result' => 'Invalid CSFR Token')); exit; } try { $file = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChatFile', $Params['user_parameters']['file_id']); if (($file->user_id == $currentUser->getUserID() || $file->chat !== false && $file->chat->user_id == $currentUser->getUserID()) && $currentUser->hasAccessTo('lhfile', 'file_delete_chat')) { $file->removeThis(); echo json_encode(array('error' => 'false')); exit; } else { throw new Exception('No permission to delete the file!'); } } catch (Exception $e) { echo json_encode(array('error' => 'true', 'result' => $e->getMessage())); exit; } exit; ?>
/** * Method override to delete proper archive messages * */ public static function fetch($chat_id) { $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChatArchive', (int) $chat_id); return $chat; }
if ($form->hasValidData('Delay')) { $Departament->delay = $form->Delay; } if ($form->hasValidData('DepartmentID')) { $Departament->department_id = $form->DepartmentID; if ($userDepartments !== true) { if (!in_array($Departament->department_id, $userDepartments)) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/cannedmsg', 'Please choose a department'); } } } else { // User has to choose a department if ($userDepartments !== true) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/cannedmsg', 'Please choose a department'); } else { $Departament->department_id = 0; } } if (count($Errors) == 0) { $Departament->msg = $form->Message; erLhcoreClassChat::getSession()->save($Departament); erLhcoreClassModule::redirect('chat/cannedmsg'); exit; } else { $tpl->set('errors', $Errors); } } $tpl->set('msg', $Departament); $tpl->set('limitDepartments', $userDepartments !== true ? array('filterin' => array('id' => $userDepartments)) : array()); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/cannedmsg', 'System configuration')), array('url' => erLhcoreClassDesign::baseurl('chat/cannedmsg'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/cannedmsg', 'Canned messages')), array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/cannedmsg', 'New canned message')));
/** * Append user departments filter * */ $departmentParams = array(); $userDepartments = erLhcoreClassUserDep::parseUserDepartmetnsForFilter($currentUser->getUserID()); if ($userDepartments !== true) { $departmentParams['filterin']['department_id'] = $userDepartments; } if (is_numeric($Params['user_parameters_unordered']['id']) && $Params['user_parameters_unordered']['action'] == 'delete') { // Delete selected canned message try { if (!$currentUser->validateCSFRToken($Params['user_parameters_unordered']['csfr'])) { die('Invalid CSRF Token'); exit; } $Msg = erLhcoreClassChat::getSession()->load('erLhcoreClassModelCannedMsg', (int) $Params['user_parameters_unordered']['id']); if ($userDepartments === true || in_array($Msg->department_id, $userDepartments)) { $Msg->removeThis(); } } catch (Exception $e) { // Do nothing } erLhcoreClassModule::redirect('chat/cannedmsg'); exit; } $pages = new lhPaginator(); $pages->serverURL = erLhcoreClassDesign::baseurl('chat/cannedmsg'); $pages->items_total = erLhcoreClassModelCannedMsg::getCount($departmentParams); $pages->setItemsPerPage(20); $pages->paginate(); $items = array();
<?php $currentUser = erLhcoreClassUser::instance(); if (!$currentUser->isLogged() && !$currentUser->authenticate($_POST['username'], $_POST['password'])) { exit; } $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']); if ($currentUser->hasAccessTo('lhchat', 'deleteglobalchat') || $currentUser->hasAccessTo('lhchat', 'deletechat') && $chat->user_id == $currentUser->getUserID()) { erLhcoreClassChat::getSession()->delete($chat); $q = ezcDbInstance::get()->createDeleteQuery(); // Messages $q->deleteFrom('lh_msg')->where($q->expr->eq('chat_id', $Params['user_parameters']['chat_id'])); $stmt = $q->prepare(); $stmt->execute(); // Transfered chats $q->deleteFrom('lh_transfer')->where($q->expr->eq('chat_id', $Params['user_parameters']['chat_id'])); $stmt = $q->prepare(); $stmt->execute(); } exit;
public static function changeStatus($params) { $changeStatus = $params['status']; $chat = $params['chat']; $userData = $params['user']; $allowCloseRemote = $params['allow_close_remote']; if ($changeStatus == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) { if ($chat->status != erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_ACTIVE_CHAT; $chat->wait_time = time() - $chat->time; } if ($chat->user_id == 0) { $chat->user_id = $userData->id; } $chat->updateThis(); } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_PENDING_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_PENDING_CHAT; $chat->support_informed = 0; $chat->has_unread_messages = 1; $chat->updateThis(); } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_CLOSED_CHAT && $chat->user_id == $userData->id || $allowCloseRemote == true) { if ($chat->status != erLhcoreClassModelChat::STATUS_CLOSED_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_CLOSED_CHAT; $chat->chat_duration = erLhcoreClassChat::getChatDurationToUpdateChatID($chat->id); $msg = new erLhcoreClassModelmsg(); $msg->msg = (string) $userData . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/closechatadmin', 'has closed the chat!'); $msg->chat_id = $chat->id; $msg->user_id = -1; $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); $chat->updateThis(); CSCacheAPC::getMem()->removeFromArray('lhc_open_chats', $chat->id); // Execute callback for close chat erLhcoreClassChat::closeChatCallback($chat, $userData); } } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_CHATBOX_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_CHATBOX_CHAT; erLhcoreClassChat::getSession()->update($chat); } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_OPERATORS_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_OPERATORS_CHAT; erLhcoreClassChat::getSession()->update($chat); } erLhcoreClassChat::updateActiveChats($chat->user_id); if ($chat->department !== false) { erLhcoreClassChat::updateDepartmentStats($chat->department); } }
erLhcoreClassChat::setTimeZoneByChat($chat); $tpl->set('survey', is_numeric($Params['user_parameters_unordered']['survey']) ? (int) $Params['user_parameters_unordered']['survey'] : false); $Result['chat'] = $chat; // User online if ($chat->user_status != 0) { $db = ezcDbInstance::get(); $db->beginTransaction(); $chat->support_informed = 1; $chat->user_typing = time() - 5; // Show for shorter period these status messages $chat->is_user_typing = 1; $chat->user_typing_txt = htmlspecialchars_decode(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/userjoined', 'Visitor has joined the chat from popup chat window!'), ENT_QUOTES); if ($chat->user_status == erLhcoreClassModelChat::USER_STATUS_PENDING_REOPEN && ($onlineuser = $chat->online_user) !== false) { $onlineuser->reopen_chat = 0; $onlineuser->saveThis(); } $chat->user_status = erLhcoreClassModelChat::USER_STATUS_JOINED_CHAT; erLhcoreClassChat::getSession()->update($chat); $db->commit(); } } else { $tpl->setFile('lhchat/errors/chatnotexists.tpl.php'); } } catch (Exception $e) { $tpl->setFile('lhchat/errors/chatnotexists.tpl.php'); } $Result['content'] = $tpl->fetch(); $Result['pagelayout'] = 'userchat'; $Result['is_sync_required'] = true; $Result['dynamic_height'] = true; $Result['path'] = array(array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chat', 'Chat started')));
public static function presendCannedMsg($chat) { $session = erLhcoreClassChat::getSession(); $q = $session->createFindQuery('erLhcoreClassModelCannedMsg'); $q->where($q->expr->lOr($q->expr->eq('department_id', $q->bindValue($chat->dep_id)), $q->expr->lAnd($q->expr->eq('department_id', $q->bindValue(0)), $q->expr->eq('user_id', $q->bindValue(0))), $q->expr->eq('user_id', $q->bindValue($chat->user_id))), $q->expr->eq('auto_send', $q->bindValue(1))); $q->limit(1, 0); $q->orderBy('user_id DESC, position ASC, id ASC'); // Questions with matched URL has higher priority $items = $session->find($q); if (!empty($items)) { $cannedMsg = array_shift($items); $msg = new erLhcoreClassModelmsg(); $msg->msg = $cannedMsg->msg; $msg->chat_id = $chat->id; $msg->user_id = $chat->user_id; $msg->name_support = $chat->user->name_support; $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); if ($chat->last_msg_id < $msg->id) { $chat->last_msg_id = $msg->id; } $chat->updateThis(); } }
if ($Params['user_parameters_unordered']['hash_resume'] != '') { list($chatID, $hash) = explode('_', $Params['user_parameters_unordered']['hash_resume']); } elseif ($Params['user_parameters_unordered']['vid'] != '') { $vid = erLhcoreClassModelChatOnlineUser::fetchByVid($Params['user_parameters_unordered']['vid']); if ($vid !== false) { $chatID = $vid->chat_id; $checkHash = false; } else { echo json_encode(array('stored' => 'false')); exit; } } } try { if ($chatID > 0) { $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $chatID); } else { $chat = false; } if (($checkHash == true && $chat !== false && $chat->hash == $hash || $checkHash == false) && (is_object($vid) || ($chat !== false && $chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT))) { if (isset($_POST['data'])) { $imgData = base64_decode(str_replace('data:image/png;base64,', '', $_POST['data'])); $fileData = erLhcoreClassModelChatConfig::fetch('file_configuration'); $data = (array) $fileData->data; if (strlen($imgData) < $data['fs_max'] * 1024 && $imgData != '') { $storageID = false; if ($chat !== false) { $path = 'var/storage/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $chat->id . '/'; $storageID = $chat->id; } else { $path = 'var/storage/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $vid->id . '/';
public static function presendCannedMsg($chat) { $session = erLhcoreClassChat::getSession(); $q = $session->createFindQuery('erLhcoreClassModelCannedMsg'); $q->where($q->expr->lOr($q->expr->eq('department_id', $q->bindValue($chat->dep_id)), $q->expr->lAnd($q->expr->eq('department_id', $q->bindValue(0)), $q->expr->eq('user_id', $q->bindValue(0))), $q->expr->eq('user_id', $q->bindValue($chat->user_id))), $q->expr->eq('auto_send', $q->bindValue(1))); $q->limit(1, 0); $q->orderBy('user_id DESC, position ASC, id ASC'); // Questions with matched URL has higher priority $items = $session->find($q); if (!empty($items)) { $cannedMsg = array_shift($items); $replaceArray = array('{nick}' => $chat->nick, '{email}' => $chat->email, '{phone}' => $chat->phone, '{operator}' => (string) $chat->user->name_support); $additionalData = $chat->additional_data_array; foreach ($additionalData as $row) { if (isset($row->identifier) && $row->identifier != '') { $replaceArray['{' . $row->identifier . '}'] = $row->value; } } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.workflow.canned_message_replace', array('chat' => $chat, 'replace_array' => &$replaceArray)); $cannedMsg->setReplaceData($replaceArray); $msg = new erLhcoreClassModelmsg(); $msg->msg = $cannedMsg->msg_to_user; $msg->chat_id = $chat->id; $msg->user_id = $chat->user_id; $msg->name_support = $chat->user->name_support; $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); if ($chat->last_msg_id < $msg->id) { $chat->last_msg_id = $msg->id; } $chat->updateThis(); } }
public function saveThis() { erLhcoreClassChat::getSession()->saveOrUpdate($this); }
public function removeThis() { erLhcoreClassChat::getSession()->delete($this); }
public function updateThis() { erLhcoreClassChat::getSession()->update($this, $this->updateIgnoreColumns); }
/** * Executed in erLhcoreClassExtensionXmppserviceHandler::handleMessageFromOperator send message to user from operator. * if provided message is a command to operator is send command response * * @param erLhcoreClassModelChat $chat * * @param erLhcoreClassModelXMPPAccount $xmppUser * * @param string $body * * @throws Exception */ public static function sendMessageToChat(erLhcoreClassModelChat $chat, erLhcoreClassModelXMPPAccount $xmppUser, $body) { $db = ezcDbInstance::get(); $db->beginTransaction(); try { $user = $xmppUser->user; $messageUserId = $user->id; $ignoreMessage = false; // Predefine $statusCommand = array('processed' => false, 'process_status' => ''); if (strpos(trim($body), '!') === 0) { $statusCommand = erLhcoreClassChatCommand::processCommand(array('no_ui_update' => true, 'msg' => $body, 'chat' => &$chat)); if ($statusCommand['processed'] === true) { $messageUserId = -1; // Message was processed set as internal message $body = '[b]' . $userData->name_support . '[/b]: ' . $body . ' ' . ($statusCommand['process_status'] != '' ? '|| ' . $statusCommand['process_status'] : ''); } if (isset($statusCommand['ignore']) && $statusCommand['ignore'] == true) { $ignoreMessage = true; } if (isset($statusCommand['info'])) { $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice'); $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] ' . $statusCommand['info'])); } } if ($ignoreMessage == false) { $msg = new erLhcoreClassModelmsg(); $msg->msg = $body; $msg->chat_id = $chat->id; $msg->user_id = $messageUserId; $msg->time = time(); $msg->name_support = $user->name_support; if ($messageUserId > 0 && $chat->chat_locale != '' && $chat->chat_locale_to != '') { erLhcoreClassTranslate::translateChatMsgOperator($chat, $msg); } erLhcoreClassChat::getSession()->save($msg); // Set last message ID if ($chat->last_msg_id < $msg->id) { $userChange = ''; // Assign operator if chat does not have one if ($chat->user_id == 0) { $userChange = ',user_id = :user_id'; } $stmt = $db->prepare("UPDATE lh_chat SET status = :status, user_status = :user_status, last_msg_id = :last_msg_id{$userChange} WHERE id = :id"); $stmt->bindValue(':id', $chat->id, PDO::PARAM_INT); $stmt->bindValue(':last_msg_id', $msg->id, PDO::PARAM_INT); $changeStatus = false; if ($user->invisible_mode == 0) { if ($chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_ACTIVE_CHAT; $changeStatus = true; } } if ($chat->user_status == erLhcoreClassModelChat::USER_STATUS_CLOSED_CHAT) { $chat->user_status = erLhcoreClassModelChat::USER_STATUS_PENDING_REOPEN; if (($onlineuser = $chat->online_user) !== false) { $onlineuser->reopen_chat = 1; $onlineuser->saveThis(); } } $stmt->bindValue(':user_status', $chat->user_status, PDO::PARAM_INT); $stmt->bindValue(':status', $chat->status, PDO::PARAM_INT); if ($userChange != '') { $stmt->bindValue(':user_id', $msg->user_id, PDO::PARAM_INT); } $stmt->execute(); } // If chat status changes update statistic if ($changeStatus == true) { if ($chat->department !== false) { erLhcoreClassChat::updateDepartmentStats($chat->department); } erLhcoreClassChat::updateActiveChats($chat->user_id); } } $db->commit(); // Inform operator about command status if ($statusCommand['processed'] == true && $statusCommand['process_status'] != '') { $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice'); $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] ' . $statusCommand['process_status'])); } // For nodejs plugin erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.desktop_client_admin_msg', array('msg' => &$msg, 'chat' => &$chat)); // For general listeners erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.web_add_msg_admin', array('msg' => &$msg, 'chat' => &$chat)); } catch (Exception $e) { $db->rollback(); throw $e; } }