'activeHelper_liveHelp_chatsByKeywordList', // 'view' => 'activeHelper_liveHelp_timeByChatView', // use external function, since it already exists // 'email' => 'activeHelper_liveHelp_timeByChatEmail' // use external function, since it already exists ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); return $actions['list'](); } function activeHelper_liveHelp_chatsByKeywordPost() { $actions = array( 'list' => 'activeHelper_liveHelp_chatsByKeywordListPost', 'export' => 'activeHelper_liveHelp_chatsByKeywordExportPost', // 'view' => 'activeHelper_liveHelp_timeByChatViewPost', // use external function, since it already exists // 'viewExport' => 'activeHelper_liveHelp_timeByChatViewExportPost', // use external function, since it already exists // 'email' => 'activeHelper_liveHelp_timeByChatEmailPost' // use external function, since it already exists ); if (!empty($_REQUEST['action']) && isset($actions[$_REQUEST['action']])) return $actions[$_REQUEST['action']](); if (empty($_REQUEST['action'])) return $actions['list'](); } function activeHelper_liveHelp_chatsByKeywordExportPost() { global $wpdb, $activeHelper_liveHelp; $keyword = !empty($_REQUEST['export_keyword']) ? htmlspecialchars((string) $_REQUEST['export_keyword']) : ''; $chatsByKeywordList = $wpdb->get_results(" SELECT jls.id AS session, CONCAT(jlu.firstname, ' ', jlu.lastname) AS name, jld.name AS domain, jls.username AS visitor, jls.email AS email, if(jls.rating = -1, '" . __('Not rate', 'activehelper_livehelp') . "', jls.rating) AS rating, (TIMEDIFF(jls.refresh, jls.datetime)) AS time, DATE_FORMAT(jls.datetime, '%m/%d/%Y') AS date FROM {$wpdb->prefix}livehelp_messages AS jlm, {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_users AS jlu, {$wpdb->prefix}livehelp_domains AS jld WHERE LOWER(jlm.message) LIKE LOWER('%" . $keyword . "%') AND jls.id = jlm.session GROUP BY 1 DESC ", ARRAY_A); $export = '"ID","Agent","Domain name","Visitor name","Visitor email","Raiting","Duration","Date"'; if (!empty($chatsByKeywordList)) foreach ($chatsByKeywordList as $chatsByKeyword) { $export .= "\n" . '"' . $chatsByKeyword['session'] . '","' . $chatsByKeyword['name'] . '","' . $chatsByKeyword['domain'] . '","' . $chatsByKeyword['visitor'] . '","' . $chatsByKeyword['email'] . '","' . $chatsByKeyword['rating'] . '","' . $chatsByKeyword['time'] . '","' . $chatsByKeyword['date'] . '"'; } header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=LiveHelp_ChatsByKeyword_" . urlencode($keyword) . ".csv"); header("Content-Type: text/csv; text/comma-separated-values"); header("Content-Transfer-Encoding: binary"); echo $export; exit(); } function activeHelper_liveHelp_chatsByKeywordListPost() { 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_chatsByKeywordList() { global $wpdb, $activeHelper_liveHelp; $keyword = !empty($_REQUEST['export_keyword']) ? htmlspecialchars((string) $_REQUEST['export_keyword']) : ''; $chatsByKeywordList = $wpdb->get_results(" SELECT jls.id AS session, CONCAT(jlu.firstname, ' ', jlu.lastname) AS name, jld.name AS domain, jls.username AS visitor, jls.email AS email, if(jls.rating = -1, '" . __('Not rate', 'activehelper_livehelp') . "', jls.rating) AS rating, (TIMEDIFF(jls.refresh, jls.datetime)) AS time, DATE_FORMAT(jls.datetime, '%m/%d/%Y') AS date FROM {$wpdb->prefix}livehelp_messages AS jlm, {$wpdb->prefix}livehelp_sessions AS jls, {$wpdb->prefix}livehelp_users AS jlu, {$wpdb->prefix}livehelp_domains AS jld WHERE LOWER(jlm.message) LIKE LOWER('%" . $keyword . "%') AND jls.id = jlm.session GROUP BY 1 DESC ", ARRAY_A); echo '

LiveHelp ยป ' . __('Time by chat', 'activehelper_livehelp') . ' ' . __('export to CSV', 'activehelper_livehelp') . '

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

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

' . $chatsByKeyword['session'] . ' ' . $chatsByKeyword['name'] . ' ' . $chatsByKeyword['domain'] . ' ' . $chatsByKeyword['visitor'] . ' ' . $chatsByKeyword['email'] . ' ' . $chatsByKeyword['rating'] . ' ' . $chatsByKeyword['time'] . ' ' . $chatsByKeyword['date'] . '
'; }