From cab4d656006adf72d8277dc2a7d82b50d77f1b9f Mon Sep 17 00:00:00 2001 From: markjcrane Date: Wed, 5 Aug 2015 16:43:22 -0500 Subject: [PATCH] Initial commit a new php destinations class. Builds a list of destinations dynamically. Typically this contains extensions, ivr menus, ring groups, voicemail and more. --- resources/classes/destinations.php | 215 +++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 resources/classes/destinations.php diff --git a/resources/classes/destinations.php b/resources/classes/destinations.php new file mode 100644 index 0000000000..fe83e981e3 --- /dev/null +++ b/resources/classes/destinations.php @@ -0,0 +1,215 @@ + $value) { + unset($this->$key); + } + } + + /** + * Get a specific item from the cache + * @var string $language_code examples: en-us, es-cl, fr-fr, pt-pt + */ + public function array() { + + //get the array from the app_config.php files + $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); + $x = 0; + foreach ($config_list as &$config_path) { + include($config_path); + $x++; + } + $i = 0; + foreach ($apps as $x => &$app) { + foreach ($app['destinations'] as &$row) { + $switch[destinations][] = $row; + } + } + + //put the array in order + foreach ($switch[destinations] as $row) { + $option_groups[] = $row['label']; + } + array_multisort($option_groups, SORT_ASC, $switch[destinations]); + + //add the sql and data to the array + $x = 0; + foreach ($switch[destinations] as $row) { + if ($row['type'] = 'sql') { + if (isset($row['sql'])) { + if (is_array($row['sql'])) { + $sql = trim($row['sql'][$db_type])." "; + } + else { + $sql = trim($row['sql'])." "; + } + } + else { + $field_count = count($row['field']); + $fields = ''; + $c = 1; + foreach ($row['field'] as $key => $value) { + if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; } + $fields .= $value." as ".$key.$delimiter." "; + $c++; + } + $sql = "select ".$fields; + $sql .= " from v_".$row['name']." "; + } + if (isset($row['where'])) { + $sql .= trim($row['where'])." "; + } + if (isset($row['sql'])) { + $sql .= "order by ".trim($row['order_by']); + } + $sql = str_replace("\${domain_name}", $_SESSION['domain_uuid'], $sql); + $sql = trim($sql); + $statement = $db->prepare($sql); + $statement->execute(); + $result = $statement->fetchAll(PDO::FETCH_NAMED); + unset($statement); + + $switch['destinations'][$x]['result']['sql'] = $sql; + $switch['destinations'][$x]['result']['data'] = $result; + } + $x++; + } + + //return the destination array + return $switch['destinations']; + + } + + /** + * Get a specific item from the cache + * @var string $destination_type can be ivr, dialplan, call_center_contact or bridge + * @var string $destination_name - current name + * @var string $destination_value - current value + */ + public function select($destination_type, $destination_name, $destination_value) { + //get the array + $destinations = $this->array(); + + //remove special characters from the name + $destination_id = str_replace("]", "", $destination_name); + $destination_id = str_replace("[", "_", $destination_id); + + //add additional + if (if_group("superadmin")) { + $response = "\n"; + $response .= "\n"; + } + + //default selection found to false + $selection_found = false; + + //print_r($switch); + $response .= " \n"; + if (if_group("superadmin")) { + $response .= ""; + } + + //return the formatted destinations + return $response; + } + //$obj = new destinations; + //echo $obj->select('dialplan', 'example' 'value'); + +} + +?> \ No newline at end of file