Эх сурвалжийг харах

Merge pull request #5122 from greenbea/master

Added destination select permissions
FusionPBX 5 жил өмнө
parent
commit
54c1a9f85f

+ 40 - 2
resources/classes/destinations.php

@@ -80,10 +80,11 @@ if (!class_exists('destinations')) {
 				$i = 0;
 				foreach ($apps as $x => &$app) {
 					if (isset($app['destinations'])) foreach ($app['destinations'] as &$row) {
-						$this->destinations[] = $row;
+						if (permission_exists($this->singular($row["name"])."_destinations")) {
+							$this->destinations[] = $row;
+						}
 					}
 				}
-
 				//put the array in order
 				foreach ($this->destinations as $row) {
 					$option_groups[] = $row['label'];
@@ -586,6 +587,43 @@ if (!class_exists('destinations')) {
 			}
 		} //method
 
+		//define singular function to convert a word in english to singular
+			public function singular($word) {
+				//"-es" is used for words that end in "-x", "-s", "-z", "-sh", "-ch" in which case you add
+				if (substr($word, -2) == "es") {
+					if (substr($word, -4) == "sses") { // eg. 'addresses' to 'address'
+						return substr($word,0,-2);
+					}
+					elseif (substr($word, -3) == "ses") { // eg. 'databases' to 'database' (necessary!)
+						return substr($word,0,-1);
+					}
+					elseif (substr($word, -3) == "ies") { // eg. 'countries' to 'country'
+						return substr($word,0,-3)."y";
+					}
+					elseif (substr($word, -3, 1) == "x") {
+						return substr($word,0,-2);
+					}
+					elseif (substr($word, -3, 1) == "s") {
+						return substr($word,0,-2);
+					}
+					elseif (substr($word, -3, 1) == "z") {
+						return substr($word,0,-2);
+					}
+					elseif (substr($word, -4, 2) == "sh") {
+						return substr($word,0,-2);
+					}
+					elseif (substr($word, -4, 2) == "ch") {
+						return substr($word,0,-2);
+					}
+					else {
+						return rtrim($word, "s");
+					}
+				}
+				else {
+					return rtrim($word, "s");
+				}
+			} //method
+
 	} //class
 }
 /*