public function __get($var) { switch ($var) { 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 'department': $this->department = false; if ($this->department_id > 0) { try { $this->department = erLhcoreClassModelDepartament::fetch($this->department_id, true); } catch (Exception $e) { $this->department = false; } } return $this->department; break; case 'msg_to_user': $this->msg_to_user = str_replace(array_keys($this->replaceData), array_values($this->replaceData), $this->msg); // If not all variables were replaced fallback to fallback message if (preg_match('/\\{[a-zA-Z0-9_]+\\}/i', $this->msg_to_user)) { $this->msg_to_user = str_replace(array_keys($this->replaceData), array_values($this->replaceData), $this->fallback_msg); } return $this->msg_to_user; break; case 'message_title': if ($this->title != '') { $this->message_title = $this->title; } else { $this->message_title = $this->msg_to_user; } return $this->message_title; break; default: break; } }
public function __get($var) { switch ($var) { case 'user': $this->user = erLhcoreClassModelUser::fetch($this->user_id); return $this->user; break; case 'lastactivity_ago': $this->lastactivity_ago = $this->user->lastactivity_ago; return $this->lastactivity_ago; break; case 'name_support': $this->name_support = $this->user->name_support; return $this->name_support; break; case 'name_official': $this->name_official = $this->user->name_official; return $this->name_official; break; case 'departments_names': $this->departments_names = array(); $ids = $this->user->departments_ids; if ($ids != '') { $parts = explode(',', $ids); sort($parts); foreach ($parts as $depId) { if ($depId == 0) { $this->departments_names[] = '∞'; } elseif ($depId > 0) { try { $dep = erLhcoreClassModelDepartament::fetch($depId, true); $this->departments_names[] = $dep->name; } catch (Exception $e) { } } } } return $this->departments_names; break; default: break; } }
public function __get($var) { switch ($var) { case 'left_menu': $this->left_menu = ''; return $this->left_menu; break; case 'departament': $this->departament = erLhcoreClassModelDepartament::fetch($this->departament_id); return $this->departament; break; case 'name_department': $this->name_department = $this->name . ' (' . $this->departament . ')'; return $this->name_department; break; default: break; } }
/** * Custom form fields validation */ public static function validateStartChat(&$inputForm, &$start_data_fields, &$chat, $additionalParams = array()) { $validationFields = array(); // Dynamic form field if ($inputForm->validate_start_chat == true) { if (isset($start_data_fields['name_visible_in_popup']) && $start_data_fields['name_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_name_visible_in_popup']) && $start_data_fields['offline_name_visible_in_popup'] == true) { $validationFields['Username'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['email_visible_in_popup']) && $start_data_fields['email_visible_in_popup'] == true || isset($additionalParams['offline'])) { $validationFields['Email'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'); } if (isset($start_data_fields['message_visible_in_popup']) && $start_data_fields['message_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_message_visible_in_popup']) && $start_data_fields['offline_message_visible_in_popup'] == true) { $validationFields['Question'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['phone_visible_in_popup']) && $start_data_fields['phone_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_phone_visible_in_popup']) && $start_data_fields['offline_phone_visible_in_popup'] == true) { $validationFields['Phone'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['tos_visible_in_popup']) && $start_data_fields['tos_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_tos_visible_in_popup']) && $start_data_fields['offline_tos_visible_in_popup'] == true) { $validationFields['AcceptTOS'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'); } } else { if (isset($start_data_fields['name_visible_in_page_widget']) && $start_data_fields['name_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_name_visible_in_page_widget']) && $start_data_fields['offline_name_visible_in_page_widget'] == true) { $validationFields['Username'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['email_visible_in_page_widget']) && $start_data_fields['email_visible_in_page_widget'] == true || isset($additionalParams['offline'])) { $validationFields['Email'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'); } if (isset($start_data_fields['message_visible_in_page_widget']) && $start_data_fields['message_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_message_visible_in_page_widget']) && $start_data_fields['offline_message_visible_in_page_widget'] == true) { $validationFields['Question'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['phone_visible_in_page_widget']) && $start_data_fields['phone_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_phone_visible_in_page_widget']) && $start_data_fields['offline_phone_visible_in_page_widget'] == true) { $validationFields['Phone'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['tos_visible_in_page_widget']) && $start_data_fields['tos_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_tos_visible_in_page_widget']) && $start_data_fields['offline_tos_visible_in_page_widget'] == true) { $validationFields['AcceptTOS'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'); } } $validationFields['DepartamentID'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => -1)); $validationFields['DepartmentIDDefined'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1), FILTER_REQUIRE_ARRAY); $validationFields['operator'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)); $validationFields['user_timezone'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int'); $validationFields['keyUpStarted'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)); $validationFields['name_items'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['values_req'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY); $validationFields['value_items'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['value_types'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['value_sizes'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['value_show'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY); $validationFields['hattr'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY); // Captcha stuff if (erLhcoreClassModelChatConfig::fetch('session_captcha')->current_value == 1) { // Start session if required only $currentUser = erLhcoreClassUser::instance(); $hashCaptcha = isset($_SESSION[$_SERVER['REMOTE_ADDR']]['form']) ? $_SESSION[$_SERVER['REMOTE_ADDR']]['form'] : null; $nameField = 'captcha_' . $hashCaptcha; $validationFields[$nameField] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string'); } else { $nameField = 'captcha_' . sha1(erLhcoreClassIPDetect::getIP() . $_POST['tscaptcha'] . erConfigClassLhConfig::getInstance()->getSetting('site', 'secrethash')); $validationFields[$nameField] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string'); } // Custom start chat fields $validationFields['value_items_admin'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['via_hidden'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $form = new ezcInputForm(INPUT_POST, $validationFields); $Errors = array(); if (erLhcoreClassModelChatBlockedUser::getCount(array('filter' => array('ip' => erLhcoreClassIPDetect::getIP()))) > 0) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'You do not have permission to chat! Please contact site owner.'); } /** * IP Ranges block * */ $ignorable_ip = erLhcoreClassModelChatConfig::fetch('banned_ip_range')->current_value; if ($ignorable_ip != '' && erLhcoreClassIPDetect::isIgnored(erLhcoreClassIPDetect::getIP(), explode(',', $ignorable_ip))) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'You do not have permission to chat! Please contact site owner.'); } if (erLhcoreClassModelChatConfig::fetch('session_captcha')->current_value == 1) { if (!$form->hasValidData($nameField) || $form->{$nameField} == '' || $form->{$nameField} < time() - 600 || $hashCaptcha != sha1($_SERVER['REMOTE_ADDR'] . $form->{$nameField} . erConfigClassLhConfig::getInstance()->getSetting('site', 'secrethash'))) { $Errors['captcha'] = erTranslationClassLhTranslation::getInstance()->getTranslation("chat/startchat", "Your request was not processed as expected - but don't worry it was not your fault. Please re-submit your request. If you experience the same issue you will need to contact us via other means."); } } else { // Captcha validation if (!$form->hasValidData($nameField) || $form->{$nameField} == '' || $form->{$nameField} < time() - 600) { $Errors['captcha'] = erTranslationClassLhTranslation::getInstance()->getTranslation("chat/startchat", "Your request was not processed as expected - but don't worry it was not your fault. Please re-submit your request. If you experience the same issue you will need to contact us via other means."); } } if (isset($validationFields['Username'])) { if (!$form->hasValidData('Username') || $form->Username == '' && ($start_data_fields['name_require_option'] == 'required' && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_name_require_option']) && $start_data_fields['offline_name_require_option'] == 'required')) { $Errors['nick'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your name'); } elseif ($form->hasValidData('Username')) { $chat->nick = $inputForm->username = $form->Username; } if ($form->hasValidData('Username') && $form->Username != '' && strlen($form->Username) > 50) { $Errors['nick'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Maximum 50 characters'); } } if (isset($validationFields['Email'])) { if (!$form->hasValidData('Email') && $start_data_fields['email_require_option'] == 'required' || !$form->hasValidData('Email') && isset($additionalParams['offline'])) { $Errors['email'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter a valid email address'); } elseif ($form->hasValidData('Email')) { $chat->email = $inputForm->email = $form->Email; } else { $chat->email = $inputForm->email = $_POST['Email']; } } // Validate question if (isset($validationFields['Question'])) { if (!$form->hasValidData('keyUpStarted') && (!$form->hasValidData('Question') || trim($form->Question) == '' && ($start_data_fields['message_require_option'] == 'required' && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_message_require_option']) && $start_data_fields['offline_message_require_option'] == 'required'))) { $Errors['question'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your message'); } elseif ($form->hasValidData('Question')) { $inputForm->question = trim($form->Question); } if ($form->hasValidData('Question') && trim($form->Question) != '' && strlen($form->Question) > (int) erLhcoreClassModelChatConfig::fetch('max_message_length')->current_value) { $Errors['question'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Maximum') . ' ' . (int) erLhcoreClassModelChatConfig::fetch('max_message_length')->current_value . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'characters for a message'); } } if (isset($validationFields['AcceptTOS'])) { if (!$form->hasValidData('AcceptTOS') || $form->AcceptTOS == false) { $Errors['accept_tos'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'You have to accept our Terms Of Service'); } else { $inputForm->accept_tos = true; } } // Validate phone if (isset($validationFields['Phone'])) { if (!$form->hasValidData('Phone') || ($form->Phone == '' || mb_strlen($form->Phone) < erLhcoreClassModelChatConfig::fetch('min_phone_length')->current_value) && ($start_data_fields['phone_require_option'] == 'required' && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_phone_require_option']) && $start_data_fields['offline_phone_require_option'] == 'required')) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your phone'); } elseif ($form->hasValidData('Phone')) { $chat->phone = $inputForm->phone = $form->Phone; } if ($form->hasValidData('Phone') && $form->Phone != '' && strlen($form->Phone) > 100) { $Errors['phone'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Maximum 100 characters for phone'); } } if ($form->hasValidData('operator') && erLhcoreClassModelUser::getUserCount(array('filter' => array('id' => $form->operator, 'disabled' => 0))) > 0) { $inputForm->operator = $chat->user_id = $form->operator; } /** * File for offline form * */ $inputForm->has_file = false; if (isset($additionalParams['offline']) && ($inputForm->validate_start_chat == true && isset($start_data_fields['offline_file_visible_in_popup']) && $start_data_fields['offline_file_visible_in_popup'] == true || $inputForm->validate_start_chat == false && isset($start_data_fields['offline_file_visible_in_page_widget']) && $start_data_fields['offline_file_visible_in_page_widget'] == true)) { $fileData = erLhcoreClassModelChatConfig::fetch('file_configuration'); $data = (array) $fileData->data; if ($_FILES['File']['error'] != 4) { // No file was provided if (isset($_FILES['File']) && erLhcoreClassSearchHandler::isFile('File', '/\\.(' . $data['ft_us'] . ')$/i', $data['fs_max'] * 1024)) { $inputForm->has_file = true; // Just extract file extension $fileNameAray = explode('.', $_FILES['File']['name']); end($fileNameAray); // Set attribute for futher $inputForm->file_extension = strtolower(current($fileNameAray)); $inputForm->file_location = $_FILES['File']['tmp_name']; } elseif (isset($_FILES['File'])) { $Errors[] = erLhcoreClassSearchHandler::$lastError != '' ? erLhcoreClassSearchHandler::$lastError : erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Invalid file'); } } } if ($form->hasValidData('user_timezone')) { $timezone_name = timezone_name_from_abbr(null, $form->user_timezone * 3600, true); if ($timezone_name !== false) { $chat->user_tz_identifier = $timezone_name; } else { $chat->user_tz_identifier = ''; } } if ($form->hasValidData('DepartmentIDDefined')) { $inputForm->departament_id_array = $form->DepartmentIDDefined; } if ($form->hasValidData('DepartamentID') && erLhcoreClassModelDepartament::getCount(array('filter' => array('id' => $form->DepartamentID, 'disabled' => 0))) > 0) { $chat->dep_id = $form->DepartamentID; } elseif ($form->hasValidData('DepartamentID') && $form->DepartamentID == -1) { $chat->dep_id == 0; if (isset($additionalParams['theme']) && $additionalParams['theme'] !== false && $additionalParams['theme']->department_title != '') { $Errors['department'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please choose') . ' ' . htmlspecialchars($additionalParams['theme']->department_title) . '!'; } else { $Errors['department'] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please choose department!'); } } elseif ($chat->dep_id == 0 || erLhcoreClassModelDepartament::getCount(array('filter' => array('id' => $chat->dep_id, 'disabled' => 0))) == 0) { // Perhaps extension overrides default department? $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.validate_department', array('input_form' => $inputForm)); // There was no callbacks or file not found etc, we try to download from standard location if ($response === false) { $departments = erLhcoreClassModelDepartament::getList(array('limit' => 1, 'filter' => array('disabled' => 0))); if (!empty($departments)) { $department = array_shift($departments); $chat->dep_id = $department->id; } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Could not determine a default department!'); } } else { $chat->dep_id = $response['department_id']; } } // Set chat attributes for transfer workflow logic if ($chat->department !== false && $chat->department->department_transfer_id > 0) { $chat->transfer_if_na = 1; $chat->transfer_timeout_ts = time(); $chat->transfer_timeout_ac = $chat->department->transfer_timeout; } if ($chat->department !== false && $chat->department->inform_unread == 1) { $chat->reinform_timeout = $chat->department->inform_unread_delay; } $inputForm->departament_id = $chat->dep_id; if ($inputForm->priority !== false && is_numeric($inputForm->priority)) { $chat->priority = (int) $inputForm->priority; } else { if ($chat->department !== false) { $chat->priority = $chat->department->priority; } } $stringParts = array(); if ($form->hasValidData('name_items') && !empty($form->name_items)) { $valuesArray = array(); if ($form->hasValidData('value_items') && !empty($form->value_items)) { $inputForm->value_items = $valuesArray = $form->value_items; } if ($form->hasValidData('values_req') && !empty($form->values_req)) { $inputForm->values_req = $form->values_req; } if ($form->hasValidData('value_types') && !empty($form->value_types)) { $inputForm->value_types = $form->value_types; } if ($form->hasValidData('value_sizes') && !empty($form->value_sizes)) { $inputForm->value_sizes = $form->value_sizes; } if ($form->hasValidData('value_show') && !empty($form->value_show)) { $inputForm->value_show = $form->value_show; } if ($form->hasValidData('hattr') && !empty($form->hattr)) { $inputForm->hattr = $form->hattr; } $inputForm->name_items = $form->name_items; foreach ($form->name_items as $key => $name_item) { if (isset($inputForm->values_req[$key]) && $inputForm->values_req[$key] == 't' && ($inputForm->value_show[$key] == 'b' || $inputForm->value_show[$key] == (isset($additionalParams['offline']) ? 'off' : 'on')) && (!isset($valuesArray[$key]) || trim($valuesArray[$key]) == '')) { $Errors['additional_' . $key] = trim($name_item) . ' : ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'is required'); } $stringParts[] = array('h' => $inputForm->value_types[$key] && $inputForm->value_types[$key] == 'hidden' ? true : false, 'key' => $name_item, 'value' => isset($valuesArray[$key]) ? trim($valuesArray[$key]) : ''); } } if (isset($start_data_fields['custom_fields']) && $start_data_fields['custom_fields'] != '') { $customAdminfields = json_decode($start_data_fields['custom_fields'], true); $valuesArray = array(); // Fill values if exists if ($form->hasValidData('value_items_admin')) { $inputForm->value_items_admin = $valuesArray = $form->value_items_admin; } if ($form->hasValidData('via_hidden')) { $inputForm->via_hidden = $form->via_hidden; } if (is_array($customAdminfields)) { foreach ($customAdminfields as $key => $adminField) { if (isset($inputForm->value_items_admin[$key]) && isset($adminField['isrequired']) && $adminField['isrequired'] == 'true' && ($adminField['visibility'] == 'all' || $adminField['visibility'] == (isset($additionalParams['offline']) ? 'off' : 'on')) && (!isset($valuesArray[$key]) || trim($valuesArray[$key]) == '')) { $Errors['additional_admin_' . $key] = trim($adminField['fieldname']) . ': ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'is required'); } if (isset($valuesArray[$key]) && $valuesArray[$key] != '') { $stringParts[] = array('identifier' => $adminField['fieldidentifier'], 'key' => $adminField['fieldname'], 'value' => isset($valuesArray[$key]) ? trim($valuesArray[$key]) : ''); } } } } if (!empty($stringParts)) { $chat->additional_data = json_encode($stringParts); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.validate_start_chat', array('errors' => &$Errors, 'input_form' => &$inputForm, 'start_data_fields' => &$start_data_fields, 'chat' => &$chat, 'additional_params' => &$additionalParams)); return $Errors; }
} } catch (Exception $e) { } // Redirect user erLhcoreClassModule::redirect('chat/chatwidgetchat', '/' . $chatID . '/' . $hash . $modeAppend . $modeAppendTheme . $sound); exit; } $tpl = erLhcoreClassTemplate::getInstance('lhchat/chatwidget.tpl.php'); $tpl->set('referer', ''); $tpl->set('referer_site', ''); $tpl->set('theme', $theme); $disabled_department = false; if (is_array($Params['user_parameters_unordered']['department']) && erLhcoreClassModelChatConfig::fetch('hide_disabled_department')->current_value == 1) { try { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']); $departments = erLhcoreClassModelDepartament::getList(array('filterin' => array('id' => $Params['user_parameters_unordered']['department']))); $disabledAll = true; foreach ($departments as $department) { if ($department->disabled == 0) { $disabledAll = false; } } // Disable only if all provided departments are disabled if ($disabledAll == true) { $disabled_department = true; } } catch (Exception $e) { exit; } } $tpl->set('disabled_department', $disabled_department);
<?php $departmentNames = array(); $departmentList = array(); $departments = erLhcoreClassModelDepartament::getList($departmentParams); foreach ($departments as $department) { $departmentNames[$department->id] = $department->name; $departmentList[] = array('id' => $department->id, 'name' => $department->name); } $dashboardOrder = (string) erLhcoreClassModelUserSetting::getSetting('dwo', ''); if ($dashboardOrder == '') { $dashboardOrder = erLhcoreClassModelChatConfig::fetch('dashboard_order')->current_value; } $dashboardOrder = explode('|', $dashboardOrder); $columnsTotal = count($dashboardOrder); $columnSize = 12 / $columnsTotal; ?> <div class="row" id="dashboard-body" ng-init='lhc.userDepartments=<?php echo json_encode($departmentList, JSON_HEX_APOS); ?> ;lhc.userDepartmentsNames=<?php echo json_encode($departmentNames, JSON_HEX_APOS); ?> ;lhc.setUpListNames(["actived","closedd","unreadd","pendingd","operatord","departmentd"])'> <a class="dashboard-configuration" onclick="return lhc.revealModal({'url':WWW_DIR_JAVASCRIPT +'chat/dashboardwidgets'})" title="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmininterface', 'Configure dashboard'); ?> "><i class="material-icons mr-0"></i></a> <?php for ($i = 0; $i < $columnsTotal; $i++) { $widgets = array_filter(explode(',', $dashboardOrder[$i]));
/** * 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; } }
</select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'Department'); ?> </label> <select id="DepartmentID" multiple="multiple" size="5" class="form-control"> <option value="0"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'Any'); ?> </option> <?php foreach (erLhcoreClassModelDepartament::getList($departmentParams) as $departament) { ?> <option value="<?php echo $departament->id; ?> "><?php echo htmlspecialchars($departament->name); ?> </option> <?php } ?> </select> </div> </div>
<h4><span class="label label-success"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/transferchat', 'Online'); ?> </span></h4> <?php $departments = erLhcoreClassModelDepartament::getList(array_merge($departments_filter['filter'], array('sort' => 'sort_priority ASC, name ASC'))); $onlineDepartments = erLhcoreClassChat::getLoggedDepartmentsIds(array_keys($departments), $departments_filter['explicit']); foreach ($departments as $departament) { if ($departament->id !== $departments_filter['dep_id'] && in_array($departament->id, $onlineDepartments)) { ?> <div class="checkbox"><label><input type="radio" name="DepartamentID<?php echo $departments_filter['chat_id']; ?> " value="<?php echo $departament->id; ?> "/> <?php echo htmlspecialchars($departament->name); ?> </label></div> <?php } } ?> <h4><span class="label label-default"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/transferchat', 'Offline'); ?> </span></h4> <?php foreach ($departments as $departament) {
$departmentParams = array(); if ($currentUser->hasAccessTo('lhdepartment', 'manageall') !== true) { $userDepartments = erLhcoreClassUserDep::parseUserDepartmetnsForFilter($currentUser->getUserID()); if ($userDepartments !== true) { $departmentParams['filterin']['id'] = $userDepartments; } } $pages = new lhPaginator(); $pages->serverURL = erLhcoreClassDesign::baseurl('departament/departaments'); $pages->items_total = erLhcoreClassModelDepartament::getCount($departmentParams); $pages->setItemsPerPage(20); $pages->paginate(); $items = array(); if ($pages->items_total > 0) { $items = erLhcoreClassModelDepartament::getList(array_merge($departmentParams, array('offset' => $pages->low, 'limit' => $pages->items_per_page, 'sort' => 'id ASC'))); } $tpl->set('items', $items); $tpl->set('pages', $pages); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('department/departments', 'System configuration')), array('url' => erLhcoreClassDesign::baseurl('department/departments'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('department/departments', 'Domains'))); } if ($_POST['inpu'] == 2) { $_SESSION['var'] = 2; $tpl = erLhcoreClassTemplate::getInstance('lhdepartament/departaments.tpl.php'); $departmentParams = array(); $items = array(); $items = erLhcoreClassModelDepartament::getListTips(); $tpl->set('items', $items); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('departament/departaments', 'System configuration')), array('url' => erLhcoreClassDesign::baseurl('departament/departaments'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('departament/departaments', 'Tips'))); }
public function __get($var) { switch ($var) { case 'time_created_front': $this->time_created_front = date('Ymd') == date('Ymd', $this->time) ? date(erLhcoreClassModule::$dateHourFormat, $this->time) : date(erLhcoreClassModule::$dateDateHourFormat, $this->time); return $this->time_created_front; break; case 'user_closed_ts_front': $this->user_closed_ts_front = date('Ymd') == date('Ymd', $this->user_closed_ts) ? date(erLhcoreClassModule::$dateHourFormat, $this->user_closed_ts) : date(erLhcoreClassModule::$dateDateHourFormat, $this->user_closed_ts); return $this->user_closed_ts_front; break; case 'is_operator_typing': $this->is_operator_typing = $this->operator_typing > time() - 60; // typing is considered if status did not changed for 30 seconds return $this->is_operator_typing; break; case 'is_user_typing': $this->is_user_typing = $this->user_typing > time() - 10; // typing is considered if status did not changed for 30 seconds return $this->is_user_typing; break; case 'wait_time_seconds': $this->wait_time_seconds = time() - $this->time; return $this->wait_time_seconds; case 'wait_time_front': $this->wait_time_front = erLhcoreClassChat::formatSeconds($this->wait_time); return $this->wait_time_front; break; case 'wait_time_pending': $this->wait_time_pending = erLhcoreClassChat::formatSeconds(time() - $this->time); return $this->wait_time_pending; break; case 'chat_duration_front': $this->chat_duration_front = erLhcoreClassChat::formatSeconds($this->chat_duration); return $this->chat_duration_front; break; case 'user_name': return $this->user_name = (string) $this->user; break; case 'plain_user_name': $this->plain_user_name = false; if ($this->user !== false) { $this->plain_user_name = (string) $this->user->name_support; } return $this->plain_user_name; break; case 'user': $this->user = false; if ($this->user_id > 0) { try { $this->user = erLhcoreClassModelUser::fetch($this->user_id, true); } catch (Exception $e) { $this->user = false; } } return $this->user; break; case 'operator_typing_user': $this->operator_typing_user = false; if ($this->operator_typing_id > 0) { try { $this->operator_typing_user = erLhcoreClassModelUser::fetch($this->operator_typing_id); } catch (Exception $e) { $this->operator_typing_user = false; } } return $this->operator_typing_user; 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 'department': $this->department = false; if ($this->dep_id > 0) { try { $this->department = erLhcoreClassModelDepartament::fetch($this->dep_id, true); } catch (Exception $e) { } } return $this->department; break; case 'department_name': return $this->department_name = (string) $this->department; break; case 'number_in_queue': $this->number_in_queue = 1; if ($this->status == self::STATUS_PENDING_CHAT) { $this->number_in_queue = erLhcoreClassChat::getCount(array('filterlt' => array('id' => $this->id), 'filter' => array('dep_id' => $this->dep_id, 'status' => self::STATUS_PENDING_CHAT))) + 1; } return $this->number_in_queue; 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 'unread_time': $diff = time() - $this->last_user_msg_time; $hours = floor($diff / 3600); $minits = floor(($diff - $hours * 3600) / 60); $seconds = $diff - $hours * 3600 - $minits * 60; $this->unread_time = array('hours' => $hours, 'minits' => $minits, 'seconds' => $seconds); return $this->unread_time; break; case 'user_tz_identifier_time': $date = new DateTime(null, new DateTimeZone($this->user_tz_identifier)); $this->user_tz_identifier_time = $date->format(erLhcoreClassModule::$dateHourFormat); return $this->user_tz_identifier_time; break; case 'additional_data_array': $jsonData = json_decode($this->additional_data); if ($jsonData !== null) { $this->additional_data_array = $jsonData; } else { $this->additional_data_array = $this->additional_data; } return $this->additional_data_array; break; case 'chat_variables_array': if (!empty($this->chat_variables)) { $jsonData = json_decode($this->chat_variables, true); if ($jsonData !== null) { $this->chat_variables_array = $jsonData; } else { $this->chat_variables_array = $this->chat_variables; } } else { $this->chat_variables_array = $this->chat_variables; } return $this->chat_variables_array; break; /** * @desc Returns user status based on the following logic * 1. Green - if widget is not closed * 2. Green - if widget is closed and user activity tracking enabled and user still on site and he is active * 3. Green - if widget is closed and user activity tracking is disabled, but we still receive pings and from last user message has not passed 5 minutes * * 4. Yellow - if widget is closed and user activity tracking enabled, but user is not active but he is still on site * 5. Yellow - from last user message has passed 5 minutes but user still on site * * 6. Widget is closed and we could not determine online user || None of above conditions are met. * * If user activity tracking is enabled but status checking not we default to 10 seconds status checks timeout * * @param array $params * * 1 GREEN user has activity in last 5 minutes and ping respond * 2 ORANGE user has no activity in last 5 minutes and ping respond * 3 GREY Offline user fails to respond pings for X number of times in a row * * @return int */ /** * @desc Returns user status based on the following logic * 1. Green - if widget is not closed * 2. Green - if widget is closed and user activity tracking enabled and user still on site and he is active * 3. Green - if widget is closed and user activity tracking is disabled, but we still receive pings and from last user message has not passed 5 minutes * * 4. Yellow - if widget is closed and user activity tracking enabled, but user is not active but he is still on site * 5. Yellow - from last user message has passed 5 minutes but user still on site * * 6. Widget is closed and we could not determine online user || None of above conditions are met. * * If user activity tracking is enabled but status checking not we default to 10 seconds status checks timeout * * @param array $params * * 1 GREEN user has activity in last 5 minutes and ping respond * 2 ORANGE user has no activity in last 5 minutes and ping respond * 3 GREY Offline user fails to respond pings for X number of times in a row * * @return int */ case 'user_status_front': $this->user_status_front = $this->user_status == self::USER_STATUS_JOINED_CHAT ? 0 : 1; if ($this->user_status_front == self::USER_STATUS_CLOSED_CHAT && $this->online_user !== false || erLhcoreClassChat::$onlineCondition == 1 && $this->online_user !== false) { $timeout = (int) erLhcoreClassChat::$trackTimeout || 10; if (erLhcoreClassChat::$trackActivity == true) { if ($this->online_user->last_check_time_ago < $timeout + 10 && $this->online_user->user_active == 1) { //User still on site, it does not matter that he have closed widget. $this->user_status_front = 0; } elseif ($this->online_user->user_active == 0 && $this->online_user->last_check_time_ago < $timeout + 10) { $this->user_status_front = 2; } } else { if ($this->online_user->last_check_time_ago < $timeout + 10 && time() - $this->last_user_msg_time < 300) { //User still on site, it does not matter that he have closed widget. $this->user_status_front = 0; } elseif (time() - $this->last_user_msg_time >= 300 && $this->online_user->last_check_time_ago < $timeout + 10) { $this->user_status_front = 2; } } } return $this->user_status_front; break; default: break; } }
/** * Custom form fields validation */ public static function validateStartChat(&$inputForm, &$start_data_fields, &$chat, $additionalParams = array()) { $validationFields = array(); // Dynamic form field if ($inputForm->validate_start_chat == true) { if (isset($start_data_fields['name_visible_in_popup']) && $start_data_fields['name_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_name_visible_in_popup']) && $start_data_fields['offline_name_visible_in_popup'] == true) { $validationFields['Username'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['email_visible_in_popup']) && $start_data_fields['email_visible_in_popup'] == true || isset($additionalParams['offline'])) { $validationFields['Email'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'); } if (isset($start_data_fields['message_visible_in_popup']) && $start_data_fields['message_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_message_visible_in_popup']) && $start_data_fields['offline_message_visible_in_popup'] == true) { $validationFields['Question'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['phone_visible_in_popup']) && $start_data_fields['phone_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_phone_visible_in_popup']) && $start_data_fields['offline_phone_visible_in_popup'] == true) { $validationFields['Phone'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['tos_visible_in_popup']) && $start_data_fields['tos_visible_in_popup'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_tos_visible_in_popup']) && $start_data_fields['offline_tos_visible_in_popup'] == true) { $validationFields['AcceptTOS'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'); } } else { if (isset($start_data_fields['name_visible_in_page_widget']) && $start_data_fields['name_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_name_visible_in_page_widget']) && $start_data_fields['offline_name_visible_in_page_widget'] == true) { $validationFields['Username'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['email_visible_in_page_widget']) && $start_data_fields['email_visible_in_page_widget'] == true || isset($additionalParams['offline'])) { $validationFields['Email'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'); } if (isset($start_data_fields['message_visible_in_page_widget']) && $start_data_fields['message_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_message_visible_in_page_widget']) && $start_data_fields['offline_message_visible_in_page_widget'] == true) { $validationFields['Question'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['phone_visible_in_page_widget']) && $start_data_fields['phone_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_phone_visible_in_page_widget']) && $start_data_fields['offline_phone_visible_in_page_widget'] == true) { $validationFields['Phone'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'); } if (isset($start_data_fields['tos_visible_in_page_widget']) && $start_data_fields['tos_visible_in_page_widget'] == true && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_tos_visible_in_page_widget']) && $start_data_fields['offline_tos_visible_in_page_widget'] == true) { $validationFields['AcceptTOS'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'); } } $validationFields['DepartamentID'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)); $validationFields['DepartmentIDDefined'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1), FILTER_REQUIRE_ARRAY); $validationFields['operator'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)); $validationFields['user_timezone'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int'); $validationFields['name_items'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['values_req'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY); $validationFields['value_items'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['value_types'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['value_sizes'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY); $validationFields['value_show'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY); $validationFields['hattr'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY); // Captcha stuff if (erLhcoreClassModelChatConfig::fetch('session_captcha')->current_value == 1) { // Start session if required only $currentUser = erLhcoreClassUser::instance(); $hashCaptcha = isset($_SESSION[$_SERVER['REMOTE_ADDR']]['form']) ? $_SESSION[$_SERVER['REMOTE_ADDR']]['form'] : null; $nameField = 'captcha_' . $hashCaptcha; $validationFields[$nameField] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string'); } else { $nameField = 'captcha_' . sha1(erLhcoreClassIPDetect::getIP() . $_POST['tscaptcha'] . erConfigClassLhConfig::getInstance()->getSetting('site', 'secrethash')); $validationFields[$nameField] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string'); } $form = new ezcInputForm(INPUT_POST, $validationFields); $Errors = array(); if (erLhcoreClassModelChatBlockedUser::getCount(array('filter' => array('ip' => erLhcoreClassIPDetect::getIP()))) > 0) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'You do not have permission to chat! Please contact site owner.'); } if (erLhcoreClassModelChatConfig::fetch('session_captcha')->current_value == 1) { if (!$form->hasValidData($nameField) || $form->{$nameField} == '' || $form->{$nameField} < time() - 600 || $hashCaptcha != sha1($_SERVER['REMOTE_ADDR'] . $form->{$nameField} . erConfigClassLhConfig::getInstance()->getSetting('site', 'secrethash'))) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Invalid captcha code, please enable Javascript!'); } } else { // Captcha validation if (!$form->hasValidData($nameField) || $form->{$nameField} == '' || $form->{$nameField} < time() - 600) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Invalid captcha code, please enable Javascript!'); } } if (isset($validationFields['Username'])) { if (!$form->hasValidData('Username') || $form->Username == '' && ($start_data_fields['name_require_option'] == 'required' && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_name_require_option']) && $start_data_fields['offline_name_require_option'] == 'required')) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your name'); } elseif ($form->hasValidData('Username')) { $chat->nick = $inputForm->username = $form->Username; } if ($form->hasValidData('Username') && $form->Username != '' && strlen($form->Username) > 50) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Maximum 50 characters'); } } if (isset($validationFields['Email'])) { if (!$form->hasValidData('Email') && $start_data_fields['email_require_option'] == 'required' || !$form->hasValidData('Email') && isset($additionalParams['offline'])) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter a valid email address'); } elseif ($form->hasValidData('Email')) { $chat->email = $inputForm->email = $form->Email; } else { $chat->email = $inputForm->email = $_POST['Email']; } } // Validate question if (isset($validationFields['Question'])) { if (!$form->hasValidData('Question') || trim($form->Question) == '' && ($start_data_fields['message_require_option'] == 'required' && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_message_require_option']) && $start_data_fields['offline_message_require_option'] == 'required')) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your message'); } elseif ($form->hasValidData('Question')) { $inputForm->question = trim($form->Question); } if ($form->hasValidData('Question') && trim($form->Question) != '' && strlen($form->Question) > (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'); } } if (isset($validationFields['AcceptTOS'])) { if (!$form->hasValidData('AcceptTOS') || $form->AcceptTOS == false) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'You have to accept our Terms Of Service'); } else { $inputForm->accept_tos = true; } } // Validate phone if (isset($validationFields['Phone'])) { if (!$form->hasValidData('Phone') || ($form->Phone == '' || mb_strlen($form->Phone) < erLhcoreClassModelChatConfig::fetch('min_phone_length')->current_value) && ($start_data_fields['phone_require_option'] == 'required' && !isset($additionalParams['offline']) || isset($additionalParams['offline']) && isset($start_data_fields['offline_phone_require_option']) && $start_data_fields['offline_phone_require_option'] == 'required')) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your phone'); } elseif ($form->hasValidData('Phone')) { $chat->phone = $inputForm->phone = $form->Phone; } if ($form->hasValidData('Phone') && $form->Phone != '' && strlen($form->Phone) > 100) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Maximum 100 characters for phone'); } } if ($form->hasValidData('operator') && erLhcoreClassModelUser::getUserCount(array('filter' => array('id' => $form->operator, 'disabled' => 0))) > 0) { $inputForm->operator = $chat->user_id = $form->operator; } if ($form->hasValidData('user_timezone')) { $timezone_name = timezone_name_from_abbr(null, $form->user_timezone * 3600, true); if ($timezone_name !== false) { $chat->user_tz_identifier = $timezone_name; } else { $chat->user_tz_identifier = ''; } } if ($form->hasValidData('DepartmentIDDefined')) { $inputForm->departament_id_array = $form->DepartmentIDDefined; } if ($form->hasValidData('DepartamentID') && erLhcoreClassModelDepartament::getCount(array('filter' => array('id' => $form->DepartamentID, 'disabled' => 0))) > 0) { $chat->dep_id = $form->DepartamentID; } elseif ($chat->dep_id == 0 || erLhcoreClassModelDepartament::getCount(array('filter' => array('id' => $chat->dep_id, 'disabled' => 0))) == 0) { $departments = erLhcoreClassModelDepartament::getList(array('limit' => 1, 'filter' => array('disabled' => 0))); if (!empty($departments)) { $department = array_shift($departments); $chat->dep_id = $department->id; } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Could not determine a default department!'); } } // Set chat attributes for transfer workflow logic if ($chat->department !== false && $chat->department->department_transfer_id > 0) { $chat->transfer_if_na = 1; $chat->transfer_timeout_ts = time(); $chat->transfer_timeout_ac = $chat->department->transfer_timeout; } if ($chat->department !== false && $chat->department->inform_unread == 1) { $chat->reinform_timeout = $chat->department->inform_unread_delay; } $inputForm->departament_id = $chat->dep_id; if ($inputForm->priority !== false && is_numeric($inputForm->priority)) { $chat->priority = (int) $inputForm->priority; } else { if ($chat->department !== false) { $chat->priority = $chat->department->priority; } } if ($form->hasValidData('name_items') && !empty($form->name_items)) { $valuesArray = array(); if ($form->hasValidData('value_items') && !empty($form->value_items)) { $inputForm->value_items = $valuesArray = $form->value_items; } if ($form->hasValidData('values_req') && !empty($form->values_req)) { $inputForm->values_req = $form->values_req; } if ($form->hasValidData('value_types') && !empty($form->value_types)) { $inputForm->value_types = $form->value_types; } if ($form->hasValidData('value_sizes') && !empty($form->value_sizes)) { $inputForm->value_sizes = $form->value_sizes; } if ($form->hasValidData('value_show') && !empty($form->value_show)) { $inputForm->value_show = $form->value_show; } if ($form->hasValidData('hattr') && !empty($form->hattr)) { $inputForm->hattr = $form->hattr; } $inputForm->name_items = $form->name_items; $stringParts = array(); foreach ($form->name_items as $key => $name_item) { if (isset($inputForm->values_req[$key]) && $inputForm->values_req[$key] == 't' && ($inputForm->value_show[$key] == 'b' || $inputForm->value_show[$key] == (isset($additionalParams['offline']) ? 'off' : 'on')) && (!isset($valuesArray[$key]) || trim($valuesArray[$key]) == '')) { $Errors[] = trim($name_item) . ' : ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'is required'); } $stringParts[] = array('key' => $name_item, 'value' => isset($valuesArray[$key]) ? trim($valuesArray[$key]) : ''); } $chat->additional_data = json_encode($stringParts); } erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.validate_start_chat', array('errors' => &$Errors, 'input_form' => &$inputForm, 'start_data_fields' => &$start_data_fields, 'chat' => &$chat, 'additional_params' => &$additionalParams)); return $Errors; }
public static function validateDepartaments() { $departaments = erLhcoreClassModelDepartament::getList(); $departamentsCount = erLhcoreClassModelDepartament::getCount(); // Chats list return array('list' => array_values($departaments), 'list_count' => $departamentsCount, 'error' => false); }
<?php $departmentParams = array(); $userDepartments = erLhcoreClassUserDep::parseUserDepartmetnsForFilter($currentUser->getUserID()); if ($userDepartments !== true) { $departmentParams['filterin']['id'] = $userDepartments; if (!$currentUser->hasAccessTo('lhchat', 'sees_all_online_visitors')) { $filter['filterin']['dep_id'] = $userDepartments; } } // Same sort as in widget $departmentParams['sort'] = 'pending_chats_counter DESC'; erLhcoreClassChatExport::exportDepartmentStats(erLhcoreClassModelDepartament::getList($departmentParams)); exit;
public function __get($var) { switch ($var) { case 'survey': $this->survey = ''; return $this->survey; break; case 'ftime_front': $this->ftime_front = date('Ymd') == date('Ymd', $this->ftime) ? date(erLhcoreClassModule::$dateHourFormat, $this->ftime) : date(erLhcoreClassModule::$dateDateHourFormat, $this->ftime); return $this->ftime_front; break; case 'user': try { $this->user = erLhcoreClassModelUser::fetch($this->user_id, true); } catch (Exception $e) { $this->user = false; } return $this->user; break; case 'is_filled': return !is_null($this->id); break; case 'department': $this->department = false; if ($this->dep_id > 0) { try { $this->department = erLhcoreClassModelDepartament::fetch($this->dep_id, true); } catch (Exception $e) { } } return $this->department; break; case 'department_name': return $this->department_name = (string) $this->department; break; case 'average_stars': return round($this->virtual_total_stars / $this->virtual_chats_number, 2); break; default: break; } }
$inputData->operator = $chat->user_id = $form->operator; } if ($form->hasValidData('user_timezone')) { $timezone_name = timezone_name_from_abbr(null, $form->user_timezone * 3600, true); if ($timezone_name !== false) { $chat->user_tz_identifier = $timezone_name; } else { $chat->user_tz_identifier = ''; } } $chat->dep_id = $inputData->departament_id; // Assign default department if ($form->hasValidData('DepartamentID') && erLhcoreClassModelDepartament::getCount(array('filter' => array('id' => $form->DepartamentID, 'disabled' => 0))) > 0) { $inputData->departament_id = $chat->dep_id = $form->DepartamentID; } elseif ($chat->dep_id == 0 || erLhcoreClassModelDepartament::getCount(array('filter' => array('id' => $chat->dep_id, 'disabled' => 0))) == 0) { $departments = erLhcoreClassModelDepartament::getList(array('limit' => 1, 'filter' => array('disabled' => 0))); if (!empty($departments)) { $department = array_shift($departments); $chat->dep_id = $department->id; } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Could not determine a default department!'); } } if (count($Errors) == 0) { $chat->time = time(); $chat->status = 0; $chat->setIP(); $chat->hash = erLhcoreClassChat::generateHash(); $chat->referrer = isset($_POST['URLRefer']) ? $_POST['URLRefer'] : ''; $chat->session_referrer = isset($_POST['r']) ? $_POST['r'] : ''; if ($chat->nick == '') {
$unreadTabEnabled = erLhcoreClassModelUserSetting::getSetting('enable_unread_list', 1); $showAllPending = erLhcoreClassModelUserSetting::getSetting('show_all_pending', 1); $showDepartmentsStats = $currentUser->hasAccessTo('lhuser', 'canseedepartmentstats'); if ($showDepartmentsStats == true) { /** * Departments stats * */ $limitList = is_numeric($Params['user_parameters_unordered']['limitd']) ? (int) $Params['user_parameters_unordered']['limitd'] : 10; $filter = array('ignore_fields' => erLhcoreClassChat::$chatListIgnoreField); $filter['limit'] = $limitList; if (is_array($Params['user_parameters_unordered']['departmentd']) && !empty($Params['user_parameters_unordered']['departmentd'])) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['departmentd']); $filter['filterin']['id'] = $Params['user_parameters_unordered']['departmentd']; } $filter['sort'] = 'pending_chats_counter DESC'; $departments = erLhcoreClassModelDepartament::getList($filter); erLhcoreClassChat::prefillGetAttributes($departments, array('id', 'name', 'pending_chats_counter', 'active_chats_counter'), array(), array('remove_all' => true)); $ReturnMessages['departments_stats'] = array('list' => array_values($departments)); } if ($activeTabEnabled == true) { /** * Active chats * */ $limitList = is_numeric($Params['user_parameters_unordered']['limita']) ? (int) $Params['user_parameters_unordered']['limita'] : 10; $filter = array('ignore_fields' => erLhcoreClassChat::$chatListIgnoreField); if (is_array($Params['user_parameters_unordered']['actived']) && !empty($Params['user_parameters_unordered']['actived'])) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['actived']); $filter['filterin']['dep_id'] = $Params['user_parameters_unordered']['actived']; } $chats = erLhcoreClassChat::getActiveChats($limitList, 0, $filter); erLhcoreClassChat::prefillGetAttributes($chats, array('time_created_front', 'department_name', 'plain_user_name'), array('department', 'time', 'status', 'user_id', 'user'));
<?php $tpl = erLhcoreClassTemplate::getInstance('lhdepartament/departaments.tpl.php'); /** * Append user departments filter * */ $departmentParams = array(); if ($currentUser->hasAccessTo('lhdepartment', 'manageall') !== true) { $userDepartments = erLhcoreClassUserDep::parseUserDepartmetnsForFilter($currentUser->getUserID()); if ($userDepartments !== true) { $departmentParams['filterin']['id'] = $userDepartments; } } $pages = new lhPaginator(); $pages->serverURL = erLhcoreClassDesign::baseurl('departament/departaments'); $pages->items_total = erLhcoreClassModelDepartament::getCount($departmentParams); $pages->setItemsPerPage(20); $pages->paginate(); $items = array(); if ($pages->items_total > 0) { $items = erLhcoreClassModelDepartament::getList(array_merge($departmentParams, array('offset' => $pages->low, 'limit' => $pages->items_per_page, 'sort' => 'id ASC'))); } $tpl->set('items', $items); $tpl->set('pages', $pages); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('department/departments', 'System configuration')), array('url' => erLhcoreClassDesign::baseurl('department/departments'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('department/departments', 'Departments')));
public function __get($var) { switch ($var) { case 'time_created_front': $this->time_created_front = date('Ymd') == date('Ymd', $this->time) ? date(erLhcoreClassModule::$dateHourFormat, $this->time) : date(erLhcoreClassModule::$dateDateHourFormat, $this->time); return $this->time_created_front; break; case 'user_closed_ts_front': $this->user_closed_ts_front = date('Ymd') == date('Ymd', $this->user_closed_ts) ? date(erLhcoreClassModule::$dateHourFormat, $this->user_closed_ts) : date(erLhcoreClassModule::$dateDateHourFormat, $this->user_closed_ts); return $this->user_closed_ts_front; break; case 'is_operator_typing': $this->is_operator_typing = $this->operator_typing > time() - 60; // typing is considered if status did not changed for 30 seconds return $this->is_operator_typing; break; case 'is_user_typing': $this->is_user_typing = $this->user_typing > time() - 10; // typing is considered if status did not changed for 30 seconds return $this->is_user_typing; break; case 'wait_time_seconds': $this->wait_time_seconds = time() - $this->time; return $this->wait_time_seconds; case 'wait_time_front': $this->wait_time_front = erLhcoreClassChat::formatSeconds($this->wait_time); return $this->wait_time_front; break; case 'wait_time_pending': $this->wait_time_pending = erLhcoreClassChat::formatSeconds(time() - $this->time); return $this->wait_time_pending; break; case 'chat_duration_front': $this->chat_duration_front = erLhcoreClassChat::formatSeconds($this->chat_duration); return $this->chat_duration_front; break; case 'user_name': return $this->user_name = (string) $this->user; break; case 'plain_user_name': $this->plain_user_name = false; if ($this->user !== false) { $this->plain_user_name = (string) $this->user->name_support; } return $this->plain_user_name; break; case 'user': $this->user = false; if ($this->user_id > 0) { try { $this->user = erLhcoreClassModelUser::fetch($this->user_id, true); } catch (Exception $e) { $this->user = false; } } return $this->user; break; case 'operator_typing_user': $this->operator_typing_user = false; if ($this->operator_typing_id > 0) { try { $this->operator_typing_user = erLhcoreClassModelUser::fetch($this->operator_typing_id); } catch (Exception $e) { $this->operator_typing_user = false; } } return $this->operator_typing_user; 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 'department': $this->department = false; if ($this->dep_id > 0) { try { $this->department = erLhcoreClassModelDepartament::fetch($this->dep_id, true); } catch (Exception $e) { } } return $this->department; break; case 'product': $this->product = false; if ($this->product_id > 0) { try { $this->product = erLhAbstractModelProduct::fetch($this->product_id, true); } catch (Exception $e) { } } return $this->product; break; case 'product_name': $this->product_name = (string) $this->product; return $this->product_name; break; case 'department_name': return $this->department_name = (string) $this->department; break; case 'number_in_queue': $this->number_in_queue = 1; if ($this->status == self::STATUS_PENDING_CHAT) { $this->number_in_queue = erLhcoreClassChat::getCount(array('filterlt' => array('id' => $this->id), 'filter' => array('dep_id' => $this->dep_id, 'status' => self::STATUS_PENDING_CHAT))) + 1; } return $this->number_in_queue; 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 'unread_time': $diff = time() - $this->last_user_msg_time; $hours = floor($diff / 3600); $minits = floor(($diff - $hours * 3600) / 60); $seconds = $diff - $hours * 3600 - $minits * 60; $this->unread_time = array('hours' => $hours, 'minits' => $minits, 'seconds' => $seconds); return $this->unread_time; break; case 'user_tz_identifier_time': $date = new DateTime(null, new DateTimeZone($this->user_tz_identifier)); $this->user_tz_identifier_time = $date->format(erLhcoreClassModule::$dateHourFormat); return $this->user_tz_identifier_time; break; case 'additional_data_array': $jsonData = json_decode($this->additional_data); if ($jsonData !== null) { $this->additional_data_array = $jsonData; } else { $this->additional_data_array = $this->additional_data; } return $this->additional_data_array; break; case 'chat_variables_array': if (!empty($this->chat_variables)) { $jsonData = json_decode($this->chat_variables, true); if ($jsonData !== null) { $this->chat_variables_array = $jsonData; } else { $this->chat_variables_array = $this->chat_variables; } } else { $this->chat_variables_array = $this->chat_variables; } return $this->chat_variables_array; break; case 'user_status_front': if ($this->online_user !== false) { $this->user_status_front = erLhcoreClassChat::setActivityByChatAndOnlineUser($this, $this->online_user); } else { $this->user_status_front = $this->user_status == self::USER_STATUS_JOINED_CHAT ? 0 : 1; } return $this->user_status_front; break; default: break; } }
public function __get($var) { switch ($var) { case 'time_created_front': $this->time_created_front = date('Ymd') == date('Ymd', $this->time) ? date(erLhcoreClassModule::$dateHourFormat, $this->time) : date(erLhcoreClassModule::$dateDateHourFormat, $this->time); return $this->time_created_front; break; case 'user_closed_ts_front': $this->user_closed_ts_front = date('Ymd') == date('Ymd', $this->user_closed_ts) ? date(erLhcoreClassModule::$dateHourFormat, $this->user_closed_ts) : date(erLhcoreClassModule::$dateDateHourFormat, $this->user_closed_ts); return $this->user_closed_ts_front; break; case 'is_operator_typing': $this->is_operator_typing = $this->operator_typing > time() - 60; // typing is considered if status did not changed for 30 seconds return $this->is_operator_typing; break; case 'is_user_typing': $this->is_user_typing = $this->user_typing > time() - 10; // typing is considered if status did not changed for 30 seconds return $this->is_user_typing; break; case 'wait_time_front': $this->wait_time_front = erLhcoreClassChat::formatSeconds($this->wait_time); return $this->wait_time_front; break; case 'chat_duration_front': $this->chat_duration_front = erLhcoreClassChat::formatSeconds($this->chat_duration); return $this->chat_duration_front; break; case 'user_name': return $this->user_name = (string) $this->user; break; case 'user': $this->user = false; if ($this->user_id > 0) { try { $this->user = erLhcoreClassModelUser::fetch($this->user_id, true); } catch (Exception $e) { $this->user = false; } } return $this->user; break; case 'operator_typing_user': $this->operator_typing_user = false; if ($this->operator_typing_id > 0) { try { $this->operator_typing_user = erLhcoreClassModelUser::fetch($this->operator_typing_id); } catch (Exception $e) { $this->operator_typing_user = false; } } return $this->operator_typing_user; 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 'department': $this->department = false; if ($this->dep_id > 0) { try { $this->department = erLhcoreClassModelDepartament::fetch($this->dep_id, true); } catch (Exception $e) { } } return $this->department; break; case 'department_name': return $this->department_name = (string) $this->department; 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 'unread_time': $diff = time() - $this->last_user_msg_time; $hours = floor($diff / 3600); $minits = floor(($diff - $hours * 3600) / 60); $seconds = $diff - $hours * 3600 - $minits * 60; $this->unread_time = array('hours' => $hours, 'minits' => $minits, 'seconds' => $seconds); return $this->unread_time; break; case 'user_tz_identifier_time': $date = new DateTime(null, new DateTimeZone($this->user_tz_identifier)); $this->user_tz_identifier_time = $date->format(erLhcoreClassModule::$dateHourFormat); return $this->user_tz_identifier_time; break; case 'additional_data_array': $jsonData = json_decode($this->additional_data); if ($jsonData !== null) { $this->additional_data_array = $jsonData; } else { $this->additional_data_array = $this->additional_data; } return $this->additional_data_array; break; case 'chat_variables_array': if (!empty($this->chat_variables)) { $jsonData = json_decode($this->chat_variables, true); if ($jsonData !== null) { $this->chat_variables_array = $jsonData; } else { $this->chat_variables_array = $this->chat_variables; } } else { $this->chat_variables_array = $this->chat_variables; } return $this->chat_variables_array; break; default: break; } }