Fix call broadcast file upload
This commit is contained in:
@@ -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";
|
||||||
|
|||||||
@@ -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,61 +172,65 @@
|
|||||||
$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]);
|
||||||
|
|
||||||
if (is_numeric($phone_1)) {
|
//skip the if empty or not numeric
|
||||||
//get the dialplan variables and bridge statement
|
if (empty($phone_number) || !is_numeric($phone_number)) {
|
||||||
//$dialplan = new dialplan;
|
continue;
|
||||||
//$dialplan->domain_uuid = $_SESSION['domain_uuid'];
|
}
|
||||||
//$dialplan->outbound_routes($phone_1);
|
|
||||||
//$dialplan_variables = $dialplan->variables;
|
|
||||||
//$bridge_array[0] = $dialplan->bridges;
|
|
||||||
|
|
||||||
//prepare the string
|
//get the dialplan variables and bridge statement
|
||||||
$channel_variables = "ignore_early_media=true";
|
//$dialplan = new dialplan;
|
||||||
$channel_variables .= ",origination_number=".$phone_1;
|
//$dialplan->domain_uuid = $_SESSION['domain_uuid'];
|
||||||
$channel_variables .= ",origination_caller_id_name='$broadcast_caller_id_name'";
|
//$dialplan->outbound_routes($phone_number);
|
||||||
$channel_variables .= ",origination_caller_id_number=$broadcast_caller_id_number";
|
//$dialplan_variables = $dialplan->variables;
|
||||||
$channel_variables .= ",domain_uuid=".$_SESSION['domain_uuid'];
|
//$bridge_array[0] = $dialplan->bridges;
|
||||||
$channel_variables .= ",domain=".$_SESSION['domain_name'];
|
|
||||||
$channel_variables .= ",domain_name=".$_SESSION['domain_name'];
|
//prepare the string
|
||||||
$channel_variables .= ",accountcode='$broadcast_accountcode'";
|
$channel_variables = "ignore_early_media=true";
|
||||||
$channel_variables .= ",toll_allow='$broadcast_toll_allow'";
|
$channel_variables .= ",origination_number=".$phone_number;
|
||||||
if ($broadcast_avmd == "true") {
|
$channel_variables .= ",origination_caller_id_name='$broadcast_caller_id_name'";
|
||||||
$channel_variables .= ",execute_on_answer='avmd start'";
|
$channel_variables .= ",origination_caller_id_number=$broadcast_caller_id_number";
|
||||||
|
$channel_variables .= ",domain_uuid=".$_SESSION['domain_uuid'];
|
||||||
|
$channel_variables .= ",domain=".$_SESSION['domain_name'];
|
||||||
|
$channel_variables .= ",domain_name=".$_SESSION['domain_name'];
|
||||||
|
$channel_variables .= ",accountcode='$broadcast_accountcode'";
|
||||||
|
$channel_variables .= ",toll_allow='$broadcast_toll_allow'";
|
||||||
|
if ($broadcast_avmd == "true") {
|
||||||
|
$channel_variables .= ",execute_on_answer='avmd start'";
|
||||||
|
}
|
||||||
|
//$origination_url = "{".$channel_variables."}".$bridge_array[0];
|
||||||
|
$origination_url = "{".$channel_variables."}loopback/".$phone_number.'/'.$_SESSION['domain_name'];
|
||||||
|
|
||||||
|
//get the context
|
||||||
|
$context = $_SESSION['domain_name'];
|
||||||
|
|
||||||
|
//set the command
|
||||||
|
$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 (!$fp) {
|
||||||
|
$fp = event_socket::create();
|
||||||
|
}
|
||||||
|
|
||||||
|
//method 1
|
||||||
|
$response = event_socket::command($command);
|
||||||
|
|
||||||
|
//method 2
|
||||||
|
//cmd_async($settings->get('switch', 'bin')."/fs_cli -x \"".$command."\";");
|
||||||
|
|
||||||
|
//spread the calls out so that they are scheduled with different times
|
||||||
|
if (strlen($broadcast_concurrent_limit) > 0 && !empty($broadcast_timeout)) {
|
||||||
|
if ($broadcast_concurrent_limit == $count) {
|
||||||
|
$sched_seconds = $sched_seconds + $broadcast_timeout;
|
||||||
|
$count=0;
|
||||||
}
|
}
|
||||||
//$origination_url = "{".$channel_variables."}".$bridge_array[0];
|
}
|
||||||
$origination_url = "{".$channel_variables."}loopback/".$phone_1.'/'.$_SESSION['domain_name'];
|
|
||||||
|
|
||||||
//get the context
|
//increment the count
|
||||||
$context = $_SESSION['domain_name'];
|
$count++;
|
||||||
|
|
||||||
//set the command
|
|
||||||
$cmd = "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 (!$fp) {
|
|
||||||
$fp = event_socket::create();
|
|
||||||
}
|
|
||||||
|
|
||||||
//method 1
|
|
||||||
$response = event_socket::command($cmd);
|
|
||||||
|
|
||||||
//method 2
|
|
||||||
//cmd_async($settings->get('switch', 'bin')."/fs_cli -x \"".$cmd."\";");
|
|
||||||
|
|
||||||
//spread the calls out so that they are scheduled with different times
|
|
||||||
if (strlen($broadcast_concurrent_limit) > 0 && !empty($broadcast_timeout)) {
|
|
||||||
if ($broadcast_concurrent_limit == $count) {
|
|
||||||
$sched_seconds = $sched_seconds + $broadcast_timeout;
|
|
||||||
$count=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<div align='center'>\n";
|
echo "<div align='center'>\n";
|
||||||
echo "<table width='50%'>\n";
|
echo "<table width='50%'>\n";
|
||||||
echo "<tr>\n";
|
echo "<tr>\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user