From 6a58bb97dd5c683d5b17a684ec2128098e8cd098 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Mon, 13 Jun 2016 17:44:15 -0600 Subject: [PATCH] Update app_defaults for muisc on hold so it reads local_stream.conf.xml and loads the information in the database. Remove music_on_hold_category. --- app/music_on_hold/app_config.php | 4 -- app/music_on_hold/app_defaults.php | 77 ++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/app/music_on_hold/app_config.php b/app/music_on_hold/app_config.php index a64dc22b0a..beb6a59c59 100644 --- a/app/music_on_hold/app_config.php +++ b/app/music_on_hold/app_config.php @@ -58,10 +58,6 @@ $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; $z++; - $apps[$x]['db'][$y]['fields'][$z]['name'] = "music_on_hold_category"; - $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; - $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; - $z++; $apps[$x]['db'][$y]['fields'][$z]['name'] = "music_on_hold_rate"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "numeric"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = "8000,16000,32000,48000"; diff --git a/app/music_on_hold/app_defaults.php b/app/music_on_hold/app_defaults.php index 563befa8d2..e4d74d5a54 100644 --- a/app/music_on_hold/app_defaults.php +++ b/app/music_on_hold/app_defaults.php @@ -22,15 +22,82 @@ Contributor(s): Mark J Crane - Matthew Vale */ if ($domains_processed == 1) { - require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; - $moh = new switch_music_on_hold; - $moh->xml(); - $moh->save(); + //require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; + //$moh = new switch_music_on_hold; + //$moh->xml(); + //$moh->save(); + + //add the music_on_hold list to the database + $sql = "select count(*) 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 directory + $xml_dir = $_SESSION["switch"]["conf"]["dir"].'/autoload_configs'; + $xml_file = $xml_dir."/local_stream.conf.xml"; + $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']; + } + + //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, "; + 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); + } + + //rename the file + rename($xml_dir.'/local_stream.conf.xml', $xml_dir.'/local_stream.conf'); } ?> \ No newline at end of file