'activeHelper_liveHelp_monthlyChatsList' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); return $actions['list'](); } function activeHelper_liveHelp_monthlyChatsPost() { $actions = array( 'export' => 'activeHelper_liveHelp_monthlyChatsExportPost', 'list' => 'activeHelper_liveHelp_monthlyChatsListPost' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); if (empty($_REQUEST['action'])) return $actions['list'](); } function activeHelper_liveHelp_monthlyChatsExportPost() { 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)); $monthlyChatsList = $wpdb->get_results(" SELECT CONCAT(jlu.firstname, ' ', jlu.lastname) AS name, jld.name AS domain, count(jls.id) AS chats FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_users AS jlu, {$wpdb->prefix}livehelp_domains AS jld 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_user = jlu.id AND jls.id_domain =jld.id_domain GROUP BY jls.id_domain, jlu.username, CONCAT(jlu.firstname, ' ', jlu.lastname) ORDER BY CONCAT(jlu.firstname, ' ', jlu.lastname) ", ARRAY_A); $export = '"Agent","Domain name","Chats"'; if (!empty($monthlyChatsList)) foreach ($monthlyChatsList as $monthlyChats) { $export .= "\n" . '"' . $monthlyChats['name'] . '","' . $monthlyChats['domain'] . '","' . $monthlyChats['chats'] . '"'; } header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=LiveHelp_MonthlyChats_" . 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_monthlyChatsListPost() { 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_monthlyChatsList() { 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)); $monthlyChatsList = $wpdb->get_results(" SELECT CONCAT(jlu.firstname, ' ', jlu.lastname) AS name, jld.name AS domain, count(jls.id) AS chats FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_users AS jlu, {$wpdb->prefix}livehelp_domains AS jld 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_user = jlu.id AND jls.id_domain = jld.id_domain GROUP BY jls.id_domain, jlu.username, CONCAT(jlu.firstname, ' ', jlu.lastname) ORDER BY CONCAT(jlu.firstname, ' ', jlu.lastname) ", ARRAY_A); echo '

LiveHelp ยป ' . __('Monthly chats', 'activehelper_livehelp') . ' ' . __('export to CSV', 'activehelper_livehelp') . '

'; echo '
'; if (empty($monthlyChatsList)) echo ' '; else { $alternate = false; foreach ($monthlyChatsList as $monthlyChats) { echo ' '; $alternate = !$alternate; } } echo '
' . __('Agent', 'activehelper_livehelp') . ' ' . __('Domain name', 'activehelper_livehelp') . ' ' . __('Chats', 'activehelper_livehelp') . '
' . __('Agent', 'activehelper_livehelp') . ' ' . __('Domain name', 'activehelper_livehelp') . ' ' . __('Chats', 'activehelper_livehelp') . '

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

' . $monthlyChats['name'] . ' ' . $monthlyChats['domain'] . ' ' . $monthlyChats['chats'] . '
'; }