'activeHelper_liveHelp_failedChatsList' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); return $actions['list'](); } function activeHelper_liveHelp_failedChatsPost() { $actions = array( 'export' => 'activeHelper_liveHelp_failedChatsExportPost', 'list' => 'activeHelper_liveHelp_failedChatsListPost' ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); if (empty($_REQUEST['action'])) return $actions['list'](); } function activeHelper_liveHelp_failedChatsExportPost() { 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)); $failedChatsList = $wpdb->get_results(" SELECT jls.id, CONCAT(jlu.firstname, ' ', jlu.lastname) AS name, jld.name AS domain, jls.username AS username, jls.email AS email, jls.datetime FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_domains AS jld, {$wpdb->prefix}livehelp_users AS jlu 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 AND jls.id NOT INT ( SELECT jlm.session FROM {$wpdb->prefix}livehelp_messages AS jlm WHERE DATE_FORMAT(jlm.datetime, '%Y%m%d') >= DATE_FORMAT('" . date("Y-m-d", $timeStart) . "', '%Y%m%d') AND DATE_FORMAT(jlm.datetime, '%Y%m%d') <= DATE_FORMAT('" . date("Y-m-d", $timeEnd) . "', '%Y%m%d') GROUP BY jlm.session ) ORDER BY 5, 2, 3 ", ARRAY_A); $export = '"ID","Agent","Domain name","Visitor name","Visitor email","Date"'; if (!empty($failedChatsList)) foreach ($failedChatsList as $failedChats) { $export .= "\n" . '"' . $failedChats['session'] . '","' . $failedChats['name'] . '","' . $failedChats['domain'] . '","' . $failedChats['visitor'] . '","' . $failedChats['email'] . '","' . $failedChats['date'] . '"'; } header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=LiveHelp_FailedChats_" . 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_failedChatsListPost() { 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_failedChatsList() { 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)); $failedChatsList = $wpdb->get_results(" SELECT jls.id, CONCAT(jlu.firstname, ' ', jlu.lastname) AS name, jld.name AS domain, jls.username AS username, jls.email AS email, jls.datetime FROM {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_domains AS jld, {$wpdb->prefix}livehelp_users AS jlu 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 AND jls.id NOT INT ( SELECT jlm.session FROM {$wpdb->prefix}livehelp_messages AS jlm WHERE DATE_FORMAT(jlm.datetime, '%Y%m%d') >= DATE_FORMAT('" . date("Y-m-d", $timeStart) . "', '%Y%m%d') AND DATE_FORMAT(jlm.datetime, '%Y%m%d') <= DATE_FORMAT('" . date("Y-m-d", $timeEnd) . "', '%Y%m%d') GROUP BY jlm.session ) ORDER BY 5, 2, 3 ", ARRAY_A); echo '

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

'; echo '
'; if (empty($failedChatsList)) echo ' '; else { $alternate = false; foreach ($failedChatsList as $failedChats) { echo ' '; $alternate = !$alternate; } } echo '
' . __('ID', 'activehelper_livehelp') . ' ' . __('Agent', 'activehelper_livehelp') . ' ' . __('Domain name', 'activehelper_livehelp') . ' ' . __('Visitor name', 'activehelper_livehelp') . ' ' . __('Visitor email', 'activehelper_livehelp') . ' ' . __('Date', 'activehelper_livehelp') . '
' . __('ID', 'activehelper_livehelp') . ' ' . __('Agent', 'activehelper_livehelp') . ' ' . __('Domain name', 'activehelper_livehelp') . ' ' . __('Visitor name', 'activehelper_livehelp') . ' ' . __('Visitor email', 'activehelper_livehelp') . ' ' . __('Date', 'activehelper_livehelp') . '

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

' . $failedChats['session'] . ' ' . $failedChats['name'] . ' ' . $failedChats['domain'] . ' ' . $failedChats['username'] . ' ' . $failedChats['email'] . ' ' . $failedChats['date'] . '
'; }