Fix call broadcast file upload

This commit is contained in:
FusionPBX
2026-04-12 00:50:23 +00:00
committed by GitHub
parent 8084d95810
commit aba6b6fde0
2 changed files with 68 additions and 102 deletions
+13 -51
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2025 Portions created by the Initial Developer are Copyright (C) 2008-2026
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@@ -60,52 +60,6 @@
$broadcast_description = ''; $broadcast_description = '';
$broadcast_toll_allow = ''; $broadcast_toll_allow = '';
//function to Upload CSV/TXT file
/**
* Uploads a file and prepares the SQL query for broadcasting phone numbers.
*
* @param string $sql The initial SQL query.
* @param mixed $broadcast_phone_numbers The phone numbers to broadcast, or an empty value if not applicable.
*
* @return array An array containing the result code ('code') and the prepared SQL query ('sql').
*/
function upload_file($sql, $broadcast_phone_numbers) {
$upload_csv = $sql = '';
if (isset($_FILES['broadcast_phone_numbers_file']) && !empty($_FILES['broadcast_phone_numbers_file']) && $_FILES['broadcast_phone_numbers_file']['size'] > 0) {
$filename=$_FILES["broadcast_phone_numbers_file"]["tmp_name"];
$file_extension = array('application/octet-stream','application/vnd.ms-excel','text/plain','text/csv','text/tsv');
if (in_array($_FILES['broadcast_phone_numbers_file']['type'],$file_extension)) {
$file = fopen($filename, "r");
$count = 0;
while (($getData = fgetcsv($file, 0, "\n")) !== FALSE)
{
$count++;
if ($count == 1) { continue; }
$getData = preg_split('/[ ,|]/', $getData[0], '', PREG_SPLIT_NO_EMPTY);
$separator = $getData[0];
$separator .= (isset($getData[1]) && $getData[1] != '')? '|'.$getData[1] : '';
$separator .= (isset($getData[2]) && $getData[2] != '')? ','.$getData[2] : '';
$separator .= PHP_EOL;
$upload_csv .= $separator;
}
fclose($file);
}
else {
return array('code'=>false,'sql'=>'');
}
}
if (!empty($broadcast_phone_numbers) && !empty($upload_csv)) {
$sql .= $broadcast_phone_numbers.'\n'.$upload_csv;
}
elseif (empty($broadcast_phone_numbers) && !empty($upload_csv)) {
$sql .= $upload_csv;
}
else {
$sql .= $broadcast_phone_numbers;
}
return array('code'=>true,'sql'=> $sql);
}
//get the http post variables and set them to php variables //get the http post variables and set them to php variables
if (!empty($_POST)) { if (!empty($_POST)) {
$broadcast_name = $_POST["broadcast_name"]; $broadcast_name = $_POST["broadcast_name"];
@@ -226,15 +180,23 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) {
//execute //execute
if (!empty($array)) { if (!empty($array)) {
//save the phone numbers upload the file
$upload_csv = $sql = '';
if (isset($_FILES['ulfile']) && !empty($_FILES['ulfile']) && $_FILES['ulfile']['size'] > 0) {
$file_name = $_FILES["ulfile"]["tmp_name"];
$allowed_file_extensions = array('application/octet-stream','application/vnd.ms-excel','text/plain','text/csv','text/tsv');
if (in_array($_FILES['ulfile']['type'], $allowed_file_extensions)) {
$broadcast_phone_numbers = file_get_contents($_FILES["ulfile"]["tmp_name"]);
}
}
//add file selection and download sample //add file selection and download sample
$file_res = upload_file($sql ?? '', $broadcast_phone_numbers); if (empty($broadcast_phone_numbers)) {
if ($file_res['code'] != true) {
$_SESSION["message_mood"] = "negative"; $_SESSION["message_mood"] = "negative";
$_SESSION["message"] = $text['file-error']; $_SESSION["message"] = $text['file-error'];
header("Location: ".$error_return_url); header("Location: ".$error_return_url);
exit; exit;
} }
$broadcast_phone_numbers = $file_res['sql'];
//build the database array //build the database array
$array['call_broadcasts'][0]['domain_uuid'] = $domain_uuid; $array['call_broadcasts'][0]['domain_uuid'] = $domain_uuid;
@@ -523,7 +485,7 @@ if (!empty($_POST) && empty($_POST["persistformvar"])) {
echo " <textarea class='formfld' style='width: 300px; height: 200px;' type='text' name='broadcast_phone_numbers' placeholder=\"".$text['label-list_example']."\">".str_replace('\n', "\n", $broadcast_phone_numbers ?? '')."</textarea>"; echo " <textarea class='formfld' style='width: 300px; height: 200px;' type='text' name='broadcast_phone_numbers' placeholder=\"".$text['label-list_example']."\">".str_replace('\n', "\n", $broadcast_phone_numbers ?? '')."</textarea>";
echo "<br><br>"; echo "<br><br>";
echo " <input type='file' name='broadcast_phone_numbers_file' accept='.csv,.txt' style=\"display:inline-block;\"><a href='sample.csv' download><i class='fas fa-cloud-download-alt' style='margin-right: 5px;'></i>".$text['label-sample_file']."</a>"; echo " <input type='file' name='ulfile' accept='.csv,.txt' style=\"display:inline-block;\"><a href='sample.csv' download><i class='fas fa-cloud-download-alt' style='margin-right: 5px;'></i>".$text['label-sample_file']."</a>";
echo "<br /><br />"; echo "<br /><br />";
echo "".$text['description-phone']." <br /><br />\n"; echo "".$text['description-phone']." <br /><br />\n";
+14 -10
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2020 Portions created by the Initial Developer are Copyright (C) 2008-2026
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@@ -172,19 +172,23 @@
$tmp_value_array = explode ("|", $tmp_value); $tmp_value_array = explode ("|", $tmp_value);
//remove the number formatting //remove the number formatting
$phone_1 = preg_replace('{\D}', '', $tmp_value_array[0]); $phone_number = preg_replace('{\D}', '', $tmp_value_array[0]);
//skip the if empty or not numeric
if (empty($phone_number) || !is_numeric($phone_number)) {
continue;
}
if (is_numeric($phone_1)) {
//get the dialplan variables and bridge statement //get the dialplan variables and bridge statement
//$dialplan = new dialplan; //$dialplan = new dialplan;
//$dialplan->domain_uuid = $_SESSION['domain_uuid']; //$dialplan->domain_uuid = $_SESSION['domain_uuid'];
//$dialplan->outbound_routes($phone_1); //$dialplan->outbound_routes($phone_number);
//$dialplan_variables = $dialplan->variables; //$dialplan_variables = $dialplan->variables;
//$bridge_array[0] = $dialplan->bridges; //$bridge_array[0] = $dialplan->bridges;
//prepare the string //prepare the string
$channel_variables = "ignore_early_media=true"; $channel_variables = "ignore_early_media=true";
$channel_variables .= ",origination_number=".$phone_1; $channel_variables .= ",origination_number=".$phone_number;
$channel_variables .= ",origination_caller_id_name='$broadcast_caller_id_name'"; $channel_variables .= ",origination_caller_id_name='$broadcast_caller_id_name'";
$channel_variables .= ",origination_caller_id_number=$broadcast_caller_id_number"; $channel_variables .= ",origination_caller_id_number=$broadcast_caller_id_number";
$channel_variables .= ",domain_uuid=".$_SESSION['domain_uuid']; $channel_variables .= ",domain_uuid=".$_SESSION['domain_uuid'];
@@ -196,13 +200,13 @@
$channel_variables .= ",execute_on_answer='avmd start'"; $channel_variables .= ",execute_on_answer='avmd start'";
} }
//$origination_url = "{".$channel_variables."}".$bridge_array[0]; //$origination_url = "{".$channel_variables."}".$bridge_array[0];
$origination_url = "{".$channel_variables."}loopback/".$phone_1.'/'.$_SESSION['domain_name']; $origination_url = "{".$channel_variables."}loopback/".$phone_number.'/'.$_SESSION['domain_name'];
//get the context //get the context
$context = $_SESSION['domain_name']; $context = $_SESSION['domain_name'];
//set the command //set the command
$cmd = "bgapi sched_api +".$sched_seconds." ".$call_broadcast_uuid." bgapi originate ".$origination_url." ".$broadcast_destination_data." XML $context"; $command = "bgapi sched_api +".$sched_seconds." ".$call_broadcast_uuid." bgapi originate ".$origination_url." ".$broadcast_destination_data." XML $context";
//if the event socket connection is lost then re-connect //if the event socket connection is lost then re-connect
if (!$fp) { if (!$fp) {
@@ -210,10 +214,10 @@
} }
//method 1 //method 1
$response = event_socket::command($cmd); $response = event_socket::command($command);
//method 2 //method 2
//cmd_async($settings->get('switch', 'bin')."/fs_cli -x \"".$cmd."\";"); //cmd_async($settings->get('switch', 'bin')."/fs_cli -x \"".$command."\";");
//spread the calls out so that they are scheduled with different times //spread the calls out so that they are scheduled with different times
if (strlen($broadcast_concurrent_limit) > 0 && !empty($broadcast_timeout)) { if (strlen($broadcast_concurrent_limit) > 0 && !empty($broadcast_timeout)) {
@@ -223,9 +227,9 @@
} }
} }
//increment the count
$count++; $count++;
} }
}
echo "<div align='center'>\n"; echo "<div align='center'>\n";
echo "<table width='50%'>\n"; echo "<table width='50%'>\n";