<?php $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();
$chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']); if (erLhcoreClassChat::hasAccessToRead($chat)) { // User clicked button second time, and languages matches, that means he just stopped translation if ($chat->chat_locale == $visitorLanguage && $chat->chat_locale_to == $operatorLanguage) { $data['error'] = false; $tpl = erLhcoreClassTemplate::getInstance('lhkernel/alert_success.tpl.php'); $tpl->set('msg', erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Chat messages automatic translations has been stopped')); $data['result'] = $tpl->fetch(); $chat->chat_locale = ''; $chat->chat_locale_to = ''; $chat->updateThis(); $data['translation_status'] = false; echo json_encode($data); } else { try { $data = erLhcoreClassTranslate::setChatLanguages($chat, $visitorLanguage, $operatorLanguage); $data['error'] = false; $tpl = erLhcoreClassTemplate::getInstance('lhkernel/alert_success.tpl.php'); $tpl->set('msg', erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Messages has been translated')); $data['result'] = $tpl->fetch(); $data['translation_status'] = true; echo json_encode($data); } catch (Exception $e) { $data = array('error' => true); $tpl = erLhcoreClassTemplate::getInstance('lhkernel/validation_error.tpl.php'); $tpl->set('errors', array($e->getMessage(), erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Please choose translation languages manually and click Auto translate'))); $data['result'] = $tpl->fetch(); $data['translation_status'] = false; echo json_encode($data); } }
<?php $tpl = erLhcoreClassTemplate::getInstance('lhtranslation/configuration.tpl.php'); $translationData = erLhcoreClassModelChatConfig::fetch('translation_data'); $data = (array) $translationData->data; if (isset($_POST['DetectLanguage'])) { try { $tpl->set('detected_language', erLhcoreClassTranslate::detectLanguage($_POST['DetectLanguageText'])); } catch (Exception $e) { $tpl->set('errors', array($e->getMessage())); } } if (isset($_POST['TranslateToLanguage'])) { try { $tpl->set('translated_text', erLhcoreClassTranslate::translateTo($_POST['DetectLanguageText'], false, $_POST['LanguageTo'])); } catch (Exception $e) { $tpl->set('errors', array($e->getMessage())); } } if (isset($_POST['StoreLanguageSettings']) || isset($_POST['StoreLanguageSettingsTest'])) { $definition = array('translation_handler' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string'), 'enable_translations' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'), 'bing_client_id' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'bing_client_secret' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'google_api_key' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw')); if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) { erLhcoreClassModule::redirect('translation/configuration'); exit; } $Errors = array(); $form = new ezcInputForm(INPUT_POST, $definition); $Errors = array(); if ($form->hasValidData('translation_handler')) { $data['translation_handler'] = $form->translation_handler; } else {
if (isset($statusCommand['info'])) { $tpl = erLhcoreClassTemplate::getInstance('lhchat/lists/assistance_message.tpl.php'); $tpl->set('msg', array('msg' => $statusCommand['info'], 'time' => time())); $returnBody = $tpl->fetch(); } } } if ($ignoreMessage == false) { $msg = new erLhcoreClassModelmsg(); $msg->msg = $msgText; $msg->chat_id = $Params['user_parameters']['chat_id']; $msg->user_id = $messageUserId; $msg->time = time(); $msg->name_support = $userData->name_support; if ($messageUserId != -1 && $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) { $stmt = $db->prepare('UPDATE lh_chat SET status = :status, user_status = :user_status, last_msg_id = :last_msg_id WHERE id = :id'); $stmt->bindValue(':id', $Chat->id, PDO::PARAM_INT); $stmt->bindValue(':last_msg_id', $msg->id, PDO::PARAM_INT); if ($userData->invisible_mode == 0 && $messageUserId > 0) { // Change status only if it's not internal command if ($Chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT) { $Chat->status = erLhcoreClassModelChat::STATUS_ACTIVE_CHAT; } } // Chat can be reopened only if user did not ended chat explictly if ($Chat->user_status == erLhcoreClassModelChat::USER_STATUS_CLOSED_CHAT && $Chat->status_sub != erLhcoreClassModelChat::STATUS_SUB_USER_CLOSED_CHAT) {
/** * 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; } }