コード例 #1
0
 /**
  * Gets pending chats
  */
 public static function getTopTodaysOperators($limit = 100, $offset = 0)
 {
     $time = time() - 24 * 3600;
     $SQL = 'SELECT lh_chat.user_id,count(lh_chat.id) as assigned_chats FROM lh_chat WHERE time > :time AND user_id > 0 GROUP BY user_id';
     $db = ezcDbInstance::get();
     $stmt = $db->prepare($SQL);
     $stmt->bindValue(':time', $time, PDO::PARAM_INT);
     $stmt->setFetchMode(PDO::FETCH_ASSOC);
     $stmt->execute();
     $rows = $stmt->fetchAll();
     $usersID = array();
     foreach ($rows as $item) {
         $usersID[] = $item['user_id'];
     }
     if (!empty($usersID)) {
         $users = erLhcoreClassModelUser::getUserList(array('limit' => $limit, 'filterin' => array('id' => $usersID)));
     }
     $usersReturn = array();
     foreach ($rows as $row) {
         $usersReturn[$row['user_id']] = $users[$row['user_id']];
         $usersReturn[$row['user_id']]->statistic_total_chats = $row['assigned_chats'];
         $usersReturn[$row['user_id']]->statistic_total_messages = erLhcoreClassChat::getCount(array('filtergte' => array('time' => $time), 'filter' => array('user_id' => $row['user_id'])), 'lh_msg');
         $usersReturn[$row['user_id']]->statistic_upvotes = erLhcoreClassChat::getCount(array('filtergte' => array('time' => $time), 'filter' => array('fbst' => 1, 'user_id' => $row['user_id'])));
         $usersReturn[$row['user_id']]->statistic_downvotes = erLhcoreClassChat::getCount(array('filtergte' => array('time' => $time), 'filter' => array('fbst' => 2, 'user_id' => $row['user_id'])));
     }
     return $usersReturn;
 }
コード例 #2
0
 public function __get($var)
 {
     switch ($var) {
         case 'user':
             $this->user = erLhcoreClassModelUser::fetch($this->user_id);
             return $this->user;
             break;
         default:
             break;
     }
 }
コード例 #3
0
 public static function loginBySSO($params)
 {
     $settings = (include 'extension/singlesignon/settings/settings.ini.php');
     // Try to find operator by our logins
     if (isset($params[$settings['attr_map']['username']][0])) {
         $username = $params[$settings['attr_map']['username']][0];
         if (erLhcoreClassModelUser::userExists($username)) {
             $user = array_shift(erLhcoreClassModelUser::getUserList(array('limit' => 1, 'filter' => array('username'))));
             erLhcoreClassUser::instance()->setLoggedUser($user->id);
         } else {
             $user = new erLhcoreClassModelUser();
             foreach ($settings['attr_map'] as $attr => $ssoAttr) {
                 $user->{$attr} = $params[$settings['attr_map'][$attr]][0];
             }
             foreach ($settings['default_attributes'] as $attr => $value) {
                 $user->{$attr} = $value;
             }
             $user->password = sha1(erLhcoreClassModelForgotPassword::randomPassword() . rand(0, 1000) . microtime());
             $user->saveThis();
             // Set that users sees all pending chats
             erLhcoreClassModelUserSetting::setSetting('show_all_pending', 1, $user->id);
             // Set default departments
             erLhcoreClassUserDep::addUserDepartaments($settings['default_departments'], $user->id, $user);
             // Cleanup if previously existed
             erLhcoreClassModelGroupUser::removeUserFromGroups($user->id);
             // Assign user to default group
             foreach ($settings['default_user_groups'] as $group_id) {
                 $groupUser = new erLhcoreClassModelGroupUser();
                 $groupUser->group_id = $group_id;
                 $groupUser->user_id = $user->id;
                 $groupUser->saveThis();
             }
             erLhcoreClassUser::instance()->setLoggedUser($user->id);
         }
         return true;
     } else {
         throw new Exception('Username field not found');
     }
 }
コード例 #4
0
 public function __get($var)
 {
     switch ($var) {
         case 'user':
             try {
                 $this->user = erLhcoreClassModelUser::fetch($this->user_id);
             } catch (Exception $e) {
                 $this->user = '******';
             }
             return $this->user;
             break;
         default:
             break;
     }
 }
コード例 #5
0
 public function __get($var)
 {
     switch ($var) {
         case 'dep_group':
             $this->dep_group = erLhcoreClassModelDepartamentGroup::fetch($this->dep_group_id);
             return $this->dep_group;
             break;
         case 'user':
             $this->user = erLhcoreClassModelUser::fetch($this->user_id);
             return $this->user;
             break;
         default:
             break;
     }
 }
 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;
     }
 }
コード例 #7
0
 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;
         default:
             break;
     }
 }
コード例 #8
0
 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;
     }
 }
コード例 #9
0
 public function __get($var)
 {
     switch ($var) {
         case 'file_path_server':
             $this->file_path_server = $this->file_path . $this->name;
             return $this->file_path_server;
             break;
         case 'security_hash':
             $this->security_hash = md5($this->name . '_' . $this->chat_id);
             return $this->security_hash;
             break;
         case 'chat':
             $this->chat = false;
             if ($this->chat_id > 0) {
                 try {
                     $this->chat = erLhcoreClassModelChat::fetch($this->chat_id);
                 } catch (Exception $e) {
                     $this->chat = new erLhcoreClassModelChat();
                 }
             }
             return $this->chat;
             break;
         case 'user':
             $this->user = false;
             if ($this->user_id > 0) {
                 try {
                     $this->user = erLhcoreClassModelUser::fetch($this->user_id);
                 } catch (Exception $e) {
                     $this->user = false;
                 }
             }
             return $this->user;
             break;
         case 'date_front':
             $this->date_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->date);
             return $this->date_front;
             break;
         default:
             break;
     }
 }
コード例 #10
0
 public function removeInstanceData()
 {
     foreach (erLhAbstractModelFormCollected::getList(array('limit' => 1000000)) as $item) {
         $item->removeThis();
     }
     foreach (erLhAbstractModelWidgetTheme::getList(array('limit' => 1000000)) as $item) {
         $item->removeThis();
     }
     foreach (erLhcoreClassChat::getList(array('limit' => 1000000)) as $item) {
         $item->removeThis();
     }
     foreach (erLhcoreClassChat::getList(array('limit' => 1000000), 'erLhcoreClassModelChatFile', 'lh_chat_file') as $item) {
         $item->removeThis();
     }
     foreach (erLhcoreClassModelUser::getUserList(array('limit' => 1000000)) as $item) {
         $item->removeFile();
     }
     // Dispatch event for extensions
     erLhcoreClassChatEventDispatcher::getInstance()->dispatch('instance.destroyed', array('instance' => $this));
     return true;
 }
コード例 #11
0
 public function __get($var)
 {
     switch ($var) {
         case 'ctime_front':
             $this->ctime_front = date('Ymd') == date('Ymd', $this->ctime) ? date(erLhcoreClassModule::$dateHourFormat, $this->ctime) : date(erLhcoreClassModule::$dateDateHourFormat, $this->ctime);
             return $this->ctime_front;
             break;
         case 'lactivity_front':
             $this->lactivity_front = date('Ymd') == date('Ymd', $this->lactivity) ? date(erLhcoreClassModule::$dateHourFormat, $this->lactivity) : date(erLhcoreClassModule::$dateDateHourFormat, $this->lactivity);
             return $this->lactivity_front;
             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 'username_plain':
             list($this->username_plain) = explode('@', $this->username);
             return $this->username_plain;
             break;
         case 'username_plain_edit':
             list($this->username_plain_edit) = explode('@', $this->username);
             $subdomain = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['subdomain'];
             if ($subdomain != '') {
                 $this->username_plain_edit = $this->str_lreplace('.' . $subdomain, '', $this->username_plain_edit);
             }
             return $this->username_plain_edit;
             break;
         default:
             break;
     }
 }
コード例 #12
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;
 }
コード例 #13
0
ファイル: edit.php プロジェクト: nagyistoce/livehelperchat
<?php

