Portions created by the Initial Developer are Copyright (C) 2008-2022 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('voicemail_add') || permission_exists('voicemail_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //initialize the destinations object $destination = new destinations; //action add or update if (is_uuid($_REQUEST["id"])) { $action = "update"; $voicemail_uuid = $_REQUEST["id"]; } else { $action = "add"; } //get http variables and set them to php variables $referer_path = $_REQUEST["referer_path"]; $referer_query = $_REQUEST["referer_query"]; if (count($_POST) > 0) { //process the http post data by submitted action if ($_POST['action'] != '' && is_uuid($_POST['voicemail_uuid'])) { $array[0]['checked'] = 'true'; $array[0]['uuid'] = $_POST['voicemail_uuid']; switch ($_POST['action']) { case 'delete': if (permission_exists('voicemail_delete')) { $obj = new voicemail; $obj->voicemail_delete($array); } break; } header('Location: voicemails.php'); exit; } //set the variables from the HTTP values $voicemail_id = $_POST["voicemail_id"]; $voicemail_password = $_POST["voicemail_password"]; $greeting_id = $_POST["greeting_id"]; $voicemail_options = $_POST["voicemail_options"]; $voicemail_alternate_greet_id = $_POST["voicemail_alternate_greet_id"]; $voicemail_mail_to = $_POST["voicemail_mail_to"]; $voicemail_sms_to = $_POST["voicemail_sms_to"]; $voicemail_transcription_enabled = $_POST["voicemail_transcription_enabled"]; $voicemail_file = $_POST["voicemail_file"]; $voicemail_local_after_email = $_POST["voicemail_local_after_email"]; $voicemail_destination = $_POST["voicemail_destination"]; $voicemail_enabled = $_POST["voicemail_enabled"]; $voicemail_description = $_POST["voicemail_description"]; $voicemail_tutorial = $_POST["voicemail_tutorial"]; $voicemail_options_delete = $_POST["voicemail_options_delete"]; $voicemail_destinations_delete = $_POST["voicemail_destinations_delete"]; //remove the space $voicemail_mail_to = str_replace(" ", "", $voicemail_mail_to); } //process the data if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $voicemail_uuid = $_POST["voicemail_uuid"]; } //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: voicemails.php'); exit; } //check for all required data $msg = ''; if (!is_numeric($voicemail_id)) { $msg .= $text['message-required']." ".$text['label-voicemail_id']."
\n"; } if (trim($voicemail_password) == '') { $msg .= $text['message-required']." ".$text['label-voicemail_password']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { 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; } //add or update the database if ($_POST["persistformvar"] != "true") { //get a new voicemail_uuid if ($action == "add" && permission_exists('voicemail_add')) { $voicemail_uuid = uuid(); //if adding a mailbox and don't have the transcription permission, set the default transcribe behavior if (!permission_exists('voicemail_transcription_enabled') && isset($_SESSION['voicemail']['transcription_enabled_default']['boolean'])) { $voicemail_transcription_enabled = $_SESSION['voicemail']['transcription_enabled_default']['boolean']; } } //add common array fields $array['voicemails'][0]['domain_uuid'] = $domain_uuid; $array['voicemails'][0]['voicemail_uuid'] = $voicemail_uuid; $array['voicemails'][0]['voicemail_id'] = $voicemail_id; $array['voicemails'][0]['voicemail_password'] = $voicemail_password; $array['voicemails'][0]['greeting_id'] = $greeting_id != '' ? $greeting_id : null; $array['voicemails'][0]['voicemail_alternate_greet_id'] = $voicemail_alternate_greet_id != '' ? $voicemail_alternate_greet_id : null; $array['voicemails'][0]['voicemail_mail_to'] = $voicemail_mail_to; $array['voicemails'][0]['voicemail_sms_to'] = $voicemail_sms_to; $array['voicemails'][0]['voicemail_transcription_enabled'] = $voicemail_transcription_enabled; $array['voicemails'][0]['voicemail_tutorial'] = $voicemail_tutorial; if (permission_exists('voicemail_file')) { $array['voicemails'][0]['voicemail_file'] = $voicemail_file; } if (permission_exists('voicemail_local_after_email')) { $array['voicemails'][0]['voicemail_local_after_email'] = $voicemail_local_after_email; } $array['voicemails'][0]['voicemail_enabled'] = $voicemail_enabled; $array['voicemails'][0]['voicemail_description'] = $voicemail_description; //create permissions object $p = new permissions; //add voicemail options if (permission_exists('voicemail_option_add') && sizeof($voicemail_options) > 0) { foreach ($voicemail_options as $x => $voicemail_option) { if ($voicemail_option['voicemail_option_digits'] == '' || $voicemail_option['voicemail_option_param'] == '') { unset($voicemail_options[$x]); } } foreach ($voicemail_options as $x => $voicemail_option) { if (is_numeric($voicemail_option["voicemail_option_param"])) { //if numeric then add tranfer $1 XML domain_name $voicemail_option['voicemail_option_action'] = "menu-exec-app"; $voicemail_option['voicemail_option_param'] = "transfer ".$voicemail_option["voicemail_option_param"]." XML ".$_SESSION['domain_name']; } else { //seperate the action and the param $option_array = explode(":", $voicemail_option["voicemail_option_param"]); $voicemail_option['voicemail_option_action'] = array_shift($option_array); $voicemail_option['voicemail_option_param'] = join(':', $option_array); } //build insert array $array['voicemail_options'][$x]['voicemail_option_uuid'] = uuid(); $array['voicemail_options'][$x]['voicemail_uuid'] = $voicemail_uuid; $array['voicemail_options'][$x]['domain_uuid'] = $domain_uuid; $array['voicemail_options'][$x]['voicemail_option_digits'] = $voicemail_option['voicemail_option_digits']; $array['voicemail_options'][$x]['voicemail_option_action'] = $voicemail_option['voicemail_option_action']; if ($destination->valid(preg_replace('/\s/', ':', $voicemail_option['voicemail_option_param'], 1))) { $array['voicemail_options'][$x]['voicemail_option_param'] = $voicemail_option['voicemail_option_param']; } $array['voicemail_options'][$x]['voicemail_option_order'] = $voicemail_option['voicemail_option_order']; $array['voicemail_options'][$x]['voicemail_option_description'] = $voicemail_option['voicemail_option_description']; } if (is_array($array['voicemail_options']) && @sizeof($array['voicemail_options']) != 0) { //grant temporary permission $p->add('voicemail_option_add', 'temp'); } } //add voicemail destination if (permission_exists('voicemail_forward') && is_uuid($voicemail_destination)) { $array['voicemail_destinations'][0]['domain_uuid'] = $domain_uuid; $array['voicemail_destinations'][0]['voicemail_destination_uuid'] = uuid(); $array['voicemail_destinations'][0]['voicemail_uuid'] = $voicemail_uuid; $array['voicemail_destinations'][0]['voicemail_uuid_copy'] = $voicemail_destination; if (is_array($array['voicemail_destinations']) && @sizeof($array['voicemail_destinations']) != 0) { //grant temporary permission $p->add('voicemail_destination_add', 'temp'); } } //execute insert/update $database = new database; $database->app_name = 'voicemails'; $database->app_uuid = 'b523c2d2-64cd-46f1-9520-ca4b4098e044'; $database->save($array); unset($array); //revoke any temporary permissions granted $p->delete('voicemail_option_add', 'temp'); $p->delete('voicemail_destination_add', 'temp'); //make sure the voicemail directory exists if (is_numeric($voicemail_id)) { if (!file_exists($_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$voicemail_id)) { mkdir($_SESSION['switch']['voicemail']['dir']."/default/".$_SESSION['domain_name']."/".$voicemail_id, 0770); } } //remove checked voicemail options if ( $action == 'update' && permission_exists('voicemail_option_delete') && is_array($voicemail_options_delete) && @sizeof($voicemail_options_delete) != 0 ) { $obj = new voicemail; $obj->voicemail_uuid = $voicemail_uuid; $obj->voicemail_options_delete($voicemail_options_delete); } //remove checked voicemail destinations if ( $action == 'update' && permission_exists('voicemail_forward') && is_array($voicemail_destinations_delete) && @sizeof($voicemail_destinations_delete) != 0 ) { $obj = new voicemail; $obj->voicemail_uuid = $voicemail_uuid; $obj->voicemail_destinations_delete($voicemail_destinations_delete); } //clear the destinations session array if (isset($_SESSION['destinations']['array'])) { unset($_SESSION['destinations']['array']); } //set message if ($action == "add" && permission_exists('voicemail_add')) { message::add($text['message-add']); } if ($action == "update" && permission_exists('voicemail_edit')) { message::add($text['message-update']); } //redirect user if ($action == 'add') { header("Location: voicemails.php"); } else if ($action == "update") { header("Location: voicemail_edit.php?id=".$voicemail_uuid); } exit; } } //pre-populate the form if (count($_GET)>0 && is_uuid($_GET["id"]) && $_POST["persistformvar"] != "true") { $voicemail_uuid = $_GET["id"]; $sql = "select * from v_voicemails "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and voicemail_uuid = :voicemail_uuid "; $parameters['domain_uuid'] = $domain_uuid; $parameters['voicemail_uuid'] = $voicemail_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $voicemail_id = $row["voicemail_id"]; $voicemail_password = $row["voicemail_password"]; $greeting_id = $row["greeting_id"]; $voicemail_alternate_greet_id = $row["voicemail_alternate_greet_id"]; $voicemail_mail_to = $row["voicemail_mail_to"]; $voicemail_sms_to = $row["voicemail_sms_to"]; $voicemail_transcription_enabled = $row["voicemail_transcription_enabled"]; $voicemail_tutorial = $row["voicemail_tutorial"]; $voicemail_file = $row["voicemail_file"]; $voicemail_local_after_email = $row["voicemail_local_after_email"]; $voicemail_enabled = $row["voicemail_enabled"]; $voicemail_description = $row["voicemail_description"]; } unset($sql, $parameters, $row); } else { $voicemail_file = $_SESSION['voicemail']['voicemail_file']['text']; $voicemail_local_after_email = $_SESSION['voicemail']['keep_local']['boolean']; } //remove the spaces $voicemail_mail_to = str_replace(" ", "", $voicemail_mail_to); //set defaults if (strlen($voicemail_local_after_email) == 0) { $voicemail_local_after_email = "true"; } if (strlen($voicemail_enabled) == 0) { $voicemail_enabled = "true"; } if (strlen($voicemail_transcription_enabled) == 0) { $voicemail_transcription_enabled = $_SESSION['voicemail']['transcription_enabled_default']['boolean']; } if (strlen($voicemail_tutorial) == 0) { $voicemail_tutorial = "false"; } //get the greetings list $sql = "select * from v_voicemail_greetings "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and voicemail_id = :voicemail_id "; $sql .= "order by greeting_name asc "; $parameters['domain_uuid'] = $domain_uuid; $parameters['voicemail_id'] = $voicemail_id; $database = new database; $greetings = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //get the voicemail options if ($action == 'update' && is_uuid($voicemail_uuid)) { $sql = "select * from v_voicemail_options "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and voicemail_uuid = :voicemail_uuid "; $sql .= "order by voicemail_option_digits, voicemail_option_order asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['voicemail_uuid'] = $voicemail_uuid; $database = new database; $voicemail_options = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); $show_option_delete = false; if (is_array($voicemail_options) && @sizeof($voicemail_options) != 0) { foreach ($voicemail_options as $x => $field) { $voicemail_option_param = $field['voicemail_option_param']; if (strlen(trim($voicemail_option_param)) == 0) { $voicemail_option_param = $field['voicemail_option_action']; } $voicemail_option_param = str_replace("menu-", "", $voicemail_option_param); $voicemail_option_param = str_replace("XML", "", $voicemail_option_param); $voicemail_option_param = str_replace("transfer", "", $voicemail_option_param); $voicemail_option_param = str_replace("bridge", "", $voicemail_option_param); $voicemail_option_param = str_replace($_SESSION['domain_name'], "", $voicemail_option_param); $voicemail_option_param = str_replace("\${domain_name}", "", $voicemail_option_param); $voicemail_option_param = str_replace("\${domain}", "", $voicemail_option_param); $voicemail_option_param = ucfirst(trim($voicemail_option_param)); $voicemail_options[$x]['voicemail_option_param'] = $voicemail_option_param; unset($voicemail_option_param); } $show_option_delete = true; } } //get the assigned voicemail destinations if ($action == 'update' && is_uuid($voicemail_uuid)) { $sql = "select v.voicemail_id, d.voicemail_destination_uuid, d.voicemail_uuid_copy "; $sql .= "from v_voicemails as v, v_voicemail_destinations as d "; $sql .= "where d.voicemail_uuid_copy = v.voicemail_uuid and "; $sql .= "v.domain_uuid = :domain_uuid and "; $sql .= "v.voicemail_enabled = 'true' and "; $sql .= "d.voicemail_uuid = :voicemail_uuid "; $sql .= "order by v.voicemail_id asc"; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['voicemail_uuid'] = $voicemail_uuid; $database = new database; $voicemail_destinations_assigned = $database->select($sql, $parameters, 'all'); if (is_array($voicemail_destinations_assigned) && @sizeof($voicemail_destinations_assigned) != 0) { foreach ($voicemail_destinations_assigned as $field) { $voicemail_destinations[] = "'".$field['voicemail_uuid_copy']."'"; } } unset($sql, $parameters); } //get the available voicemail destinations $sql = "select v.voicemail_id, v.voicemail_uuid "; $sql .= "from v_voicemails as v "; $sql .= "where v.domain_uuid = :domain_uuid and "; $sql .= "v.voicemail_enabled = 'true' "; if (is_uuid($voicemail_uuid)) { $sql .= "and v.voicemail_uuid <> :voicemail_uuid "; } if (is_array($voicemail_destinations) && @sizeof($voicemail_destinations) != 0) { $sql .= "and v.voicemail_uuid not in (".implode(',', $voicemail_destinations).") "; } $sql .= "order by v.voicemail_id asc"; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; if (is_uuid($voicemail_uuid)) { $parameters['voicemail_uuid'] = $voicemail_uuid; } $database = new database; $voicemail_destinations_available = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $voicemail_destinations); //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header $document['title'] = $text['title-voicemail']; require_once "resources/header.php"; //password complexity $password_complexity = $_SESSION['voicemail']['password_complexity']['boolean']; if ($password_complexity == "true") { echo "\n"; } //set the location for the back button if (permission_exists('voicemail_view')) { $back_button_location = "voicemails.php"; } else { $back_button_location = "voicemail_messages.php?voicemail_uuid=".urlencode($voicemail_uuid); } //show the content echo "
\n"; echo "
\n"; echo "
".$text['title-voicemail']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>$back_button_location]); if ($action == "update" && (permission_exists('voicemail_delete') || permission_exists('voicemail_option_delete'))) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-left: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;','onclick'=>($password_complexity == "true" ? "if (check_password_strength(document.getElementById('password').value)) { submit_form(); } else { this.blur(); return false; }" : 'submit_form();')]); echo "
\n"; echo "
\n"; echo "
\n"; if ($action == "update" && (permission_exists('voicemail_delete') || permission_exists('voicemail_option_delete'))) { 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"; 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 "\n"; echo "\n"; if (permission_exists('voicemail_option_add') || permission_exists('voicemail_option_edit')) { echo " "; echo " "; echo " "; echo " "; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('voicemail_sms_edit') && file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH.'/app/sms/')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('voicemail_transcription_enabled') && $_SESSION['voicemail']['transcribe_enabled']['boolean'] == "true") { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('voicemail_file')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('voicemail_local_after_email')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('voicemail_forward')) { echo " "; echo " "; echo " "; echo " "; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-voicemail_id']."\n"; echo "\n"; echo " \n"; echo " \n"; //help defeat browser auto-fill echo "
\n"; echo $text['description-voicemail_id']."\n"; echo "
\n"; echo " ".$text['label-voicemail_password']."\n"; echo "\n"; echo " \n"; //help defeat browser auto-fill echo " \n"; echo "
\n"; echo $text['description-voicemail_password']."\n"; echo "
\n"; echo " ".$text['label-voicemail_tutorial']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_tutorial']."\n"; echo "
\n"; echo " ".$text['label-greeting']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-greeting']."\n"; echo "
\n"; echo " ".$text['label-voicemail_alternate_greet_id']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['description-voicemail_alternate_greet_id']."\n"; echo "
".$text['label-options'].""; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if ($show_option_delete && permission_exists('voicemail_option_delete')) { echo " \n"; } echo " \n"; if ($action == 'update' && is_array($voicemail_options) && @sizeof($voicemail_options) != 0) { foreach ($voicemail_options as $x => $field) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if ($show_option_delete && permission_exists('voicemail_option_delete')) { echo " \n"; } echo " \n"; } } unset($voicemail_options, $field); for ($c = 0; $c < 1; $c++) { echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; } echo "
".$text['label-option']."".$text['label-destination']."".$text['label-order']."".$text['label-description']."\n"; echo " ".$text['label-delete']."\n"; echo " \n"; echo "
".escape($field['voicemail_option_digits'])."".escape($field['voicemail_option_param'])."".escape($field['voicemail_option_order'])."".escape($field['voicemail_option_description']).""; if (is_uuid($field['voicemail_option_uuid'])) { echo " \n"; echo " \n"; } echo "
\n"; echo " \n"; echo " \n"; echo $destination->select('ivr', 'voicemail_options['.$c.'][voicemail_option_param]', ''); echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-options']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-voicemail_mail_to']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_mail_to']."\n"; echo "
\n"; echo " ".$text['label-voicemail_sms_to']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_sms_to']."\n"; echo "
\n"; echo " ".$text['label-voicemail_transcription_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_transcription_enabled']."\n"; echo "
\n"; echo " ".$text['label-voicemail_file']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_file']."\n"; echo "
\n"; echo " ".$text['label-voicemail_local_after_email']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_local_after_email']."\n"; echo "
".$text['label-forward_destinations'].""; echo " \n"; if (is_array($voicemail_destinations_assigned) && @sizeof($voicemail_destinations_assigned) != 0) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; foreach ($voicemail_destinations_assigned as $x => $field) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; } } unset($voicemail_destinations_assigned, $field); if (is_array($voicemail_destinations_available) && @sizeof($voicemail_destinations_available) != 0) { echo " \n"; echo " \n"; echo " \n"; } unset($voicemail_destinations_available, $field); echo "
".$text['label-destination']."\n"; echo " ".$text['label-delete']."\n"; echo " \n"; echo "
".escape($field['voicemail_id']).""; echo " \n"; echo " \n"; echo "
\n"; echo " "; if ($action == 'update') { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'collapse'=>'never','onclick'=>'submit_form();']); } echo "
\n"; echo " ".$text['description-forward_destinations']."\n"; echo "
\n"; echo " ".$text['label-voicemail_enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_enabled']."\n"; echo "
\n"; echo " ".$text['label-voicemail_description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-voicemail_description']."\n"; echo "
"; echo "

"; if ($action == "update") { echo "\n"; } $http_referer = parse_url($_SERVER["HTTP_REFERER"]); echo "\n"; echo "\n"; echo "\n"; echo "
"; echo "\n"; //include the footer require_once "resources/footer.php"; ?>