Music on Hold: Database class integration.

This commit is contained in:
Nate 2019-08-09 11:42:43 -06:00
parent 3699f09771
commit a59d0db433
4 changed files with 279 additions and 322 deletions

View File

@ -24,102 +24,96 @@
Mark J Crane <markjcrane@fusionpbx.com>
*/
if ($domains_processed == 1) {
if ($domains_processed == 1) {
//set the directory
if (is_array($_SESSION["switch"]["conf"])) {
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/local_stream.conf";
}
//rename the file
if (is_array($_SESSION["switch"]["conf"])) {
if (file_exists($xml_dir.'/local_stream.conf.xml')) {
rename($xml_dir.'/local_stream.conf', $xml_dir.'/'.$xml_file);
}
if (file_exists($xml_dir.'/local_stream.conf.xml.noload')) {
rename($xml_dir.'/local_stream.conf', $xml_dir.'/'.$xml_file);
}
}
//add the music_on_hold list to the database
if (is_array($_SESSION["switch"]["conf"])) {
$sql = "select count(music_on_hold_uuid) from v_music_on_hold; ";
$database = new database;
$num_rows = $database->select($sql, null, 'column');
unset($sql);
if ($num_rows == 0) {
//set the alternate directory
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/local_stream.conf';
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt);
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//process the array
foreach ($conf_array['directory'] as $row) {
//get the data from the array
$stream_name = $row['@attributes']['name'];
$stream_path = $row['@attributes']['path'];
foreach ($row['param'] as $p) {
$name = $p['@attributes']['name'];
$name = str_replace("-", "_", $name);
$$name = $p['@attributes']['value'];
$attributes[] = $name;
}
//strip the domain name and rate from the name
$array = explode('/', $stream_name);
if (count($array) == 3) { $stream_name = $array[1]; }
if (count($array) == 2) { $stream_name = $array[0]; }
//insert the data into the database
$music_on_hold_uuid = uuid();
$array['music_on_hold'][0]['music_on_hold_uuid'] = $music_on_hold_uuid;
$array['music_on_hold'][0]['music_on_hold_name'] = $stream_name;
$array['music_on_hold'][0]['music_on_hold_rate'] = isset($rate) ? $rate : null;
$array['music_on_hold'][0]['music_on_hold_shuffle'] = isset($shuffle) ? $shuffle : null;
$array['music_on_hold'][0]['music_on_hold_timer_name'] = isset($timer_name) ? $timer_name : null;
$array['music_on_hold'][0]['music_on_hold_chime_list'] = isset($chime_list) ? $chime_list : null;
$array['music_on_hold'][0]['music_on_hold_chime_freq'] = isset($chime_freq) ? $chime_freq : null;
$array['music_on_hold'][0]['music_on_hold_chime_max'] = isset($chime_max) ? $chime_max : null;
$array['music_on_hold'][0]['music_on_hold_path'] = $stream_path;
$p = new permissions;
$p->add('music_on_hold_add', 'temp');
$database = new database;
$database->app_name = 'app_name';
$database->app_uuid = 'app_uuid';
$database->save($array);
unset($array);
$p->add('music_on_hold_delete', 'temp');
//unset the attribute variables
foreach ($attributes as $value) {
unset($$value);
}
}
//set the directory
if (is_array($_SESSION["switch"]["conf"])) {
$xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs';
$xml_file = $xml_dir."/local_stream.conf";
}
//rename the file
if (is_array($_SESSION["switch"]["conf"])) {
if (file_exists($xml_dir.'/local_stream.conf.xml')) {
rename($xml_dir.'/local_stream.conf', $xml_dir.'/'.$xml_file);
}
if (file_exists($xml_dir.'/local_stream.conf.xml.noload')) {
rename($xml_dir.'/local_stream.conf', $xml_dir.'/'.$xml_file);
}
}
//add the music_on_hold list to the database
if (is_array($_SESSION["switch"]["conf"])) {
$sql = "select count(music_on_hold_uuid) as num_rows from v_music_on_hold; ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
//set the alternate directory
$xml_file_alt = $_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH.'/resources/templates/conf/autoload_configs/local_stream.conf';
//load the xml and save it into an array
if (file_exists($xml_file)) {
$xml_string = file_get_contents($xml_file);
}
elseif (file_exists($xml_file_alt)) {
$xml_string = file_get_contents($xml_file_alt);
}
$xml_object = simplexml_load_string($xml_string);
$json = json_encode($xml_object);
$conf_array = json_decode($json, true);
//process the array
foreach ($conf_array['directory'] as $row) {
//get the data from the array
$stream_name = $row['@attributes']['name'];
$stream_path = $row['@attributes']['path'];
foreach ($row['param'] as $p) {
$name = $p['@attributes']['name'];
$name = str_replace("-", "_", $name);
$$name = $p['@attributes']['value'];
$attributes[] = $name;
}
//strip the domain name and rate from the name
$array = explode('/', $stream_name);
if (count($array) == 3) { $stream_name = $array[1]; }
if (count($array) == 2) { $stream_name = $array[0]; }
//insert the data into the database
$music_on_hold_uuid = uuid();
$sql = "insert into v_music_on_hold ";
$sql .= "(";
$sql .= "music_on_hold_uuid, ";
$sql .= "music_on_hold_name, ";
if (isset($rate)) $sql .= "music_on_hold_rate, ";
if (isset($shuffle)) $sql .= "music_on_hold_shuffle, ";
if (isset($timer_name)) $sql .= "music_on_hold_timer_name, ";
if (isset($chime_list)) $sql .= "music_on_hold_chime_list, ";
if (isset($chime_freq)) $sql .= "music_on_hold_chime_freq, ";
if (isset($chime_max)) $sql .= "music_on_hold_chime_max, ";
$sql .= "music_on_hold_path ";
$sql .= ") ";
$sql .= "values ";
$sql .= "( ";
$sql .= "'".$music_on_hold_uuid."', ";
$sql .= "'".check_str($stream_name)."', ";
if (isset($rate)) $sql .= "'".check_str($rate)."', ";
if (isset($shuffle)) $sql .= "'".check_str($shuffle)."', ";
if (isset($timer_name)) $sql .= "'".check_str($timer_name)."', ";
if (isset($chime_list)) $sql .= "'".check_str($chime_list)."', ";
if (isset($chime_max)) $sql .= "'".check_str($chime_max)."', ";
$sql .= "'".check_str($stream_path)."' ";
$sql .= ");";
//echo $sql."\n";
$db->exec(check_sql($sql));
unset($sql);
//unset the attribute variables
foreach ($attributes as $value) {
unset($$value);
}
}
} //if num_rows
} //if prep_statement
} //if is_array
}
}
}
?>