$tpl = erLhcoreClassTemplate::getInstance('lhuser/edit.tpl.php');
$UserData = erLhcoreClassUser::getSession()->load('erLhcoreClassModelUser', (int) $Params['user_parameters']['user_id']);
if (isset($_POST['Update_account']) || isset($_POST['Save_account'])) {
    $definition = array('Password' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Password1' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Email' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'), 'Name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Surname' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Username' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'JobTitle' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Skype' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'XMPPUsername' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'UserTimeZone' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'UserDisabled' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'), 'HideMyStatus' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'), 'UserInvisible' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'), 'DefaultGroup' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', null, FILTER_REQUIRE_ARRAY));
    if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) {
        erLhcoreClassModule::redirect('user/userlist');
        exit;
    }
    $form = new ezcInputForm(INPUT_POST, $definition);
    $Errors = array();
    if (!$form->hasValidData('Username')) {
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/account', 'Please enter a username!');
    } elseif ($form->hasValidData('Username') && $form->Username != $UserData->username && !erLhcoreClassModelUser::userExists($form->Username)) {
        $UserData->username = $form->Username;
    } elseif ($form->hasValidData('Username') && $form->Username != $UserData->username) {
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/account', 'User exists!');
    }
    if (!$form->hasValidData('Email')) {
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/edit', 'Wrong email address');
    }
    if (!$form->hasValidData('Name') || $form->Name == '') {
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/edit', 'Please enter a name');
    }
    if ($form->hasValidData('Surname') && $form->Surname != '') {
        $UserData->surname = $form->Surname;
    } else {
        $UserData->surname = '';
    }
    if ($form->hasValidData('UserTimeZone') && $form->UserTimeZone != '') {
コード例 #14
0
ファイル: install.php プロジェクト: p4prawin/livechat
 erLhcoreClassRole::getSession()->save($RoleOperators);
 //Assing group role
 $db->query("CREATE TABLE IF NOT EXISTS `lh_grouprole` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `group_id` int(11) NOT NULL,\n                  `role_id` int(11) NOT NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `group_id` (`role_id`,`group_id`),\n                  KEY `group_id_primary` (`group_id`)\n                ) DEFAULT CHARSET=utf8;");
 // Assign admin role to admin group
 $GroupRole = new erLhcoreClassModelGroupRole();
 $GroupRole->group_id = $GroupData->id;
 $GroupRole->role_id = $Role->id;
 erLhcoreClassRole::getSession()->save($GroupRole);
 // Assign operators role to operators group
 $GroupRoleOperators = new erLhcoreClassModelGroupRole();
 $GroupRoleOperators->group_id = $GroupDataOperators->id;
 $GroupRoleOperators->role_id = $RoleOperators->id;
 erLhcoreClassRole::getSession()->save($GroupRoleOperators);
 // Users
 $db->query("CREATE TABLE IF NOT EXISTS `lh_users` (\n                  `id` int(11) NOT NULL AUTO_INCREMENT,\n                  `username` varchar(40) NOT NULL,\n                  `password` varchar(40) NOT NULL,\n                  `email` varchar(100) NOT NULL,\n                  `time_zone` varchar(100) NOT NULL,\n                  `name` varchar(100) NOT NULL,\n                  `surname` varchar(100) NOT NULL,\n                  `filepath` varchar(200) NOT NULL,\n                  `filename` varchar(200) NOT NULL,\n                  `job_title` varchar(100) NOT NULL,\n                  `xmpp_username` varchar(200) NOT NULL,\n                  `skype` varchar(50) NOT NULL,\n                  `disabled` tinyint(4) NOT NULL,\n                  `hide_online` tinyint(1) NOT NULL,\n                  `all_departments` tinyint(1) NOT NULL,\n                  `invisible_mode` tinyint(1) NOT NULL,\n                  `rec_per_req` tinyint(1) NOT NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `hide_online` (`hide_online`),\n                  KEY `rec_per_req` (`rec_per_req`),\n                  KEY `email` (`email`),\n                  KEY `xmpp_username` (`xmpp_username`)\n                ) DEFAULT CHARSET=utf8;");
 $UserData = new erLhcoreClassModelUser();
 $UserData->setPassword($form->AdminPassword);
 $UserData->email = $form->AdminEmail;
 $UserData->name = $form->AdminName;
 $UserData->surname = $form->AdminSurname;
 $UserData->username = $form->AdminUsername;
 $UserData->all_departments = 1;
 erLhcoreClassUser::getSession()->save($UserData);
 // User departaments
 $db->query("CREATE TABLE IF NOT EXISTS `lh_userdep` (\n\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `user_id` int(11) NOT NULL,\n\t\t\t\t  `dep_id` int(11) NOT NULL,\n\t\t\t\t  `last_activity` int(11) NOT NULL,\n\t\t\t\t  `hide_online` int(11) NOT NULL,\n\t\t\t\t  `last_accepted` int(11) NOT NULL,\n\t\t\t\t  `active_chats` int(11) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t\t  KEY `last_activity_hide_online_dep_id` (`last_activity`,`hide_online`,`dep_id`),\n\t\t\t\t  KEY `dep_id` (`dep_id`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 // Insert record to departament instantly
 $db->query("INSERT INTO `lh_userdep` (`user_id`,`dep_id`,`last_activity`,`hide_online`,`last_accepted`,`active_chats`) VALUES ({$UserData->id},0,0,0,0,0)");
 // Transfer chat
 $db->query("CREATE TABLE IF NOT EXISTS `lh_transfer` (\n\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `chat_id` int(11) NOT NULL,\n\t\t\t\t  `dep_id` int(11) NOT NULL,\n\t\t\t\t  `transfer_user_id` int(11) NOT NULL,\n\t\t\t\t  `from_dep_id` int(11) NOT NULL,\n\t\t\t\t  `transfer_to_user_id` int(11) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `dep_id` (`dep_id`),\n\t\t\t\t  KEY `transfer_user_id_dep_id` (`transfer_user_id`,`dep_id`),\n\t\t\t\t  KEY `transfer_to_user_id` (`transfer_to_user_id`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 // Remember user table
 $db->query("CREATE TABLE IF NOT EXISTS `lh_users_remember` (\n\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t `user_id` int(11) NOT NULL,\n\t\t\t\t `mtime` int(11) NOT NULL,\n\t\t\t\t PRIMARY KEY (`id`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
コード例 #15
0
 public function __get($var)
 {
     switch ($var) {
         case 'last_visit_front':
             return $this->last_visit_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->last_visit);
             break;
         case 'first_visit_front':
             return $this->first_visit_front = date(erLhcoreClassModule::$dateDateHourFormat, $this->first_visit);
             break;
         case 'invitation':
             $this->invitation = false;
             if ($this->invitation_id > 0) {
                 try {
                     $this->invitation = erLhAbstractModelProactiveChatInvitation::fetch($this->invitation_id);
                 } catch (Exception $e) {
                     $this->invitation = false;
                 }
             }
             return $this->invitation;
             break;
         case 'has_message_from_operator':
             return $this->message_seen == 0 && $this->operator_message != '';
             break;
         case 'notes_intro':
             return $this->notes_intro = $this->notes != '' ? '[ ' . mb_substr($this->notes, 0, 50) . ' ]' . '<br/>' : '';
             break;
         case 'chat':
             $this->chat = false;
             if ($this->chat_id > 0) {
                 try {
                     $this->chat = erLhcoreClassModelChat::fetch($this->chat_id);
                 } catch (Exception $e) {
                     //
                 }
             }
             return $this->chat;
             break;
         case 'can_view_chat':
             $this->can_view_chat = false;
             $currentUser = erLhcoreClassUser::instance();
             if ($this->operator_user_id == $currentUser->getUserID()) {
                 $this->can_view_chat = true;
                 // Faster way
             } else {
                 if ($this->chat instanceof erLhcoreClassModelChat) {
                     $this->can_view_chat = erLhcoreClassChat::hasAccessToRead($this->chat);
                 }
             }
             return $this->can_view_chat;
             break;
         case 'operator_user':
             $this->operator_user = false;
             if ($this->operator_user_id > 0) {
                 try {
                     $this->operator_user = erLhcoreClassModelUser::fetch($this->operator_user_id);
                 } catch (Exception $e) {
                 }
             }
             return $this->operator_user;
             break;
         case 'operator_user_send':
             $this->operator_user_send = $this->operator_user !== false;
             return $this->operator_user_send;
             break;
         case 'operator_user_string':
             $this->operator_user_string = (string) $this->operator_user;
             return $this->operator_user_string;
             break;
         case 'time_on_site_front':
             $this->time_on_site_front = gmdate(erLhcoreClassModule::$dateHourFormat, $this->time_on_site);
             return $this->time_on_site_front;
             break;
         case 'tt_time_on_site_front':
             $this->tt_time_on_site_front = null;
             $diff = $this->tt_time_on_site;
             $days = floor($diff / (3600 * 24));
             $hours = floor(($diff - $days * 3600 * 24) / 3600);
             $minits = floor(($diff - $hours * 3600 - $days * 3600 * 24) / 60);
             $seconds = $diff - $hours * 3600 - $minits * 60 - $days * 3600 * 24;
             if ($days > 0) {
                 $this->tt_time_on_site_front = $days . ' d.';
             } elseif ($hours > 0) {
                 $this->tt_time_on_site_front = $hours . ' h.';
             } elseif ($minits > 0) {
                 $this->tt_time_on_site_front = $minits . ' m.';
             } elseif ($seconds >= 0) {
                 $this->tt_time_on_site_front = $seconds . ' s.';
             }
             return $this->tt_time_on_site_front;
             break;
         case 'last_visit_seconds_ago':
             $this->last_visit_seconds_ago = time() - $this->last_visit;
             return $this->last_visit_seconds_ago;
             break;
         case 'last_check_time_ago':
             $this->last_check_time_ago = time() - $this->last_check_time;
             return $this->last_check_time_ago;
             break;
         case 'visitor_tz_time':
             $this->visitor_tz_time = '-';
             if ($this->visitor_tz != '') {
                 $date = new DateTime(null, new DateTimeZone($this->visitor_tz));
                 $this->visitor_tz_time = $date->format(erLhcoreClassModule::$dateHourFormat);
             }
             return $this->visitor_tz_time;
             break;
         case 'lastactivity_ago':
             $this->lastactivity_ago = '';
             if ($this->last_visit > 0) {
                 $periods = array("s.", "m.", "h.", "d.", "w.", "m.", "y.", "dec.");
                 $lengths = array("60", "60", "24", "7", "4.35", "12", "10");
                 $difference = time() - $this->last_visit;
                 for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) {
                     $difference /= $lengths[$j];
                 }
                 $difference = round($difference);
                 $this->lastactivity_ago = "{$difference} {$periods[$j]}";
             }
             return $this->lastactivity_ago;
             break;
         case 'screenshot':
             $this->screenshot = false;
             if ($this->screenshot_id > 0) {
                 try {
                     $this->screenshot = erLhcoreClassModelChatFile::fetch($this->screenshot_id);
                 } catch (Exception $e) {
                 }
             }
             return $this->screenshot;
             break;
         case 'online_attr_system_array':
             $this->online_attr_system_array = array();
             if ($this->online_attr_system != '') {
                 $this->online_attr_system_array = json_decode($this->online_attr_system, true);
             }
             return $this->online_attr_system_array;
             break;
         case 'online_status':
             $this->online_status = 2;
             // Offline
             if (erLhcoreClassChat::$trackTimeout == 0) {
                 erLhcoreClassChat::$trackTimeout = 15;
             }
             if (erLhcoreClassChat::$trackActivity == true) {
                 if ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && $this->user_active == 1) {
                     //User still on site, it does not matter that he have closed widget.
                     $this->online_status = 0;
                     // Online
                 } elseif ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && $this->user_active == 0) {
                     $this->online_status = 1;
                     // Away
                 }
             } else {
                 if ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && time() - $this->last_user_msg_time < 300) {
                     //User still on site, it does not matter that he have closed widget.
                     $this->online_status = 0;
                     // Online
                 } elseif ($this->last_check_time_ago < erLhcoreClassChat::$trackTimeout + 10 && time() - $this->last_user_msg_time >= 300) {
                     $this->online_status = 1;
                     // Away
                 }
             }
             return $this->online_status;
             break;
         default:
             break;
     }
 }
コード例 #16
0
ファイル: statistic.tpl.php プロジェクト: p4prawin/livechat
				    ['<?php 
    echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic', 'User');
    ?>
','<?php 
    echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic', 'Messages');
    ?>
']
				    <?php 
    foreach ($numberOfMsgByUser as $data) {
        $operator = '';
        if ($data['user_id'] == 0) {
            $operator = 'Visitor';
        } elseif ($data['user_id'] == -1) {
            $operator = 'System assistant';
        } else {
            $operator = erLhcoreClassModelUser::fetch($data['user_id'], true)->username;
        }
        ?>
				    	<?php 
        echo ',[\'' . htmlspecialchars($operator, ENT_QUOTES) . '\',' . $data['number_of_chats'] . ']';
        ?>
				    <?php 
    }
    ?>
				  ]);	   
				  var options = {
				    title: '<?php 
    echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/statistic', 'Number of messages by user');
    ?>
',
				    hAxis: {titleTextStyle: {color: 'red'}},
コード例 #17
0
         }
         $stringParts[] = array('key' => $name_item, 'value' => isset($valuesArray[$key]) ? trim($valuesArray[$key]) : '');
     }
     $chat->additional_data = json_encode($stringParts);
 }
 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 ($form->hasValidData('operator') && erLhcoreClassModelUser::getUserCount(array('filter' => array('id' => $form->operator, 'disabled' => 0))) > 0) {
     $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) {
コード例 #18
0
 public function canUserBeSaved($params)
 {
     if (erLhcoreClassInstance::getInstance()->max_operators > 0 && $params['userData']->disabled == 0) {
         $isEditingUserDisabled = erLhcoreClassModelUser::getUserCount(array('filter' => array('disabled' => 1, 'id' => $params['userData']->id))) > 0;
         // User is enabling one of disabled users
         if ($isEditingUserDisabled == true && erLhcoreClassModelUser::getUserCount(array('filter' => array('disabled' => 0))) + 1 > erLhcoreClassInstance::getInstance()->max_operators) {
             $params['errors'][] = erTranslationClassLhTranslation::getInstance()->getTranslation('instance/edit', 'You cannot enable user, because you have exceeded maximum number of allowed operators!');
         }
     }
 }
コード例 #19
0
 public static function validateAccount(&$userData)
 {
     $definition = array('Password' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Password1' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Email' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'validate_email'), 'Name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'unsafe_raw'), 'Surname' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::REQUIRED, 'unsafe_raw'), 'Username' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'JobTitle' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Skype' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'XMPPUsername' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'ChatNickname' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'UserTimeZone' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'UserInvisible' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'), 'ReceivePermissionRequest' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean'));
     $form = new ezcInputForm(INPUT_POST, $definition);
     $Errors = array();
     if (!$form->hasValidData('Username') || $form->Username == '') {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/validator', 'Please enter a username');
     } else {
         if ($form->Username != $userData->username) {
             $userData->username = $form->Username;
             if (erLhcoreClassModelUser::userExists($userData->username) === true) {
                 $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/validator', 'User exists');
             }
         }
     }
     if ($form->hasValidData('Password') && $form->hasValidData('Password1')) {
         $userData->password_temp_1 = $form->Password;
         $userData->password_temp_2 = $form->Password1;
     }
     if ($form->hasInputField('Password') && (!$form->hasInputField('Password1') || $form->Password != $form->Password1)) {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/validator', 'Passwords mismatch');
     } else {
         if ($form->hasInputField('Password') && $form->hasInputField('Password1') && $form->Password != '' && $form->Password1 != '') {
             $userData->setPassword($form->Password);
             $userData->password_front = $form->Password;
         }
     }
     if ($form->hasValidData('ChatNickname') && $form->ChatNickname != '') {
         $userData->chat_nickname = $form->ChatNickname;
     } else {
         $userData->chat_nickname = '';
     }
     if (!$form->hasValidData('Email')) {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/validator', 'Wrong email address');
     } else {
         $userData->email = $form->Email;
     }
     if (!$form->hasValidData('Name') || $form->Name == '') {
         $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/validator', 'Please enter a name');
     } else {
         $userData->name = $form->Name;
     }
     if ($form->hasValidData('Surname') && $form->Surname != '') {
         $userData->surname = $form->Surname;
     } else {
         $userData->surname = '';
     }
     if ($form->hasValidData('JobTitle') && $form->JobTitle != '') {
         $userData->job_title = $form->JobTitle;
     } else {
         $userData->job_title = '';
     }
     if ($form->hasValidData('UserTimeZone') && $form->UserTimeZone != '') {
         $userData->time_zone = $form->UserTimeZone;
         CSCacheAPC::getMem()->setSession('lhc_user_timezone', $userData->time_zone, true);
     } else {
         CSCacheAPC::getMem()->setSession('lhc_user_timezone', '', true);
         $userData->time_zone = '';
     }
     if (erLhcoreClassUser::instance()->hasAccessTo('lhuser', 'changevisibility')) {
         if ($form->hasValidData('UserInvisible') && $form->UserInvisible == true) {
             $userData->invisible_mode = 1;
         } else {
             $userData->invisible_mode = 0;
         }
     }
     if (erLhcoreClassUser::instance()->hasAccessTo('lhuser', 'receivepermissionrequest')) {
         if ($form->hasValidData('ReceivePermissionRequest') && $form->ReceivePermissionRequest == true) {
             $userData->rec_per_req = 1;
         } else {
             $userData->rec_per_req = 0;
         }
     }
     if (erLhcoreClassUser::instance()->hasAccessTo('lhuser', 'changeskypenick')) {
         if ($form->hasValidData('Skype') && $form->Skype != '') {
             $userData->skype = $form->Skype;
         } else {
             $userData->skype = '';
         }
     }
     if ($form->hasValidData('XMPPUsername') && $form->XMPPUsername != '') {
         $userData->xmpp_username = $form->XMPPUsername;
     } else {
         $userData->xmpp_username = '';
     }
     return $Errors;
 }
