From ff6a3ea71df9ebe507838a65b4f731946ca994fc Mon Sep 17 00:00:00 2001 From: fusionate Date: Tue, 7 Nov 2023 01:56:39 +0000 Subject: [PATCH] Call Center Queue - Edit: Add playback of selected Greeting and Announce Sound (Recordings and Sounds). --- app/call_centers/call_center_queue_edit.php | 354 +++++++++++--------- 1 file changed, 201 insertions(+), 153 deletions(-) diff --git a/app/call_centers/call_center_queue_edit.php b/app/call_centers/call_center_queue_edit.php index b70bda5dae..9cb2bc32e1 100644 --- a/app/call_centers/call_center_queue_edit.php +++ b/app/call_centers/call_center_queue_edit.php @@ -592,7 +592,16 @@ //get the sounds $sounds = new sounds; - $sounds = $sounds->get(); + $audio_files[0] = $sounds->get(); + unset($sounds); + + if (permission_exists('call_center_announce_sound')) { + $sounds = new sounds; + $sounds->sound_types = ['recordings']; + $sounds->full_path = ['recordings']; + $audio_files[1] = $sounds->get(); + unset($sounds); + } //set default values if (empty($queue_strategy)) { $queue_strategy = "longest-idle-agent"; } @@ -613,23 +622,6 @@ $object = new token; $token = $object->create($_SERVER['PHP_SELF']); -//get the recordings - $sql = "select recording_name, recording_filename from v_recordings "; - $sql .= "where domain_uuid = :domain_uuid "; - $sql .= "order by recording_name asc "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; - $recordings = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters); - -//get the phrases - $sql = "select * from v_phrases "; - $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; - $parameters['domain_uuid'] = $domain_uuid; - $database = new database; - $phrases = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters); - //show the header if ($action == "add") { $document['title'] = $text['title-call_center_queue_add']; @@ -644,40 +636,77 @@ $call_center_queue_uuid = null; } -//option to change select to text - if (if_group("superadmin")) { - echo "\n"; + } + if (if_group("superadmin")) { + echo "\n"; - echo "\n"; } -//show the content echo "
\n"; echo "
\n"; @@ -729,30 +758,76 @@ echo "\n"; echo "\n"; + $instance_id = 'queue_greeting'; + $instance_label = 'greeting'; + $instance_value = $queue_greeting; echo "\n"; - echo "\n"; - echo " ".$text['label-greeting']."\n"; + echo "\n"; + echo " ".$text['label-'.$instance_label]."\n"; echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; - echo "\n"; echo " \n"; - foreach($sounds as $key => $value) { - echo "\n"; - $selected = false; - foreach($value as $row) { - if (!empty($queue_greeting) && $queue_greeting == $row["value"]) { - $selected = true; - echo " \n"; - } - else { - echo " \n"; + $found = $playable = false; + if (!empty($audio_files[0]) && is_array($audio_files[0]) && @sizeof($audio_files[0]) != 0) { + foreach ($audio_files[0] as $key => $value) { + echo "\n"; + foreach ($value as $row) { + if ($key == 'recordings') { + if ( + !empty($instance_value) && + ($instance_value == $row["value"] || $instance_value == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'].'/'.$row["value"]) && + file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'].'/'.pathinfo($row["value"], PATHINFO_BASENAME)) + ) { + $selected = "selected='selected'"; + $playable = '../recordings/recordings.php?action=download&type=rec&filename='.pathinfo($row["value"], PATHINFO_BASENAME); + $found = true; + } + else { + unset($selected); + } + } + else if ($key == 'sounds') { + if (!empty($instance_value) && $instance_value == $row["value"]) { + $selected = "selected='selected'"; + $playable = '../switch/sounds.php?action=download&filename='.$row["value"]; + $found = true; + } + else { + unset($selected); + } + } + else { + unset($selected); + } + echo " \n"; } + echo "\n"; } - echo "\n"; } + if (if_group("superadmin") && !empty($instance_value) && !$found) { + echo " \n"; + } + unset($selected); echo " \n"; + if (if_group("superadmin")) { + echo ""; + } + if ((permission_exists('recording_play') || permission_exists('recording_download')) && (!empty($playable) || empty($instance_value))) { + switch (pathinfo($playable, PATHINFO_EXTENSION)) { + case 'wav' : $mime_type = 'audio/wav'; break; + case 'mp3' : $mime_type = 'audio/mpeg'; break; + case 'ogg' : $mime_type = 'audio/ogg'; break; + } + echo ""; + echo button::create(['type'=>'button','title'=>$text['label-play'].' / '.$text['label-pause'],'icon'=>$_SESSION['theme']['button_icon_play'],'id'=>'recording_button_'.$instance_id,'style'=>'display: '.(!empty($mime_type) ? 'inline' : 'none'),'onclick'=>"recording_play('".$instance_id."')"]); + unset($playable, $mime_type); + } echo "
\n"; - echo $text['description-greeting']."\n"; + echo $text['description-'.$instance_label]."\n"; echo "\n"; echo "\n"; @@ -1184,103 +1259,76 @@ } if (permission_exists('call_center_announce_sound')) { + $instance_id = 'queue_announce_sound'; + $instance_label = 'caller_announce_sound'; + $instance_value = $queue_announce_sound; echo "\n"; - echo "\n"; - echo " ".$text['label-caller_announce_sound']."\n"; + echo "\n"; + echo " ".$text['label-'.$instance_label]."\n"; echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; echo "\n"; - - $destination_id = "queue_announce_sound"; - $script = "\n"; - $script .= "\n"; - echo $script; - - echo "\n"; + echo " \n"; + $found = $playable = false; + if (!empty($audio_files[1]) && is_array($audio_files[1]) && @sizeof($audio_files[1]) != 0) { + foreach ($audio_files[1] as $key => $value) { + echo "\n"; + foreach ($value as $row) { + if ($key == 'recordings') { + if ( + !empty($instance_value) && + ($instance_value == $row["value"] || $instance_value == $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'].'/'.$row["value"]) && + file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name'].'/'.pathinfo($row["value"], PATHINFO_BASENAME)) + ) { + $selected = "selected='selected'"; + $playable = '../recordings/recordings.php?action=download&type=rec&filename='.pathinfo($row["value"], PATHINFO_BASENAME); + $found = true; + } + else { + unset($selected); + } + } + else if ($key == 'sounds') { + if (!empty($instance_value) && $instance_value == $row["value"]) { + $selected = "selected='selected'"; + $playable = '../switch/sounds.php?action=download&filename='.$row["value"]; + $found = true; + } + else { + unset($selected); + } + } + else { + unset($selected); + } + echo " \n"; } + echo "\n"; } - echo "\n"; } - - if (!$tmp_selected && !empty($queue_announce_sound)) { - echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$queue_announce_sound)) { - echo " \n"; - } - else if (substr($queue_announce_sound, -3) == "wav" || substr($queue_announce_sound, -3) == "mp3") { - echo " \n"; - } - else { - echo " \n"; - } - echo "\n"; + if (if_group("superadmin") && !empty($instance_value) && !$found) { + echo " \n"; } - - unset($tmp_selected); - + unset($selected); echo " \n"; - echo ""; - - unset($destination_id); - - echo "
\n"; - echo $text['description-caller_announce_sound']."\n"; + if (if_group("superadmin")) { + echo ""; + } + if ((permission_exists('recording_play') || permission_exists('recording_download')) && (!empty($playable) || empty($instance_value))) { + switch (pathinfo($playable, PATHINFO_EXTENSION)) { + case 'wav' : $mime_type = 'audio/wav'; break; + case 'mp3' : $mime_type = 'audio/mpeg'; break; + case 'ogg' : $mime_type = 'audio/ogg'; break; + } + echo ""; + echo button::create(['type'=>'button','title'=>$text['label-play'].' / '.$text['label-pause'],'icon'=>$_SESSION['theme']['button_icon_play'],'id'=>'recording_button_'.$instance_id,'style'=>'display: '.(!empty($mime_type) ? 'inline' : 'none'),'onclick'=>"recording_play('".$instance_id."')"]); + unset($playable, $mime_type); + } + echo "
\n"; + echo $text['description-'.$instance_label]."\n"; echo "\n"; echo "\n"; }