Update destination_edit.php

Rewrote a large amount of the page to the new class which allows for much less code. Also remove the proprietary billing system and its contributor as their code was removed. Proper integration should not have to touch project code but be a standalone plugin. If current plugin capability is not sufficient will need to expand its capabilities.
This commit is contained in:
FusionPBX 2016-10-02 11:40:49 -06:00 committed by GitHub
parent c372ece23e
commit e1556c9dc3
1 changed files with 252 additions and 356 deletions

View File

@ -17,12 +17,11 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2013-2016
Portions created by the Initial Developer are Copyright (C) 2008-2016
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
*/
//includes
@ -39,12 +38,6 @@
exit;
}
//billing
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")) {
require_once "app/billing/resources/functions/currency.php";
require_once "app/billing/resources/functions/rating.php";
}
//add multi-lingual support
$language = new text;
$text = $language->get();
@ -113,9 +106,13 @@
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//get the uuid
if ($action == "update") {
if ($action == "update" && isset($_POST["destination_uuid"])) {
$destination_uuid = check_str($_POST["destination_uuid"]);
}
else {
$destination_uuid = uuid();
$_POST["destination_uuid"] = $destination_uuid;
}
//check for all required data
$msg = '';
@ -153,333 +150,275 @@
return;
}
//add or update the database
if ($_POST["persistformvar"] != "true") {
//determine whether save the dialplan
foreach ($_POST["dialplan_details"] as $row) {
if (strlen($row["dialplan_detail_data"]) > 0) {
$add_dialplan = true;
break;
}
}
//determine whether save the dialplan
foreach ($_POST["dialplan_details"] as $row) {
if (strlen($row["dialplan_detail_data"]) > 0) {
$add_dialplan = true;
break;
}
//get the array
$dialplan_details = $_POST["dialplan_details"];
//remove the array from the HTTP POST
unset($_POST["dialplan_details"]);
//array cleanup
foreach ($dialplan_details as $index => $row) {
//unset the empty row
if (strlen($row["dialplan_detail_data"]) == 0) {
unset($dialplan_details[$index]);
}
}
//if empty then get new uuid
if (strlen($dialplan_uuid) == 0) {
$dialplan_uuid = uuid();
}
//add or update the dialplan if the destination number is set
if ($add_dialplan) {
//build the dialplan array
$dialplan["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4";
$dialplan["dialplan_uuid"] = $dialplan_uuid;
$dialplan["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_name"] = ($dialplan_name != '') ? $dialplan_name : format_phone($destination_number);
$dialplan["dialplan_number"] = $destination_number;
$dialplan["dialplan_context"] = $destination_context;
$dialplan["dialplan_continue"] = "false";
$dialplan["dialplan_order"] = "100";
$dialplan["dialplan_enabled"] = $destination_enabled;
$dialplan["dialplan_description"] = ($dialplan_description != '') ? $dialplan_description : $destination_description;
$dialplan_detail_order = 10;
//get the array
$dialplan_details = $_POST["dialplan_details"];
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
//remove the array from the HTTP POST
unset($_POST["dialplan_details"]);
//check the destination number
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
if (strlen($_SESSION['dialplan']['destination']['text']) > 0) {
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text'];
}
else {
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
}
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//array cleanup
foreach ($dialplan_details as $index => $row) {
//unset the empty row
if (strlen($row["dialplan_detail_data"]) == 0) {
unset($dialplan_details[$index]);
}
}
//if empty then get new uuid
if (strlen($dialplan_uuid) == 0) {
$dialplan_uuid = uuid();
}
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
//build the dialplan array
$dialplan["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4";
$dialplan["dialplan_uuid"] = $dialplan_uuid;
$dialplan["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_name"] = ($dialplan_name != '') ? $dialplan_name : format_phone($destination_number);
$dialplan["dialplan_number"] = $destination_number;
$dialplan["dialplan_context"] = $destination_context;
$dialplan["dialplan_continue"] = "false";
$dialplan["dialplan_order"] = "100";
$dialplan["dialplan_enabled"] = $destination_enabled;
$dialplan["dialplan_description"] = ($dialplan_description != '') ? $dialplan_description : $destination_description;
$dialplan_detail_order = 10;
//set the caller id name prefix
if (strlen($destination_cid_name_prefix) > 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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=".$destination_cid_name_prefix."#\${caller_id_name}";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//check the destination number
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
if (strlen($_SESSION['dialplan']['destination']['text']) > 0) {
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text'];
}
else {
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number";
}
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//set the call accountcode
if (strlen($destination_accountcode) > 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "accountcode=".$destination_accountcode;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//set the caller id name prefix
if (strlen($destination_cid_name_prefix) > 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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=".$destination_cid_name_prefix."#\${caller_id_name}";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//set the call carrier
if (strlen($destination_carrier) > 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "carrier=$destination_carrier";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//set the call accountcode
if (strlen($destination_accountcode) > 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "accountcode=".$destination_accountcode;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//set the call carrier
if (strlen($destination_carrier) > 0) {
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "carrier=$destination_carrier";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//add fax detection
if (strlen($fax_uuid) > 0) {
//get the fax information
$sql = "select * from v_fax ";
$sql .= "where fax_uuid = '".$fax_uuid."' ";
if (!permission_exists('destination_domain')) {
$sql .= "and domain_uuid = '".$domain_uuid."' ";
}
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$fax_extension = $row["fax_extension"];
$fax_destination_number = $row["fax_destination_number"];
$fax_name = $row["fax_name"];
$fax_email = $row["fax_email"];
$fax_pin_number = $row["fax_pin_number"];
$fax_caller_id_name = $row["fax_caller_id_name"];
$fax_caller_id_number = $row["fax_caller_id_number"];
$fax_forward_number = $row["fax_forward_number"];
$fax_description = $row["fax_description"];
}
unset ($prep_statement);
//delete previous fax detection settings
$sql = "delete from v_dialplan_details ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= "and dialplan_uuid = '".$dialplan_uuid."' ";
$sql .= "and (";
$sql .= " dialplan_detail_data like '%tone_detect%' ";
$sql .= " or dialplan_detail_type = 'tone_detect' ";
$sql .= " or (dialplan_detail_type = 'sleep' and dialplan_detail_data = '3000') ";
$sql .= ")";
$db->exec($sql);
unset($sql);
//add set tone detect_hits=1
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "tone_detect_hits=1";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
// execute on tone detect
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "execute_on_tone_detect=transfer ".$fax_extension." XML \${domain_name}";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
//add tone_detect fax 1100 r +5000
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "tone_detect";
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "fax 1100 r +5000";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
// execute on tone detect
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "sleep";
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "3000";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//add the actions
foreach ($dialplan_details as $row) {
if (strlen($row["dialplan_detail_data"]) > 1) {
$actions = explode(":", $row["dialplan_detail_data"]);
$dialplan_detail_type = array_shift($actions);
$dialplan_detail_data = join(':', $actions);
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $dialplan_detail_type;
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $dialplan_detail_data;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$dialplan_detail_order = $dialplan_detail_order + 10;
$y++;
}
}
//delete the previous details
if(strlen($dialplan_uuid) > 0) {
$sql = "delete from v_dialplan_details ";
$sql .= "where dialplan_uuid = '".$dialplan_uuid."' ";
if (!permission_exists('destination_domain')) {
$sql .= "and domain_uuid = '".$domain_uuid."' ";
}
//echo $sql."<br><br>";
$db->exec(check_sql($sql));
unset($sql);
}
//prepare the array
$array['dialplans'][] = $dialplan;
unset($dialplan);
//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->app_name = 'dialplans';
$orm->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139';
if (isset($dialplan["dialplan_uuid"])) {
$orm->uuid($dialplan["dialplan_uuid"]);
}
$orm->save($array);
$dialplan_response = $orm->message;
//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');
//update the dialplan xml
$dialplans = new dialplan;
$dialplans->source = "details";
$dialplans->destination = "database";
$dialplans->uuid = $dialplan_uuid;
$dialplans->xml();
//synchronize the xml config
save_dialplan_xml();
//clear the cache
$cache = new cache;
$cache->delete("dialplan:".$destination_context);
} //add or update the dialplan if the destination number is set
else {
//remove empty dialplan details from POST array so doesn't attempt to insert below
unset($_POST["dialplan_details"]);
//add fax detection
if (strlen($fax_uuid) > 0) {
//get the fax information
$sql = "select * from v_fax ";
$sql .= "where fax_uuid = '".$fax_uuid."' ";
if (!permission_exists('destination_domain')) {
$sql .= "and domain_uuid = '".$domain_uuid."' ";
}
//get the destination_uuid
if (strlen($dialplan_response['uuid']) > 0) {
$_POST["dialplan_uuid"] = $dialplan_response['uuid'];
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$fax_extension = $row["fax_extension"];
$fax_destination_number = $row["fax_destination_number"];
$fax_name = $row["fax_name"];
$fax_email = $row["fax_email"];
$fax_pin_number = $row["fax_pin_number"];
$fax_caller_id_name = $row["fax_caller_id_name"];
$fax_caller_id_number = $row["fax_caller_id_number"];
$fax_forward_number = $row["fax_forward_number"];
$fax_description = $row["fax_description"];
}
unset ($prep_statement);
//add the dialplan permission
$permission = "dialplan_edit";
$p = new permissions;
$p->add($permission, 'temp');
//delete previous fax detection settings
$sql = "delete from v_dialplan_details ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= "and dialplan_uuid = '".$dialplan_uuid."' ";
$sql .= "and (";
$sql .= " dialplan_detail_data like '%tone_detect%' ";
$sql .= " or dialplan_detail_type = 'tone_detect' ";
$sql .= " or (dialplan_detail_type = 'sleep' and dialplan_detail_data = '3000') ";
$sql .= ")";
$db->exec($sql);
unset($sql);
//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;
//add set tone detect_hits=1
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "tone_detect_hits=1";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//remove the temporary permission
$p->delete($permission, 'temp');
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
//get the destination_uuid
if (strlen($destination_response['uuid']) > 0) {
$destination_uuid = $destination_response['uuid'];
}
// execute on tone detect
$dialplan["dialplan_details"][$y]["domain_uuid"] = $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"] = "execute_on_tone_detect=transfer ".$fax_extension." XML \${domain_name}";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//redirect the user
if ($action == "add") {
$_SESSION["message"] = $text['message-add'];
// billing
if (file_exists($_SERVER["PROJECT_ROOT"]."/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);
$billing_uuid = $db2->result[0]['billing_uuid'];
$balance = $db2->result[0]['balance'];
unset($db2->sql, $db2->result);
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
$balance -= $destination_sell_current_currency;
$db2->sql = "update v_billings set balance = $balance, old_balance = $balance where type_value='$destination_accountcode'";
$db2->result = $db2->execute();
unset($db2->sql, $db2->result);
//add tone_detect fax 1100 r +5000
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "tone_detect";
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "fax 1100 r +5000";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
$billing_invoice_uuid = uuid();
$user_uuid = check_str($_SESSION['user_uuid']);
$settled=1;
$mc_gross = -1 * $destination_sell_current_currency;
$post_payload = serialize($_POST);
$db2->sql = "insert into v_billing_invoices (billing_invoice_uuid, billing_uuid, payer_uuid, billing_payment_date, settled, amount, debt, post_payload,plugin_used, domain_uuid) values ('$billing_invoice_uuid', '$billing_uuid', '$user_uuid', NOW(), $settled, $mc_gross, $balance, '$post_payload', 'DID $destination_number Assigment', '".$domain_uuid."' )";
$db2->result = $db2->execute();
unset($db2->sql, $db2->result);
}
}
if ($action == "update") {
$_SESSION["message"] = $text['message-update'];
}
header("Location: destination_edit.php?id=".$destination_uuid);
return;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
// execute on tone detect
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "sleep";
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "3000";
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$y++;
//increment the dialplan detail order
$dialplan_detail_order = $dialplan_detail_order + 10;
}
//add the actions
foreach ($dialplan_details as $row) {
if (strlen($row["dialplan_detail_data"]) > 1) {
$actions = explode(":", $row["dialplan_detail_data"]);
$dialplan_detail_type = array_shift($actions);
$dialplan_detail_data = join(':', $actions);
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $dialplan_detail_type;
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $dialplan_detail_data;
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
$dialplan_detail_order = $dialplan_detail_order + 10;
$y++;
}
}
//delete the previous details
if ($action == "update") {
$sql = "delete from v_dialplan_details ";
$sql .= "where dialplan_uuid = '".$dialplan_uuid."' ";
if (!permission_exists('destination_domain')) {
$sql .= "and domain_uuid = '".$domain_uuid."' ";
}
//echo $sql."<br><br>";
$db->exec(check_sql($sql));
unset($sql);
}
//remove empty dialplan details from the POST array
unset($_POST["dialplan_details"]);
//make sure the dialplan_uuid is set
if(strlen($_POST["dialplan_uuid"]) == 0) {
$_POST["dialplan_uuid"] = $dialplan_uuid;
}
//prepare the array
$array['destinations'][] = $_POST;
$array['dialplans'][] = $dialplan;
unset($dialplan);
//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->app_name = 'dialplans';
$orm->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139';
if (isset($dialplan["dialplan_uuid"])) {
$orm->uuid($dialplan["dialplan_uuid"]);
}
$orm->save($array);
$dialplan_response = $orm->message;
//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');
//update the dialplan xml
$dialplans = new dialplan;
$dialplans->source = "details";
$dialplans->destination = "database";
$dialplans->uuid = $dialplan_uuid;
$dialplans->xml();
//synchronize the xml config
save_dialplan_xml();
//clear the cache
$cache = new cache;
$cache->delete("dialplan:".$destination_context);
//redirect the user
if ($action == "add") {
$_SESSION["message"] = $text['message-add'];
}
if ($action == "update") {
$_SESSION["message"] = $text['message-update'];
}
header("Location: destination_edit.php?id=".$destination_uuid);
return;
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0)
//initialize the destinations object
@ -787,46 +726,6 @@
echo "</td>\n";
echo "</tr>\n";
// billing
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){
echo "<tr id='tr_sell'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-monthly_price']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='number' min='0' step='0.01' name='destination_sell' maxlength='255' value=\"$destination_sell\">\n";
currency_select($currency);
echo "<br />\n";
echo $text['description-monthly_price']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr id='tr_buy'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-monthly_price_buy']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='number' min='0' step='0.01' name='destination_buy' maxlength='255' value=\"$destination_buy\">\n";
currency_select($currency_buy,0,'currency_buy');
echo "<br />\n";
echo $text['description-monthly_price_buy']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr id='tr_carrier'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-carrier']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='destination_carrier' maxlength='255' value=\"$destination_carrier\">\n";
echo "<br />\n";
echo $text['description-carrier']."\n";
echo "</td>\n";
//set the default account code
if ($action == "add") { $destination_accountcode = $_SESSION['domain_name']; }
}
echo "<tr id='tr_account_code'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-account_code']."\n";
@ -835,9 +734,6 @@
echo " <input class='formfld' type='text' name='destination_accountcode' maxlength='255' value=\"$destination_accountcode\">\n";
echo "<br />\n";
echo $text['description-account_code']."\n";
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){
echo " ".$text['billing-warning'];
}
echo "</td>\n";
if (permission_exists('destination_domain')) {