diff --git a/app/dialplan/resources/classes/dialplan.php b/app/dialplan/resources/classes/dialplan.php index 4fddce35ad..26efd15802 100644 --- a/app/dialplan/resources/classes/dialplan.php +++ b/app/dialplan/resources/classes/dialplan.php @@ -29,6 +29,7 @@ include "root.php"; if (!class_exists('dialplan')) { class dialplan { //variables + public $db; public $result; public $domain_uuid; public $dialplan_uuid; @@ -56,8 +57,19 @@ include "root.php"; public $dialplan_detail_inline; public $dialplan_detail_group; + //class constructor + public function __construct() { + //connect to the database if not connected + if (!$this->db) { + require_once "resources/classes/database.php"; + $database = new database; + $database->connect(); + $this->db = $database->db; + } + } + public function dialplan_add() { - global $db; + $sql = "insert into v_dialplans "; $sql .= "("; $sql .= "domain_uuid, "; @@ -89,12 +101,12 @@ include "root.php"; $sql .= "'".check_str($this->dialplan_enabled)."', "; $sql .= "'".check_str($this->dialplan_description)."' "; $sql .= ")"; - $db->exec(check_sql($sql)); + $this->db->exec(check_sql($sql)); unset($sql); } //end function public function dialplan_update() { - global $db; + $sql = "update v_dialplans set "; $sql .= "dialplan_name = '".check_str($this->dialplan_name)."', "; if (strlen($this->dialplan_continue) > 0) { @@ -107,12 +119,12 @@ include "root.php"; $sql .= "where (domain_uuid = '".check_str($this->domain_uuid)."' or domain_uuid is null) "; $sql .= "and dialplan_uuid = '".check_str($this->dialplan_uuid)."' "; //echo "sql: ".$sql."
"; - $db->query($sql); + $this->db->query($sql); unset($sql); } public function dialplan_detail_add() { - global $db; + $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; @@ -161,12 +173,12 @@ include "root.php"; } $sql .= ")"; //echo $sql."\n\n"; - $db->exec(check_sql($sql)); + $this->db->exec(check_sql($sql)); unset($sql); } //end function public function dialplan_detail_update() { - global $db; + $sql = "update v_dialplans set "; $sql .= "dialplan_detail_order = '".check_str($this->dialplan_detail_order)."', "; $sql .= "dialplan_detail_type = '".check_str($this->dialplan_detail_type)."', "; @@ -184,7 +196,7 @@ include "root.php"; $sql .= "where (domain_uuid = '".check_str($this->domain_uuid)."' or domain_uuid is null) "; $sql .= "and dialplan_uuid = '".check_str($this->dialplan_uuid)."' "; //echo "sql: ".$sql."
"; - $db->query($sql); + $this->db->query($sql); unset($sql); } //end function @@ -216,11 +228,10 @@ include "root.php"; } private function app_uuid_exists() { - global $db; $sql = "select count(*) as num_rows from v_dialplans "; $sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null) "; $sql .= "and app_uuid = '".$this->app_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement = $this->db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); @@ -235,11 +246,10 @@ include "root.php"; } public function dialplan_exists() { - global $db; $sql = "select count(*) as num_rows from v_dialplans "; $sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null)"; $sql .= "and dialplan_uuid = '".$this->dialplan_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement = $this->db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); @@ -254,7 +264,6 @@ include "root.php"; } public function import() { - global $db; if (strlen($this->xml) > 0) { //replace the variables $this->xml = str_replace("{v_context}", $this->default_context, $this->xml); @@ -287,7 +296,7 @@ include "root.php"; } else { //start the transaction - $db->beginTransaction(); + $this->db->beginTransaction(); //get the attributes $this->dialplan_uuid = uuid(); $this->dialplan_name = $dialplan['extension']['@attributes']['name']; @@ -381,13 +390,11 @@ include "root.php"; $x++; } //end the transaction - $db->commit(); + $this->db->commit(); } } public function outbound_routes($destination_number) { - //get the database connection - global $db; //normalize the destination number $destination_number = trim($destination_number); @@ -415,7 +422,7 @@ include "root.php"; $sql .= "WHEN 'anti-action' THEN 3 "; $sql .= "ELSE 100 END, "; $sql .= "s.dialplan_detail_order asc "; - $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $dialplans = $prep_statement->fetchAll(PDO::FETCH_ASSOC); $x = 0; $y = 0; diff --git a/resources/classes/domains.php b/resources/classes/domains.php index 2f9840404c..ac556abcf7 100644 --- a/resources/classes/domains.php +++ b/resources/classes/domains.php @@ -201,9 +201,6 @@ public function upgrade() { - //set the global variable - global $db; - //get the db variables $config = new config; $config_exists = $config->exists(); @@ -225,6 +222,7 @@ $config_list_2 = glob($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/*/*/app_menu.php"); $config_list = array_merge((array)$config_list_1, (array)$config_list_2); unset($config_list_1,$config_list_2); + $db = $this->db; $x=0; foreach ($config_list as &$config_path) { include($config_path); diff --git a/resources/classes/schema.php b/resources/classes/schema.php index 787a1c45dd..b143ce5c1a 100644 --- a/resources/classes/schema.php +++ b/resources/classes/schema.php @@ -27,6 +27,7 @@ include "root.php"; //define the schema class class schema { + //define variables public $db; public $apps;