'activeHelper_liveHelp_domainsList',
'edit' => 'activeHelper_liveHelp_domainsRegister',
'register' => 'activeHelper_liveHelp_domainsRegister',
'settings' => 'activeHelper_liveHelp_domainsSettings',
'script' => 'activeHelper_liveHelp_domainsGenerateScript'
);
if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']]))
return $actions[$_REQUEST['action']]();
return $actions['list']();
}
function activeHelper_liveHelp_domainsPost()
{
$actions = array(
'delete' => 'activeHelper_liveHelp_domainsDeletePost',
'edit' => 'activeHelper_liveHelp_domainsEditPost',
'register' => 'activeHelper_liveHelp_domainsRegisterPost',
'settings' => 'activeHelper_liveHelp_domainsSettingsPost',
'widget' => 'activeHelper_liveHelp_domainsWidgetPost'
);
if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']]))
return $actions[$_REQUEST['action']]();
}
function activeHelper_liveHelp_domainsWidgetPost()
{
global $wpdb, $activeHelper_liveHelp;
$_REQUEST['id'] = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
if (empty($_REQUEST['id']))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
$domain = $wpdb->get_row("
SELECT COUNT(*)
FROM {$wpdb->prefix}livehelp_domains
WHERE id_domain = '{$_REQUEST['id']}'
LIMIT 1
", ARRAY_A);
if (empty($domain))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
// update widget
$widgetOriginal = $activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget.php';
$widgetDownload = $activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget/activehelper_livehelp_widget.php';
activeHelper_liveHelp_filesDelete($widgetDownload);
activeHelper_liveHelp_filesDuplicate($widgetOriginal, $widgetDownload);
$fhandle = fopen($widgetDownload, "r");
$content = fread($fhandle, filesize($widgetDownload));
$content = str_replace('{liveHelp_externalWidget_serverUrl}', $activeHelper_liveHelp['serverUrl'], $content);
$content = str_replace('{liveHelp_externalWidget_domain}', $_REQUEST['id'], $content);
$fhandle = fopen($widgetDownload, "w");
fwrite($fhandle, $content);
fclose($fhandle);
activeHelper_liveHelp_filesDelete($activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget.zip');
activeHelper_liveHelp_filesZip($activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget', $activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget.zip');
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=WordPress_LiveHelp_externalWidget.zip");
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". filesize($activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget.zip'));
readfile($activeHelper_liveHelp['baseDir'] . '/widget/activehelper_livehelp_widget.zip');
exit();
}
function activeHelper_liveHelp_domainsGenerateScript()
{
global $wpdb, $activeHelper_liveHelp;
$_REQUEST['id'] = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$domain = $wpdb->get_row("
SELECT name AS domain_name, status AS domain_status,
configuration AS domain_global_configuration
FROM {$wpdb->prefix}livehelp_domains
WHERE id_domain = '{$_REQUEST['id']}'
LIMIT 1
", ARRAY_A);
$_POST = array_merge($_POST, $domain);
$languages = $wpdb->get_results("
SELECT l.code, l.name, IF(ISNULL(ld.welcome_message), 0, 1) AS status,
IFNULL(ld.welcome_message, '') AS welcome_message
FROM {$wpdb->prefix}livehelp_languages AS l
LEFT JOIN {$wpdb->prefix}livehelp_languages_domain AS ld
ON (ld.id_domain = '{$_REQUEST['id']}' AND ld.code = l.code)
", ARRAY_A);
$activeHelper_liveHelp['languages'] = $languages;
$languages = array();
foreach ($activeHelper_liveHelp['languages'] as $language)
$languages[$language['code']] = $language['name'];
$tabindex = 1;
$generatedScript = '
';
echo '
LiveHelp » ' . __('Domains', 'activehelper_livehelp') . ' (' . $_POST['domain_name'] . ') » ' . __('Generate script', 'activehelper_livehelp') . '
';
echo '
';
}
function activeHelper_liveHelp_domainsList()
{
global $wpdb, $activeHelper_liveHelp;
$domainsList = $wpdb->get_results("
SELECT id_domain AS ID, name AS domain_name, status AS domain_status,
configuration AS domain_global_configuration
FROM {$wpdb->prefix}livehelp_domains
ORDER BY id_domain
", ARRAY_A);
echo '
';
if (isset($_GET['register']))
echo '
' . sprintf(__('The %s was successfully registered.', 'activehelper_livehelp'), __('domain', 'activehelper_livehelp')) . '
';
if (isset($_GET['update']))
echo '
' . sprintf(__('The %s was successfully updated.', 'activehelper_livehelp'), __('domain', 'activehelper_livehelp')) . '
';
if (isset($_GET['delete']))
echo '
' . sprintf(__('The %s was deleted permanently.', 'activehelper_livehelp'), __('domain', 'activehelper_livehelp')) . '
';
if (isset($_GET['miss']))
echo '
' . sprintf(__('The %s was not found.', 'activehelper_livehelp'), __('domain', 'activehelper_livehelp')) . '
';
echo '
';
}
function activeHelper_liveHelp_domainsDeletePost()
{
global $wpdb, $activeHelper_liveHelp;
$_REQUEST['id'] = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
if (empty($_REQUEST['id']))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
$domain = $wpdb->get_row("
SELECT COUNT(*)
FROM {$wpdb->prefix}livehelp_domains
WHERE id_domain = '{$_REQUEST['id']}'
LIMIT 1
", ARRAY_A);
if (empty($domain))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
$wpdb->query("
DELETE FROM {$wpdb->prefix}livehelp_accounts_domain
WHERE id_domain = '{$_REQUEST['id']}'
");
$wpdb->query("
DELETE FROM {$wpdb->prefix}livehelp_languages_domain
WHERE Id_domain = '{$_REQUEST['id']}'
");
$wpdb->query("
DELETE FROM {$wpdb->prefix}livehelp_settings
WHERE id_domain = '{$_REQUEST['id']}'
");
activeHelper_liveHelp_filesDelete($activeHelper_liveHelp['domainsDir'] . '/' . $_REQUEST['id']);
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&delete');
exit;
}
function activeHelper_liveHelp_domainsRegisterPost()
{
global $wpdb, $activeHelper_liveHelp;
$_POST['domain_name'] = !empty($_POST['domain_name']) ? (string) $_POST['domain_name'] : '';
$_POST['domain_status'] = !empty($_POST['domain_status']) ? 1 : 0;
$_POST['domain_global_configuration'] = !empty($_POST['domain_global_configuration']) ? (string) $_POST['domain_global_configuration'] : '';
$errors = array();
$activeHelper_liveHelp['errors'] = &$errors;
while (isset($_POST['submit']))
{
unset($_POST['submit']);
if (empty($_POST['domain_name']))
$errors['domain_name'] = sprintf(__('You must insert a %s', 'activehelper_livehelp'), __('name', 'activehelper_livehelp')); // error
// errors ...
if (!empty($errors))
break;
$wpdb->query("
INSERT INTO {$wpdb->prefix}livehelp_domains
(name, status, configuration)
VALUES
('{$_POST['domain_name']}', '{$_POST['domain_status']}', '{$_POST['domain_global_configuration']}')
");
$insert_id = $wpdb->get_row("
SELECT id_domain AS ID
FROM {$wpdb->prefix}livehelp_domains
ORDER BY id_domain DESC
LIMIT 1
", ARRAY_A);
$insert_id = $insert_id['ID'];
$settingsQuery = activeHelper_liveHelp_domainsSettingsQuery($insert_id);
$wpdb->query($settingsQuery);
activeHelper_liveHelp_filesDuplicate($activeHelper_liveHelp['domainsDir'] . '/0',
$activeHelper_liveHelp['domainsDir'] . '/' . $insert_id);
$wpdb->query("
INSERT INTO {$wpdb->prefix}livehelp_languages_domain
(Id_domain, code, name, welcome_message)
VALUES
('{$insert_id}', 'en', 'English', 'Welcome to our LiveHelp, one moment please.')
");
$wpdb->query("
INSERT INTO {$wpdb->prefix}livehelp_accounts_domain
(id_account, id_domain, status)
VALUES
('1', '{$insert_id}', '1')
");
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '®ister');
exit;
}
}
function activeHelper_liveHelp_domainsEditPost()
{
global $wpdb, $activeHelper_liveHelp;
$_REQUEST['id'] = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$_POST['domain_name'] = !empty($_POST['domain_name']) ? (string) $_POST['domain_name'] : '';
$_POST['domain_status'] = !empty($_POST['domain_status']) ? 1 : 0;
$_POST['domain_global_configuration'] = !empty($_POST['domain_global_configuration']) ? (string) $_POST['domain_global_configuration'] : '';
if (empty($_REQUEST['id']))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
$errors = array();
$activeHelper_liveHelp['errors'] = &$errors;
$domain = $wpdb->get_row("
SELECT name AS domain_name, status AS domain_status,
configuration AS domain_global_configuration
FROM {$wpdb->prefix}livehelp_domains
WHERE id_domain = '{$_REQUEST['id']}'
LIMIT 1
", ARRAY_A);
if (empty($domain))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
if (!isset($_POST['submit']))
$_POST = array_merge($_POST, $domain);
while (isset($_POST['submit']))
{
unset($_POST['submit']);
if (empty($_POST['domain_name']))
$errors['domain_name'] = sprintf(__('You must insert a %s', 'activehelper_livehelp'), __('name', 'activehelper_livehelp')); // error
// errors ...
if (!empty($errors))
break;
$wpdb->query("
UPDATE {$wpdb->prefix}livehelp_domains
SET name = '{$_POST['domain_name']}',
status = '{$_POST['domain_status']}',
configuration = '{$_POST['domain_global_configuration']}'
WHERE id_domain = '{$_REQUEST['id']}'
LIMIT 1
");
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&update');
exit;
}
}
function activeHelper_liveHelp_domainsRegister()
{
global $activeHelper_liveHelp;
if (!empty($activeHelper_liveHelp['errors']))
$errors = $activeHelper_liveHelp['errors'];
$tabindex = 1;
echo '
LiveHelp » ' . __('Domains', 'activehelper_livehelp') . (!empty($_REQUEST['id']) ? ' (' . $_POST['domain_name'] . ')' : '') . ' » ' . (!empty($_REQUEST['id']) ? __('Edit', 'activehelper_livehelp') : __('Add new', 'activehelper_livehelp')) . '
';
}
function activeHelper_liveHelp_domainsSettingsPost()
{
global $wpdb, $activeHelper_liveHelp;
$_REQUEST['id'] = !empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
if (empty($_REQUEST['id']))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
$errors = array();
$activeHelper_liveHelp['errors'] = &$errors;
$domain = $wpdb->get_row("
SELECT name AS domain_name, status AS domain_status,
configuration AS domain_global_configuration
FROM {$wpdb->prefix}livehelp_domains
WHERE id_domain = '{$_REQUEST['id']}'
LIMIT 1
", ARRAY_A);
if (empty($domain))
{
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&miss');
exit;
}
$domain['domain_language'] = 'en'; // fix!
$activeHelper_liveHelp['domain'] = $domain;
$languages = $wpdb->get_results("
SELECT l.code, l.name, IF(ISNULL(ld.welcome_message), 0, 1) AS status,
IFNULL(ld.welcome_message, '') AS welcome_message
FROM {$wpdb->prefix}livehelp_languages AS l
LEFT JOIN {$wpdb->prefix}livehelp_languages_domain AS ld
ON (ld.id_domain = '{$_REQUEST['id']}' AND ld.code = l.code)
", ARRAY_A);
$activeHelper_liveHelp['languages'] = $languages;
$languages = array();
foreach ($activeHelper_liveHelp['languages'] as $language)
$languages[$language['code']] = $language['name'];
$settings = $wpdb->get_results("
SELECT name, value FROM {$wpdb->prefix}livehelp_settings
WHERE id_domain = '{$_REQUEST['id']}'
", ARRAY_A);
$settingsValues = array();
foreach ($settings as $setting)
$settingsValues[$setting['name']] = $setting['value'];
if (!isset($_POST['submit']))
{
$_POST = $settingsValues;
}
else
{
$_POST['campaign_image'] = $settingsValues['campaign_image'];
$_POST['chat_button_img'] = $settingsValues['chat_button_img'];
$_POST['chat_button_hover_img'] = $settingsValues['chat_button_hover_img'];
$_POST['chat_invitation_img'] = $settingsValues['chat_invitation_img'];
$_POST['company_logo'] = $settingsValues['company_logo'];
}
while (isset($_POST['submit']))
{
unset($_POST['submit']);
$domainsPicturesDir = $activeHelper_liveHelp['domainsDir'] . '/' . $_REQUEST['id'] . '/i18n/' . $_POST['domain_language_selector'] . '/pictures';
while (!empty($_FILES['campaign_image']['tmp_name']))
{
if (!empty($_POST['campaign_image']))
activeHelper_liveHelp_imagesDelete($domainsPicturesDir, $_POST['campaign_image']);
$image = activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'chat_banner', $_FILES['campaign_image']);
unset($_FILES['campaign_image']);
if ($image === false)
break;
$_POST['campaign_image'] = $image;
}
while (!empty($_FILES['chat_button_img']['tmp_name']))
{
if (!empty($_POST['chat_button_img']))
activeHelper_liveHelp_imagesDelete($domainsPicturesDir, $_POST['chat_button_img']);
$image = activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'send', $_FILES['chat_button_img']);
unset($_FILES['chat_button_img']);
if ($image === false)
break;
$_POST['chat_button_img'] = $image;
}
while (!empty($_FILES['chat_button_hover_img']['tmp_name']))
{
if (!empty($_POST['chat_button_hover_img']))
activeHelper_liveHelp_imagesDelete($domainsPicturesDir, $_POST['chat_button_hover_img']);
$image = activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'send_hover', $_FILES['chat_button_hover_img']);
unset($_FILES['chat_button_hover_img']);
if ($image === false)
break;
$_POST['chat_button_hover_img'] = $image;
}
while (!empty($_FILES['chat_invitation_img']['tmp_name']))
{
if (!empty($_POST['chat_invitation_img']))
activeHelper_liveHelp_imagesDelete($domainsPicturesDir, $_POST['chat_invitation_img']);
$image = activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'initiate_dialog', $_FILES['chat_invitation_img']);
unset($_FILES['chat_invitation_img']);
if ($image === false)
break;
$_POST['chat_invitation_img'] = $image;
}
while (!empty($_FILES['company_logo']['tmp_name']))
{
if (!empty($_POST['company_logo']))
activeHelper_liveHelp_imagesDelete($domainsPicturesDir, $_POST['company_logo']);
$image = activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'logo', $_FILES['company_logo']);
unset($_FILES['company_logo']);
if ($image === false)
break;
$_POST['company_logo'] = $image;
}
$settingsPost = array();
foreach ($_POST as $name => $value)
if (strpos($name, 'domain_') === false)
$settingsPost[$name] = $value;
$languageStatus = array();
$languageMessages = array();
if (!empty($_POST['domain_language_status']))
foreach ($_POST['domain_language_status'] as $name => $value)
$languageStatus[$name] = !empty($value);
if (!empty($_POST['domain_language_message']))
foreach ($_POST['domain_language_message'] as $name => $value)
$languageMessages[$name] = $value;
foreach ($settingsPost as $name => $value)
$wpdb->query("
UPDATE {$wpdb->prefix}livehelp_settings
SET value = '{$value}'
WHERE name = '{$name}' AND id_domain = '{$_REQUEST['id']}'
");
foreach ($languageStatus as $language => $status)
if (!$status)
$wpdb->query("
DELETE FROM {$wpdb->prefix}livehelp_languages_domain
WHERE code = '{$language}' AND Id_domain = '{$_REQUEST['id']}'
");
foreach ($languageMessages as $language => $message)
if (!empty($languageStatus[$language]))
$wpdb->query("
REPLACE INTO {$wpdb->prefix}livehelp_languages_domain
(Id_domain, name, code, welcome_message)
VALUES
('{$_REQUEST['id']}', '{$languages[$language]}', '{$language}', '{$message}')
");
while (!empty($_FILES['domain_image_online']['tmp_name']))
{
activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'online', $_FILES['domain_image_online'], '.gif');
unset($_FILES['domain_image_online']);
}
while (!empty($_FILES['domain_image_offline']['tmp_name']))
{
activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'offline', $_FILES['domain_image_offline'], '.gif');
unset($_FILES['domain_image_offline']);
}
while (!empty($_FILES['domain_image_away']['tmp_name']))
{
activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'away', $_FILES['domain_image_away'], '.gif');
unset($_FILES['domain_image_away']);
}
while (!empty($_FILES['domain_image_brb']['tmp_name']))
{
activeHelper_liveHelp_imagesUpload($domainsPicturesDir, 'brb', $_FILES['domain_image_brb'], '.gif');
unset($_FILES['domain_image_brb']);
}
wp_redirect('admin.php?page=' . strtolower('activeHelper_liveHelp_domains') . '&update');
exit;
}
}
function activeHelper_liveHelp_domainsSettings()
{
global $activeHelper_liveHelp;
if (!empty($activeHelper_liveHelp['errors']))
$errors = $activeHelper_liveHelp['errors'];
$tabindex = 1;
echo '
LiveHelp » ' . __('Domains', 'activehelper_livehelp') . (!empty($_REQUEST['id']) ? ' (' . $activeHelper_liveHelp['domain']['domain_name'] . ')' : '') . ' » ' . __('Settings', 'activehelper_livehelp') . '
';
}
function activeHelper_liveHelp_domainsSettingsQuery($domain)
{
global $wpdb;
$settingsQuery = "
INSERT INTO {$wpdb->prefix}livehelp_settings
(name, value, id_domain)
VALUES
('admin_homepage', '/eserver1/panel/visitors_index.php', {$domain}),
('timezone', '+1000', {$domain}),
('default_department', 'General', {$domain}),
('departments', '1', {$domain}),
('disable_offline_email', '0', {$domain}),
('disable_login_details', '0', {$domain}),
('admin_chat_font_size', '12px', {$domain}),
('guest_chat_font_size', '12px', {$domain}),
('background_color', '#F9F9F9', {$domain}),
('font_link_color', '#333399', {$domain}),
('received_font_color', '#000000', {$domain}),
('sent_font_color', '#666666', {$domain}),
('chat_font_type', 'Arial, Arial Unicode, Lucida, Verdana', {$domain}),
('font_color', '#000000', {$domain}),
('font_size', '13px', {$domain}),
('font_type', 'Arial, Helvetica, sans-serif,Verdana', {$domain}),
('admin_smilies', '0', {$domain}),
('guest_smilies', '1', {$domain}),
('livehelp_logo', 'eserver/i18n/sp/pictures/help_logo.gif', {$domain}),
('livehelp_name', 'www.activehelper.com Live Help', {$domain}),
('offline_email', 'support@activehelper.com', {$domain}),
('site_address', 'http://www.activehelper.com', {$domain}),
('site_name', 'www.activehelper.com', {$domain}),
('initiate_chat_valign', 'top', {$domain}),
('initiate_chat_halign', 'right', {$domain}),
('disable_chat_username', '0', {$domain}),
('campaign_image', 'chat_banner.gif', {$domain}),
('campaign_link', 'http://www.activehelper.com/', {$domain}),
('disable_popup_help', '1', {$domain}),
('p3p', 'ALL DSP COR CUR OUR IND ONL UNI COM NAV', {$domain}),
('require_guest_details', '0', {$domain}),
('configure_smtp', '0', {$domain}),
('smtp_server', '', {$domain}),
('smtp_port', '25', {$domain}),
('from_email', 'support@activehelper.com', {$domain}),
('login_timeout', '20', {$domain}),
('chat_background_img', 'background_chat_grey.jpg', {$domain}),
('chat_invitation_img', 'initiate_dialog.gif', {$domain}),
('chat_button_img', 'send.gif', {$domain}),
('chat_button_hover_img', 'send_hover.gif', {$domain}),
('custom_offline_form_link', '', {$domain}),
('log_offline_email', 0, {$domain}),
('disable_language', 0, {$domain}),
('company_logo', 'logo.jpg', {$domain}),
('company_link', 'http://www.activehelper.com', {$domain}),
('disable_copyright', 1, {$domain}),
('company_slogan', 'ACTIVEHELPER Platform All Rights Reserved', {$domain}),
('copyright_image', 1, {$domain}),
('analytics_account','', {$domain}),
('invitation_refresh', 0, {$domain}),
('disable_invitation', 0, {$domain}),
('disable_geolocation', 0, {$domain}),
('disable_tracking_offline', 0, {$domain}),
('captcha', 1, {$domain}),
('disable_agent_bannner', 0, {$domain})
";
return $settingsQuery;
}