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; } }
$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);
$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);
$inputData->departament_id = array_shift($Params['user_parameters_unordered']['department']); } else { $inputData->departament_id = 0; } if (is_array($Params['user_parameters_unordered']['department'])) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']); $inputData->departament_id_array = $Params['user_parameters_unordered']['department']; } $inputData->accept_tos = false; $inputData->question = ''; $inputData->operator = (int) $Params['user_parameters_unordered']['operator']; // Perhaps user was redirected to leave a message form because chat was not acceptend in some time interval if ((string) $Params['user_parameters_unordered']['chatprefill'] != '') { list($chatID, $hash) = explode('_', $Params['user_parameters_unordered']['chatprefill']); try { $chatPrefill = erLhcoreClassModelChat::fetch($chatID); if ($chatPrefill->hash == $hash) { $inputData->chatprefill = $Params['user_parameters_unordered']['chatprefill']; $inputData->username = $chatPrefill->nick; $inputData->departament_id = $chatPrefill->dep_id; $inputData->email = $chatPrefill->email; $inputData->phone = $chatPrefill->phone; $inputData->accept_tos = true; $inputData->question = erLhcoreClassChat::getFirstUserMessage($chatPrefill->id); } else { unset($chatPrefill); } } catch (Exception $e) { // Do nothing } }
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') {
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; } }
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; }
<?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;
<?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;
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; } }
/** * 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; } }