Misc Classes: Database class integration.
This commit is contained in:
parent
601198e01a
commit
836fb87136
|
|
@ -29,10 +29,10 @@ include "root.php";
|
|||
if (!class_exists('dialplan')) {
|
||||
class dialplan {
|
||||
//variables
|
||||
public $db;
|
||||
public $result;
|
||||
public $domain_uuid;
|
||||
public $dialplan_uuid;
|
||||
public $dialplan_detail_uuid;
|
||||
public $xml;
|
||||
public $json;
|
||||
public $display_type;
|
||||
|
|
@ -70,151 +70,114 @@ include "root.php";
|
|||
|
||||
//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;
|
||||
}
|
||||
|
||||
//set the default value
|
||||
$this->dialplan_global = false;
|
||||
}
|
||||
|
||||
public function dialplan_add() {
|
||||
|
||||
$sql = "insert into v_dialplans ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "app_uuid, ";
|
||||
$sql .= "dialplan_uuid, ";
|
||||
$sql .= "dialplan_name, ";
|
||||
$sql .= "dialplan_number, ";
|
||||
$sql .= "dialplan_destination, ";
|
||||
$sql .= "dialplan_continue, ";
|
||||
$sql .= "dialplan_order, ";
|
||||
$sql .= "dialplan_context, ";
|
||||
$sql .= "dialplan_enabled, ";
|
||||
$sql .= "dialplan_description ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
if ($this->dialplan_global) {
|
||||
$sql .= "null, ";
|
||||
//build insert array
|
||||
$array['dialplans'][0]['dialplan_uuid'] = $this->dialplan_uuid;
|
||||
$array['dialplans'][0]['domain_uuid'] = !$this->dialplan_global ? $this->domain_uuid : null;
|
||||
$array['dialplans'][0]['app_uuid'] = $this->app_uuid;
|
||||
$array['dialplans'][0]['dialplan_name'] = $this->dialplan_name;
|
||||
$array['dialplans'][0]['dialplan_number'] = $this->dialplan_number;
|
||||
$array['dialplans'][0]['dialplan_destination'] = $this->dialplan_destination;
|
||||
$array['dialplans'][0]['dialplan_continue'] = $this->dialplan_continue;
|
||||
$array['dialplans'][0]['dialplan_order'] = $this->dialplan_order;
|
||||
$array['dialplans'][0]['dialplan_context'] = $this->dialplan_order;
|
||||
$array['dialplans'][0]['dialplan_enabled'] = $this->dialplan_enabled;
|
||||
$array['dialplans'][0]['dialplan_description'] = $this->dialplan_description;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('dialplan_add', 'temp');
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'dialplans';
|
||||
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('dialplan_add', 'temp');
|
||||
}
|
||||
else {
|
||||
$sql .= "'".check_str($this->domain_uuid)."', ";
|
||||
}
|
||||
$sql .= "'".check_str($this->app_uuid)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_uuid)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_name)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_number)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_destination)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_continue)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_order)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_context)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_enabled)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_description)."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
} //end function
|
||||
|
||||
public function dialplan_update() {
|
||||
|
||||
$sql = "update v_dialplans set ";
|
||||
$sql .= "dialplan_name = '".check_str($this->dialplan_name)."', ";
|
||||
//build update array
|
||||
$array['dialplans'][0]['dialplan_uuid'] = $this->dialplan_uuid;
|
||||
$array['dialplans'][0]['dialplan_name'] = $this->dialplan_name;
|
||||
if (strlen($this->dialplan_continue) > 0) {
|
||||
$sql .= "dialplan_continue = '".check_str($this->dialplan_continue)."', ";
|
||||
$array['dialplans'][0]['dialplan_continue'] = $this->dialplan_continue;
|
||||
}
|
||||
$sql .= "dialplan_order = '".check_str($this->dialplan_order)."', ";
|
||||
$sql .= "dialplan_context = '".check_str($this->dialplan_context)."', ";
|
||||
$sql .= "dialplan_enabled = '".check_str($this->dialplan_enabled)."', ";
|
||||
$sql .= "dialplan_description = '".check_str($this->dialplan_description)."' ";
|
||||
$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."<br />";
|
||||
$this->db->query($sql);
|
||||
unset($sql);
|
||||
$array['dialplans'][0]['dialplan_order'] = $this->dialplan_order;
|
||||
$array['dialplans'][0]['dialplan_context'] = $this->dialplan_context;
|
||||
$array['dialplans'][0]['dialplan_enabled'] = $this->dialplan_enabled;
|
||||
$array['dialplans'][0]['dialplan_description'] = $this->dialplan_description;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('dialplan_edit', 'temp');
|
||||
//execute update
|
||||
$database = new database;
|
||||
$database->app_name = 'dialplans';
|
||||
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('dialplan_edit', 'temp');
|
||||
}
|
||||
|
||||
public function dialplan_detail_add() {
|
||||
|
||||
//build insert array
|
||||
$dialplan_detail_uuid = uuid();
|
||||
$sql = "insert into v_dialplan_details ";
|
||||
$sql .= "(";
|
||||
$sql .= "dialplan_detail_uuid, ";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "dialplan_uuid, ";
|
||||
$sql .= "dialplan_detail_tag, ";
|
||||
$sql .= "dialplan_detail_order, ";
|
||||
$sql .= "dialplan_detail_type, ";
|
||||
$sql .= "dialplan_detail_data, ";
|
||||
$sql .= "dialplan_detail_break, ";
|
||||
$sql .= "dialplan_detail_inline, ";
|
||||
$sql .= "dialplan_detail_group ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "( ";
|
||||
$sql .= "'".$dialplan_detail_uuid."', ";
|
||||
if ($this->dialplan_global) {
|
||||
$sql .= "null, ";
|
||||
$array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid;
|
||||
$array['dialplan_details'][0]['domain_uuid'] = !$this->dialplan_global ? $this->domain_uuid : null;
|
||||
$array['dialplan_details'][0]['dialplan_uuid'] = $this->dialplan_uuid;
|
||||
$array['dialplan_details'][0]['dialplan_detail_tag'] = $this->dialplan_detail_tag;
|
||||
$array['dialplan_details'][0]['dialplan_detail_order'] = $this->dialplan_detail_order;
|
||||
$array['dialplan_details'][0]['dialplan_detail_type'] = $this->dialplan_detail_type;
|
||||
$array['dialplan_details'][0]['dialplan_detail_data'] = $this->dialplan_detail_data;
|
||||
$array['dialplan_details'][0]['dialplan_detail_break'] = strlen($this->dialplan_detail_break) != 0 ? $this->dialplan_detail_break : null;
|
||||
$array['dialplan_details'][0]['dialplan_detail_inline'] = strlen($this->dialplan_detail_inline) != 0 ? $this->dialplan_detail_inline : null;
|
||||
$array['dialplan_details'][0]['dialplan_detail_group'] = strlen($this->dialplan_detail_group) != 0 ? $this->dialplan_detail_group : null;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('dialplan_detail_add', 'temp');
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'dialplans';
|
||||
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('dialplan_detail_add', 'temp');
|
||||
}
|
||||
else {
|
||||
$sql .= "'".check_str($this->domain_uuid)."', ";
|
||||
}
|
||||
$sql .= "'".check_str($this->dialplan_uuid)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_detail_tag)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_detail_order)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_detail_type)."', ";
|
||||
$sql .= "'".check_str($this->dialplan_detail_data)."', ";
|
||||
if (strlen($this->dialplan_detail_break) == 0) {
|
||||
$sql .= "null, ";
|
||||
}
|
||||
else {
|
||||
$sql .= "'".check_str($this->dialplan_detail_break)."', ";
|
||||
}
|
||||
if (strlen($this->dialplan_detail_inline) == 0) {
|
||||
$sql .= "null, ";
|
||||
}
|
||||
else {
|
||||
$sql .= "'".check_str($this->dialplan_detail_inline)."', ";
|
||||
}
|
||||
if (strlen($this->dialplan_detail_group) == 0) {
|
||||
$sql .= "null ";
|
||||
}
|
||||
else {
|
||||
$sql .= "'".check_str($this->dialplan_detail_group)."' ";
|
||||
}
|
||||
$sql .= ")";
|
||||
//echo $sql."\n\n";
|
||||
$this->db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
} //end function
|
||||
|
||||
public function dialplan_detail_update() {
|
||||
|
||||
$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)."', ";
|
||||
$sql .= "dialplan_detail_data = '".check_str($this->dialplan_detail_data)."', ";
|
||||
if (strlen($this->dialplan_detail_break) > 0) {
|
||||
$sql .= "dialplan_detail_break = '".check_str($this->dialplan_detail_break)."', ";
|
||||
//build update array
|
||||
$array['dialplan_details'][0]['dialplan_detail_uuid'] = $this->dialplan_detail_uuid;
|
||||
$array['dialplan_details'][0]['dialplan_detail_tag'] = $this->dialplan_detail_tag;
|
||||
$array['dialplan_details'][0]['dialplan_detail_order'] = $this->dialplan_detail_order;
|
||||
$array['dialplan_details'][0]['dialplan_detail_type'] = $this->dialplan_detail_type;
|
||||
$array['dialplan_details'][0]['dialplan_detail_data'] = $this->dialplan_detail_data;
|
||||
if (strlen($this->dialplan_detail_break) != 0) {
|
||||
$array['dialplan_details'][0]['dialplan_detail_break'] = $this->dialplan_detail_break;
|
||||
}
|
||||
if (strlen($this->dialplan_detail_inline) > 0) {
|
||||
$sql .= "dialplan_detail_inline = '".check_str($this->dialplan_detail_inline)."', ";
|
||||
if (strlen($this->dialplan_detail_inline) != 0) {
|
||||
$array['dialplan_details'][0]['dialplan_detail_inline'] = $this->dialplan_detail_inline;
|
||||
}
|
||||
if (strlen($this->dialplan_detail_group) > 0) {
|
||||
$sql .= "dialplan_detail_group = '".check_str($this->dialplan_detail_group)."', ";
|
||||
if (strlen($this->dialplan_detail_group) != 0) {
|
||||
$array['dialplan_details'][0]['dialplan_detail_group'] = $this->dialplan_detail_group;
|
||||
}
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('dialplan_detail_edit', 'temp');
|
||||
//execute update
|
||||
$database = new database;
|
||||
$database->app_name = 'dialplans';
|
||||
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('dialplan_detail_edit', 'temp');
|
||||
}
|
||||
$sql .= "dialplan_detail_tag = '".check_str($this->dialplan_detail_tag)."' ";
|
||||
$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."<br />";
|
||||
$this->db->query($sql);
|
||||
unset($sql);
|
||||
} //end function
|
||||
|
||||
public function restore_advanced_xml() {
|
||||
$switch_dialplan_dir = $this->switch_dialplan_dir;
|
||||
|
|
@ -244,39 +207,25 @@ include "root.php";
|
|||
}
|
||||
|
||||
private function app_uuid_exists() {
|
||||
$sql = "select domain_uuid from v_dialplans ";
|
||||
$sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null) ";
|
||||
$sql .= "and app_uuid = '".$this->app_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($result)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result);
|
||||
$sql = "select count(*) from v_dialplans ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
$sql .= "and app_uuid = :app_uuid ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['app_uuid'] = $this->app_uuid;
|
||||
$database = new database;
|
||||
return $database->select($sql, $parameters, 'column') != 0 ? true : false;
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
public function dialplan_exists() {
|
||||
$sql = "select domain_uuid from v_dialplans ";
|
||||
$sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null)";
|
||||
$sql .= "and dialplan_uuid = '".$this->dialplan_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (count($result)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unset($sql, $prep_statement, $result);
|
||||
$sql = "select count(*) from v_dialplans ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null)";
|
||||
$sql .= "and dialplan_uuid = :dialplan_uuid ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['dialplan_uuid'] = $this->dialplan_uuid;
|
||||
$database = new database;
|
||||
return $database->select($sql, $parameters, 'column') != 0 ? true : false;
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
public function import() {
|
||||
|
|
@ -312,11 +261,10 @@ include "root.php";
|
|||
|
||||
//get the list of domains
|
||||
if (!isset($_SESSION['domains'])) {
|
||||
$sql = "select * from v_domains; ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$_SESSION['domains'] = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
unset($sql, $prep_statement);
|
||||
$sql = "select * from v_domains ";
|
||||
$database = new database;
|
||||
$_SESSION['domains'] = $database->select($sql, null, 'all');
|
||||
unset($sql);
|
||||
}
|
||||
|
||||
//check if the dialplan app uuid exists
|
||||
|
|
@ -330,8 +278,6 @@ include "root.php";
|
|||
}
|
||||
//check if the dialplan exists
|
||||
if (!$this->app_uuid_exists()) {
|
||||
//start the transaction
|
||||
$this->db->beginTransaction();
|
||||
//get the attributes
|
||||
$this->dialplan_uuid = uuid();
|
||||
$this->dialplan_name = $dialplan['extension']['@attributes']['name'];
|
||||
|
|
@ -439,8 +385,6 @@ include "root.php";
|
|||
$x++;
|
||||
}
|
||||
}
|
||||
//end the transaction
|
||||
$this->db->commit();
|
||||
//update the session array
|
||||
$_SESSION['upgrade']['app_defaults']['dialplans'][$domain['domain_name']][]['dialplan_name'] = $this->dialplan_name;
|
||||
}
|
||||
|
|
@ -455,10 +399,12 @@ include "root.php";
|
|||
//check the session array if it doesn't exist then build the array
|
||||
if (!is_array($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) {
|
||||
//get the outbound routes from the database
|
||||
$sql = "select * from v_dialplans as d, v_dialplan_details as s ";
|
||||
$sql = "select * ";
|
||||
$sql .= "from v_dialplans as d, ";
|
||||
$sql .= "v_dialplan_details as s ";
|
||||
$sql .= "where ";
|
||||
$sql .= "( ";
|
||||
$sql .= "d.domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "d.domain_uuid = :domain_uuid ";
|
||||
$sql .= "or d.domain_uuid is null ";
|
||||
$sql .= ") ";
|
||||
$sql .= "and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' ";
|
||||
|
|
@ -469,18 +415,19 @@ include "root.php";
|
|||
$sql .= "d.dialplan_name asc, ";
|
||||
$sql .= "d.dialplan_uuid asc, ";
|
||||
$sql .= "s.dialplan_detail_group asc, ";
|
||||
$sql .= "CASE s.dialplan_detail_tag ";
|
||||
$sql .= "WHEN 'condition' THEN 1 ";
|
||||
$sql .= "WHEN 'action' THEN 2 ";
|
||||
$sql .= "WHEN 'anti-action' THEN 3 ";
|
||||
$sql .= "ELSE 100 END, ";
|
||||
$sql .= "case s.dialplan_detail_tag ";
|
||||
$sql .= "when 'condition' then 1 ";
|
||||
$sql .= "when 'action' then 2 ";
|
||||
$sql .= "when 'anti-action' then 3 ";
|
||||
$sql .= "else 100 end, ";
|
||||
$sql .= "s.dialplan_detail_order asc ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$dialplans = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
unset($prep_statement, $sql);
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$database = new database;
|
||||
$dialplans = $database->select($sql, $parameters, 'all');
|
||||
unset($sql, $parameters);
|
||||
$x = 0; $y = 0;
|
||||
if (isset($dialplans)) foreach ($dialplans as &$row) {
|
||||
if (isset($dialplans) && @sizeof($dialplans) != 0) {
|
||||
foreach ($dialplans as &$row) {
|
||||
//if the previous dialplan uuid has not been set then set it
|
||||
if (!isset($previous_dialplan_uuid)) { $previous_dialplan_uuid = $row['dialplan_uuid']; }
|
||||
|
||||
|
|
@ -509,13 +456,16 @@ include "root.php";
|
|||
//set the previous dialplan_uuid
|
||||
$previous_dialplan_uuid = $row['dialplan_uuid'];
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
//set the session array
|
||||
$_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] = $array;
|
||||
} //end if !is_array
|
||||
}
|
||||
|
||||
//find the matching outbound routes
|
||||
if (isset($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) foreach ($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] as $row) {
|
||||
if (isset($row['dialplan_details'])) foreach ($row['dialplan_details'] as $field) {
|
||||
if (isset($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'])) {
|
||||
foreach ($_SESSION[$_SESSION['domain_uuid']]['outbound_routes'] as $row) {
|
||||
if (isset($row['dialplan_details'])) {
|
||||
foreach ($row['dialplan_details'] as $field) {
|
||||
if ($field['dialplan_detail_tag'] == "condition") {
|
||||
if ($field['dialplan_detail_type'] == "destination_number") {
|
||||
$dialplan_detail_data = $field['dialplan_detail_data'];
|
||||
|
|
@ -548,13 +498,15 @@ include "root.php";
|
|||
$dialplan_detail_data = str_replace("\$3", $regex_match_3, $dialplan_detail_data);
|
||||
$this->bridges = $dialplan_detail_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end if isset
|
||||
} // outbound_routes
|
||||
} //if
|
||||
} //foreach
|
||||
} //if
|
||||
} //foreach
|
||||
} //if
|
||||
} //function
|
||||
|
||||
//reads dialplan details from the database to build the xml
|
||||
public function xml () {
|
||||
public function xml() {
|
||||
|
||||
//set the xml array and then concatenate the array to a string
|
||||
/* $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; */
|
||||
|
|
@ -572,88 +524,86 @@ include "root.php";
|
|||
if ($this->source == "dialplans") {
|
||||
//get the data using a join between the dialplans and dialplan details tables
|
||||
$sql = "select dialplan_uuid, dialplan_xml ";
|
||||
$sql .= "from v_dialplans \n";
|
||||
if (isset($this->uuid)) {
|
||||
$sql .= "where dialplan_uuid = '".$this->uuid."' \n";
|
||||
$sql .= "from v_dialplans ";
|
||||
if (is_uuid($this->uuid)) {
|
||||
$sql .= "where dialplan_uuid = :dialplan_uuid ";
|
||||
$parameters['dialplan_uuid'] = $this->uuid;
|
||||
}
|
||||
else {
|
||||
if (isset($this->context)) {
|
||||
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
||||
$sql .= "where dialplan_context = '" . $this->context . "' \n";
|
||||
$sql .= "where dialplan_context = :dialplan_context ";
|
||||
}
|
||||
else {
|
||||
$sql .= "where (dialplan_context = '" . $this->context . "' or dialplan_context = '\${domain_name}') \n";
|
||||
$sql .= "where (dialplan_context = :dialplan_context or dialplan_context = '\${domain_name}') ";
|
||||
}
|
||||
$sql .= "and dialplan_enabled = 'true' \n";
|
||||
$sql .= "and dialplan_enabled = 'true' ";
|
||||
$parameters['dialplan_context'] = $this->context;
|
||||
}
|
||||
}
|
||||
if ($this->is_empty == "dialplan_xml") {
|
||||
$sql .= "and p.dialplan_xml is null \n";
|
||||
$sql .= "and p.dialplan_xml is null ";
|
||||
}
|
||||
$sql .= "order by \n";
|
||||
$sql .= "dialplan_context asc, \n";
|
||||
$sql .= "dialplan_order asc \n";
|
||||
//echo $sql;
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$results = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
//echo $sql;
|
||||
$sql .= "order by ";
|
||||
$sql .= "dialplan_context asc, ";
|
||||
$sql .= "dialplan_order asc ";
|
||||
$database = new database;
|
||||
$results = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($results as $row) {
|
||||
$dialplans[$row["dialplan_uuid"]] = $row["dialplan_xml"];
|
||||
}
|
||||
}
|
||||
unset($sql, $parameters, $results, $row);
|
||||
}
|
||||
|
||||
//get the dialplans from the dialplan details
|
||||
if ($this->source == "details") {
|
||||
|
||||
//get the data using a join between the dialplans and dialplan details tables
|
||||
$sql = "select ";
|
||||
$sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, \n";
|
||||
$sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, \n";
|
||||
$sql .= "s.dialplan_detail_uuid, s.dialplan_detail_tag, s.dialplan_detail_type, s.dialplan_detail_data, \n";
|
||||
$sql .= "s.dialplan_detail_break, s.dialplan_detail_inline, s.dialplan_detail_group, s.dialplan_detail_order \n";
|
||||
$sql .= "from v_dialplans as p, v_dialplan_details as s \n";
|
||||
$sql .= "where p.dialplan_uuid = s.dialplan_uuid \n";
|
||||
$sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, ";
|
||||
$sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, ";
|
||||
$sql .= "s.dialplan_detail_uuid, s.dialplan_detail_tag, s.dialplan_detail_type, s.dialplan_detail_data, ";
|
||||
$sql .= "s.dialplan_detail_break, s.dialplan_detail_inline, s.dialplan_detail_group, s.dialplan_detail_order ";
|
||||
$sql .= "from v_dialplans as p, v_dialplan_details as s ";
|
||||
$sql .= "where p.dialplan_uuid = s.dialplan_uuid ";
|
||||
if ($this->is_empty == "dialplan_xml") {
|
||||
$sql .= "and p.dialplan_xml is null \n";
|
||||
$sql .= "and p.dialplan_xml is null ";
|
||||
}
|
||||
if (isset($this->context)) {
|
||||
if ($this->context == "public" || substr($this->context, 0, 7) == "public@" || substr($this->context, -7) == ".public") {
|
||||
$sql .= "and p.dialplan_context = '" . $this->context . "' \n";
|
||||
$sql .= "and p.dialplan_context = :dialplan_context ";
|
||||
}
|
||||
else {
|
||||
$sql .= "and (p.dialplan_context = '" . $this->context . "' or p.dialplan_context = '\${domain_name}') \n";
|
||||
$sql .= "and (p.dialplan_context = :dialplan_context or p.dialplan_context = '\${domain_name}') ";
|
||||
}
|
||||
$sql .= "and p.dialplan_enabled = 'true' \n";
|
||||
$sql .= "and p.dialplan_enabled = 'true' ";
|
||||
$parameters['dialplan_context'] = $this->context;
|
||||
}
|
||||
if (isset($this->uuid)) {
|
||||
$sql .= "and p.dialplan_uuid = '".$this->uuid."' \n";
|
||||
$sql .= "and s.dialplan_uuid = '".$this->uuid."' \n";
|
||||
if (is_uuid($this->uuid)) {
|
||||
$sql .= "and p.dialplan_uuid = :dialplan_uuid ";
|
||||
$sql .= "and s.dialplan_uuid = :dialplan_uuid ";
|
||||
$parameters['dialplan_uuid'] = $this->uuid;
|
||||
}
|
||||
$sql .= "order by \n";
|
||||
$sql .= "p.dialplan_order asc, \n";
|
||||
$sql .= "p.dialplan_name asc, \n";
|
||||
$sql .= "p.dialplan_uuid asc, \n";
|
||||
$sql .= "s.dialplan_detail_group asc, \n";
|
||||
$sql .= "CASE s.dialplan_detail_tag \n";
|
||||
$sql .= "WHEN 'condition' THEN 1 \n";
|
||||
$sql .= "WHEN 'action' THEN 2 \n";
|
||||
$sql .= "WHEN 'anti-action' THEN 3 \n";
|
||||
$sql .= "ELSE 100 END, \n";
|
||||
$sql .= "s.dialplan_detail_order asc \n";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$results = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
|
||||
//debug info
|
||||
//echo "sql: $sql\n";
|
||||
//echo "<pre>\n";
|
||||
//print_r($results);
|
||||
//echo "</pre>\n";
|
||||
//exit;
|
||||
$sql .= "order by ";
|
||||
$sql .= "p.dialplan_order asc, ";
|
||||
$sql .= "p.dialplan_name asc, ";
|
||||
$sql .= "p.dialplan_uuid asc, ";
|
||||
$sql .= "s.dialplan_detail_group asc, ";
|
||||
$sql .= "case s.dialplan_detail_tag ";
|
||||
$sql .= "when 'condition' then 1 ";
|
||||
$sql .= "when 'action' then 2 ";
|
||||
$sql .= "when 'anti-action' then 3 ";
|
||||
$sql .= "else 100 end, ";
|
||||
$sql .= "s.dialplan_detail_order asc ";
|
||||
$database = new database;
|
||||
$results = $database->select($sql, $parameters, 'all');
|
||||
unset($sql, $parameters);
|
||||
|
||||
//loop through the results to get the xml from the dialplan_xml field or from dialplan details table
|
||||
$x = 0;
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($results as $row) {
|
||||
//clear flag pass
|
||||
$pass = false;
|
||||
|
|
@ -700,12 +650,12 @@ include "root.php";
|
|||
$condition_attribute = "";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
elseif ($condition && (strlen($condition) > 0)) {
|
||||
else if ($condition && (strlen($condition) > 0)) {
|
||||
$xml .= " ".$condition . "/>";
|
||||
$condition = "";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
elseif ($condition_tag_status != "closed") {
|
||||
else if ($condition_tag_status != "closed") {
|
||||
$xml .= " </condition>\n";
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
|
|
@ -737,37 +687,37 @@ include "root.php";
|
|||
if ($dialplan_detail_type == "hour") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "minute") {
|
||||
else if ($dialplan_detail_type == "minute") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "minute-of-day") {
|
||||
else if ($dialplan_detail_type == "minute-of-day") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "mday") {
|
||||
else if ($dialplan_detail_type == "mday") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "mweek") {
|
||||
else if ($dialplan_detail_type == "mweek") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "mon") {
|
||||
else if ($dialplan_detail_type == "mon") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "time-of-day") {
|
||||
else if ($dialplan_detail_type == "time-of-day") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "yday") {
|
||||
else if ($dialplan_detail_type == "yday") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "year") {
|
||||
else if ($dialplan_detail_type == "year") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "wday") {
|
||||
else if ($dialplan_detail_type == "wday") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "week") {
|
||||
else if ($dialplan_detail_type == "week") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
elseif ($dialplan_detail_type == "date-time") {
|
||||
else if ($dialplan_detail_type == "date-time") {
|
||||
$condition_type = 'time';
|
||||
}
|
||||
else {
|
||||
|
|
@ -781,7 +731,7 @@ include "root.php";
|
|||
$condition = '';
|
||||
$condition_tag_status = "closed";
|
||||
}
|
||||
elseif (strlen($condition_attribute) > 0 && $condition_tag_status == "open") {
|
||||
else if (strlen($condition_attribute) > 0 && $condition_tag_status == "open") {
|
||||
// previous condition(s) must have been of type time
|
||||
// do not finalize if new condition is also of type time
|
||||
if ($condition_type != 'time') {
|
||||
|
|
@ -809,10 +759,11 @@ include "root.php";
|
|||
if ($condition_type == "default") {
|
||||
$condition = " <condition field=\"" . $dialplan_detail_type . "\" expression=\"" . $dialplan_detail_data . "\"" . $condition_break;
|
||||
}
|
||||
elseif ($condition_type == "time") {
|
||||
else if ($condition_type == "time") {
|
||||
if ($condition_attribute) {
|
||||
$condition_attribute = $condition_attribute . $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$condition_attribute = $dialplan_detail_type . "=\"" . $dialplan_detail_data . "\" ";
|
||||
}
|
||||
$condition = ""; //prevents a duplicate time condition
|
||||
|
|
@ -829,7 +780,7 @@ include "root.php";
|
|||
$xml .= " <condition " . $condition_attribute . $condition_break . ">\n";
|
||||
$condition_attribute = "";
|
||||
}
|
||||
elseif ($condition && (strlen($condition) > 0)) {
|
||||
else if ($condition && (strlen($condition) > 0)) {
|
||||
$xml .= $condition . ">\n";
|
||||
$condition = "";
|
||||
}
|
||||
|
|
@ -841,14 +792,16 @@ include "root.php";
|
|||
if ($first_action) {
|
||||
//get the domains
|
||||
if (!isset($domains)) {
|
||||
$sql = "select * from v_domains; \n";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$sql = "select * from v_domains ";
|
||||
$database = new database;
|
||||
$result = $database->select($sql, null, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach($result as $row) {
|
||||
$domains[$row['domain_uuid']] = $row['domain_name'];
|
||||
}
|
||||
}
|
||||
unset($sql, $result, $row);
|
||||
}
|
||||
//add the call direction and domain name and uuid
|
||||
$xml .= " <action application=\"export\" data=\"call_direction=inbound\" inline=\"true\"/>\n";
|
||||
if ($domain_uuid != null and $domain_uuid != '') {
|
||||
|
|
@ -879,6 +832,8 @@ include "root.php";
|
|||
//set flag pass
|
||||
$pass = true;
|
||||
}
|
||||
}
|
||||
unset($results, $row);
|
||||
|
||||
// prevent partial dialplan (pass=nil may be error in sql or empty resultset)
|
||||
if ($pass == false) {
|
||||
|
|
@ -893,9 +848,10 @@ include "root.php";
|
|||
if ($condition_attribute and (strlen($condition_attribute) > 0)) {
|
||||
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
|
||||
}
|
||||
elseif ($condition && (strlen($condition) > 0)) {
|
||||
else if ($condition && (strlen($condition) > 0)) {
|
||||
$xml .= $condition . "/>\n";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$xml .= " </condition>\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -920,29 +876,29 @@ include "root.php";
|
|||
//save the dialplan xml
|
||||
if ($this->destination == "database") {
|
||||
if (is_array($dialplans)) {
|
||||
$x = 0;
|
||||
foreach ($dialplans as $key => $value) {
|
||||
$sql = "update v_dialplans ";
|
||||
//$sql .= "set dialplan_xml = ':xml' ";
|
||||
$sql .= "set dialplan_xml = '".check_str($value)."' ";
|
||||
//$sql .= "where dialplan_uuid=:dialplan_uuid ";
|
||||
$sql .= "where dialplan_uuid = '$key';";
|
||||
//$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
//$prep_statement->bindParam(':xml', $value );
|
||||
//$prep_statement->bindParam(':dialplan_uuid', $key);
|
||||
//$prep_statement->execute();
|
||||
//$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
//print_r($result);
|
||||
unset($prep_statement);
|
||||
$this->db->query($sql);
|
||||
unset($sql);
|
||||
//build update array
|
||||
$array['dialplans'][$x]['dialplan_uuid'] = $key;
|
||||
$array['dialplans'][$x]['dialplan_xml'] = $value;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('dialplan_edit', 'temp');
|
||||
//execute update
|
||||
$database = new database;
|
||||
$database->app_name = 'dialplans';
|
||||
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('dialplan_edit', 'temp');
|
||||
}
|
||||
}
|
||||
//return true;
|
||||
}
|
||||
|
||||
} //end method
|
||||
}
|
||||
|
||||
public function defaults () {
|
||||
public function defaults() {
|
||||
|
||||
//get the array of xml files and then process thm
|
||||
$xml_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/resources/switch/conf/dialplan/*.xml");
|
||||
|
|
@ -964,13 +920,14 @@ include "root.php";
|
|||
}
|
||||
|
||||
//update the dialplan order
|
||||
$sql = "update v_dialplans set dialplan_order = '870' where dialplan_order = '980' and dialplan_name = 'cidlookup';\n";
|
||||
$this->db->query($sql);
|
||||
$sql = "update v_dialplans set dialplan_order = '880' where dialplan_order = '990' and dialplan_name = 'call_screen';\n";
|
||||
$this->db->query($sql);
|
||||
$sql = "update v_dialplans set dialplan_order = '890' where dialplan_order = '999' and dialplan_name = 'local_extension';\n";
|
||||
$this->db->query($sql);
|
||||
unset($sql);
|
||||
$sql[] = "update v_dialplans set dialplan_order = '870' where dialplan_order = '980' and dialplan_name = 'cidlookup' ";
|
||||
$sql[] = "update v_dialplans set dialplan_order = '880' where dialplan_order = '990' and dialplan_name = 'call_screen' ";
|
||||
$sql[] = "update v_dialplans set dialplan_order = '890' where dialplan_order = '999' and dialplan_name = 'local_extension' ";
|
||||
$database = new database;
|
||||
foreach ($sql as $query) {
|
||||
$database->execute($query);
|
||||
}
|
||||
unset($sql, $query);
|
||||
|
||||
//add xml for each dialplan where the dialplan xml is empty
|
||||
$this->source = "details";
|
||||
|
|
@ -978,10 +935,11 @@ include "root.php";
|
|||
$this->is_empty = "dialplan_xml";
|
||||
$array = $this->xml();
|
||||
//print_r($array);
|
||||
unset($this->source,$this->destination,$this->is_empty,$array);
|
||||
unset($this->source, $this->destination, $this->is_empty, $array);
|
||||
|
||||
} // end method
|
||||
} // end class
|
||||
} // class_exists
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -27,7 +27,6 @@
|
|||
//define the directory class
|
||||
if (!class_exists('extension')) {
|
||||
class extension {
|
||||
public $db;
|
||||
public $domain_uuid;
|
||||
public $domain_name;
|
||||
private $app_uuid;
|
||||
|
|
@ -72,14 +71,6 @@ if (!class_exists('extension')) {
|
|||
public $description;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//set the application id
|
||||
$this->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
|
||||
}
|
||||
|
|
@ -91,21 +82,18 @@ if (!class_exists('extension')) {
|
|||
}
|
||||
|
||||
public function exists($domain_uuid, $extension) {
|
||||
$sql = "select extension_uuid from v_extensions ";
|
||||
$sql = "select count(*) from v_extensions ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and (extension = :extension or number_alias = :extension) ";
|
||||
$sql .= "and ( ";
|
||||
$sql .= "extension = :extension ";
|
||||
$sql .= "or number_alias = :extension ";
|
||||
$sql .= ") ";
|
||||
$sql .= "and enabled = 'true' ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->bindParam(':domain_uuid', $domain_uuid);
|
||||
$prep_statement->bindParam(':extension', $extension);
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if ($result && count($result) > 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
$parameters['domain_uuid'] = $domain_uuid;
|
||||
$parameters['extension'] = $extension;
|
||||
$database = new database;
|
||||
return $database->select($sql, $parameters, 'column') != 0 ? true : false;
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
public function get_domain_uuid() {
|
||||
|
|
@ -117,7 +105,6 @@ if (!class_exists('extension')) {
|
|||
}
|
||||
|
||||
public function voicemail() {
|
||||
|
||||
//determine the voicemail_id
|
||||
if (is_numeric($this->number_alias)) {
|
||||
$this->voicemail_id = $this->number_alias;
|
||||
|
|
@ -126,66 +113,58 @@ if (!class_exists('extension')) {
|
|||
$this->voicemail_id = $this->extension;
|
||||
}
|
||||
|
||||
//update the voicemail settings
|
||||
$sql = "select * from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (count($result) == 0) {
|
||||
//add the voicemail box
|
||||
$sql = "insert into v_voicemails ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "voicemail_uuid, ";
|
||||
$sql .= "voicemail_id, ";
|
||||
$sql .= "voicemail_password, ";
|
||||
if (strlen($this->greeting_id) > 0) {
|
||||
$sql .= "greeting_id, ";
|
||||
}
|
||||
$sql .= "voicemail_mail_to, ";
|
||||
$sql .= "voicemail_file, ";
|
||||
$sql .= "voicemail_local_after_email, ";
|
||||
$sql .= "voicemail_enabled, ";
|
||||
$sql .= "voicemail_description ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$this->voicemail_id."', ";
|
||||
$sql .= "'".$this->voicemail_password."', ";
|
||||
$sql .= "'".$this->voicemail_mail_to."', ";
|
||||
$sql .= "'".$this->voicemail_file."', ";
|
||||
$sql .= "'".$this->voicemail_local_after_email."', ";
|
||||
$sql .= "'".$this->voicemail_enabled."', ";
|
||||
$sql .= "'".$this->description."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//insert or update the voicemail settings
|
||||
$sql = "select voicemail_uuid from v_voicemails ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and voicemail_id = :voicemail_id ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['voicemail_id'] = $this->voicemail_id;
|
||||
$database = new database;
|
||||
$voicemail_uuid = $database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
|
||||
if (is_uuid($voicemail_uuid)) {
|
||||
//build update array
|
||||
$array['voicemails'][0]['voicemail_uuid'] = $voicemail_uuid;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('voicemail_edit', 'temp');
|
||||
}
|
||||
else {
|
||||
//update the voicemail box
|
||||
$sql = "update v_voicemails set ";
|
||||
$sql .= "voicemail_password = '".$this->voicemail_password."', ";
|
||||
$sql .= "voicemail_mail_to = '".$this->voicemail_mail_to."', ";
|
||||
$sql .= "voicemail_file = '".$this->voicemail_file."', ";
|
||||
$sql .= "voicemail_local_after_email = '".$this->voicemail_local_after_email."', ";
|
||||
$sql .= "voicemail_enabled = '".$this->voicemail_enabled."', ";
|
||||
$sql .= "voicemail_description = '".$this->description."' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
|
||||
$this->db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//build insert array
|
||||
$array['voicemails'][0]['voicemail_uuid'] = uuid();
|
||||
$array['voicemails'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('voicemail_add', 'temp');
|
||||
}
|
||||
unset ($prep_statement);
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//include common array fields
|
||||
$array['voicemails'][0]['voicemail_id'] = $this->voicemail_id;
|
||||
$array['voicemails'][0]['voicemail_password'] = $this->voicemail_password;
|
||||
$array['voicemails'][0]['voicemail_mail_to'] = $this->voicemail_mail_to;
|
||||
$array['voicemails'][0]['voicemail_file'] = $this->voicemail_file;
|
||||
$array['voicemails'][0]['voicemail_local_after_email'] = $this->voicemail_local_after_email;
|
||||
$array['voicemails'][0]['voicemail_enabled'] = $this->voicemail_enabled;
|
||||
$array['voicemails'][0]['voicemail_description'] = $this->description;
|
||||
//execute insert/update
|
||||
$database = new database;
|
||||
$database->app_name = 'extensions';
|
||||
$database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('voicemail_edit', 'temp');
|
||||
$p->delete('voicemail_add', 'temp');
|
||||
}
|
||||
|
||||
unset($voicemail_uuid);
|
||||
}
|
||||
|
||||
public function xml() {
|
||||
if (isset($_SESSION['switch']['extensions']['dir'])) {
|
||||
//declare global variables
|
||||
global $config, $db, $domain_uuid;
|
||||
global $config, $domain_uuid;
|
||||
|
||||
//get the domain_name
|
||||
$domain_name = $_SESSION['domains'][$domain_uuid]['domain_name'];
|
||||
|
|
@ -198,15 +177,18 @@ if (!class_exists('extension')) {
|
|||
}
|
||||
|
||||
//write the xml files
|
||||
$sql = "SELECT * FROM v_extensions AS e, v_voicemails AS v ";
|
||||
$sql .= "WHERE e.domain_uuid = '$domain_uuid' ";
|
||||
$sql .= "AND COALESCE(NULLIF(e.number_alias,''),e.extension) = CAST(v.voicemail_id as VARCHAR) ";
|
||||
$sql .= "ORDER BY e.call_group ASC ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$i = 0;
|
||||
$sql = "select * from v_extensions as e, v_voicemails as v ";
|
||||
$sql .= "where e.domain_uuid = :domain_uuid ";
|
||||
$sql .= "and coalesce(nullif(e.number_alias,''),e.extension) = cast(v.voicemail_id as varchar) ";
|
||||
$sql .= "order by e.call_group asc ";
|
||||
$parameters['domain_uuid'] = $domain_uuid;
|
||||
$database = new database;
|
||||
$rows = $database->select($sql, $parameters, 'all');
|
||||
unset($sql, $parameters);
|
||||
|
||||
$extension_xml_condensed = false;
|
||||
while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (is_array($rows) && @sizeof($rows) != 0) {
|
||||
foreach ($rows as $row) {
|
||||
$call_group = $row['call_group'];
|
||||
$call_group = str_replace(";", ",", $call_group);
|
||||
$tmp_array = explode(",", $call_group);
|
||||
|
|
@ -220,7 +202,6 @@ if (!class_exists('extension')) {
|
|||
$call_group_array[$tmp_call_group] = $call_group_array[$tmp_call_group].','.$row['extension'];
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$call_timeout = $row['call_timeout'];
|
||||
$user_context = $row['user_context'];
|
||||
|
|
@ -434,7 +415,8 @@ if (!class_exists('extension')) {
|
|||
fclose($fout);
|
||||
}
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
unset($rows, $row);
|
||||
|
||||
//prepare extension
|
||||
$extension_dir = realpath($_SESSION['switch']['extensions']['dir']);
|
||||
|
|
|
|||
|
|
@ -25,10 +25,9 @@
|
|||
*/
|
||||
include "root.php";
|
||||
|
||||
//define the directory class
|
||||
class modules {
|
||||
//define the modules class
|
||||
class modules {
|
||||
//define the variables
|
||||
public $db;
|
||||
public $dir;
|
||||
public $fp;
|
||||
public $modules;
|
||||
|
|
@ -656,12 +655,7 @@ include "root.php";
|
|||
if ($this->fp) {
|
||||
$cmd = "api module_exists ".$name;
|
||||
$response = trim(event_socket_request($this->fp, $cmd));
|
||||
if ($response == "true") {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return $response == "true" ? true : false;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
|
@ -672,10 +666,9 @@ include "root.php";
|
|||
public function get_modules() {
|
||||
$sql = " select * from v_modules ";
|
||||
$sql .= "order by module_category, module_label";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->execute();
|
||||
$this->modules = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
unset ($prep_statement, $sql);
|
||||
$database = new database;
|
||||
$this->modules = $database->select($sql, null, 'all');
|
||||
unset($sql);
|
||||
}
|
||||
|
||||
//add missing modules for more module info see http://wiki.freeswitch.com/wiki/Modules
|
||||
|
|
@ -683,6 +676,7 @@ include "root.php";
|
|||
if ($handle = opendir($this->dir)) {
|
||||
$modules_new = '';
|
||||
$module_found = false;
|
||||
$x = 0;
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != "." && $file != "..") {
|
||||
if (substr($file, -3) == ".so" || substr($file, -4) == ".dll") {
|
||||
|
|
@ -701,36 +695,33 @@ include "root.php";
|
|||
$modules_new .= "<li>".$mod['module_label']."</li>\n";
|
||||
//set the order
|
||||
$order = $mod['module_order'];
|
||||
//insert the data
|
||||
$module_uuid = uuid();
|
||||
$sql = "insert into v_modules ";
|
||||
$sql .= "(";
|
||||
$sql .= "module_uuid, ";
|
||||
$sql .= "module_label, ";
|
||||
$sql .= "module_name, ";
|
||||
$sql .= "module_description, ";
|
||||
$sql .= "module_category, ";
|
||||
$sql .= "module_order, ";
|
||||
$sql .= "module_enabled, ";
|
||||
$sql .= "module_default_enabled ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$module_uuid."', ";
|
||||
$sql .= "'".$mod['module_label']."', ";
|
||||
$sql .= "'".$mod['module_name']."', ";
|
||||
$sql .= "'".$mod['module_description']."', ";
|
||||
$sql .= "'".$mod['module_category']."', ";
|
||||
$sql .= "'".$order."', ";
|
||||
$sql .= "'".$mod['module_enabled']."', ";
|
||||
$sql .= "'".$mod['module_default_enabled']."' ";
|
||||
$sql .= ")";
|
||||
$this->db->exec($sql);
|
||||
unset($sql);
|
||||
//build insert array
|
||||
$array['modules'][$x]['module_uuid'] = uuid();
|
||||
$array['modules'][$x]['module_label'] = $mod['module_label'];
|
||||
$array['modules'][$x]['module_name'] = $mod['module_name'];
|
||||
$array['modules'][$x]['module_description'] = $mod['module_description'];
|
||||
$array['modules'][$x]['module_category'] = $mod['module_category'];
|
||||
$array['modules'][$x]['module_order'] = $order;
|
||||
$array['modules'][$x]['module_enabled'] = $mod['module_enabled'];
|
||||
$array['modules'][$x]['module_default_enabled'] = $mod['module_default_enabled'];
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('module_add', 'temp');
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'modules';
|
||||
$database->app_uuid = '5eb9cba1-8cb6-5d21-e36a-775475f16b5e';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('module_add', 'temp');
|
||||
}
|
||||
closedir($handle);
|
||||
if ($module_found) {
|
||||
$msg = "<strong>Added New Modules:</strong><br />\n";
|
||||
|
|
@ -747,22 +738,19 @@ include "root.php";
|
|||
//set the globals
|
||||
global $config, $domain_uuid;
|
||||
|
||||
//get the database connection
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$db = $database->db;
|
||||
|
||||
//compose xml
|
||||
$xml = "<configuration name=\"modules.conf\" description=\"Modules\">\n";
|
||||
$xml .= " <modules>\n";
|
||||
|
||||
$sql = "select * from v_modules ";
|
||||
$sql .= "order by module_order ASC, ";
|
||||
$sql .= "module_category ASC";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$sql .= "order by module_order asc, ";
|
||||
$sql .= "module_category asc ";
|
||||
$database = new database;
|
||||
$result = $database->select($sql, null, 'all');
|
||||
unset($sql);
|
||||
|
||||
$prev_module_cat = '';
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach ($result as $row) {
|
||||
if ($prev_module_cat != $row['module_category']) {
|
||||
$xml .= "\n <!-- ".$row['module_category']." -->\n";
|
||||
|
|
@ -772,6 +760,9 @@ include "root.php";
|
|||
}
|
||||
$prev_module_cat = $row['module_category'];
|
||||
}
|
||||
}
|
||||
unset($result, $row);
|
||||
|
||||
$xml .= "\n";
|
||||
$xml .= " </modules>\n";
|
||||
$xml .= "</configuration>";
|
||||
|
|
@ -783,18 +774,15 @@ include "root.php";
|
|||
|
||||
//apply settings
|
||||
$_SESSION["reload_xml"] = true;
|
||||
|
||||
}
|
||||
} //class
|
||||
|
||||
//add the database structure
|
||||
}
|
||||
|
||||
/*
|
||||
require_once "resources/classes/modules.php";
|
||||
$mod = new modules;
|
||||
$mod->dir = $_SESSION['switch']['mod']['dir'];
|
||||
echo $mod->dir."\n";
|
||||
//database connection object
|
||||
$mod->db = $db;
|
||||
//get modules from the database
|
||||
$mod->get_modules();
|
||||
//module exists
|
||||
|
|
|
|||
|
|
@ -8,19 +8,11 @@
|
|||
if (!class_exists('registrations')) {
|
||||
class registrations {
|
||||
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -47,16 +39,13 @@ if (!class_exists('registrations')) {
|
|||
//get the default settings
|
||||
$sql = "select sip_profile_name from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_enabled = 'true' ";
|
||||
if ($profile == 'all' || $profile == '') {
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($profile != 'all' && $profile != '') {
|
||||
$sql .= "and sip_profile_name = :sip_profile_name ";
|
||||
$parameters['sip_profile_name'] = $profile;
|
||||
}
|
||||
else {
|
||||
$sql .= "and sip_profile_name=:sip_profile_name ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->bindParam(':sip_profile_name', $profile);
|
||||
}
|
||||
$prep_statement->execute();
|
||||
$sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$database = new database;
|
||||
$sip_profiles = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
|
||||
foreach ($sip_profiles as $field) {
|
||||
|
||||
//get sofia status profile information including registrations
|
||||
|
|
@ -73,7 +62,7 @@ if (!class_exists('registrations')) {
|
|||
echo $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
$array = json_decode(json_encode($xml) , true);
|
||||
$array = json_decode(json_encode($xml), true);
|
||||
}
|
||||
|
||||
//normalize the array
|
||||
|
|
@ -104,9 +93,10 @@ if (!class_exists('registrations')) {
|
|||
$registrations[$id]['sip_profile_name'] = $field['sip_profile_name'];
|
||||
|
||||
//get network-ip to url or blank
|
||||
if(isset($row['network-ip'])) {
|
||||
if (isset($row['network-ip'])) {
|
||||
$registrations[$id]['network-ip'] = $row['network-ip'];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$registrations[$id]['network-ip'] = '';
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +116,8 @@ if (!class_exists('registrations')) {
|
|||
$lan_ip = preg_replace('/_/', '.', $lan_ip);
|
||||
}
|
||||
$registrations[$id]['lan-ip'] = $lan_ip;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$registrations[$id]['lan-ip'] = '';
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +125,7 @@ if (!class_exists('registrations')) {
|
|||
if (count($_SESSION["domains"]) > 1) {
|
||||
if (!(permission_exists('registration_all') && $profile == "all")) {
|
||||
if ($registrations[$id]['sip-auth-realm'] == $_SESSION['domain_name']) {}
|
||||
elseif ($user_array[1] == $_SESSION['domain_name']){}
|
||||
else if ($user_array[1] == $_SESSION['domain_name']) {}
|
||||
else {
|
||||
unset($registrations[$id]);
|
||||
}
|
||||
|
|
@ -147,6 +138,7 @@ if (!class_exists('registrations')) {
|
|||
unset($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return the registrations array
|
||||
return $registrations;
|
||||
|
|
@ -166,16 +158,13 @@ if (!class_exists('registrations')) {
|
|||
//get the default settings
|
||||
$sql = "select sip_profile_name from v_sip_profiles ";
|
||||
$sql .= "where sip_profile_enabled = 'true' ";
|
||||
if ($profile == 'all' || $profile == '') {
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($profile != 'all' && $profile != '') {
|
||||
$sql .= "and sip_profile_name = :sip_profile_name ";
|
||||
$parameters['sip_profile_name'] = $profile;
|
||||
}
|
||||
else {
|
||||
$sql .= "and sip_profile_name=:sip_profile_name ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
$prep_statement->bindParam(':sip_profile_name', $profile);
|
||||
}
|
||||
$prep_statement->execute();
|
||||
$sip_profiles = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$database = new database;
|
||||
$sip_profiles = $database->select($sql, $parameters, 'all');
|
||||
if (is_array($sip_profiles) && @sizeof($sip_profiles) != 0) {
|
||||
foreach ($sip_profiles as $field) {
|
||||
|
||||
//get sofia status profile information including registrations
|
||||
|
|
@ -193,11 +182,12 @@ if (!class_exists('registrations')) {
|
|||
echo $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
$array = json_decode(json_encode($xml) , true);
|
||||
$array = json_decode(json_encode($xml), true);
|
||||
$count = $count + count($array['registrations']['registration']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//return the registrations count
|
||||
return $count;
|
||||
|
|
@ -205,6 +195,7 @@ if (!class_exists('registrations')) {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
$obj = new registrations;
|
||||
$registrations = $obj->get('all');
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@ if (!class_exists('scripts')) {
|
|||
* Called when the object is created
|
||||
*/
|
||||
public function __construct() {
|
||||
//connect to the database if not connected
|
||||
require_once "resources/classes/database.php";
|
||||
//get database properties
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$this->db = $database->db;
|
||||
|
|
@ -137,35 +136,16 @@ if (!class_exists('scripts')) {
|
|||
$this->db_path = str_replace("\\", "/", $this->db_path);
|
||||
|
||||
//get the odbc information
|
||||
$sql = "select count(*) as num_rows from v_databases ";
|
||||
$sql .= "where database_driver = 'odbc' ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
unset($prep_statement);
|
||||
if ($row['num_rows'] > 0) {
|
||||
$odbc_num_rows = $row['num_rows'];
|
||||
|
||||
$sql = "select * from v_databases ";
|
||||
$sql .= "where database_driver = 'odbc' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (is_array($result)) {
|
||||
foreach ($result as &$row) {
|
||||
$database = new database;
|
||||
$row = $database->select($sql, null, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
$this->dsn_name = $row["database_name"];
|
||||
$this->dsn_username = $row["database_username"];
|
||||
$this->dsn_password = $row["database_password"];
|
||||
break; //limit to 1 row
|
||||
}
|
||||
unset ($prep_statement);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$odbc_num_rows = '0';
|
||||
}
|
||||
}
|
||||
unset($sql, $row);
|
||||
|
||||
//get the recordings directory
|
||||
if (is_array($_SESSION['switch']['recordings'])) {
|
||||
|
|
@ -183,7 +163,8 @@ if (!class_exists('scripts')) {
|
|||
//find the location to write the config.lua
|
||||
if (is_dir("/etc/fusionpbx")){
|
||||
$config = "/etc/fusionpbx/config.lua";
|
||||
} elseif (is_dir("/usr/local/etc/fusionpbx")){
|
||||
}
|
||||
else if (is_dir("/usr/local/etc/fusionpbx")){
|
||||
$config = "/usr/local/etc/fusionpbx/config.lua";
|
||||
}
|
||||
else {
|
||||
|
|
@ -346,9 +327,11 @@ if (!class_exists('scripts')) {
|
|||
unset($tmp);
|
||||
fclose($fout);
|
||||
}
|
||||
} //end config_lua
|
||||
} //end scripts class
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//example use
|
||||
|
||||
|
|
@ -356,4 +339,5 @@ if (!class_exists('scripts')) {
|
|||
$obj = new scripts;
|
||||
$obj->write_config();
|
||||
*/
|
||||
|
||||
?>
|
||||
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
//define the voicemail class
|
||||
class voicemail {
|
||||
public $db;
|
||||
public $domain_uuid;
|
||||
public $domain_name;
|
||||
public $voicemail_uuid;
|
||||
|
|
@ -37,14 +36,6 @@
|
|||
public $app_uuid;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//set the application specific uuid
|
||||
$this->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
|
||||
|
||||
|
|
@ -63,60 +54,55 @@
|
|||
public function get_voicemail_id() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_uuid($this->voicemail_uuid) && is_uuid($this->domain_uuid) ) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_uuid($this->voicemail_uuid) || !is_uuid($this->domain_uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the voicemail id if it isn't set already
|
||||
if (!isset($this->voicemail_id)) {
|
||||
$sql = "select voicemail_id from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (is_array($result)) foreach ($result as &$row) {
|
||||
$this->voicemail_id = $row["voicemail_id"];
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and voicemail_uuid = :voicemail_uuid ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
$database = new database;
|
||||
$voicemail_id = $database->select($sql, $parameters, 'column');
|
||||
if (is_numeric($voicemail_id)) {
|
||||
$this->voicemail_id = $voicemail_id;
|
||||
}
|
||||
unset ($prep_statement);
|
||||
unset($sql, $parameters, $voicemail_id);
|
||||
}
|
||||
}
|
||||
|
||||
public function voicemails() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_uuid($this->domain_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_uuid($this->domain_uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//set the voicemail id and voicemail uuid arrays
|
||||
if (isset($_SESSION['user']['extension'])) foreach ($_SESSION['user']['extension'] as $index => $row) {
|
||||
if (strlen($row['number_alias']) > 0) {
|
||||
$voicemail_ids[$index]['voicemail_id'] = $row['number_alias'];
|
||||
}
|
||||
else {
|
||||
$voicemail_ids[$index]['voicemail_id'] = $row['user'];
|
||||
if (isset($_SESSION['user']['extension'])) {
|
||||
foreach ($_SESSION['user']['extension'] as $index => $row) {
|
||||
$voicemail_ids[$index]['voicemail_id'] = strlen($row['number_alias']) > 0 ? $row['number_alias'] : $row['user'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['user']['voicemail'])) foreach ($_SESSION['user']['voicemail'] as $row) {
|
||||
if (isset($_SESSION['user']['voicemail'])) {
|
||||
foreach ($_SESSION['user']['voicemail'] as $row) {
|
||||
if (strlen($row['voicemail_uuid']) > 0) {
|
||||
$voicemail_uuids[]['voicemail_uuid'] = $row['voicemail_uuid'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//get the uuid and voicemail_id
|
||||
$sql = "select * from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
if (strlen($this->voicemail_uuid) > 0) {
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
if (is_uuid($this->voicemail_uuid)) {
|
||||
if (permission_exists('voicemail_delete')) {
|
||||
//view specific voicemail box usually reserved for an admin or superadmin
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = :voicemail_uuid ";
|
||||
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
}
|
||||
else {
|
||||
//ensure that the requested voicemail box is assigned to this user
|
||||
|
|
@ -124,10 +110,10 @@
|
|||
if (is_array($voicemail_uuids)) {
|
||||
foreach($voicemail_uuids as $row) {
|
||||
if ($voicemail_uuid == $row['voicemail_uuid']) {
|
||||
$sql .= "and voicemail_uuid = '".$row['voicemail_uuid']."' ";
|
||||
$sql .= "and voicemail_uuid = :voicemail_uuid ";
|
||||
$parameters['voicemail_uuid'] = $row['voicemail_uuid'];
|
||||
$found = true;
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
//id requested is not owned by the user return no results
|
||||
|
|
@ -137,20 +123,18 @@
|
|||
}
|
||||
}
|
||||
else {
|
||||
$x = 0;
|
||||
if (count($voicemail_ids) > 0) {
|
||||
if (is_array($voicemail_ids) && @sizeof($voicemail_ids) != 0) {
|
||||
//show only the assigned voicemail ids
|
||||
$sql .= "and (";
|
||||
if (is_array($voicemail_ids)) foreach($voicemail_ids as $row) {
|
||||
if ($x == 0) {
|
||||
$sql .= "voicemail_id = '".$row['voicemail_id']."' ";
|
||||
}
|
||||
else {
|
||||
$sql .= " or voicemail_id = '".$row['voicemail_id']."'";
|
||||
}
|
||||
$x = 0;
|
||||
$sql .= "and ( ";
|
||||
foreach($voicemail_ids as $row) {
|
||||
$sql_where_or[] = "voicemail_id = :voicemail_id_".$x;
|
||||
$parameters['voicemail_id_'.$x] = $row['voicemail_id'];
|
||||
$x++;
|
||||
}
|
||||
$sql .= ")";
|
||||
$sql .= implode(' or ', $sql_where_or);
|
||||
$sql .= ") ";
|
||||
unset($sql_where_or);
|
||||
}
|
||||
else {
|
||||
//no assigned voicemail ids so return no results
|
||||
|
|
@ -158,10 +142,10 @@
|
|||
}
|
||||
}
|
||||
$sql .= "order by voicemail_id asc ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
unset ($prep_statement);
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
unset($sql, $parameters);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +154,8 @@
|
|||
$voicemails = $this->voicemails();
|
||||
|
||||
//add the voicemail messages to the array
|
||||
if (is_array($voicemails)) foreach ($voicemails as &$row) {
|
||||
if (is_array($voicemails)) {
|
||||
foreach ($voicemails as &$row) {
|
||||
//get the voicemail messages
|
||||
$this->voicemail_uuid = $row['voicemail_uuid'];
|
||||
$this->voicemail_id = $row['voicemail_id'];
|
||||
|
|
@ -178,6 +163,7 @@
|
|||
$voicemail_count = count($result);
|
||||
$row['messages'] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
//return the array
|
||||
return $voicemails;
|
||||
|
|
@ -186,43 +172,40 @@
|
|||
public function voicemail_messages() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_numeric($this->voicemail_id) && is_uuid($this->domain_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_numeric($this->voicemail_id) || !is_uuid($this->domain_uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the message from the database
|
||||
$sql = "select * from v_voicemail_messages as m, v_voicemails as v ";
|
||||
$sql .= "where m.domain_uuid = '$this->domain_uuid' ";
|
||||
$sql .= "where m.domain_uuid = :domain_uuid ";
|
||||
$sql .= "and m.voicemail_uuid = v.voicemail_uuid ";
|
||||
if (is_array($this->voicemail_id)) {
|
||||
$sql .= "and (";
|
||||
if (is_array($this->voicemail_id) && @sizeof($this->voicemail_id) != 0) {
|
||||
$x = 0;
|
||||
if (is_array($this->voicemail_id)) foreach($this->voicemail_id as $row) {
|
||||
if ($x > 0) {
|
||||
$sql .= "or ";
|
||||
}
|
||||
$sql .= "v.voicemail_id = '".$row['voicemail_id']."' ";
|
||||
$sql .= "and ( ";
|
||||
foreach ($this->voicemail_id as $row) {
|
||||
$sql_where_or[] = "v.voicemail_id = :voicemail_id_".$x;
|
||||
$parameters['voicemail_id_'.$x] = $row['voicemail_id'];
|
||||
$x++;
|
||||
}
|
||||
$sql .= implode(' or ', $sql_where_or);
|
||||
$sql .= ") ";
|
||||
unset($sql_where_or);
|
||||
}
|
||||
else {
|
||||
$sql .= "and v.voicemail_id = '$this->voicemail_id' ";
|
||||
$sql .= "and v.voicemail_id = :voicemail_id ";
|
||||
$parameters['voicemail_id'] = $this->voicemail_id;
|
||||
}
|
||||
if (strlen($this->order_by) == 0) {
|
||||
$sql .= "order by v.voicemail_id, m.created_epoch desc ";
|
||||
}
|
||||
else {
|
||||
$sql .= "order by v.voicemail_id, m.$this->order_by $this->order ";
|
||||
$sql .= "order by v.voicemail_id, m.".$this->order_by." ".$this->order." ";
|
||||
}
|
||||
//$sql .= "limit $this->rows_per_page offset $this->offset ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
unset ($prep_statement, $sql);
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$database = new database;
|
||||
$result = $database->select($sql, $parameters, 'all');
|
||||
unset($sql, $parameters);
|
||||
|
||||
//update the array with additional information
|
||||
if (is_array($result)) {
|
||||
|
|
@ -259,11 +242,7 @@
|
|||
$this->get_voicemail_id();
|
||||
|
||||
//check if for valid input
|
||||
if (is_uuid($this->voicemail_uuid)
|
||||
&& is_uuid($this->domain_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_uuid($this->voicemail_uuid) || !is_uuid($this->domain_uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -279,69 +258,67 @@
|
|||
@rmdir($file_path);
|
||||
}
|
||||
|
||||
//delete voicemail destinations
|
||||
$sql = "delete from v_voicemail_destinations ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql, $prep_statement);
|
||||
//build voicemail destinations delete array
|
||||
$array['voicemail_destinations'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['voicemail_destinations'][0]['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
|
||||
//delete voicemail greetings
|
||||
//build voicemail greetings delete array
|
||||
if (is_numeric($this->voicemail_id)) {
|
||||
$sql = "delete from v_voicemail_greetings ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql, $prep_statement);
|
||||
$array['voicemail_greetings'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['voicemail_greetings'][0]['voicemail_id'] = $this->voicemail_id;
|
||||
}
|
||||
|
||||
//delete voicemail options
|
||||
$sql = "delete from v_voicemail_options ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql, $prep_statement);
|
||||
//build voicemail options delete array
|
||||
$array['voicemail_options'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['voicemail_options'][0]['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
|
||||
//build voicemail delete array
|
||||
$array['voicemails'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['voicemails'][0]['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('voicemail_destination_delete', 'temp');
|
||||
if (is_numeric($this->voicemail_id)) {
|
||||
$p->add('voicemail_greeting_delete', 'temp');
|
||||
}
|
||||
$p->add('voicemail_option_delete', 'temp');
|
||||
$p->add('voicemail_delete', 'temp');
|
||||
|
||||
//execute delete
|
||||
$database = new database;
|
||||
$database->app_name = 'voicemails';
|
||||
$database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
|
||||
$database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('voicemail_destination_delete', 'temp');
|
||||
if (is_numeric($this->voicemail_id)) {
|
||||
$p->delete('voicemail_greeting_delete', 'temp');
|
||||
}
|
||||
$p->delete('voicemail_option_delete', 'temp');
|
||||
$p->delete('voicemail_delete', 'temp');
|
||||
|
||||
//delete voicemail
|
||||
$sql = "delete from v_voicemails ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql, $prep_statement);
|
||||
}
|
||||
|
||||
public function message_count() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_uuid($this->voicemail_uuid) && is_uuid($this->domain_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_uuid($this->voicemail_uuid) || !is_uuid($this->domain_uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the message count
|
||||
$sql = "select count(*) as num_rows from v_voicemail_messages ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$prep_statement = $this->db->prepare($sql);
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row['num_rows'] > 0) {
|
||||
$num_rows = $row['num_rows'];
|
||||
}
|
||||
else {
|
||||
$num_rows = '0';
|
||||
}
|
||||
}
|
||||
|
||||
//return the message count
|
||||
return $num_rows;
|
||||
$sql = "select count(*) from v_voicemail_messages ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and voicemail_uuid = :voicemail_uuid ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
$database = new database;
|
||||
return $database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
|
||||
}
|
||||
|
||||
public function message_waiting() {
|
||||
|
|
@ -362,19 +339,17 @@
|
|||
$this->get_voicemail_id();
|
||||
|
||||
//check if for valid input
|
||||
if (is_numeric($this->voicemail_id)
|
||||
&& is_uuid($this->voicemail_uuid)
|
||||
&& is_uuid($this->domain_uuid)
|
||||
&& is_uuid($this->voicemail_message_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_numeric($this->voicemail_id)
|
||||
|| !is_uuid($this->voicemail_uuid)
|
||||
|| !is_uuid($this->domain_uuid)
|
||||
|| !is_uuid($this->voicemail_message_uuid)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//delete the recording
|
||||
$file_path = $_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$this->voicemail_id;
|
||||
if ($this->voicemail_message_uuid != '') {
|
||||
if (is_uuid($this->voicemail_message_uuid)) {
|
||||
foreach (glob($file_path."/intro_".$this->voicemail_message_uuid.".*") as $file_name) {
|
||||
unlink($file_name);
|
||||
}
|
||||
|
|
@ -388,16 +363,26 @@
|
|||
}
|
||||
}
|
||||
|
||||
//delete voicemail message(s)
|
||||
$sql = "delete from v_voicemail_messages ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
if ($this->voicemail_message_uuid != '') {
|
||||
$sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
|
||||
//build delete array
|
||||
$array['voicemail_messages'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['voicemail_messages'][0]['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
if (is_uuid($this->voicemail_message_uuid)) {
|
||||
$array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
|
||||
}
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql);
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('voicemail_message_delete', 'temp');
|
||||
|
||||
//execute delete
|
||||
$database = new database;
|
||||
$database->app_name = 'voicemails';
|
||||
$database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
|
||||
$database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('voicemail_message_delete', 'temp');
|
||||
|
||||
//check the message waiting status
|
||||
$this->message_waiting();
|
||||
|
|
@ -406,35 +391,38 @@
|
|||
public function message_toggle() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_uuid($this->voicemail_uuid)
|
||||
&& is_uuid($this->domain_uuid)
|
||||
&& is_uuid($this->voicemail_message_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_uuid($this->voicemail_uuid)
|
||||
|| !is_uuid($this->domain_uuid)
|
||||
|| !is_uuid($this->voicemail_message_uuid)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//get message status
|
||||
$sql = "select message_status from v_voicemail_messages ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$row = $prep_statement->fetch(PDO::FETCH_NAMED);
|
||||
$new_status = ($row['message_status'] == 'saved') ? 'null' : "'saved'";
|
||||
unset($sql, $prep_statement, $row);
|
||||
$sql .= "where voicemail_message_uuid = :voicemail_message_uuid ";
|
||||
$parameters['voicemail_message_uuid'] = $this->voicemail_message_uuid;
|
||||
$database = new database;
|
||||
$new_status = $database->select($sql, $parameters, 'column') != 'saved' ? 'saved' : null;
|
||||
unset($sql, $parameters);
|
||||
|
||||
//set message status
|
||||
$sql = "update v_voicemail_messages set ";
|
||||
$sql .= "message_status = ".$new_status." ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql, $prep_statement);
|
||||
//build message status update array
|
||||
$array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
|
||||
$array['voicemail_messages'][0]['message_status'] = $new_status;
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('voicemail_message_edit', 'temp');
|
||||
|
||||
//execute update
|
||||
$database = new database;
|
||||
$database->app_name = 'voicemails';
|
||||
$database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('voicemail_message_edit', 'temp');
|
||||
|
||||
//check the message waiting status
|
||||
$this->message_waiting();
|
||||
|
|
@ -443,24 +431,30 @@
|
|||
public function message_saved() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_uuid($this->voicemail_uuid)
|
||||
&& is_uuid($this->domain_uuid)
|
||||
&& is_uuid($this->voicemail_message_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_uuid($this->voicemail_uuid)
|
||||
|| !is_uuid($this->domain_uuid)
|
||||
|| !is_uuid($this->voicemail_message_uuid)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//set the voicemail status to saved
|
||||
$sql = "update v_voicemail_messages set ";
|
||||
$sql .= "message_status = 'saved' ";
|
||||
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$sql .= "and voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
unset($sql, $prep_statement);
|
||||
//build message status update array
|
||||
$array['voicemail_messages'][0]['voicemail_message_uuid'] = $this->voicemail_message_uuid;
|
||||
$array['voicemail_messages'][0]['message_status'] = 'saved';
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('voicemail_message_edit', 'temp');
|
||||
|
||||
//execute update
|
||||
$database = new database;
|
||||
$database->app_name = 'voicemails';
|
||||
$database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('voicemail_message_edit', 'temp');
|
||||
|
||||
//check the message waiting status
|
||||
$this->message_waiting();
|
||||
|
|
@ -469,13 +463,11 @@
|
|||
public function message_download() {
|
||||
|
||||
//check if for valid input
|
||||
if (is_numeric($this->voicemail_id)
|
||||
&& is_uuid($this->voicemail_uuid)
|
||||
&& is_uuid($this->domain_uuid)
|
||||
&& is_uuid($this->voicemail_message_uuid)) {
|
||||
//input is valid
|
||||
}
|
||||
else {
|
||||
if (!is_numeric($this->voicemail_id)
|
||||
|| !is_uuid($this->voicemail_uuid)
|
||||
|| !is_uuid($this->domain_uuid)
|
||||
|| !is_uuid($this->voicemail_message_uuid)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -490,22 +482,24 @@
|
|||
|
||||
//prepare base64 content from db, if enabled
|
||||
if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') {
|
||||
$sql = "select message_base64 from ";
|
||||
$sql = "select message_base64 ";
|
||||
$sql .= "from ";
|
||||
$sql .= "v_voicemail_messages as m, ";
|
||||
$sql .= "v_voicemails as v ";
|
||||
$sql .= "where ";
|
||||
$sql .= "m.voicemail_uuid = v.voicemail_uuid ";
|
||||
$sql .= "and v.voicemail_id = '".$this->voicemail_id."' ";
|
||||
$sql .= "and m.voicemail_uuid = '".$this->voicemail_uuid."' ";
|
||||
$sql .= "and m.domain_uuid = '".$this->domain_uuid."' ";
|
||||
$sql .= "and m.voicemail_message_uuid = '".$this->voicemail_message_uuid."' ";
|
||||
$prep_statement = $this->db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
if (is_array($result)) {
|
||||
foreach($result as &$row) {
|
||||
if ($row['message_base64'] != '') {
|
||||
$message_decoded = base64_decode($row['message_base64']);
|
||||
$sql .= "and v.voicemail_id = :voicemail_id ";
|
||||
$sql .= "and m.voicemail_uuid = :voicemail_uuid ";
|
||||
$sql .= "and m.domain_uuid = :domain_uuid ";
|
||||
$sql .= "and m.voicemail_message_uuid = :voicemail_message_uuid ";
|
||||
$parameters['voicemail_id'] = $this->voicemail_id;
|
||||
$parameters['voicemail_uuid'] = $this->voicemail_uuid;
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
$parameters['voicemail_message_uuid'] = $this->voicemail_message_uuid;
|
||||
$database = new database;
|
||||
$message_base64 = $database->select($sql, $parameters, 'column');
|
||||
if ($message_base64 != '') {
|
||||
$message_decoded = base64_decode($message_base64);
|
||||
file_put_contents($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $message_decoded);
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE); //determine mime type (requires PHP >= 5.3.0, must be manually enabled on Windows)
|
||||
$file_mime = finfo_file($finfo, $path.'/msg_'.$this->voicemail_message_uuid.'.ext');
|
||||
|
|
@ -522,10 +516,7 @@
|
|||
}
|
||||
rename($path.'/msg_'.$this->voicemail_message_uuid.'.ext', $path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset ($sql, $prep_statement, $result, $message_decoded);
|
||||
unset($sql, $parameters, $message_base64, $message_decoded);
|
||||
}
|
||||
|
||||
//prepare and stream the file
|
||||
|
|
@ -571,7 +562,8 @@
|
|||
@unlink($path.'/msg_'.$this->voicemail_message_uuid.'.'.$file_ext);
|
||||
}
|
||||
|
||||
} // download
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//example voicemail messages
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@
|
|||
$voicemail_uuid = $_REQUEST["voicemail_uuid"];
|
||||
if (is_uuid($voicemail_message_uuid) && $voicemail_id != '' && is_uuid($voicemail_uuid)) {
|
||||
$voicemail = new voicemail;
|
||||
$voicemail->db = $db;
|
||||
$voicemail->domain_uuid = $_SESSION['domain_uuid'];
|
||||
$voicemail->voicemail_id = $voicemail_id;
|
||||
$voicemail->voicemail_uuid = $voicemail_uuid;
|
||||
|
|
@ -76,7 +75,6 @@
|
|||
|
||||
//get the voicemail
|
||||
$vm = new voicemail;
|
||||
$vm->db = $db;
|
||||
$vm->domain_uuid = $_SESSION['domain_uuid'];
|
||||
$vm->voicemail_uuid = $voicemail_uuid;
|
||||
$vm->order_by = $order_by;
|
||||
|
|
|
|||
|
|
@ -26,47 +26,28 @@ class plugin_database {
|
|||
*/
|
||||
function database() {
|
||||
|
||||
//save the database connection to a local variable
|
||||
include "root.php";
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$db = $database->db;
|
||||
//set the default status
|
||||
$user_authorized = false;
|
||||
|
||||
//check the username and password if they don't match then redirect to the login
|
||||
$sql = "select * from v_users ";
|
||||
$sql = "select * from v_users where ";
|
||||
if (strlen($this->key) > 30) {
|
||||
$sql .= "where api_key = :key ";
|
||||
//$sql .= "where api_key = '".$this->key."' ";
|
||||
$sql .= "api_key = :key ";
|
||||
$parameters['api_key'] = $this->key;
|
||||
}
|
||||
else {
|
||||
$sql .= "where lower(username) = lower(:username) ";
|
||||
//$sql .= "where username = '".$this->username."' ";
|
||||
$sql .= "lower(username) = lower(:username) ";
|
||||
$parameters['username'] = $this->username;
|
||||
}
|
||||
if ($_SESSION["users"]["unique"]["text"] == "global") {
|
||||
//unique username - global (example: email address)
|
||||
}
|
||||
else {
|
||||
//unique username - per domain
|
||||
if ($_SESSION["users"]["unique"]["text"] != "global") {
|
||||
//unique username per domain (not globally unique across system - example: email address)
|
||||
$sql .= "and domain_uuid = :domain_uuid ";
|
||||
//$sql .= "and domain_uuid = '".$this->domain_uuid."' ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$sql .= "and (user_enabled = 'true' or user_enabled is null) ";
|
||||
$prep_statement = $db->prepare($sql);
|
||||
if ($_SESSION["users"]["unique"]["text"] != "global") {
|
||||
$prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
|
||||
}
|
||||
if (strlen($this->key) > 30) {
|
||||
$prep_statement->bindParam(':key', $this->key);
|
||||
}
|
||||
if (strlen($this->username) > 0) {
|
||||
$prep_statement->bindParam(':username', $this->username);
|
||||
}
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$user_authorized = false;
|
||||
if (is_array($result)) {
|
||||
foreach ($result as &$row) {
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
|
||||
//get the domain uuid when users are unique globally
|
||||
if ($_SESSION["users"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
|
||||
|
|
@ -96,15 +77,11 @@ class plugin_database {
|
|||
//compare the password provided by the user with the one in the database
|
||||
if (md5($row["salt"].$this->password) == $row["password"]) {
|
||||
$user_authorized = true;
|
||||
} elseif (strlen($this->key) > 30 && $this->key == $row["api_key"]) {
|
||||
}
|
||||
else if (strlen($this->key) > 30 && $this->key == $row["api_key"]) {
|
||||
$user_authorized = true;
|
||||
} else {
|
||||
$user_authorized = false;
|
||||
}
|
||||
|
||||
//end the loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($result);
|
||||
|
||||
|
|
@ -119,12 +96,8 @@ class plugin_database {
|
|||
$result["domain_uuid"] = $this->domain_uuid;
|
||||
$result["contact_uuid"] = $this->contact_uuid;
|
||||
$result["sql"] = $sql;
|
||||
if ($user_authorized) {
|
||||
$result["authorized"] = "true";
|
||||
}
|
||||
else {
|
||||
$result["authorized"] = "false";
|
||||
}
|
||||
$result["authorized"] = $user_authorized ? 'true' : 'false';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,6 @@ class plugin_ldap {
|
|||
*/
|
||||
function ldap() {
|
||||
|
||||
//save the database connection to a local variable
|
||||
include "root.php";
|
||||
require_once "resources/classes/database.php";
|
||||
$database = new database;
|
||||
$database->connect();
|
||||
$db = $database->db;
|
||||
|
||||
//use ldap to validate the user credentials
|
||||
if (isset($_SESSION["ldap"]["certpath"])) {
|
||||
$s = "LDAPTLS_CERT=" . $_SESSION["ldap"]["certpath"]["text"];
|
||||
|
|
@ -41,13 +34,13 @@ class plugin_ldap {
|
|||
}
|
||||
$host = $_SESSION["ldap"]["server_host"]["text"];
|
||||
$port = $_SESSION["ldap"]["server_port"]["numeric"];
|
||||
$connect = ldap_connect($host,$port)
|
||||
$connect = ldap_connect($host, $port)
|
||||
or die("Could not connect to the LDAP server.");
|
||||
//ldap_set_option($connect, LDAP_OPT_NETWORK_TIMEOUT, 10);
|
||||
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
//ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
|
||||
|
||||
//set the default for $user_authorized to false
|
||||
//set the default status
|
||||
$user_authorized = false;
|
||||
|
||||
//provide backwards compatability
|
||||
|
|
@ -69,37 +62,22 @@ class plugin_ldap {
|
|||
$user_authorized = true;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
//connection failed
|
||||
$user_authorized = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//password not provided
|
||||
$user_authorized = false;
|
||||
}
|
||||
}
|
||||
|
||||
//check to see if the user exists
|
||||
if ($user_authorized) {
|
||||
$sql = "select * from v_users ";
|
||||
$sql .= "where username=:username ";
|
||||
if ($_SESSION["users"]["unique"]["text"] == "global") {
|
||||
//unique username - global (example: email address)
|
||||
}
|
||||
else {
|
||||
//unique username - per domain
|
||||
$sql .= "and domain_uuid=:domain_uuid ";
|
||||
}
|
||||
$prep_statement = $db->prepare($sql);
|
||||
$sql .= "where username = :username ";
|
||||
if ($_SESSION["users"]["unique"]["text"] != "global") {
|
||||
$prep_statement->bindParam(':domain_uuid', $this->domain_uuid);
|
||||
//unique username per domain (not globally unique across system - example: email address)
|
||||
$sql .= "and domain_uuid = :domain_uuid ";
|
||||
$parameters['domain_uuid'] = $this->domain_uuid;
|
||||
}
|
||||
$prep_statement->bindParam(':username', $this->username);
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
if (count($result) > 0) {
|
||||
foreach ($result as &$row) {
|
||||
$parameters['username'] = $this->username;
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
if ($_SESSION["users"]["unique"]["text"] == "global" && $row["domain_uuid"] != $this->domain_uuid) {
|
||||
//get the domain uuid
|
||||
$this->domain_uuid = $row["domain_uuid"];
|
||||
|
|
@ -111,13 +89,11 @@ class plugin_ldap {
|
|||
|
||||
//set the setting arrays
|
||||
$domain = new domains();
|
||||
$domain->db = $db;
|
||||
$domain->set();
|
||||
}
|
||||
$this->user_uuid = $row["user_uuid"];
|
||||
$this->contact_uuid = $row["contact_uuid"];
|
||||
}
|
||||
}
|
||||
else {
|
||||
//salt used with the password to create a one way hash
|
||||
$salt = generate_password('32', '4');
|
||||
|
|
@ -127,53 +103,40 @@ class plugin_ldap {
|
|||
$this->user_uuid = uuid();
|
||||
$this->contact_uuid = uuid();
|
||||
|
||||
//add the user
|
||||
$sql = "insert into v_users ";
|
||||
$sql .= "(";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "user_uuid, ";
|
||||
$sql .= "contact_uuid, ";
|
||||
$sql .= "username, ";
|
||||
$sql .= "password, ";
|
||||
$sql .= "salt, ";
|
||||
$sql .= "add_date, ";
|
||||
$sql .= "add_user, ";
|
||||
$sql .= "user_enabled ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'".$this->user_uuid."', ";
|
||||
$sql .= "'".$this->contact_uuid."', ";
|
||||
$sql .= "'".strtolower($this->username)."', ";
|
||||
$sql .= "'".md5($salt.$password)."', ";
|
||||
$sql .= "'".$salt."', ";
|
||||
$sql .= "now(), ";
|
||||
$sql .= "'".strtolower($this->username)."', ";
|
||||
$sql .= "'true' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//build user insert array
|
||||
$array['users'][0]['user_uuid'] = $this->user_uuid;
|
||||
$array['users'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['users'][0]['contact_uuid'] = $this->contact_uuid;
|
||||
$array['users'][0]['username'] = strtolower($this->username);
|
||||
$array['users'][0]['password'] = md5($salt.$password);
|
||||
$array['users'][0]['salt'] = $salt;
|
||||
$array['users'][0]['add_date'] = now();
|
||||
$array['users'][0]['add_user'] = strtolower($this->username);
|
||||
$array['users'][0]['user_enabled'] = 'true';
|
||||
|
||||
//add the user to group user
|
||||
$group_name = 'user';
|
||||
$sql = "insert into v_user_groups ";
|
||||
$sql .= "(";
|
||||
$sql .= "user_group_uuid, ";
|
||||
$sql .= "domain_uuid, ";
|
||||
$sql .= "group_name, ";
|
||||
$sql .= "user_uuid ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$this->domain_uuid."', ";
|
||||
$sql .= "'".$group_name."', ";
|
||||
$sql .= "'".$this->user_uuid."' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//build user group insert array
|
||||
$array['user_groups'][0]['user_group_uuid'] = uuid();
|
||||
$array['user_groups'][0]['domain_uuid'] = $this->domain_uuid;
|
||||
$array['user_groups'][0]['group_name'] = 'user';
|
||||
$array['user_groups'][0]['user_uuid'] = $this->user_uuid;
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('user_add', 'temp');
|
||||
$p->add('user_group_add', 'temp');
|
||||
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'authentication';
|
||||
$database->app_uuid = 'a8a12918-69a4-4ece-a1ae-3932be0e41f1';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('user_add', 'temp');
|
||||
$p->delete('user_group_add', 'temp');
|
||||
}
|
||||
unset($sql, $parameters, $row);
|
||||
}
|
||||
|
||||
//result array
|
||||
|
|
@ -185,12 +148,7 @@ class plugin_ldap {
|
|||
}
|
||||
$result["user_uuid"] = $this->user_uuid;
|
||||
$result["domain_uuid"] = $this->domain_uuid;
|
||||
if ($user_authorized) {
|
||||
$result["authorized"] = "true";
|
||||
}
|
||||
else {
|
||||
$result["authorized"] = "false";
|
||||
}
|
||||
$result["authorized"] = $user_authorized ? 'true' : 'false';
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,105 +29,113 @@
|
|||
|
||||
//delete the permissions
|
||||
function delete() {
|
||||
//set the variables
|
||||
$db = $this->db;
|
||||
//get unprotected groups and their domain uuids (if any)
|
||||
$sql = "select group_name, domain_uuid from v_groups where group_protected <> 'true' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$result_count = count($result);
|
||||
if ($result_count > 0) {
|
||||
$sql = "select group_name, domain_uuid ";
|
||||
$sql .= "from v_groups ";
|
||||
$sql .= "where group_protected <> 'true' ";
|
||||
$database = new database;
|
||||
$result = $database->select($sql, null, 'all');
|
||||
if (is_array($result) && @sizeof($result) != 0) {
|
||||
foreach($result as $row) {
|
||||
$unprotected_groups[$row['group_name']] = $row['domain_uuid'];
|
||||
}
|
||||
}
|
||||
unset ($prep_statement, $sql, $result, $result_count);
|
||||
unset($sql, $result, $row);
|
||||
//delete unprotected group permissions
|
||||
if (is_array($unprotected_groups) && sizeof($unprotected_groups) > 0) {
|
||||
$x = 0;
|
||||
foreach ($unprotected_groups as $unprotected_group_name => $unprotected_domain_uuid) {
|
||||
$sql = "delete from v_group_permissions where ";
|
||||
$sql .= "group_name = '".$unprotected_group_name."' ";
|
||||
$sql .= "and domain_uuid ".(($unprotected_domain_uuid != '') ? " = '".$unprotected_domain_uuid."' " : " is null ");
|
||||
if (false === $db->exec($sql)) {
|
||||
//echo $db->errorCode() . "<br>";
|
||||
$info = $db->errorInfo();
|
||||
print_r($info);
|
||||
// $info[0] == $db->errorCode() unified error code
|
||||
// $info[1] is the driver specific error code
|
||||
// $info[2] is the driver specific error string
|
||||
//build delete array
|
||||
$array['group_permissions'][$x]['group_name'] = $unprotected_group_name;
|
||||
$array['group_permissions'][$x]['domain_uuid'] = $unprotected_domain_uuid != '' ? $unprotected_domain_uuid : null;
|
||||
$x++;
|
||||
}
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('group_permission_delete', 'temp');
|
||||
//execute delete
|
||||
$database = new database;
|
||||
$database->app_name = 'groups';
|
||||
$database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
|
||||
$database->delete($array);
|
||||
unset($array);
|
||||
//revoke temporary permissions
|
||||
$p->delete('group_permission_delete', 'temp');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//restore the permissions
|
||||
function restore() {
|
||||
//set the variables
|
||||
$db = $this->db;
|
||||
|
||||
//delete the group permisisons
|
||||
$this->delete();
|
||||
|
||||
//get the $apps array from the installed apps from the core and mod directories
|
||||
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
|
||||
$x=0;
|
||||
$x = 0;
|
||||
foreach ($config_list as &$config_path) {
|
||||
include($config_path);
|
||||
$x++;
|
||||
}
|
||||
|
||||
//restore default permissions
|
||||
foreach($apps as $row) {
|
||||
$x = 0;
|
||||
foreach ($apps as $row) {
|
||||
foreach ($row['permissions'] as $permission) {
|
||||
//set the variables
|
||||
if ($permission['groups']) {
|
||||
foreach ($permission['groups'] as $group) {
|
||||
//check group protection
|
||||
$sql = "select * from v_groups ";
|
||||
$sql .= "where group_name = '".$group."' ";
|
||||
$sql = "select count(*) from v_groups ";
|
||||
$sql .= "where group_name = :group_name ";
|
||||
$sql .= "and group_protected = 'true'";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
unset ($prep_statement);
|
||||
if (count($result) == 0) {
|
||||
//if the item uuid is not currently in the db then add it
|
||||
$sql = "select * from v_group_permissions ";
|
||||
$sql .= "where permission_name = '".$permission['name']."' ";
|
||||
$sql .= "and group_name = '$group' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
if ($prep_statement) {
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
|
||||
unset ($prep_statement);
|
||||
if (count($result) == 0) {
|
||||
//insert the default permissions into the database
|
||||
$sql = "insert into v_group_permissions ";
|
||||
$sql .= "(";
|
||||
$sql .= "group_permission_uuid, ";
|
||||
$sql .= "permission_name, ";
|
||||
$sql .= "group_name ";
|
||||
$sql .= ") ";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'".uuid()."', ";
|
||||
$sql .= "'".$permission['name']."', ";
|
||||
$sql .= "'".$group."' ";
|
||||
$sql .= ");";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
} // if count
|
||||
} // if prepared statement
|
||||
} // if count
|
||||
} // if prepared statement
|
||||
} // foreach group permission
|
||||
} // if permission
|
||||
} // foreach permission
|
||||
} // foreach app
|
||||
$parameters['group_name'] = $group;
|
||||
$database = new database;
|
||||
$num_rows = $database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
|
||||
} // function
|
||||
} // class
|
||||
if ($num_rows == 0) {
|
||||
//if the item uuid is not currently in the db then add it
|
||||
$sql = "select count(*) from v_group_permissions ";
|
||||
$sql .= "where permission_name = :permission_name ";
|
||||
$sql .= "and group_name = :group_name ";
|
||||
$parameters['permission_name'] = $permission['name'];
|
||||
$parameters['group_name'] = $group;
|
||||
$database = new database;
|
||||
$num_rows = $database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters);
|
||||
|
||||
if ($num_rows == 0) {
|
||||
//build default permissions insert array
|
||||
$array['group_permissions'][$x]['group_permission_uuid'] = uuid();
|
||||
$array['group_permissions'][$x]['permission_name'] = $permission['name'];
|
||||
$array['group_permissions'][$x]['group_name'] = $group;
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($array) && @sizeof($array)) {
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('group_permission_add', 'temp');
|
||||
|
||||
//execute insert
|
||||
$database = new database;
|
||||
$database->app_name = 'groups';
|
||||
$database->app_uuid = '2caf27b0-540a-43d5-bb9b-c9871a1e4f84';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('group_permission_add', 'temp');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -34,8 +34,6 @@ class captcha {
|
|||
/**
|
||||
* Called when the object is created
|
||||
*/
|
||||
//public $db;
|
||||
//public $domain_uuid;
|
||||
public $code;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue