'activeHelper_liveHelp_chatsByCountryList' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); return $actions['list'](); } function activeHelper_liveHelp_chatsByCountryPost() { $actions = array( 'export' => 'activeHelper_liveHelp_chatsByCountryExportPost', 'list' => 'activeHelper_liveHelp_chatsByCountryListPost' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); if (empty($_REQUEST['action'])) return $actions['list'](); } function activeHelper_liveHelp_chatsByCountryExportPost() { global $wpdb, $activeHelper_liveHelp; $timeEnd = !empty($_REQUEST['export_end_date']) ? strtotime((string) $_REQUEST['export_end_date']) : time(); $timeStart = !empty($_REQUEST['export_start_date']) ? strtotime((string) $_REQUEST['export_start_date']) : mktime(0, 0, 0, date("n", $timeEnd) - 1, date("j", $timeEnd), date("Y", $timeEnd)); $chatsByCountryList = $wpdb->get_results(" SELECT jlr.country, COUNT(*) AS chats , IFNULL(AVG(IF(jls.rating = -1, NULL, jls.rating)), 0) AS rating FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_requests AS jlr WHERE DATE_FORMAT(jls.datetime, '%Y%m%d') >= DATE_FORMAT('" . date("Y-m-d", $timeStart) . "', '%Y%m%d') AND DATE_FORMAT(jls.datetime, '%Y%m%d') <= DATE_FORMAT('" . date("Y-m-d", $timeEnd) . "', '%Y%m%d') AND jls.request = jlr.id GROUP BY jlr.country ORDER BY 2 DESC ", ARRAY_A); $export = '"Country","Chats","Raiting"'; if (!empty($chatsByCountryList)) foreach ($chatsByCountryList as $chatsByCountry) { $export .= "\n" . '"' . $chatsByCountry['country'] . '","' . $chatsByCountry['chats'] . '","' . $chatsByCountry['rating'] . '"'; } header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=LiveHelp_ChatsByCountry_" . date("Y-m-d", $timeStart) . "~" . date("Y-m-d", $timeEnd) . ".csv"); header("Content-Type: text/csv; text/comma-separated-values"); header("Content-Transfer-Encoding: binary"); echo $export; exit(); } function activeHelper_liveHelp_chatsByCountryListPost() { global $wpdb, $activeHelper_liveHelp; wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-datepicker', $activeHelper_liveHelp['baseUrl'] . '/scripts/jquery.ui.datepicker.min.js', array('jquery', 'jquery-ui-core') ); wp_enqueue_style('jquery.ui.theme', $activeHelper_liveHelp['baseUrl'] . '/scripts/smoothness/jquery-ui-1.8.16.custom.css'); } function activeHelper_liveHelp_chatsByCountryList() { global $wpdb, $activeHelper_liveHelp; $timeEnd = !empty($_REQUEST['export_end_date']) ? strtotime((string) $_REQUEST['export_end_date']) : time(); $timeStart = !empty($_REQUEST['export_start_date']) ? strtotime((string) $_REQUEST['export_start_date']) : mktime(0, 0, 0, date("n", $timeEnd) - 1, date("j", $timeEnd), date("Y", $timeEnd)); $chatsByCountryList = $wpdb->get_results(" SELECT jlr.country, COUNT(*) AS chats , IFNULL(AVG(IF(jls.rating = -1, NULL, jls.rating)), 0) AS rating FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_requests AS jlr WHERE DATE_FORMAT(jls.datetime, '%Y%m%d') >= DATE_FORMAT('" . date("Y-m-d", $timeStart) . "', '%Y%m%d') AND DATE_FORMAT(jls.datetime, '%Y%m%d') <= DATE_FORMAT('" . date("Y-m-d", $timeEnd) . "', '%Y%m%d') AND jls.request = jlr.id GROUP BY jlr.country ORDER BY 2 DESC ", ARRAY_A); echo '

LiveHelp ยป ' . __('Chats by country', 'activehelper_livehelp') . ' ' . __('export to CSV', 'activehelper_livehelp') . '

'; echo '
'; if (empty($chatsByCountryList)) echo ' '; else { $alternate = false; foreach ($chatsByCountryList as $chatsByCountry) { echo ' '; $alternate = !$alternate; } } echo '
' . __('Country', 'activehelper_livehelp') . ' ' . __('Chats', 'activehelper_livehelp') . ' ' . __('Raiting', 'activehelper_livehelp') . '
' . __('Department', 'activehelper_livehelp') . ' ' . __('Chats', 'activehelper_livehelp') . ' ' . __('Raiting', 'activehelper_livehelp') . '

' . sprintf(__('No %s found.', 'activehelper_livehelp'), __('chats', 'activehelper_livehelp')) . '

' . $chatsByCountry['country'] . ' ' . $chatsByCountry['chats'] . ' ' . $chatsByCountry['rating'] . '
'; }