public static function unansweredChatWorkflow(erLhcoreClassModelChat &$chat) { $chat->na_cb_executed = 1; $chat->updateThis(); // Execute callback if it exists $extensions = erConfigClassLhConfig::getInstance()->getSetting('site', 'extensions'); $instance = erLhcoreClassSystem::instance(); erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.unread_chat_workflow', array('chat' => &$chat)); foreach ($extensions as $ext) { $callbackFile = $instance->SiteDir . '/extension/' . $ext . '/callbacks/unanswered_chat.php'; if (file_exists($callbackFile)) { include $callbackFile; } } }
public function __get($var) { switch ($var) { case 'mtime_front': return date('Ymd') == date('Ymd', $this->mtime) ? date(erLhcoreClassModule::$dateHourFormat, $this->mtime) : date(erLhcoreClassModule::$dateDateHourFormat, $this->mtime); break; case 'is_sharing': return $this->finished == 0 && $this->mtime > time() - 3600; break; case 'online_user': $this->online_user = false; if ($this->online_user_id > 0) { try { $this->online_user = erLhcoreClassModelChatOnlineUser::fetch($this->online_user_id); } catch (Exception $e) { $this->online_user = false; } } return $this->online_user; break; case 'chat': $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); return $this->chat; break; default: break; } }
public function __get($var) { switch ($var) { case 'chat': $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); return $this->chat; break; default: break; } }
public function __get($var) { switch ($var) { case 'mtime_front': return date('Ymd') == date('Ymd', $this->mtime) ? date(erLhcoreClassModule::$dateHourFormat, $this->mtime) : date(erLhcoreClassModule::$dateDateHourFormat, $this->mtime); break; case 'is_sharing': return $this->finished == 0 && $this->mtime > time() - 3600; break; case 'chat': $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); return $this->chat; break; default: break; } }
public function __get($var) { switch ($var) { case 'file_path_server': $this->file_path_server = $this->file_path . $this->name; return $this->file_path_server; break; case 'security_hash': $this->security_hash = md5($this->name . '_' . $this->chat_id); return $this->security_hash; break; case 'chat': $this->chat = false; if ($this->chat_id > 0) { try { $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); } catch (Exception $e) { $this->chat = new erLhcoreClassModelChat(); } } return $this->chat; break; case 'user': $this->user = false; if ($this->user_id > 0) { try { $this->user = erLhcoreClassModelUser::fetch($this->user_id); } catch (Exception $e) { $this->user = false; } } return $this->user; break; case 'date_front': $this->date_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->date); return $this->date_front; break; default: break; } }
public function __get($var) { switch ($var) { case 'chat': $this->chat = false; if ($this->chat_id > 0) { try { $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); } catch (Exception $e) { erLhcoreClassChatbox::getSession()->delete($this); } } else { $this->chat = new erLhcoreClassModelChat(); $this->chat->hash = erLhcoreClassChat::generateHash(); } return $this->chat; break; default: break; } }
public static function canReopenDirectly($params = array()) { if (($chatPart = CSCacheAPC::getMem()->getSession('chat_hash_widget_resume', true)) !== false) { try { $parts = explode('_', $chatPart); $chat = erLhcoreClassModelChat::fetch($parts[0]); if (($chat->last_user_msg_time > time() - 600 || $chat->last_user_msg_time == 0) && (!isset($params['reopen_closed']) || $params['reopen_closed'] == 1 || $params['reopen_closed'] == 0 && $chat->status != erLhcoreClassModelChat::STATUS_CLOSED_CHAT)) { return array('id' => $parts[0], 'hash' => $parts[1]); } else { return false; } } catch (Exception $e) { return false; } } return false; }
$theme = erLhAbstractModelWidgetTheme::fetch($defaultTheme); $Result['theme'] = $theme; } catch (Exception $e) { } } } $tpl = erLhcoreClassTemplate::getInstance('lhsurvey/fill.tpl.php'); if (isset($Result['theme'])) { $tpl->set('theme', $Result['theme']); } try { if ((string) $Params['user_parameters_unordered']['hash'] != '') { $hash = $Params['user_parameters_unordered']['hash']; } if (is_numeric($Params['user_parameters_unordered']['chatid'])) { $chat = erLhcoreClassModelChat::fetch($Params['user_parameters_unordered']['chatid']); } erLhcoreClassChat::setTimeZoneByChat($chat); if ($chat->hash == $hash) { $survey = erLhAbstractModelSurvey::fetch($Params['user_parameters_unordered']['survey']); $surveyItem = erLhAbstractModelSurveyItem::getInstance($chat, $survey); if (isset($_POST['Vote'])) { $errors = erLhcoreClassSurveyValidator::validateSurvey($surveyItem, $survey); if (empty($errors)) { $surveyItem->saveOrUpdate(); $tpl->set('just_stored', true); } else { $tpl->set('errors', $errors); } } $tpl->set('chat', $chat);
/** * If user was redirected to contact form and he changed some default attributes we change then in intial chat * */ public static function updateInitialChatAttributes(erLhcoreClassModelChat &$prefillChat, erLhcoreClassModelChat $currentChat) { $attributesPrefill = array('nick', 'email', 'phone'); $attrChanged = false; foreach ($attributesPrefill as $attr) { if ($prefillChat->{$attr} == '' && $currentChat->{$attr} != '') { $prefillChat->{$attr} = $currentChat->{$attr}; $attrChanged = true; } } if ($attrChanged) { $prefillChat->saveThis(); } }
/** * 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; } }
} // Leave a message functionality $leaveamessage = (string) $Params['user_parameters_unordered']['leaveamessage'] == 'true' || isset($startDataFields['force_leave_a_message']) && $startDataFields['force_leave_a_message'] == true ? true : false; $tpl->set('forceoffline', false); $additionalParams = array(); if ((string) $Params['user_parameters_unordered']['offline'] == 'true' && $leaveamessage == true) { $additionalParams['offline'] = true; $tpl->set('forceoffline', true); } $tpl->set('leaveamessage', $leaveamessage); if (isset($_POST['StartChat']) && $disabled_department === false) { // Validate post data $Errors = erLhcoreClassChatValidator::validateStartChat($inputData, $startDataFields, $chat, $additionalParams); if (count($Errors) == 0 && !isset($_POST['switchLang'])) { $chat->setIP(); erLhcoreClassModelChat::detectLocation($chat); $statusGeoAdjustment = erLhcoreClassChat::getAdjustment(erLhcoreClassModelChatConfig::fetch('geoadjustment_data')->data_value, $inputData->vid); if ($statusGeoAdjustment['status'] == 'hidden') { // This should never happen exit('Chat not available in your country'); } if (isset($additionalParams['offline']) && $additionalParams['offline'] == true || $statusGeoAdjustment['status'] == 'offline') { erLhcoreClassChatMail::sendMailRequest($inputData, $chat, array('chatprefill' => isset($chatPrefill) ? $chatPrefill : false)); if (isset($chatPrefill) && $chatPrefill instanceof erLhcoreClassModelChat) { erLhcoreClassChatValidator::updateInitialChatAttributes($chatPrefill, $chat); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chat_offline_request', array('input_data' => $inputData, 'chat' => $chat, 'prefill' => array('chatprefill' => isset($chatPrefill) ? $chatPrefill : false))); $Result['parent_messages'][] = 'lh_callback:offline_request_cb'; $tpl->set('request_send', true); } else { $chat->time = time();
public function assignChatOsTicketId(erLhcoreClassModelChat &$chat, $ticketId) { /** * Remember created issue id * */ $variablesArray = $chat->chat_variables_array; $variablesArray['os_ticket_id'] = $ticketId; $chat->chat_variables = json_encode($variablesArray); $chat->chat_variables_array = $variablesArray; $chat->updateThis(); }
public function __get($var) { switch ($var) { case 'last_visit_front': return $this->last_visit_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->last_visit); break; case 'first_visit_front': return $this->first_visit_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->first_visit); break; case 'invitation': $this->invitation = false; if ($this->invitation_id > 0) { try { $this->invitation = erLhAbstractModelProactiveChatInvitation::fetch($this->invitation_id); } catch (Exception $e) { $this->invitation = false; } } return $this->invitation; break; case 'has_message_from_operator': return $this->message_seen == 0 && $this->operator_message != ''; break; case 'chat': $this->chat = false; if ($this->chat_id > 0) { try { $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); } catch (Exception $e) { // } } return $this->chat; break; case 'can_view_chat': $this->can_view_chat = false; $currentUser = erLhcoreClassUser::instance(); if ($this->operator_user_id == $currentUser->getUserID()) { $this->can_view_chat = true; // Faster way } else { if ($this->chat instanceof erLhcoreClassModelChat) { $this->can_view_chat = erLhcoreClassChat::hasAccessToRead($this->chat); } } return $this->can_view_chat; break; case 'operator_user': $this->operator_user = false; if ($this->operator_user_id > 0) { try { $this->operator_user = erLhcoreClassModelUser::fetch($this->operator_user_id); } catch (Exception $e) { } } return $this->operator_user; break; case 'operator_user_send': $this->operator_user_send = $this->operator_user !== false; return $this->operator_user_send; break; case 'operator_user_string': $this->operator_user_string = (string) $this->operator_user; return $this->operator_user_string; break; case 'time_on_site_front': $this->time_on_site_front = gmdate(erLhcoreClassModule::$dateHourFormat, $this->time_on_site); return $this->time_on_site_front; break; case 'tt_time_on_site_front': $this->tt_time_on_site_front = null; $diff = $this->tt_time_on_site; $days = floor($diff / (3600 * 24)); $hours = floor(($diff - $days * 3600 * 24) / 3600); $minits = floor(($diff - $hours * 3600 - $days * 3600 * 24) / 60); $seconds = $diff - $hours * 3600 - $minits * 60 - $days * 3600 * 24; if ($days > 0) { $this->tt_time_on_site_front = $days . ' d.'; } elseif ($hours > 0) { $this->tt_time_on_site_front = $hours . ' h.'; } elseif ($minits > 0) { $this->tt_time_on_site_front = $minits . ' m.'; } elseif ($seconds >= 0) { $this->tt_time_on_site_front = $seconds . ' s.'; } return $this->tt_time_on_site_front; break; case 'last_visit_seconds_ago': $this->last_visit_seconds_ago = time() - $this->last_visit; return $this->last_visit_seconds_ago; break; case 'last_check_time_ago': $this->last_check_time_ago = time() - $this->last_check_time; return $this->last_check_time_ago; break; case 'visitor_tz_time': $this->visitor_tz_time = '-'; if ($this->visitor_tz != '') { $date = new DateTime(null, new DateTimeZone($this->visitor_tz)); $this->visitor_tz_time = $date->format(erLhcoreClassModule::$dateHourFormat); } return $this->visitor_tz_time; break; case 'lastactivity_ago': $this->lastactivity_ago = ''; if ($this->last_visit > 0) { $periods = array("s.", "m.", "h.", "d.", "w.", "m.", "y.", "dec."); $lengths = array("60", "60", "24", "7", "4.35", "12", "10"); $difference = time() - $this->last_visit; for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) { $difference /= $lengths[$j]; } $difference = round($difference); $this->lastactivity_ago = "{$difference} {$periods[$j]}"; } return $this->lastactivity_ago; break; case 'screenshot': $this->screenshot = false; if ($this->screenshot_id > 0) { try { $this->screenshot = erLhcoreClassModelChatFile::fetch($this->screenshot_id); } catch (Exception $e) { } } return $this->screenshot; break; default: break; } }
$tpl->set('theme', $theme); } catch (Exception $e) { } } try { if (is_numeric((string) $Params['user_parameters_unordered']['chatid']) && $Params['user_parameters_unordered']['chatid'] > 0) { if ((string) $Params['user_parameters_unordered']['hash'] != '') { $hash = $Params['user_parameters_unordered']['hash']; } if (is_numeric($Params['user_parameters_unordered']['chatid'])) { $chat = erLhcoreClassModelChat::fetch($Params['user_parameters_unordered']['chatid']); } } else { if ((string) $Params['user_parameters_unordered']['hash'] != '') { list($chatID, $hash) = explode('_', $Params['user_parameters_unordered']['hash']); $chat = erLhcoreClassModelChat::fetch($chatID); } } erLhcoreClassChat::setTimeZoneByChat($chat); if ($chat->hash == $hash) { $survey = erLhAbstractModelSurvey::fetch($Params['user_parameters_unordered']['survey']); if ($survey instanceof erLhAbstractModelSurvey) { $surveyItem = erLhAbstractModelSurveyItem::getInstance($chat, $survey); if (isset($_POST['Vote'])) { $errors = erLhcoreClassSurveyValidator::validateSurvey($surveyItem, $survey); if (empty($errors)) { $surveyItem->saveOrUpdate(); erLhcoreClassChatEventDispatcher::getInstance()->dispatch('survey.filled', array('chat' => &$chat, 'survey' => $survey, 'survey_item' => &$surveyItem)); $tpl->set('just_stored', true); } else { $tpl->set('errors', $errors);
$tpl->set('theme', $theme); } catch (Exception $e) { } } else { $defaultTheme = erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value; if ($defaultTheme > 0) { try { $theme = erLhAbstractModelWidgetTheme::fetch($defaultTheme); $tpl->set('theme', $theme); } catch (Exception $e) { } } } $responseArray = array(); try { $chat = erLhcoreClassModelChat::fetch($Params['user_parameters']['chat_id']); if ($chat->hash == $Params['user_parameters']['hash']) { // Main unasnwered chats callback if ($chat->na_cb_executed == 0 && $chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT && erLhcoreClassModelChatConfig::fetch('run_unaswered_chat_workflow')->current_value > 0) { $delay = time() - erLhcoreClassModelChatConfig::fetch('run_unaswered_chat_workflow')->current_value * 60; if ($chat->time < $delay) { erLhcoreClassChatWorkflow::unansweredChatWorkflow($chat); } } if ($chat->nc_cb_executed == 0 && $chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT) { $department = $chat->department; if ($department !== false) { $options = $department->inform_options_array; $delay = time() - $department->inform_delay; if ($chat->time < $delay) { erLhcoreClassChatWorkflow::newChatInformWorkflow(array('department' => $department, 'options' => $options), $chat);
<?php header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); header('Content-Type: application/json'); try { erLhcoreClassRestAPIHandler::validateRequest(); $chat = erLhcoreClassModelChat::fetch((int) $_GET['chat_id']); if (erLhcoreClassRestAPIHandler::hasAccessToRead($chat) == true) { erLhcoreClassRestAPIHandler::outputResponse(array('error' => false, 'messages' => erLhcoreClassChat::getPendingMessages($chat->id, isset($_GET['last_message_id']) ? (int) $_GET['last_message_id'] : 0))); } else { throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('lhrestapi/validation', 'You do not have permission to read this chat!')); } } catch (Exception $e) { echo json_encode(array('error' => true, 'result' => $e->getMessage())); } exit;
$validationFields = array(); $validationFields['Message'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); $form = new ezcInputForm(INPUT_POST, $validationFields); $Errors = array(); if (!$form->hasValidData('Message') || $form->Message == '') { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your message'); } elseif ($form->hasValidData('Message')) { $msg->msg = $form->Message; } if ($form->hasValidData('Message') && $form->Message != '' && mb_strlen($form->Message) > (int) erLhcoreClassModelChatConfig::fetch('max_message_length')->current_value) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Maximum') . ' ' . (int) erLhcoreClassModelChatConfig::fetch('max_message_length')->current_value . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'characters for a message'); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.before_startchatwithoperator', array('errors' => &$Errors)); if (count($Errors) == 0) { $currentUserData = $currentUser->getUserData(); $chat = new erLhcoreClassModelChat(); $chat->time = time(); $chat->status = erLhcoreClassModelChat::STATUS_OPERATORS_CHAT; $chat->setIP(); $chat->hash = erLhcoreClassChat::generateHash(); $chat->referrer = ''; $chat->session_referrer = ''; $chat->nick = $currentUserData->name . ' ' . $currentUserData->surname; $chat->user_id = $user->id; // Assign chat to receiver operator, this way he will get permission to open chat $chat->dep_id = erLhcoreClassUserDep::getDefaultUserDepartment(); // Set default department to chat creator, this way current user will get permission to open it // Store chat erLhcoreClassChat::getSession()->save($chat); // Store User Message $msg->chat_id = $chat->id;
<?php header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); header('Content-Type: application/json'); try { erLhcoreClassRestAPIHandler::validateRequest(); $chat = erLhcoreClassModelChat::fetch((int) $_GET['chat_id']); if (erLhcoreClassRestAPIHandler::hasAccessToRead($chat) == true) { erLhcoreClassRestAPIHandler::outputResponse(array('error' => false, 'chat' => erLhcoreClassModelChat::fetch((int) $_GET['chat_id']))); } else { throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('lhrestapi/validation', 'You do not have permission to read this chat!')); } } catch (Exception $e) { echo json_encode(array('error' => true, 'result' => $e->getMessage())); } exit;
if ((string) $Params['user_parameters_unordered']['vid'] != '') { $inputData->vid = (string) $Params['user_parameters_unordered']['vid']; } // Assign department instantly if ($inputData->departament_id > 0) { $tpl->set('department', $inputData->departament_id); } else { $tpl->set('department', false); } // Set time zone if script detected it if ($userInstance->visitor_tz != '') { erLhcoreClassModule::$defaultTimeZone = $userInstance->visitor_tz; date_default_timezone_set(erLhcoreClassModule::$defaultTimeZone); } $tpl->set('playsound', (string) $Params['user_parameters_unordered']['playsound'] == 'true' && !isset($_POST['askQuestion']) && erLhcoreClassModelChatConfig::fetch('sound_invitation')->current_value == 1); $chat = new erLhcoreClassModelChat(); $modeAppendTheme = ''; if (isset($Params['user_parameters_unordered']['theme']) && (int) $Params['user_parameters_unordered']['theme'] > 0) { try { $theme = erLhAbstractModelWidgetTheme::fetch($Params['user_parameters_unordered']['theme']); $Result['theme'] = $theme; $modeAppendTheme = '/(theme)/' . $theme->id; } catch (Exception $e) { } } else { $defaultTheme = erLhcoreClassModelChatConfig::fetch('default_theme_id')->current_value; if ($defaultTheme > 0) { try { $theme = erLhAbstractModelWidgetTheme::fetch($defaultTheme); $Result['theme'] = $theme; $modeAppendTheme = '/(theme)/' . $theme->id;
public function __get($var) { switch ($var) { case 'last_visit_front': return $this->last_visit_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->last_visit); break; case 'first_visit_front': return $this->first_visit_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->first_visit); break; case 'invitation': $this->invitation = false; if ($this->invitation_id > 0) { try { $this->invitation = erLhAbstractModelProactiveChatInvitation::fetch($this->invitation_id); } catch (Exception $e) { $this->invitation = false; } } return $this->invitation; break; case 'has_message_from_operator': return $this->message_seen == 0 && $this->operator_message != ''; break; case 'notes_intro': return $this->notes_intro = $this->notes != '' ? '[ ' . mb_substr($this->notes, 0, 50) . ' ]' . '<br/>' : ''; break; case 'chat': $this->chat = false; if ($this->chat_id > 0) { try { $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); } catch (Exception $e) { // } } return $this->chat; break; case 'can_view_chat': $this->can_view_chat = false; $currentUser = erLhcoreClassUser::instance(); if ($this->operator_user_id == $currentUser->getUserID()) { $this->can_view_chat = true; // Faster way } else { if ($this->chat instanceof erLhcoreClassModelChat) { $this->can_view_chat = erLhcoreClassChat::hasAccessToRead($this->chat); } } return $this->can_view_chat; break; case 'operator_user': $this->operator_user = false; if ($this->operator_user_id > 0) { try { $this->operator_user = erLhcoreClassModelUser::fetch($this->operator_user_id); } catch (Exception $e) { } } return $this->operator_user; break; case 'operator_user_send': $this->operator_user_send = $this->operator_user !== false; return $this->operator_user_send; break; case 'operator_user_string': $this->operator_user_string = (string) $this->operator_user; return $this->operator_user_string; break; case 'time_on_site_front': $this->time_on_site_front = gmdate(erLhcoreClassModule::$dateHourFormat, $this->time_on_site); return $this->time_on_site_front; break; case 'tt_time_on_site_front': $this->tt_time_on_site_front = null; $diff = $this->tt_time_on_site; $days = floor($diff / (3600 * 24)); $hours = floor(($diff - $days * 3600 * 24) / 3600); $minits = floor(($diff - $hours * 3600 - $days * 3600 * 24) / 60); $seconds = $diff - $hours * 3600 - $minits * 60 - $days * 3600 * 24; if ($days > 0) { $this->tt_time_on_site_front = $days . ' d.'; } elseif ($hours > 0) { $this->tt_time_on_site_front = $hours . ' h.'; } elseif ($minits > 0) { $this->tt_time_on_site_front = $minits . ' m.'; } elseif ($seconds >= 0) { $this->tt_time_on_site_front = $seconds . ' s.'; } return $this->tt_time_on_site_front; break; case 'last_visit_seconds_ago': $this->last_visit_seconds_ago = time() - $this->last_visit; return $this->last_visit_seconds_ago; break; case 'last_check_time_ago': $this->last_check_time_ago = time() - $this->last_check_time; return $this->last_check_time_ago; break; case 'visitor_tz_time': $this->visitor_tz_time = '-'; if ($this->visitor_tz != '') { $date = new DateTime(null, new DateTimeZone($this->visitor_tz)); $this->visitor_tz_time = $date->format(erLhcoreClassModule::$dateHourFormat); } return $this->visitor_tz_time; break; case 'lastactivity_ago': $this->lastactivity_ago = ''; if ($this->last_visit > 0) { $periods = array("s.", "m.", "h.", "d.", "w.", "m.", "y.", "dec."); $lengths = array("60", "60", "24", "7", "4.35", "12", "10"); $difference = time() - $this->last_visit; for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) { $difference /= $lengths[$j]; } $difference = round($difference); $this->lastactivity_ago = "{$difference} {$periods[$j]}"; } return $this->lastactivity_ago; break; case 'screenshot': $this->screenshot = false; if ($this->screenshot_id > 0) { try { $this->screenshot = erLhcoreClassModelChatFile::fetch($this->screenshot_id); } catch (Exception $e) { } } return $this->screenshot; break; case 'online_attr_system_array': $this->online_attr_system_array = array(); if ($this->online_attr_system != '') { $this->online_attr_system_array = json_decode($this->online_attr_system, true); } return $this->online_attr_system_array; break; case 'online_status': $this->online_status = 2; // Offline if (erLhcoreClassChat::$trackTimeout == 0) { erLhcoreClassChat::$trackTimeout = 15; } if (erLhcoreClassChat::$trackActivity == true) { if ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && $this->user_active == 1) { //User still on site, it does not matter that he have closed widget. $this->online_status = 0; // Online } elseif ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && $this->user_active == 0) { $this->online_status = 1; // Away } } else { if ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && time() - $this->last_user_msg_time < 300) { //User still on site, it does not matter that he have closed widget. $this->online_status = 0; // Online } elseif ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && time() - $this->last_user_msg_time >= 300) { $this->online_status = 1; // Away } } return $this->online_status; break; default: break; } }
if (isset($_POST['chats']) && is_array($_POST['chats']) && count($_POST['chats']) > 0) { $ReturnMessages = array(); $ReturnStatuses = array(); $tpl = erLhcoreClassTemplate::getInstance('lhchat/syncadmin.tpl.php'); $currentUser = erLhcoreClassUser::instance(); if (!isset($_SERVER['HTTP_X_CSRFTOKEN']) || !$currentUser->validateCSFRToken($_SERVER['HTTP_X_CSRFTOKEN'])) { echo json_encode(array('error' => 'true', 'result' => 'Invalid CSRF Token')); exit; } $db = ezcDbInstance::get(); while (true) { $db->beginTransaction(); try { foreach ($_POST['chats'] as $chat_id_list) { list($chat_id, $MessageID) = explode(',', $chat_id_list); $Chat = erLhcoreClassModelChat::fetch($chat_id); $Chat->updateIgnoreColumns = array('last_msg_id'); if (isset($hasAccessToReadArray[$chat_id]) || erLhcoreClassChat::hasAccessToRead($Chat)) { $hasAccessToReadArray[$chat_id] = true; if ($Chat->last_msg_id > (int) $MessageID && count($Messages = erLhcoreClassChat::getPendingMessages($chat_id, $MessageID)) > 0) { // If chat had flag that it contains unread messages set to 0 if ($Chat->has_unread_messages == 1 || $Chat->unread_messages_informed == 1) { $Chat->has_unread_messages = 0; $Chat->unread_messages_informed = 0; $Chat->saveThis(); } $newMessagesNumber = count($Messages); $tpl->set('messages', $Messages); $tpl->set('chat', $Chat); $msgText = ''; if ($userOwner == 'true') {
/** * handles messages from operator. * Workflow sounds like that * 1. Check that we can determine an operator * 2. Check to what messages was send, to chat or online visitor * 3. If message is send to online visitor check perphaps visitor has active chat * 4. If active chat found, send a message * 5. If active chat not found send message as proactive invitation * * @param array $params * */ public static function handleMessageFromOperator($params) { try { $parts = explode('.', $params['receiver']); if (isset($parts[1])) { $xmppUserLogin = $params['sender'] . '@' . $params['server']; $xmppUser = erLhcoreClassModelXMPPAccount::findOne(array('filter' => array('username' => $xmppUserLogin))); if ($xmppUser !== false) { // It's message to online visitor if (isset($parts[2]) && $parts[2] == 'chat') { $chat = erLhcoreClassModelChat::fetch($parts[1]); $user = $xmppUser->user; // Messages to chat is only send if chat is not accepted or sender is chat owner if ($chat->user_id == $user->id || $chat->user_id == 0) { self::sendMessageToChat($chat, $xmppUser, $params['body']); } else { $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice'); $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] Chat was already accepted by [' . $chat->user . '], your messages are now ignored')); } } else { $visitorId = $parts[1]; $visitor = erLhcoreClassModelChatOnlineUser::fetch($visitorId); // We do not have any active chat if ($visitor->chat === false || !in_array($visitor->chat->status, array(erLhcoreClassModelChat::STATUS_ACTIVE_CHAT, erLhcoreClassModelChat::STATUS_PENDING_CHAT))) { $visitor->operator_message = $params['body']; $visitor->message_seen = 0; $visitor->invitation_id = -1; $visitor->operator_user_id = $xmppUser->user_id; $visitor->saveThis(); // We have active chat } else { self::sendMessageToChat($visitor->chat, $xmppUser, $params['body']); } } } else { throw new Exception('Could not find a operator'); } } else { throw new Exception('Could not extract visitor ID'); } } catch (Exception $e) { throw $e; } }