diff --git a/app/xml_cdr/xml_cdr_extension_summary.php b/app/xml_cdr/xml_cdr_extension_summary.php index b1816870a9..cb60fa18b4 100644 --- a/app/xml_cdr/xml_cdr_extension_summary.php +++ b/app/xml_cdr/xml_cdr_extension_summary.php @@ -60,9 +60,46 @@ $cdr->start_stamp_begin = $start_stamp_begin; $cdr->start_stamp_end = $start_stamp_end; $cdr->include_internal = $include_internal; - $cdr->quick_select = $quick_select; $summary = $cdr->user_summary(); - $extensions = $cdr->extensions; + +//set the http header + if ($_REQUEST['type'] == "csv") { + + //set the headers + header('Content-type: application/octet-binary'); + header('Content-Disposition: attachment; filename=cdr-statistics.csv'); + + //show the column names on the first line + $z = 0; + foreach($summary[1] as $key => $val) { + if ($z == 0) { + echo '"'.$key.'"'; + } + else { + echo ',"'.$key.'"'; + } + $z++; + } + echo "\n"; + + //add the values to the csv + $x = 0; + foreach($summary as $users) { + $z = 0; + foreach($users as $key => $val) { + if ($z == 0) { + echo '"'.$summary[$x][$key].'"'; + } + else { + echo ',"'.$summary[$x][$key].'"'; + } + $z++; + } + echo "\n"; + $x++; + } + exit; + } //page title and description echo "\n"; @@ -184,43 +221,23 @@ $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; - if (isset($extensions)) foreach ($extensions as $extension => $row) { - $seconds['inbound'] = $summary[$extension]['inbound']['seconds']; - $seconds['outbound'] = $summary[$extension]['outbound']['seconds']; - if ($summary[$extension]['missed'] == null) { - $summary[$extension]['missed'] = 0; - } - if ($summary[$extension]['no_answer'] == null) { - $summary[$extension]['no_answer'] = 0; - } - if ($summary[$extension]['busy'] == null) { - $summary[$extension]['busy'] = 0; - } - - //missed - $missed = $summary[$extension]['missed']; - - //volume - $volume = $summary[$extension]['inbound']['count'] + $summary[$extension]['outbound']['count']; - - //average length of call - $summary[$extension]['aloc'] = $volume==0 ? 0 : ($seconds['inbound'] + $seconds['outbound']) / ($volume - $missed); - + if (isset($summary)) foreach ($summary as $key => $row) { $tr_link = "xhref='xml_cdr.php?'"; echo "\n"; if ($_GET['showall'] && permission_exists('xml_cdr_all')) { - echo " \n"; + echo " \n"; } - echo " \n"; + echo " \n"; echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + //echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo " \n"; echo "\n"; $c = ($c==0) ? 1 : 0;
".$_SESSION['domains'][$row['domain_uuid']]['domain_name']."".$row['domain_name']."".$extension."".$row['extension']."".$row['number_alias']." ".$summary[$extension]['missed']." ".$summary[$extension]['no_answer']." ".$summary[$extension]['busy']." ".gmdate("H:i:s",$summary[$extension]['aloc'])."  ".(($summary[$extension]['inbound']['count'] != '') ? $summary[$extension]['inbound']['count'] : "0")."".(($seconds['inbound'] != '') ? gmdate("G:i:s", $seconds['inbound']) : '0:00:00')." ".(($summary[$extension]['outbound']['count'] != '') ? $summary[$extension]['outbound']['count'] : "0")."".(($seconds['outbound'] != '') ? gmdate("G:i:s", $seconds['outbound']) : '0:00:00')."".$row['answered']." ".$row['missed']." ".$row['no_answer']." ".$row['busy']." ".gmdate("H:i:s",$row['aloc'])."  ". $row['inbound_calls'] ."".(($row['inbound_duration'] != '0') ? gmdate("G:i:s", $row['inbound_duration']) : '0:00:00')." ".(($row['outbound_calls'] != '') ? $row['outbound_calls'] : "0")."".(($row['outbound_duration'] != '') ? gmdate("G:i:s", $row['outbound_duration']) : '0:00:00')."".$row['description']."