Add destination conditions.
This commit is contained in:
parent
ca5ef8d03d
commit
8ce558702a
|
|
@ -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_conditions = $_POST["destination_conditions"];
|
||||
$destination_actions = $_POST["destination_actions"];
|
||||
$fax_uuid = $_POST["fax_uuid"];
|
||||
$provider_uuid = $_POST["provider_uuid"];
|
||||
|
|
@ -120,6 +121,21 @@
|
|||
$destination_type_text = $_POST["destination_type_text"];
|
||||
$destination_type_emergency = $_POST["destination_type_emergency"];
|
||||
$destination_carrier = $_POST["destination_carrier"];
|
||||
|
||||
//sanitize the destination conditions
|
||||
if (is_array($destination_conditions)) {
|
||||
$i=0;
|
||||
foreach($destination_conditions as $row) {
|
||||
if (isset($row['condition_expression']) && strlen($row['condition_expression']) > 0) {
|
||||
if ($row['condition_field'] == 'caller_id_number') {
|
||||
$row['condition_expression'] = preg_replace('#[^\+0-9\*]#', '', $row['condition_expression']);
|
||||
$conditions[$i]['condition_field'] = $row['condition_field'];
|
||||
$conditions[$i]['condition_expression'] = $row['condition_expression'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//process the http post
|
||||
|
|
@ -424,6 +440,20 @@
|
|||
|
||||
//build the xml dialplan
|
||||
$dialplan["dialplan_xml"] = "<extension name=\"".$dialplan["dialplan_name"]."\" continue=\"false\" uuid=\"".$dialplan_uuid."\">\n";
|
||||
|
||||
//add the dialplan xml destination conditions
|
||||
if (is_array($conditions)) {
|
||||
foreach($conditions as $row) {
|
||||
if (is_numeric($row['condition_expression']) && strlen($destination_number) == strlen($row['condition_expression']) && strlen($destination_prefix) > 0) {
|
||||
$condition_expression = '\+?'.$destination_prefix.'?'.$row['condition_expression'];
|
||||
}
|
||||
else {
|
||||
$condition_expression = str_replace("+", "\+", $row['condition_expression']);
|
||||
}
|
||||
$dialplan["dialplan_xml"] .= " <condition field=\"".$row['condition_field']."\" expression=\"^".$condition_expression."$\"/>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$dialplan["dialplan_xml"] .= " <condition field=\"".$dialplan_detail_type."\" expression=\"".$destination_number_regex."\">\n";
|
||||
$dialplan["dialplan_xml"] .= " <action application=\"export\" data=\"call_direction=inbound\" inline=\"true\"/>\n";
|
||||
$dialplan["dialplan_xml"] .= " <action application=\"set\" data=\"domain_uuid=".$_SESSION['domain_uuid']."\" inline=\"true\"/>\n";
|
||||
|
|
@ -468,10 +498,8 @@
|
|||
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"] .= " <action application=\"".$destination_app."\" data=\"".$destination_data."\"/>\n";
|
||||
if ($destination->valid($action_array[0].':'.$action_array[1])) {
|
||||
$dialplan["dialplan_xml"] .= " <action application=\"".$action_array[0]."\" data=\"".$action_array[1]."\"/>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -482,12 +510,40 @@
|
|||
//dialplan details
|
||||
if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") {
|
||||
|
||||
//set initial value of the row id
|
||||
$y=0;
|
||||
|
||||
//increment the dialplan detail order
|
||||
$dialplan_detail_order = $dialplan_detail_order + 10;
|
||||
|
||||
//add the dialplan detail destination conditions
|
||||
if (is_array($conditions)) {
|
||||
foreach($conditions as $row) {
|
||||
//prepare the expression
|
||||
if (is_numeric($row['condition_expression']) && strlen($destination_number) == strlen($row['condition_expression']) && strlen($destination_prefix) > 0) {
|
||||
$condition_expression = '\+?'.$destination_prefix.'?'.$row['condition_expression'];
|
||||
}
|
||||
else {
|
||||
$condition_expression = str_replace("+", "\+", $row['condition_expression']);
|
||||
}
|
||||
|
||||
//add to the dialplan_details array
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $row['condition_field'];
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = '^'.$condition_expression.'$';
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order;
|
||||
$y++;
|
||||
|
||||
//increment the dialplan detail order
|
||||
$dialplan_detail_order = $dialplan_detail_order + 10;
|
||||
}
|
||||
}
|
||||
|
||||
//check the destination number
|
||||
$y=0;
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition";
|
||||
if (strlen($destination_condition_field) > 0) {
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $destination_condition_field;
|
||||
|
|
@ -509,6 +565,7 @@
|
|||
if ($destination_app == 'bridge') {
|
||||
//add hangup_after_bridge
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_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";
|
||||
|
|
@ -521,6 +578,7 @@
|
|||
|
||||
//add continue_on_fail
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "continue_on_fail=true";
|
||||
|
|
@ -535,6 +593,7 @@
|
|||
//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_uuid"] = $dialplan_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}";
|
||||
|
|
@ -549,6 +608,7 @@
|
|||
//set the call accountcode
|
||||
if (strlen($destination_accountcode) > 0) {
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "export";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode;
|
||||
|
|
@ -563,6 +623,7 @@
|
|||
//set the call carrier
|
||||
if (strlen($destination_carrier) > 0) {
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_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";
|
||||
|
|
@ -577,6 +638,7 @@
|
|||
//set the hold music
|
||||
if (strlen($destination_hold_music) > 0) {
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "export";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "hold_music=".$destination_hold_music;
|
||||
|
|
@ -588,6 +650,7 @@
|
|||
//set the distinctive ring
|
||||
if (strlen($destination_distinctive_ring) > 0) {
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "export";
|
||||
$dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "sip_h_Alert-Info=".$destination_distinctive_ring;
|
||||
|
|
@ -601,6 +664,7 @@
|
|||
|
||||
//add set tone detect_hits=1
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_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";
|
||||
|
|
@ -613,6 +677,7 @@
|
|||
|
||||
//execute on tone detect
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_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}";
|
||||
|
|
@ -625,6 +690,7 @@
|
|||
|
||||
//add tone_detect fax 1100 r +5000
|
||||
$dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid;
|
||||
$dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_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";
|
||||
|
|
@ -729,6 +795,7 @@
|
|||
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_uuid"] = $dialplan_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;
|
||||
|
|
@ -807,6 +874,15 @@
|
|||
$array['destinations'][$x]["destination_type_emergency"] = $destination_type_emergency ? 1 : null;
|
||||
}
|
||||
|
||||
//prepare the destination_conditions json
|
||||
if (is_array($conditions)) {
|
||||
$array['destinations'][$x]["destination_conditions"] = json_encode($conditions);
|
||||
unset($conditions);
|
||||
}
|
||||
else {
|
||||
$array['destinations'][$x]["destination_conditions"] = '';
|
||||
}
|
||||
|
||||
//prepare the $actions array
|
||||
$y=0;
|
||||
foreach($destination_actions as $action) {
|
||||
|
|
@ -957,6 +1033,7 @@
|
|||
$destination_type_text = $row["destination_type_text"];
|
||||
$destination_type_emergency = $row["destination_type_emergency"];
|
||||
$destination_context = $row["destination_context"];
|
||||
$destination_conditions = $row["destination_conditions"];
|
||||
$destination_actions = $row["destination_actions"];
|
||||
$fax_uuid = $row["fax_uuid"];
|
||||
$provider_uuid = $row["provider_uuid"];
|
||||
|
|
@ -976,8 +1053,21 @@
|
|||
}
|
||||
|
||||
//decode the json to an array
|
||||
$destination_conditions = json_decode($destination_conditions, true);
|
||||
$destination_actions = json_decode($destination_actions, true);
|
||||
|
||||
//prepare the conditions array, add an empty row
|
||||
if (is_array($destination_conditions)) {
|
||||
$i=0;
|
||||
foreach ($destination_conditions as $row) { $i++; }
|
||||
$destination_conditions[$i]['condition_field'] = '';
|
||||
$destination_conditions[$i]['condition_expression'] = '';
|
||||
}
|
||||
else {
|
||||
$destination_conditions[0]['condition_field'] = '';
|
||||
$destination_conditions[0]['condition_expression'] = '';
|
||||
}
|
||||
|
||||
//get the dialplan details in an array
|
||||
$sql = "select * from v_dialplan_details ";
|
||||
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
|
||||
|
|
@ -1185,7 +1275,7 @@
|
|||
switch ($destination_type) {
|
||||
case "inbound" : $selected[0] = "selected='selected'"; break;
|
||||
case "outbound" : $selected[1] = "selected='selected'"; break;
|
||||
case "local" : $selected[2] = "selected='selected'"; break;
|
||||
case "local" : $selected[2] = "selected='selected'"; break;
|
||||
}
|
||||
echo " <option value='inbound' ".$selected[0].">".$text['option-inbound']."</option>\n";
|
||||
echo " <option value='outbound' ".$selected[1].">".$text['option-outbound']."</option>\n";
|
||||
|
|
@ -1312,21 +1402,51 @@
|
|||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
//destination conditions
|
||||
if (permission_exists('destination_conditions')) {
|
||||
echo "<tr id='tr_actions'>\n";
|
||||
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
||||
echo " ".$text['label-destination_conditions']."\n";
|
||||
echo "</td>\n";
|
||||
echo "<td class='vtable' align='left'>\n";
|
||||
$x=0;
|
||||
foreach ($destination_conditions as $row) {
|
||||
echo " <select name=\"destination_conditions[$x][condition_field]\" id='destination_conditions' class='formfld' style='".$select_style."'>\n";
|
||||
echo " <option value=''></option>\n";
|
||||
if ($row['condition_field'] == 'caller_id_number') {
|
||||
echo " <option value=\"caller_id_number\" selected='selected'>".$text['label-option-caller_id_number']."</option>\n";
|
||||
}
|
||||
else {
|
||||
echo " <option value=\"caller_id_number\">".$text['option-caller_id_number']."</option>\n";
|
||||
}
|
||||
echo " </select>\n";
|
||||
echo " <input class='formfld' type='text' name=\"destination_conditions[$x][condition_expression]\" id='destination_conditions' maxlength='255' value=\"".escape($row['condition_expression'])."\">\n";
|
||||
echo " <br />\n";
|
||||
$x++;
|
||||
}
|
||||
echo " ".$text['description-destination_conditions']."\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
||||
//destination actions
|
||||
echo "<tr id='tr_actions'>\n";
|
||||
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
||||
echo " ".$text['label-detail_action']."\n";
|
||||
echo " ".$text['label-destination_actions']."\n";
|
||||
echo "</td>\n";
|
||||
echo "<td class='vtable' align='left'>\n";
|
||||
$x=0;
|
||||
foreach($destination_actions as $row) {
|
||||
//view_array($row, false);
|
||||
echo $destination->select('dialplan', "destination_actions[$x]", $row['destination_app'].':'.$row['destination_data']);
|
||||
echo "<br />\n";
|
||||
$x++;
|
||||
}
|
||||
|
||||
//destination action
|
||||
echo $destination->select('dialplan', "destination_actions[$x]", '');
|
||||
echo " <br />\n";
|
||||
echo " ".$text['description-destination_actions']."\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
|
||||
//fax destinations
|
||||
if (permission_exists('destination_fax')) {
|
||||
|
|
@ -1462,6 +1582,7 @@
|
|||
}
|
||||
echo " </select>\n";
|
||||
echo "<br />\n";
|
||||
echo $text['description-destination_record']."\n";
|
||||
echo "</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
|
|
@ -1580,7 +1701,8 @@
|
|||
$i++;
|
||||
}
|
||||
echo " </select>\n";
|
||||
echo " <br />\n";
|
||||
echo "<br />\n";
|
||||
echo $text['description-destination_order']."\n";
|
||||
echo " </td>\n";
|
||||
echo " </tr>\n";
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue