2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2014-01-17 19:33:11 +01:00
|
|
|
Copyright (C) 2010 - 2014
|
2012-06-04 16:58:40 +02:00
|
|
|
All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2013-12-18 03:04:32 +01:00
|
|
|
Luis Daniel Lucio Quiroz <daniel.lucio@astraqom.com>
|
2012-06-04 16:58:40 +02:00
|
|
|
*/
|
|
|
|
|
include "root.php";
|
|
|
|
|
|
|
|
|
|
//define the call_forward class
|
|
|
|
|
class call_forward {
|
2012-12-17 22:30:49 +01:00
|
|
|
public $debug;
|
2012-06-04 16:58:40 +02:00
|
|
|
public $domain_uuid;
|
2012-12-17 22:30:49 +01:00
|
|
|
public $domain_name;
|
2012-12-16 08:39:03 +01:00
|
|
|
public $extension_uuid;
|
2012-12-17 22:30:49 +01:00
|
|
|
private $extension;
|
2012-12-16 08:39:03 +01:00
|
|
|
public $forward_all_destination;
|
|
|
|
|
public $forward_all_enabled;
|
2012-12-17 22:30:49 +01:00
|
|
|
private $dial_string;
|
2013-05-01 20:14:13 +02:00
|
|
|
public $accountcode;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2012-12-17 22:30:49 +01:00
|
|
|
public function set() {
|
|
|
|
|
//set the global variable
|
|
|
|
|
global $db;
|
|
|
|
|
|
2013-05-01 20:14:13 +02:00
|
|
|
//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"];
|
|
|
|
|
$this->accountcode = $row["accountcode"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unset ($prep_statement);
|
|
|
|
|
|
2012-12-17 22:30:49 +01:00
|
|
|
//set the dial string
|
|
|
|
|
if ($this->forward_all_enabled == "true") {
|
2014-05-30 01:49:17 +02:00
|
|
|
$dial_string = "{presence_id=".$this->forward_all_destination."@".$_SESSION['domain_name'];
|
|
|
|
|
$dial_string .= ",instant_ringback=true";
|
|
|
|
|
$dial_string .= ",domain_uuid=".$_SESSION['domain_uuid'];
|
|
|
|
|
$dial_string .= ",sip_invite_domain=".$_SESSION['domain_name'];
|
|
|
|
|
$dial_string .= ",domain_name=".$_SESSION['domain_name'];
|
|
|
|
|
$dial_string .= ",domain=".$_SESSION['domain_name'];
|
2013-05-01 20:14:13 +02:00
|
|
|
if (strlen($this->accountcode) > 0) {
|
|
|
|
|
$dial_string .= ",accountcode=".$this->accountcode;
|
|
|
|
|
}
|
|
|
|
|
$dial_string .= "}";
|
2013-01-19 18:11:04 +01:00
|
|
|
if (extension_exists($this->forward_all_destination)) {
|
2013-12-18 03:04:32 +01:00
|
|
|
$dial_string .= "user/".$this->forward_all_destination."@".$_SESSION['domain_name'];
|
2013-01-19 18:11:04 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2013-01-25 22:57:39 +01:00
|
|
|
$bridge = outbound_route_to_bridge ($_SESSION['domain_uuid'], $this->forward_all_destination);
|
2013-02-03 07:47:19 +01:00
|
|
|
//if (strlen($bridge[0]) > 0) {
|
|
|
|
|
// $dial_string .= $bridge[0];
|
|
|
|
|
//}
|
|
|
|
|
//else {
|
2013-01-25 22:57:39 +01:00
|
|
|
$dial_string .= "loopback/".$this->forward_all_destination;
|
2013-02-03 07:47:19 +01:00
|
|
|
//}
|
2013-01-19 18:11:04 +01:00
|
|
|
}
|
2013-01-25 22:57:39 +01:00
|
|
|
$this->dial_string = $dial_string;
|
2012-12-17 22:30:49 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$this->dial_string = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//update the extension
|
|
|
|
|
$sql = "update v_extensions set ";
|
|
|
|
|
$sql .= "forward_all_destination = '$this->forward_all_destination', ";
|
2013-01-17 07:14:31 +01:00
|
|
|
$sql .= "dial_string = '".$this->dial_string."', ";
|
2012-12-17 22:30:49 +01:00
|
|
|
$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
|
2013-01-15 23:56:40 +01:00
|
|
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
|
|
|
|
if ($fp) {
|
2013-01-16 01:26:48 +01:00
|
|
|
$switch_cmd = "memcache delete directory:".$this->extension."@".$this->domain_name;
|
2013-01-15 23:56:40 +01:00
|
|
|
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
|
2012-12-17 22:30:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //function
|
|
|
|
|
} //class
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2013-12-18 03:04:32 +01:00
|
|
|
?>
|