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 462211173f
commit 5e639f753e
4 changed files with 234 additions and 84 deletions
@@ -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
?>