/** * Add a dialplan for call center * @var string $domain_uuid the multi-tenant id * @var string $value string to be cached */ public function dialplan() { //normalize the fax forward number if (strlen($this->fax_forward_number) > 3) { //$fax_forward_number = preg_replace("~[^0-9]~", "",$fax_forward_number); $this->fax_forward_number = str_replace(" ", "", $this->fax_forward_number); $this->fax_forward_number = str_replace("-", "", $this->fax_forward_number); } //set the forward prefix if (strripos($this->fax_forward_number, '$1') === false) { $this->forward_prefix = ''; //not found } else { $this->forward_prefix = $this->forward_prefix . $this->fax_forward_number . '#'; //found } //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->fax_extension; $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"; if (substr($data, 0, 8) == "inbound:") { $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = substr($data, 8, strlen($data)); } elseif (substr($data, 0, 9) == "outbound:") { } else { $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"; if (strlen($_SESSION['fax']['last_fax']['text']) > 0) { $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "last_fax=" . $_SESSION['fax']['last_fax']['text']; } else { $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"; $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $_SESSION['switch']['storage']['dir'] . '/fax/' . $_SESSION['domain_name'] . '/' . $this->fax_extension . '/inbox/' . $this->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; }
} //add the dialplan permission $permission = "dialplan_edit"; $p = new permissions(); $p->add($permission, 'temp'); //save the destination $orm = new orm(); $orm->name('destinations'); if (strlen($destination_uuid) > 0) { $orm->uuid($destination_uuid); } $orm->save($_POST); $message = $orm->message; $destination_response = $orm->message; //remove the temporary permission $p->delete($permission, 'temp'); //get the destination_uuid if (strlen($destination_response['uuid']) > 0) { $destination_uuid = $destination_response['uuid']; } //redirect the user if ($action == "add") { $_SESSION["message"] = $text['message-add']; // billing if (file_exists($_SERVER['DOCUMENT_ROOT'] . PROJECT_PATH . "/app/billing/app_config.php")) { $db2 = new database(); $db2->sql = "select currency, billing_uuid, balance from v_billings where type_value='{$destination_accountcode}'"; $db2->result = $db2->execute(); $default_currency = strlen($_SESSION['billing']['currency']['text']) ? $_SESSION['billing']['currency']['text'] : 'USD'; $billing_currency = strlen($db2->result[0]['currency']) ? $db2->result[0]['currency'] : $default_currency; $destination_sell_current_currency = currency_convert($destination_sell, $billing_currency, $currency);
$result = $orm->find()->get(); //$message = $orm->message; foreach ($result as &$row) { $domain_uuid = $row["domain_uuid"]; //$app_uuid = $row["app_uuid"]; $dialplan_name = $row["dialplan_name"]; $dialplan_number = $row["dialplan_number"]; $dialplan_order = $row["dialplan_order"]; $dialplan_continue = $row["dialplan_continue"]; $dialplan_context = $row["dialplan_context"]; $dialplan_enabled = $row["dialplan_enabled"]; $dialplan_description = $row["dialplan_description"]; } unset($prep_statement); //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'); //get dialplan detail conditions $sql = "select dialplan_detail_group, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data from v_dialplan_details "; $sql .= "where dialplan_uuid = '" . $dialplan_uuid . "' "; $sql .= "and "; $sql .= "( "; $sql .= "\t( "; $sql .= "\t\tdialplan_detail_tag = 'condition' "; $sql .= "\t\tand dialplan_detail_type in ('year','mon','mday','wday','yday','week','mweek','hour','minute','minute-of-day','time-of-day','date-time') "; $sql .= "\t) "; $sql .= "\tor ( "; $sql .= "\t\tdialplan_detail_tag = 'action' "; $sql .= "\t\tand dialplan_detail_data not like 'preset=%' ";
/** * 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"] = "95788e50-9500-079e-2807-fd530b0ea370"; $dialplan["domain_uuid"] = $this->domain_uuid; $dialplan["dialplan_name"] = $this->queue_name != '' ? $this->queue_name : format_phone($this->destination_number); $dialplan["dialplan_number"] = $this->destination_number; $dialplan["dialplan_context"] = $_SESSION['context']; $dialplan["dialplan_continue"] = "false"; $dialplan["dialplan_order"] = "210"; $dialplan["dialplan_enabled"] = "true"; $dialplan["dialplan_description"] = $this->queue_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"] = "\${caller_id_name}"; $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "^([^#]+#)(.*)\$"; $dialplan["dialplan_details"][$y]["dialplan_detail_break"] = "never"; $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"] = "caller_id_name=\$2"; $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"] = "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"] = "2"; $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"] = "2"; $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"] = "hangup_after_bridge=true"; $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2"; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; $y++; if (strlen($this->queue_cid_prefix) > 0) { $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"] = "effective_caller_id_name=" . $this->queue_cid_prefix . "#\${caller_id_name}"; $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2"; $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"] = "callcenter"; $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $this->queue_name . '@' . $_SESSION["domain_name"]; $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2"; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; $y++; if (strlen($this->queue_timeout_action) > 0) { $action_array = explode(":", $this->queue_timeout_action); $dialplan["dialplan_details"][$y]["domain_uuid"] = $this->domain_uuid; $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $action_array[0]; $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = substr($this->queue_timeout_action, strlen($action_array[0]) + 1, strlen($this->queue_timeout_action)); $dialplan["dialplan_details"][$y]["dialplan_detail_group"] = "2"; $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"] = "2"; $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $y * 10; //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_call_center_queues "; $sql .= "set dialplan_uuid = '" . $this->dialplan_uuid . "' "; $sql .= "where call_center_queue_uuid = '" . $this->call_center_queue_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; }