From 2e21be8cd4160b6ff156f47be38e83c79bfb4c4f Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 16 Dec 2019 12:00:33 -0700 Subject: [PATCH] MOH: List view updates. --- app/music_on_hold/app_languages.php | 38 +- app/music_on_hold/music_on_hold.php | 439 ++++++++---------- .../classes/switch_music_on_hold.php | 166 ++++++- resources/classes/button.php | 2 +- 4 files changed, 385 insertions(+), 260 deletions(-) diff --git a/app/music_on_hold/app_languages.php b/app/music_on_hold/app_languages.php index d7f305537a..ee941e34e8 100644 --- a/app/music_on_hold/app_languages.php +++ b/app/music_on_hold/app_languages.php @@ -781,25 +781,25 @@ $text['header-music_on_hold_settings']['ru-ru'] = "Музыка на удерж $text['header-music_on_hold_settings']['sv-se'] = "Väntmusik inställningar"; $text['header-music_on_hold_settings']['uk-ua'] = "Музика на утриманні настройки"; -$text['desc-music_on_hold']['en-us'] = "Music on hold can be in WAV or MP3 format. To play an MP3 file you must have mod_shout enabled on the 'Modules' tab. You can adjust the volume of the MP3 audio from the 'Settings' tab. For best performance upload 16 bit, 8/16/32/48 kHz mono WAV files."; -$text['desc-music_on_hold']['ar-eg'] = ""; -$text['desc-music_on_hold']['de-at'] = "Haltemusik können Dateien im WAV oder MP3 Format sein. Um MP3 Dateien abzuspielen zu können, muss mod_shout installiert und aktiviert sein. Sie können die Lautstärke der MP3 Dateien in den Einstellungen verändern. Für beste Funktionalität laden Sie 16bit, 8/16/32/48 kHz mono WAV Dateien hoch."; //copied from de-de -$text['desc-music_on_hold']['de-ch'] = "Haltemusik können Dateien im WAV oder MP3 Format sein. Um MP3 Dateien abzuspielen zu können, muss mod_shout installiert und aktiviert sein. Sie können die Lautstärke der MP3 Dateien in den Einstellungen verändern. Für beste Funktionalität laden Sie 16bit, 8/16/32/48 kHz mono WAV Dateien hoch."; //copied from de-de -$text['desc-music_on_hold']['de-de'] = "Haltemusik können Dateien im WAV oder MP3 Format sein. Um MP3 Dateien abzuspielen zu können, muss mod_shout installiert und aktiviert sein. Sie können die Lautstärke der MP3 Dateien in den Einstellungen verändern. Für beste Funktionalität laden Sie 16bit, 8/16/32/48 kHz mono WAV Dateien hoch."; -$text['desc-music_on_hold']['es-cl'] = "La música en espera puede estar en formato WAV o MP3. Para reproducir un archivo en frmato MP3 debe tener activado el módulo mod_shout. Puede ajustar el volumen del MP3 desde la pestaña 'Configuraciones'. Para el mejor rendimiento se recomienda utilizar archivos en formato WAV 16 bit, 8/16/32/48 kHz mono."; -$text['desc-music_on_hold']['es-mx'] = "La música en espera puede estar en formato WAV o MP3. Para reproducir un archivo en frmato MP3 debe tener activado el módulo mod_shout. Puede ajustar el volumen del MP3 desde la pestaña 'Configuraciones'. Para el mejor rendimiento se recomienda utilizar archivos en formato WAV 16 bit, 8/16/32/48 kHz mono."; //copied from es-cl -$text['desc-music_on_hold']['fr-ca'] = "La Musique d'attente peut être en WAV ou en MP3. Pour le MP3, mod_shout doit être activé dans la section modules. Le volume peut être réglé dans la partie configuration. Pour de meilleures performances, utiliser des fichiers WAV 16 bit, 8/16/32/48 kHz mono."; //copied from fr-fr -$text['desc-music_on_hold']['fr-fr'] = "La Musique d'attente peut être en WAV ou en MP3. Pour le MP3, mod_shout doit être activé dans la section modules. Le volume peut être réglé dans la partie configuration. Pour de meilleures performances, utiliser des fichiers WAV 16 bit, 8/16/32/48 kHz mono."; -$text['desc-music_on_hold']['he-il'] = ""; -$text['desc-music_on_hold']['it-it'] = "La musica di attesa può essere in formato WAV o MP3. Per suonare i file MP3 è necessario avere mod_shout abilitato nella sezione 'Moduli'. Si può regolare il volume dei file MP3 dalla sezione Parametri. Per una migliore qualità caricare file 16 bit, 8/16/32/48 kHz mono WAV files."; -$text['desc-music_on_hold']['nl-nl'] = "Wachtmuziek mag in WAV of MP3 formaat zijn. Om een MP3 bestand te spelen moet mod_shout aan staan bij de Modulen tab. Het volume van de MP3 audio kan op de instellingen tab ingevoerd worden. Voor de beste prestaties gebruik 16 bit, 8/16/32/48 kHz mono WAV files."; -$text['desc-music_on_hold']['pl-pl'] = "Muzyka na czekanie może być w formacie wav lub mp3. Aby odtwarzać mp3 konieczne jest zainstalowanie modułu mod_shout (można to zrobić w zakładce Moduły). Można także zmienić głośność formatu mp3 w zakładce Ustawienia. W celu osiągniecia najlepszej jakości prześlij pliki w formacie wav o następującej specyfikacji: 16 bit, 8/16/32/48 kHz mono."; -$text['desc-music_on_hold']['pt-br'] = "Música em espera pode ser com base em arquivos com o formato WAV ou MP3. Para ouvir um ficheiro MP3 deverá ter o mod_shout activado na tab 'Módulos'. Pode ajustar o volume do áudio MP3 a partir da tab 'Definições'. Para um melhor desempenho carregue ficheiros WAV de 16 bit, 8/16/32/48 kHz mono."; -$text['desc-music_on_hold']['pt-pt'] = "Música em espera pode ser com base em ficheiros com o formato WAV ou MP3. Para ouvir um ficheiro MP3 deverá ter o mod_shout activado na tab 'Módulos'. Pode ajustar o volume do áudio MP3 a partir da tab 'Definições'. Para um melhor desempenho carregue ficheiros WAV de 16 bit, 8/16/32/48 kHz mono."; -$text['desc-music_on_hold']['ro-ro'] = ""; -$text['desc-music_on_hold']['ru-ru'] = "Музыка на удержании может быть в формате WAV или MP3. Чтобы воспроизвести файл MP3, на вкладке «Модули» необходимо включить mod_shout. Вы можете отрегулировать громкость звука MP3 на вкладке «Настройки». Для лучшей производительности загружайте 16-битные, 8/16/32/48 кГц моно файлы WAV."; -$text['desc-music_on_hold']['sv-se'] = "Väntmusik kan vara i formaten WAV eller MP3. För att spela upp en MP3 fil så måste 'mod_shout' vara aktiverat i 'moduler' fliken. Du kan justera volymen på MP3 filerna genom inställnings fliken. För bästa prestanda, ladda upp 16 bit, 8/16/32/48 kHz mono WAV filer."; -$text['desc-music_on_hold']['uk-ua'] = "Музика на утриманні може бути в WAV або MP3 формат. Для відтворення файлів MP3 ви повинні включити mod_shout на вкладці 'модулі'. Ви можете налаштувати гучність MP3-аудіо на вкладці «Налаштування». Для кращої продуктивності завантаження 16 біт, моно 8/16/32/48 кГц WAV файлів."; +$text['title_description-music_on_hold']['en-us'] = "Music on hold can be in WAV or MP3 format. To play an MP3 file you must have mod_shout enabled on the 'Modules' tab. You can adjust the volume of the MP3 audio from the 'Settings' tab. For best performance upload 16 bit, 8/16/32/48 kHz mono WAV files."; +$text['title_description-music_on_hold']['ar-eg'] = ""; +$text['title_description-music_on_hold']['de-at'] = "Haltemusik können Dateien im WAV oder MP3 Format sein. Um MP3 Dateien abzuspielen zu können, muss mod_shout installiert und aktiviert sein. Sie können die Lautstärke der MP3 Dateien in den Einstellungen verändern. Für beste Funktionalität laden Sie 16bit, 8/16/32/48 kHz mono WAV Dateien hoch."; //copied from de-de +$text['title_description-music_on_hold']['de-ch'] = "Haltemusik können Dateien im WAV oder MP3 Format sein. Um MP3 Dateien abzuspielen zu können, muss mod_shout installiert und aktiviert sein. Sie können die Lautstärke der MP3 Dateien in den Einstellungen verändern. Für beste Funktionalität laden Sie 16bit, 8/16/32/48 kHz mono WAV Dateien hoch."; //copied from de-de +$text['title_description-music_on_hold']['de-de'] = "Haltemusik können Dateien im WAV oder MP3 Format sein. Um MP3 Dateien abzuspielen zu können, muss mod_shout installiert und aktiviert sein. Sie können die Lautstärke der MP3 Dateien in den Einstellungen verändern. Für beste Funktionalität laden Sie 16bit, 8/16/32/48 kHz mono WAV Dateien hoch."; +$text['title_description-music_on_hold']['es-cl'] = "La música en espera puede estar en formato WAV o MP3. Para reproducir un archivo en frmato MP3 debe tener activado el módulo mod_shout. Puede ajustar el volumen del MP3 desde la pestaña 'Configuraciones'. Para el mejor rendimiento se recomienda utilizar archivos en formato WAV 16 bit, 8/16/32/48 kHz mono."; +$text['title_description-music_on_hold']['es-mx'] = "La música en espera puede estar en formato WAV o MP3. Para reproducir un archivo en frmato MP3 debe tener activado el módulo mod_shout. Puede ajustar el volumen del MP3 desde la pestaña 'Configuraciones'. Para el mejor rendimiento se recomienda utilizar archivos en formato WAV 16 bit, 8/16/32/48 kHz mono."; //copied from es-cl +$text['title_description-music_on_hold']['fr-ca'] = "La Musique d'attente peut être en WAV ou en MP3. Pour le MP3, mod_shout doit être activé dans la section modules. Le volume peut être réglé dans la partie configuration. Pour de meilleures performances, utiliser des fichiers WAV 16 bit, 8/16/32/48 kHz mono."; //copied from fr-fr +$text['title_description-music_on_hold']['fr-fr'] = "La Musique d'attente peut être en WAV ou en MP3. Pour le MP3, mod_shout doit être activé dans la section modules. Le volume peut être réglé dans la partie configuration. Pour de meilleures performances, utiliser des fichiers WAV 16 bit, 8/16/32/48 kHz mono."; +$text['title_description-music_on_hold']['he-il'] = ""; +$text['title_description-music_on_hold']['it-it'] = "La musica di attesa può essere in formato WAV o MP3. Per suonare i file MP3 è necessario avere mod_shout abilitato nella sezione 'Moduli'. Si può regolare il volume dei file MP3 dalla sezione Parametri. Per una migliore qualità caricare file 16 bit, 8/16/32/48 kHz mono WAV files."; +$text['title_description-music_on_hold']['nl-nl'] = "Wachtmuziek mag in WAV of MP3 formaat zijn. Om een MP3 bestand te spelen moet mod_shout aan staan bij de Modulen tab. Het volume van de MP3 audio kan op de instellingen tab ingevoerd worden. Voor de beste prestaties gebruik 16 bit, 8/16/32/48 kHz mono WAV files."; +$text['title_description-music_on_hold']['pl-pl'] = "Muzyka na czekanie może być w formacie wav lub mp3. Aby odtwarzać mp3 konieczne jest zainstalowanie modułu mod_shout (można to zrobić w zakładce Moduły). Można także zmienić głośność formatu mp3 w zakładce Ustawienia. W celu osiągniecia najlepszej jakości prześlij pliki w formacie wav o następującej specyfikacji: 16 bit, 8/16/32/48 kHz mono."; +$text['title_description-music_on_hold']['pt-br'] = "Música em espera pode ser com base em arquivos com o formato WAV ou MP3. Para ouvir um ficheiro MP3 deverá ter o mod_shout activado na tab 'Módulos'. Pode ajustar o volume do áudio MP3 a partir da tab 'Definições'. Para um melhor desempenho carregue ficheiros WAV de 16 bit, 8/16/32/48 kHz mono."; +$text['title_description-music_on_hold']['pt-pt'] = "Música em espera pode ser com base em ficheiros com o formato WAV ou MP3. Para ouvir um ficheiro MP3 deverá ter o mod_shout activado na tab 'Módulos'. Pode ajustar o volume do áudio MP3 a partir da tab 'Definições'. Para um melhor desempenho carregue ficheiros WAV de 16 bit, 8/16/32/48 kHz mono."; +$text['title_description-music_on_hold']['ro-ro'] = ""; +$text['title_description-music_on_hold']['ru-ru'] = "Музыка на удержании может быть в формате WAV или MP3. Чтобы воспроизвести файл MP3, на вкладке «Модули» необходимо включить mod_shout. Вы можете отрегулировать громкость звука MP3 на вкладке «Настройки». Для лучшей производительности загружайте 16-битные, 8/16/32/48 кГц моно файлы WAV."; +$text['title_description-music_on_hold']['sv-se'] = "Väntmusik kan vara i formaten WAV eller MP3. För att spela upp en MP3 fil så måste 'mod_shout' vara aktiverat i 'moduler' fliken. Du kan justera volymen på MP3 filerna genom inställnings fliken. För bästa prestanda, ladda upp 16 bit, 8/16/32/48 kHz mono WAV filer."; +$text['title_description-music_on_hold']['uk-ua'] = "Музика на утриманні може бути в WAV або MP3 формат. Для відтворення файлів MP3 ви повинні включити mod_shout на вкладці 'модулі'. Ви можете налаштувати гучність MP3-аудіо на вкладці «Налаштування». Для кращої продуктивності завантаження 16 біт, моно 8/16/32/48 кГц WAV файлів."; $text['button-upload']['en-us'] = "Upload"; $text['button-upload']['ar-eg'] = ""; diff --git a/app/music_on_hold/music_on_hold.php b/app/music_on_hold/music_on_hold.php index 8efdcbba9f..64c5da6638 100644 --- a/app/music_on_hold/music_on_hold.php +++ b/app/music_on_hold/music_on_hold.php @@ -28,9 +28,9 @@ //includes include "root.php"; require_once "resources/require.php"; + require_once "resources/check_auth.php"; //check permissions - require_once "resources/check_auth.php"; if (permission_exists('music_on_hold_view')) { //access granted } @@ -56,6 +56,27 @@ $database = new database; $streams = $database->select($sql, $parameters, 'all'); +//get the http post data + if (is_array($_POST['moh']) || is_array($_POST['moh_files'])) { + $action = $_POST['action']; + $moh = $_POST['moh']; + } + +//process the http post data by action + if ($action != '' && is_array($moh) && @sizeof($moh) != 0) { + switch ($action) { + case 'delete': + if (permission_exists('music_on_hold_delete')) { + $obj = new switch_music_on_hold; + $obj->delete($moh); + } + break; + } + + header('Location: music_on_hold.php'); + exit; + } + //download music on hold file if ($_GET['action'] == "download" && is_uuid($_GET['id']) @@ -88,7 +109,6 @@ $stream_full_path = path_join($stream_path, $stream_file); //download the file - session_cache_limiter('public'); if (file_exists($stream_full_path)) { $fd = fopen($stream_full_path, "rb"); if ($_GET['t'] == "bin") { @@ -121,6 +141,14 @@ && is_array($streams) && @sizeof($streams) != 0) { + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: music_on_hold.php'); + exit; + } + //determine name if ($_POST['name_new'] != '') { //set the action @@ -192,14 +220,13 @@ } //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 $stream_new_name = true; foreach ($streams as $row) { $alternate_path = str_replace('$${sounds_dir}', $_SESSION['switch']['sounds']['dir'], $row['music_on_hold_path']); - if ($stream_path == $row['music_on_hold_path'] - || $stream_path == $alternate_path) { + if ($stream_path == $row['music_on_hold_path'] || $stream_path == $alternate_path) { $stream_new_name = false; break; } @@ -260,6 +287,7 @@ exit; } +/* //delete the music on hold file if ($_GET['action'] == "delete" && is_uuid($_GET['id']) @@ -314,165 +342,128 @@ header("Location: music_on_hold.php"); exit; } +*/ + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); //include the header - require_once "resources/header.php"; $document['title'] = $text['title-music_on_hold']; + require_once "resources/header.php"; +//script echo "\n"; - echo "\n"; + echo ""; - echo "".$text['label-music_on_hold'].""; - echo "

