Portions created by the Initial Developer are Copyright (C) 2008-2025 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (!permission_exists('voicemail_greeting_edit')) { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //add the settings object $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); //as long as the class exists, enable speech using default settings $speech_enabled = class_exists('speech') && $settings->get('speech', 'enabled', false); $speech_engine = $settings->get('speech', 'engine', ''); //as long as the class exists, enable transcribe using default settings $transcribe_enabled = class_exists('transcribe') && $settings->get('transcribe', 'enabled', false); $transcribe_engine = $settings->get('transcribe', 'engine', ''); //set the storage type from default settings $storage_type = $settings->get('voicemail', 'storage_type', ''); //set defaults $translate_enabled = false; $language_enabled = false; //add the speech object and get the voices and languages arrays if ($speech_enabled && !empty($speech_engine)) { $speech = new speech($settings); $voices = $speech->get_voices(); //$speech_models = $speech->get_models(); //$translate_enabled = $speech->get_translate_enabled(); //$language_enabled = $speech->get_language_enabled(); //$languages = $speech->get_languages(); } //add the transcribe object and get the languages arrays if ($transcribe_enabled && !empty($transcribe_engine)) { $transcribe = new transcribe($settings); //$transcribe_models = $transcribe->get_models(); //$translate_enabled = $transcribe->get_translate_enabled(); //$language_enabled = $transcribe->get_language_enabled(); //$languages = $transcribe->get_languages(); } //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $action = "update"; $voicemail_greeting_uuid = $_REQUEST["id"]; } else { $action = "add"; $voicemail_greeting_uuid = uuid(); } if (!empty($_REQUEST["voicemail_id"]) && is_numeric($_REQUEST["voicemail_id"])) { $voicemail_id = $_REQUEST["voicemail_id"]; } //get the form value and set to php variables if (!empty($_POST) && is_array($_POST)) { $greeting_id = $_POST["greeting_id"]; $greeting_name = $_POST["greeting_name"]; $greeting_voice = $_POST["greeting_voice"]; //$greeting_model = $_POST["greeting_model"]; $greeting_language = $_POST["greeting_language"] ?? null; //$translate = $_POST["translate"]; $greeting_message = $_POST["greeting_message"]; $greeting_description = $_POST["greeting_description"]; //clean the name $greeting_name = str_replace("'", "", $greeting_name); } if (!empty($_POST) && empty($_POST["persistformvar"])) { //delete the voicemail greeting if (permission_exists('voicemail_greeting_delete')) { if (!empty($_POST['action']) && $_POST['action'] == 'delete' && is_uuid($voicemail_greeting_uuid)) { //prepare $array[0]['checked'] = 'true'; $array[0]['uuid'] = $voicemail_greeting_uuid; //delete $obj = new voicemail_greetings; $obj->voicemail_id = $voicemail_id; $obj->delete($array); //redirect header("Location: voicemail_greetings.php?id=".$voicemail_id); exit; } } //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: ../voicemails/voicemails.php'); exit; } //check for all required data $msg = ''; if (empty($greeting_name)) { $msg .= "".$text['confirm-name']."
\n"; } if (!empty($msg) && empty($_POST["persistformvar"])) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //update the database if ((empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") && permission_exists('voicemail_greeting_edit')) { //get current vm greeting ids for mailbox $sql = "select greeting_id "; $sql .= "from v_voicemail_greetings where domain_uuid = :domain_uuid "; $sql .= "and voicemail_id = :voicemail_id "; $sql .= "order by greeting_id asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['voicemail_id'] = $voicemail_id; $rows = $database->select($sql, $parameters, 'all'); $greeting_ids = array(); if (!empty($rows) && is_array($rows)) { foreach ($rows as $row) { $greeting_ids[] = $row['greeting_id']; } } unset($sql, $parameters); //set the recording format $greeting_format = $greeting_format ?? 'wav'; //build the setting object and get the recording path $greeting_path = $settings->get('switch', 'voicemail').'/default/'.$_SESSION['domain_name'].'/'.$voicemail_id.'/'; if ($action == 'add') { //find the next available greeting id $greeting_id = 0; for ($i = 1; $i <= 9; $i++) { if (!in_array($i, $greeting_ids) && !file_exists($greeting_path.'greeting_'.$i.'.'.$greeting_format)) { $greeting_id = $i; break; } } } if (!empty($greeting_id)) { //set file name $greeting_filename = 'greeting_'.$greeting_id.'.'.$greeting_format; //text to audio - make a new audio file from the message if ($speech_enabled && !empty($greeting_voice) && !empty($greeting_message)) { $speech->audio_path = $greeting_path; $speech->audio_filename = $greeting_filename; $speech->audio_format = $greeting_format; //$speech->audio_model = $greeting_model ?? ''; $speech->audio_voice = $greeting_voice; //$speech->audio_language = $greeting_language; //$speech->audio_translate = $translate; $speech->audio_message = $greeting_message; $speech->speech(); //fix invalid riff & data header lengths in generated wave file if ($speech_engine == 'openai') { $greeting_filename_temp = str_replace('.'.$greeting_format, '.tmp.'.$greeting_format, $greeting_filename); exec('sox --ignore-length '.$greeting_path.$greeting_filename.' '.$greeting_path.$greeting_filename_temp); if (file_exists($greeting_path.$greeting_filename_temp)) { exec('rm -f '.$greeting_path.$greeting_filename.' && mv '.$greeting_path.$greeting_filename_temp.' '.$greeting_path.$greeting_filename); } unset($greeting_filename_temp); } } //audio to text - get the transcription from the audio file if ($transcribe_enabled && empty($greeting_voice) && empty($greeting_message)) { $transcribe->audio_path = $greeting_path; $transcribe->audio_filename = $greeting_filename; $greeting_message = $transcribe->transcribe(); } //if base64 is enabled base64 if ($storage_type == 'base64' && file_exists($greeting_path.'/'.$greeting_filename)) { $greeting_base64 = base64_encode(file_get_contents($greeting_path.'/'.$greeting_filename)); } //build data array $array['voicemail_greetings'][0]['voicemail_greeting_uuid'] = $voicemail_greeting_uuid; $array['voicemail_greetings'][0]['domain_uuid'] = $_SESSION['domain_uuid']; $array['voicemail_greetings'][0]['voicemail_id'] = $voicemail_id; $array['voicemail_greetings'][0]['greeting_id'] = $greeting_id; $array['voicemail_greetings'][0]['greeting_name'] = $greeting_name; $array['voicemail_greetings'][0]['greeting_message'] = $greeting_message; $array['voicemail_greetings'][0]['greeting_filename'] = $greeting_filename; $array['voicemail_greetings'][0]['greeting_base64'] = $greeting_base64; $array['voicemail_greetings'][0]['greeting_description'] = $greeting_description; //execute query $database->save($array); unset($array); //set message message::add($text['message-'.($action == 'add' ? 'greeting_created' : 'update')]); } //redirect header("Location: voicemail_greetings.php?id=".$voicemail_id); exit; } } //pre-populate the form if ( $action == 'update' && !empty($voicemail_greeting_uuid) && is_uuid($voicemail_greeting_uuid) && (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") ) { $sql = "select * from v_voicemail_greetings "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and voicemail_greeting_uuid = :voicemail_greeting_uuid "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['voicemail_greeting_uuid'] = $voicemail_greeting_uuid; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $greeting_id = $row["greeting_id"]; $greeting_name = $row["greeting_name"]; $greeting_message = $row["greeting_message"]; $greeting_description = $row["greeting_description"]; } unset($sql, $parameters, $row); } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //show the header $document['title'] = $text['label-'.($action == 'update' ? 'edit' : 'add')]; require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
".$text['label-'.($action == 'update' ? 'edit' : 'add')]."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','style'=>'margin-right: 15px;','collapse'=>'hide-xs','link'=>'voicemail_greetings.php?id='.urlencode($voicemail_id)]); if (permission_exists('voicemail_greeting_delete') && $action == 'update') { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'name'=>'btn_delete','collapse'=>'hide-xs','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','collapse'=>'hide-xs']); echo "
\n"; echo "
\n"; echo "
\n"; if (permission_exists('voicemail_greeting_delete') && $action == 'update') { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); } echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($speech_enabled || $transcribe_enabled) { //models if (!empty($models) && is_array($models)) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } // else { // echo "\n"; // } //voices echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($language_enabled) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if ($translate_enabled) { 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 "
\n"; echo " ".$text['label-name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "".$text['description-name']."\n"; echo "
\n"; echo " ".$text['label-model']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-model']."\n"; echo "
\n"; echo " ".$text['label-voice']."\n"; echo "\n"; if (!empty($voices) && is_array($voices)) { echo " \n"; } else { echo " \n"; } echo "
\n"; echo $text['description-voice']."\n"; echo "
\n"; echo " ".$text['label-language']."\n"; echo "\n"; if (!empty($languages) && is_array($languages)) { sort($languages); echo " \n"; } else { echo " \n"; } echo "
\n"; echo $text['description-languages']."\n"; echo "
\n"; echo " ".$text['label-translate']."\n"; echo "\n"; if ($input_toggle_style_switch) { echo " \n"; } echo " \n"; if ($input_toggle_style_switch) { echo " \n"; echo " \n"; } echo "
\n"; echo $text['description-translate']."\n"; echo "
\n"; echo " ".$text['label-message']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message']."\n"; echo "
\n"; echo " ".$text['label-description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo "".$text['description-info']."\n"; echo "
"; echo "
\n"; echo "

"; if ($action == 'update' && !empty($voicemail_greeting_uuid) && is_uuid($voicemail_greeting_uuid)) { echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "
"; //include the footer require_once "resources/footer.php"; ?>