Update call forward to use the dial string. Make call forward, dnd and follow me work better together.

This commit is contained in:
Mark Crane
2012-12-17 21:30:49 +00:00
parent 16517b8214
commit ddf9a5a70f
4 changed files with 234 additions and 84 deletions

View File

@@ -27,22 +27,77 @@ include "root.php";
//define the call_forward class
class call_forward {
public $debug;
public $domain_uuid;
public $domain_name;
public $extension_uuid;
private $extension;
public $forward_all_destination;
public $forward_all_enabled;
private $dial_string;
private $dial_string_update = false;
public function update() {
global $db;
$sql = "update v_extensions set ";
$sql .= "forward_all_destination = '$this->forward_all_destination', ";
$sql .= "forward_all_enabled = '$this->forward_all_enabled' ";
$sql .= "where domain_uuid = '$this->domain_uuid' ";
$sql .= "and extension_uuid = '$this->extension_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
} //end function
public function set() {
//set the global variable
global $db;
}
//set the dial string
if ($this->forward_all_enabled == "true") {
$this->dial_string = "loopback/".$this->forward_all_destination;
}
else {
$this->dial_string = '';
}
//determine whether to update the dial string
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and extension_uuid = '".$this->extension_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
foreach ($result as &$row) {
$this->extension = $row["extension"];
if ($this->forward_all_enabled == "false" && $row["forward_all_enabled"] == "true") {
$this->dial_string_update = true;
}
}
}
unset ($prep_statement);
if ($this->forward_all_enabled == "true") {
$this->dial_string_update = true;
}
//update the extension
$sql = "update v_extensions set ";
$sql .= "forward_all_destination = '$this->forward_all_destination', ";
if ($this->dial_string_update) {
$sql .= "dial_string = '".$this->dial_string."', ";
}
$sql .= "forward_all_enabled = '$this->forward_all_enabled' ";
$sql .= "where domain_uuid = '$this->domain_uuid' ";
$sql .= "and extension_uuid = '$this->extension_uuid' ";
if ($this->debug) {
echo $sql;
}
$db->exec(check_sql($sql));
unset($sql);
//delete extension from memcache
if ($this->dial_string_update) {
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) {
$switch_cmd .= "memcache delete ".$this->extension."@".$this->domain_name;
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
}
}
//syncrhonize configuration
if ($this->dial_string_update) {
save_extension_xml();
}
} //function
} //class
?>

View File

@@ -27,60 +27,103 @@ include "root.php";
//define the dnd class
class do_not_disturb {
public $debug;
public $domain_uuid;
public $domain_name;
public $extension;
public $extension_uuid;
private $extension;
public $enabled;
private $dial_string;
private $dial_string_update = false;
//update the user_status
public function user_status() {
global $db;
if ($this->enabled == "true") {
//update the call center status
$user_status = "Logged Out";
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) {
$switch_cmd .= "callcenter_config agent set status ".$_SESSION['username']."@".$this->domain_name." '".$user_status."'";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
}
//set the global variable
global $db;
//update the database user_status
$user_status = "Do Not Disturb";
$sql = "update v_users set ";
$sql .= "user_status = '$user_status' ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and username = '".$_SESSION['username']."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
}
//update the status
if ($this->enabled == "true") {
//update the call center status
$user_status = "Logged Out";
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) {
$switch_cmd .= "callcenter_config agent set status ".$_SESSION['username']."@".$this->domain_name." '".$user_status."'";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
}
//update the database user_status
$user_status = "Do Not Disturb";
$sql = "update v_users set ";
$sql .= "user_status = '$user_status' ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and username = '".$_SESSION['username']."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
}
}
public function set() {
global $db;
//update the extension
//set the global variable
global $db;
//determine whether to update the dial string
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and extension_uuid = '".$this->extension_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
foreach ($result as &$row) {
$this->extension = $row["extension"];
if ($this->enabled == "false" && $row["do_not_disturb"] == "true") {
$this->dial_string_update = true;
}
}
}
unset ($prep_statement);
if ($this->enabled == "true") {
$this->dial_string_update = true;
}
//set the dial string
if ($this->enabled == "true") {
$this->dial_string = "loopback/*99".$this->extension;
}
else {
$this->dial_string = "";
$this->dial_string = '';
}
//update the extension
$sql = "update v_extensions set ";
$sql .= "do_not_disturb = '".$this->enabled."', ";
// $sql .= "dial_string = '".$this->dial_string."', ";
$sql .= "dial_domain = '".$this->domain_name."' ";
if ($this->dial_string_update) {
$sql .= "dial_string = '".$this->dial_string."', ";
}
//$sql .= "dial_domain = '".$this->domain_name."', ";
$sql .= "do_not_disturb = '".$this->enabled."' ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and extension = '".$this->extension."' ";
$sql .= "and extension_uuid = '".$this->extension_uuid."' ";
if ($this->debug) {
echo $sql."<br />";
}
$db->exec(check_sql($sql));
unset($sql);
//syncrhonize configuration
save_extension_xml();
} //function
//delete extension from memcache
if ($this->dial_string_update) {
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) {
$switch_cmd .= "memcache delete ".$this->extension."@".$this->domain_name;
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
}
}
//syncrhonize configuration
if ($this->dial_string_update) {
save_extension_xml();
}
} //function
} //class
?>

