Ejemplo n.º 1
0
 public static function getIP()
 {
     if (self::$couldflareRun == false) {
         self::cloudflareInit();
         self::$couldflareRun = true;
     }
     if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '') {
         $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
     }
     return $_SERVER["REMOTE_ADDR"];
 }
Ejemplo n.º 2
0
 // Additional attributes
 $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);
 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;
 } else {
     // Captcha stuff
     $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 ($form->hasValidData('DepartmentIDDefined')) {
     $inputData->departament_id_array = $form->DepartmentIDDefined;
 }
 if (!$form->hasValidData('Question') || trim($form->Question) == '') {
     $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your message');
 } elseif ($form->hasValidData('Question')) {
     $inputData->question = $form->Question;
 }
 if ((!$form->hasValidData('Username') || trim($form->Username) == '') && $userInstance->requires_username == 1) {
     $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please enter your name');
 } elseif ($form->hasValidData('Username')) {
Ejemplo n.º 3
0
 public static function informChatClosed(erLhcoreClassModelChat $chat, $operator = false)
 {
     $sendMail = erLhAbstractModelEmailTemplate::fetch(5);
     $mail = new PHPMailer();
     $mail->CharSet = "UTF-8";
     if ($sendMail->from_email != '') {
         $mail->Sender = $mail->From = $sendMail->from_email;
     }
     $mail->FromName = $sendMail->from_name;
     $mail->Subject = $sendMail->subject;
     $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 10, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
     $messagesContent = '';
     foreach ($messages as $msg) {
         if ($msg->user_id == -1) {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
         } else {
             $messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
         }
     }
     $emailRecipient = array();
     if ($sendMail->recipient != '') {
         // This time we give priority to template recipients
         $emailRecipient = explode(',', $sendMail->recipient);
     } elseif ($chat->department !== false && $chat->department->email != '') {
         $emailRecipient = explode(',', $chat->department->email);
     } else {
         // Lets find first user and send him an e-mail
         $list = erLhcoreClassModelUser::getUserList(array('limit' => 1, 'sort' => 'id ASC'));
         $user = array_pop($list);
         $emailRecipient = array($user->email);
     }
     self::setupSMTP($mail);
     $cfgSite = erConfigClassLhConfig::getInstance();
     $secretHash = $cfgSite->getSetting('site', 'secrethash');
     if ($chat->email != '') {
         $mail->AddReplyTo($chat->email, $chat->nick);
     }
     // Format user friendly additional data
     if ($chat->additional_data != '') {
         $paramsAdditional = json_decode($chat->additional_data, true);
         $elementsAdditional = array();
         if (is_array($paramsAdditional) && !empty($paramsAdditional)) {
             foreach ($paramsAdditional as $param) {
                 $elementsAdditional[] = $param['key'] . ' - ' . $param['value'];
             }
             $additional_data = implode("\n", $elementsAdditional);
         } else {
             $additional_data = $chat->additional_data;
         }
     } else {
         $additional_data = '';
     }
     foreach ($emailRecipient as $receiver) {
         $veryfyEmail = sha1(sha1($receiver . $secretHash) . $secretHash);
         $mail->Body = str_replace(array('{chat_id}', '{phone}', '{name}', '{email}', '{message}', '{additional_data}', '{url_request}', '{ip}', '{department}', '{url_accept}', '{operator}', '{country}', '{city}'), array($chat->id, $chat->phone, $chat->nick, $chat->email, $messagesContent, $additional_data, $chat->referrer, erLhcoreClassIPDetect::getIP(), (string) $chat->department, 'http://' . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $receiver, $operator, $chat->country_name, $chat->city), $sendMail->content);
         $mail->AddAddress($receiver);
         $mail->Send();
         $mail->ClearAddresses();
     }
     if ($sendMail->bcc_recipients != '') {
         $recipientsBCC = explode(',', $sendMail->bcc_recipients);
         foreach ($recipientsBCC as $receiver) {
             $receiver = trim($receiver);
             $veryfyEmail = sha1(sha1($receiver . $secretHash) . $secretHash);
             $mail->Body = str_replace(array('{chat_id}', '{phone}', '{name}', '{email}', '{message}', '{additional_data}', '{url_request}', '{ip}', '{department}', '{url_accept}', '{operator}', '{country}', '{city}'), array($chat->id, $chat->phone, $chat->nick, $chat->email, $messagesContent, $additional_data, $chat->referrer, erLhcoreClassIPDetect::getIP(), (string) $chat->department, 'http://' . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $receiver, $operator, $chat->country_name, $chat->city), $sendMail->content);
             $mail->AddAddress($receiver);
             $mail->Send();
             $mail->ClearAddresses();
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 public static function storeCollectedInformation($form, $collectedInformation)
 {
     $formCollected = new erLhAbstractModelFormCollected();
     $formCollected->ip = erLhcoreClassIPDetect::getIP();
     $formCollected->ctime = time();
     $formCollected->form_id = $form->id;
     $formCollected->identifier = isset($_POST['identifier']) ? $_POST['identifier'] : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');
     $formCollected->saveThis();
     // Finish collect information
     foreach ($collectedInformation as $fieldName => &$params) {
         if ($params['definition']['type'] == 'file') {
             $dir = 'var/storageform/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $formCollected->id . '/';
             erLhcoreClassChatEventDispatcher::getInstance()->dispatch('form.fill.file_path', array('path' => &$dir, 'storage_id' => $formCollected->id));
             erLhcoreClassFileUpload::mkdirRecursive($dir);
             $file = erLhcoreClassSearchHandler::moveUploadedFile($params['definition']['name'], $dir);
             $params['filename'] = $file;
             $params['filepath'] = $dir;
             erLhcoreClassChatEventDispatcher::getInstance()->dispatch('form.fill.store_file', array('file_params' => &$params));
         }
     }
     $formCollected->content = serialize($collectedInformation);
     $formCollected->saveThis();
     // Inform user about filled form
     erLhcoreClassChatMail::informFormFilled($formCollected, array('email' => self::$mainEmail));
 }
 public function saveThis()
 {
     $this->ctime = time();
     $this->ip = ip2long(erLhcoreClassIPDetect::getIP());
     erLhcoreClassQuestionary::getSession()->saveOrUpdate($this);
 }
 public static function handleRequest($paramsHandle = array())
 {
     if (isset($_SERVER['HTTP_USER_AGENT']) && !self::isBot($_SERVER['HTTP_USER_AGENT'])) {
         $newVisitor = false;
         if (isset($paramsHandle['vid']) && !empty($paramsHandle['vid'])) {
             $items = erLhcoreClassModelChatOnlineUser::getList(array('filter' => array('vid' => $paramsHandle['vid'])));
             if (!empty($items)) {
                 $item = array_shift($items);
                 // Visit duration les than 30m. Same as google analytics
                 // See: https://support.google.com/analytics/answer/2731565?hl=en
                 if (time() - $item->last_visit <= 30 * 60) {
                     $item->time_on_site += time() - $item->last_visit;
                     $item->tt_time_on_site += time() - $item->last_visit;
                 } else {
                     $item->time_on_site = 0;
                     $item->total_visits++;
                     $item->last_visit = time();
                     $item->pages_count = 0;
                     // Reset chat_id only if chat is not active or pending
                     if ($item->chat_id > 0) {
                         if ($item->chat === false || !in_array($item->chat->status, array(erLhcoreClassModelChat::STATUS_ACTIVE_CHAT, erLhcoreClassModelChat::STATUS_PENDING_CHAT))) {
                             $item->chat_id = 0;
                         }
                     }
                     if ($item->message_seen == 1 && $item->message_seen_ts < time() - (int) $paramsHandle['message_seen_timeout'] * 3600) {
                         $item->message_seen = 0;
                         $item->message_seen_ts = 0;
                         $item->operator_message = '';
                     }
                 }
                 $item->identifier = isset($paramsHandle['identifier']) && !empty($paramsHandle['identifier']) ? $paramsHandle['identifier'] : $item->identifier;
                 if (isset($paramsHandle['department']) && is_array($paramsHandle['department']) && count($paramsHandle['department']) == 1) {
                     $item->dep_id = array_shift($paramsHandle['department']);
                 } elseif (isset($paramsHandle['department']) && is_numeric($paramsHandle['department'])) {
                     $item->dep_id = (int) $paramsHandle['department'];
                 }
             } else {
                 $item = new erLhcoreClassModelChatOnlineUser();
                 $item->ip = erLhcoreClassIPDetect::getIP();
                 $item->vid = $paramsHandle['vid'];
                 $item->identifier = isset($paramsHandle['identifier']) && !empty($paramsHandle['identifier']) ? $paramsHandle['identifier'] : '';
                 $item->referrer = isset($_GET['r']) ? rawurldecode($_GET['r']) : '';
                 $item->total_visits = 1;
                 if (isset($paramsHandle['department']) && is_array($paramsHandle['department']) && count($paramsHandle['department']) == 1) {
                     $item->dep_id = array_shift($paramsHandle['department']);
                 } elseif (isset($paramsHandle['department']) && is_numeric($paramsHandle['department'])) {
                     $item->dep_id = (int) $paramsHandle['department'];
                 }
                 if (isset($paramsHandle['tz']) && is_numeric($paramsHandle['tz'])) {
                     $timezone_name = timezone_name_from_abbr(null, (int) $paramsHandle['tz'] * 3600, true);
                     if ($timezone_name !== false) {
                         $item->visitor_tz = $timezone_name;
                     }
                 }
                 self::detectLocation($item);
                 // Cleanup database then new user comes
                 self::cleanupOnlineUsers();
                 $item->store_chat = true;
                 $newVisitor = true;
             }
         } else {
             self::cleanupOnlineUsers();
             return false;
         }
         if (isset($paramsHandle['pages_count']) && $paramsHandle['pages_count'] == true) {
             $item->pages_count++;
             $item->tt_pages_count++;
             $item->store_chat = true;
             if (isset($_GET['onattr']) && is_array($_GET['onattr']) && !empty($_GET['onattr'])) {
                 $item->online_attr = json_encode($_GET['onattr']);
             }
             if ($item->has_message_from_operator == true) {
                 $item->invitation_seen_count++;
             }
             if (isset($paramsHandle['tz']) && is_numeric($paramsHandle['tz']) && $item->visitor_tz == '') {
                 $timezone_name = timezone_name_from_abbr(null, (int) $paramsHandle['tz'] * 3600, true);
                 if ($timezone_name !== false) {
                     $item->visitor_tz = $timezone_name;
                 }
             }
             // Hide invitation message after n times if required
             if ($item->has_message_from_operator == true && $item->invitation !== false && $item->invitation->hide_after_ntimes > 0 && $item->invitation_seen_count > $item->invitation->hide_after_ntimes) {
                 $item->message_seen = 1;
                 $item->message_seen_ts = time();
             }
         }
         $logPageView = false;
         // Update variables only if it's not JS to check for operator message
         if (!isset($paramsHandle['check_message_operator']) || isset($paramsHandle['pages_count']) && $paramsHandle['pages_count'] == true) {
             $item->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
             $item->current_page = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
             $item->page_title = isset($_GET['dt']) ? (string) rawurldecode($_GET['dt']) : '';
             $item->last_visit = time();
             $item->store_chat = true;
             $logPageView = true;
         }
         if ((!isset($paramsHandle['wopen']) || $paramsHandle['wopen'] == 0) && $item->operator_message == '' && isset($paramsHandle['pro_active_invite']) && $paramsHandle['pro_active_invite'] == 1 && isset($paramsHandle['pro_active_limitation']) && ($paramsHandle['pro_active_limitation'] == -1 || erLhcoreClassChat::getPendingChatsCountPublic($item->dep_id > 0 ? $item->dep_id : false) <= $paramsHandle['pro_active_limitation'])) {
             //Process pro active chat invitation if this visitor matches any rules
             erLhAbstractModelProactiveChatInvitation::processProActiveInvitation($item);
         }
         $activityChanged = false;
         if (isset($paramsHandle['uactiv'])) {
             $activityChanged = $item->user_active != (int) $paramsHandle['uactiv'] && $newVisitor == false;
             $item->user_active = (int) $paramsHandle['uactiv'];
         }
         // Save only then we have to, in general only then page view appears
         if ($item->store_chat == true) {
             $item->last_check_time = time();
             $item->saveThis();
             if ($newVisitor == true) {
                 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('onlineuser.created', array('tpl' => isset($paramsHandle['tpl']) ? $paramsHandle['tpl'] : false, 'ou' => &$item));
             } elseif ($logPageView == true) {
                 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('onlineuser.pageview_logged', array('tpl' => isset($paramsHandle['tpl']) ? $paramsHandle['tpl'] : false, 'ou' => &$item));
             }
             if ($activityChanged == true && $item->chat_id > 0) {
                 erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.data_changed_chat', array('chat_id' => $item->chat_id));
             }
         }
         return $item;
     } else {
         // Stop execution on google bot
         exit;
     }
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
            if (erLhcoreClassQuestionary::getCount($baseFilter, 'lh_question_answer') > 0) {
                $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('questionary/votingwidget', 'You have already send your feedback!');
            }
        }
        erLhcoreClassChatEventDispatcher::getInstance()->dispatch('questionaire.before_feedback_left', array('feedback' => &$answer, 'errors' => &$Errors));
        if (count($Errors) == 0) {
            $answer->saveThis();
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('questionaire.feedback_left', array('feedback' => &$answer));
            $tpl->set('received', true);
        } else {
            $tpl->set('errors', $Errors);
        }
    }
}
if ($votingRelative !== false) {
    $baseFilter = array('filter' => array('question_id' => $votingRelative->id, 'ip' => ip2long(erLhcoreClassIPDetect::getIP())));
    if ($votingRelative->revote > 0) {
        $baseFilter['filtergt']['ctime'] = time() - $votingRelative->revote_seconds;
    }
    if ($votingRelative->is_voting == 1) {
        if (erLhcoreClassQuestionary::getCount($baseFilter, 'lh_question_option_answer') > 0) {
            $tpl->set('already_voted', true);
        }
    } elseif (erLhcoreClassQuestionary::getCount($baseFilter, 'lh_question_answer') > 0) {
        $tpl->set('already_voted', true);
    }
}
$tpl->set('voting', $votingRelative);
$tpl->set('answer', $answer);
$Result['content'] = $tpl->fetch();
$Result['pagelayout'] = 'widget';
Ejemplo n.º 10
0
                 $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('locatorhq', erLhcoreClassIPDetect::getServerAddress(), array('ip' => $data['locatorhqip'], 'username' => $data['locatorhqusername'], 'api_key' => $data['locatorhq_api_key']));
                 if ($responseDetection == false || !isset($responseDetection->country_code)) {
                     $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that your service provider allows you to make requests to remote pages and your API key and username is correct!');
                 }
             }
         } elseif ($form->UseGeoIP == 'ipinfodbcom') {
             $data['geo_service_identifier'] = 'ipinfodbcom';
             $filledAPIData = true;
             if ($form->hasValidData('ipinfodbAPIKey') && $form->ipinfodbAPIKey != '') {
                 $data['ipinfodbcom_api_key'] = $form->ipinfodbAPIKey;
             } else {
                 $filledAPIData = false;
                 $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Please enter the API key!');
             }
             if ($filledAPIData == true) {
                 $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('ipinfodbcom', erLhcoreClassIPDetect::getServerAddress(), array('api_key' => $data['ipinfodbcom_api_key']));
                 if ($responseDetection == false || !isset($responseDetection->country_code)) {
                     $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that your service provider allows you to make requests to remote pages and your API key is correct!');
                 }
             }
         } elseif ($form->UseGeoIP == 'php_geoip') {
             $data['geo_service_identifier'] = 'php_geoip';
             $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('php_geoip', '94.23.200.91');
             if ($responseDetection == false || !isset($responseDetection->country_code)) {
                 $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that you have installed php-GeoIP module and GeoIPCity.dat file is available!');
             }
         }
     } else {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Please choose a service provider!');
     }
 }
Ejemplo n.º 11
0
 public static function getAdjustment($geo_adjustment, $onlineUserVid = '', $widgetMode = false, $onlineUserDefined = false)
 {
     $responseStatus = array('status' => 'normal');
     $onlineUser = false;
     if (isset($geo_adjustment['use_geo_adjustment']) && $geo_adjustment['use_geo_adjustment'] == true) {
         if ($widgetMode === true && $geo_adjustment['apply_widget'] == 0) {
             return $responseStatus;
         }
         if (is_object($onlineUserDefined)) {
             $onlineUser = $onlineUserDefined;
         } elseif (!empty($onlineUserVid)) {
             $onlineUser = erLhcoreClassModelChatOnlineUser::fetchByVid($onlineUserVid);
         }
         if ($onlineUser === false) {
             $onlineUser = new erLhcoreClassModelChatOnlineUser();
             // Just to pass instance
             $onlineUser->ip = erLhcoreClassIPDetect::getIP();
             erLhcoreClassModelChatOnlineUser::detectLocation($onlineUser);
         }
         $countriesAvailableFor = array();
         if ($geo_adjustment['available_for'] != '') {
             $countriesAvailableFor = explode(',', $geo_adjustment['available_for']);
         }
         if (!in_array($onlineUser->user_country_code, $countriesAvailableFor)) {
             if ($geo_adjustment['other_countries'] == 'all') {
                 if ($geo_adjustment['other_status'] == 'offline') {
                     $responseStatus = array('status' => 'offline');
                 } else {
                     $responseStatus = array('status' => 'hidden');
                 }
             } else {
                 if ($geo_adjustment['hide_for'] != '') {
                     $countrieshideFor = explode(',', $geo_adjustment['hide_for']);
                     if (in_array($onlineUser->user_country_code, $countrieshideFor)) {
                         if ($geo_adjustment['other_status'] == 'offline') {
                             $responseStatus = array('status' => 'offline');
                         } else {
                             $responseStatus = array('status' => 'hidden');
                         }
                     } else {
                         if ($geo_adjustment['rest_status'] == 'offline') {
                             $responseStatus = array('status' => 'offline');
                         } elseif ($geo_adjustment['rest_status'] == 'normal') {
                             $responseStatus = array('status' => 'normal');
                         } else {
                             $responseStatus = array('status' => 'hidden');
                         }
                     }
                 } else {
                     if ($geo_adjustment['rest_status'] == 'offline') {
                         $responseStatus = array('status' => 'offline');
                     } elseif ($geo_adjustment['rest_status'] == 'normal') {
                         $responseStatus = array('status' => 'normal');
                     } else {
                         $responseStatus = array('status' => 'hidden');
                     }
                 }
             }
         }
         // Normal status
     }
     return $responseStatus;
 }