View File

@ -49,18 +49,23 @@
//get the music_on_hold array
$sql = "select * from v_music_on_hold ";
$sql .= "where ( ";
$sql .= "domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "domain_uuid = :domain_uuid ";
if (permission_exists('music_on_hold_domain')) {
$sql .= "or domain_uuid is null ";
}
$sql .= ") ";
$sql .= "order by domain_uuid desc, music_on_hold_name asc, music_on_hold_rate asc";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$streams = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$streams = $database->select($sql, $parameters, 'all');
//download music on hold file
if ($_GET['action'] == "download") {
if (
$_GET['action'] == "download"
&& is_uuid($_GET['id'])
&& is_array($streams)
&& @sizeof($streams) != 0
) {
//get the uuid
$stream_uuid = $_GET['id'];
@ -75,7 +80,6 @@
}
//replace the sounds_dir variable in the path
// str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
$stream_path = str_replace('$${sounds_dir}', $_SESSION['switch']['sounds']['dir'], $stream_path);
//get the file
@ -110,7 +114,13 @@
}
//upload music on hold file
if ($_POST['action'] == 'upload' && is_array($_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) {
if (
$_POST['action'] == 'upload'
&& is_array($_FILES)
&& is_uploaded_file($_FILES['file']['tmp_name'])
&& is_array($streams)
&& @sizeof($streams) != 0
) {
//determine name
if ($_POST['name_new'] != '') {
@ -119,7 +129,7 @@
//get the stream_name
$stream_name = $_POST['name_new'];
//get the rate
if (is_numeric($_POST['rate'])) { $stream_rate = $_POST['rate']; } else { $stream_rate = ''; }
$stream_rate = is_numeric($_POST['rate']) ? $_POST['rate'] : '';
}
else {
//get the stream uuid
@ -199,50 +209,32 @@
//set the variables
$stream_path = str_replace('$${sounds_dir}', $_SESSION['switch']['sounds']['dir'], $stream_path);
//begin query
//execute query
if ($stream_new_name) {
$stream_uuid = uuid();
$sql = "insert into v_music_on_hold ";
$sql .= "( ";
$sql .= "music_on_hold_uuid, ";
$sql .= "domain_uuid, ";
$sql .= "music_on_hold_name, ";
$sql .= "music_on_hold_path, ";
$sql .= "music_on_hold_rate, ";
$sql .= "music_on_hold_shuffle, ";
$sql .= "music_on_hold_channels, ";
$sql .= "music_on_hold_interval, ";
$sql .= "music_on_hold_timer_name, ";
$sql .= "music_on_hold_chime_list, ";
$sql .= "music_on_hold_chime_freq, ";
$sql .= "music_on_hold_chime_max ";
$sql .= ") ";
$sql .= "values ( ";
$sql .= "'".$stream_uuid."',";
$sql .= "'".$domain_uuid."', ";
$sql .= "'".check_str($stream_name)."', ";
$sql .= "'".check_str($stream_path)."', ";
if (strlen($stream_rate) == 0) {
$sql .= "null, ";
}
else {
$sql .= "'".$stream_rate."', ";
}
$sql .= "'false', ";
$sql .= "1, ";
$sql .= "20, ";
$sql .= "'soft', ";
$sql .= "null, ";
$sql .= "null, ";
$sql .= "null ";
$sql .= ") ";
unset($music_on_hold_name, $music_on_hold_path);
}
$array['music_on_hold'][0]['music_on_hold_uuid'] = $stream_uuid;
$array['music_on_hold'][0]['domain_uuid'] = $domain_uuid;
$array['music_on_hold'][0]['music_on_hold_name'] = $stream_name;
$array['music_on_hold'][0]['music_on_hold_path'] = $stream_path;
$array['music_on_hold'][0]['music_on_hold_rate'] = strlen($stream_rate) != 0 ? $stream_rate : null;
$array['music_on_hold'][0]['music_on_hold_shuffle'] = 'false';
$array['music_on_hold'][0]['music_on_hold_channels'] = 1;
$array['music_on_hold'][0]['music_on_hold_interval'] = 20;
$array['music_on_hold'][0]['music_on_hold_timer_name'] = 'soft';
$array['music_on_hold'][0]['music_on_hold_chime_list'] = null;
$array['music_on_hold'][0]['music_on_hold_chime_freq'] = null;
$array['music_on_hold'][0]['music_on_hold_chime_max'] = null;
//execute query
if (!$stream_path_found) {
$db->exec(check_sql($sql));
unset($sql);
$p = new permissions;
$p->add('music_on_hold_add', 'temp');
$database = new database;
$database->app_name = 'music_on_hold';
$database->app_uuid = '1dafe0f8-c08a-289b-0312-15baf4f20f81';
$database->save($array);
unset($array);
$p->delete('music_on_hold_add', 'temp');
}
}
@ -270,11 +262,16 @@
}
//delete the music on hold file
if ($_GET['action'] == "delete") {
if (
$_GET['action'] == "delete"
&& is_uuid($_GET['id'])
&& is_array($streams)
&& @sizeof($streams) != 0
) {
//get submitted values
$stream_uuid = check_str($_GET['id']);
$stream_file = check_str(base64_decode($_GET['file']));
$stream_uuid = $_GET['id'];
$stream_file = base64_decode($_GET['file']);
//get the record
foreach($streams as $row) {
@ -301,14 +298,13 @@
array_map('unlink', glob(path_join($stream_path, '*.mp3')));
array_map('unlink', glob(path_join($stream_path, '*.ogg')));
}
//reload moh
$music = new switch_music_on_hold;
$music->reload();
//set message
message::add($text['message-delete']);
}
//require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
$music = new switch_music_on_hold;
$music->reload();
//redirect
header("Location: music_on_hold.php");
exit;
@ -468,13 +464,13 @@
$previous_name = '';
//show the array of data
if (is_array($streams)) {
if (is_array($streams) && @sizeof($streams) != 0) {
//start the table
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0' style='margin-bottom: 3px;'>\n";
//loop through the array
foreach($streams as $row) {
foreach ($streams as $row) {
//set the variables
$music_on_hold_name = $row['music_on_hold_name'];
@ -567,36 +563,38 @@
//show the files
if (file_exists($stream_path)) {
$stream_files = array_merge(glob($stream_path.'/*.wav'), glob($stream_path.'/*.mp3'), glob($stream_path.'/*.ogg'));
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;
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 "<tr id='recording_progress_bar_".$row_uuid."' style='display: none;'><td colspan='4' class='".$row_style[$c]." playback_progress_bar_background' style='padding: 0; border: none;'><span class='playback_progress_bar' id='recording_progress_".$row_uuid."'></span></td></tr>\n";
$tr_link = "href=\"javascript:recording_play('".$row_uuid."');\"";
echo "<tr ".$tr_link.">\n";
echo " <td class='".$row_style[$c]."'>".escape($stream_file)."</td>\n";
echo " <td valign='top' class='".$row_style[$c]." row_style_slim tr_link_void'>";
echo "<audio id='recording_audio_".$row_uuid."' style='display: none;' preload='none' ontimeupdate=\"update_progress('".$row_uuid."')\" onended=\"recording_reset('".$row_uuid."');\" src='?action=download&id=".escape($row['music_on_hold_uuid'])."&file=".base64_encode($stream_file)."' type='".escape($stream_file_type)."'></audio>";
echo "<span id='recording_button_".$row_uuid."' onclick=\"recording_play('".$row_uuid."')\" title='".$text['label-play']." / ".$text['label-pause']."'>".$v_link_label_play."</span>";
echo "<span onclick=\"recording_stop('".$row_uuid."')\" title='".$text['label-stop']."'>".$v_link_label_stop."</span>";
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: right; white-space: nowrap;'>".escape($stream_file_size)."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: right; white-space: nowrap;'>".escape($stream_file_date)."</td>\n";
echo " <td valign='top' class='".((!permission_exists('music_on_hold_domain')) ? 'list_control_icon' : 'list_control_icons')."'>\n";
echo "<a href='?action=download&id=".escape($row['music_on_hold_uuid'])."&file=".base64_encode($stream_file)."' title='".$text['label-download']."'>".$v_link_label_download."</a>";
if ( (!is_uuid($domain_uuid) && permission_exists('music_on_hold_domain')) || (is_uuid($domain_uuid) && permission_exists('music_on_hold_delete')) ) {
echo "<a href='?action=delete&id=".escape($row['music_on_hold_uuid'])."&file=".base64_encode($stream_file)."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>";
}
echo " </td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
$row_uuid = uuid();
echo "<tr id='recording_progress_bar_".$row_uuid."' style='display: none;'><td colspan='4' class='".$row_style[$c]." playback_progress_bar_background' style='padding: 0; border: none;'><span class='playback_progress_bar' id='recording_progress_".$row_uuid."'></span></td></tr>\n";
$tr_link = "href=\"javascript:recording_play('".$row_uuid."');\"";
echo "<tr ".$tr_link.">\n";
echo " <td class='".$row_style[$c]."'>".escape($stream_file)."</td>\n";
echo " <td valign='top' class='".$row_style[$c]." row_style_slim tr_link_void'>";
echo "<audio id='recording_audio_".$row_uuid."' style='display: none;' preload='none' ontimeupdate=\"update_progress('".$row_uuid."')\" onended=\"recording_reset('".$row_uuid."');\" src='?action=download&id=".escape($row['music_on_hold_uuid'])."&file=".base64_encode($stream_file)."' type='".escape($stream_file_type)."'></audio>";
echo "<span id='recording_button_".$row_uuid."' onclick=\"recording_play('".$row_uuid."')\" title='".$text['label-play']." / ".$text['label-pause']."'>".$v_link_label_play."</span>";
echo "<span onclick=\"recording_stop('".$row_uuid."')\" title='".$text['label-stop']."'>".$v_link_label_stop."</span>";
echo " </td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: right; white-space: nowrap;'>".escape($stream_file_size)."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style='text-align: right;'>".escape($stream_file_date)."</td>\n";
echo " <td valign='top' class='".((!permission_exists('music_on_hold_domain')) ? 'list_control_icon' : 'list_control_icons')."'>\n";
echo "<a href='?action=download&id=".escape($row['music_on_hold_uuid'])."&file=".base64_encode($stream_file)."' title='".$text['label-download']."'>".$v_link_label_download."</a>";
if ( ($domain_uuid == '' && permission_exists('music_on_hold_domain')) || ($domain_uuid != '' && permission_exists('music_on_hold_delete')) ) {
echo "<a href='?action=delete&id=".escape($row['music_on_hold_uuid'])."&file=".base64_encode($stream_file)."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>";
}
echo " </td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
}
@ -604,14 +602,14 @@
$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);
$c = ($c) ? 0 : 1;
}
unset($streams, $row);
//end the table
echo "</table>\n";
} //end if results
}
echo "<tr>\n";
echo "<td colspan='11' align='left'>\n";

View File

@ -43,29 +43,34 @@
$text = $language->get();
//get the id
if (count($_GET) > 0) {
$id = check_str($_GET["id"]);
}
$music_on_hold_uuid = $_GET["id"];
//delete the data
if (strlen($id) > 0) {
$sql = "delete from v_music_on_hold ";
$sql .= "where music_on_hold_uuid = '$id' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
unset($sql);
}
//clear the cache
$cache = new cache;
$cache->delete("configuration:local_stream.conf");
if (is_uuid($music_on_hold_uuid)) {
//reload mod local stream
$music = new switch_music_on_hold;
$music->reload();
//delete the data
$array['music_on_hold'][0]['music_on_hold_uuid'] = $music_on_hold_uuid;
$database = new database;
$database->app_name = 'music_on_hold';
$database->app_uuid = '1dafe0f8-c08a-289b-0312-15baf4f20f81';
$database->delete($array);
unset($array);
//clear the cache
$cache = new cache;
$cache->delete("configuration:local_stream.conf");
//reload mod local stream
$music = new switch_music_on_hold;
$music->reload();
//set messsage
message::add($text['message-delete']);
}
//redirect the user
message::add($text['message-delete']);
header('Location: music_on_hold.php');
exit;
?>

View File

@ -43,9 +43,9 @@
$text = $language->get();
//action add or update
if (isset($_REQUEST["id"])) {
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$music_on_hold_uuid = check_str($_REQUEST["id"]);
$music_on_hold_uuid = $_REQUEST["id"];
}
else {
$action = "add";
@ -54,18 +54,18 @@
//get http post variables and set them to php variables
if (count($_POST) > 0) {
if (permission_exists('music_on_hold_domain')) {
$domain_uuid = check_str($_POST["domain_uuid"]);
$domain_uuid = $_POST["domain_uuid"];
}
$music_on_hold_name = check_str($_POST["music_on_hold_name"]);
$music_on_hold_path = check_str($_POST["music_on_hold_path"]);
$music_on_hold_rate = check_str($_POST["music_on_hold_rate"]);
$music_on_hold_shuffle = check_str($_POST["music_on_hold_shuffle"]);
$music_on_hold_channels = check_str($_POST["music_on_hold_channels"]);
$music_on_hold_interval = check_str($_POST["music_on_hold_interval"]);
$music_on_hold_timer_name = check_str($_POST["music_on_hold_timer_name"]);
$music_on_hold_chime_list = check_str($_POST["music_on_hold_chime_list"]);
$music_on_hold_chime_freq = check_str($_POST["music_on_hold_chime_freq"]);
$music_on_hold_chime_max = check_str($_POST["music_on_hold_chime_max"]);
$music_on_hold_name = $_POST["music_on_hold_name"];
$music_on_hold_path = $_POST["music_on_hold_path"];
$music_on_hold_rate = $_POST["music_on_hold_rate"];
$music_on_hold_shuffle = $_POST["music_on_hold_shuffle"];
$music_on_hold_channels = $_POST["music_on_hold_channels"];
$music_on_hold_interval = $_POST["music_on_hold_interval"];
$music_on_hold_timer_name = $_POST["music_on_hold_timer_name"];
$music_on_hold_chime_list = $_POST["music_on_hold_chime_list"];
$music_on_hold_chime_freq = $_POST["music_on_hold_chime_freq"];
$music_on_hold_chime_max = $_POST["music_on_hold_chime_max"];
}
//add or update the data
@ -73,7 +73,7 @@
//get the uuid
if ($action == "update") {
$music_on_hold_uuid = check_str($_POST["music_on_hold_uuid"]);
$music_on_hold_uuid = $_POST["music_on_hold_uuid"];
}
//check for all required data
@ -104,91 +104,46 @@
//add or update the database
if ($_POST["persistformvar"] != "true") {
if ($action == "add" && permission_exists('music_on_hold_add')) {
//insert the new music on hold
$sql = "insert into v_music_on_hold ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "music_on_hold_uuid, ";
$sql .= "music_on_hold_name, ";
$sql .= "music_on_hold_path, ";
$sql .= "music_on_hold_rate, ";
$sql .= "music_on_hold_shuffle, ";
$sql .= "music_on_hold_channels, ";
$sql .= "music_on_hold_interval, ";
$sql .= "music_on_hold_timer_name, ";
$sql .= "music_on_hold_chime_list, ";
$sql .= "music_on_hold_chime_freq, ";
$sql .= "music_on_hold_chime_max ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
if (permission_exists('music_on_hold_domain')) {
if (strlen($domain_uuid) == null) {
$sql .= "null, ";
}
else {
$sql .= "'".$domain_uuid."', ";
}
}
else {
$sql .= "'".$_SESSION['domain_uuid']."', ";
}
$sql .= "'".uuid()."', ";
$sql .= "'$music_on_hold_name', ";
$sql .= "'$music_on_hold_path', ";
if (strlen($music_on_hold_rate) == 0) { $sql .= "null, "; } else { $sql .= "'$music_on_hold_rate', "; }
$sql .= "'$music_on_hold_shuffle', ";
if (strlen($music_on_hold_channels) == 0) { $sql .= "null, "; } else { $sql .= "'$music_on_hold_channels', "; }
if (strlen($music_on_hold_interval) == 0) { $sql .= "null, "; } else { $sql .= "'$music_on_hold_interval', "; }
$sql .= "'$music_on_hold_timer_name', ";
$sql .= "'$music_on_hold_chime_list', ";
if (strlen($music_on_hold_chime_freq) == 0) { $sql .= "null, "; } else { $sql .= "'$music_on_hold_chime_freq', "; }
if (strlen($music_on_hold_chime_max) == 0) { $sql .= "null "; } else { $sql .= "'$music_on_hold_chime_max' "; }
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
//clear the cache
$cache = new cache;
$cache->delete("configuration:local_stream.conf");
//reload mod local stream
$music = new switch_music_on_hold;
$music->reload();
//set the message and redirect the user
//begin insert array
$array['music_on_hold'][0]['music_on_hold_uuid'] = uuid();
//set message
message::add($text['message-add']);
header("Location: music_on_hold.php");
return;
} //if ($action == "add")
}
if ($action == "update" && permission_exists('music_on_hold_edit')) {
//update the stream settings
$sql = "update v_music_on_hold set ";
//begin update array
$array['music_on_hold'][0]['music_on_hold_uuid'] = $music_on_hold_uuid;
//set message
message::add($text['message-update']);
}
if (is_array($array) && @sizeof($array) != 0) {
//add common array elements
if (permission_exists('music_on_hold_domain')) {
if (strlen($domain_uuid) == null) {
$sql .= "domain_uuid = null, ";
}
else {
$sql .= "domain_uuid = '$domain_uuid', ";
}
$array['music_on_hold'][0]['domain_uuid'] = is_uuid($domain_uuid) ? $domain_uuid : null;
}
else {
$sql .= "domain_uuid = '".$_SESSION['domain_uuid']."', ";
$array['music_on_hold'][0]['domain_uuid'] = $_SESSION['domain_uuid'];
}
$sql .= "music_on_hold_name = '$music_on_hold_name', ";
$sql .= "music_on_hold_path = '$music_on_hold_path', ";
if (strlen($music_on_hold_rate) == 0) { $sql .= "music_on_hold_rate = null, "; } else { $sql .= "music_on_hold_rate = '$music_on_hold_rate', "; }
$sql .= "music_on_hold_shuffle = '$music_on_hold_shuffle', ";
if (strlen($music_on_hold_channels) == 0) { $sql .= "music_on_hold_channels = null, "; } else { $sql .= "music_on_hold_channels = '$music_on_hold_channels', "; }
if (strlen($music_on_hold_interval) == 0) { $sql .= "music_on_hold_interval = null, "; } else { $sql .= "music_on_hold_interval = '$music_on_hold_interval', "; }
$sql .= "music_on_hold_timer_name = '$music_on_hold_timer_name', ";
$sql .= "music_on_hold_chime_list = '$music_on_hold_chime_list', ";
if (strlen($music_on_hold_chime_freq) == 0) { $sql .= "music_on_hold_chime_freq = null, "; } else { $sql .= "music_on_hold_chime_freq = '$music_on_hold_chime_freq', "; }
if (strlen($music_on_hold_chime_max) == 0) { $sql .= "music_on_hold_chime_max = null "; } else { $sql .= "music_on_hold_chime_max = '$music_on_hold_chime_max' "; }
$sql .= "where music_on_hold_uuid = '$music_on_hold_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
$array['music_on_hold'][0]['music_on_hold_name'] = $music_on_hold_name;
$array['music_on_hold'][0]['music_on_hold_path'] = $music_on_hold_path;
$array['music_on_hold'][0]['music_on_hold_rate'] = strlen($music_on_hold_rate) != 0 ? $music_on_hold_rate : null;
$array['music_on_hold'][0]['music_on_hold_shuffle'] = $music_on_hold_shuffle;
$array['music_on_hold'][0]['music_on_hold_channels'] = strlen($music_on_hold_channels) != 0 ? $music_on_hold_channels : null;
$array['music_on_hold'][0]['music_on_hold_interval'] = strlen($music_on_hold_interval) != 0 ? $music_on_hold_interval : null;
$array['music_on_hold'][0]['music_on_hold_timer_name'] = $music_on_hold_timer_name;
$array['music_on_hold'][0]['music_on_hold_chime_list'] = $music_on_hold_chime_list;
$array['music_on_hold'][0]['music_on_hold_chime_freq'] = strlen($music_on_hold_chime_freq) != 0 ? $music_on_hold_chime_freq : null;
$array['music_on_hold'][0]['music_on_hold_chime_max'] = strlen($music_on_hold_chime_max) != 0 ? $music_on_hold_chime_max : null;
//execute
$database = new database;
$database->app_name = 'music_on_hold';
$database->app_uuid = '1dafe0f8-c08a-289b-0312-15baf4f20f81';
$database->save($array);
unset($array);
//clear the cache
$cache = new cache;
@ -198,27 +153,29 @@
$music = new switch_music_on_hold;
$music->reload();
//set the message and redirect the user
message::add($text['message-update']);
//redirect the user
header("Location: music_on_hold.php");
return;
} //if ($action == "update")
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
exit;
}
}
}
//pre-populate the form
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
$music_on_hold_uuid = check_str($_GET["id"]);
if (count($_GET) > 0 && is_uuid($_GET["id"]) && $_POST["persistformvar"] != "true") {
$music_on_hold_uuid = $_GET["id"];
$sql = "select * from v_music_on_hold ";
$sql .= "where ( ";
$sql .= " domain_uuid = '$domain_uuid' ";
$sql .= " domain_uuid = :domain_uuid ";
$sql .= " or domain_uuid is null ";
$sql .= ") ";
$sql .= "and music_on_hold_uuid = '$music_on_hold_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$sql .= "and music_on_hold_uuid = :music_on_hold_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['music_on_hold_uuid'] = $music_on_hold_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$domain_uuid = $row["domain_uuid"];
$music_on_hold_name = $row["music_on_hold_name"];
$music_on_hold_path = $row["music_on_hold_path"];
@ -231,7 +188,7 @@
$music_on_hold_chime_freq = $row["music_on_hold_chime_freq"];
$music_on_hold_chime_max = $row["music_on_hold_chime_max"];
}
unset ($prep_statement);
unset($sql, $parameters, $row);
}
//show the header
@ -392,11 +349,11 @@
*/
//recordings
$tmp_selected = false;
$sql = "select * from v_recordings where domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$recordings = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($recordings) > 0) {
$sql = "select * from v_recordings where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$database = new database;
$recordings = $database->select($sql, $parameters, 'all');
if (is_array($recordings) && @sizeof($recordings) != 0) {
echo "<optgroup label='Recordings'>\n";
foreach ($recordings as &$row) {
$recording_name = $row["recording_name"];
@ -415,12 +372,14 @@
}
echo "</optgroup>\n";
}
unset($sql, $parameters, $recordings, $row);
//phrases
$sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
$sql = "select * from v_phrases where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$database = new database;
$result = $database->select($sql, $parameters, 'all');
if (is_array($result) && @sizeof($result) != 0) {
echo "<optgroup label='Phrases'>\n";
foreach ($result as &$row) {
if ($music_on_hold_chime_list == "phrase:".$row["phrase_uuid"]) {
@ -431,13 +390,13 @@
echo " <option value='phrase:".escape($row["phrase_uuid"])."'>".escape($row["phrase_name"])."</option>\n";
}
}
unset ($prep_statement);
echo "</optgroup>\n";
}
unset($sql, $parameters, $result, $row);
//sounds
$file = new file;
$sound_files = $file->sounds();
if (is_array($sound_files)) {
if (is_array($sound_files) && @sizeof($sound_files) != 0) {
echo "<optgroup label='Sounds'>\n";
foreach ($sound_files as $value) {
if (strlen($value) > 0) {
@ -455,6 +414,7 @@
}
echo "</optgroup>\n";
}
unset($sound_files, $value);
//select
if (if_group("superadmin")) {
if (!$tmp_selected && strlen($music_on_hold_chime_list) > 0) {