diff --git a/app/destinations/app_defaults.php b/app/destinations/app_defaults.php index fbde451a8c..38048c65b4 100644 --- a/app/destinations/app_defaults.php +++ b/app/destinations/app_defaults.php @@ -17,15 +17,16 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2017 + Portions created by the Initial Developer are Copyright (C) 2017 - 2022 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ -//update the v_destinations set destination_app and destination_data - if ($domains_processed == 1) { +if ($domains_processed == 1) { + + //update the v_destinations set destination_app and destination_data $sql = "select dialplan_uuid, dialplan_detail_type as destination_app, dialplan_detail_data as destination_data\n"; $sql .= "from v_dialplan_details\n"; $sql .= "where dialplan_uuid in (select dialplan_uuid from v_destinations where destination_type = 'inbound' and destination_app is null and destination_data is null)\n"; @@ -49,7 +50,53 @@ unset($sql, $parameters); } } - unset($extensions, $row); - } + unset($extensions, $row, $array); + + //use destinations actions to + $sql = "select * from v_destinations "; + $sql .= "where destination_actions is null "; + $database = new database; + $destinations = $database->select($sql, null, 'all'); + if (is_array($destinations)) { + $z=0; + foreach ($destinations as $row) { + //prepare the actions array + if (isset($row['destination_app']) && $row['destination_data'] != '') { + $actions[0]['destination_app'] = $row['destination_app']; + $actions[0]['destination_data'] = $row['destination_data']; + } + if (isset($row['destination_alternate_data']) && $row['destination_alternate_data'] != '') { + $actions[1]['destination_app'] = $row['destination_alternate_app']; + $actions[1]['destination_data'] = $row['destination_alternate_data']; + } + + //build the array of destinations + if (is_array($actions)) { + $array['destinations'][$z]['destination_uuid'] = $row['destination_uuid']; + $array['destinations'][$z]['destination_actions'] = json_encode($actions); + $z++; + } + } + + if (is_array($array)) { + //add temporary permissions + $p = new permissions; + $p->add('destination_edit', 'temp'); + + //create the database object and save the data + $database = new database; + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + $database->save($array, false); + unset($array); + + //remove the temporary permissions + $p->delete('destination_edit', 'temp'); + } + } + unset($sql, $num_rows); + + +} ?> diff --git a/app/destinations/destination_edit.php b/app/destinations/destination_edit.php index bea61afba8..9ec7c8c0db 100644 --- a/app/destinations/destination_edit.php +++ b/app/destinations/destination_edit.php @@ -99,6 +99,7 @@ $destination_caller_id_number = $_POST["destination_caller_id_number"]; $destination_cid_name_prefix = $_POST["destination_cid_name_prefix"]; $destination_context = $_POST["destination_context"]; + $destination_actions = $_POST["destination_actions"]; $fax_uuid = $_POST["fax_uuid"]; $provider_uuid = $_POST["provider_uuid"]; $user_uuid = $_POST["user_uuid"]; @@ -119,16 +120,6 @@ $destination_type_text = $_POST["destination_type_text"]; $destination_type_emergency = $_POST["destination_type_emergency"]; $destination_carrier = $_POST["destination_carrier"]; - - //get the destination app and data - $destination_action_array = explode(":", $_POST["destination_action"], 2); - $destination_app = $destination_action_array[0]; - $destination_data = $destination_action_array[1]; - - //get the alternate destination app and data - $destination_alternate_action_array = explode(":", $_POST["destination_alternate_action"], 2); - $destination_alternate_app = $destination_alternate_action_array[0]; - $destination_alternate_data = $destination_alternate_action_array[1]; } //process the http post @@ -223,7 +214,7 @@ } } - //if the user doesn't have the correct permission then + //if the user doesn't have the correct permission then //override variables using information from the database if (is_array($row) && @sizeof($row) != 0) { if (!permission_exists('destination_prefix')) { @@ -422,6 +413,15 @@ $dialplan_detail_type = "destination_number"; } + //set the last destination_app and destination_data variables + foreach($destination_actions as $action) { + $action_array = explode(":", $action, 2); + if (isset($action_array[1]) && $action_array[1] != '') { + $destination_app = $action_array[0]; + $destination_data = $action_array[1]; + } + } + //build the xml dialplan $dialplan["dialplan_xml"] = "\n"; $dialplan["dialplan_xml"] .= " \n"; @@ -463,12 +463,19 @@ $dialplan["dialplan_xml"] .= " \n"; $dialplan["dialplan_xml"] .= " \n"; } - if ($destination->valid($destination_app.':'.$destination_data)) { - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($destination_alternate_app) > 0 && $destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { - $dialplan["dialplan_xml"] .= " \n"; + + //add the actions to the dialplan_xml + foreach($destination_actions as $action) { + $action_array = explode(":", $action, 2); + if (isset($action_array[1]) && $action_array[1] != '') { + $destination_app = $action_array[0]; + $destination_data = $action_array[1]; + if ($destination->valid($destination_app.':'.$destination_data)) { + $dialplan["dialplan_xml"] .= " \n"; + } + } } + $dialplan["dialplan_xml"] .= " \n"; $dialplan["dialplan_xml"] .= "\n"; @@ -588,7 +595,7 @@ $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; } - + //add fax detection if (is_uuid($fax_uuid)) { @@ -714,54 +721,42 @@ } //add the actions - if ($destination->valid($destination_app.':'.$destination_data)) { - //add to the dialplan_details array - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $destination_app; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_data; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + foreach($destination_actions as $field) { + $action_array = explode(":", $field, 2); + $action_app = $action_array[0]; + $action_data = $action_array[1]; + if (isset($action_array[1]) && $action_array[1] != '') { + if ($destination->valid($action_app.':'.$action_data)) { + //add to the dialplan_details array + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $action_app; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $action_data; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - //set inline to true - if ($destination_app == 'set' || $destination_data == 'export') { - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + //set inline to true + if ($action_app == 'set' || $action_app == 'export') { + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + } + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } } - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - if ($destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { - //add to the dialplan_details array - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $destination_alternate_app; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_alternate_data; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - - //set inline to true - if ($destination_alternate_app == 'set' || $destination_alternate_app == 'export') { - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; - } - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; } //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 or domain_uuid is null) "; - $parameters['domain_uuid'] = $domain_uuid; - } - $parameters['dialplan_uuid'] = $dialplan_uuid; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); + $sql = "delete from v_dialplan_details "; + $sql .= "where dialplan_uuid = :dialplan_uuid "; + if (!permission_exists('destination_domain')) { + $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; + $parameters['domain_uuid'] = $domain_uuid; } + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); } //build the destination array @@ -811,22 +806,23 @@ if (permission_exists('destination_emergency')){ $array['destinations'][$x]["destination_type_emergency"] = $destination_type_emergency ? 1 : null; } - if (strlen($destination_app) == 0) { - $array['destinations'][$x]["destination_app"] = null; - $array['destinations'][$x]["destination_data"] = null; - } - elseif ($destination->valid($destination_app.':'.$destination_data)) { - $array['destinations'][$x]["destination_app"] = $destination_app; - $array['destinations'][$x]["destination_data"] = $destination_data; - } - if (strlen($destination_alternate_app) == 0) { - $array['destinations'][$x]["destination_alternate_app"] = null; - $array['destinations'][$x]["destination_alternate_data"] = null; - } - elseif ($destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { - $array['destinations'][$x]["destination_alternate_app"] = $destination_alternate_app; - $array['destinations'][$x]["destination_alternate_data"] = $destination_alternate_data; + + //prepare the $actions array + $y=0; + foreach($destination_actions as $action) { + $action_array = explode(":", $action, 2); + $action_app = $action_array[0]; + $action_data = $action_array[1]; + if (isset($action_array[1]) && $action_array[1] != '') { + if ($destination->valid($action_app.':'.$action_data)) { + $actions[$y]['destination_app'] = $action_app; + $actions[$y]['destination_data'] = $action_data; + $y++; + } + } } + $array['destinations'][$x]["destination_actions"] = json_encode($actions); + $array['destinations'][$x]["destination_order"] = $destination_order; $array['destinations'][$x]["destination_enabled"] = $destination_enabled; $array['destinations'][$x]["destination_description"] = $destination_description; @@ -961,10 +957,7 @@ $destination_type_text = $row["destination_type_text"]; $destination_type_emergency = $row["destination_type_emergency"]; $destination_context = $row["destination_context"]; - $destination_app = $row["destination_app"]; - $destination_data = $row["destination_data"]; - $destination_alternate_app = $row["destination_alternate_app"]; - $destination_alternate_data = $row["destination_alternate_data"]; + $destination_actions = $row["destination_actions"]; $fax_uuid = $row["fax_uuid"]; $provider_uuid = $row["provider_uuid"]; $user_uuid = $row["user_uuid"]; @@ -982,6 +975,9 @@ } } +//decode the json to an array + $destination_actions = json_decode($destination_actions, true); + //get the dialplan details in an array $sql = "select * from v_dialplan_details "; $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; @@ -1179,6 +1175,7 @@ echo "\n"; + //destination type echo "\n"; echo "\n"; echo "\n"; + //destination number if (permission_exists('destination_number')) { echo "\n"; echo "\n"; } + //trunk prefix if (permission_exists('destination_trunk_prefix')) { echo "\n"; echo "\n"; } + //area code if (permission_exists('destination_area_code')) { echo "\n"; echo "\n"; } + //destination number echo "\n"; echo "\n"; echo "\n"; - + + //condition field if (permission_exists('destination_condition_field')) { echo "\n"; echo "\n"; } + //caller id name if (permission_exists('destination_caller_id_name')) { echo "\n"; echo "\n"; } + //caler id number if (permission_exists('destination_caller_id_number')) { echo "\n"; echo "\n"; } + //context if (permission_exists('destination_context')) { echo "\n"; echo "\n"; } + //destination actions echo "\n"; echo "\n"; echo "\n"; + $x=0; + foreach($destination_actions as $row) { + echo $destination->select('dialplan', "destination_actions[$x]", $row['destination_app'].':'.$row['destination_data']); + echo "
\n"; + $x++; + } + //destination action + echo $destination->select('dialplan', "destination_actions[$x]", ''); + + //fax destinations if (permission_exists('destination_fax')) { $sql = "select * from v_fax "; $sql .= "where domain_uuid = :domain_uuid "; @@ -1351,6 +1361,7 @@ unset($sql, $parameters, $result, $row); } + //providers if (permission_exists('provider_edit') && is_array($providers) && @sizeof($providers) != 0) { echo "\n"; echo "\n"; } + //users if (permission_exists('user_edit')) { echo "\n"; echo "\n"; } + //groups if (permission_exists('group_edit')) { echo "\n"; echo "\n"; } + //caller id name prefix if (permission_exists('destination_cid_name_prefix')) { echo "\n"; echo "\n"; } + //record if ($destination_type == 'inbound' && permission_exists('destination_record')) { echo "\n"; echo "\n"; @@ -1451,6 +1466,7 @@ echo "\n"; } + //hold music if (permission_exists("destination_hold_music") && is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/music_on_hold')) { echo "\n"; echo "\n"; } + //distinctive ring if (permission_exists("destination_distinctive_ring")) { echo "\n"; echo "\n"; } + //account code if (permission_exists("destination_accountcode")) { echo "\n"; echo "\n"; } + //destination types echo "\n"; echo "\n"; echo "\n"; + //domain if (permission_exists('destination_domain')) { echo "\n"; echo "\n"; echo " \n"; echo " \n"; + //enabled echo "\n"; echo "\n"; echo "\n"; + //description echo "\n"; echo "
\n"; echo " ".$text['label-destination_type']."\n"; @@ -1200,6 +1197,7 @@ echo "
\n"; @@ -1213,6 +1211,7 @@ echo "
\n"; @@ -1226,6 +1225,7 @@ echo "
\n"; @@ -1239,6 +1239,7 @@ echo "
\n"; echo " ".$text['label-destination_number']."\n"; @@ -1254,7 +1255,8 @@ } echo "
\n"; @@ -1268,6 +1270,7 @@ echo "
\n"; @@ -1281,6 +1284,7 @@ echo "
\n"; @@ -1294,6 +1298,7 @@ echo "
\n"; @@ -1307,18 +1312,23 @@ echo "
\n"; echo " ".$text['label-detail_action']."\n"; echo "\n"; - $destination_action = $destination_app.":".$destination_data; - echo $destination->select('dialplan', 'destination_action', $destination_action); - echo "
\n"; - $destination_alternate_action = $destination_alternate_app.":".$destination_alternate_data; - echo $destination->select('dialplan', 'destination_alternate_action', $destination_alternate_action); - echo "
\n"; @@ -1374,6 +1385,7 @@ echo "
\n"; @@ -1394,6 +1406,7 @@ echo "
\n"; @@ -1414,6 +1427,7 @@ echo "
\n"; @@ -1427,6 +1441,7 @@ echo "
".$text['label-destination_record']."
\n"; @@ -1466,6 +1482,7 @@ echo "
\n"; @@ -1479,6 +1496,7 @@ echo "
\n"; @@ -1491,6 +1509,7 @@ echo "
\n"; echo " ".$text['label-usage']."\n"; @@ -1507,6 +1526,7 @@ echo "
\n"; @@ -1538,6 +1558,7 @@ echo "\n"; } + //order echo "
\n"; echo " ".$text['label-order']."\n"; @@ -1563,6 +1584,7 @@ echo "
\n"; echo " ".$text['label-destination_enabled']."\n"; @@ -1582,6 +1604,7 @@ echo "
\n"; echo " ".$text['label-destination_description']."\n"; @@ -1596,6 +1619,7 @@ echo "
"; echo "

