diff --git a/lhc_web/design/defaulttheme/tpl/lhstatistic/tabs/chatsstatistic.tpl.php b/lhc_web/design/defaulttheme/tpl/lhstatistic/tabs/chatsstatistic.tpl.php index 442833feaf..bb4b8fe6c0 100644 --- a/lhc_web/design/defaulttheme/tpl/lhstatistic/tabs/chatsstatistic.tpl.php +++ b/lhc_web/design/defaulttheme/tpl/lhstatistic/tabs/chatsstatistic.tpl.php @@ -998,7 +998,8 @@ function drawChartPerMonth() { chart_type) ? $input->chart_type : array())) : ?>
-
+
+file_download
diff --git a/lhc_web/lib/core/lhchat/lhchatstatistic.php b/lhc_web/lib/core/lhchat/lhchatstatistic.php index 841c466463..1c6be64874 100644 --- a/lhc_web/lib/core/lhchat/lhchatstatistic.php +++ b/lhc_web/lib/core/lhchat/lhchatstatistic.php @@ -3857,15 +3857,34 @@ public static function exportCSV($statistic, $type) { (is_object($obUser) ? $obUser->name_official : $value['user_id']) ]); } - } else if ($type == 'nickgroupingdatenick') { - $counter = 0; - foreach ($statistic['nickgroupingdatenick']['labels'] as $date => $value) { - if ($counter == 0) { - fputcsv($fp,array_merge(array('Date'),$value['nick'])); + } else if ($type == 'cs_nickgroupingdatenick' || $type == 'nickgroupingdatenick') { + + $groupField = 'nickgroupingdatenick'; + + $dates = ['Entity']; + foreach ($statistic[$groupField]['labels'] as $date => $value) { + $dates[] = date('Y-m-d H:i:s',$date); + } + + fputcsv($fp, array_merge($dates,['Total'])); + $agents = []; + foreach ($statistic[$groupField]['labels'] as $date => $value) { + $agents = array_unique(array_merge($agents,(isset($value['nick']) ? $value['nick'] : []))); + } + + foreach ($agents as $agent) { + $agentRow = []; + foreach ($statistic[$groupField]['labels'] as $date => $value) { + $index = array_search($agent, (isset($value['nick']) ? $value['nick'] : [])); + if ($index !== false) { + $agentRow[] = $value['data'][$index]; + } else { + $agentRow[] = 0; + } } - fputcsv($fp,array_merge(array(date('Y-m-d H:i:s',$date)),$value['data'])); - $counter++; + fputcsv($fp,array_merge([(string)json_decode($agent)],$agentRow,[array_sum($agentRow)])); } + } else if ($type == 'unanswered') { fputcsv($fp, ['Date','Chats number']); foreach ($statistic['numberOfChatsPerMonth'] as $date => $value) {