瀏覽代碼

Move the destinations array generation into the constructor and add selected support.

markjcrane 10 年之前
父節點
當前提交
40dd8763a7
共有 1 個文件被更改,包括 35 次插入34 次删除
  1. 35 34
      resources/classes/destinations.php

+ 35 - 34
resources/classes/destinations.php

@@ -3,35 +3,22 @@
 /**
  * destinations
  *
- * @method array get the destinations
+ * @method get_array get the destinations
+ * @method select build the html select
  */
 class destinations {
 
 	/**
-	 * Called when the object is created
+	 * destinations array
 	 */
-	public function __construct() {
-		//place holder
-	}
-
-	/**
-	 * Called when there are no references to a particular object
-	 * unset the variables used in the class
-	 */
-	public function __destruct() {
-		foreach ($this as $key => $value) {
-			unset($this->$key);
-		}
-	}
+	public $destinations;
 
 	/**
-	 * Get the destination array
-	 * @var null
+	 * Called when the object is created
 	 */
-	public function get_array() {
-
+	public function __construct() {
 		//set the global variables
-			global $db;
+			global $db, $db_type;
 
 		//get the array from the app_config.php files
 			$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
@@ -43,19 +30,19 @@ class destinations {
 			$i = 0;
 			foreach ($apps as $x => &$app) {
 				foreach ($app['destinations'] as &$row) {
-					$switch[destinations][] = $row;
+					$this->destinations[] = $row;
 				}
 			}
 
 		//put the array in order
-			foreach ($switch[destinations] as $row) {
+			foreach ($this->destinations as $row) {
 				$option_groups[] = $row['label'];
 			}
-			array_multisort($option_groups, SORT_ASC, $switch[destinations]);
+			array_multisort($option_groups, SORT_ASC, $this->destinations);
 
 		//add the sql and data to the array
 			$x = 0;
-			foreach ($switch[destinations] as $row) {
+			foreach ($this->destinations as $row) {
 				if ($row['type'] = 'sql') {
 					if (isset($row['sql'])) {
 						if (is_array($row['sql'])) {
@@ -97,21 +84,27 @@ class destinations {
 			}
 
 		//return the destination array
-			return $switch['destinations'];
+			$this->destinations = $switch['destinations'];
+	}
 
+	/**
+	 * Called when there are no references to a particular object
+	 * unset the variables used in the class
+	 */
+	public function __destruct() {
+		foreach ($this as $key => $value) {
+			unset($this->$key);
+		}
 	}
 
 	/**
-	 * Get a specific item from the cache
+	 * Get the destination menu
 	 * @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
-			$switch['destinations'] = $this->get_array();
-
 		//remove special characters from the name
 			$destination_id = str_replace("]", "", $destination_name);
 			$destination_id = str_replace("[", "_", $destination_id);
@@ -165,7 +158,7 @@ class destinations {
 
 			//print_r($switch);
 			$response .= "	<select name='".$destination_name."' id='".$destination_id."' class='formfld' style='".$select_style."' onchange=\"".$onchange."\">\n";
-			foreach ($switch['destinations'] as $row) {
+			foreach ($this->destinations as $row) {
 
 				$name = $row['name'];
 				$label = $row['label'];
@@ -179,7 +172,7 @@ class destinations {
 
 				$response .= "		<optgroup label='".$text2['title-'.$label]."'>\n";
 				foreach ($row['result']['data'] as $data) {
-					$select_value = $row['select_value']['dialplan'];
+					$select_value = $row['select_value'][$destination_type];
 					$select_label = $row['select_label'];
 					foreach ($row['field'] as $key => $value) {
 						if ($key == 'destination' and is_array($value)){
@@ -198,7 +191,8 @@ class destinations {
 					$select_value = str_replace("\${context}", $_SESSION['context'], $select_value); //to do: context can come from the array
 					$select_label = str_replace("\${domain_name}", $_SESSION['domain_name'], $select_label);
 					$select_label = str_replace("\${context}", $_SESSION['context'], $select_label);
-					$response .= "			<option value='".$select_value."'>".trim($select_label)."</option>\n";
+					if ($select_value == $destination_value) { $selected = "selected='selected' "; } else { $selected = ''; }
+					$response .= "			<option value='".$select_value."' $selected>".trim($select_label)."</option>\n";
 				}
 				$response .= "		</optgroup>\n";
 				unset($text);
@@ -212,7 +206,14 @@ class destinations {
 			return $response;
 	}
 }
-//$obj = new destinations;
-//echo $obj->select('dialplan', 'example', 'value');
+/*
+$obj = new destinations;
+echo $obj->select('ivr', 'example1', 'menu-exec-app:transfer 32 XML voip.fusionpbx.com');
+echo $obj->select('ivr', 'example2', '');
+echo $obj->select('ivr', 'example3', '');
+echo $obj->select('ivr', 'example4', '');
+echo $obj->select('ivr', 'example5', '');
+echo $obj->select('ivr', 'example6', '');
+*/
 
 ?>