MOH: Selecting an MP3 now hides the Sampling field. Selecting files other than MP3 and WAV will result in a warning message being displayed. Uploading an MP3 now places a copy of the file in all rate folders at once.

This commit is contained in:
Nate Jones 2015-04-14 16:40:51 +00:00
parent 287b12d50f
commit f6f5ef4e12
2 changed files with 225 additions and 163 deletions

View File

@ -28,6 +28,20 @@ $text['message-nofiles']['fr-fr'] = "Pas de fichier trouvé.";
$text['message-nofiles']['pt-br'] = "Não foram encontrados os arquivos";
$text['message-nofiles']['pl'] = "Nie znaleziono plików";
$text['message-upload_completed']['en-us'] = "Upload Completed";
$text['message-upload_completed']['es-cl'] = "Cargar Completado";
$text['message-upload_completed']['pt-pt'] = "Carregar Concluído";
$text['message-upload_completed']['fr-fr'] = "Upload terminé";
$text['message-upload_completed']['pt-br'] = "Carregar Concluído";
$text['message-upload_completed']['pl'] = "Prześlij Zakończony";
$text['message-unsupported_file_type']['en-us'] = "Unsupported File Type";
$text['message-unsupported_file_type']['es-cl'] = "Tipo de archivo no compatible";
$text['message-unsupported_file_type']['pt-pt'] = "Não suportado Tipo de Arquivo";
$text['message-unsupported_file_type']['fr-fr'] = "Type de fichier non pris en charge";
$text['message-unsupported_file_type']['pt-br'] = "Não suportado Tipo de Arquivo";
$text['message-unsupported_file_type']['pl'] = "Nieobsługiwany typ pliku";
$text['message-event-socket']['en-us'] = "Connection to Event Socket failed.";
$text['message-event-socket']['es-cl'] = "Conexión a socket fallida.";
$text['message-event-socket']['pt-pt'] = "A Conexão ao Event Socket falhou.";

View File