コード例 #20
0
<?php

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
header('Content-Type: application/json');
try {
    erLhcoreClassRestAPIHandler::validateRequest();
    if (isset($_GET['user_id']) && is_numeric($_GET['user_id'])) {
        $userData = erLhcoreClassModelUser::fetch((int) $_GET['user_id']);
    } elseif (isset($_GET['username']) && !empty($_GET['username'])) {
        $userData = erLhcoreClassModelUser::findOne(array('filter' => array('username' => $_GET['username'])));
    } elseif (isset($_GET['email']) && !empty($_GET['email'])) {
        $userData = erLhcoreClassModelUser::findOne(array('filter' => array('email' => $_GET['email'])));
    }
    if (!$userData instanceof erLhcoreClassModelUser) {
        throw new Exception('User could not be found!');
    }
    if ($_GET['status'] == 'true') {
        $userData->hide_online = 0;
        $text = 'flash_on';
    } else {
        $text = 'flash_off';
        $userData->hide_online = 1;
    }
    $userData->operation_admin .= "\$('#online-offline-user').text('" . $text . "');";
    erLhcoreClassUser::getSession()->update($userData);
    erLhcoreClassUserDep::setHideOnlineStatus($userData);
    erLhcoreClassRestAPIHandler::outputResponse(array('offline' => $userData->hide_online));
    erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.operator_status_changed', array('user' => &$userData, 'reason' => 'rest_api'));
} catch (Exception $e) {
    echo json_encode(array('error' => true, 'result' => $e->getMessage()));
コード例 #21
0
<?php

$cfg = erConfigClassLhConfig::getInstance();
$secretHash = $cfg->getSetting('site', 'seller_secret_hash');
$validateHash = sha1((string) $Params['user_parameters']['id'] . (string) $Params['user_parameters']['date'] . $secretHash . '_' . (string) $Params['user_parameters']['operators']);
if ((string) $Params['user_parameters']['hash'] == $validateHash && $Params['user_parameters']['id'] == erLhcoreClassInstance::$instanceChat->id && date('Ym') == (string) $Params['user_parameters']['date']) {
    if ($Params['user_parameters']['operators'] > 0) {
        $userCount = erLhcoreClassModelUser::getUserCount(array('filter' => array('disabled' => 0)));
        // We have to disable exceeded users
        if ($userCount > $Params['user_parameters']['operators']) {
            $users = erLhcoreClassModelUser::getUserList(array('sort' => 'id ASC', 'filter' => array('disabled' => 0), 'offset' => (int) $Params['user_parameters']['operators'], 'limit' => 100000000));
            foreach ($users as $user) {
                $user->disabled = 1;
                $user->saveThis();
            }
        }
    }
    echo "ok";
} else {
    echo 'Invalid hash';
}
exit;
コード例 #22
0
ファイル: edit.php プロジェクト: detain/livehelperchat
<?php

$tpl = erLhcoreClassTemplate::getInstance('lhuser/edit.tpl.php');
try {
    $UserData = erLhcoreClassModelUser::fetch((int) $Params['user_parameters']['user_id']);
} catch (Exception $e) {
    erLhcoreClassModule::redirect('user/userlist');
    exit;
}
$tpl->set('tab', $Params['user_parameters_unordered']['tab'] == 'canned' ? 'tab_canned' : '');
if (isset($_POST['Update_account']) || isset($_POST['Save_account'])) {
    if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) {
        erLhcoreClassModule::redirect('user/edit', '/' . $UserData->id);
        exit;
    }
    $Errors = erLhcoreClassUserValidator::validateUserEdit($UserData);
    if (isset($_POST['DeletePhoto'])) {
        $UserData->removeFile();
    }
    $userPhotoErrors = erLhcoreClassUserValidator::validateUserPhoto($UserData);
    if ($userPhotoErrors !== false) {
        $Errors = array_merge($Errors, $userPhotoErrors);
    }
    if (count($Errors) == 0) {
        erLhcoreClassUser::getSession()->update($UserData);
        erLhcoreClassUserDep::setHideOnlineStatus($UserData);
        $UserData->setUserGroups();
        $CacheManager = erConfigClassLhCacheConfig::getInstance();
        $CacheManager->expireCache();
        erLhcoreClassChatEventDispatcher::getInstance()->dispatch('user.user_modified', array('userData' => &$UserData, 'password' => $UserData->password_front));
        if (isset($_POST['Save_account'])) {
コード例 #23
0
ファイル: lhchatmail.php プロジェクト: sirromas/medical
 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();
         }
     }
 }
コード例 #24
0
 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;
     }
 }
