From a87d15dece094e42e5432c218e8f8c086d6f4f9c Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 7 Feb 2020 10:59:05 -0700 Subject: [PATCH] Update destinations.php --- resources/classes/destinations.php | 99 +++++++++++++++++++----------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/resources/classes/destinations.php b/resources/classes/destinations.php index e45b66bc42..bb2738df61 100644 --- a/resources/classes/destinations.php +++ b/resources/classes/destinations.php @@ -1,4 +1,28 @@ + Portions created by the Initial Developer are Copyright (C) 2017 - 2020 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ /** * destinations @@ -86,50 +110,53 @@ if (!class_exists('destinations')) { } } //put the array in order - foreach ($this->destinations as $row) { - $option_groups[] = $row['label']; + if ($this->destinations !== null && is_array($this->destinations)) { + foreach ($this->destinations as $row) { + $option_groups[] = $row['label']; + } + array_multisort($option_groups, SORT_ASC, $this->destinations); } - array_multisort($option_groups, SORT_ASC, $this->destinations); - //add the sql and data to the array - $x = 0; - foreach ($this->destinations as $row) { - if ($row['type'] = 'sql') { - $table_name = preg_replace('#[^a-zA-Z0-9_]#', '', $row['name']); - if (isset($row['sql'])) { - if (is_array($row['sql'])) { - $sql = trim($row['sql'][$db_type])." "; + if ($this->destinations !== null && is_array($this->destinations)) { + $x = 0; + foreach ($this->destinations as $row) { + if ($row['type'] = 'sql') { + $table_name = preg_replace('#[^a-zA-Z0-9_]#', '', $row['name']); + if (isset($row['sql'])) { + if (is_array($row['sql'])) { + $sql = trim($row['sql'][$db_type])." "; + } + else { + $sql = trim($row['sql'])." "; + } } else { - $sql = trim($row['sql'])." "; + $field_count = count($row['field']); + $fields = ''; + $c = 1; + foreach ($row['field'] as $key => $value) { + $key = preg_replace('#[^a-zA-Z0-9_]#', '', $key); + $value = preg_replace('#[^a-zA-Z0-9_]#', '', $value); + if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; } + $fields .= $value." as ".$key.$delimiter." "; + $c++; + } + $sql = "select ".$fields; + $sql .= " from v_".$table_name." "; } - } - else { - $field_count = count($row['field']); - $fields = ''; - $c = 1; - foreach ($row['field'] as $key => $value) { - $key = preg_replace('#[^a-zA-Z0-9_]#', '', $key); - $value = preg_replace('#[^a-zA-Z0-9_]#', '', $value); - if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; } - $fields .= $value." as ".$key.$delimiter." "; - $c++; + if (isset($row['where'])) { + $sql .= trim($row['where'])." "; } - $sql = "select ".$fields; - $sql .= " from v_".$table_name." "; - } - if (isset($row['where'])) { - $sql .= trim($row['where'])." "; - } - $sql .= "order by ".trim($row['order_by']); - $sql = str_replace("\${domain_uuid}", $_SESSION['domain_uuid'], $sql); - $database = new database; - $result = $database->select($sql, null, 'all'); + $sql .= "order by ".trim($row['order_by']); + $sql = str_replace("\${domain_uuid}", $_SESSION['domain_uuid'], $sql); + $database = new database; + $result = $database->select($sql, null, 'all'); - $this->destinations[$x]['result']['sql'] = $sql; - $this->destinations[$x]['result']['data'] = $result; + $this->destinations[$x]['result']['sql'] = $sql; + $this->destinations[$x]['result']['data'] = $result; + } + $x++; } - $x++; } $this->destinations[$x]['type'] = 'array';