@ -44,7 +44,6 @@ else {
require_once "resources/paging.php";
//set the music on hold directory
$sampling_rate_dirs = Array(8000, 16000, 32000, 48000);
if (file_exists('/var/lib/fusionpbx/sounds/music')) {
$music_on_hold_dir = $_SESSION['switch']['sounds']['dir'].'/music/fusionpbx';
}
@ -57,107 +56,178 @@ else {
$order_by = check_str($_GET["order_by"]);
$order = check_str($_GET["order"]);
if ($_GET['a'] == "download") {
$slashes = array("/", "\\");
$_GET['category'] = str_replace($slashes, "", $_GET['category']);
$_GET['file_name'] = str_replace($slashes, "", $_GET['file_name']);
//download moh file
if ($_GET['a'] == "download") {
$slashes = array("/", "\\");
$_GET['category'] = str_replace($slashes, "", $_GET['category']);
$_GET['file_name'] = str_replace($slashes, "", $_GET['file_name']);
$category_dir = $_GET['category'];
$sampling_rate_dir = $_GET['sampling_rate'];
$category_dir = $_GET['category'];
$sampling_rate_dir = $_GET['sampling_rate'];
if ($category_dir != '') {
$path_mod = $category_dir."/";
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/".$path_mod;
}
}
session_cache_limiter('public');
if ($_GET['type'] = "moh") {
if (file_exists($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name']))) {
$fd = fopen($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name']), "rb");
if ($_GET['t'] == "bin") {
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
if ($category_dir != '') {
$path_mod = $category_dir."/";
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/".$path_mod;
}
else {
$file_ext = substr(base64_decode($_GET['file_name']), -3);
if ($file_ext == "wav") {
header("Content-Type: audio/x-wav");
}
if ($file_ext == "mp3") {
header("Content-Type: audio/mp3");
}
}
header('Content-Disposition: attachment; filename="'.base64_decode($_GET['file_name']).'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Length: " . filesize($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name'])));
fpassthru($fd);
}
}
exit;
}
if (is_uploaded_file($_FILES['upload_file']['tmp_name'])) {
$file_ext = strtolower(pathinfo($_FILES['upload_file']['name'], PATHINFO_EXTENSION));
if ($file_ext == 'wav' || $file_ext == 'mp3') {
if ($_POST['type'] == 'moh' && permission_exists('music_on_hold_add')) {
//remove the slashes
$slashes = array("/", "\\");
$_POST['upload_category_new'] = str_replace($slashes, "", $_POST['upload_category_new']);
$_FILES['upload_file']['name'] = str_replace($slashes, "", $_FILES['upload_file']['name']);
// replace any spaces in the file_name with dashes
$new_file_name = str_replace(' ', '-', $_FILES['upload_file']['name']);
// convert sampling rate from value passed by form
$sampling_rate_dir = $_POST['upload_sampling_rate'] * 1000;
// if multi-tenant, modify directory paths
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/";
}
// create new category, if necessary
if ($_POST['upload_category'] == '_NEW_CAT_' && $_POST['upload_category_new'] != '') {
$new_category_name = str_replace(' ', '_', $_POST['upload_category_new']);
if (!is_dir($music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir)) {
@mkdir($music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir, 0777, true);
}
if (is_dir($music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir)) {
move_uploaded_file($_FILES['upload_file']['tmp_name'], $music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir."/".$new_file_name);
$target_dir = $music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir;
}
}
// use existing category directory
else if ($_POST['upload_category'] != '' && $_POST['upload_category'] != '_NEW_CAT_') {
if (!is_dir($music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir)) {
@mkdir($music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir, 0777, true);
}
if (is_dir($music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir)) {
move_uploaded_file($_FILES['upload_file']['tmp_name'], $music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir."/".$new_file_name);
$target_dir = $music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir;
}
}
// use default directory
else if ($_POST['upload_category'] == '') {
if (permission_exists('music_on_hold_default_add')) {
if (!is_dir($music_on_hold_dir."/".$sampling_rate_dir)) {
@mkdir($music_on_hold_dir."/".$sampling_rate_dir, 0777, true);
}
if (is_dir($music_on_hold_dir."/".$sampling_rate_dir)) {
move_uploaded_file($_FILES['upload_file']['tmp_name'], $music_on_hold_dir."/".$sampling_rate_dir."/".$new_file_name);
$target_dir = $music_on_hold_dir."/".$sampling_rate_dir;
}
}
session_cache_limiter('public');
if ($_GET['type'] = "moh") {
if (file_exists($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name']))) {
$fd = fopen($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name']), "rb");
if ($_GET['t'] == "bin") {
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
}
else {
exit();
$file_ext = substr(base64_decode($_GET['file_name']), -3);
if ($file_ext == "wav") {
header("Content-Type: audio/x-wav");
}
if ($file_ext == "mp3") {
header("Content-Type: audio/mpeg");
}
}
header('Content-Disposition: attachment; filename="'.base64_decode($_GET['file_name']).'"');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-Length: " . filesize($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name'])));
fpassthru($fd);
}
}
exit;
}
//upload moh file
if (is_uploaded_file($_FILES['upload_file']['tmp_name'])) {
$file_ext = strtolower(pathinfo($_FILES['upload_file']['name'], PATHINFO_EXTENSION));
if ($file_ext == 'wav' || $file_ext == 'mp3') {
if ($_POST['type'] == 'moh' && permission_exists('music_on_hold_add')) {
//remove the slashes
$slashes = array("/", "\\");
$_POST['upload_category_new'] = str_replace($slashes, "", $_POST['upload_category_new']);
$_FILES['upload_file']['name'] = str_replace($slashes, "", $_FILES['upload_file']['name']);
//replace any spaces in the file_name with dashes
$new_file_name = str_replace(' ', '-', $_FILES['upload_file']['name']);
//convert sampling rate from value passed by form
if ($file_ext == 'mp3') {
$sampling_rate_dirs = Array(8000, 16000, 32000, 48000);
}
else {
$sampling_rate_dirs[] = $_POST['upload_sampling_rate'] * 1000;
}
//if multi-tenant, modify directory paths
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/";
}
//create new category, if necessary
if ($_POST['upload_category'] == '_NEW_CAT_' && $_POST['upload_category_new'] != '') {
$new_category_name = str_replace(' ', '_', $_POST['upload_category_new']);
//process sampling rate(s)
foreach ($sampling_rate_dirs as $sampling_rate_dir) {
if (!is_dir($music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir)) {
@mkdir($music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir, 0777, true);
}
if (is_dir($music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir)) {
copy($_FILES['upload_file']['tmp_name'], $music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir."/".$new_file_name);
$target_dir = $music_on_hold_dir."/".$path_mod.$new_category_name."/".$sampling_rate_dir;
}
}
//delete temp file
@unlink($_FILES['upload_file']['tmp_name']);
}
//use existing category directory
else if ($_POST['upload_category'] != '' && $_POST['upload_category'] != '_NEW_CAT_') {
//process sampling rate(s)
foreach ($sampling_rate_dirs as $sampling_rate_dir) {
if (!is_dir($music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir)) {
@mkdir($music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir, 0777, true);
}
if (is_dir($music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir)) {
copy($_FILES['upload_file']['tmp_name'], $music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir."/".$new_file_name);
$target_dir = $music_on_hold_dir."/".$path_mod.$_POST['upload_category']."/".$sampling_rate_dir;
}
}
//delete temp file
@unlink($_FILES['upload_file']['tmp_name']);
}
//use default directory
else if ($_POST['upload_category'] == '') {
if (permission_exists('music_on_hold_default_add')) {
//process sampling rate(s)
foreach ($sampling_rate_dirs as $sampling_rate_dir) {
if (!is_dir($music_on_hold_dir."/".$sampling_rate_dir)) {
@mkdir($music_on_hold_dir."/".$sampling_rate_dir, 0777, true);
}
if (is_dir($music_on_hold_dir."/".$sampling_rate_dir)) {
copy($_FILES['upload_file']['tmp_name'], $music_on_hold_dir."/".$sampling_rate_dir."/".$new_file_name);
$target_dir = $music_on_hold_dir."/".$sampling_rate_dir;
}
}
//delete temp file
@unlink($_FILES['upload_file']['tmp_name']);
}
}
else {
//delete temp file and exit
@unlink($_FILES['upload_file']['tmp_name']);
exit();
}
//build and save the XML
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$moh = new switch_music_on_hold;
$moh->xml();
$moh->save();
//set an upload message
$save_msg = "Uploaded file to ".$target_dir."/".htmlentities($_FILES['upload_file']['name']);
}
}
$_SESSION['message'] = $text['message-upload_completed'];
header("Location: music_on_hold.php");
exit;
}
//define valid sampling rates
$sampling_rate_dirs = Array(8000, 16000, 32000, 48000);
//delete moh file
if ($_GET['act'] == "del" && permission_exists('music_on_hold_delete')) {
if ($_GET['type'] == 'moh') {
//remove the slashes
$slashes = array("/", "\\");
$_GET['category'] = str_replace($slashes, "", $_GET['category']);
$_GET['file_name'] = str_replace($slashes, "", $_GET['file_name']);
//set the variables
$sampling_rate_dir = $_GET['sampling_rate'];
$category_dir = $_GET['category'];
//default category
if ($category_dir == "") {
if (!permission_exists('music_on_hold_default_delete')) {
echo "access denied";
exit;
}
}
//other categories
if ($category_dir != "") {
$path_mod = $category_dir."/";
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/".$path_mod;
}
}
//remove the directory
unlink($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name']));
//build and save the XML
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
@ -165,86 +235,62 @@ if (is_uploaded_file($_FILES['upload_file']['tmp_name'])) {
$moh->xml();
$moh->save();
//set an upload message
$save_msg = "Uploaded file to ".$target_dir."/".htmlentities($_FILES['upload_file']['name']);
//redirect the browser
header("Location: music_on_hold.php");
exit;
}
}
}
if ($_GET['act'] == "del" && permission_exists('music_on_hold_delete')) {
if ($_GET['type'] == 'moh') {
//remove the slashes
$slashes = array("/", "\\");
$_GET['category'] = str_replace($slashes, "", $_GET['category']);
$_GET['file_name'] = str_replace($slashes, "", $_GET['file_name']);
//set the variables
$sampling_rate_dir = $_GET['sampling_rate'];
if ($_GET['type'] == 'cat') {
$category_dir = $_GET['category'];
//default category
if ($category_dir == "") {
if (!permission_exists('music_on_hold_default_delete')) {
echo "access denied";
exit;
}
if (strlen($category_dir) > 0) {
// adjus the path for multiple domains
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/";
}
// remove sampling rate directory (if any)
foreach ($sampling_rate_dirs as $sampling_rate_dir) {
rmdir($music_on_hold_dir."/".$path_mod.(base64_decode($category_dir))."/".$sampling_rate_dir);
}
// remove category directory
if (rmdir($music_on_hold_dir."/".$path_mod.(base64_decode($category_dir)))) {
sleep(5); // allow time for the OS to catch up (at least Windows, anyway)
}
}
//other categories
if ($category_dir != "") {
$path_mod = $category_dir."/";
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/".$path_mod;
}
}
//remove the directory
unlink($music_on_hold_dir."/".$path_mod.$sampling_rate_dir."/".base64_decode($_GET['file_name']));
//build and save the XML
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$moh = new switch_music_on_hold;
$moh->xml();
$moh->save();
//build and save the XML
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$moh = new switch_music_on_hold;
$moh->xml();
$moh->save();
//redirect the browser
header("Location: music_on_hold.php");
exit;
}
if ($_GET['type'] == 'cat') {
$category_dir = $_GET['category'];
if (strlen($category_dir) > 0) {
// adjus the path for multiple domains
if (count($_SESSION['domains']) > 1) {
$path_mod = $_SESSION["domain_name"]."/";
}
// remove sampling rate directories (if any)
foreach ($sampling_rate_dirs as $sampling_rate_dir) {
rmdir($music_on_hold_dir."/".$path_mod.(base64_decode($category_dir))."/".$sampling_rate_dir);
}
// remove category directory
if (rmdir($music_on_hold_dir."/".$path_mod.(base64_decode($category_dir)))) {
sleep(5); // allow time for the OS to catch up (at least Windows, anyway)
}
//redirect the browser
header("Location: music_on_hold.php");
exit;
}
//build and save the XML
require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$moh = new switch_music_on_hold;
$moh->xml();
$moh->save();
//redirect the browser
header("Location: music_on_hold.php");
exit;
}
}
//include the header
require_once "resources/header.php";
$document['title'] = $text['title-moh'];
//show the title and description
echo "<script language='JavaScript' type='text/javascript'>\n";
echo " function check_filetype(file_input) {\n";
echo " file_ext = file_input.value.substr((~-file_input.value.lastIndexOf('.') >>> 0) + 2);\n";
echo " if (file_ext != 'mp3' && file_ext != 'wav' && file_ext != '') {\n";
echo " display_message(\"".$text['message-unsupported_file_type']."\", 'negative', '2750');\n";
echo " }\n";
echo " else {\n";
echo " if (file_ext == 'mp3') {\n";
echo " document.getElementById('sampling_rate').style.display='none';\n";
echo " }\n";
echo " else {\n";
echo " document.getElementById('sampling_rate').style.display='';\n";
echo " }\n";
echo " }\n";
echo " }\n";
echo "</script>\n";
echo "<script language='JavaScript' type='text/javascript' src='".PROJECT_PATH."/resources/javascript/reset_file_input.js'></script>\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
@ -269,9 +315,11 @@ if ($_GET['act'] == "del" && permission_exists('music_on_hold_delete')) {
echo " <tr>\n";
echo " <td style='padding-right: 15px;' nowrap>\n";
echo " ".$text['label-file-path'];
echo " <input name='upload_file' type='file' class='formfld fileinput' style='width: 300px; margin-right: 3px;' id='upload_file'><input type='button' class='btn' value='".$text['button-clear']."' onclick=\"reset_file_input('upload_file');\">\n";
echo " <input name='upload_file' id='upload_file' type='file' class='formfld fileinput' style='width: 300px; margin-right: 3px;' onchange=\"check_filetype(this);\">";
echo "<input type='button' class='btn' value='".$text['button-clear']."' onclick=\"reset_file_input('upload_file'); document.getElementById('sampling_rate').style.display='inline';\">\n";
echo " </td>\n";
echo " <td style='padding-right: 15px;' nowrap>".$text['label-sampling']."";
echo " <td id='sampling_rate' style='padding-right: 15px;' nowrap>";
echo " ".$text['label-sampling'];
echo " <select id='upload_sampling_rate' name='upload_sampling_rate' class='formfld' style='width: auto;'>\n";
echo " <option value='8'>8 kHz</option>\n";
echo " <option value='16'>16 kHz</option>\n";