get_var(" SELECT COUNT(*) FROM {$wpdb->prefix}livehelp_domains "); $activeHelper_liveHelp['is_installed'] = $is_installed !== null; if (!$activeHelper_liveHelp['is_installed']) return activeHelper_liveHelp_install(); // Run an SQL to update Database $plugin_data = get_plugin_data( __FILE__ ); // Plugin version $plugin_version = $plugin_data['Version']; // Database version $database_version = $wpdb->get_var(" SELECT value FROM {$wpdb->prefix}livehelp_settings WHERE name = 'database_version' AND id_domain = '0' LIMIT 1 "); if (empty($database_version)) { $database_version = $plugin_version; $wpdb->query(" INSERT INTO {$wpdb->prefix}livehelp_settings (name, value, id_domain) VALUES ('database_version', '" . $plugin_version . "', 0); "); } if ( $plugin_version != $database_version ) { $new_database_version = activeHelper_liveHelp_updateDatabase($database_version, $plugin_version); $wpdb->query(" UPDATE {$wpdb->prefix}livehelp_settings SET value = '" . $new_database_version . "' WHERE name = 'database_version' AND id_domain = '0' LIMIT 1 "); } } 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 '

LiveHelp

' . __('Welcome to ActiveHelper LiveHelp', 'activehelper_livehelp') . '

' . __('Thank you for choosing ActiveHelper LiveHelp as your Live Chat solution. This screen will give you a quick overview of your LiveHelp statistics. The links on the left-hand side of this screen allow you to a LiveHelp special reports.', 'activehelper_livehelp') . '


' . __('General stats', 'activehelper_livehelp') . '

' . __('Domains', 'activehelper_livehelp') . ' ' . $domains . '
' . __('Departments', 'activehelper_livehelp') . ' ' . $departments . '
' . __('Chats today', 'activehelper_livehelp') . ' ' . $chats_today . '
' . __('Latest aggent connected', 'activehelper_livehelp') . ' ' . (!empty($latest_aggent) ? $latest_aggent : __('No records found', 'activehelper_livehelp')) . '
' . __('Failed chats', 'activehelper_livehelp') . ' ' . $fail_chats . '
' . __('Agents', 'activehelper_livehelp') . ' ' . $agents . '
' . __('Chats', 'activehelper_livehelp') . ' ' . $chats . '
' . __('Visitors today', 'activehelper_livehelp') . ' ' . $visitors_today . '
' . __('Oldest aggent connected', 'activehelper_livehelp') . ' ' . (!empty($oldest_aggent) ? $oldest_aggent : __('No records found', 'activehelper_livehelp')) . '
' . __('AVG chat rating', 'activehelper_livehelp') . ' ' . $avg_chat_rating . '

' . __('Top 5 most active domains', 'activehelper_livehelp') . '

' . __('Domain', 'activehelper_livehelp') . '

' . __('Chats', 'activehelper_livehelp') . '

'; if (empty($rowsdomains)) echo '
' . __('No records found', 'activehelper_livehelp') . '
'; else foreach ($rowsdomains as $row) echo '
' . $row['name'] . ' ' . $row['value'] . '
'; echo '

' . __('Top 5 avg agents raiting', 'activehelper_livehelp') . '

' . __('Username', 'activehelper_livehelp') . '

' . __('AVG raiting', 'activehelper_livehelp') . '

'; if (empty($rowsagents_rating)) echo '
' . __('No records found', 'activehelper_livehelp') . '
'; else foreach ($rowsagents_rating as $row) echo '
' . $row['name'] . ' ' . $row['value'] . '
'; echo '

' . __('Top 5 most active users', 'activehelper_livehelp') . '

' . __('Username', 'activehelper_livehelp') . '

' . __('Chats', 'activehelper_livehelp') . '

'; if (empty($rowuser_avg)) echo '
' . __('No records found', 'activehelper_livehelp') . '
'; else foreach ($rowuser_avg as $row) echo '
' . $row['name'] . ' ' . $row['value'] . '
'; echo '

' . __('Top 5 most active agents by duration', 'activehelper_livehelp') . '

' . __('Username', 'activehelper_livehelp') . '

' . __('Duration', 'activehelper_livehelp') . '

'; if (empty($rowsagents_duration)) echo '
' . __('No records found', 'activehelper_livehelp') . '
'; else foreach ($rowsagents_duration as $row) echo '
' . $row['name'] . ' ' . $row['value'] . '
'; echo '

