From 0a20ef955fa67577c55dd33e6248733d9effbfcb Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Wed, 29 Jun 2016 21:42:12 -0600 Subject: [PATCH] Update music_on_hold.php Music on hold - combine the same name with multiple rates under the heading. Improve indentation and comments. --- app/music_on_hold/music_on_hold.php | 239 ++++++++++++++++------------ 1 file changed, 133 insertions(+), 106 deletions(-) diff --git a/app/music_on_hold/music_on_hold.php b/app/music_on_hold/music_on_hold.php index 9a8159b322..e48745d1e2 100644 --- a/app/music_on_hold/music_on_hold.php +++ b/app/music_on_hold/music_on_hold.php @@ -538,125 +538,152 @@ $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; +//set the variable with an empty string + $previous_name = ''; + +//show the array of data if (is_array($streams)) { - foreach($streams as $row) { - $music_on_hold_name = $row['music_on_hold_name']; - $name_array = explode("/", $music_on_hold_name); - if (count($name_array) == 2) { $music_on_hold_name = $name_array[0]; } - if (count($name_array) == 3) { $music_on_hold_name = $name_array[1]; } - echo "".$music_on_hold_name."\n"; - if ($row['domain_uuid'] == null) { - echo "  - ".$text['label-global']."\n"; - } - $moh_scope = $row['domain_uuid']; - if (!$moh_scope) $moh_scope = '_global_'; - $tmp = explode('/', $row['music_on_hold_name']); - $moh_name_only = $tmp[0]; - $moh_rate = $row['music_on_hold_rate']; + //start the table + echo "\n"; - $moh_settings = $mohs[$moh_scope][$moh_name_only][$moh_rate]; + //loop through the array + foreach($streams as $row) { - //start the table - echo "
\n"; + //set the variables and work with them + $music_on_hold_name = $row['music_on_hold_name']; + //$name_array = explode("/", $music_on_hold_name); + //if (count($name_array) == 2) { $music_on_hold_name = $name_array[0]; } + //if (count($name_array) == 3) { $music_on_hold_name = $name_array[1]; } + //echo "".$music_on_hold_name."\n"; - //determine if rate was set to auto or not - $auto_rate = (substr_count($moh_settings['name'], '/') == 0) ? true : false; + $moh_scope = $row['domain_uuid']; + if (!$moh_scope) $moh_scope = '_global_'; + $tmp = explode('/', $row['music_on_hold_name']); + $moh_name_only = $tmp[0]; + $moh_rate = $row['music_on_hold_rate']; + $moh_settings = $mohs[$moh_scope][$moh_name_only][$moh_rate]; - //determine icons to show - $moh_icons = array(); - $i = 0; - if (permission_exists('music_on_hold_path')) { - $moh_icons[$i]['glyphicon'] = 'glyphicon-folder-open'; - $moh_icons[$i]['title'] = $moh_paths[$row['music_on_hold_uuid']]; - $i++; - } - if ($moh_settings['shuffle'] == 'true') { - $moh_icons[$i]['glyphicon'] = 'glyphicon-random'; - $moh_icons[$i]['title'] = $text['label-shuffle']; - $i++; - } - if ($moh_settings['chime_list'] != '') { - $moh_icons[$i]['glyphicon'] = 'glyphicon-bell'; - $moh_icons[$i]['title'] = $text['label-chime_list'].': '.$moh_settings['chime_list']; - $i++; - } - if ($moh_settings['channels'] == '2') { - $moh_icons[$i]['glyphicon'] = 'glyphicon-headphones'; - $moh_icons[$i]['title'] = $text['label-stereo']; - $moh_icons[$i]['margin'] = 6; - $i++; - } - if (is_array($moh_icons) && sizeof($moh_icons) > 0) { - foreach ($moh_icons as $moh_icon) { - $icons .= ""; + //add a vertical space + echo "\n"; + + //add the name + if ($previous_name != $music_on_hold_name) { + echo "\n"; + echo " \n"; + echo "\n"; } - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " "; - unset($moh_icons, $icons); - if (permission_exists('music_on_hold_edit')) { - $tr_link = "href='music_on_hold_edit.php?id=".$row['music_on_hold_uuid']."'"; - } + //determine if rate was set to auto or not + $auto_rate = (substr_count($moh_settings['name'], '/') == 0) ? true : false; - //get the music on hold path - $moh_path = $row['music_on_hold_path']; - $moh_path = str_replace("\$\${sounds_dir}",$_SESSION['switch']['sounds']['dir'], $moh_path); - - if (file_exists($moh_path)) { - $moh_files = array_merge(glob($moh_path.'/*.wav'), glob($moh_path.'/*.mp3'), glob($moh_path.'/*.ogg')); - foreach ($moh_files as $moh_file_path) { - $moh_file = strtolower(pathinfo($moh_file_path, PATHINFO_BASENAME)); - $moh_file_size = byte_convert(filesize($moh_file_path)); - $moh_file_date = date("M d, Y H:i:s", filemtime($moh_file_path)); - $moh_file_ext = pathinfo($moh_file, PATHINFO_EXTENSION); - switch ($moh_file_ext) { - case "wav" : $moh_file_type = "audio/wav"; break; - case "mp3" : $moh_file_type = "audio/mpeg"; break; - case "ogg" : $moh_file_type = "audio/ogg"; break; + //determine icons to show + $moh_icons = array(); + $i = 0; + if (permission_exists('music_on_hold_path')) { + $moh_icons[$i]['glyphicon'] = 'glyphicon-folder-open'; + $moh_icons[$i]['title'] = $moh_paths[$row['music_on_hold_uuid']]; + $i++; } - $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; - } - } - echo "\n"; - echo "
".(($auto_rate) ? ($moh_rate/1000).' kHz / '.$text['option-default'] : ($moh_rate/1000)." kHz").$icons."".$text['label-tools']."".$text['label-file-size']."".$text['label-uploaded'].""; - if (permission_exists('music_on_hold_edit')) { - echo "$v_link_label_edit"; - } - if (permission_exists('music_on_hold_delete')) { - echo "$v_link_label_delete"; - } - echo "
".str_replace('_', '_​', $moh_file)."".$moh_file_size."".$moh_file_date."\n"; - echo "".$v_link_label_download.""; - if ( ($domain_uuid == '_global_' && permission_exists('music_on_hold_global_delete')) || ($domain_uuid != '_global_' && permission_exists('music_on_hold_delete')) ) { - echo "".$v_link_label_delete.""; + if ($moh_settings['shuffle'] == 'true') { + $moh_icons[$i]['glyphicon'] = 'glyphicon-random'; + $moh_icons[$i]['title'] = $text['label-shuffle']; + $i++; + } + if ($moh_settings['chime_list'] != '') { + $moh_icons[$i]['glyphicon'] = 'glyphicon-bell'; + $moh_icons[$i]['title'] = $text['label-chime_list'].': '.$moh_settings['chime_list']; + $i++; + } + if ($moh_settings['channels'] == '2') { + $moh_icons[$i]['glyphicon'] = 'glyphicon-headphones'; + $moh_icons[$i]['title'] = $text['label-stereo']; + $moh_icons[$i]['margin'] = 6; + $i++; + } + if (is_array($moh_icons) && sizeof($moh_icons) > 0) { + foreach ($moh_icons as $moh_icon) { + $icons .= ""; + } } - echo "