Ejemplo n.º 12
0
 function validateRemember($hashCookie)
 {
     $parts = explode(':', $hashCookie);
     if (count($parts) == 3) {
         list($salt1, $id, $hash) = $parts;
         $cfgSite = erConfigClassLhConfig::getInstance();
         $salt2 = $cfgSite->getSetting('site', 'secrethash');
         try {
             $ruser = erLhcoreClassModelUserRemember::fetch($id);
             if ($hash == sha1($ruser->user_id . '_' . $ruser->id . $salt2 . $salt1 . erLhcoreClassIPDetect::getIP() . $_SERVER['HTTP_USER_AGENT'])) {
                 $ruser->mtime = time();
                 $ruser->updateThis();
                 $this->setLoggedUser($ruser->user_id);
                 // Update remember hash
                 $salt1 = erLhcoreClassModelForgotPassword::randomPassword(30);
                 $hash = $salt1 . ':' . $ruser->id . ':' . sha1($this->userid . '_' . $ruser->id . $salt2 . $salt1 . erLhcoreClassIPDetect::getIP() . $_SERVER['HTTP_USER_AGENT']);
                 setcookie('lhc_rm_u', $hash, time() + 365 * 24 * 3600, '/');
                 return true;
             }
         } catch (Exception $e) {
             return false;
         }
     } else {
         if (isset($_COOKIE['lhc_rm_u'])) {
             unset($_COOKIE['lhc_rm_u']);
             setcookie('lhc_rm_u', '', time() - 31 * 24 * 3600, '/');
         }
     }
     return false;
 }
