From eb67c3e9084bb93aa798cc6ca202e926406971a0 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 28 Jun 2016 02:32:22 -0600 Subject: [PATCH] Update music_on_hold.php Update music_on_hold.php so that it displays all streams from the database. --- app/music_on_hold/music_on_hold.php | 429 ++++++++++++++++++++-------- 1 file changed, 311 insertions(+), 118 deletions(-) diff --git a/app/music_on_hold/music_on_hold.php b/app/music_on_hold/music_on_hold.php index 806b8d4215..d9c0ed907c 100644 --- a/app/music_on_hold/music_on_hold.php +++ b/app/music_on_hold/music_on_hold.php @@ -24,25 +24,27 @@ Mark J Crane James Rose */ -ini_set('max_execution_time', 7200); -include "root.php"; -require_once "resources/require.php"; -require_once "resources/check_auth.php"; -if (permission_exists('music_on_hold_view') || permission_exists('music_on_hold_global_view')) { - //access granted -} -else { - echo "access denied"; - exit; -} +//includes + include "root.php"; + require_once "resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (permission_exists('music_on_hold_view') || permission_exists('music_on_hold_global_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } //add multi-lingual support $language = new text; $text = $language->get(); -//include paging - require_once "resources/paging.php"; +//increase the exucution time + ini_set('max_execution_time', 7200); //get moh records, build array $sql = "select * from v_music_on_hold "; @@ -296,6 +298,71 @@ else { exit; } +//get variables used to control the order + $order_by = check_str($_GET["order_by"]); + $order = check_str($_GET["order"]); + +//add the search term + $search = check_str($_GET["search"]); + if (strlen($search) > 0) { + $sql_search = "and ("; + $sql_search .= "music_on_hold_name like '%".$search."%'"; + $sql_search .= "or music_on_hold_path like '%".$search."%'"; + $sql_search .= "or music_on_hold_rate like '%".$search."%'"; + $sql_search .= "or music_on_hold_shuffle like '%".$search."%'"; + $sql_search .= "or music_on_hold_channels like '%".$search."%'"; + $sql_search .= "or music_on_hold_interval like '%".$search."%'"; + $sql_search .= "or music_on_hold_timer_name like '%".$search."%'"; + $sql_search .= "or music_on_hold_chime_list like '%".$search."%'"; + $sql_search .= "or music_on_hold_chime_freq like '%".$search."%'"; + $sql_search .= "or music_on_hold_chime_max like '%".$search."%'"; + $sql_search .= ")"; + } + +//additional includes + require_once "resources/paging.php"; + +//prepare to page the results + $sql = "select count(*) as num_rows from v_music_on_hold "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= $sql_search; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + $num_rows = $row['num_rows']; + } + else { + $num_rows = '0'; + } + } + +//prepare to page the results + $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + $param = ""; + $page = $_GET['page']; + if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $page; + +//get the list + $sql = "select * from v_music_on_hold "; + $sql .= "where ("; + $sql .= "domain_uuid = '$domain_uuid' "; + if (permission_exists('music_on_hold_global_view')) { + $sql .= "or domain_uuid is null "; + } + $sql .= ") "; + $sql .= $sql_search; + + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $sql .= "limit $rows_per_page offset $offset "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $streams = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement, $sql); //include the header require_once "resources/header.php"; @@ -347,7 +414,6 @@ else { echo $text['desc-moh']."\n"; echo "

\n"; - //show the upload form if (permission_exists('music_on_hold_add') || permission_exists('music_on_hold_global_add')) { echo "".$text['label-upload-moh']."\n"; @@ -453,126 +519,253 @@ else { $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; +/* + //output moh list + foreach ($mohs as $domain_uuid => &$moh) { -//output moh list - foreach ($mohs as $domain_uuid => &$moh) { + foreach ($moh as $moh_name => &$moh_rates) { - foreach ($moh as $moh_name => &$moh_rates) { - - $moh_name = str_replace('_', ' ', $moh_name); - if ($domain_uuid == '_global_') { - echo "".$moh_name."  - ".$text['label-global']."\n"; - } - else { - echo "".$moh_name."\n"; - } - echo "

\n"; - - echo "\n"; - - foreach ($moh_rates as $moh_rate => $moh_settings) { - $c = 0; - - //determine if rate was set to auto or not - $auto_rate = (substr_count($moh_settings['name'], '/') == 0) ? true : false; - - //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[$moh_settings['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 .= ""; + $moh_name = str_replace('_', ' ', $moh_name); + if ($domain_uuid == '_global_') { + echo "".$moh_name."  - ".$text['label-global']."\n"; } - } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " "; - unset($moh_icons, $icons); + else { + echo "".$moh_name."\n"; + } + echo "

\n"; - //show moh files - if (isset($moh_settings['path'])) { - $moh_path = $moh_settings['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; + 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 ( ($domain_uuid == '_global_' && permission_exists('music_on_hold_global_edit')) || ($domain_uuid != '_global_' && permission_exists('music_on_hold_edit')) ) { - echo "".$v_link_label_edit.""; - } - 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"; + + foreach ($moh_rates as $moh_rate => $moh_settings) { + $c = 0; + + //determine if rate was set to auto or not + $auto_rate = (substr_count($moh_settings['name'], '/') == 0) ? true : false; + + //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; + 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"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " "; + unset($moh_icons, $icons); + + //show moh files + if (isset($moh_settings['path'])) { + $moh_path = $moh_settings['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; + } + $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 "
".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++; } - 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 ( ($domain_uuid == '_global_' && permission_exists('music_on_hold_global_edit')) || ($domain_uuid != '_global_' && permission_exists('music_on_hold_edit')) ) { + echo "".$v_link_label_edit.""; } + 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 "
".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.""; + } + echo "
\n"; + echo "
\n"; + } - echo "
\n"; + } + echo "

\n"; +*/ + //echo "\n"; + + if (is_array($streams)) { + foreach($streams as $row) { + echo "".$row['music_on_hold_name']."\n"; + if ($row['domain_uuid'] == null) { + echo "  - ".$text['label-global']."\n"; } - echo "
\n"; - echo "
\n"; + //start the table + echo "\n"; + //determine if rate was set to auto or not + $auto_rate = (substr_count($moh_settings['name'], '/') == 0) ? true : false; - } + //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 .= ""; + } + } + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " "; + unset($moh_icons, $icons); - } - echo "

\n"; + 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); + + 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 " \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.""; + } + echo "

\n"; + + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + 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 "

"; //include the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?>