Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane James Rose */ include "root.php"; require_once "includes/require.php"; require_once "includes/checkauth.php"; if (permission_exists('music_on_hold_view') || permission_exists('music_on_hold_default_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } require_once "includes/paging.php"; $sampling_rate_dirs = Array(8000, 16000, 32000, 48000); $music_on_hold_dir = $_SESSION['switch']['sounds']['dir'].'/music'; ini_set(max_execution_time,7200); $order_by = $_GET["order_by"]; $order = $_GET["order"]; if ($_GET['a'] == "download") { $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"); header('Content-Disposition: attachment; file_name="'.base64_decode($_GET['file_name']).'"'); } 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("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 (($_POST['submit'] == "Upload") && 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')) { // 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; } } } else { 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']); } } } if ($_GET['act'] == "del" && permission_exists('music_on_hold_delete')) { if ($_GET['type'] == 'moh') { //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"; $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) } } //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 "includes/header.php"; //show the title and description echo "\n"; echo ""; echo "
\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "

\n"; echo " ".$text['label-moh']."

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

\n"; echo "
\n"; echo "\n"; echo "

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

\n"; echo "
\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-file-path']."
\n"; echo " \n"; echo "
".$text['label-sampling']."
\n"; echo " \n"; echo "
".$text['label-category']."
\n"; echo " \n"; echo " "; echo "
 
\n"; echo " "; echo "
 
\n"; echo " \n"; echo "
\n"; echo "
\n"; echo "

\n"; } //set the row styles $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; //show the default category if (permission_exists('music_on_hold_default_view')) { echo "".$text['label-default']."\n"; if (count($_SESSION['domains']) > 1) { echo "  - ".$text['message-available-to-all']."\n"; } echo "

\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " "; foreach ($sampling_rate_dirs as $sampling_rate_dir) { if ($handle = opendir($music_on_hold_dir."/".$sampling_rate_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && is_file($music_on_hold_dir."/".$sampling_rate_dir."/".$file)) { $file_size = filesize($music_on_hold_dir."/".$sampling_rate_dir."/".$file); $file_size = byte_convert($file_size); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; $c = ($c==0) ? 1 : 0; } } closedir($handle); } } echo "
".$text['label-download']."".$text['label-play']."".$text['label-uploaded']."".$text['label-file-size']."".$text['label-sampling']."
".$file."\n"; echo " \n"; $tmp_file_array = explode("\.",$file); echo " ".$tmp_file_array[0]; echo " "; echo " ".date ("F d Y H:i:s", filemtime($music_on_hold_dir."/".$sampling_rate_dir."/".$file))."".$file_size."".($sampling_rate_dir / 1000)." kHz\n"; if (permission_exists('music_on_hold_default_delete')) { echo " $v_link_label_delete\n"; } echo "
\n"; } if ($v_path_show) { echo "
".$text['label-location'].": ".$music_on_hold_dir."
\n"; } echo "

\n"; //show additional categories foreach ($category_dirs as $category_number => $category_dir) { $c = 0; echo "".(str_replace('_', ' ', $category_dir))."\n"; echo "

\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " "; $moh_found = false; foreach ($sampling_rate_dirs as $sampling_rate_dir) { if ($handle = opendir($music_on_hold_category_parent_dir."/".$category_dir."/".$sampling_rate_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && is_file($music_on_hold_category_parent_dir."/".$category_dir."/".$sampling_rate_dir."/".$file)) { $file_size = filesize($music_on_hold_category_parent_dir."/".$category_dir."/".$sampling_rate_dir."/".$file); $file_size = byte_convert($file_size); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; $c = ($c==0) ? 1 : 0; $moh_found = true; } } closedir($handle); } } if (!$moh_found) { echo "\n"; echo " \n"; echo "\n"; } echo "
".$text['label-download']."".$text['label-play']."".$text['label-uploaded']."".$text['label-file-size']."".$text['label-sampling']."
".$file."\n"; echo " \n"; $tmp_file_array = explode("\.",$file); echo " ".$tmp_file_array[0]; echo " "; echo " ".date ("F d Y H:i:s", filemtime($music_on_hold_category_parent_dir."/".$category_dir."/".$sampling_rate_dir."/".$file))."".$file_size."".($sampling_rate_dir / 1000)." kHz\n"; if (permission_exists('music_on_hold_delete')) { echo " $v_link_label_delete\n"; } echo "
\n"; echo " ".$text['message-nofiles'].""; echo " \n"; echo "
\n"; if ($v_path_show) { echo "
Location: ".$music_on_hold_category_parent_dir."/".$category_dir."
\n"; } echo "

\n"; } //include the footer require_once "includes/footer.php"; ?>