diff --git a/app/phrases/phrase_edit.php b/app/phrases/phrase_edit.php index dc57eaae39..f0063ef047 100644 --- a/app/phrases/phrase_edit.php +++ b/app/phrases/phrase_edit.php @@ -271,6 +271,27 @@ unset ($prep_statement); } +//get the phrase details + if (strlen($phrase_uuid) > 0) { + $sql = "select * from v_phrase_details "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and phrase_uuid = '".$phrase_uuid."' "; + $sql .= "order by phrase_detail_order asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $phrase_details = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset($sql, $prep_statement); + } + +//get the recordings + $sql = "select * from v_recordings "; + $sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' "; + $sql .= "order by recording_name asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $recordings = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + unset($sql, $prep_statement); + //show the header require_once "resources/header.php"; if ($action == 'add') { $document['title'] = $text['title-add_phrase']; } @@ -300,12 +321,6 @@ echo " if (selected_index == 0) {\n"; //play echo " obj_action.options[obj_action.options.length] = new Option('', '');\n"; //blank option //recordings - $sql = "select * from v_recordings "; - $sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' "; - $sql .= "order by recording_name asc "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $recordings = $prep_statement->fetchAll(PDO::FETCH_ASSOC); $tmp_selected = false; if (count($recordings) > 0) { echo "var opt_group = document.createElement('optgroup');\n"; @@ -322,18 +337,20 @@ } unset($sql, $prep_statement, $recordings); //sounds - $files = recur_sounds_dir($_SESSION['switch']['sounds']['dir']); - if (count($files) > 0) { + //$files = recur_sounds_dir($_SESSION['switch']['sounds']['dir']); + $file = new file; + $sound_files = $file->sounds(); + if (is_array($sound_files)) { echo "var opt_group = document.createElement('optgroup');\n"; echo "opt_group.label = \"".$text['label-sounds']."\";\n"; - foreach ($files as $key => $value) { + foreach ($sound_files as $value) { if (strlen($value) > 0) { - if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { - echo "opt_group.appendChild(new Option(\"".$key."\", \"lua(streamfile.lua ".$key.")\"));\n"; - } - else { - echo "opt_group.appendChild(new Option(\"".$key."\", \"".$key."\"));\n"; - } + //if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { + // echo "opt_group.appendChild(new Option(\"".$value."\", \"lua(streamfile.lua ".$value.")\"));\n"; + //} + //else { + echo "opt_group.appendChild(new Option(\"".$value."\", \"".$value."\"));\n"; + //} } } echo "obj_action.appendChild(opt_group);\n"; @@ -453,34 +470,28 @@ echo " ".$text['label-order']."\n"; echo " \n"; echo " \n"; - if (strlen($phrase_uuid) > 0) { - $sql = "select * from v_phrase_details "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and phrase_uuid = '".$phrase_uuid."' "; - $sql .= "order by phrase_detail_order asc "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $result_count = count($result); - foreach($result as $field) { + if (is_array($phrase_details)) { + foreach($phrase_details as $field) { //clean up output for display - if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { - if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 19) == 'lua(streamfile.lua ') { - $phrase_detail_function = $text['label-play']; - $phrase_detail_data = str_replace('lua(streamfile.lua ', '', $field['phrase_detail_data']); - $phrase_detail_data = str_replace(')', '', $phrase_detail_data); - } + if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 19) == 'lua(streamfile.lua ') { + $phrase_detail_function = $text['label-play']; + $phrase_detail_data = str_replace('lua(streamfile.lua ', '', $field['phrase_detail_data']); + $phrase_detail_data = str_replace(')', '', $phrase_detail_data); } - if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 6) == 'sleep(') { + elseif ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 6) == 'sleep(') { $phrase_detail_function = $text['label-pause']; $phrase_detail_data = str_replace('sleep(', '', $field['phrase_detail_data']); $phrase_detail_data = str_replace(')', '', $phrase_detail_data); $phrase_detail_data = ($phrase_detail_data / 1000).'s'; // seconds } - if ($field['phrase_detail_function'] == 'play-file') { + elseif ($field['phrase_detail_function'] == 'play-file') { $phrase_detail_function = $text['label-play']; $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/', '', $field['phrase_detail_data']); } + else { + $phrase_detail_function = $field['phrase_detail_function']; + $phrase_detail_data = $field['phrase_detail_data']; + } echo "\n"; echo " ".$phrase_detail_function." \n"; echo " ".$phrase_detail_data." \n"; @@ -491,19 +502,13 @@ echo "\n"; } } - unset($sql, $result); echo "\n"; echo " \n"; echo " \n"; echo " \n"; @@ -599,4 +604,5 @@ //include the footer require_once "resources/footer.php"; + ?>