/** * @package ActiveHelper Live Help */ /* Plugin Name: ActiveHelper Live Help Plugin URI: http://www.activehelper.com Description: Provide superior service by real time chat with your website visitors and interact them through your website. Create a more efficient connection with your website visitors, increase your sales and customer satisfaction. Version: 2.9.1 Author: ActiveHelper Inc Author URI: http://www.activehelper.com */ /* Developer: Marco Florian (marco@marcorfg.com) Developer URI: http://www.marcorfg.com Updates : Activehelper Inc. */ // make sure we don't expose any info if called directly if (!function_exists('add_action')) { echo 'Hi there! I\'m just a plugin, not much I can do when called directly.'; exit(); } define("ACTIVEHELPER_LIVEHELP", true); $activeHelper_liveHelp = array(); $activeHelper_liveHelp['baseDir'] = dirname(__FILE__); $activeHelper_liveHelp['sourcesDir'] = $activeHelper_liveHelp['baseDir'] . '/sources'; $activeHelper_liveHelp['importDir'] = $activeHelper_liveHelp['baseDir'] . '/server/import'; $activeHelper_liveHelp['domainsDir'] = $activeHelper_liveHelp['baseDir'] . '/server/domains'; $activeHelper_liveHelp['agentsDir'] = $activeHelper_liveHelp['baseDir'] . '/server/pictures/agents'; $activeHelper_liveHelp['languagesDir'] = 'activehelper_livehelp/languages'; $activeHelper_liveHelp['baseUrl'] = plugins_url('', __FILE__); $activeHelper_liveHelp['serverUrl'] = $activeHelper_liveHelp['baseUrl'] . '/server'; $activeHelper_liveHelp['domainsUrl'] = $activeHelper_liveHelp['baseUrl'] . '/server/domains'; $activeHelper_liveHelp['agentsUrl'] = $activeHelper_liveHelp['baseUrl'] . '/server/pictures/agents'; $activeHelper_liveHelp['imagesUrl'] = $activeHelper_liveHelp['baseUrl'] . '/images'; require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_widget.php'); if (!is_admin()) return; require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_lib-install.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_lib-images.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_lib-files.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_domains.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_agents.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_monthly-chats.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_time-by-chat.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_failed-chats.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_chats-by-department.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_chats-by-country.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_chats-by-keyword.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_offline-messages.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_server-settings.php'); require_once($activeHelper_liveHelp['sourcesDir'] . '/livehelp_restricted-countries.php'); add_action('init', 'activeHelper_liveHelp_mainLanguages'); add_action('admin_init', 'activeHelper_liveHelp_mainInstall'); add_action('admin_init', 'activeHelper_liveHelp_mainPost'); add_action('admin_menu', 'activeHelper_liveHelp_mainMenu'); function activeHelper_liveHelp_mainLanguages() { global $activeHelper_liveHelp; if (!defined('WP_PLUGIN_DIR')) load_plugin_textdomain('activehelper_livehelp', $activeHelper_liveHelp['languagesDir']); else load_plugin_textdomain('activehelper_livehelp', false, $activeHelper_liveHelp['languagesDir']); } function activeHelper_liveHelp_mainInstall() { global $wpdb, $activeHelper_liveHelp; $is_installed = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_domains "); $activeHelper_liveHelp['is_installed'] = $is_installed !== null; if (!$activeHelper_liveHelp['is_installed']) activeHelper_liveHelp_install(); } function activeHelper_liveHelp_mainPost() { $pages = array( strtolower('activeHelper_liveHelp_domains') => 'activeHelper_liveHelp_domainsPost', strtolower('activeHelper_liveHelp_agents') => 'activeHelper_liveHelp_agentsPost', strtolower('activeHelper_liveHelp_welcome') => 'activeHelper_liveHelp_welcomePost', strtolower('activeHelper_liveHelp_monthlyChats') => 'activeHelper_liveHelp_monthlyChatsPost', strtolower('activeHelper_liveHelp_timeByChat') => 'activeHelper_liveHelp_timeByChatPost', strtolower('activeHelper_liveHelp_failedChats') => 'activeHelper_liveHelp_failedChatsPost', strtolower('activeHelper_liveHelp_chatsByDepartment') => 'activeHelper_liveHelp_chatsByDepartmentPost', strtolower('activeHelper_liveHelp_chatsByCountry') => 'activeHelper_liveHelp_chatsByCountryPost', strtolower('activeHelper_liveHelp_chatsByKeyword') => 'activeHelper_liveHelp_chatsByKeywordPost', strtolower('activeHelper_liveHelp_offlineMessages') => 'activeHelper_liveHelp_offlineMessagesPost', strtolower('activeHelper_liveHelp_serverSettings') => 'activeHelper_liveHelp_serverSettingsPost', strtolower('activeHelper_liveHelp_about') => 'activeHelper_liveHelp_aboutPost', strtolower('activeHelper_liveHelp_restrictedCountries') => 'activeHelper_liveHelp_restrictedCountriesPost', strtolower('activehelper_livehelp_uninstall') => 'activehelper_livehelp_uninstallPost' ); if (!empty($_GET['page']) && isset($pages[$_GET['page']])) { if (empty($_REQUEST['action'])) $_REQUEST['action'] = 'list'; return $pages[$_GET['page']](); } } function activeHelper_liveHelp_mainMenu() { if (!function_exists('add_menu_page') || !function_exists('add_submenu_page')) return; // add block add_menu_page( 'LiveHelp System', // page title 'LiveHelp System', // menu title 'none', // type strtolower('activeHelper_liveHelp') // id ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Dashboard', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Dashboard', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_welcome'), // id 'activeHelper_liveHelp_welcome' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Manage domains', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Manage domains', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_domains'), // id 'activeHelper_liveHelp_domains' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Manage agents', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Manage agents', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_agents'), // id 'activeHelper_liveHelp_agents' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Monthly chats', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Monthly chats', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_monthlyChats'), // id 'activeHelper_liveHelp_monthlyChats' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Time by chat', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Time by chat', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_timeByChat'), // id 'activeHelper_liveHelp_timeByChat' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Failed chats', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Failed chats', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_failedChats'), // id 'activeHelper_liveHelp_failedChats' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Chats by department', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Chats by department', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_chatsByDepartment'), // id 'activeHelper_liveHelp_chatsByDepartment' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Chats by country', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Chats by country', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_chatsByCountry'), // id 'activeHelper_liveHelp_chatsByCountry' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Chats by keyword', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Chats by keyword', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_chatsByKeyword'), // id 'activeHelper_liveHelp_chatsByKeyword' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Offline messages', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Offline messages', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_offlineMessages'), // id 'activeHelper_liveHelp_offlineMessages' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Server settings', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Server settings', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_serverSettings'), // id 'activeHelper_liveHelp_serverSettings' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Not allowed countries', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Not allowed countries', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_restrictedCountries'), // id 'activeHelper_liveHelp_restrictedCountries' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('About', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('About', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activeHelper_liveHelp_about'), // id 'activeHelper_liveHelp_about' // callback ); add_submenu_page( strtolower('activeHelper_liveHelp'), // parent __('Uninstall', 'activehelper_livehelp') . ' ‹ ActiveHelper LiveHelp', // page title __('Uninstall', 'activehelper_livehelp'), // menu title 'manage_options', // type strtolower('activehelper_livehelp_uninstall'), // id 'activehelper_livehelp_uninstall' // callback ); } function activeHelper_liveHelp_welcomePost() { wp_enqueue_style('dashboard'); } function activeHelper_liveHelp_welcome() { global $wpdb, $activeHelper_liveHelp; $domains = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_domains "); $agents = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_users "); $departments = $wpdb->get_var(" SELECT COUNT(*) FROM ( SELECT department FROM {$wpdb->prefix}livehelp_users GROUP BY department ) AS t "); $chats = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_sessions "); $chats_today = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_sessions AS ls WHERE DATE_FORMAT(ls.datetime, '%m/%d/%Y') = DATE_FORMAT(now(), '%m/%d/%Y') "); $visitors_today = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_requests AS ls WHERE DATE_FORMAT(ls.datetime, '%m/%d/%Y') = DATE_FORMAT(now(), '%m/%d/%Y') "); $latest_aggent = $wpdb->get_var(" SELECT username FROM {$wpdb->prefix}livehelp_users ORDER BY refresh DESC LIMIT 1 "); $oldest_aggent = $wpdb->get_var(" SELECT username FROM {$wpdb->prefix}livehelp_users ORDER BY refresh ASC LIMIT 1 "); $fail_chats = $wpdb->get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_messages AS lm RIGHT JOIN {$wpdb->prefix}livehelp_sessions AS ls ON (ls.id = lm.session) WHERE lm.username IS NULL AND lm.message IS NULL "); $avg_chat_rating = $wpdb->get_var(" SELECT IFNULL(AVG(rating), 0) FROM {$wpdb->prefix}livehelp_sessions WHERE rating != -1 "); $rowsdomains = $wpdb->get_results(" SELECT jld.name, COUNT(jls.id) AS value FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_domains AS jld WHERE jls.id_domain = jld.id_domain GROUP BY jls.id_domain LIMIT 5 ", ARRAY_A); $rowsagents = $wpdb->get_results(" SELECT jlu.username AS name, COUNT(jls.id) AS value FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_users AS jlu WHERE jls.id_user = jlu.id GROUP BY jlu.username LIMIT 5 ", ARRAY_A); $rowsagents_rating = $wpdb->get_results(" SELECT jlu.username AS name, IFNULL(AVG(IF(jls.rating = -1, NULL, jls.rating)), 0) AS value FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_users AS jlu WHERE jls.id_user = jlu.id GROUP BY jlu.username LIMIT 5 ", ARRAY_A); $rowuser_avg = $wpdb->get_results(" SELECT CONCAT(jls.username, ' (', jls.email, ')') AS name, COUNT(jls.id) AS value FROM {$wpdb->prefix}livehelp_sessions AS jls GROUP BY jls.email LIMIT 5 ", ARRAY_A); $rowsagents_duration = $wpdb->get_results(" SELECT t1.name, SEC_TO_TIME(SUM(TIME_TO_SEC(Time))) AS value FROM ( SELECT b.username AS name, TIMEDIFF(c.refresh, c.datetime) AS Time FROM {$wpdb->prefix}livehelp_users AS b, {$wpdb->prefix}livehelp_sessions AS c WHERE c.id_user = b.id AND DATE_FORMAT(c.datetime,'%Y%m%d') >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND DATE_FORMAT(c.datetime,'%Y%m%d') <= CURDATE() GROUP BY c.id ORDER BY CONCAT(b.firstname, ' ', b.lastname) ) AS t1 GROUP BY t1.name LIMIT 5 ", ARRAY_A); echo '