コード例 #25
0
ファイル: getuser.php プロジェクト: remdex/livehelperchat
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
header('Content-Type: application/json');
try {
    erLhcoreClassRestAPIHandler::validateRequest();
    // init data
    $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
    $username = isset($_GET['username']) ? trim($_GET['username']) : '';
    $email = isset($_GET['email']) ? trim($_GET['email']) : '';
    $password = isset($_GET['password']) ? trim($_GET['password']) : '';
    // init param, check what is supplied
    $param = $username != '' ? array('username' => $username) : array('email' => '00');
    // dummy email value to ensure 0 res
    $param = $email != '' ? array('email' => $email) : $param;
    // init user
    $user = $user_id > 0 ? erLhcoreClassModelUser::fetch($user_id) : erLhcoreClassModelUser::findOne(array('filter' => $param));
    // check we have data
    if (!$user instanceof erLhcoreClassModelUser) {
        throw new Exception('User could not be found!');
    }
    // check if password is given, if so, validate password
    if ($password != '') {
        // check password encryption type
        if (strlen($user->password) == 40) {
            // get password hash
            $cfgSite = erConfigClassLhConfig::getInstance();
            $secretHash = $cfgSite->getSetting('site', 'secrethash');
            $pass_hash = sha1($password . $secretHash . sha1($password));
            $verified = $user->password == $pass_hash ? 1 : 0;
        } else {
            $verified = password_verify($password, $user->password) ? 1 : 0;
コード例 #26
0
    exit;
}
$data = erLhcoreClassModelChatConfig::fetch('autologin_data')->data;
if ($data['enabled'] == 1) {
    $dataRequest = array('r' => base64_decode(rawurldecode($Params['user_parameters_unordered']['r'])), 'u' => rawurldecode($Params['user_parameters_unordered']['u']), 'l' => rawurldecode($Params['user_parameters_unordered']['l']), 't' => rawurldecode($Params['user_parameters_unordered']['t']));
    $dataRequest = array_filter($dataRequest);
    $validateHash = sha1($data['secret_hash'] . sha1($data['secret_hash'] . implode(',', $dataRequest)));
    if ($validateHash == $Params['user_parameters']['hash']) {
        if ($dataRequest['t'] > 0 && $dataRequest['t'] < time()) {
            die(erTranslationClassLhTranslation::getInstance()->getTranslation('users/autologin', 'Autologin hash has expired'));
        }
        try {
            if (is_numeric($dataRequest['u'])) {
                $userToLogin = erLhcoreClassModelUser::fetch((int) $dataRequest['u']);
            } else {
                $users = erLhcoreClassModelUser::getUserList(array('limit' => 1, 'filter' => array('username' => $dataRequest['l'])));
                if (!empty($users)) {
                    $userToLogin = array_shift($users);
                } else {
                    die(erTranslationClassLhTranslation::getInstance()->getTranslation('users/autologin', 'Could not find a user'));
                }
            }
        } catch (Exception $e) {
            die($e->getMessage());
        }
        if ($userToLogin instanceof erLhcoreClassModelUser) {
            erLhcoreClassUser::instance()->setLoggedUser($userToLogin->id);
            header('Location: ' . erLhcoreClassDesign::baseurldirect('site_admin') . '/' . ltrim($dataRequest['r'], '/'));
            exit;
        } else {
            die(erTranslationClassLhTranslation::getInstance()->getTranslation('users/autologin', 'Could not find a provided user'));
コード例 #27
0
ファイル: accept.php プロジェクト: Adeelgill/livehelperchat
<?php

$cfgSite = erConfigClassLhConfig::getInstance();
$secretHash = $cfgSite->getSetting('site', 'secrethash');
if ($Params['user_parameters']['validation_hash'] == sha1(sha1($Params['user_parameters']['email'] . $secretHash) . $secretHash)) {
    $accept = erLhcoreClassModelChatAccept::fetchByHash($Params['user_parameters']['hash']);
    if ($accept !== false) {
        $chat_id = $accept->chat_id;
        if ($accept->wused == 0) {
            $userID = erLhcoreClassModelUser::fetchUserByEmail($Params['user_parameters']['email'], trim($Params['user_parameters']['email']) != '' ? trim($Params['user_parameters']['email']) : false);
            if ($userID !== false && $accept->ctime > time() - erLhcoreClassModelChatConfig::fetch('accept_chat_link_timeout')->current_value) {
                $accept->wused = 1;
                $accept->saveThis();
                erLhcoreClassUser::instance()->setLoggedUser($userID);
                erLhcoreClassModule::redirect('chat/single', '/' . $chat_id);
                exit;
            } else {
                erLhcoreClassModule::redirect('user/login', '/(r)/' . rawurlencode(base64_encode('chat/single/' . $chat_id)));
                exit;
            }
        } else {
            erLhcoreClassModule::redirect('user/login', '/(r)/' . rawurlencode(base64_encode('chat/single/' . $chat_id)));
            exit;
        }
        erLhcoreClassModelChatAccept::cleanup();
    }
}
erLhcoreClassModule::redirect('user/login');
exit;
コード例 #28
0
ファイル: request.php プロジェクト: sirromas/medical
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('permission/request', 'Please choose a user!');
    } else {
        $userRecipient = erLhcoreClassModelUser::fetch($form->UserID);
    }
    if ($userRecipient !== false && $userRecipient->rec_per_req == 0) {
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('permission/request', 'This user can not receive permision request!');
    }
    if ($form->hasValidData('Permissions') && $form->Permissions != '') {
        $permissionsCombinations = explode(',', $form->Permissions);
        $permissionsRequestedData = array();
        foreach ($permissionsCombinations as $combination) {
            list($module, $function) = explode('_f_', $combination);
            $moduleName = erLhcoreClassModules::getModuleName($module);
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('lhpermission.getmodulename', array('module' => $module, 'name' => &$moduleName));
            $functionName = erLhcoreClassModules::getFunctionName($module, $function);
            $permissionsRequestedData[] = $moduleName . ' - ' . $functionName;
        }
        $tpl->set('permission', $form->Permissions);
    } else {
        $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('permission/request', 'Permissions were not provided');
    }
    if (empty($Errors)) {
        erLhcoreClassChatMail::sendMailRequestPermission($userRecipient, $currentUser->getUserData(), implode("\n", $permissionsRequestedData));
        $tpl->set('requested', true);
    } else {
        $tpl->set('errors', $Errors);
    }
}
$tpl->set('users', erLhcoreClassModelUser::getUserList(array('limit' => 100, 'filter' => array('rec_per_req' => 1))));
$Result['content'] = $tpl->fetch();
$Result['pagelayout'] = 'popup';
コード例 #29
0
 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;
     }
 }
コード例 #30
0
ファイル: install.php プロジェクト: detain/livehelperchat
 function step3()
 {
     $Errors = array();
     $form = (object) $this->settings['admin'];
     if (!filter_var($form->AdminUsername, FILTER_UNSAFE_RAW)) {
         $Errors[] = 'Please enter admin username';
     }
     if (!empty($form->AdminUsername) && strlen($form->AdminUsername) > 40) {
         $Errors[] = 'Maximum 40 characters for admin username';
     }
     if (!filter_var($form->AdminPassword, FILTER_UNSAFE_RAW)) {
         $Errors[] = 'Please enter admin password';
     }
     if (!empty($form->AdminPassword) && strlen($form->AdminPassword) > 40) {
         $Errors[] = 'Maximum 40 characters for admin password';
     }
     if (!filter_var($form->AdminEmail, FILTER_VALIDATE_EMAIL)) {
         $Errors[] = 'Wrong email address';
     }
     if (!filter_var($form->DefaultDepartament, FILTER_SANITIZE_STRING)) {
         $Errors[] = 'Please enter default department name';
     }
     if (count($Errors) == 0) {
         $adminEmail = $form->AdminEmail;
         /*DATABASE TABLES SETUP*/
         $db = ezcDbInstance::get();
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `nick` varchar(50) NOT NULL,\n                `status` int(11) NOT NULL DEFAULT '0',\n                `status_sub` int(11) NOT NULL DEFAULT '0',\n                `time` int(11) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                `hash` varchar(40) NOT NULL,\n                `referrer` text NOT NULL,\n                `session_referrer` text NOT NULL,\n                `chat_variables` text NOT NULL,\n                `remarks` text NOT NULL,\n                `ip` varchar(100) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                `product_id` int(11) NOT NULL,\n                `user_status` int(11) NOT NULL DEFAULT '0',\n                `user_closed_ts` int(11) NOT NULL DEFAULT '0',\n                `support_informed` int(11) NOT NULL DEFAULT '0',\n                `unread_messages_informed` int(11) NOT NULL DEFAULT '0',\n                `reinform_timeout` int(11) NOT NULL DEFAULT '0',\n                `email` varchar(100) NOT NULL,\n                `country_code` varchar(100) NOT NULL,\n                `country_name` varchar(100) NOT NULL,\n                `unanswered_chat` int(11) NOT NULL,\n                `user_typing` int(11) NOT NULL,\n                `user_typing_txt` varchar(50) NOT NULL,\n                `operator_typing` int(11) NOT NULL,\n                `operator_typing_id` int(11) NOT NULL,\n                `phone` varchar(100) NOT NULL,\n                `has_unread_messages` int(11) NOT NULL,\n                `last_user_msg_time` int(11) NOT NULL,\n                `fbst` tinyint(1) NOT NULL,\n                `online_user_id` int(11) NOT NULL,\n                `last_msg_id` int(11) NOT NULL,\n                `additional_data` text NOT NULL,\n                `timeout_message` varchar(250) NOT NULL,\n                `user_tz_identifier` varchar(50) NOT NULL,\n                `lat` varchar(10) NOT NULL,\n                `lon` varchar(10) NOT NULL,\n                `city` varchar(100) NOT NULL,\n                `operation` text NOT NULL,\n                `operation_admin` varchar(200) NOT NULL,\n                `chat_locale` varchar(10) NOT NULL,\n                `chat_locale_to` varchar(10) NOT NULL,\n                `mail_send` int(11) NOT NULL,\n                `screenshot_id` int(11) NOT NULL,\n                `wait_time` int(11) NOT NULL,\n                `wait_timeout` int(11) NOT NULL,\n                `wait_timeout_send` int(11) NOT NULL,\n                `wait_timeout_repeat` int(11) NOT NULL,\n                `chat_duration` int(11) NOT NULL,\n                `tslasign` int(11) NOT NULL,\n                `priority` int(11) NOT NULL,\n                `chat_initiator` int(11) NOT NULL,\n                `transfer_timeout_ts` int(11) NOT NULL,\n                `transfer_timeout_ac` int(11) NOT NULL,\n                `transfer_if_na` int(11) NOT NULL,\n                `na_cb_executed` int(11) NOT NULL,\n                `nc_cb_executed` tinyint(1) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `status_user_id` (`status`,`user_id`),\n            KEY `user_id` (`user_id`),\n            KEY `unanswered_chat` (`unanswered_chat`),\n            KEY `online_user_id` (`online_user_id`),\n            KEY `dep_id` (`dep_id`),\n            KEY `product_id` (`product_id`),\n            KEY `has_unread_messages_dep_id_id` (`has_unread_messages`,`dep_id`,`id`),\n            KEY `status_dep_id_id` (`status`,`dep_id`,`id`),\n            KEY `status_dep_id_priority_id` (`status`,`dep_id`,`priority`,`id`),\n            KEY `status_priority_id` (`status`,`priority`,`id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_blocked_user` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `ip` varchar(100) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                `datets` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `ip` (`ip`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_archive_range` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `range_from` int(11) NOT NULL,\n                `range_to` int(11) NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_auto_responder` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `siteaccess` varchar(3) NOT NULL,\n                `wait_message` varchar(250) NOT NULL,\n                `wait_timeout` int(11) NOT NULL,\n                `position` int(11) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                `repeat_number` int(11) NOT NULL DEFAULT '1',\n                `timeout_message` varchar(250) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `siteaccess_position` (`siteaccess`,`position`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_widget_theme` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(250) NOT NULL,\n                `name_company` varchar(250) NOT NULL,\n                `onl_bcolor` varchar(10) NOT NULL,\n                `bor_bcolor` varchar(10) NOT NULL DEFAULT 'e3e3e3',\n                `text_color` varchar(10) NOT NULL,\n                `online_image` varchar(250) NOT NULL,\n                `online_image_path` varchar(250) NOT NULL,\n                `offline_image` varchar(250) NOT NULL,\n                `offline_image_path` varchar(250) NOT NULL,\n                `logo_image` varchar(250) NOT NULL,\n                `logo_image_path` varchar(250) NOT NULL,\n                `need_help_image` varchar(250) NOT NULL,\n                `header_background` varchar(10) NOT NULL,\n                `need_help_tcolor` varchar(10) NOT NULL,\n                `need_help_bcolor` varchar(10) NOT NULL,\n                `need_help_border` varchar(10) NOT NULL,\n                `need_help_close_bg` varchar(10) NOT NULL,\n                `need_help_hover_bg` varchar(10) NOT NULL,\n                `need_help_close_hover_bg` varchar(10) NOT NULL,\n                `need_help_image_path` varchar(250) NOT NULL,\n                `custom_status_css` text NOT NULL,\n                `custom_container_css` text NOT NULL,\n                `custom_widget_css` text NOT NULL,\n                `need_help_header` varchar(250) NOT NULL,\n                `need_help_text` varchar(250) NOT NULL,\n                `online_text` varchar(250) NOT NULL,\n                `offline_text` varchar(250) NOT NULL,\n                `widget_border_color` varchar(10) NOT NULL,\n                `copyright_image` varchar(250) NOT NULL,\n                `copyright_image_path` varchar(250) NOT NULL,\n                `widget_copyright_url` varchar(250) NOT NULL,\n                `show_copyright` int(11) NOT NULL DEFAULT '1',\n                `explain_text` text NOT NULL,\n                `intro_operator_text` varchar(250) NOT NULL,\n                `operator_image` varchar(250) NOT NULL,\n                `operator_image_path` varchar(250) NOT NULL,\n                `minimize_image` varchar(250) NOT NULL,\n                `minimize_image_path` varchar(250) NOT NULL,\n                `restore_image` varchar(250) NOT NULL,\n                `restore_image_path` varchar(250) NOT NULL,\n                `close_image` varchar(250) NOT NULL,\n                `close_image_path` varchar(250) NOT NULL,\n                `popup_image` varchar(250) NOT NULL,\n                `popup_image_path` varchar(250) NOT NULL,\n                `support_joined` varchar(250) NOT NULL,\n                `support_closed` varchar(250) NOT NULL,\n                `pending_join` varchar(250) NOT NULL,\n                `noonline_operators` varchar(250) NOT NULL,\n                `noonline_operators_offline` varchar(250) NOT NULL,\n                `hide_close` int(11) NOT NULL,\n                `hide_popup` int(11) NOT NULL,\n                `show_need_help` int(11) NOT NULL DEFAULT '1',\n                `show_need_help_timeout` int(11) NOT NULL DEFAULT '24',\n                `header_height` int(11) NOT NULL,\n                `header_padding` int(11) NOT NULL,\n                `widget_border_width` int(11) NOT NULL,\n                `show_voting` tinyint(1) NOT NULL DEFAULT '1',\n                `department_title` varchar(250) NOT NULL,\n                `department_select` varchar(250) NOT NULL,\n                `buble_visitor_background` varchar(250) NOT NULL,\n                `buble_visitor_title_color` varchar(250) NOT NULL,\n                `buble_visitor_text_color` varchar(250) NOT NULL,\n                `buble_operator_background` varchar(250) NOT NULL,\n                `buble_operator_title_color` varchar(250) NOT NULL,\n                `buble_operator_text_color` varchar(250) NOT NULL,\n                PRIMARY KEY (`id`)\t\t\t\t\n            ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_faq` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `question` varchar(250) NOT NULL,\n                `answer` text NOT NULL,\n                `url` varchar(250) NOT NULL,\n                `email` varchar(50) NOT NULL,\n                `identifier` varchar(10) NOT NULL,\n                `active` int(11) NOT NULL,\n                `has_url` tinyint(1) NOT NULL,\n                `is_wildcard` tinyint(1) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `active` (`active`),\n            KEY `active_url` (`active`,`url`),\n            KEY `has_url` (`has_url`),\n            KEY `identifier` (`identifier`),\n            KEY `is_wildcard` (`is_wildcard`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_cobrowse` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `chat_id` int(11) NOT NULL,\n                `online_user_id` int(11) NOT NULL,\n                `mtime` int(11) NOT NULL,\n                `url` varchar(250) NOT NULL,\n                `initialize` longtext NOT NULL,\n                `modifications` longtext NOT NULL,\n                `finished` tinyint(1) NOT NULL,\n                `w` int NOT NULL,\n                `wh` int NOT NULL,\n                `x` int NOT NULL,\n                `y` int NOT NULL,        \t   \t\t\n                PRIMARY KEY (`id`),\n            KEY `chat_id` (`chat_id`),\n            KEY `online_user_id` (`online_user_id`)\n        ) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE `lh_abstract_survey` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(250) NOT NULL,\n                `max_stars` int(11) NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE `lh_admin_theme` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(100) NOT NULL,\n                `static_content` longtext NOT NULL,\n                `static_js_content` longtext NOT NULL,\n                `static_css_content` longtext NOT NULL,\n                `header_content` text NOT NULL,\n                `header_css` text NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE `lh_chat_paid` ( \n                `id` int(11) NOT NULL AUTO_INCREMENT,  \n                `hash` varchar(250) NOT NULL,  \n                `chat_id` int(11) NOT NULL, \n                PRIMARY KEY (`id`),  \n            KEY `hash` (`hash`),  \n            KEY `chat_id` (`chat_id`)) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_survey_item` (\n                `id` bigint(20) NOT NULL AUTO_INCREMENT,\n                `survey_id` int(11) NOT NULL,\n                `chat_id` int(11) NOT NULL,\n                `stars` int(11) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                `ftime` int(11) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `survey_id` (`survey_id`),\n            KEY `chat_id` (`chat_id`),\n            KEY `user_id` (`user_id`),\n            KEY `dep_id` (`dep_id`),\n            KEY `ftime` (`ftime`)\n        ) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_speech_language` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(100) NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_speech_language_dialect` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `language_id` int(11) NOT NULL,\n                `lang_name` varchar(100) NOT NULL,\n                `lang_code` varchar(100) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `language_id` (`language_id`)\n        ) DEFAULT CHARSET=utf8");
         $db->query("INSERT INTO `lh_speech_language` (`id`, `name`) VALUES\n                (1,\t'Afrikaans'),\n            (2,\t'Bahasa Indonesia'),\n            (3,\t'Bahasa Melayu'),\n            (4,\t'Català'),\n            (5,\t'Čeština'),\n            (6,\t'Deutsch'),\n            (7,\t'English'),\n            (8,\t'Español'),\n            (9,\t'Euskara'),\n            (10,\t'Français'),\n            (11,\t'Galego'),\n            (12,\t'Hrvatski'),\n            (13,\t'IsiZulu'),\n            (14,\t'Íslenska'),\n            (15,\t'Italiano'),\n            (16,\t'Magyar'),\n            (17,\t'Nederlands'),\n            (18,\t'Norsk bokmål'),\n            (19,\t'Polski'),\n            (20,\t'Português'),\n            (21,\t'Română'),\n            (22,\t'Slovenčina'),\n            (23,\t'Suomi'),\n            (24,\t'Svenska'),\n            (25,\t'Türkçe'),\n            (26,\t'български'),\n            (27,\t'Pусский'),\n            (28,\t'Српски'),\n            (29,\t'한국어'),\n            (30,\t'中文'),\n            (31,\t'日本語'),\n            (32,\t'Lingua latīna')");
         $db->query("INSERT INTO `lh_speech_language_dialect` (`id`, `language_id`, `lang_name`, `lang_code`) VALUES\n                (1,\t1,\t'Afrikaans',\t'af-ZA'),\n            (2,\t2,\t'Bahasa Indonesia',\t'id-ID'),\n            (3,\t3,\t'Bahasa Melayu',\t'ms-MY'),\n            (4,\t4,\t'Català',\t'ca-ES'),\n            (5,\t5,\t'Čeština',\t'cs-CZ'),\n            (6,\t6,\t'Deutsch',\t'de-DE'),\n            (7,\t7,\t'Australia',\t'en-AU'),\n            (8,\t7,\t'Canada',\t'en-CA'),\n            (9,\t7,\t'India',\t'en-IN'),\n            (10,\t7,\t'New Zealand',\t'en-NZ'),\n            (11,\t7,\t'South Africa',\t'en-ZA'),\n            (12,\t7,\t'United Kingdom',\t'en-GB'),\n            (13,\t7,\t'United States',\t'en-US'),\n            (14,\t8,\t'Argentina',\t'es-AR'),\n            (15,\t8,\t'Bolivia',\t'es-BO'),\n            (16,\t8,\t'Chile',\t'es-CL'),\n            (17,\t8,\t'Colombia',\t'es-CO'),\n            (18,\t8,\t'Costa Rica',\t'es-CR'),\n            (19,\t8,\t'Ecuador',\t'es-EC'),\n            (20,\t8,\t'El Salvador',\t'es-SV'),\n            (21,\t8,\t'España',\t'es-ES'),\n            (22,\t8,\t'Estados Unidos',\t'es-US'),\n            (23,\t8,\t'Guatemala',\t'es-GT'),\n            (24,\t8,\t'Honduras',\t'es-HN'),\n            (25,\t8,\t'México',\t'es-MX'),\n            (26,\t8,\t'Nicaragua',\t'es-NI'),\n            (27,\t8,\t'Panamá',\t'es-PA'),\n            (28,\t8,\t'Paraguay',\t'es-PY'),\n            (29,\t8,\t'Perú',\t'es-PE'),\n            (30,\t8,\t'Puerto Rico',\t'es-PR'),\n            (31,\t8,\t'República Dominicana',\t'es-DO'),\n            (32,\t8,\t'Uruguay',\t'es-UY'),\n            (33,\t8,\t'Venezuela',\t'es-VE'),\n            (34,\t9,\t'Euskara',\t'eu-ES'),\n            (35,\t10,\t'Français',\t'fr-FR'),\n            (36,\t11,\t'Galego',\t'gl-ES'),\n            (37,\t12,\t'Hrvatski',\t'hr_HR'),\n            (38,\t13,\t'IsiZulu',\t'zu-ZA'),\n            (39,\t14,\t'Íslenska',\t'is-IS'),\n            (40,\t15,\t'Italia',\t'it-IT'),\n            (41,\t15,\t'Svizzera',\t'it-CH'),\n            (42,\t16,\t'Magyar',\t'hu-HU'),\n            (43,\t17,\t'Nederlands',\t'nl-NL'),\n            (44,\t18,\t'Norsk bokmål',\t'nb-NO'),\n            (45,\t19,\t'Polski',\t'pl-PL'),\n            (46,\t20,\t'Brasil',\t'pt-BR'),\n            (47,\t20,\t'Portugal',\t'pt-PT'),\n            (48,\t21,\t'Română',\t'ro-RO'),\n            (49,\t22,\t'Slovenčina',\t'sk-SK'),\n            (50,\t23,\t'Suomi',\t'fi-FI'),\n            (51,\t24,\t'Svenska',\t'sv-SE'),\n            (52,\t25,\t'Türkçe',\t'tr-TR'),\n            (53,\t26,\t'български',\t'bg-BG'),\n            (54,\t27,\t'Pусский',\t'ru-RU'),\n            (55,\t28,\t'Српски',\t'sr-RS'),\n            (56,\t29,\t'한국어',\t'ko-KR'),\n            (57,\t30,\t'普通话 (中国大陆)',\t'cmn-Hans-CN'),\n            (58,\t30,\t'普通话 (香港)',\t'cmn-Hans-HK'),\n            (59,\t30,\t'中文 (台灣)',\t'cmn-Hant-TW'),\n            (60,\t30,\t'粵語 (香港)',\t'yue-Hant-HK'),\n            (61,\t31,\t'日本語',\t'ja-JP'),\n            (62,\t32,\t'Lingua latīna',\t'la')");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_speech_chat_language` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `chat_id` int(11) NOT NULL,\n                `language_id` int(11) NOT NULL,\n                `dialect` varchar(50) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `chat_id` (`chat_id`)\n        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_file` (\n                `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n                `name` varchar(255) NOT NULL,\n                `upload_name` varchar(255) NOT NULL,\n                `size` int(11) NOT NULL,\n                `type` varchar(255) NOT NULL,\n                `file_path` varchar(255) NOT NULL,\n                `extension` varchar(255) NOT NULL,\n                `chat_id` int(11) NOT NULL,\n                `online_user_id` int(11) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                `date` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `chat_id` (`chat_id`),\n            KEY `online_user_id` (`online_user_id`),\n            KEY `user_id` (`user_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_email_template` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(250) NOT NULL,\n                `from_name` varchar(150) NOT NULL,\n                `from_name_ac` tinyint(4) NOT NULL,\n                `from_email` varchar(150) NOT NULL,\n                `from_email_ac` tinyint(4) NOT NULL,\n                `user_mail_as_sender` tinyint(4) NOT NULL,\n                `content` text NOT NULL,\n                `subject` varchar(250) NOT NULL,\n                `bcc_recipients` varchar(200) NOT NULL,\n                `subject_ac` tinyint(4) NOT NULL,\n                `reply_to` varchar(150) NOT NULL,\n                `reply_to_ac` tinyint(4) NOT NULL,\n                `recipient` varchar(150) NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8;");
         $db->query("INSERT INTO `lh_abstract_email_template` (`id`, `name`, `from_name`, `from_name_ac`, `from_email`, `from_email_ac`, `user_mail_as_sender`, `content`, `subject`, `subject_ac`, `reply_to`, `reply_to_ac`, `recipient`,`bcc_recipients`) VALUES\n                (1,'Send mail to user','Live Helper Chat',0,'',0, 0,'Dear {user_chat_nick},\r\n\r\n{additional_message}\r\n\r\nLive Support response:\r\n{messages_content}\r\n\r\nSincerely,\r\nLive Support Team\r\n','{name_surname} has responded to your request',\t1,'',1,'',''),\n            (2,'Support request from user',\t'',\t0,\t'',\t0,\t 0,'Hello,\r\n\r\nUser request data:\r\nName: {name}\r\nEmail: {email}\r\nPhone: {phone}\r\nDepartment: {department}\r\nCountry: {country}\r\nCity: {city}\r\nIP: {ip}\r\n\r\nMessage:\r\n{message}\r\n\r\nAdditional data, if any:\r\n{additional_data}\r\n\r\nURL of page from which user has send request:\r\n{url_request}\r\n\r\nLink to chat if any:\r\n{prefillchat}\r\n\r\nSincerely,\r\nLive Support Team',\t'Support request from user',\t0,\t'',\t0,\t'{$adminEmail}',''),\n            (3,\t'User mail for himself',\t'Live Helper Chat',\t0,\t'',\t0,\t 0,'Dear {user_chat_nick},\r\n\r\nTranscript:\r\n{messages_content}\r\n\r\nSincerely,\r\nLive Support Team\r\n',\t'Chat transcript',\t0,\t'',\t0,\t'',''),\n            (4,\t'New chat request',\t'Live Helper Chat',\t0,\t'',\t0,\t 0,'Hello,\r\n\r\nUser request data:\r\nName: {name}\r\nEmail: {email}\r\nPhone: {phone}\r\nDepartment: {department}\r\nCountry: {country}\r\nCity: {city}\r\nIP: {ip}\r\n\r\nMessage:\r\n{message}\r\n\r\nURL of page from which user has send request:\r\n{url_request}\r\n\r\nClick to accept chat automatically\r\n{url_accept}\r\n\r\nSincerely,\r\nLive Support Team',\t'New chat request',\t0,\t'',\t0,\t'{$adminEmail}',''),\n            (5,\t'Chat was closed',\t'Live Helper Chat',\t0,\t'',\t0,\t 0,'Hello,\r\n\r\n{operator} has closed a chat\r\nName: {name}\r\nEmail: {email}\r\nPhone: {phone}\r\nDepartment: {department}\r\nCountry: {country}\r\nCity: {city}\r\nIP: {ip}\r\n\r\nMessage:\r\n{message}\r\n\r\nAdditional data, if any:\r\n{additional_data}\r\n\r\nURL of page from which user has send request:\r\n{url_request}\r\n\r\nSincerely,\r\nLive Support Team',\t'Chat was closed',\t0,\t'',\t0,\t'',''),\n            (6,\t'New FAQ question',\t'Live Helper Chat',\t0,\t'',\t0,\t 0,'Hello,\r\n\r\nNew FAQ question\r\nEmail: {email}\r\n\r\nQuestion:\r\n{question}\r\n\r\nQuestion URL:\r\n{url_question}\r\n\r\nURL to answer a question:\r\n{url_request}\r\n\r\nSincerely,\r\nLive Support Team',\t'New FAQ question',\t0,\t'',\t0,\t'',\t''),\n            (7,\t'New unread message',\t'Live Helper Chat',\t0,\t'',\t0,\t 0,'Hello,\r\n\r\nUser request data:\r\nName: {name}\r\nEmail: {email}\r\nPhone: {phone}\r\nDepartment: {department}\r\nCountry: {country}\r\nCity: {city}\r\nIP: {ip}\r\n\r\nMessage:\r\n{message}\r\n\r\nURL of page from which user has send request:\r\n{url_request}\r\n\r\nClick to accept chat automatically\r\n{url_accept}\r\n\r\nSincerely,\r\nLive Support Team',\t'New chat request',\t0,\t'',\t0,\t'{$adminEmail}',''),\n            (8,\t'Filled form',\t'Live Helper Chat',\t0,\t'',\t0,\t 0,'Hello,\r\n\r\nUser has filled a form\r\nForm name - {form_name}\r\nUser IP - {ip}\r\nDownload filled data - {url_download}\r\nIdentifier - {identifier}\r\nView filled data - {url_view}\r\n\r\n {content} \r\n\r\nSincerely,\r\nLive Support Team','Filled form - {form_name}',\t0,\t'',\t0,\t'{$adminEmail}',''),\n            (9,\t'Chat was accepted',\t'Live Helper Chat',\t0,\t'',\t0,\t 0, 'Hello,\r\n\r\nOperator {user_name} has accepted a chat [{chat_id}]\r\n\r\nUser request data:\r\nName: {name}\r\nEmail: {email}\r\nPhone: {phone}\r\nDepartment: {department}\r\nCountry: {country}\r\nCity: {city}\r\nIP: {ip}\r\n\r\nMessage:\r\n{message}\r\n\r\nURL of page from which user has send request:\r\n{url_request}\r\n\r\nClick to accept chat automatically\r\n{url_accept}\r\n\r\nSincerely,\r\nLive Support Team',\t'Chat was accepted [{chat_id}]',\t0,\t'',\t0,\t'{$adminEmail}',''),\n            (10, 'Permission request',\t'Live Helper Chat',\t0,\t'',\t0,\t0, 'Hello,\r\n\r\nOperator {user} has requested these permissions\n\r\n{permissions}\r\n\r\nSincerely,\r\nLive Support Team',\t'Permission request from {user}',\t0,\t'',\t0,\t'{$adminEmail}',\t'');");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_question` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `question` varchar(250) NOT NULL,\n                `location` varchar(250) NOT NULL,\n                `active` int(11) NOT NULL,\n                `priority` int(11) NOT NULL,\n                `is_voting` int(11) NOT NULL,\n                `question_intro` text NOT NULL,\n                `revote` int(11) NOT NULL DEFAULT '0',\n                PRIMARY KEY (`id`),\n            KEY `priority` (`priority`),\n            KEY `active_priority` (`active`,`priority`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_question_answer` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `ip` bigint(20) NOT NULL,\n                `question_id` int(11) NOT NULL,\n                `answer` text NOT NULL,\n                `ctime` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `ip` (`ip`),\n            KEY `question_id` (`question_id`)\n        ) DEFAULT CHARSET=utf8");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_question_option` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `question_id` int(11) NOT NULL,\n                `option_name` varchar(250) NOT NULL,\n                `priority` tinyint(4) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `question_id` (`question_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_question_option_answer` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `question_id` int(11) NOT NULL,\n                `option_id` int(11) NOT NULL,\n                `ctime` int(11) NOT NULL,\n                `ip` bigint(20) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `question_id` (`question_id`),\n            KEY `ip` (`ip`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_product` (\n                `id` int(11) NOT NULL AUTO_INCREMENT, \n                `name` varchar(250) NOT NULL, \n                `disabled` int(11) NOT NULL, \n                `priority` int(11) NOT NULL, \n                `departament_id` int(11) NOT NULL, \n                KEY `departament_id` (`departament_id`), \n            PRIMARY KEY (`id`)) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_browse_offer_invitation` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `siteaccess` varchar(10) NOT NULL,\n                `time_on_site` int(11) NOT NULL,\n                `content` longtext NOT NULL,\n                `callback_content` longtext NOT NULL,\n                `lhc_iframe_content` tinyint(4) NOT NULL,\n                `custom_iframe_url` varchar(250) NOT NULL,\n                `name` varchar(250) NOT NULL,\n                `identifier` varchar(50) NOT NULL,\n                `executed_times` int(11) NOT NULL,\n                `url` varchar(250) NOT NULL,\n                `active` int(11) NOT NULL,\n                `has_url` int(11) NOT NULL,\n                `is_wildcard` int(11) NOT NULL,\n                `referrer` varchar(250) NOT NULL,\n                `priority` varchar(250) NOT NULL,\n                `hash` varchar(40) NOT NULL,\n                `width` int(11) NOT NULL,\n                `height` int(11) NOT NULL,\n                `unit` varchar(10) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `active` (`active`),\n            KEY `identifier` (`identifier`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_form` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(100) NOT NULL,        \t   \n                `content` longtext NOT NULL,\n                `recipient` varchar(250) NOT NULL,\n                `active` int(11) NOT NULL,\n                `name_attr` varchar(250) NOT NULL,\n                `intro_attr` varchar(250) NOT NULL,\n                `xls_columns` text NOT NULL,\n                `pagelayout` varchar(200) NOT NULL,\n                `post_content` text NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_form_collected` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `form_id` int(11) NOT NULL,\n                `ctime` int(11) NOT NULL,\n                `ip` varchar(250) NOT NULL,\n                `identifier` varchar(250) NOT NULL,\n                `content` longtext NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `form_id` (`form_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chatbox` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `identifier` varchar(50) NOT NULL,\n                `name` varchar(100) NOT NULL,\n                `chat_id` int(11) NOT NULL,\n                `active` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `identifier` (`identifier`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_canned_msg` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `msg` text NOT NULL,\n                `fallback_msg` text NOT NULL,\n                `title` varchar(250) NOT NULL,\n                `explain` varchar(250) NOT NULL,\n                `position` int(11) NOT NULL,\n                `department_id` int(11) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                `delay` int(11) NOT NULL,\n                `auto_send` tinyint(1) NOT NULL,\n                `attr_int_1` int(11) NOT NULL,\n                `attr_int_2` int(11) NOT NULL,\n                `attr_int_3` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `department_id` (`department_id`),\n            KEY `attr_int_1` (`attr_int_1`),\n            KEY `attr_int_2` (`attr_int_2`),\n            KEY `attr_int_3` (`attr_int_3`),\n            KEY `position_title` (`position`, `title`),\n            KEY `user_id` (`user_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_online_user_footprint` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `chat_id` int(11) NOT NULL,\n                `online_user_id` int(11) NOT NULL,\n                `page` varchar(250) NOT NULL,\n                `vtime` varchar(250) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `chat_id_vtime` (`chat_id`,`vtime`),\n            KEY `online_user_id` (`online_user_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_users_setting` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `user_id` int(11) NOT NULL,\n                `identifier` varchar(50) NOT NULL,\n                `value` varchar(255) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `user_id` (`user_id`,`identifier`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_users_setting_option` (\n                `identifier` varchar(50) NOT NULL,\n                `class` varchar(50) NOT NULL,\n                `attribute` varchar(40) NOT NULL,\n                PRIMARY KEY (`identifier`)\n            ) DEFAULT CHARSET=utf8;");
         $db->query("INSERT INTO `lh_users_setting_option` (`identifier`, `class`, `attribute`) VALUES\n                ('chat_message',\t'',\t''),\n            ('new_chat_sound',\t'',\t''),\n            ('enable_pending_list', '', ''),\n            ('enable_active_list', '', ''),\n            ('enable_close_list', '', ''),\n            ('new_user_bn', '', ''),\n            ('new_user_sound', '', ''),\n            ('oupdate_timeout', '', ''),\n            ('ouser_timeout', '', ''),\n            ('o_department', '', ''),\n            ('omax_rows', '', ''),\n            ('ogroup_by', '', ''),\n            ('omap_depid', '', ''),\n            ('omap_mtimeout', '', ''),\n            ('dwo', '', ''),\n            ('enable_unread_list', '', '')");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_config` (\n                `identifier` varchar(50) NOT NULL,\n                `value` text NOT NULL,\n                `type` tinyint(1) NOT NULL DEFAULT '0',\n                `explain` varchar(250) NOT NULL,\n                `hidden` int(11) NOT NULL DEFAULT '0',\n                PRIMARY KEY (`identifier`)\n            ) DEFAULT CHARSET=utf8;");
         $randomHash = erLhcoreClassModelForgotPassword::randomPassword(9);
         $randomHashLength = strlen($randomHash);
         $exportHash = erLhcoreClassModelForgotPassword::randomPassword(9);
         if (extension_loaded('bcmath')) {
             $geoRow = "('geo_data','a:5:{i:0;b:0;s:21:\"geo_detection_enabled\";i:1;s:22:\"geo_service_identifier\";s:8:\"max_mind\";s:23:\"max_mind_detection_type\";s:7:\"country\";s:22:\"max_mind_city_location\";s:37:\"var/external/geoip/GeoLite2-City.mmdb\";}',0,'',1)";
         } else {
             $geoRow = "('geo_data', '', '0', '', '1')";
         }
         $db->query("INSERT INTO `lh_chat_config` (`identifier`, `value`, `type`, `explain`, `hidden`) VALUES\n                ('tracked_users_cleanup',\t'160',\t0,\t'How many days keep records of online users.',\t0),\n            ('list_online_operators', '0', '0', 'List online operators.', '0'),\n            ('voting_days_limit',\t'7',\t0,\t'How many days voting widget should not be expanded after last show',\t0),\n            ('track_online_visitors',\t'1',\t0,\t'Enable online site visitors tracking',\t0),\n            ('pro_active_invite',\t'1',\t0,\t'Is pro active chat invitation active. Online users tracking also has to be enabled',\t0),\n            ('customer_company_name',\t'Live Helper Chat',\t0,\t'Your company name - visible in bottom left corner',\t0),\n            ('customer_site_url',\t'http://livehelperchat.com',\t0,\t'Your site URL address',\t0),\n            ('smtp_data',\t'a:5:{s:4:\"host\";s:0:\"\";s:4:\"port\";s:2:\"25\";s:8:\"use_smtp\";i:0;s:8:\"username\";s:0:\"\";s:8:\"password\";s:0:\"\";}',\t0,\t'SMTP configuration',\t1),\n            ('chatbox_data',\t'a:6:{i:0;b:0;s:20:\"chatbox_auto_enabled\";i:0;s:19:\"chatbox_secret_hash\";s:{$randomHashLength}:\"{$randomHash}\";s:20:\"chatbox_default_name\";s:7:\"Chatbox\";s:17:\"chatbox_msg_limit\";i:50;s:22:\"chatbox_default_opname\";s:7:\"Manager\";}',\t0,\t'Chatbox configuration',\t1),\n            ('start_chat_data',\t'a:23:{i:0;b:0;s:21:\"name_visible_in_popup\";b:1;s:27:\"name_visible_in_page_widget\";b:1;s:19:\"name_require_option\";s:8:\"required\";s:22:\"email_visible_in_popup\";b:0;s:28:\"email_visible_in_page_widget\";b:0;s:20:\"email_require_option\";s:8:\"required\";s:24:\"message_visible_in_popup\";b:1;s:30:\"message_visible_in_page_widget\";b:1;s:22:\"message_require_option\";s:8:\"required\";s:22:\"phone_visible_in_popup\";b:0;s:28:\"phone_visible_in_page_widget\";b:0;s:20:\"phone_require_option\";s:8:\"required\";s:21:\"force_leave_a_message\";b:0;s:29:\"offline_name_visible_in_popup\";b:1;s:35:\"offline_name_visible_in_page_widget\";b:1;s:27:\"offline_name_require_option\";s:8:\"required\";s:30:\"offline_phone_visible_in_popup\";b:0;s:36:\"offline_phone_visible_in_page_widget\";b:0;s:28:\"offline_phone_require_option\";s:8:\"required\";s:32:\"offline_message_visible_in_popup\";b:1;s:38:\"offline_message_visible_in_page_widget\";b:1;s:30:\"offline_message_require_option\";s:8:\"required\";}',\t0,\t'',\t1),\n            ('application_name',\t'a:6:{s:3:\"eng\";s:31:\"Live Helper Chat - live support\";s:3:\"lit\";s:26:\"Live Helper Chat - pagalba\";s:3:\"hrv\";s:0:\"\";s:3:\"esp\";s:0:\"\";s:3:\"por\";s:0:\"\";s:10:\"site_admin\";s:31:\"Live Helper Chat - live support\";}',\t1,\t'Support application name, visible in browser title.',\t0),\n            ('track_footprint',\t'0',\t0,\t'Track users footprint. For this also online visitors tracking should be enabled',\t0),\n            ('pro_active_limitation',\t'-1',\t0,\t'Pro active chats invitations limitation based on pending chats, (-1) do not limit, (0,1,n+1) number of pending chats can be for invitation to be shown.',\t0),\n            ('pro_active_show_if_offline',\t'0',\t0,\t'Should invitation logic be executed if there is no online operators',\t0),\n            ('export_hash',\t'{$exportHash}',\t0,\t'Chats export secret hash',\t0),\n            ('message_seen_timeout', 24, 0, 'Proactive message timeout in hours. After how many hours proactive chat mesasge should be shown again.',\t0),\n            ('reopen_chat_enabled',1,\t0,\t'Reopen chat functionality enabled',\t0),\n            ('ignorable_ip',\t'',\t0,\t'Which ip should be ignored in online users list, separate by comma',0),\n            ('run_departments_workflow', 0, 0, 'Should cronjob run departments transfer workflow, even if user leaves a chat',\t0),\n            ('geo_location_data', 'a:3:{s:4:\"zoom\";i:4;s:3:\"lat\";s:7:\"49.8211\";s:3:\"lng\";s:7:\"11.7835\";}', '0', '', '1'),\n            ('xmp_data','a:14:{i:0;b:0;s:4:\"host\";s:15:\"talk.google.com\";s:6:\"server\";s:9:\"gmail.com\";s:8:\"resource\";s:6:\"xmpphp\";s:4:\"port\";s:4:\"5222\";s:7:\"use_xmp\";i:0;s:8:\"username\";s:0:\"\";s:8:\"password\";s:0:\"\";s:11:\"xmp_message\";s:78:\"New chat request [{chat_id}]\r\n{messages}\r\nClick to accept a chat\r\n{url_accept}\";s:10:\"recipients\";s:0:\"\";s:20:\"xmp_accepted_message\";s:69:\"{user_name} has accepted a chat [{chat_id}]\r\n{messages}\r\n{url_accept}\";s:16:\"use_standard_xmp\";i:0;s:15:\"test_recipients\";s:0:\"\";s:21:\"test_group_recipients\";s:0:\"\";}',0,'XMP data',1),\n            ('run_unaswered_chat_workflow', 0, 0, 'Should cronjob run unanswered chats workflow and execute unaswered chats callback, 0 - no, any other number bigger than 0 is a minits how long chat have to be not accepted before executing callback.',0),\n            ('disable_popup_restore', 0, 0, 'Disable option in widget to open new window. Restore icon will be hidden',\t0),\n            ('accept_tos_link', '#', 0, 'Change to your site Terms of Service', 0),\n            ('hide_button_dropdown', '0', 0, 'Hide close button in dropdown', 0),\n            ('on_close_exit_chat', '0', 0, 'On chat close exit chat', 0),\n            ('product_enabled_module','0','0','Product module is enabled', '1'),\n            ('paidchat_data','','0','Paid chat configuration','1'),\n            ('disable_iframe_sharing',\t'1',\t0,\t'Disable iframes in sharing mode',\t0),\n            ('file_configuration',\t'a:7:{i:0;b:0;s:5:\"ft_op\";s:43:\"gif|jpe?g|png|zip|rar|xls|doc|docx|xlsx|pdf\";s:5:\"ft_us\";s:26:\"gif|jpe?g|png|doc|docx|pdf\";s:6:\"fs_max\";i:2048;s:18:\"active_user_upload\";b:0;s:16:\"active_op_upload\";b:1;s:19:\"active_admin_upload\";b:1;}',\t0,\t'Files configuration item',\t1),\n            ('accept_chat_link_timeout',\t'300',\t0,\t'How many seconds chat accept link is valid. Set 0 to force login all the time manually.',\t0),\n            ('session_captcha',0,\t0,\t'Use session captcha. LHC have to be installed on the same domain or subdomain.',\t0),\n            ('sync_sound_settings',\t'a:16:{i:0;b:0;s:12:\"repeat_sound\";i:1;s:18:\"repeat_sound_delay\";i:5;s:10:\"show_alert\";b:0;s:22:\"new_chat_sound_enabled\";b:1;s:31:\"new_message_sound_admin_enabled\";b:1;s:30:\"new_message_sound_user_enabled\";b:1;s:14:\"online_timeout\";d:300;s:22:\"check_for_operator_msg\";d:10;s:21:\"back_office_sinterval\";d:10;s:22:\"chat_message_sinterval\";d:3.5;s:20:\"long_polling_enabled\";b:0;s:30:\"polling_chat_message_sinterval\";d:1.5;s:29:\"polling_back_office_sinterval\";d:5;s:18:\"connection_timeout\";i:30;s:28:\"browser_notification_message\";b:0;}',\t0,\t'',\t1),\n            ('sound_invitation', 1, 0, 'Play sound on invitation to chat.',\t0),\n            ('explicit_http_mode', '',0,'Please enter explicit http mode. Either http: or https:, do not forget : at the end.', '0'),\n            ('track_domain',\t'',\t0,\t'Set your domain to enable user tracking across different domain subdomains.',\t0),\n            ('max_message_length','500',0,'Maximum message length in characters', '0'),\n            ('need_help_tip','1',0,'Show need help tooltip?', '0'),\n            ('need_help_tip_timeout','24',0,'Need help tooltip timeout, after how many hours show again tooltip?', '0'),\n            ('use_secure_cookie','0',0,'Use secure cookie, check this if you want to force SSL all the time', '0'),\n            ('faq_email_required','0',0,'Is visitor e-mail required for FAQ', '0'),\n            ('disable_print','0',0,'Disable chat print', '0'),\n            ('hide_disabled_department','1',0,'Hide disabled department widget', '0'),\n            ('disable_send','0',0,'Disable chat transcript send', '0'),\n            ('ignore_user_status','0',0,'Ignore users online statuses and use departments online hours', '0'),\n            ('bbc_button_visible','1',0,'Show BB Code button', '0'),\n            ('allow_reopen_closed','1', 0, 'Allow user to reopen closed chats?', '0'),\n            ('reopen_as_new','1', 0, 'Reopen closed chat as new? Otherwise it will be reopened as active.', '0'),\n            ('default_theme_id','0', 0, 'Default theme ID.', '1'),  \n            ('default_admin_theme_id','0', 0, 'Default admin theme ID', '1'),  \n            ('translation_data',\t'a:6:{i:0;b:0;s:19:\"translation_handler\";s:4:\"bing\";s:19:\"enable_translations\";b:0;s:14:\"bing_client_id\";s:0:\"\";s:18:\"bing_client_secret\";s:0:\"\";s:14:\"google_api_key\";s:0:\"\";}',\t0,\t'Translation data',\t1),              \n            ('disable_html5_storage','1',0,'Disable HMTL5 storage, check it if your site is switching between http and https', '0'),\n            ('automatically_reopen_chat','1',0,'Automatically reopen chat on widget open', '0'),\n            ('autoclose_timeout','0', 0, 'Automatic chats closing. 0 - disabled, n > 0 time in minutes before chat is automatically closed', '0'),\n            ('autopurge_timeout','0', 0, 'Automatic chats purging. 0 - disabled, n > 0 time in minutes before chat is automatically deleted', '0'),\n            ('update_ip',\t'127.0.0.1',\t0,\t'Which ip should be allowed to update DB by executing http request, separate by comma?',0),\n            ('track_if_offline',\t'0',\t0,\t'Track online visitors even if there is no online operators',0),\n            ('min_phone_length','8',0,'Minimum phone number length',0),\n            ('mheight','',0,'Messages box height',0),\n            ('dashboard_order', 'online_operators,departments_stats|pending_chats,unread_chats,transfered_chats|active_chats,closed_chats', '0', 'Home page dashboard widgets order', '0'),\n            ('banned_ip_range','',0,'Which ip should not be allowed to chat',0),\n            ('suggest_leave_msg','1',0,'Suggest user to leave a message then user chooses offline department',0),\n            ('checkstatus_timeout','0',0,'Interval between chat status checks in seconds, 0 disabled.',0),\n            ('show_language_switcher','0',0,'Show users option to switch language at widget',0),\n            ('sharing_auto_allow','0',0,'Do not ask permission for users to see their screen',0),\n            ('sharing_nodejs_enabled','0',0,'NodeJs support enabled',0),\n            ('sharing_nodejs_path','',0,'socket.io path, optional',0),\n            ('online_if','0','0','','0'),\n            ('track_mouse_activity','0','0','Should mouse movement be tracked as activity measure, if not checked only basic events would be tracked','0'),\n            ('track_activity','0','0','Track users activity on site?','0'),\n            ('autologin_data','a:3:{i:0;b:0;s:11:\"secret_hash\";s:16:\"please_change_me\";s:7:\"enabled\";i:0;}',0,'Autologin configuration data',\t1),\n            ('sharing_nodejs_secure','0',0,'Connect to NodeJs in https mode',0),\n            ('disable_js_execution','1',0,'Disable JS execution in Co-Browsing operator window',0),\n            ('sharing_nodejs_socket_host','',0,'Host where NodeJs is running',0),\n            ('hide_right_column_frontpage','0','0','Hide right column in frontpage','0'),\n            ('front_tabs', 'dashboard,online_users,online_map', '0', 'Home page tabs order', '0'),\n            ('speech_data',\t'a:3:{i:0;b:0;s:8:\"language\";i:7;s:7:\"dialect\";s:5:\"en-US\";}',\t1,\t'',\t1),\n            ('sharing_nodejs_sllocation','https://cdn.socket.io/socket.io-1.1.0.js',0,'Location of SocketIO JS library',0),\n            ('track_is_online','0',0,'Track is user still on site, chat status checks also has to be enabled',0),\n            ('show_languages','eng,lit,hrv,esp,por,nld,ara,ger,pol,rus,ita,fre,chn,cse,nor,tur,vnm,idn,sve,per,ell,dnk,rou,bgr,tha,geo,fin,alb',0,'Between what languages user should be able to switch',0),\n            ('geoadjustment_data',\t'a:8:{i:0;b:0;s:18:\"use_geo_adjustment\";b:0;s:13:\"available_for\";s:0:\"\";s:15:\"other_countries\";s:6:\"custom\";s:8:\"hide_for\";s:0:\"\";s:12:\"other_status\";s:7:\"offline\";s:11:\"rest_status\";s:6:\"hidden\";s:12:\"apply_widget\";i:0;}',\t0,\t'Geo adjustment settings',\t1),\n            {$geoRow}");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_online_user` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `vid` varchar(50) NOT NULL,\n                `ip` varchar(50) NOT NULL,\n                `current_page` text NOT NULL,\n                `page_title` varchar(250) NOT NULL,\n                `referrer` text NOT NULL,\n                `chat_id` int(11) NOT NULL,\n                `invitation_seen_count` int(11) NOT NULL,\n                `invitation_id` int(11) NOT NULL,\n                `last_visit` int(11) NOT NULL,\n                `first_visit` int(11) NOT NULL,\n                `total_visits` int(11) NOT NULL,\n                `pages_count` int(11) NOT NULL,\n                `tt_pages_count` int(11) NOT NULL,\n                `invitation_count` int(11) NOT NULL,\n                `last_check_time` int(11) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                `user_agent` varchar(250) NOT NULL,\n                `notes` varchar(250) NOT NULL,\n                `user_country_code` varchar(50) NOT NULL,\n                `user_country_name` varchar(50) NOT NULL,\n                `visitor_tz` varchar(50) NOT NULL,\n                `operator_message` text NOT NULL,\n                `operator_user_proactive` varchar(100) NOT NULL,\n                `operator_user_id` int(11) NOT NULL,\n                `message_seen` int(11) NOT NULL,\n                `message_seen_ts` int(11) NOT NULL,\n                `user_active` int(11) NOT NULL,\n                `lat` varchar(10) NOT NULL,\n                `lon` varchar(10) NOT NULL,\n                `city` varchar(100) NOT NULL,\n                `reopen_chat` int(11) NOT NULL,\n                `time_on_site` int(11) NOT NULL,\n                `tt_time_on_site` int(11) NOT NULL,\n                `requires_email` int(11) NOT NULL,\n                `requires_username` int(11) NOT NULL,\n                `requires_phone` int(11) NOT NULL,\n                `screenshot_id` int(11) NOT NULL,\n                `identifier` varchar(50) NOT NULL,\n                `operation` text NOT NULL,\n                `online_attr_system` text NOT NULL,\n                `operation_chat` text NOT NULL,\n                `online_attr` text NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `vid` (`vid`),\n            KEY `dep_id` (`dep_id`),\n            KEY `last_visit_dep_id` (`last_visit`,`dep_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_proactive_chat_invitation` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `siteaccess` varchar(10) NOT NULL,\n                `time_on_site` int(11) NOT NULL,\n                `pageviews` int(11) NOT NULL,\n                `message` text NOT NULL,\n                `message_returning` text NOT NULL,\n                `executed_times` int(11) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                `hide_after_ntimes` int(11) NOT NULL,\n                `name` varchar(50) NOT NULL,\n                `operator_ids` varchar(100) NOT NULL,\n                `wait_message` varchar(250) NOT NULL,\n                `timeout_message` varchar(250) NOT NULL,\n                `message_returning_nick` varchar(250) NOT NULL,\n                `referrer` varchar(250) NOT NULL,\n                `wait_timeout` int(11) NOT NULL,\n                `show_random_operator` int(11) NOT NULL,\n                `operator_name` varchar(100) NOT NULL,\n                `position` int(11) NOT NULL,\n                `identifier` varchar(50) NOT NULL,\n                `requires_email` int(11) NOT NULL,\n                `requires_username` int(11) NOT NULL,\n                `requires_phone` int(11) NOT NULL,\n                `repeat_number` int(11) NOT NULL DEFAULT '1',\n                PRIMARY KEY (`id`),\n            KEY `time_on_site_pageviews_siteaccess_position` (`time_on_site`,`pageviews`,`siteaccess`,`identifier`,`position`),\n            KEY `identifier` (`identifier`),\n            KEY `dep_id` (`dep_id`)\n        ) DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_accept` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `chat_id` int(11) NOT NULL,\n                `hash` varchar(50) NOT NULL,\n                `ctime` int(11) NOT NULL,\n                `wused` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `hash` (`hash`)\n        ) DEFAULT CHARSET=utf8;");
         //Default departament
         $db->query("CREATE TABLE IF NOT EXISTS `lh_departament` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(100) NOT NULL,\n                `email` varchar(100) NOT NULL,\n                `xmpp_recipients` text NOT NULL,\n                `xmpp_group_recipients` text NOT NULL,\n                `priority` int(11) NOT NULL,\n                `sort_priority` int(11) NOT NULL,\n                `department_transfer_id` int(11) NOT NULL,\n                `transfer_timeout` int(11) NOT NULL,\n                `disabled` int(11) NOT NULL,\n                `hidden` int(11) NOT NULL,\n                `delay_lm` int(11) NOT NULL,\n                `max_active_chats` int(11) NOT NULL,\n                `max_timeout_seconds` int(11) NOT NULL,\n                `identifier` varchar(50) NOT NULL,\n                `mod` tinyint(1) NOT NULL,\n                `tud` tinyint(1) NOT NULL,\n                `wed` tinyint(1) NOT NULL,\n                `thd` tinyint(1) NOT NULL,\n                `frd` tinyint(1) NOT NULL,\n                `sad` tinyint(1) NOT NULL,\n                `sud` tinyint(1) NOT NULL,\n                `nc_cb_execute` tinyint(1) NOT NULL,\n                `na_cb_execute` tinyint(1) NOT NULL,\n                `inform_unread` tinyint(1) NOT NULL,\n                `active_balancing` tinyint(1) NOT NULL,\n                `visible_if_online` tinyint(1) NOT NULL,\n                `start_hour` int(2) NOT NULL,\n                `end_hour` int(2) NOT NULL,\n                `inform_close` int(11) NOT NULL,\n                `inform_unread_delay` int(11) NOT NULL,\n                `inform_options` varchar(250) NOT NULL,\n                `online_hours_active` tinyint(1) NOT NULL,\n                `inform_delay` int(11) NOT NULL,\n                `attr_int_1` int(11) NOT NULL,\n                `attr_int_2` int(11) NOT NULL,\n                `attr_int_3` int(11) NOT NULL,\n                `active_chats_counter` int(11) NOT NULL,\n                `pending_chats_counter` int(11) NOT NULL,\n                `closed_chats_counter` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `identifier` (`identifier`),\n            KEY `attr_int_1` (`attr_int_1`),\n            KEY `attr_int_2` (`attr_int_2`),\n            KEY `attr_int_3` (`attr_int_3`),\n            KEY `disabled_hidden` (`disabled`, `hidden`),\n            KEY `sort_priority_name` (`sort_priority`, `name`),\n            KEY `oha_sh_eh` (`online_hours_active`,`start_hour`,`end_hour`)\n        ) DEFAULT CHARSET=utf8;");
         $Departament = new erLhcoreClassModelDepartament();
         $Departament->name = $form->DefaultDepartament;
         erLhcoreClassDepartament::getSession()->save($Departament);
         //Administrators group
         $db->query("CREATE TABLE IF NOT EXISTS `lh_group` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(50) NOT NULL,\n                `disabled` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `disabled` (`disabled`)\n        ) DEFAULT CHARSET=utf8;");
         // Admin group
         $GroupData = new erLhcoreClassModelGroup();
         $GroupData->name = "Administrators";
         erLhcoreClassUser::getSession()->save($GroupData);
         // Precreate operators group
         $GroupDataOperators = new erLhcoreClassModelGroup();
         $GroupDataOperators->name = "Operators";
         erLhcoreClassUser::getSession()->save($GroupDataOperators);
         //Administrators role
         $db->query("CREATE TABLE IF NOT EXISTS `lh_role` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `name` varchar(50) NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8;");
         // Administrators role
         $Role = new erLhcoreClassModelRole();
         $Role->name = 'Administrators';
         erLhcoreClassRole::getSession()->save($Role);
         // Operators role
         $RoleOperators = new erLhcoreClassModelRole();
         $RoleOperators->name = 'Operators';
         erLhcoreClassRole::getSession()->save($RoleOperators);
         //Assing group role
         $db->query("CREATE TABLE IF NOT EXISTS `lh_grouprole` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `group_id` int(11) NOT NULL,\n                `role_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `group_id` (`role_id`,`group_id`),\n            KEY `group_id_primary` (`group_id`)\n        ) DEFAULT CHARSET=utf8;");
         // Assign admin role to admin group
         $GroupRole = new erLhcoreClassModelGroupRole();
         $GroupRole->group_id = $GroupData->id;
         $GroupRole->role_id = $Role->id;
         erLhcoreClassRole::getSession()->save($GroupRole);
         // Assign operators role to operators group
         $GroupRoleOperators = new erLhcoreClassModelGroupRole();
         $GroupRoleOperators->group_id = $GroupDataOperators->id;
         $GroupRoleOperators->role_id = $RoleOperators->id;
         erLhcoreClassRole::getSession()->save($GroupRoleOperators);
         // Users
         $db->query("CREATE TABLE IF NOT EXISTS `lh_users` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `username` varchar(40) NOT NULL,\n                `password` varchar(200) NOT NULL,\n                `email` varchar(100) NOT NULL,\n                `time_zone` varchar(100) NOT NULL,\n                `name` varchar(100) NOT NULL,\n                `surname` varchar(100) NOT NULL,\n                `filepath` varchar(200) NOT NULL,\n                `filename` varchar(200) NOT NULL,\n                `job_title` varchar(100) NOT NULL,\n                `departments_ids` varchar(100) NOT NULL,\n                `chat_nickname` varchar(100) NOT NULL,\n                `xmpp_username` varchar(200) NOT NULL,\n                `session_id` varchar(40) NOT NULL,\n                `skype` varchar(50) NOT NULL,\n                `disabled` tinyint(4) NOT NULL,\n                `hide_online` tinyint(1) NOT NULL,\n                `all_departments` tinyint(1) NOT NULL,\n                `invisible_mode` tinyint(1) NOT NULL,\n                `rec_per_req` tinyint(1) NOT NULL,\n                `active_chats_counter` int(11) NOT NULL,\n                `closed_chats_counter` int(11) NOT NULL,\n                `pending_chats_counter` int(11) NOT NULL,\n                `attr_int_1` int(11) NOT NULL,\n                `attr_int_2` int(11) NOT NULL,\n                `attr_int_3` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `hide_online` (`hide_online`),\n            KEY `rec_per_req` (`rec_per_req`),\n            KEY `email` (`email`),\n            KEY `xmpp_username` (`xmpp_username`)\n        ) DEFAULT CHARSET=utf8;");
         $UserData = new erLhcoreClassModelUser();
         $UserData->setPassword($form->AdminPassword);
         $UserData->email = $form->AdminEmail;
         $UserData->name = $form->AdminName;
         $UserData->surname = $form->AdminSurname;
         $UserData->username = $form->AdminUsername;
         $UserData->all_departments = 1;
         $UserData->departments_ids = 0;
         erLhcoreClassUser::getSession()->save($UserData);
         // User departaments
         $db->query("CREATE TABLE IF NOT EXISTS `lh_userdep` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `user_id` int(11) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                `last_activity` int(11) NOT NULL,\n                `hide_online` int(11) NOT NULL,\n                `last_accepted` int(11) NOT NULL,\n                `active_chats` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `user_id` (`user_id`),\n            KEY `last_activity_hide_online_dep_id` (`last_activity`,`hide_online`,`dep_id`),\n            KEY `dep_id` (`dep_id`)\n        ) DEFAULT CHARSET=utf8;");
         // Insert record to departament instantly
         $db->query("INSERT INTO `lh_userdep` (`user_id`,`dep_id`,`last_activity`,`hide_online`,`last_accepted`,`active_chats`) VALUES ({$UserData->id},0,0,0,0,0)");
         // Transfer chat
         $db->query("CREATE TABLE IF NOT EXISTS `lh_transfer` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `chat_id` int(11) NOT NULL,\n                `dep_id` int(11) NOT NULL,\n                `transfer_user_id` int(11) NOT NULL,\n                `from_dep_id` int(11) NOT NULL,\n                `transfer_to_user_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `dep_id` (`dep_id`),\n            KEY `transfer_user_id_dep_id` (`transfer_user_id`,`dep_id`),\n            KEY `transfer_to_user_id` (`transfer_to_user_id`)\n        ) DEFAULT CHARSET=utf8;");
         // Remember user table
         $db->query("CREATE TABLE IF NOT EXISTS `lh_users_remember` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `user_id` int(11) NOT NULL,\n                `mtime` int(11) NOT NULL,\n                PRIMARY KEY (`id`)\n            ) DEFAULT CHARSET=utf8;");
         // API table
         $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_rest_api_key` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `api_key` varchar(50) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                `active` int(11) NOT NULL DEFAULT '0',\n                PRIMARY KEY (`id`),\n            KEY `api_key` (`api_key`),\n            KEY `user_id` (`user_id`)\n        ) DEFAULT CHARSET=utf8;");
         // Chat messages
         $db->query("CREATE TABLE IF NOT EXISTS `lh_msg` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `msg` text NOT NULL,\n                `time` int(11) NOT NULL,\n                `chat_id` int(11) NOT NULL DEFAULT '0',\n                `user_id` int(11) NOT NULL DEFAULT '0',\n                `name_support` varchar(100) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `chat_id_id` (`chat_id`, `id`)\n        ) DEFAULT CHARSET=utf8;");
         // Forgot password table
         $db->query("CREATE TABLE IF NOT EXISTS `lh_forgotpasswordhash` (\n                `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n                `user_id` INT NOT NULL ,\n                `hash` VARCHAR( 40 ) NOT NULL ,\n                `created` INT NOT NULL\n            ) DEFAULT CHARSET=utf8;");
         // User groups table
         $db->query("CREATE TABLE IF NOT EXISTS `lh_groupuser` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `group_id` int(11) NOT NULL,\n                `user_id` int(11) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `group_id` (`group_id`),\n            KEY `user_id` (`user_id`),\n            KEY `group_id_2` (`group_id`,`user_id`)\n        ) DEFAULT CHARSET=utf8;");
         // Assign admin user to admin group
         $GroupUser = new erLhcoreClassModelGroupUser();
         $GroupUser->group_id = $GroupData->id;
         $GroupUser->user_id = $UserData->id;
         erLhcoreClassUser::getSession()->save($GroupUser);
         //Assign default role functions
         $db->query("CREATE TABLE IF NOT EXISTS `lh_rolefunction` (\n                `id` int(11) NOT NULL AUTO_INCREMENT,\n                `role_id` int(11) NOT NULL,\n                `module` varchar(100) NOT NULL,\n                `function` varchar(100) NOT NULL,\n                PRIMARY KEY (`id`),\n            KEY `role_id` (`role_id`)\n        ) DEFAULT CHARSET=utf8;");
         // Admin role and function
         $RoleFunction = new erLhcoreClassModelRoleFunction();
         $RoleFunction->role_id = $Role->id;
         $RoleFunction->module = '*';
         $RoleFunction->function = '*';
         erLhcoreClassRole::getSession()->save($RoleFunction);
         // Operators rules and functions
         $permissionsArray = array(array('module' => 'lhuser', 'function' => 'selfedit'), array('module' => 'lhuser', 'function' => 'changeonlinestatus'), array('module' => 'lhuser', 'function' => 'changeskypenick'), array('module' => 'lhuser', 'function' => 'personalcannedmsg'), array('module' => 'lhuser', 'function' => 'change_visibility_list'), array('module' => 'lhuser', 'function' => 'see_assigned_departments'), array('module' => 'lhuser', 'function' => 'canseedepartmentstats'), array('module' => 'lhchat', 'function' => 'use'), array('module' => 'lhchat', 'function' => 'chattabschrome'), array('module' => 'lhchat', 'function' => 'singlechatwindow'), array('module' => 'lhchat', 'function' => 'allowopenremotechat'), array('module' => 'lhchat', 'function' => 'allowchattabs'), array('module' => 'lhchat', 'function' => 'use_onlineusers'), array('module' => 'lhchat', 'function' => 'take_screenshot'), array('module' => 'lhfront', 'function' => 'use'), array('module' => 'lhsystem', 'function' => 'use'), array('module' => 'lhtranslation', 'function' => 'use'), array('module' => 'lhchat', 'function' => 'allowblockusers'), array('module' => 'lhsystem', 'function' => 'generatejs'), array('module' => 'lhsystem', 'function' => 'changelanguage'), array('module' => 'lhchat', 'function' => 'allowredirect'), array('module' => 'lhchat', 'function' => 'allowtransfer'), array('module' => 'lhchat', 'function' => 'administratecannedmsg'), array('module' => 'lhchat', 'function' => 'sees_all_online_visitors'), array('module' => 'lhpermission', 'function' => 'see_permissions'), array('module' => 'lhquestionary', 'function' => 'manage_questionary'), array('module' => 'lhfaq', 'function' => 'manage_faq'), array('module' => 'lhchatbox', 'function' => 'manage_chatbox'), array('module' => 'lhbrowseoffer', 'function' => 'manage_bo'), array('module' => 'lhxml', 'function' => '*'), array('module' => 'lhcobrowse', 'function' => 'browse'), array('module' => 'lhfile', 'function' => 'use_operator'), array('module' => 'lhfile', 'function' => 'file_delete_chat'), array('module' => 'lhstatistic', 'function' => 'use'), array('module' => 'lhspeech', 'function' => 'changedefaultlanguage'), array('module' => 'lhspeech', 'function' => 'use'), array('module' => 'lhspeech', 'function' => 'change_chat_recognition'));
         foreach ($permissionsArray as $paramsPermission) {
             $RoleFunctionOperator = new erLhcoreClassModelRoleFunction();
             $RoleFunctionOperator->role_id = $RoleOperators->id;
             $RoleFunctionOperator->module = $paramsPermission['module'];
             $RoleFunctionOperator->function = $paramsPermission['function'];
             erLhcoreClassRole::getSession()->save($RoleFunctionOperator);
         }
         $cfgSite = erConfigClassLhConfig::getInstance();
         $cfgSite->setSetting('site', 'installed', true);
         $cfgSite->setSetting('site', 'templatecache', true);
         $cfgSite->setSetting('site', 'templatecompile', true);
         $cfgSite->setSetting('site', 'modulecompile', true);
         return true;
     } else {
         return $Errors;
     }
 }