Update music_on_hold.php

Fix the upload to specific music on hold categories and fix an issue with case sensitivity that prevented ability to delete a file with upper case letters.
This commit is contained in:
FusionPBX 2016-07-15 10:44:27 -06:00 committed by GitHub
parent 6af31a91da
commit a4ad4113cd
1 changed files with 115 additions and 100 deletions

View File

@ -114,13 +114,21 @@
//determine name //determine name
if ($_POST['name_new'] != '') { if ($_POST['name_new'] != '') {
$stream_name = strtolower($_POST['name_new']); //set the action
$action = 'add';
//get the stream_name
$stream_name = $_POST['name_new'];
//get the rate
if (is_numeric($_POST['rate'])) { $stream_rate = $_POST['rate']; } else { $stream_rate = ''; } if (is_numeric($_POST['rate'])) { $stream_rate = $_POST['rate']; } else { $stream_rate = ''; }
} }
else { else {
//get the stream uuid
$stream_uuid = $_POST['name']; $stream_uuid = $_POST['name'];
//find the matching stream
foreach ($streams as $row) { foreach ($streams as $row) {
if ($stream_uuid == $row['music_on_hold_uuid']) { if ($stream_uuid == $row['music_on_hold_uuid']) {
//set the action
$action = 'update';
//set the variables //set the variables
$stream_domain_uuid = $row['domain_uuid']; $stream_domain_uuid = $row['domain_uuid'];
$stream_name = $row['music_on_hold_name']; $stream_name = $row['music_on_hold_name'];
@ -134,7 +142,6 @@
$stream_chime_freq = $row['music_on_hold_chime_freq']; $stream_chime_freq = $row['music_on_hold_chime_freq'];
$stream_chime_max = $row['music_on_hold_chime_max']; $stream_chime_max = $row['music_on_hold_chime_max'];
$stream_rate = $row['music_on_hold_rate']; $stream_rate = $row['music_on_hold_rate'];
//end the loop //end the loop
break; break;
} }
@ -145,6 +152,7 @@
$stream_file_name_temp = $_FILES['file']['tmp_name']; $stream_file_name_temp = $_FILES['file']['tmp_name'];
$stream_file_name = $_FILES['file']['name']; $stream_file_name = $_FILES['file']['name'];
$stream_file_ext = strtolower(pathinfo($stream_file_name, PATHINFO_EXTENSION)); $stream_file_ext = strtolower(pathinfo($stream_file_name, PATHINFO_EXTENSION));
//check file type //check file type
$valid_file_type = ($stream_file_ext == 'wav' || $stream_file_ext == 'mp3' || $stream_file_ext == 'ogg') ? true : false; $valid_file_type = ($stream_file_ext == 'wav' || $stream_file_ext == 'mp3' || $stream_file_ext == 'ogg') ? true : false;
@ -154,16 +162,18 @@
} }
else { else {
//add the new stream
if ($action == "add") {
//strip slashes, replace spaces //strip slashes, replace spaces
$slashes = array("/", "\\"); $slashes = array("/", "\\");
$stream_name = str_replace($slashes, '', $stream_name); $stream_name = str_replace($slashes, '', $stream_name);
$stream_name = str_replace(' ', '_', $stream_name); $stream_name = str_replace(' ', '_', $stream_name);
$stream_file_name = str_replace($slashes, '', $stream_file_name); $stream_file_name = str_replace($slashes, '', $stream_file_name);
$stream_file_name = str_replace(' ', '-', $stream_file_name); $stream_file_name = str_replace(' ', '-', $stream_file_name);
$stream_file_name = strtolower($stream_file_name);
//detect auto rate //detect auto rate
if ($stream_rate == 'auto') { if ($stream_rate == '') {
$stream_rate = '';
$path_rate = '48000'; $path_rate = '48000';
$stream_rate_auto = true; $stream_rate_auto = true;
} }
@ -171,8 +181,10 @@
$path_rate = $stream_rate; $path_rate = $stream_rate;
$stream_rate_auto = false; $stream_rate_auto = false;
} }
//define default path //define default path
$stream_path = path_join($_SESSION['switch']['sounds']['dir'], 'music', $_SESSION['domain_name'],$stream_name, $path_rate); $stream_path = path_join($_SESSION['switch']['sounds']['dir'], 'music', $_SESSION['domain_name'],$stream_name, $path_rate);
//find whether the path already exists //find whether the path already exists
$stream_new_name = true; $stream_new_name = true;
foreach ($streams as $row) { foreach ($streams as $row) {
@ -232,6 +244,8 @@
$db->exec(check_sql($sql)); $db->exec(check_sql($sql));
unset($sql); unset($sql);
} }
}
//check target folder, move uploaded file //check target folder, move uploaded file
if (!is_dir($stream_path)) { if (!is_dir($stream_path)) {
event_socket_mkdir($stream_path); event_socket_mkdir($stream_path);
@ -241,6 +255,7 @@
@unlink($stream_file_name_temp); @unlink($stream_file_name_temp);
} }
} }
//set message //set message
$_SESSION['message'] = $text['message-upload_completed']; $_SESSION['message'] = $text['message-upload_completed'];
} }
@ -429,7 +444,7 @@
echo " </td>\n"; echo " </td>\n";
echo " <td class='vtable' width='70%'>\n"; echo " <td class='vtable' width='70%'>\n";
echo " <select id='rate' name='rate' class='formfld' style='width: auto;'>\n"; echo " <select id='rate' name='rate' class='formfld' style='width: auto;'>\n";
echo " <option value='auto'>".$text['option-default']."</option>\n"; echo " <option value=''>".$text['option-default']."</option>\n";
echo " <option value='8000'>8 kHz</option>\n"; echo " <option value='8000'>8 kHz</option>\n";
echo " <option value='16000'>16 kHz</option>\n"; echo " <option value='16000'>16 kHz</option>\n";
echo " <option value='32000'>32 kHz</option>\n"; echo " <option value='32000'>32 kHz</option>\n";
@ -576,7 +591,7 @@
if (file_exists($stream_path)) { if (file_exists($stream_path)) {
$stream_files = array_merge(glob($stream_path.'/*.wav'), glob($stream_path.'/*.mp3'), glob($stream_path.'/*.ogg')); $stream_files = array_merge(glob($stream_path.'/*.wav'), glob($stream_path.'/*.mp3'), glob($stream_path.'/*.ogg'));
foreach ($stream_files as $stream_file_path) { foreach ($stream_files as $stream_file_path) {
$stream_file = strtolower(pathinfo($stream_file_path, PATHINFO_BASENAME)); $stream_file = pathinfo($stream_file_path, PATHINFO_BASENAME);
$stream_file_size = byte_convert(filesize($stream_file_path)); $stream_file_size = byte_convert(filesize($stream_file_path));
$stream_file_date = date("M d, Y H:i:s", filemtime($stream_file_path)); $stream_file_date = date("M d, Y H:i:s", filemtime($stream_file_path));
$stream_file_ext = pathinfo($stream_file, PATHINFO_EXTENSION); $stream_file_ext = pathinfo($stream_file, PATHINFO_EXTENSION);