' . __('Top 5 most active agents', 'activehelper_livehelp') . '

' . __('Username', 'activehelper_livehelp') . '

' . __('Duration', 'activehelper_livehelp') . '

'; if (empty($rowsagents)) echo '
' . __('No records found', 'activehelper_livehelp') . '
'; else foreach ($rowsagents as $row) echo '
' . $row['name'] . ' ' . $row['value'] . '
'; echo '
'; } function activeHelper_liveHelp_aboutPost() { wp_enqueue_style('dashboard'); } function activeHelper_liveHelp_about() { echo '

LiveHelp » ' . __('About', 'activehelper_livehelp') . '

' . __('About', 'activehelper_livehelp') . '

' . __('LiveHelp support system', 'activehelper_livehelp') . '

' . __('Info', 'activehelper_livehelp') . '

' . __('Name', 'activehelper_livehelp') . ' ' . __('LiveHelp system for WordPress', 'activehelper_livehelp') . '
' . __('Version', 'activehelper_livehelp') . ' ' . __('2.9.5', 'activehelper_livehelp') . '
' . __('Check for Update', 'activehelper_livehelp') . ' ' . __('http://www.activehelper.com/', 'activehelper_livehelp') . '
' . __('Help', 'activehelper_livehelp') . ' ' . __('http://www.activehelper.com/faq.html', 'activehelper_livehelp') . '
' . __('Support Forum', 'activehelper_livehelp') . ' ' . __('http://www.activehelper.com/forum/wordpress-extension', 'activehelper_livehelp') . '
' . __('Follow at Twitter', 'activehelper_livehelp') . ' ' . __('https://twitter.com/activehelper', 'activehelper_livehelp') . '
' . __('License', 'activehelper_livehelp') . ' ' . __('GNU/GPL v2 - http://www.activehelper.com/license.txt', 'activehelper_livehelp') . '
' . __('Copyright', 'activehelper_livehelp') . ' ' . __('Copyright © 2010 - 2012. Activehelper - 2010 - 2012 - All Rights Reserved', 'activehelper_livehelp') . '
'; } function activehelper_livehelp_uninstallPost() { // :( if (isset($_GET['uninstall'])) activeHelper_liveHelp_libUninstall(); } function activehelper_livehelp_uninstall() { echo '

LiveHelp » ' . __('Uninstall', 'activehelper_livehelp') . '

' . __('Are you sure you want to uninstall the ActiveHelper LiveHelp plugin?', 'activehelper_livehelp') . '

' . __('To deactivate this plugin, go to Plugins | To uninstall this plugin, click on the link below', 'activehelper_livehelp') . '

 

' . __('Delete all files and database tables related with this plugin permanently') . '

'; } function activehelper_livehelp_plugin_backup() { $f = dirname( __FILE__ ); $t = dirname( dirname( __FILE__ ) ) . '/activehelper-livehelp-backup'; @mkdir( $t ); activeHelper_liveHelp_filesDuplicate( $f . '/server/domains', $t . '/domains' ); activeHelper_liveHelp_filesDuplicate( $f . '/server/import/config_database.php', $t . '/config_database.php' ); activeHelper_liveHelp_filesDuplicate( $f . '/server/import/constants.php', $t . '/constants.php' ); activeHelper_liveHelp_filesDuplicate( $f . '/server/import/jlhconst.php', $t . '/jlhconst.php' ); } function activehelper_livehelp_plugin_recover() { $f = dirname( dirname( __FILE__ ) ) . '/activehelper-livehelp-backup'; $t = dirname( __FILE__ ) . ''; activeHelper_liveHelp_filesDuplicate( $f . '/domains', $t . '/server/domains' ); activeHelper_liveHelp_filesDuplicate( $f . '/config_database.php', $t . '/server/import/config_database.php' ); activeHelper_liveHelp_filesDuplicate( $f . '/constants.php', $t . '/server/import/constants.php' ); activeHelper_liveHelp_filesDuplicate( $f . '/jlhconst.php', $t . '/server/import/jlhconst.php' ); activeHelper_liveHelp_filesDelete( $f ); } add_filter( 'upgrader_pre_install', 'activehelper_livehelp_plugin_backup', 10, 2 ); add_filter( 'upgrader_post_install', 'activehelper_livehelp_plugin_recover', 10, 2 );