Ejemplo n.º 13
0
<?php

$ipUpdate = erLhcoreClassModelChatConfig::fetch('update_ip')->current_value;
if ($ipUpdate != '' && erLhcoreClassIPDetect::isIgnored(erLhcoreClassIPDetect::getIP(), explode(',', $ipUpdate))) {
    $jsonObject = json_decode(erLhcoreClassModelChatOnlineUser::executeRequest('https://raw.githubusercontent.com/LiveHelperChat/livehelperchat/master/lhc_web/doc/update_db/structure.json'), true);
    if (is_array($jsonObject)) {
        $errorMessages = erLhcoreClassUpdate::doTablesUpdate($jsonObject);
        if (empty($errorMessages)) {
            $CacheManager = erConfigClassLhCacheConfig::getInstance();
            $CacheManager->expireCache();
            echo "UPDATE DONE\n";
        } else {
            echo "ERROR:\n" . implode("\n", $errorMessages);
        }
    }
} else {
    echo "Your IP is not allowed to perform updates\n";
}
exit;
echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Username');
?>
</label> 
								    <input class="form-control" type="text" name="locatorhqUsername" value="<?php 
isset($geo_data['locatorhqusername']) ? print htmlspecialchars($geo_data['locatorhqusername']) : (print '');
?>
"> 
								</div>
								
								<div class="form-group">
								    <label><?php 
echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'IP, if your site remote IP is different from detected one, please provide correct remote IP address');
?>
</label> 
								    <input class="form-control" type="text" name="locatorhqIP" value="<?php 
isset($geo_data['locatorhqip']) ? print htmlspecialchars($geo_data['locatorhqip']) : (print erLhcoreClassIPDetect::getServerAddress());
?>
"> 
                                </div>
								
						      </div>
						</div>
												
					</div>
				</div>
				
				<input type="submit" class="btn btn-default" name="StoreGeoIPConfiguration" value="<?php 
echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Save');
?>
" />
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
$tpl = erLhcoreClassTemplate::getInstance('lhchat/chatcheckstatus.tpl.php');
if (is_array($Params['user_parameters_unordered']['department'])) {
    erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']);
    $tpl->set('department', implode('/', $Params['user_parameters_unordered']['department']));
    $tpl->set('department_array', $Params['user_parameters_unordered']['department']);
} else {
    $tpl->set('department', false);
    $tpl->set('department_array', false);
}
$tpl->set('status', $Params['user_parameters_unordered']['status'] == 'true' ? true : false);
if (erLhcoreClassModelChatConfig::fetch('track_is_online')->current_value) {
    $ignorable_ip = erLhcoreClassModelChatConfig::fetch('ignorable_ip')->current_value;
    if ($ignorable_ip == '' || !erLhcoreClassIPDetect::isIgnored(erLhcoreClassIPDetect::getIP(), explode(',', $ignorable_ip))) {
        if ((string) $Params['user_parameters_unordered']['vid'] != '') {
            $db = ezcDbInstance::get();
            /**
             * Perhaps there is some pending operations for online visitor
             * */
            $stmt = $db->prepare('SELECT operation FROM lh_chat_online_user WHERE vid = :vid');
            $stmt->bindValue(':vid', (string) $Params['user_parameters_unordered']['vid']);
            $stmt->execute();
            $operation = $stmt->fetch(PDO::FETCH_COLUMN);
            echo $operation;
            $stmt = $db->prepare("UPDATE lh_chat_online_user SET last_check_time = :time, operation = '', operation_chat = '' WHERE vid = :vid");
            $stmt->bindValue(':time', time(), PDO::PARAM_INT);
            $stmt->bindValue(':vid', (string) $Params['user_parameters_unordered']['vid']);
            $stmt->execute();
        }
Ejemplo n.º 16
0
        if (!$form->hasValidData($nameField) || $form->{$nameField} == '' || $form->{$nameField} < time() - 600) {
            $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Invalid captcha code, please enable Javascript!');
        }
    }
    // Dynamic URL has higher priority
    if ($dynamic_url != '') {
        $item_new->url = $dynamic_url;
    }
    if (count($Errors) == 0) {
        $item_new->active = 0;
        $item_new->saveThis();
        erLhcoreClassChatMail::sendMailFAQ($item_new);
        $item_new = new erLhcoreClassFaq();
        $tpl->set('success', true);
        if (isset($_SESSION[erLhcoreClassIPDetect::getIP()]['form'])) {
            unset($_SESSION[erLhcoreClassIPDetect::getIP()]['form']);
        }
    } else {
        $tpl->set('errors', $Errors);
    }
    $tpl->set('edittab', true);
}
$tpl->set('items', $items);
$tpl->set('item_new', $item_new);
$tpl->set('pages', $pages);
$Result['content'] = $tpl->fetch();
$Result['pagelayout'] = 'widget';
$Result['dynamic_height'] = true;
$Result['dynamic_height_message'] = 'lhc_sizing_faq';
$Result['dynamic_height_append'] = 0;
if ($embedMode == true) {
 public function setIP()
 {
     $this->ip = erLhcoreClassIPDetect::getIP();
 }
Ejemplo n.º 18
0
<?php

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
header('Content-type: text/javascript');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 * 8) . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
$hash = sha1(erLhcoreClassIPDetect::getIP() . $Params['user_parameters']['timets'] . erConfigClassLhConfig::getInstance()->getSetting('site', 'secrethash'));
if (time() - $Params['user_parameters']['timets'] > 600 || time() - $Params['user_parameters']['timets'] < 0) {
    echo json_encode(array('result' => 'false'));
    exit;
}
if (erLhcoreClassModelChatConfig::fetch('session_captcha')->current_value == 1) {
    // Start session if required only
    $currentUser = erLhcoreClassUser::instance();
    $_SESSION[$_SERVER['REMOTE_ADDR']][$Params['user_parameters']['captcha_name']] = $hash;
}
echo json_encode(array('result' => $hash));
exit;