From befc947b8da2d907ad44a679972dfab3b7046dca Mon Sep 17 00:00:00 2001 From: Digital Daz Date: Wed, 29 Apr 2015 20:45:32 +0000 Subject: [PATCH] Slight change to correct sql queries for times, thanks Nate. --- app/xml_cdr/xml_cdr_extension_summary.php | 694 +++++++++++----------- 1 file changed, 347 insertions(+), 347 deletions(-) diff --git a/app/xml_cdr/xml_cdr_extension_summary.php b/app/xml_cdr/xml_cdr_extension_summary.php index bacd30b3a3..eccf4d5173 100644 --- a/app/xml_cdr/xml_cdr_extension_summary.php +++ b/app/xml_cdr/xml_cdr_extension_summary.php @@ -1,347 +1,347 @@ - - Portions created by the Initial Developer are Copyright (C) 2008-2014 - the Initial Developer. All Rights Reserved. - - Contributor(s): - Mark J Crane - Luis Daniel Lucio Quiroz -*/ - -require_once "root.php"; -require_once "resources/require.php"; - -//check permisisions - require_once "resources/check_auth.php"; - if (permission_exists('xml_cdr_view')) { - //access granted - } - else { - echo "access denied"; - exit; - } - -//add multi-lingual support - $language = new text; - $text = $language->get(); - -//additional includes - require_once "resources/header.php"; - -//retrieve submitted data - $quick_select = check_str($_POST['quick_select']); - $start_stamp_begin = check_str($_POST['start_stamp_begin']); - $start_stamp_end = check_str($_POST['start_stamp_end']); - $include_internal = check_str($_POST['include_internal']); - - $quick_select = (sizeof($_POST) == 0) ? 1 : $quick_select; //set default - -//get current extension info - $sql = "select "; - $sql .= "domain_uuid, "; - $sql .= "extension_uuid, "; - $sql .= "extension, "; - $sql .= "number_alias, "; - $sql .= "description "; - $sql .= "from "; - $sql .= "v_extensions "; - $sql .= "where "; - $sql .= "enabled = 'true' "; - if (!($_GET['showall'] == 'true' && permission_exists('xml_cdr_all'))) { - $sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' "; - } - if (!(if_group("admin") || if_group("superadmin"))) { - if (count($_SESSION['user']['extension']) > 0) { - $sql .= "and ("; - $x = 0; - foreach($_SESSION['user']['extension'] as $row) { - if ($x > 0) { $sql .= "or "; } - $sql .= "extension = '".$row['user']."' "; - $x++; - } - $sql .= ")"; - } - else { - //used to hide any results when a user has not been assigned an extension - $sql .= "and extension = 'disabled' "; - } - } - - $sql .= "order by "; - $sql .= "extension asc"; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $result_count = count($result); - if ($result_count > 0) { - foreach($result as $row) { - $extensions[$row['extension']]['domain_uuid'] = $row['domain_uuid']; - $extensions[$row['extension']]['extension'] = $row['extension']; - $extensions[$row['extension']]['extension_uuid'] = $row['extension_uuid']; - $extensions[$row['extension']]['number_alias'] = $row['number_alias']; - $extensions[$row['extension']]['description'] = $row['description']; - } - } - unset ($sql, $prep_statement, $result, $row_count); - // create list of extensions for query below - foreach ($extensions as $extension => $blah) { - $ext_array[] = $extension; - } - $ext_list = implode("','", $ext_array); - -//calculate the summary data - $sql = "select "; - $sql .= "caller_id_number, "; - $sql .= "destination_number, "; - $sql .= "billsec, "; - $sql .= "hangup_cause "; - $sql .= "from v_xml_cdr "; - $sql .= "where "; - if (!($_GET['showall'] && permission_exists('xml_cdr_all'))) { - $sql .= " domain_uuid = '".$_SESSION['domain_uuid']."' and "; - } - $sql .= "( "; - $sql .= " caller_id_number in ('".$ext_list."') or "; - $sql .= " destination_number in ('".$ext_list."') "; - $sql .= ") "; - if (!$include_internal) { - $sql .= " and (direction = 'inbound' or direction = 'outbound') "; - } - if (strlen($start_stamp_begin) > 0 || strlen($start_stamp_end) > 0) { - unset($quick_select); - if (strlen($start_stamp_begin) > 0 && strlen($start_stamp_end) > 0) { - $sql .= " and start_stamp between '".$start_stamp_begin.":00.000' and '".$start_stamp_end.":59.999'"; - } - else { - if (strlen($start_stamp_begin) > 0) { $sql .= "and start_stamp >= '".$start_stamp_begin.":00.000' "; } - if (strlen($start_stamp_end) > 0) { $sql .= "and start_stamp <= '".$start_stamp_end.":59.999' "; } - } - } - else { - switch ($quick_select) { - case 1: $sql .= "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))."' "; break; //last 7 days - case 2: $sql .= "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))."' "; break; //last hour - case 3: $sql .= "and start_stamp >= '".date('Y-m-d')." "."00:00.000' "; break; //today - case 4: $sql .= "and start_stamp between '".date('Y-m-d',strtotime("-1 day"))." "."00:00.000' and '".date('Y-m-d',strtotime("-1 day"))." "."23:59.999' "; break; //yesterday - case 5: $sql .= "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00.000' "; break; //this week - case 6: $sql .= "and start_stamp >= '".date('Y-m-')."01 "."00:00.000' "; break; //this month - case 7: $sql .= "and start_stamp >= '".date('Y-')."01-01 "."00:00.000' "; break; //this year - } - } - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $result_count = count($result); - - if ($result_count > 0) { - foreach($result as $row) { - if ($summary[$row['destination_number']]['missed'] == null) { - $summary[$row['destination_number']]['missed'] = 0; - } - if (in_array($row['caller_id_number'], $ext_array)) { - $summary[$row['caller_id_number']]['outbound']['count']++; - $summary[$row['caller_id_number']]['outbound']['seconds'] += $row['billsec']; - } - if (in_array($row['destination_number'], $ext_array)) { - $summary[$row['destination_number']]['inbound']['count']++; - $summary[$row['destination_number']]['inbound']['seconds'] += $row['billsec']; - if ($row['billsec'] == "0") { - $summary[$row['destination_number']]['missed']++; - } - } - if ($row['hangup_cause'] == "NO_ANSWER") { - $summary[$row['destination_number']]['no_answer']++; - } - if ($row['hangup_cause'] == "USER_BUSY") { - $summary[$row['destination_number']]['busy']++; - } - } //end foreach - } //end if results - unset ($sql, $prep_statement, $result, $row_count); - -//page title and description - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['title-extension_summary']."

