diff --git a/app/fax/fax_edit.php b/app/fax/fax_edit.php index 2e5ab6398a..e52a9ade26 100644 --- a/app/fax/fax_edit.php +++ b/app/fax/fax_edit.php @@ -317,9 +317,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //update the fax extension in the database $dialplan_type = ""; $sql = "update v_fax set "; - if (strlen($dialplan_uuid) > 0) { - $sql .= "dialplan_uuid = '".$dialplan_uuid."', "; - } $sql .= "fax_extension = '$fax_extension', "; $sql .= "accountcode = '$fax_accountcode', "; $sql .= "fax_destination_number = '$fax_destination_number', "; @@ -354,173 +351,28 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { unset($sql); } - //if there are no variables in the vars table then add them - if ($dialplan_type != "add") { - $sql = "select count(*) as num_rows from v_dialplans "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - $dialplan_type = "add"; - } - else { - $dialplan_type = "update"; - } - } + //get the dialplan_uuid + $sql = "select * from v_fax "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and fax_uuid = '$fax_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $dialplan_uuid = $row["dialplan_uuid"]; } + unset ($prep_statement); - if ($dialplan_type == "add") { - //add the dialplan entry for fax - $dialplan_name = $fax_name; - $dialplan_order ='310'; - $dialplan_context = $_SESSION['context']; - $dialplan_enabled = 'true'; - $dialplan_description = $fax_description; - $app_uuid = '24108154-4ac3-1db6-1551-4731703a4440'; - dialplan_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_name, $dialplan_order, $dialplan_context, $dialplan_enabled, $dialplan_description, $app_uuid); - - // - // - $dialplan_detail_tag = 'condition'; //condition, action, antiaction - $dialplan_detail_type = 'destination_number'; - $dialplan_detail_data = '^'.$fax_destination_number.'$'; - $dialplan_detail_order = '010'; - $dialplan_detail_group = ''; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'answer'; - $dialplan_detail_data = ''; - $dialplan_detail_order = '020'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'set'; - $dialplan_detail_data = 'fax_uuid='.$fax_uuid; - $dialplan_detail_order = '030'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, anti-action - $dialplan_detail_type = 'set'; - $dialplan_detail_data = "api_hangup_hook=lua app/fax/resources/scripts/hangup_rx.lua"; - $dialplan_detail_order = '040'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'set'; - $dialplan_detail_data = 'fax_enable_t38=true'; - $dialplan_detail_order = '050'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'set'; - $dialplan_detail_data = 'fax_enable_t38_request=false'; - $dialplan_detail_order = '060'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'set'; - $dialplan_detail_data = 'last_fax=${caller_id_number}-${strftime(%Y-%m-%d-%H-%M-%S)}'; - $dialplan_detail_order = '070'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'playback'; - $dialplan_detail_data = 'silence_stream://2000'; - $dialplan_detail_order = '080'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'rxfax'; - if (count($_SESSION["domains"]) > 1) { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'].'/'.$fax_extension.'/inbox/'.$forward_prefix.'${last_fax}.tif'; - } - else { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$fax_extension.'/inbox/'.$forward_prefix.'${last_fax}.tif'; - } - $dialplan_detail_order = '090'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - - // - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'hangup'; - $dialplan_detail_data = ''; - $dialplan_detail_order = '100'; - dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); - } - if ($dialplan_type == "update") { - //update the fax dialplan entry - $sql = "update v_dialplans set "; - $sql .= "dialplan_name = '$fax_name', "; - if (strlen($dialplan_order) > 0) { - $sql .= "dialplan_order = '333', "; - } - $sql .= "dialplan_context = '".$_SESSION['context']."', "; - $sql .= "dialplan_enabled = 'true', "; - $sql .= "dialplan_description = '$fax_description' "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); - - //update dialplan detail condition - $sql = "update v_dialplan_details set "; - $sql .= "dialplan_detail_data = '^".$fax_destination_number."$' "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and dialplan_detail_tag = 'condition' "; - $sql .= "and dialplan_detail_type = 'destination_number' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - unset($sql); - - //update dialplan detail action - if (count($_SESSION["domains"]) > 1) { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'].'/'.$fax_extension.'/inbox/'.$forward_prefix.'${last_fax}.tif'; - } - else { - $dialplan_detail_data = $_SESSION['switch']['storage']['dir'].'/fax/'.$fax_extension.'/inbox/'.$forward_prefix.'${last_fax}.tif'; - } - $sql = "update v_dialplan_details set "; - $sql .= "dialplan_detail_data = '".$dialplan_detail_data."' "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and dialplan_detail_tag = 'action' "; - $sql .= "and dialplan_detail_type = 'rxfax' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $db->query($sql); - - //update dialplan detail action - $dialplan_detail_tag = 'action'; //condition, action, antiaction - $dialplan_detail_type = 'set'; - $dialplan_detail_data = "api_hangup_hook=lua app/fax/resources/scripts/hangup_rx.lua"; - $sql = "update v_dialplan_details set "; - $sql .= "dialplan_detail_data = '".check_str($dialplan_detail_data)."' "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and dialplan_detail_tag = 'action' "; - $sql .= "and dialplan_detail_type = 'set' "; - $sql .= "and dialplan_uuid = '$dialplan_uuid' "; - $sql .= "and dialplan_detail_data like 'api_hangup_hook=%' "; - $db->query(check_sql($sql)); - } - - //save the xml - save_dialplan_xml(); - - //apply settings reminder - $_SESSION["reload_xml"] = true; - - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$_SESSION["context"]); + //dialplan add or update + $c = new fax; + $c->db = $db; + $c->domain_uuid = $_SESSION['domain_uuid']; + $c->dialplan_uuid = $dialplan_uuid; + $c->fax_name = $fax_name; + $c->fax_uuid = $fax_uuid; + $c->fax_description = $fax_description; + $c->destination_number = $fax_extension; + $a = $c->dialplan(); //redirect the browser if ($action == "update" && permission_exists('fax_extension_edit')) { diff --git a/app/fax/resources/classes/fax.php b/app/fax/resources/classes/fax.php new file mode 100644 index 0000000000..ff6fe01780 --- /dev/null +++ b/app/fax/resources/classes/fax.php @@ -0,0 +1,223 @@ + + Copyright (C) 2015 + All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +/** + * cache class provides an abstracted cache + * + * @method string dialplan - builds the dialplan for the fax servers + */ +//define the fax class + if (!class_exists('fax')) { + class fax { + /** + * define the variables + */ + public $domain_uuid; + public $fax_uuid; + public $dialplan_uuid; + public $fax_name; + public $fax_description; + public $destination_number; + + /** + * Called when the object is created + */ + public function __construct() { + //place holder + } + + /** + * Called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + /** + * Add a dialplan for call center + * @var string $domain_uuid the multi-tenant id + * @var string $value string to be cached + */ + public function dialplan() { + + //delete previous dialplan + if (strlen($this->dialplan_uuid) > 0) { + //delete the previous dialplan + $sql = "delete from v_dialplans "; + $sql .= "where dialplan_uuid = '".$this->dialplan_uuid."' "; + $sql .= "and domain_uuid = '".$this->domain_uuid."' "; + $this->db->exec($sql); + + $sql = "delete from v_dialplan_details "; + $sql .= "where dialplan_uuid = '".$this->dialplan_uuid."' "; + $sql .= "and domain_uuid = '".$this->domain_uuid."' "; + $this->db->exec($sql); + unset($sql); + } + unset($prep_statement); + + //build the dialplan array + $dialplan["app_uuid"] = "24108154-4ac3-1db6-1551-4731703a4440"; + $dialplan["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_name"] = ($this->fax_name != '') ? $this->fax_name : format_phone($this->destination_number); + $dialplan["dialplan_number"] = $this->destination_number; + $dialplan["dialplan_context"] = $_SESSION['context']; + $dialplan["dialplan_continue"] = "false"; + $dialplan["dialplan_order"] = "310"; + $dialplan["dialplan_enabled"] = "true"; + $dialplan["dialplan_description"] = $this->fax_description; + $dialplan_detail_order = 10; + + //add the public condition + $y = 1; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "^".$this->destination_number."\$"; + $dialplan["dialplan_details"][$y]["dialplan_detail_break"] = ""; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "answer"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = ""; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "fax_uuid=".$this->fax_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "api_hangup_hook=lua app/fax/resources/scripts/hangup_rx.lua"; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + foreach($_SESSION['fax']['variable'] as $data) { + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $data; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + } + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=\${caller_id_number}-\${strftime(%Y-%m-%d-%H-%M-%S)}"; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "playback"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "silence_stream://2000"; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "rxfax"; + if (count($_SESSION["domains"]) > 1) { + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'].'/fax/'.$_SESSION['domain_name'].'/'.$fax_extension.'/inbox/'.$forward_prefix.'${last_fax}.tif'; + } + else { + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'].'/fax/'.$fax_extension.'/inbox/'.$forward_prefix.'${last_fax}.tif'; + } + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "hangup"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = ""; + $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; + $y++; + + //add the dialplan permission + $p = new permissions; + $p->add("dialplan_add", 'temp'); + $p->add("dialplan_detail_add", 'temp'); + $p->add("dialplan_edit", 'temp'); + $p->add("dialplan_detail_edit", 'temp'); + + //save the dialplan + $orm = new orm; + $orm->name('dialplans'); + $orm->save($dialplan); + $dialplan_response = $orm->message; + $this->dialplan_uuid = $dialplan_response['uuid']; + + //if new dialplan uuid then update the call center queue + $sql = "update v_fax "; + $sql .= "set dialplan_uuid = '".$this->dialplan_uuid."' "; + $sql .= "where fax_uuid = '".$this->fax_uuid."' "; + $sql .= "and domain_uuid = '".$this->domain_uuid."' "; + $this->db->exec($sql); + unset($sql); + + //remove the temporary permission + $p->delete("dialplan_add", 'temp'); + $p->delete("dialplan_detail_add", 'temp'); + $p->delete("dialplan_edit", 'temp'); + $p->delete("dialplan_detail_edit", 'temp'); + + //synchronize the xml config + save_dialplan_xml(); + + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$_SESSION['context']); + + //return the dialplan_uuid + return $dialplan_response; + + } + } + } + +/* +$o = new fax; +$c->domain_uuid = ""; +$c->dialplan_uuid = ""; +$c->fax_name = ""; +$c->fax_description = ""; +$c->destination_number = ""; +$c->dialplan(); +*/ + +?> \ No newline at end of file