\n"; - echo $text['desc-music_on_hold']."\n"; - echo "

\n"; - -//show the upload form +//show the content + echo "
\n"; + echo "
".$text['title-music_on_hold']."
\n"; + echo "
\n"; if (permission_exists('music_on_hold_add')) { - echo "".$text['label-upload-music_on_hold']."\n"; - echo "

\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); });"]); + echo "
\n"; + echo ""; } + if (permission_exists('music_on_hold_delete') && $streams) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + echo "
\n"; + echo "
\n"; + echo "
\n"; -//set the row styles - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; + echo $text['title_description-music_on_hold']."\n"; + echo "

\n"; -//set the variable with an empty string - $previous_name = ''; + echo "
\n"; + echo "\n"; //show the array of data if (is_array($streams) && @sizeof($streams) != 0) { - - //start the table - echo "\n"; + $previous_name = ''; //loop through the array foreach ($streams as $row) { @@ -481,25 +472,13 @@ $music_on_hold_name = $row['music_on_hold_name']; $music_on_hold_rate = $row['music_on_hold_rate']; - $stream_rate = $row['music_on_hold_rate']; - - //add vertical space - echo "\n"; - - //add the name + //add the name (category) if ($previous_name != $music_on_hold_name) { - echo "\n"; - echo "\n"; - echo " \n"; - echo "\n"; + echo "".escape($music_on_hold_name)."".(!is_uuid($row['domain_uuid']) ? '   ('.$text['label-global'].')' : null)."
\n"; } //determine if rate was set to auto or not - $auto_rate = (strlen($music_on_hold_rate) == 0) ? true : false; + $auto_rate = strlen($music_on_hold_rate) == 0 ? true : false; //determine icons to show $stream_icons = array(); @@ -527,112 +506,100 @@ } if (is_array($stream_icons) && sizeof($stream_icons) > 0) { foreach ($stream_icons as $stream_icon) { - $icons .= ""; + $icons .= ""; } } //set the rate label - if ($auto_rate) { - $stream_details = $text['option-default'].' '.$icons; + $stream_rate = $auto_rate ? $text['option-default'] : ($music_on_hold_rate/1000).' kHz'; + if (permission_exists('music_on_hold_edit')) { + $stream_details = "".$stream_rate.' '.$icons; } else { - $stream_details = ($music_on_hold_rate/1000).' kHz / '.$icons; + $stream_details = $stream_rate.' '.$icons; } - //show the table header - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$stream_details."".$text['label-tools']."".$text['label-file-size']."".$text['label-uploaded'].""; - if (permission_exists('music_on_hold_edit')) { - echo "$v_link_label_edit"; + //get the music on hold path and files + $stream_path = str_replace("\$\${sounds_dir}",$_SESSION['switch']['sounds']['dir'], $row['music_on_hold_path']); + if (file_exists($stream_path)) { + $stream_files = array_merge(glob($stream_path.'/*.wav'), glob($stream_path.'/*.mp3'), glob($stream_path.'/*.ogg')); } + + //start the table + echo "\n"; + echo " \n"; if (permission_exists('music_on_hold_delete')) { - echo "$v_link_label_delete"; + echo " \n"; } - echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; +// if (permission_exists('music_on_hold_delete')) { +// echo "$v_link_label_delete"; +// } echo " "; unset($stream_icons, $icons); - //add the uuid of to the link - if (permission_exists('music_on_hold_edit')) { - $tr_link = "href='music_on_hold_edit.php?id=".escape($row['music_on_hold_uuid'])."'"; - } - - //get the music on hold path - $stream_path = $row['music_on_hold_path']; - $stream_path = str_replace("\$\${sounds_dir}",$_SESSION['switch']['sounds']['dir'], $stream_path); - - //show the files - if (file_exists($stream_path)) { - $stream_files = array_merge(glob($stream_path.'/*.wav'), glob($stream_path.'/*.mp3'), glob($stream_path.'/*.ogg')); - if (is_array($stream_files) && @sizeof($stream_files) != 0) { - foreach ($stream_files as $stream_file_path) { - $stream_file = pathinfo($stream_file_path, PATHINFO_BASENAME); - $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_ext = pathinfo($stream_file, PATHINFO_EXTENSION); - switch ($stream_file_ext) { - case "wav" : $stream_file_type = "audio/wav"; break; - case "mp3" : $stream_file_type = "audio/mpeg"; break; - case "ogg" : $stream_file_type = "audio/ogg"; break; - } - $row_uuid = uuid(); - echo "\n"; - $tr_link = "href=\"javascript:recording_play('".$row_uuid."');\""; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - $c = ($c) ? 0 : 1; + //list the stream files + if (is_array($stream_files) && @sizeof($stream_files) != 0) { + $x = 0; + foreach ($stream_files as $stream_file_path) { + $row_uuid = uuid(); + $stream_file = pathinfo($stream_file_path, PATHINFO_BASENAME); + $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_ext = pathinfo($stream_file, PATHINFO_EXTENSION); + switch ($stream_file_ext) { + case "wav" : $stream_file_type = "audio/wav"; break; + case "mp3" : $stream_file_type = "audio/mpeg"; break; + case "ogg" : $stream_file_type = "audio/ogg"; break; } + //playback progress bar + echo "\n"; + echo "\n"; // dummy row to maintain alternating background color + $list_row_link = "javascript:recording_play('".$row_uuid."');"; + echo "\n"; + if (permission_exists('music_on_hold_delete')) { + echo " \n"; + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; +// if ( (!is_uuid($domain_uuid) && permission_exists('music_on_hold_domain')) || (is_uuid($domain_uuid) && permission_exists('music_on_hold_delete')) ) { +// echo "".$v_link_label_delete.""; +// } + echo "\n"; + $x++; } } + echo "
\n"; + echo " \n"; + echo " ".$stream_details."".$text['label-tools']."".$text['label-file-size']."".$text['label-uploaded']."
".escape($stream_file)."".escape($stream_file_size)."".escape($stream_file_date)."\n"; - echo "".$v_link_label_download.""; - if ( (!is_uuid($domain_uuid) && permission_exists('music_on_hold_domain')) || (is_uuid($domain_uuid) && permission_exists('music_on_hold_delete')) ) { - echo "".$v_link_label_delete.""; - } - echo "
\n"; + echo " \n"; + echo " \n"; + echo " ".escape($stream_file)."".escape($stream_file_size)."".escape($stream_file_date)."
\n"; + echo "
\n"; + //set the previous music_on_hold_name $previous_name = $music_on_hold_name; - //toggle the light highlighting - $c = ($c) ? 0 : 1; } unset($streams, $row); - //end the table - echo "
\n"; - } - echo "\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - echo "  "; - echo "
\n"; - echo "\n"; - echo "\n"; - echo ""; - echo "