\n"; - echo "
"; - if (permission_exists('xml_cdr_all') && $_GET['showall'] != 'true') { - echo " \n"; - } - echo "
\n"; - echo "
\n"; - - if (permission_exists('xml_cdr_search')) { - echo "
\n"; - - echo "\n"; - echo " \n"; - - echo " "; - - echo " "; - - echo " "; - - echo " "; - - echo " "; - echo " "; - echo " "; - echo " "; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['label-preset']."\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['label-start_date_time']."\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['label-end_date_time']."\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['label-include_internal']."\n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
"; - echo " \n"; - echo " \n"; - echo "
"; - - echo "
"; - echo "

"; - } - -//show the results - echo "\n"; - 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"; - - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - foreach ($extensions as $extension => $ext) { - $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'] = ($seconds['inbound'] + $seconds['outbound']) / ($volume - $missed); - - $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"; - $c = ($c==0) ? 1 : 0; - } - - echo "
".$text['label-domain']."".$text['label-extension']."".$text['label-number_alias']."".$text['label-missed']."".$text['label-no_answer']."".$text['label-busy']."".$text['label-aloc']."".$text['label-inbound_calls']."".$text['label-inbound_duration']."".$text['label-outbound_calls']."".$text['label-outbound_duration']."".$text['label-description']."
".$_SESSION['domains'][$ext['domain_uuid']]['domain_name']."".$extension."".$ext['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')."".$ext['description']." 
"; - echo "

"; - -//show the footer - require_once "resources/footer.php"; - -?> + + Portions created by the Initial Developer are Copyright (C) 2008-2014 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + Luis Daniel Lucio Quiroz +*/ + +require_once "root.php"; +require_once "resources/require.php"; + +//check permisisions + require_once "resources/check_auth.php"; + if (permission_exists('xml_cdr_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//additional includes + require_once "resources/header.php"; + +//retrieve submitted data + $quick_select = check_str($_POST['quick_select']); + $start_stamp_begin = check_str($_POST['start_stamp_begin']); + $start_stamp_end = check_str($_POST['start_stamp_end']); + $include_internal = check_str($_POST['include_internal']); + + $quick_select = (sizeof($_POST) == 0) ? 1 : $quick_select; //set default + +//get current extension info + $sql = "select "; + $sql .= "domain_uuid, "; + $sql .= "extension_uuid, "; + $sql .= "extension, "; + $sql .= "number_alias, "; + $sql .= "description "; + $sql .= "from "; + $sql .= "v_extensions "; + $sql .= "where "; + $sql .= "enabled = 'true' "; + if (!($_GET['showall'] == 'true' && permission_exists('xml_cdr_all'))) { + $sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' "; + } + if (!(if_group("admin") || if_group("superadmin"))) { + if (count($_SESSION['user']['extension']) > 0) { + $sql .= "and ("; + $x = 0; + foreach($_SESSION['user']['extension'] as $row) { + if ($x > 0) { $sql .= "or "; } + $sql .= "extension = '".$row['user']."' "; + $x++; + } + $sql .= ")"; + } + else { + //used to hide any results when a user has not been assigned an extension + $sql .= "and extension = 'disabled' "; + } + } + + $sql .= "order by "; + $sql .= "extension asc"; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + if ($result_count > 0) { + foreach($result as $row) { + $extensions[$row['extension']]['domain_uuid'] = $row['domain_uuid']; + $extensions[$row['extension']]['extension'] = $row['extension']; + $extensions[$row['extension']]['extension_uuid'] = $row['extension_uuid']; + $extensions[$row['extension']]['number_alias'] = $row['number_alias']; + $extensions[$row['extension']]['description'] = $row['description']; + } + } + unset ($sql, $prep_statement, $result, $row_count); + // create list of extensions for query below + foreach ($extensions as $extension => $blah) { + $ext_array[] = $extension; + } + $ext_list = implode("','", $ext_array); + +//calculate the summary data + $sql = "select "; + $sql .= "caller_id_number, "; + $sql .= "destination_number, "; + $sql .= "billsec, "; + $sql .= "hangup_cause "; + $sql .= "from v_xml_cdr "; + $sql .= "where "; + if (!($_GET['showall'] && permission_exists('xml_cdr_all'))) { + $sql .= " domain_uuid = '".$_SESSION['domain_uuid']."' and "; + } + $sql .= "( "; + $sql .= " caller_id_number in ('".$ext_list."') or "; + $sql .= " destination_number in ('".$ext_list."') "; + $sql .= ") "; + if (!$include_internal) { + $sql .= " and (direction = 'inbound' or direction = 'outbound') "; + } + if (strlen($start_stamp_begin) > 0 || strlen($start_stamp_end) > 0) { + unset($quick_select); + if (strlen($start_stamp_begin) > 0 && strlen($start_stamp_end) > 0) { + $sql .= " and start_stamp between '".$start_stamp_begin.":00.000' and '".$start_stamp_end.":59.999'"; + } + else { + if (strlen($start_stamp_begin) > 0) { $sql .= "and start_stamp >= '".$start_stamp_begin.":00.000' "; } + if (strlen($start_stamp_end) > 0) { $sql .= "and start_stamp <= '".$start_stamp_end.":59.999' "; } + } + } + else { + switch ($quick_select) { + case 1: $sql .= "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))."' "; break; //last 7 days + case 2: $sql .= "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))."' "; break; //last hour + case 3: $sql .= "and start_stamp >= '".date('Y-m-d')." "."00:00:00.000' "; break; //today + case 4: $sql .= "and start_stamp between '".date('Y-m-d',strtotime("-1 day"))." "."00:00:00.000' and '".date('Y-m-d',strtotime("-1 day"))." "."23:59:59.999' "; break; //yesterday + case 5: $sql .= "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00:00.000' "; break; //this week + case 6: $sql .= "and start_stamp >= '".date('Y-m-')."01 "."00:00:00.000' "; break; //this month + case 7: $sql .= "and start_stamp >= '".date('Y-')."01-01 "."00:00:00.000' "; break; //this year + } + } + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + + if ($result_count > 0) { + foreach($result as $row) { + if ($summary[$row['destination_number']]['missed'] == null) { + $summary[$row['destination_number']]['missed'] = 0; + } + if (in_array($row['caller_id_number'], $ext_array)) { + $summary[$row['caller_id_number']]['outbound']['count']++; + $summary[$row['caller_id_number']]['outbound']['seconds'] += $row['billsec']; + } + if (in_array($row['destination_number'], $ext_array)) { + $summary[$row['destination_number']]['inbound']['count']++; + $summary[$row['destination_number']]['inbound']['seconds'] += $row['billsec']; + if ($row['billsec'] == "0") { + $summary[$row['destination_number']]['missed']++; + } + } + if ($row['hangup_cause'] == "NO_ANSWER") { + $summary[$row['destination_number']]['no_answer']++; + } + if ($row['hangup_cause'] == "USER_BUSY") { + $summary[$row['destination_number']]['busy']++; + } + } //end foreach + } //end if results + unset ($sql, $prep_statement, $result, $row_count); + +//page title and description + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['title-extension_summary']."

\n"; + echo "
"; + if (permission_exists('xml_cdr_all') && $_GET['showall'] != 'true') { + echo " \n"; + } + echo "
\n"; + echo "
\n"; + + if (permission_exists('xml_cdr_search')) { + echo "
\n"; + + echo "\n"; + echo " \n"; + + echo " "; + + echo " "; + + echo " "; + + echo " "; + + echo " "; + echo " "; + echo " "; + echo " "; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-preset']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-start_date_time']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-end_date_time']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['label-include_internal']."\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
"; + echo " \n"; + echo " \n"; + echo "
"; + + echo "
"; + echo "

"; + } + +//show the results + echo "\n"; + 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"; + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + foreach ($extensions as $extension => $ext) { + $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'] = ($seconds['inbound'] + $seconds['outbound']) / ($volume - $missed); + + $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"; + $c = ($c==0) ? 1 : 0; + } + + echo "
".$text['label-domain']."".$text['label-extension']."".$text['label-number_alias']."".$text['label-missed']."".$text['label-no_answer']."".$text['label-busy']."".$text['label-aloc']."".$text['label-inbound_calls']."".$text['label-inbound_duration']."".$text['label-outbound_calls']."".$text['label-outbound_duration']."".$text['label-description']."
".$_SESSION['domains'][$ext['domain_uuid']]['domain_name']."".$extension."".$ext['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')."".$ext['description']." 
"; + echo "

"; + +//show the footer + require_once "resources/footer.php"; + +?>