public static function generateAcceptLink(erLhcoreClassModelChat $chat)
 {
     $accept = new self();
     $accept->hash = erLhcoreClassModelForgotPassword::randomPassword(40);
     $accept->chat_id = $chat->id;
     $accept->saveThis();
     return $accept->hash;
 }
 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');
     }
 }
 public function saveThis()
 {
     if ($this->url != '') {
         $matchStringURL = '';
         $parts = parse_url($this->url);
         if (isset($parts['path'])) {
             $matchStringURL = $parts['path'];
         }
         if (isset($parts['query'])) {
             $matchStringURL .= '?' . $parts['query'];
         }
         $this->url = $matchStringURL;
         $this->has_url = 1;
         if (substr($this->url, -1) == '*') {
             $this->is_wildcard = 1;
         }
     } else {
         $this->has_url = 0;
         $this->is_wildcard = 0;
     }
     if ($this->hash == '') {
         $this->hash = erLhcoreClassModelForgotPassword::randomPassword(30);
     }
     erLhcoreClassAbstract::getSession()->saveOrUpdate($this);
 }
Пример #4
0
 $db->query("CREATE TABLE IF NOT EXISTS `lh_question_answer` (\n        \t   `id` int(11) NOT NULL AUTO_INCREMENT,\n        \t   `ip` bigint(20) NOT NULL,\n        \t   `question_id` int(11) NOT NULL,\n        \t   `answer` text NOT NULL,\n        \t   `ctime` int(11) NOT NULL,\n        \t   PRIMARY KEY (`id`),\n        \t   KEY `ip` (`ip`),\n        \t   KEY `question_id` (`question_id`)\n        \t   ) DEFAULT CHARSET=utf8");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_question_option` (\n        \t   `id` int(11) NOT NULL AUTO_INCREMENT,\n        \t   `question_id` int(11) NOT NULL,\n        \t   `option_name` varchar(250) NOT NULL,\n        \t   `priority` tinyint(4) NOT NULL,\n        \t   PRIMARY KEY (`id`),\n        \t   KEY `question_id` (`question_id`)\n        \t   ) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_question_option_answer` (\n        \t   `id` int(11) NOT NULL AUTO_INCREMENT,\n        \t   `question_id` int(11) NOT NULL,\n        \t   `option_id` int(11) NOT NULL,\n        \t   `ctime` int(11) NOT NULL,\n        \t   `ip` bigint(20) NOT NULL,\n        \t   PRIMARY KEY (`id`),\n        \t   KEY `question_id` (`question_id`),\n        \t   KEY `ip` (`ip`)\n        \t   ) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_browse_offer_invitation` (\n\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `siteaccess` varchar(10) NOT NULL,\n\t\t\t\t  `time_on_site` int(11) NOT NULL,\n\t\t\t\t  `content` longtext NOT NULL,\n\t\t\t\t  `callback_content` longtext NOT NULL,\n\t\t\t\t  `lhc_iframe_content` tinyint(4) NOT NULL,\n\t\t\t\t  `custom_iframe_url` varchar(250) NOT NULL,\n\t\t\t\t  `name` varchar(250) NOT NULL,\n\t\t\t\t  `identifier` varchar(50) NOT NULL,\n\t\t\t\t  `executed_times` int(11) NOT NULL,\n\t\t\t\t  `url` varchar(250) NOT NULL,\n\t\t\t\t  `active` int(11) NOT NULL,\n\t\t\t\t  `has_url` int(11) NOT NULL,\n\t\t\t\t  `is_wildcard` int(11) NOT NULL,\n\t\t\t\t  `referrer` varchar(250) NOT NULL,\n\t\t\t\t  `priority` varchar(250) NOT NULL,\n\t\t\t\t  `hash` varchar(40) NOT NULL,\n\t\t\t\t  `width` int(11) NOT NULL,\n\t\t\t\t  `height` int(11) NOT NULL,\n\t\t\t\t  `unit` varchar(10) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `active` (`active`),\n\t\t\t\t  KEY `identifier` (`identifier`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_form` (\n        \t   `id` int(11) NOT NULL AUTO_INCREMENT,\n        \t   `name` varchar(100) NOT NULL,        \t   \n        \t   `content` longtext NOT NULL,\n        \t   `recipient` varchar(250) NOT NULL,\n        \t   `active` int(11) NOT NULL,\n        \t   `name_attr` varchar(250) NOT NULL,\n        \t   `intro_attr` varchar(250) NOT NULL,\n        \t   `xls_columns` text NOT NULL,\n        \t   `pagelayout` varchar(200) NOT NULL,\n        \t   `post_content` text NOT NULL,\n        \t   PRIMARY KEY (`id`)\n        \t   ) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_abstract_form_collected` (\n\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `form_id` int(11) NOT NULL,\n\t\t\t\t  `ctime` int(11) NOT NULL,\n\t\t\t\t  `ip` varchar(250) NOT NULL,\n        \t   \t  `identifier` varchar(250) NOT NULL,\n\t\t\t\t  `content` longtext NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `form_id` (`form_id`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_chatbox` (\n\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `identifier` varchar(50) NOT NULL,\n\t\t\t\t  `name` varchar(100) NOT NULL,\n\t\t\t\t  `chat_id` int(11) NOT NULL,\n\t\t\t\t  `active` int(11) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `identifier` (`identifier`)\n\t\t\t\t) 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        \t   \t  `position` int(11) NOT NULL,\n        \t   \t  `department_id` int(11) NOT NULL,\n        \t   \t  `user_id` int(11) NOT NULL,\n  \t\t\t\t  `delay` int(11) NOT NULL,\n        \t   \t  `auto_send` tinyint(1) NOT NULL,\n                  PRIMARY KEY (`id`),\n        \t   \t  KEY `department_id` (`department_id`),\n        \t   \t  KEY `user_id` (`user_id`)\n                ) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_online_user_footprint` (\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  `online_user_id` int(11) NOT NULL,\n\t\t\t\t  `page` varchar(250) NOT NULL,\n\t\t\t\t  `vtime` varchar(250) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `chat_id_vtime` (`chat_id`,`vtime`),\n\t\t\t\t  KEY `online_user_id` (`online_user_id`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_users_setting` (\n        \t   `id` int(11) NOT NULL AUTO_INCREMENT,\n        \t   `user_id` int(11) NOT NULL,\n        \t   `identifier` varchar(50) NOT NULL,\n        \t   `value` varchar(50) NOT NULL,\n        \t   PRIMARY KEY (`id`),\n        \t   KEY `user_id` (`user_id`,`identifier`)\n        \t   ) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_users_setting_option` (\n\t\t\t\t  `identifier` varchar(50) NOT NULL,\n\t\t\t\t  `class` varchar(50) NOT NULL,\n\t\t\t\t  `attribute` varchar(40) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`identifier`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 $db->query("INSERT INTO `lh_users_setting_option` (`identifier`, `class`, `attribute`) VALUES\n        \t   ('chat_message',\t'',\t''),\n        \t   ('new_chat_sound',\t'',\t''),\n        \t   ('enable_pending_list', '', ''),\n        \t   ('enable_active_list', '', ''),\n        \t   ('enable_close_list', '', ''),\n        \t   ('new_user_bn', '', ''),\n        \t   ('new_user_sound', '', ''),\n        \t   ('oupdate_timeout', '', ''),\n        \t   ('ouser_timeout', '', ''),\n        \t   ('o_department', '', ''),\n        \t   ('omax_rows', '', ''),\n        \t   ('ogroup_by', '', ''),\n        \t   ('omap_depid', '', ''),\n        \t   ('omap_mtimeout', '', ''),\n        \t   ('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        \t   \t('list_online_operators', '0', '0', 'List online operators.', '0'),\n        \t   \t('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        \t   \t('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        \t   \t('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        \t    ('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                ('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                ('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                ('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                ('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                ('front_tabs', 'online_users,online_map,pending_chats,active_chats,unread_chats,closed_chats,online_operators', '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\t\t\t\t('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        \t   \t  `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        \t   \t  `invitation_id` int(11) NOT NULL,\n                  `last_visit` int(11) NOT NULL,\n        \t   \t  `first_visit` int(11) NOT NULL,\n        \t   \t  `total_visits` int(11) NOT NULL,\n        \t   \t  `pages_count` int(11) NOT NULL,\n        \t   \t  `tt_pages_count` int(11) NOT NULL,\n        \t   \t  `invitation_count` int(11) NOT NULL,\n        \t   \t  `last_check_time` int(11) NOT NULL,\n        \t   \t  `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        \t   \t  `lat` varchar(10) NOT NULL,\n  \t\t\t\t  `lon` varchar(10) NOT NULL,\n  \t\t\t\t  `city` varchar(100) NOT NULL,\n        \t   \t  `reopen_chat` int(11) NOT NULL,\n        \t   \t  `time_on_site` int(11) NOT NULL,\n  \t\t\t\t  `tt_time_on_site` int(11) NOT NULL,\n        \t   \t  `requires_email` int(11) NOT NULL,\n        \t   \t  `requires_username` int(11) NOT NULL,\n        \t   \t  `requires_phone` int(11) NOT NULL,\n        \t   \t  `screenshot_id` int(11) NOT NULL,\n        \t   \t  `identifier` varchar(50) NOT NULL,\n        \t   \t  `operation` text NOT NULL,\n        \t   \t  `online_attr_system` text NOT NULL,\n        \t   \t  `operation_chat` text NOT NULL,\n        \t   \t  `online_attr` varchar(250) NOT NULL,\n                  PRIMARY KEY (`id`),\n                  KEY `vid` (`vid`),\n\t\t\t\t  KEY `dep_id` (`dep_id`),\n\t\t\t\t  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\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `siteaccess` varchar(10) NOT NULL,\n\t\t\t\t  `time_on_site` int(11) NOT NULL,\n\t\t\t\t  `pageviews` int(11) NOT NULL,\n\t\t\t\t  `message` text NOT NULL,\n\t\t\t\t  `message_returning` text NOT NULL,\n\t\t\t\t  `executed_times` int(11) NOT NULL,\n\t\t\t\t  `dep_id` int(11) NOT NULL,\n\t\t\t\t  `hide_after_ntimes` int(11) NOT NULL,\n\t\t\t\t  `name` varchar(50) NOT NULL,\n\t\t\t\t  `operator_ids` varchar(100) NOT NULL,\n\t\t\t\t  `wait_message` varchar(250) NOT NULL,\n\t\t\t\t  `timeout_message` varchar(250) NOT NULL,\n\t\t\t\t  `message_returning_nick` varchar(250) NOT NULL,\n\t\t\t\t  `referrer` varchar(250) NOT NULL,\n\t\t\t\t  `wait_timeout` int(11) NOT NULL,\n\t\t\t\t  `show_random_operator` int(11) NOT NULL,\n\t\t\t\t  `operator_name` varchar(100) NOT NULL,\n\t\t\t\t  `position` int(11) NOT NULL,\n        \t   \t  `identifier` varchar(50) NOT NULL,\n        \t   \t  `requires_email` int(11) NOT NULL,\n        \t   \t  `requires_username` int(11) NOT NULL,\n        \t   \t  `requires_phone` int(11) NOT NULL,\n        \t   \t  `repeat_number` int(11) NOT NULL DEFAULT '1',\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `time_on_site_pageviews_siteaccess_position` (`time_on_site`,`pageviews`,`siteaccess`,`identifier`,`position`),\n        \t      KEY `identifier` (`identifier`),\n        \t      KEY `dep_id` (`dep_id`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 $db->query("CREATE TABLE IF NOT EXISTS `lh_chat_accept` (\n        \t   `id` int(11) NOT NULL AUTO_INCREMENT,\n        \t   `chat_id` int(11) NOT NULL,\n        \t   `hash` varchar(50) NOT NULL,\n        \t   `ctime` int(11) NOT NULL,\n        \t   `wused` int(11) NOT NULL,\n        \t   PRIMARY KEY (`id`),\n        \t   KEY `hash` (`hash`)\n        \t   ) DEFAULT CHARSET=utf8;");
 //Default departament
 $db->query("CREATE TABLE IF NOT EXISTS `lh_departament` (\n\t\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `name` varchar(100) NOT NULL,\n\t\t\t\t  `email` varchar(100) NOT NULL,\n\t\t\t\t  `xmpp_recipients` varchar(250) NOT NULL,\n\t\t\t\t  `xmpp_group_recipients` varchar(250) NOT NULL,\n\t\t\t\t  `priority` int(11) NOT NULL,\n\t\t\t\t  `department_transfer_id` int(11) NOT NULL,\n\t\t\t\t  `transfer_timeout` int(11) NOT NULL,\n\t\t\t\t  `disabled` int(11) NOT NULL,\n\t\t\t\t  `hidden` int(11) NOT NULL,\n\t\t\t\t  `delay_lm` int(11) NOT NULL,\n\t\t\t\t  `max_active_chats` int(11) NOT NULL,\n\t\t\t\t  `max_timeout_seconds` int(11) NOT NULL,\n\t\t\t\t  `identifier` varchar(50) NOT NULL,\n\t\t\t\t  `mod` tinyint(1) NOT NULL,\n\t\t\t\t  `tud` tinyint(1) NOT NULL,\n\t\t\t\t  `wed` tinyint(1) NOT NULL,\n\t\t\t\t  `thd` tinyint(1) NOT NULL,\n\t\t\t\t  `frd` tinyint(1) NOT NULL,\n\t\t\t\t  `sad` tinyint(1) NOT NULL,\n\t\t\t\t  `sud` tinyint(1) NOT NULL,\n\t\t\t\t  `nc_cb_execute` tinyint(1) NOT NULL,\n\t\t\t\t  `na_cb_execute` tinyint(1) NOT NULL,\n\t\t\t\t  `inform_unread` tinyint(1) NOT NULL,\n\t\t\t\t  `active_balancing` tinyint(1) NOT NULL,\n\t\t\t\t  `start_hour` int(2) NOT NULL,\n\t\t\t\t  `end_hour` int(2) NOT NULL,\n\t\t\t\t  `inform_close` int(11) NOT NULL,\n\t\t\t\t  `inform_unread_delay` int(11) NOT NULL,\n\t\t\t\t  `inform_options` varchar(250) NOT NULL,\n\t\t\t\t  `online_hours_active` tinyint(1) NOT NULL,\n\t\t\t\t  `inform_delay` int(11) NOT NULL,\n\t\t\t\t  PRIMARY KEY (`id`),\n\t\t\t\t  KEY `identifier` (`identifier`),\n\t\t\t\t  KEY `disabled_hidden` (`disabled`, `hidden`),\n\t\t\t\t  KEY `oha_sh_eh` (`online_hours_active`,`start_hour`,`end_hour`)\n\t\t\t\t) DEFAULT CHARSET=utf8;");
 $Departament = new erLhcoreClassModelDepartament();
 $Departament->name = $form->DefaultDepartament;
 erLhcoreClassDepartament::getSession()->save($Departament);
 //Administrators group
Пример #5
0
 protected function get_file_name($name, $type = null, $index = null, $content_range = null)
 {
     $name = sha1($name . erLhcoreClassModelForgotPassword::randomPassword(40) . time());
     return md5($this->get_unique_filename($this->trim_file_name($name, $type, $index, $content_range), $type, $index, $content_range));
 }
 public static function createCustomer($instance)
 {
     $originalSiteAccess = erLhcoreClassSystem::instance()->SiteAccess;
     if ($instance->locale != '') {
         erLhcoreClassSystem::instance()->setSiteAccessByLocale($instance->locale);
     }
     $password = erLhcoreClassModelForgotPassword::randomPassword(10);
     $chat_box_hash = erLhcoreClassModelForgotPassword::randomPassword(10);
     $searchArray = array('{email_replace}', '{password_hash}', '{export_hash_chats}', '{chat_box_hash}', '{chat_box_hash_length}');
     $cfg = erConfigClassLhConfig::getInstance();
     $replaceArray = array($instance->email, sha1($password . $cfg->getSetting('site', 'secrethash') . sha1($password)), erLhcoreClassModelForgotPassword::randomPassword(10), $chat_box_hash, strlen($chat_box_hash));
     $db = ezcDbInstance::get();
     self::deleteDatabase($instance->id);
     self::createDatabase($instance->id);
     $db->query('USE ' . $cfg->getSetting('db', 'database_user_prefix') . $instance->id);
     $sql = file_get_contents('extension/instance/doc/db_3.sql');
     $sql = str_replace($searchArray, $replaceArray, $sql);
     $db->query($sql);
     $dbPostUpdate = ltrim(erLhcoreClassDesign::design('db_post_update/db.sql'), '/');
     if (file_exists($dbPostUpdate)) {
         $db->query(file_get_contents($dbPostUpdate));
     }
     // Insert default user language
     if ($instance->locale != '') {
         $stm = $db->prepare("INSERT INTO `lh_users_setting` (`user_id`, `identifier`, `value`) VALUES (1,'user_language',:value)");
         $stm->bindValue(':value', $instance->locale);
         $stm->execute();
     } else {
         $stm = $db->prepare("INSERT INTO `lh_users_setting` (`user_id`, `identifier`, `value`) VALUES (1,'user_language',:value)");
         $stm->bindValue(':value', 'en_EN');
         $stm->execute();
     }
     $tpl = erLhcoreClassTemplate::getInstance('lhinstance/email.tpl.php');
     $tpl->setArray(array('instance' => $instance, 'email' => $instance->email, 'password' => $password));
     $mail = new PHPMailer();
     $mail->CharSet = 'UTF-8';
     $mail->Sender = $mail->From = $cfg->getSetting('site', 'seller_mail');
     $mail->FromName = $cfg->getSetting('site', 'seller_title');
     $mail->Subject = $cfg->getSetting('site', 'seller_title');
     $mail->AddReplyTo($cfg->getSetting('site', 'seller_mail'), $cfg->getSetting('site', 'seller_title'));
     $mail->Body = $tpl->fetch();
     $mail->AddAddress($instance->email);
     erLhcoreClassChatMail::setupSMTP($mail);
     $mail->Send();
     $mail->ClearAddresses();
     // Dispatch event for listeners
     erLhcoreClassChatEventDispatcher::getInstance()->dispatch('instance.registered.created', array('instance' => $instance));
     $db->query('USE ' . $cfg->getSetting('db', 'database'));
     // Activate instance
     $sql = "UPDATE lhc_instance_client SET status = 1 WHERE id = {$instance->id}";
     $db->query($sql);
     if ($instance->locale != '') {
         erLhcoreClassSystem::instance()->setSiteAccess($originalSiteAccess);
     }
 }
Пример #7
0
 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;
     }
 }
Пример #8
0
 function validateRemember($hashCookie)
 {
     $parts = explode(':', $hashCookie);
     if (count($parts) == 3) {
         list($salt1, $id, $hash) = $parts;
         $cfgSite = erConfigClassLhConfig::getInstance();
         $salt2 = $cfgSite->getSetting('site', 'secrethash');
         try {
             $ruser = erLhcoreClassModelUserRemember::fetch($id);
             if ($hash == sha1($ruser->user_id . '_' . $ruser->id . $salt2 . $salt1 . erLhcoreClassIPDetect::getIP() . $_SERVER['HTTP_USER_AGENT'])) {
                 $ruser->mtime = time();
                 $ruser->updateThis();
                 $this->setLoggedUser($ruser->user_id);
                 // Update remember hash
                 $salt1 = erLhcoreClassModelForgotPassword::randomPassword(30);
                 $hash = $salt1 . ':' . $ruser->id . ':' . sha1($this->userid . '_' . $ruser->id . $salt2 . $salt1 . erLhcoreClassIPDetect::getIP() . $_SERVER['HTTP_USER_AGENT']);
                 setcookie('lhc_rm_u', $hash, time() + 365 * 24 * 3600, '/');
                 return true;
             }
         } catch (Exception $e) {
             return false;
         }
     } else {
         if (isset($_COOKIE['lhc_rm_u'])) {
             unset($_COOKIE['lhc_rm_u']);
             setcookie('lhc_rm_u', '', time() - 31 * 24 * 3600, '/');
         }
     }
     return false;
 }
Пример #9
0
 $form = new ezcInputForm(INPUT_POST, $definition);
 $Errors = array();
 if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) {
     erLhcoreClassModule::redirect('user/forgotpassword');
     exit;
 }
 if (!$form->hasValidData('Email')) {
     $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('user/forgotpassword', 'Invalid e-mail address!');
 }
 if (count($Errors) == 0) {
     if (($userID = erLhcoreClassModelUser::fetchUserByEmail($form->Email)) !== false) {
         $host = $_SERVER['HTTP_HOST'];
         $adminEmail = erConfigClassLhConfig::getInstance()->getSetting('site', 'site_admin_email');
         $UserData = erLhcoreClassUser::getSession()->load('erLhcoreClassModelUser', $userID);
         $hash = erLhcoreClassModelForgotPassword::randomPassword(40);
         erLhcoreClassModelForgotPassword::setRemindHash($UserData->id, $hash);
         $mail = new PHPMailer();
         $mail->CharSet = "UTF-8";
         $mail->From = $adminEmail;
         $mail->FromName = erConfigClassLhConfig::getInstance()->getSetting('site', 'title');
         $mail->Subject = erTranslationClassLhTranslation::getInstance()->getTranslation('user/forgotpassword', 'Password remind');
         // HTML body
         $body = erTranslationClassLhTranslation::getInstance()->getTranslation('user/forgotpassword', 'Click this link and You will be sent a new password') . ' </br><a href="http://' . $host . erLhcoreClassDesign::baseurl('user/remindpassword') . '/' . $hash . '">Restore password</a>';
         // Plain text body
         $text_body = erTranslationClassLhTranslation::getInstance()->getTranslation('user/forgotpassword', 'Click this link and You will be sent a new password') . ' - http://' . $host . erLhcoreClassDesign::baseurl('user/remindpassword') . '/' . $hash;
         $mail->Body = $body;
         $mail->AltBody = $text_body;
         $mail->AddAddress($UserData->email, $UserData->username);
         erLhcoreClassChatMail::setupSMTP($mail);
         $mail->Send();
         $mail->ClearAddresses();
    if (isset($_POST['attr_int_3'])) {
        $instance->attr_int_3 = $_POST['attr_int_3'];
    }
    if ($Params['user_parameters_unordered']['is_reseller'] == 1) {
        $instance->is_reseller = 1;
        if ($Params['user_parameters_unordered']['reseller_tite'] != '') {
            $instance->reseller_tite = base64_decode(rawurldecode($Params['user_parameters_unordered']['reseller_tite']));
        }
        if ($Params['user_parameters_unordered']['reseller_max_instance_request'] != '') {
            $instance->reseller_max_instance_request = (int) $Params['user_parameters_unordered']['reseller_max_instance_request'];
        }
        if ($Params['user_parameters_unordered']['reseller_secret_hash'] != '') {
            $instance->reseller_secret_hash = base64_decode(rawurldecode($Params['user_parameters_unordered']['reseller_secret_hash']));
        }
        // Generate reseller hash if it was not provided
        if ($instance->reseller_secret_hash == '') {
            $instance->reseller_secret_hash = erLhcoreClassModelForgotPassword::randomPassword(20);
        }
        if ($Params['user_parameters_unordered']['reseller_max_instances'] != '') {
            $instance->reseller_max_instances = (int) $Params['user_parameters_unordered']['reseller_max_instances'];
        }
        if ($Params['user_parameters_unordered']['reseller_request'] != '') {
            $instance->reseller_request = (int) $Params['user_parameters_unordered']['reseller_request'];
        }
    }
    $instance->saveThis();
    echo json_encode(array('error' => 'false', 'msg' => 'instance created', 'data' => get_object_vars($instance)));
} else {
    echo json_encode(array('error' => 'true', 'reason' => 'invalid hash'));
}
exit;
Пример #11
0
    $hashData = erLhcoreClassModelForgotPassword::checkHash($hash);
    if ($hashData) {
        $UserData = erLhcoreClassUser::getSession()->load('erLhcoreClassModelUser', (int) $hashData['user_id']);
        if ($UserData) {
            $password = erLhcoreClassModelForgotPassword::randomPassword(10);
            $UserData->setPassword($password);
            erLhcoreClassUser::getSession()->update($UserData);
            $adminEmail = erConfigClassLhConfig::getInstance()->getSetting('site', 'site_admin_email');
            $mail = new PHPMailer();
            $mail->CharSet = "UTF-8";
            $mail->From = $adminEmail;
            $mail->FromName = erConfigClassLhConfig::getInstance()->getSetting('site', 'title');
            $mail->Subject = erTranslationClassLhTranslation::getInstance()->getTranslation('user/remindpassword', 'Password remind - new password');
            // HTML body
            $body = erTranslationClassLhTranslation::getInstance()->getTranslation('user/remindpassword', 'New password:'******' ' . $password;
            // Plain text body
            $text_body = erTranslationClassLhTranslation::getInstance()->getTranslation('user/remindpassword', 'New password:'******' ' . $password;
            $mail->Body = $body;
            $mail->AltBody = $text_body;
            $mail->AddAddress($UserData->email, $UserData->username);
            erLhcoreClassChatMail::setupSMTP($mail);
            $mail->Send();
            $mail->ClearAddresses();
            $msg = erTranslationClassLhTranslation::getInstance()->getTranslation('user/remindpassword', 'New password has been sent to your email.');
            erLhcoreClassModelForgotPassword::deleteHash($hashData['id']);
        }
    }
}
$tpl->set('msg', $msg);
$Result['content'] = $tpl->fetch();
$Result['pagelayout'] = 'login';