"; + //hidden values if ($action == "update") { echo "\n"; echo "\n"; diff --git a/app/destinations/destination_imports.php b/app/destinations/destination_imports.php index 716812f6a1..c361d78d7e 100644 --- a/app/destinations/destination_imports.php +++ b/app/destinations/destination_imports.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2018-2020 + Portions created by the Initial Developer are Copyright (C) 2018-2022 the Initial Developer. All Rights Reserved. Contributor(s): @@ -216,6 +216,11 @@ //add the actions foreach ($array['destinations'] as $row) { + //build the array + $actions[0]['destination_app'] = $row['destination_app']; + $actions[0]['destination_data'] = $row['destination_data']; + $destination_actions = json_encode($actions); + //get the values $destination_number = $row['destination_number']; $destination_app = $row['destination_app']; @@ -235,6 +240,7 @@ //add the additional fields $dialplan_uuid = uuid(); + $array["destinations"][$row_id]['destination_actions'] = $destination_actions; $array["destinations"][$row_id]['destination_type'] = $destination_type; $array["destinations"][$row_id]['destination_record'] = $destination_record; $array["destinations"][$row_id]['destination_context'] = $destination_context; @@ -404,7 +410,7 @@ $dialplan_detail_order = $dialplan_detail_order + 10; } - //set the call accountcode + //set the destination app and data if (strlen($destination_app) > 0 && strlen($destination_data) > 0) { $array["dialplans"][$row_id]["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; @@ -413,6 +419,11 @@ $array["dialplans"][$row_id]["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; $y++; + //set inline to true + if ($action_app == 'set' || $action_app == 'export') { + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + } + //increment the dialplan detail order $dialplan_detail_order = $dialplan_detail_order + 10; } @@ -731,7 +742,7 @@ echo $text['description-destination_type']."\n"; echo "\n"; echo "\n"; - + echo "\n"; echo "\n"; echo " ".$text['label-destination_record']."\n"; diff --git a/app/destinations/destinations.php b/app/destinations/destinations.php index 987f735c52..fcd2366fba 100644 --- a/app/destinations/destinations.php +++ b/app/destinations/destinations.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2021 + Portions created by the Initial Developer are Copyright (C) 2008-2022 the Initial Developer. All Rights Reserved. Contributor(s): @@ -279,9 +279,20 @@ if (is_array($destinations) && @sizeof($destinations) != 0) { $x = 0; foreach($destinations as $row) { + + //prepare the destination actions + $destination_actions = json_decode($row['destination_actions'], true); + foreach($destination_actions as $action) { + $destination_app = $action['destination_app']; + $destination_data = $action['destination_data']; + } + + //create the row link if (permission_exists('destination_edit')) { $list_row_url = "destination_edit.php?id=".urlencode($row['destination_uuid']); } + + //show the data echo "\n"; if (permission_exists('destination_delete')) { echo " \n"; @@ -299,7 +310,7 @@ echo " ".escape($domain)."\n"; } echo " ".escape($row['destination_type'])." \n"; - + echo " ".escape($row['destination_prefix'])." \n"; if (permission_exists('destination_trunk_prefix')) { echo " ".escape($row['destination_trunk_prefix'])." \n"; @@ -318,7 +329,7 @@ echo " \n"; if (!$_GET['show'] == "all") { - echo " ".action_name($destination_array, $row['destination_app'].':'.$row['destination_data'])." \n"; + echo " ".action_name($destination_array, $destination_app.':'.$destination_data)." \n"; } if (permission_exists("destination_context")) { echo " ".escape($row['destination_context'])." \n";