View File

@@ -31,6 +31,8 @@ include "root.php";
public $db_type;
public $follow_me_uuid;
public $follow_me_enabled;
private $extension;
private $dial_string_update = false;
public $destination_data_1;
public $destination_type_1;
@@ -61,42 +63,46 @@ include "root.php";
public $destination_order = 1;
public function follow_me_add() {
global $db;
//set the global variable
global $db;
$sql = "insert into v_follow_me ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "follow_me_uuid, ";
$sql .= "follow_me_enabled ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$this->domain_uuid', ";
$sql .= "'$this->follow_me_uuid', ";
$sql .= "'$this->follow_me_enabled' ";
$sql .= ")";
if ($v_debug) {
echo $sql."<br />";
}
$db->exec(check_sql($sql));
unset($sql);
$this->follow_me_destinations();
//add a new follow me
$sql = "insert into v_follow_me ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "follow_me_uuid, ";
$sql .= "follow_me_enabled ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$this->domain_uuid', ";
$sql .= "'$this->follow_me_uuid', ";
$sql .= "'$this->follow_me_enabled' ";
$sql .= ")";
if ($v_debug) {
echo $sql."<br />";
}
$db->exec(check_sql($sql));
unset($sql);
$this->follow_me_destinations();
} //end function
public function follow_me_update() {
global $db;
$sql = "update follow_me set ";
$sql .= "follow_me_enabled = '$this->follow_me_enabled' ";
$sql .= "where domain_uuid = '$this->domain_uuid' ";
$sql .= "and follow_me_uuid = '$this->follow_me_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
$this->follow_me_destinations();
//set the global variable
global $db;
//update follow me table
$sql = "update v_follow_me set ";
$sql .= "follow_me_enabled = '$this->follow_me_enabled' ";
$sql .= "where domain_uuid = '$this->domain_uuid' ";
$sql .= "and follow_me_uuid = '$this->follow_me_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
$this->follow_me_destinations();
} //end function
public function follow_me_destinations() {
global $db;
//set the global variable
global $db;
//delete related follow me destinations
$sql = "delete from v_follow_me_destinations where follow_me_uuid = '$this->follow_me_uuid' ";
@@ -231,11 +237,45 @@ include "root.php";
} //function
public function set() {
global $db;
//set the global variable
global $db;
//determine whether to update the dial string
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and extension_uuid = '".$this->extension_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
foreach ($result as &$row) {
$this->extension = $row["extension"];
}
}
//determine whether to update the dial string
$sql = "select * from v_follow_me ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and follow_me_uuid = '".$this->follow_me_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
foreach ($result as &$row) {
if ($this->follow_me_enabled == "false" && $row["follow_me_enabled"] == "true") {
$this->dial_string_update = true;
}
}
}
unset ($prep_statement);
if ($this->follow_me_enabled == "true") {
$this->dial_string_update = true;
}
//update the extension
if ($this->follow_me_enabled == "true") {
$sql = "select * from v_follow_me_destinations ";
$sql .= "where follow_me_uuid = '$this->follow_me_uuid' ";
$sql .= "where follow_me_uuid = '".$this->follow_me_uuid."' ";
$sql .= "order by follow_me_order asc ";
$prep_statement_2 = $db->prepare(check_sql($sql));
$prep_statement_2->execute();
@@ -255,11 +295,12 @@ include "root.php";
$this->dial_string = trim($dial_string, ",");
}
else {
// $this->dial_string = "";
$this->dial_string = '';
}
$sql = "update v_extensions set ";
$sql .= "do_not_disturb = 'false', ";
$sql .= "dial_string = '".$this->dial_string."', ";
if ($this->dial_string_update) {
$sql .= "dial_string = '".$this->dial_string."', ";
}
$sql .= "dial_domain = '".$_SESSION['domain_name']."' ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and follow_me_uuid = '".$this->follow_me_uuid."' ";
@@ -269,8 +310,19 @@ include "root.php";
$db->exec($sql);
unset($sql);
//delete extension from memcache
if ($this->dial_string_update) {
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) {
$switch_cmd .= "memcache delete ".$this->extension."@".$this->domain_name;
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
}
}
//syncrhonize configuration
save_extension_xml();
if ($this->dial_string_update) {
save_extension_xml();
}
}
} //class