"; + echo "\n"; + echo "
\n"; //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/music_on_hold/resources/classes/switch_music_on_hold.php b/app/music_on_hold/resources/classes/switch_music_on_hold.php index a8a212df9b..2c6e59a262 100644 --- a/app/music_on_hold/resources/classes/switch_music_on_hold.php +++ b/app/music_on_hold/resources/classes/switch_music_on_hold.php @@ -28,15 +28,39 @@ include "root.php"; //define the switch_music_on_hold class +if (!class_exists('switch_music_on_hold')) { class switch_music_on_hold { - public $domain_uuid; + /** + * declare private variables + */ private $xml; + private $app_name; + private $app_uuid; + private $permission_prefix; + private $list_page; + private $table; + private $uuid_prefix; + /** + * called when the object is created + */ public function __construct() { - $this->domain_uuid = $_SESSION['domain_uuid']; + + //assign private variables + $this->app_name = 'music_on_hold'; + $this->app_uuid = '1dafe0f8-c08a-289b-0312-15baf4f20f81'; + $this->permission_prefix = 'music_on_hold_'; + $this->list_page = 'music_on_hold.php'; + $this->table = 'music_on_hold'; + $this->uuid_prefix = 'music_on_hold_'; + } + /** + * called when there are no references to a particular object + * unset the variables used in the class + */ public function __destruct() { foreach ($this as $key => $value) { unset($this->$key); @@ -214,7 +238,141 @@ include "root.php"; $this->reload(); } - } + /** + * delete records/files + */ + public function delete($records) { + if (permission_exists($this->permission_prefix.'delete')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->list_page); + exit; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + + //filter checked records + foreach ($records as $music_on_hold_uuid => $record) { + if (is_uuid($music_on_hold_uuid)) { + if ($record['checked'] == 'true') { + foreach ($record as $key => $array) { + if (is_numeric($key) && is_array($array) && @sizeof($array) != 0) { + $moh[$music_on_hold_uuid][] = $array['file_name']; + } + } + $moh[$music_on_hold_uuid]['delete'] = true; + continue; + } + foreach ($record as $key => $array) { + if (is_numeric($key) && is_array($array) && @sizeof($array) != 0 && $array['checked'] == 'true') { + $moh[$music_on_hold_uuid][] = $array['file_name']; + } + } + } + } + unset($array); +// view_array($moh); + + //loop checked records + $files_deleted = 0; + if (is_array($moh) && @sizeof($moh) != 0) { + + //get music on hold details + $sql = "select * from v_music_on_hold "; + $sql .= "where (domain_uuid = :domain_uuid ".(!permission_exists('music_on_hold_domain') ?: "or domain_uuid is null ").") "; + $sql .= "and music_on_hold_uuid in ('".implode("','", array_keys($moh))."') "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $streams[$row['music_on_hold_uuid']] = $row; + } + } + unset($sql, $parameters, $rows, $row); + + //delete files, folders, build delete array + $x = 0; + foreach ($moh as $music_on_hold_uuid => $row) { + + //prepare path + $stream_path = $streams[$music_on_hold_uuid]['music_on_hold_path']; + $stream_path = str_replace('$${sounds_dir}', $_SESSION['switch']['sounds']['dir'], $stream_path); + + //delete checked files + foreach ($row as $key => $stream_file) { + if (is_numeric($key)) { + $stream_file_path = str_replace('../', '', path_join($stream_path, $stream_file)); + if (@unlink($stream_file_path)) { + $files_deleted++; + } + } + } + + //delete name rate + if ($row['delete']) { + + //build delete array + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $music_on_hold_uuid; + if (!permission_exists('music_on_hold_domain')) { + $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid']; + } + $x++; + + //delete rate folder + @rmdir($stream_path); + + //delete name (category) folder, if empty + $name_path = dirname($stream_path); + if (@sizeof(scandir($name_path)) == 2) { //empty (only /.. and /. remaining) + @rmdir($name_path); + } + } + + } + + } + + //delete the moh records + if (is_array($array) && @sizeof($array) != 0) { + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //set flag + $moh_deleted = true; + + } + unset($records, $moh); + + //post delete + if ($moh_deleted || $files_deleted) { + //reload moh + $this->reload(); + + //set message + message::add($text['message-delete']); + } + + } + + } + } //method + + } //class +} //build and save the XML //require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; @@ -222,4 +380,4 @@ include "root.php"; //$moh->xml(); //$moh->save(); -?> +?> \ No newline at end of file diff --git a/resources/classes/button.php b/resources/classes/button.php index 728b78b176..f1e401a25a 100644 --- a/resources/classes/button.php +++ b/resources/classes/button.php @@ -59,7 +59,7 @@ if (!class_exists('button')) { !$array['label'] )) { $icon_class = is_array($array['icon']) ? $array['icon']['text'] : 'fas fa-'.$array['icon']; - $button .= ""; + $button .= ""; } //label if ($array['label'] && (