\n"; + //show the table header + echo " \n"; + echo " ".(($auto_rate) ? ($moh_rate/1000).' kHz / '.$text['option-default'] : ($moh_rate/1000)." kHz").$icons."\n"; + echo " ".$text['label-tools']."\n"; + echo " ".$text['label-file-size']."\n"; + echo " ".$text['label-uploaded']."\n"; + echo " "; + if (permission_exists('music_on_hold_edit')) { + echo "$v_link_label_edit"; + } + if (permission_exists('music_on_hold_delete')) { + echo "$v_link_label_delete"; + } + echo "\n"; + echo " "; + unset($moh_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=".$row['music_on_hold_uuid']."'"; + } + + //get the music on hold path + $moh_path = $row['music_on_hold_path']; + $moh_path = str_replace("\$\${sounds_dir}",$_SESSION['switch']['sounds']['dir'], $moh_path); + + //show the files + if (file_exists($moh_path)) { + $moh_files = array_merge(glob($moh_path.'/*.wav'), glob($moh_path.'/*.mp3'), glob($moh_path.'/*.ogg')); + foreach ($moh_files as $moh_file_path) { + $moh_file = strtolower(pathinfo($moh_file_path, PATHINFO_BASENAME)); + $moh_file_size = byte_convert(filesize($moh_file_path)); + $moh_file_date = date("M d, Y H:i:s", filemtime($moh_file_path)); + $moh_file_ext = pathinfo($moh_file, PATHINFO_EXTENSION); + switch ($moh_file_ext) { + case "wav" : $moh_file_type = "audio/wav"; break; + case "mp3" : $moh_file_type = "audio/mpeg"; break; + case "ogg" : $moh_file_type = "audio/ogg"; break; + } + $row_uuid = uuid(); + echo "\n"; + $tr_link = "href=\"javascript:recording_play('".$row_uuid."');\""; + echo "\n"; + echo " ".str_replace('_', '_​', $moh_file)."\n"; + echo " "; + echo ""; + echo "".$v_link_label_play.""; + echo "".$v_link_label_stop.""; + echo " \n"; + echo " ".$moh_file_size."\n"; + echo " ".$moh_file_date."\n"; + echo " \n"; + echo "".$v_link_label_download.""; + if ( ($domain_uuid == '_global_' && permission_exists('music_on_hold_global_delete')) || ($domain_uuid != '_global_' && permission_exists('music_on_hold_delete')) ) { + echo "".$v_link_label_delete.""; + } + echo " \n"; + echo "\n"; + $c = ($c) ? 0 : 1; + } + } + + //set the previous music_on_hold_name + $previous_name = $music_on_hold_name; + + //toggle the light highlighting + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + + //end the table + echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $result, $row_count); } //end if results echo "\n";