diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 9e415cedc7..72d27ad7ee 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -948,34 +948,42 @@ if (!class_exists('xml_cdr')) { */ public function user_summary() { + //set the time zone + if (isset($_SESSION['domain']['time_zone']['name'])) { + $time_zone = $_SESSION['domain']['time_zone']['name']; + } + else { + $time_zone = date_default_timezone_get(); + } + //build the date range if (strlen($this->start_stamp_begin) > 0 || strlen($this->start_stamp_end) > 0) { unset($this->quick_select); if (strlen($this->start_stamp_begin) > 0 && strlen($this->start_stamp_end) > 0) { - $sql_date_range = " and start_stamp between :start_stamp_begin and :start_stamp_end \n"; - $parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000'; - $parameters['start_stamp_end'] = $this->start_stamp_end.':59.999'; + $sql_date_range = " and start_stamp between :start_stamp_begin::timestamptz and :start_stamp_end::timestamptz \n"; + $parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000 '.$time_zone; + $parameters['start_stamp_end'] = $this->start_stamp_end.':59.999 '.$time_zone; } else { if (strlen($this->start_stamp_begin) > 0) { - $sql_date_range = "and start_stamp >= :start_stamp_begin \n"; - $parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000'; + $sql_date_range = "and start_stamp >= :start_stamp_begin::timestamptz \n"; + $parameters['start_stamp_begin'] = $this->start_stamp_begin.':00.000 '.$time_zone; } if (strlen($this->start_stamp_end) > 0) { - $sql_date_range .= "and start_stamp <= :start_stamp_end \n"; - $parameters['start_stamp_end'] = $this->start_stamp_end.':59.999'; + $sql_date_range .= "and start_stamp <= :start_stamp_end::timestamptz \n"; + $parameters['start_stamp_end'] = $this->start_stamp_end.':59.999 '.$time_zone; } } } else { switch ($this->quick_select) { - case 1: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))."' \n"; break; //last 7 days - case 2: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))."' \n"; break; //last hour - case 3: $sql_date_range = "and start_stamp >= '".date('Y-m-d')." "."00:00:00.000' \n"; break; //today - case 4: $sql_date_range = "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' \n"; break; //yesterday - case 5: $sql_date_range = "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00:00.000' \n"; break; //this week - case 6: $sql_date_range = "and start_stamp >= '".date('Y-m-')."01 "."00:00:00.000' \n"; break; //this month - case 7: $sql_date_range = "and start_stamp >= '".date('Y-')."01-01 "."00:00:00.000' \n"; break; //this year + case 1: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 week"))." ".$time_zone."'::timestamptz \n"; break; //last 7 days + case 2: $sql_date_range = "and start_stamp >= '".date('Y-m-d H:i:s.000', strtotime("-1 hour"))." ".$time_zone."'::timestamptz \n"; break; //last hour + case 3: $sql_date_range = "and start_stamp >= '".date('Y-m-d')." "."00:00:00.000 ".$time_zone."'::timestamptz \n"; break; //today + case 4: $sql_date_range = "and start_stamp between '".date('Y-m-d',strtotime("-1 day"))." "."00:00:00.000 ".$time_zone."'::timestamptz and '".date('Y-m-d',strtotime("-1 day"))." "."23:59:59.999 ".$time_zone."'::timestamptz \n"; break; //yesterday + case 5: $sql_date_range = "and start_stamp >= '".date('Y-m-d',strtotime("this week"))." "."00:00:00.000 ".$time_zone."' \n"; break; //this week + case 6: $sql_date_range = "and start_stamp >= '".date('Y-m-')."01 "."00:00:00.000 ".$time_zone."'::timestamptz \n"; break; //this month + case 7: $sql_date_range = "and start_stamp >= '".date('Y-')."01-01 "."00:00:00.000 ".$time_zone."'::timestamptz \n"; break; //this year } } @@ -1377,4 +1385,4 @@ if (!class_exists('xml_cdr')) { } //class } -?> \ No newline at end of file +?> diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index adf9c25588..e74cf43e5a 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -629,17 +629,6 @@ //loop through the results $x = 0; foreach ($result as $index => $row) { - //get the date and time - $tmp_year = date("Y", strtotime($row['start_stamp'])); - $tmp_month = date("M", strtotime($row['start_stamp'])); - $tmp_day = date("d", strtotime($row['start_stamp'])); - $tmp_start_epoch_date = escape(date("j M Y", $row['start_epoch'])); - if ($_SESSION['domain']['time_format']['text'] == '12h') { - $tmp_start_epoch_time = escape(date("g:i:s a", $row['start_epoch'])); - } - else { - $tmp_start_epoch_time = escape(date("H:i:s", $row['start_epoch'])); - } //get the hangup cause $hangup_cause = $row['hangup_cause']; @@ -791,8 +780,8 @@ } //start if (permission_exists('xml_cdr_start')) { - $content .= " ".$tmp_start_epoch_date."\n"; - $content .= " ".$tmp_start_epoch_time."\n"; + $content .= " ".$row['start_date_formatted']."\n"; + $content .= " ".$row['start_time_formatted']."\n"; } //tta (time to answer) if (permission_exists('xml_cdr_tta')) { diff --git a/app/xml_cdr/xml_cdr_inc.php b/app/xml_cdr/xml_cdr_inc.php index d7255167d8..d082aef62a 100644 --- a/app/xml_cdr/xml_cdr_inc.php +++ b/app/xml_cdr/xml_cdr_inc.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2020 + Portions created by the Initial Developer are Copyright (C) 2008-2021 the Initial Developer. All Rights Reserved. Contributor(s): @@ -220,12 +220,23 @@ if (!isset($_GET['page'])) { $page = 0; $_GET['page'] = 0; } $offset = $rows_per_page * $page; +//set the time zone + if (isset($_SESSION['domain']['time_zone']['name'])) { + $time_zone = $_SESSION['domain']['time_zone']['name']; + } + else { + $time_zone = date_default_timezone_get(); + } + $parameters['time_zone'] = $time_zone; + //get the results from the db $sql = "select \n"; $sql .= "c.domain_uuid, \n"; $sql .= "e.extension, \n"; $sql .= "c.start_stamp, \n"; $sql .= "c.end_stamp, \n"; + $sql .= "to_char(timezone(:time_zone, start_stamp), 'DD Mon YYYY') as start_date_formatted, \n"; + $sql .= "to_char(timezone(:time_zone, start_stamp), 'HH12:MI:SS am') as start_time_formatted, \n"; $sql .= "c.start_epoch, \n"; $sql .= "c.hangup_cause, \n"; $sql .= "c.duration, \n"; @@ -357,48 +368,49 @@ } if (strlen($start_stamp_begin) > 0 && strlen($start_stamp_end) > 0) { - $sql .= "and start_stamp between :start_stamp_begin and :start_stamp_end "; - $parameters['start_stamp_begin'] = $start_stamp_begin.':00.000'; - $parameters['start_stamp_end'] = $start_stamp_end.':59.999'; + $sql .= "and start_stamp between :start_stamp_begin::timestamptz and :start_stamp_end::timestamptz "; + $parameters['start_stamp_begin'] = $start_stamp_begin.':00.000 '.$time_zone; + $parameters['start_stamp_end'] = $start_stamp_end.':59.999 '.$time_zone; } else { if (strlen($start_stamp_begin) > 0) { $sql .= "and start_stamp >= :start_stamp_begin "; - $parameters['start_stamp_begin'] = $start_stamp_begin.':00.000'; + $parameters['start_stamp_begin'] = $start_stamp_begin.':00.000 '.$time_zone; } if (strlen($start_stamp_end) > 0) { $sql .= "and start_stamp <= :start_stamp_end "; - $parameters['start_stamp_end'] = $start_stamp_end.':59.999'; + $parameters['start_stamp_end'] = $start_stamp_end.':59.999 '.$time_zone; } } if (strlen($answer_stamp_begin) > 0 && strlen($answer_stamp_end) > 0) { - $sql .= "and answer_stamp between :answer_stamp_begin and :answer_stamp_end "; - $parameters['answer_stamp_begin'] = $answer_stamp_begin.':00.000'; - $parameters['answer_stamp_end'] = $answer_stamp_end.':59.999'; + $sql .= "and answer_stamp between :answer_stamp_begin::timestamptz and :answer_stamp_end::timestamptz "; + + $parameters['answer_stamp_begin'] = $answer_stamp_begin.':00.000 '.$time_zone; + $parameters['answer_stamp_end'] = $answer_stamp_end.':59.999 '.$time_zone; } else { if (strlen($answer_stamp_begin) > 0) { $sql .= "and answer_stamp >= :answer_stamp_begin "; - $parameters['answer_stamp_begin'] = $answer_stamp_begin.':00.000'; + $parameters['answer_stamp_begin'] = $answer_stamp_begin.':00.000 '.$time_zone;; } if (strlen($answer_stamp_end) > 0) { $sql .= "and answer_stamp <= :answer_stamp_end "; - $parameters['answer_stamp_end'] = $answer_stamp_end.':59.999'; + $parameters['answer_stamp_end'] = $answer_stamp_end.':59.999 '.$time_zone; } } if (strlen($end_stamp_begin) > 0 && strlen($end_stamp_end) > 0) { - $sql .= "and end_stamp between :end_stamp_begin and :end_stamp_end "; - $parameters['end_stamp_begin'] = $end_stamp_begin.':00.000'; - $parameters['end_stamp_end'] = $end_stamp_end.':59.999'; + $sql .= "and end_stamp between :end_stamp_begin::timestamptz and :end_stamp_end::timestamptz "; + $parameters['end_stamp_begin'] = $end_stamp_begin.':00.000 '.$time_zone; + $parameters['end_stamp_end'] = $end_stamp_end.':59.999 '.$time_zone; } else { if (strlen($end_stamp_begin) > 0) { $sql .= "and end_stamp >= :end_stamp_begin "; - $parameters['end_stamp_begin'] = $end_stamp_begin.':00.000'; + $parameters['end_stamp_begin'] = $end_stamp_begin.':00.000 '.$time_zone; } if (strlen($end_stamp_end) > 0) { $sql .= "and end_stamp <= :end_stamp_end "; - $parameters['end_stamp'] = $end_stamp_end.':59.999'; + $parameters['end_stamp'] = $end_stamp_end.':59.999 '.$time_zone; } } if (is_numeric($duration_min)) { @@ -551,6 +563,9 @@ } } $sql = str_replace(" ", " ", $sql); +//echo $sql; +//print_r($parameters); +//exit; $database = new database; if ($archive_request && $_SESSION['cdr']['archive_database']['boolean'] == 'true') { $database->driver = $_SESSION['cdr']['archive_database_driver']['text'];