'activeHelper_liveHelp_chatsByDepartmentList' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); return $actions['list'](); } function activeHelper_liveHelp_chatsByDepartmentPost() { $actions = array( 'export' => 'activeHelper_liveHelp_chatsByDepartmentExportPost', 'list' => 'activeHelper_liveHelp_chatsByDepartmentListPost' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); if (empty($_REQUEST['action'])) return $actions['list'](); } function activeHelper_liveHelp_chatsByDepartmentExportPost() { 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)); $chatsByDepartmentList = $wpdb->get_results(" SELECT jls.department, jld.name AS domain, IFNULL(AVG(IF(jls.rating = -1, NULL, jls.rating)), 0) AS rating, COUNT(*) AS chats FROM {$wpdb->prefix}livehelp_domains AS jld, {$wpdb->prefix}livehelp_sessions AS jls 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.id_domain = jld.id_domain GROUP BY jls.department ORDER BY jls.department ", ARRAY_A); $export = '"Department","Domain name","Raiting","Chats"'; if (!empty($chatsByDepartmentList)) foreach ($chatsByDepartmentList as $chatsByDepartment) { $export .= "\n" . '"' . $chatsByDepartment['department'] . '","' . $chatsByDepartment['domain'] . '","' . $chatsByDepartment['rating'] . '","' . $chatsByDepartment['chats'] . '"'; } header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=LiveHelp_ChatsByDepartment_" . 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_chatsByDepartmentListPost() { 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_chatsByDepartmentList() { 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)); $chatsByDepartmentList = $wpdb->get_results(" SELECT jls.department, jld.name AS domain, IFNULL(AVG(IF(jls.rating = -1, NULL, jls.rating)), 0) AS rating, COUNT(*) AS chats FROM {$wpdb->prefix}livehelp_domains AS jld, {$wpdb->prefix}livehelp_sessions AS jls 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.id_domain = jld.id_domain GROUP BY jls.department ORDER BY jls.department ", ARRAY_A); echo '

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

'; echo '
'; if (empty($chatsByDepartmentList)) echo ' '; else { $alternate = false; foreach ($chatsByDepartmentList as $chatsByDepartment) { echo ' '; $alternate = !$alternate; } } echo '
' . __('Department', 'activehelper_livehelp') . ' ' . __('Domain name', 'activehelper_livehelp') . ' ' . __('Raiting', 'activehelper_livehelp') . ' ' . __('Chats', 'activehelper_livehelp') . '
' . __('Department', 'activehelper_livehelp') . ' ' . __('Domain name', 'activehelper_livehelp') . ' ' . __('Raiting', 'activehelper_livehelp') . ' ' . __('Chats', 'activehelper_livehelp') . '

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

' . $chatsByDepartment['department'] . ' ' . $chatsByDepartment['domain'] . ' ' . $chatsByDepartment['rating'] . ' ' . $chatsByDepartment['chats'] . '
'; }