diff --git a/app/dialplan/dialplans.php b/app/dialplan/dialplans.php index 6f02b4d4d1..d27ee091b0 100644 --- a/app/dialplan/dialplans.php +++ b/app/dialplan/dialplans.php @@ -235,7 +235,7 @@ else { echo "\n"; echo "\n"; if (permission_exists('dialplan_delete') && $result_count > 0) { - echo ""; + echo ""; } echo th_order_by('dialplan_name', $text['label-name'], $order_by, $order, $app_uuid, null, (($search != '') ? "search=".$search : null)); echo th_order_by('dialplan_number', $text['label-number'], $order_by, $order, $app_uuid, null, (($search != '') ? "search=".$search : null)); diff --git a/app/ivr_menu/ivr_menus.php b/app/ivr_menu/ivr_menus.php index 180fa65c06..624efb90ba 100644 --- a/app/ivr_menu/ivr_menus.php +++ b/app/ivr_menu/ivr_menus.php @@ -54,119 +54,109 @@ else { } //show the content - echo "
\n"; + echo "".$text['header-ivr_menus']."\n"; + echo "

\n"; + echo $text['description-ivr_menus']."\n"; + echo "

\n"; + +//get the count + require_once "resources/classes/database.php"; + require_once "resources/classes/ivr_menu.php"; + $ivr = new ivr_menu; + $ivr->domain_uuid = $_SESSION["domain_uuid"]; + $ivr->table = "v_ivr_menus"; + $where[0]['name'] = 'domain_uuid'; + $where[0]['value'] = $_SESSION["domain_uuid"]; + $where[0]['operator'] = '='; + $ivr->where = $where; + $num_rows = $ivr->count(); + +//use total ivr menu count from the database + $total_ivr_menus = $num_rows; + +//prepare to page the results + $rows_per_page = 150; + $param = ""; + if (!isset($_GET['page'])) { $_GET['page'] = 0; } + $_GET['page'] = check_str($_GET['page']); + list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $_GET['page']; + +//get the list from the db + if (isset($order_by)) { + if (count($order_by) > 0) { + $ivr->order_by = $order_by; + } + } + $result = $ivr->find(); + $result_count = count($result); + unset ($prep_statement, $sql); + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + + echo "
\n"; echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo th_order_by('ivr_menu_name', $text['label-name'], $order_by[0]['name'], $order_by[0]['order']); + echo th_order_by('ivr_menu_extension', $text['label-extension'], $order_by[0]['name'], $order_by[0]['order']); + echo th_order_by('ivr_menu_direct_dial', $text['label-direct_dial'], $order_by[0]['name'], $order_by[0]['order']); + echo th_order_by('ivr_menu_enabled', $text['label-enabled'], $order_by[0]['name'], $order_by[0]['order']); + echo th_order_by('ivr_menu_description', $text['label-description'], $order_by[0]['name'], $order_by[0]['order']); + echo "\n"; echo "\n"; + + if ($result_count > 0) { + foreach($result as $row) { + $ivr_menu_name = str_replace("-", " ", $row['ivr_menu_name']); + $tr_link = (permission_exists('ivr_menu_edit')) ? "href='ivr_menu_edit.php?id=".$row['ivr_menu_uuid']."'" : null; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + if (permission_exists('ivr_menu_add')) { + if ($_SESSION['limit']['ivr_menus']['numeric'] == '' || ($_SESSION['limit']['ivr_menus']['numeric'] != '' && $total_ivr_menus < $_SESSION['limit']['ivr_menus']['numeric'])) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + } echo "
".$text['header-ivr_menus']."
".$text['description-ivr_menus'].""; + if (permission_exists('ivr_menu_add')) { + if ($_SESSION['limit']['ivr_menus']['numeric'] == '' || ($_SESSION['limit']['ivr_menus']['numeric'] != '' && $total_ivr_menus < $_SESSION['limit']['ivr_menus']['numeric'])) { + echo "".$v_link_label_add.""; + } + } + echo "
"; + if (permission_exists('ivr_menu_edit')) { + echo "".$ivr_menu_name.""; + } + else { + echo $ivr_menu_name; + } + echo " ".$row['ivr_menu_extension']." ".ucwords($row['ivr_menu_direct_dial'])."".ucwords($row['ivr_menu_enabled'])."".$row['ivr_menu_description']." "; + if (permission_exists('ivr_menu_edit')) { + echo "$v_link_label_edit"; + } + if (permission_exists('ivr_menu_delete')) { + echo "$v_link_label_delete"; + } + echo "
 "; + echo "".$v_link_label_add.""; + echo "
\n"; - echo "
\n"; + echo "
"; - //get the count - require_once "resources/classes/database.php"; - require_once "resources/classes/ivr_menu.php"; - $ivr = new ivr_menu; - $ivr->domain_uuid = $_SESSION["domain_uuid"]; - $ivr->table = "v_ivr_menus"; - $where[0]['name'] = 'domain_uuid'; - $where[0]['value'] = $_SESSION["domain_uuid"]; - $where[0]['operator'] = '='; - $ivr->where = $where; - $num_rows = $ivr->count(); - - //use total ivr menu count from the database - $total_ivr_menus = $num_rows; - - //prepare to page the results - $rows_per_page = 150; - $param = ""; - if (!isset($_GET['page'])) { $_GET['page'] = 0; } - $_GET['page'] = check_str($_GET['page']); - list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); - $offset = $rows_per_page * $_GET['page']; - - //get the list from the db - if (isset($order_by)) { - if (count($order_by) > 0) { - $ivr->order_by = $order_by; - } - } - $result = $ivr->find(); - $result_count = count($result); - unset ($prep_statement, $sql); - - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; - - echo "\n"; - echo "\n"; - echo th_order_by('ivr_menu_name', $text['label-name'], $order_by[0]['name'], $order_by[0]['order']); - echo th_order_by('ivr_menu_extension', $text['label-extension'], $order_by[0]['name'], $order_by[0]['order']); - echo th_order_by('ivr_menu_direct_dial', $text['label-direct_dial'], $order_by[0]['name'], $order_by[0]['order']); - echo th_order_by('ivr_menu_enabled', $text['label-enabled'], $order_by[0]['name'], $order_by[0]['order']); - echo th_order_by('ivr_menu_description', $text['label-description'], $order_by[0]['name'], $order_by[0]['order']); - echo "\n"; - echo "\n"; - - if ($result_count > 0) { - foreach($result as $row) { - $ivr_menu_name = str_replace("-", " ", $row['ivr_menu_name']); - $tr_link = (permission_exists('ivr_menu_edit')) ? "href='ivr_menu_edit.php?id=".$row['ivr_menu_uuid']."'" : null; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $result, $row_count); - } //end if results - - echo "\n"; - echo "\n"; - echo "\n"; - - echo "
"; - if (permission_exists('ivr_menu_add')) { - if ($_SESSION['limit']['ivr_menus']['numeric'] == '' || ($_SESSION['limit']['ivr_menus']['numeric'] != '' && $total_ivr_menus < $_SESSION['limit']['ivr_menus']['numeric'])) { - echo "".$v_link_label_add.""; - } - } - echo "
"; - if (permission_exists('ivr_menu_edit')) { - echo "".$ivr_menu_name.""; - } - else { - echo $ivr_menu_name; - } - echo " ".$row['ivr_menu_extension']." ".ucwords($row['ivr_menu_direct_dial'])."".ucwords($row['ivr_menu_enabled'])."".$row['ivr_menu_description']." "; - if (permission_exists('ivr_menu_edit')) { - echo "$v_link_label_edit"; - } - if (permission_exists('ivr_menu_delete')) { - echo "$v_link_label_delete"; - } - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - if (permission_exists('ivr_menu_add')) { - if ($_SESSION['limit']['ivr_menus']['numeric'] == '' || ($_SESSION['limit']['ivr_menus']['numeric'] != '' && $total_ivr_menus < $_SESSION['limit']['ivr_menus']['numeric'])) { - echo "".$v_link_label_add.""; - } - } - echo "
\n"; - echo "
"; + echo "
".$paging_controls."
\n"; echo "

"; //show the footer diff --git a/app/recordings/app_languages.php b/app/recordings/app_languages.php index 1dba0fd31d..781e16e3aa 100644 --- a/app/recordings/app_languages.php +++ b/app/recordings/app_languages.php @@ -140,12 +140,12 @@ $text['header']['fr-fr'] = "Télécharger Enregistrement"; $text['header']['pt-br'] = "Carregadr gravações"; $text['header']['pl'] = "Wyślij nagranie"; -$text['description-recording']['en-us'] = "Recording Name. example: recording_x"; -$text['description-recording']['es-cl'] = "Nombre de la grabación. ejemplo: grabacion_x"; -$text['description-recording']['pt-pt'] = "Nome da gravação. exemplo: recording_x"; -$text['description-recording']['fr-fr'] = "Nom de l'enregistrement. exemple: enregistrement_x"; -$text['description-recording']['pt-br'] = "Nome da gravação: exemplo: recording_x"; -$text['description-recording']['pl'] = "Nazwa nagrania, przykład: nagranie_x"; +$text['description-recording']['en-us'] = "A name for the recording (not parsed)."; +$text['description-recording']['es-cl'] = "Nombre de la grabación."; +$text['description-recording']['pt-pt'] = "Nome da gravação."; +$text['description-recording']['fr-fr'] = "Nom de l'enregistrement (non parsé)."; +$text['description-recording']['pt-br'] = "Nome da gravação:"; +$text['description-recording']['pl'] = "Nazwa nagrania."; $text['description-file']['en-us'] = "Name of the file. example.wav"; $text['description-file']['es-cl'] = "Nombre del archivo. ejemplo.wav"; @@ -161,12 +161,12 @@ $text['description-description']['fr-fr'] = "Vous pouvez entrer ici une descript $text['description-description']['pt-br'] = "Insira a descrição, caso desejar"; $text['description-description']['pl'] = "Tutaj możesz wpisać opis w celach informacyjnych."; -$text['description']['en-us'] = "To make a recording dial *732 or you can make a 16bit 8khz/16khz Mono WAV file then copy it to the following directory then refresh the page to play it back. Click on the \'Filename\' to download it or the \'Recording Name\' to play the audio."; -$text['description']['es-cl'] = "Para realizar una grabación marque *732 o puede crear un archivo en formato WAV a 16 bit 8khz/16khz Mono y luego copiarlo en el siguiente directorio y refrezcar la página para reproducirlo. Click en el 'Nombre de archivo' para descargarlo o el 'Nombre de grabación' para reproducirlo."; -$text['description']['pt-pt'] = "Para fazer uma gravação marque *732 ou crie um ficheiro WAV de 16bit 8khz/16khz e copie-o para a seguinte directoria e actualize a página para o ouvir. Clique em \'Filename\' para descarregá-lo ou em \'Recording Name\' para ouvir o áudio."; +$text['description']['en-us'] = "Dial *732 to create a recording, or (for best results) upload a 16bit 8khz/16khz mono WAV file."; +$text['description']['es-cl'] = "Para realizar una grabación marque *732 o puede crear un archivo en formato WAV a 16 bit 8khz/16khz Mono y luego copiarlo en el siguiente directorio y refrezcar la página para reproducirlo."; +$text['description']['pt-pt'] = "Para fazer uma gravação marque *732 ou crie um ficheiro WAV de 16bit 8khz/16khz e copie-o para a seguinte directoria e actualize a página para o ouvir."; $text['description']['fr-fr'] = "Pour créer un guide vocal, composer le *732 ou créer un fichier audio WAV 16bit 8khz/16khz Mono et ensuite le copier dans le répertoire qui suit. Rafraîchir ensuite cette page pour le voir apparaitre."; $text['description']['pt-br'] = "Editar informações da conta."; -$text['description']['pl'] = "Aby stworzyć nagranie wybierz *732 z klawiatury telefonu lub stwórz plik audio w formacie WAV o następujących parametrach: 16bit 8khz/16khz Mono, a następnie skopiuj go do odpowiedniego katalogu i odśwież, aby go odsłuchać. Kliknij na \’Filename\’, aby pobrać plik lub na \’Recording Name\’, aby odsłuchać."; +$text['description']['pl'] = "Aby stworzyć nagranie wybierz *732 z klawiatury telefonu lub stwórz plik audio w formacie WAV o następujących parametrach: 16bit 8khz/16khz Mono, a następnie skopiuj go do odpowiedniego katalogu i odśwież, aby go odsłuchać."; $text['confirm-delete']['en-us'] = "Do you really want to delete this?"; $text['confirm-delete']['es-cl'] = "¿Realmente desea eliminar esto?"; diff --git a/app/recordings/recording_edit.php b/app/recordings/recording_edit.php index 78e3022943..e5d29ce62b 100644 --- a/app/recordings/recording_edit.php +++ b/app/recordings/recording_edit.php @@ -39,42 +39,32 @@ else { $language = new text; $text = $language->get(); -//set the action as an add or an update +//get recording id if (isset($_REQUEST["id"])) { - $action = "update"; $recording_uuid = check_str($_REQUEST["id"]); } - else { - $action = "add"; - } //get the form value and set to php variables - if (count($_POST)>0) { + if (count($_POST) > 0) { $recording_filename = check_str($_POST["recording_filename"]); + $recording_filename_original = check_str($_POST["recording_filename_original"]); $recording_name = check_str($_POST["recording_name"]); - //$recording_uuid = check_str($_POST["recording_uuid"]); $recording_description = check_str($_POST["recording_description"]); //clean the recording filename and name $recording_filename = str_replace(" ", "_", $recording_filename); $recording_filename = str_replace("'", "", $recording_filename); - $recording_name = str_replace(" ", "_", $recording_name); $recording_name = str_replace("'", "", $recording_name); } -if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { - - $msg = ''; - if ($action == "update") { +if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + //get recording uuid to edit $recording_uuid = check_str($_POST["recording_uuid"]); - } //check for all required data - //if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid
\n"; } + $msg = ''; if (strlen($recording_filename) == 0) { $msg .= $text['label-edit-file']."
\n"; } if (strlen($recording_name) == 0) { $msg .= $text['label-edit-recording']."
\n"; } - //if (strlen($recording_uuid) == 0) { $msg .= "Please provide: recording_uuid
\n"; } - //if (strlen($recording_description) == 0) { $msg .= "Please provide: Description
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; @@ -88,72 +78,29 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { return; } - //add or update the database + //update the database if ($_POST["persistformvar"] != "true") { - if ($action == "add" && permission_exists('recording_add')) { - $recording_uuid = uuid(); - $sql = "insert into v_recordings "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "recording_uuid, "; - $sql .= "recording_filename, "; - $sql .= "recording_name, "; - $sql .= "recording_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$recording_uuid', "; - $sql .= "'$recording_filename', "; - $sql .= "'$recording_name', "; - $sql .= "'$recording_description' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - - $_SESSION["message"] = $text['message-add']; - header("Location: recordings.php"); - return; - } //if ($action == "add") - - if ($action == "update" && permission_exists('recording_edit')) { - //get the original filename - $sql = "select * from v_recordings "; - $sql .= "where recording_uuid = '$recording_uuid' "; - $sql .= "and domain_uuid = '$domain_uuid' "; - //echo "sql: ".$sql."
\n"; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $recording_filename_orig = $row["recording_filename"]; - break; //limit to 1 row - } - unset ($prep_statement); - + if (permission_exists('recording_edit')) { //if file name is not the same then rename the file - if ($recording_filename != $recording_filename_orig) { - //echo "orig: ".$_SESSION['switch']['recordings']['dir'].'/'.$recording_filename_orig."
\n"; - //echo "new: ".$_SESSION['switch']['recordings']['dir'].'/'.$recording_filename."
\n"; - rename($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename_orig, $_SESSION['switch']['recordings']['dir'].'/'.$recording_filename); + if ($recording_filename != $recording_filename_original) { + rename($_SESSION['switch']['recordings']['dir'].'/'.$recording_filename_original, $_SESSION['switch']['recordings']['dir'].'/'.$recording_filename); } //update the database with the new data $sql = "update v_recordings set "; - $sql .= "domain_uuid = '$domain_uuid', "; - $sql .= "recording_filename = '$recording_filename', "; - $sql .= "recording_name = '$recording_name', "; - //$sql .= "recording_uuid = '$recording_uuid', "; - $sql .= "recording_description = '$recording_description' "; - $sql .= "where domain_uuid = '$domain_uuid'"; - $sql .= "and recording_uuid = '$recording_uuid'"; + $sql .= "domain_uuid = '".$domain_uuid."', "; + $sql .= "recording_filename = '".$recording_filename."', "; + $sql .= "recording_name = '".$recording_name."', "; + $sql .= "recording_description = '".$recording_description."' "; + $sql .= "where domain_uuid = '".$domain_uuid."'"; + $sql .= "and recording_uuid = '".$recording_uuid."'"; $db->exec(check_sql($sql)); unset($sql); $_SESSION["message"] = $text['message-update']; header("Location: recordings.php"); return; - } //if ($action == "update") + } //if (permission_exists('recording_edit')) { } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -161,16 +108,14 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $recording_uuid = $_GET["id"]; $sql = "select * from v_recordings "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and recording_uuid = '$recording_uuid' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and recording_uuid = '".$recording_uuid."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { - $domain_uuid = $row["domain_uuid"]; $recording_filename = $row["recording_filename"]; $recording_name = $row["recording_name"]; - //$recording_uuid = $row["recording_uuid"]; $recording_description = $row["recording_description"]; break; //limit to 1 row } @@ -178,30 +123,31 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } //show the header + $document['title'] = $text['title-edit']; require_once "resources/header.php"; //show the content echo "
\n"; - echo "\n"; + echo "
\n"; echo "\n"; - if ($action == "add") { - echo "\n"; - } - if ($action == "update") { - echo "\n"; - } - echo "\n"; echo "\n"; + echo "
".$text['title-add']."".$text['title-edit'].""; + echo ""; echo " "; echo " \n"; echo "
\n"; + + echo "".$text['title-edit']."\n"; + echo "

\n"; + + echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; echo "\n"; @@ -231,9 +178,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo " \n"; echo " \n"; @@ -242,7 +187,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "

"; echo ""; - //include the footer require_once "resources/footer.php"; ?> \ No newline at end of file diff --git a/app/recordings/recordings.php b/app/recordings/recordings.php index d051e5e60c..8f2bbbaa26 100644 --- a/app/recordings/recordings.php +++ b/app/recordings/recordings.php @@ -39,6 +39,12 @@ require_once "resources/check_auth.php"; $order_by = $_GET["order_by"]; $order = $_GET["order"]; +//define order by default + if ($order_by == '') { + $order_by = "recording_name"; + $order = "asc"; + } + //download the recordings if ($_GET['a'] == "download" && (permission_exists('recording_play') || permission_exists('recording_download'))) { session_cache_limiter('public'); @@ -99,13 +105,12 @@ require_once "resources/check_auth.php"; //upload the recording if (permission_exists('recording_upload')) { - if ($_POST['submit'] == "Upload" && $_POST['type'] == 'rec') { - if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) { - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_FILES['ulfile']['name']); - unset($_POST['txtCommand']); + if ($_POST['submit'] == $text['button-upload'] && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { + $recording_filename = str_replace(" ", "_", $_FILES['ulfile']['name']); + $recording_filename = str_replace("'", "", $recording_filename); + move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$recording_filename); - $_SESSION['message'] = $text['message-uploaded'].": ".htmlentities($_FILES['ulfile']['name']); - } + $_SESSION['message'] = $text['message-uploaded'].": ".htmlentities($recording_filename); header("Location: recordings.php"); exit; } @@ -150,7 +155,7 @@ require_once "resources/check_auth.php"; if (!in_array($file, $array_recordings)) { //file not found, add it to the database - $a_file = explode("\.", $file); + $a_file = explode('.', $file); $recording_uuid = uuid(); $sql = "insert into v_recordings "; $sql .= "("; @@ -214,29 +219,23 @@ require_once "resources/check_auth.php"; require_once "resources/header.php"; //begin the content - echo "
\n"; + echo "\n"; echo " ".$text['label-recording_name']."\n"; echo "\n"; + echo "\n"; echo " \n"; echo "
\n"; echo $text['description-recording']."\n"; @@ -214,6 +160,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "
\n"; echo " \n"; + echo " \n"; echo "
\n"; echo $text['message-file']."\n"; echo "
\n"; - if ($action == "update") { - echo " \n"; - } + echo " \n"; echo "
"; echo " \n"; echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['title'].""; - echo "

\n"; - echo " ".stripslashes($text['description'])."\n"; - echo "

\n"; - echo "
"; - echo "

\n"; - if (permission_exists('recording_upload')) { - echo "".$text['header'].""; - echo "

"; - echo "
\n"; - echo "\n"; - echo "".$text['label-upload']."\n"; - echo "\n"; - echo "\n"; - echo "
"; - echo "

\n"; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
"; + echo "
"; } + echo "".$text['title'].""; + echo "

\n"; + echo $text['description']."\n"; + echo "

\n"; $sql = "select * from v_recordings "; $sql .= "where domain_uuid = '".$domain_uuid."' "; @@ -248,7 +247,7 @@ require_once "resources/check_auth.php"; unset ($prep_statement, $result, $sql); $rows_per_page = 100; - $param = ""; + $param = "&order_by=".$order_by."&order=".$order; $page = $_GET['page']; if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); @@ -256,7 +255,7 @@ require_once "resources/check_auth.php"; $sql = "select * from v_recordings "; $sql .= "where domain_uuid = '".$domain_uuid."' "; - $sql .= "order by ".((strlen($order_by) > 0) ? $order_by." ".$order : "recording_name asc")." "; + $sql .= "order by ".$order_by." ".$order." "; $sql .= "limit ".$rows_per_page." offset ".$offset." "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); @@ -272,57 +271,54 @@ require_once "resources/check_auth.php"; echo "\n"; echo "\n"; echo th_order_by('recording_name', $text['label-recording_name'], $order_by, $order); - echo th_order_by('recording_filename', $text['label-file_name'], $order_by, $order); - echo "\n"; if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { + echo th_order_by('recording_filename', $text['label-file_name'], $order_by, $order); echo "\n"; } + echo "\n"; echo th_order_by('recording_description', $text['label-description'], $order_by, $order); echo "\n"; echo "\n"; + //calculate colspan for progress bar + $colspan = 5; //max + if ($_SESSION['recordings']['storage_type']['text'] == 'base64') { $colspan = $colspan - 2; } + if (!(permission_exists('recording_edit') || permission_exists('recording_delete'))) { $colspan = $colspan - 1; } + if ($result_count > 0) { foreach($result as $row) { - if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { - $tmp_filesize = filesize($_SESSION['switch']['recordings']['dir'].'/'.$row['recording_filename']); - $tmp_filesize = byte_convert($tmp_filesize); - } - //playback progress bar - echo "\n"; - + if (permission_exists('recording_play')) { + echo "\n"; + } $tr_link = (permission_exists('recording_edit')) ? "href='recording_edit.php?id=".$row['recording_uuid']."'" : null; echo "\n"; - echo " \n"; - echo " \n"; - if (strlen($row['recording_filename']) > 0) { - echo " \n"; + echo " \n"; if ($_SESSION['recordings']['storage_type']['text'] != 'base64') { + echo " \n"; + $tmp_filesize = filesize($_SESSION['switch']['recordings']['dir'].'/'.$row['recording_filename']); + $tmp_filesize = byte_convert($tmp_filesize); echo " \n"; } + if (permission_exists('recording_play') || permission_exists('recording_download')) { + echo " \n"; + } echo " \n"; echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } + $c = ($c) ? 0 : 1; } //end foreach unset($sql, $result, $row_count); } //end if results echo "
".$text['label-tools']."".$text['label-file-size']."".$text['label-tools']." 
"; - echo $row['recording_name']; - echo ""; - echo " \n"; - echo $row['recording_filename']; - echo " "; - echo " "; - echo " "; - } - echo " ".$row['recording_name']."".$row['recording_filename']."".$tmp_filesize."".$row['recording_description']." "; if (permission_exists('recording_edit')) { @@ -334,20 +330,14 @@ require_once "resources/check_auth.php"; echo "
\n"; + echo "
\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - echo "
\n"; + echo "
".$paging_controls."
\n"; echo "

\n"; //include the footer diff --git a/app/voicemail_greetings/app_config.php b/app/voicemail_greetings/app_config.php index e08f842a7a..02b2a1d0c3 100644 --- a/app/voicemail_greetings/app_config.php +++ b/app/voicemail_greetings/app_config.php @@ -103,6 +103,10 @@ $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'] = "greeting_filename"; + $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'] = "greeting_description"; $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; diff --git a/app/voicemail_greetings/app_defaults.php b/app/voicemail_greetings/app_defaults.php new file mode 100644 index 0000000000..7db79cb0ae --- /dev/null +++ b/app/voicemail_greetings/app_defaults.php @@ -0,0 +1,123 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +if ($domains_processed == 1) { + //if greeting filename field empty, copy greeting name field value + $sql = "update v_voicemail_greetings "; + $sql .= "set greeting_filename = greeting_name "; + $sql .= "where greeting_filename is null "; + $sql .= "or greeting_filename = '' "; + $db->exec(check_sql($sql)); + unset($sql); + + //populate greeting id number if empty + $sql = "select voicemail_greeting_uuid, greeting_filename "; + $sql .= "from v_voicemail_greetings "; + $sql .= "where greeting_id is null "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; + $greeting_id = preg_replace('{\D}', '', $row['greeting_filename']); + $sqlu = "update v_voicemail_greetings "; + $sqlu .= "set greeting_id = ".$greeting_id." "; + $sqlu .= "where voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; + $db->exec(check_sql($sqlu)); + unset($sqlu, $voicemail_greeting_uuid, $greeting_id); + } + unset ($sql, $prep_statement); + + //if base64, populate from existing greeting files, then remove + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + //get greetings without base64 in db + $sql = "select voicemail_greeting_uuid, domain_uuid, voicemail_id, greeting_filename "; + $sql .= "from v_voicemail_greetings where greeting_base64 is null or greeting_base64 = '' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + if (count($result) > 0) { + foreach ($result as &$row) { + $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; + $greeting_domain_uuid = $row['domain_uuid']; + $voicemail_id = $row['voicemail_id']; + $greeting_filename = $row['greeting_filename']; + //set greeting directory + $greeting_directory = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$greeting_domain_uuid]['domain_name'].'/'.$voicemail_id; + //encode greeting file (if exists) + if (file_exists($greeting_directory.'/'.$greeting_filename)) { + $greeting_base64 = base64_encode(file_get_contents($greeting_directory.'/'.$greeting_filename)); + //update greeting record with base64 + $sql = "update v_voicemail_greetings set "; + $sql .= "greeting_base64 = '".$greeting_base64."' "; + $sql .= "where domain_uuid = '".$greeting_domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + //remove local greeting file + @unlink($greeting_directory.'/'.$greeting_filename); + } + } + } + unset($sql, $prep_statement, $result, $row); + } + //if not base64, decode to local files, remove base64 data from db + else if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') { + //get greetings with base64 in db + $sql = "select voicemail_greeting_uuid, domain_uuid, voicemail_id, greeting_filename, greeting_base64 "; + $sql .= "from v_voicemail_greetings where greeting_base64 is not null "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + if (count($result) > 0) { + foreach ($result as &$row) { + $voicemail_greeting_uuid = $row['voicemail_greeting_uuid']; + $greeting_domain_uuid = $row['domain_uuid']; + $voicemail_id = $row['voicemail_id']; + $greeting_filename = $row['greeting_filename']; + $greeting_base64 = $row['greeting_base64']; + //set greeting directory + $greeting_directory = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$greeting_domain_uuid]['domain_name'].'/'.$voicemail_id; + //remove local file, if any + if (file_exists($greeting_directory.'/'.$greeting_filename)) { + @unlink($greeting_directory.'/'.$greeting_filename); + } + //decode base64, save to local file + $greeting_decoded = base64_decode($greeting_base64); + file_put_contents($greeting_directory.'/'.$greeting_filename, $greeting_decoded); + $sql = "update v_voicemail_greetings "; + $sql .= "set greeting_base64 = null "; + $sql .= "where domain_uuid = '".$greeting_domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + } + } + unset($sql, $prep_statement, $result, $row); + } +} + +?> \ No newline at end of file diff --git a/app/voicemail_greetings/app_languages.php b/app/voicemail_greetings/app_languages.php index 65f853a7f4..623e38366f 100644 --- a/app/voicemail_greetings/app_languages.php +++ b/app/voicemail_greetings/app_languages.php @@ -11,12 +11,24 @@ $text['table-size']['pt-pt'] = "Tamanho"; $text['table-size']['fr-fr'] = "Taille"; $text['table-size']['pt-br'] = "Tamanho"; +$text['table-number']['en-us'] = "#"; +$text['table-number']['es-cl'] = "Número"; +$text['table-number']['pt-pt'] = "Número"; +$text['table-number']['fr-fr'] = "Nombre"; +$text['table-number']['pt-br'] = "Número"; + $text['table-name']['en-us'] = "Name"; $text['table-name']['es-cl'] = "Nombre"; $text['table-name']['pt-pt'] = "Nome"; $text['table-name']['fr-fr'] = "Nom"; $text['table-name']['pt-br'] = "Nome"; +$text['table-filename']['en-us'] = "File Name"; +$text['table-filename']['es-cl'] = "Nombre Del Archivo"; +$text['table-filename']['pt-pt'] = "Nome Do Arquivo"; +$text['table-filename']['fr-fr'] = "Nom de fichier"; +$text['table-filename']['pt-br'] = "Nome Do Arquivo"; + $text['table-download']['en-us'] = "Download"; $text['table-download']['es-cl'] = "Descargar"; $text['table-download']['pt-pt'] = "Descarregar"; @@ -47,6 +59,12 @@ $text['message-update']['pt-pt'] = "Actualização Efectuada"; $text['message-update']['fr-fr'] = "Mis à jour"; $text['message-update']['pt-br'] = "Atualização Efetuada"; +$text['message-greeting_selected']['en-us'] = "Greeting Selected"; +$text['message-greeting_selected']['es-cl'] = "Saludo Seleccionado"; +$text['message-greeting_selected']['pt-pt'] = "Saudação Selecionada"; +$text['message-greeting_selected']['fr-fr'] = "Message d'accueil Sélectionné"; +$text['message-greeting_selected']['pt-br'] = "Saudação Selecionada"; + $text['message-delete']['en-us'] = "Delete Complete"; $text['message-delete']['es-cl'] = "Eliminación Completada"; $text['message-delete']['pt-pt'] = "Remoção Efectuada"; @@ -83,6 +101,18 @@ $text['label-name']['pt-pt'] = "Nome da Saudação"; $text['label-name']['fr-fr'] = "Nom de salutation"; $text['label-name']['pt-br'] = "Nome"; +$text['label-greeting']['en-us'] = "Greeting"; +$text['label-greeting']['es-cl'] = "Saludo"; +$text['label-greeting']['pt-pt'] = "Saudação"; +$text['label-greeting']['fr-fr'] = "Salutation"; +$text['label-greeting']['pt-br'] = "Saudação"; + +$text['label-filename']['en-us'] = "File Name"; +$text['label-filename']['es-cl'] = "Nombre Del Archivo"; +$text['label-filename']['pt-pt'] = "Nome Do Arquivo"; +$text['label-filename']['fr-fr'] = "Nom de fichier"; +$text['label-filename']['pt-br'] = "Nome Do Arquivo"; + $text['label-edit']['en-us'] = "Edit Greeting"; $text['label-edit']['es-cl'] = "Edición de Saludo"; $text['label-edit']['pt-pt'] = "Editar Saudação"; @@ -107,10 +137,10 @@ $text['label-add']['pt-pt'] = "Adicionar Saudação"; $text['label-add']['fr-fr'] = "Ajouter salutation"; $text['label-add']['pt-br'] = "Adicionar Greeting"; -$text['description-name']['en-us'] = "Greeting Name. example: greeting_x"; -$text['description-name']['es-cl'] = "Nombre de Bienvenida. Ejemplo: bienvenida_x"; -$text['description-name']['pt-pt'] = "Nome da Saudação. exemplo: saudação_x"; -$text['description-name']['fr-fr'] = "Nome da Salutation. exemple: accueil_x"; +$text['description-name']['en-us'] = "A name for the greeting (not parsed)."; +$text['description-name']['es-cl'] = "Nombre de Bienvenida."; +$text['description-name']['pt-pt'] = "Nome da Saudação."; +$text['description-name']['fr-fr'] = "Nome da Salutation (non parsé)."; $text['description-name']['pt-br'] = "Insira o nome do menu"; $text['description-info']['en-us'] = "You may enter a description here for your reference (not parsed)."; @@ -125,12 +155,18 @@ $text['description']['pt-pt'] = "Escolha e active uma mensagem de saudação a a $text['description']['fr-fr'] = "Choisir le message de salutation à jouer pour l'extension:"; $text['description']['pt-br'] = "Editar informações da conta."; -$text['confirm-name']['en-us'] = "Please provide: Greeting Name (play)"; -$text['confirm-name']['es-cl'] = "Por favor indique: Nombre de Bienvenida (reproducir)"; -$text['confirm-name']['pt-pt'] = "Por favor indique: Nome da saudação (tocar)"; -$text['confirm-name']['fr-fr'] = "Merci d'indiquer: Nom de salutation (jouer)"; +$text['confirm-name']['en-us'] = "Please provide: Greeting Name"; +$text['confirm-name']['es-cl'] = "Por favor indique: Nombre de Bienvenida"; +$text['confirm-name']['pt-pt'] = "Por favor indique: Nome da saudação"; +$text['confirm-name']['fr-fr'] = "Merci d'indiquer: Nom de salutation"; $text['confirm-name']['pt-br'] = "Por favor indique: Nome"; +$text['confirm-filename']['en-us'] = "Please provide: Greeting Filename"; +$text['confirm-filename']['es-cl'] = "Por favor indique: Nombre Del Archivo"; +$text['confirm-filename']['pt-pt'] = "Por favor indique: Nome Do Arquivo"; +$text['confirm-filename']['fr-fr'] = "Merci d'indiquer: Nom De Fichier"; +$text['confirm-filename']['pt-br'] = "Por favor indique: Nome Do Arquivo"; + $text['button-upload']['en-us'] = "Upload"; $text['button-upload']['es-cl'] = "Subir"; $text['button-upload']['pt-pt'] = "Carregar"; diff --git a/app/voicemail_greetings/voicemail_greeting_delete.php b/app/voicemail_greetings/voicemail_greeting_delete.php index 20e206f5e8..a5cbe320de 100644 --- a/app/voicemail_greetings/voicemail_greeting_delete.php +++ b/app/voicemail_greetings/voicemail_greeting_delete.php @@ -38,31 +38,31 @@ else { $language = new text; $text = $language->get(); -if (count($_GET)>0) { - $id = check_str($_GET["id"]); +if (count($_GET) > 0) { + $voicemail_greeting_uuid = check_str($_GET["id"]); $voicemail_id = check_str($_GET["voicemail_id"]); } -if (strlen($id)>0) { +if (strlen($voicemail_greeting_uuid) > 0) { //get the greeting filename - $sql = "select * from v_voicemail_greetings "; - $sql .= "where voicemail_greeting_uuid = '$id' "; - $sql .= "and domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; + $sql = "select greeting_filename from v_voicemail_greetings "; + $sql .= "where voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; + $sql .= "and domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { - $greeting_name = $row["greeting_name"]; + $greeting_filename = $row["greeting_filename"]; break; //limit to 1 row } unset ($prep_statement); //delete recording from the database $sql = "delete from v_voicemail_greetings "; - $sql .= "where voicemail_greeting_uuid = '$id' "; - $sql .= "and domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; + $sql .= "where voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; + $sql .= "and domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); unset($sql); @@ -71,7 +71,9 @@ if (strlen($id)>0) { $v_greeting_dir = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id; //delete the recording file - unlink($v_greeting_dir."/".$greeting_name); + if (file_exists($v_greeting_dir."/".$greeting_filename)) { + @unlink($v_greeting_dir."/".$greeting_filename); + } } //redirect the user diff --git a/app/voicemail_greetings/voicemail_greeting_edit.php b/app/voicemail_greetings/voicemail_greeting_edit.php index dffa08835a..033db6cc0e 100644 --- a/app/voicemail_greetings/voicemail_greeting_edit.php +++ b/app/voicemail_greetings/voicemail_greeting_edit.php @@ -26,7 +26,7 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; -if (permission_exists('voicemail_greeting_add') || permission_exists('voicemail_greeting_edit')) { +if (permission_exists('voicemail_greeting_edit')) { //access granted } else { @@ -38,14 +38,10 @@ else { $language = new text; $text = $language->get(); -//set the action as an add or an update +//get greeting id if (isset($_REQUEST["id"])) { - $action = "update"; $voicemail_greeting_uuid = check_str($_REQUEST["id"]); } - else { - $action = "add"; - } //get the form value and set to php variables $voicemail_id = check_str($_REQUEST["voicemail_id"]); @@ -53,22 +49,17 @@ else { $greeting_name = check_str($_POST["greeting_name"]); $greeting_description = check_str($_POST["greeting_description"]); - //clean the filename and recording name - $greeting_name = str_replace(" ", "_", $greeting_name); + //clean the name $greeting_name = str_replace("'", "", $greeting_name); } -if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { - - $msg = ''; - if ($action == "update") { +if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + //get greeting uuid to edit $voicemail_greeting_uuid = check_str($_POST["voicemail_greeting_uuid"]); - } //check for all required data - //if (strlen($domain_uuid) == 0) { $msg .= "Please provide: domain_uuid
\n"; } + $msg = ''; if (strlen($greeting_name) == 0) { $msg .= "".$text['confirm-name']."
\n"; } - //if (strlen($greeting_description) == 0) { $msg .= "Please provide: Description
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; @@ -82,59 +73,15 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { return; } - //add or update the database + //update the database if ($_POST["persistformvar"] != "true") { - if ($action == "add" && permission_exists('voicemail_greeting_add')) { - $voicemail_greeting_uuid = uuid(); - $sql = "insert into v_voicemail_greetings "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "voicemail_greeting_uuid, "; - $sql .= "greeting_name, "; - $sql .= "greeting_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$voicemail_greeting_uuid', "; - $sql .= "'$greeting_name', "; - $sql .= "'$greeting_description' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); - - $_SESSION["message"] = $text['message-add']; - header("Location: voicemail_greetings.php?id=".$voicemail_id); - return; - } //if ($action == "add") - - if ($action == "update" && permission_exists('voicemail_greeting_edit')) { - //get the original filename - $sql = "select * from v_voicemail_greetings "; - $sql .= "where voicemail_greeting_uuid = '$voicemail_greeting_uuid' "; - $sql .= "and voicemail_greeting_uuid = '$domain_uuid' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $greeting_name_orig = $row["greeting_name"]; - break; //limit to 1 row - } - unset ($prep_statement); - - //if file name is not the same then rename the file - if ($greeting_name != $greeting_name_orig) { - //echo "orig: ".$voicemail_greetings_dir.'/'.$filename_orig."
\n"; - //echo "new: ".$voicemail_greetings_dir.'/'.$greeting_name."
\n"; - rename($voicemail_greetings_dir.'/'.$greeting_name_orig, $voicemail_greetings_dir.'/'.$greeting_name); - } - + if (permission_exists('voicemail_greeting_edit')) { //update the database with the new data $sql = "update v_voicemail_greetings set "; - $sql .= "greeting_name = '$greeting_name', "; - $sql .= "greeting_description = '$greeting_description' "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_greeting_uuid = '$voicemail_greeting_uuid' "; + $sql .= "greeting_name = '".$greeting_name."', "; + $sql .= "greeting_description = '".$greeting_description."' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; $db->exec(check_sql($sql)); unset($sql); @@ -142,7 +89,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $_SESSION["message"] = $text['message-update']; header("Location: voicemail_greetings.php?id=".$voicemail_id); return; - } //if ($action == "update") + } //if (permission_exists('voicemail_greeting_edit')) { } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -150,8 +97,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $voicemail_greeting_uuid = check_str($_GET["id"]); $sql = "select * from v_voicemail_greetings "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_greeting_uuid = '$voicemail_greeting_uuid' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); @@ -164,30 +111,30 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { } //show the header + $document['title'] = $text['label-edit']; require_once "resources/header.php"; //show the content echo "
\n"; - echo "\n"; + echo "
\n"; echo "\n"; - if ($action == "add") { - echo "\n"; - } - if ($action == "update") { - echo "\n"; - } - echo "\n"; echo "\n"; + echo "
".$text['label-add']."".$text['label-edit']."\n"; + echo "\n"; echo " "; echo " \n"; echo "
\n"; + echo "".$text['label-edit']."\n"; + echo "

\n"; + + echo "\n"; echo "\n"; - echo "\n"; - echo "\n"; echo " \n"; echo " \n"; echo " "; echo "
\n"; + echo "\n"; echo " ".$text['label-name']."\n"; echo "\n"; + echo "\n"; echo " \n"; echo "
\n"; echo "".$text['description-name']."\n"; @@ -206,16 +153,15 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "
\n"; - if ($action == "update") { - echo " \n"; - } - echo " \n"; + echo " \n"; + echo " \n"; echo "
"; echo " \n"; echo "
"; echo "

"; + echo "
"; //include the footer diff --git a/app/voicemail_greetings/voicemail_greetings.php b/app/voicemail_greetings/voicemail_greetings.php index 72d20182a5..623a832287 100644 --- a/app/voicemail_greetings/voicemail_greetings.php +++ b/app/voicemail_greetings/voicemail_greetings.php @@ -26,21 +26,11 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; -if (permission_exists('voicemail_greeting_view')) { - //access granted -} -else { - echo "access denied"; - exit; -} //add multi-lingual support $language = new text; $text = $language->get(); -//additional includes - require_once "resources/paging.php"; - //set the max php execution time ini_set(max_execution_time,7200); @@ -49,7 +39,21 @@ else { $order_by = check_str($_GET["order_by"]); $order = check_str($_GET["order"]); -//used to search the array to determin if an extension is assigned to the user +//define order by default + if ($order_by == '') { + $order_by = "greeting_name"; + $order = "asc"; + } + +//deny access if the user extension is not assigned + if (!(if_group("superadmin") || if_group("admin"))) { + if (!is_extension_assigned($voicemail_id)) { + echo "access denied"; + return; + } + } + +//used (above) to search the array to determine if an extension is assigned to the user function is_extension_assigned($number) { $result = false; foreach ($_SESSION['user']['extension'] as $row) { @@ -60,48 +64,131 @@ else { return $result; } -//allow admins, superadmins and users that are assigned to the extension to view the page - if (if_group("superadmin") || if_group("admin")) { +//get currently selected greeting + $sql = "select greeting_id from v_voicemails "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; + $prep_statement = $db->prepare(check_sql($sql)); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + $selected_greeting_id = $row['greeting_id']; + } + unset($prep_statement, $row); + +//define greeting directory + $v_greeting_dir = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id; + +//download the greeting + if ($_GET['a'] == "download" && (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download'))) { + session_cache_limiter('public'); + if ($_GET['type'] = "rec") { + $voicemail_greeting_uuid = check_str($_GET['uuid']); + //get voicemail greeting details from db + $sql = "select greeting_filename, greeting_base64, greeting_id from v_voicemail_greetings "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$voicemail_greeting_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + if (count($result) > 0) { + foreach($result as &$row) { + $greeting_filename = $row['greeting_filename']; + $greeting_id = $row['greeting_id']; + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64' && $row['greeting_base64'] != '') { + $greeting_decoded = base64_decode($row['greeting_base64']); + file_put_contents($v_greeting_dir.'/'.$greeting_filename, $greeting_decoded); + } + break; + } + } + unset ($sql, $prep_statement, $result, $greeting_decoded); + + if (file_exists($v_greeting_dir.'/'.$greeting_filename)) { + $fd = fopen($v_greeting_dir.'/'.$greeting_filename, "rb"); + if ($_GET['t'] == "bin") { + header("Content-Type: application/force-download"); + header("Content-Type: application/octet-stream"); + header("Content-Type: application/download"); + header("Content-Description: File Transfer"); + } + else { + $file_ext = substr($greeting_filename, -3); + if ($file_ext == "wav") { + header("Content-Type: audio/x-wav"); + } + if ($file_ext == "mp3") { + header("Content-Type: audio/mpeg"); + } + } + header('Content-Disposition: attachment; filename="'.$greeting_filename.'"'); + header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past + header("Content-Length: " . filesize($v_greeting_dir.'/'.$greeting_filename)); + ob_clean(); + fpassthru($fd); + } + + //if base64, remove temp greeting file (if not currently selected greeting) + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64' && $row['greeting_base64'] != '') { + if ($greeting_id != $selected_greeting_id) { + @unlink($v_greeting_dir.'/'.$greeting_filename); + } + } + } + exit; + } + +//upload the greeting + if (permission_exists('voicemail_greeting_upload')) { + if ($_POST['submit'] == $text['button-upload'] && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['file']['tmp_name'])) { + //find the next available + for ($i = 1; $i < 10; $i++) { + $file_name = 'greeting_'.$i.'.wav'; + //check the database + $sql = "select voicemail_greeting_uuid from v_voicemail_greetings "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; + $sql .= "and greeting_filename = '".$file_name."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + if (count($result) == 0 && !file_exists($v_greeting_dir.'/'.$file_name)) { + //move the uploaded greeting + mkdir($v_greeting_dir, 0777, true); + move_uploaded_file($_FILES['file']['tmp_name'], $v_greeting_dir.'/'.$file_name); + //set newly uploaded greeting as active greeting for voicemail box + $sql = "update v_voicemails "; + $sql .= "set greeting_id = '".$i."' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + unset($prep_statement); + + $_SESSION["message"] = $text['message-uploaded'].": ".$_FILES['file']['name']; + break; + } + else { + continue; + } + unset ($prep_statement); + } + + //set the file name to be inserted as the greeting description + $greeting_description = base64_encode($_FILES['file']['name']); + header("Location: voicemail_greetings.php?id=".$voicemail_id."&order_by=".$order_by."&order=".$order."&gd=".$greeting_description); + exit; + } + } + +//check the permission + if (permission_exists('voicemail_greeting_view')) { //access granted } else { - //deny access if the user extension is not assigned - if (!is_extension_assigned($voicemail_id)) { - echo "access denied"; - return; - } - } - -//set the greeting directory - $v_greeting_dir = $_SESSION['switch']['storage']['dir'].'/voicemail/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id; - -//upload the recording - if (($_POST['submit'] == $text['button-upload']) && is_uploaded_file($_FILES['file']['tmp_name']) && permission_exists('voicemail_greeting_upload')) { - if ($_POST['type'] == 'rec') { - //find the next available - for($i = 1; $i < 10; $i++){ - $file_name = 'greeting_'.$i.'.wav'; - if (!file_exists($v_greeting_dir.'/'.$file_name)) { - $greeting_id = $i; - $_REQUEST['greeting'] = $file_name; - break; - } - } - //move the uploaded greeting - if ($_REQUEST['greeting']) { - mkdir($v_greeting_dir, 0777, true); - move_uploaded_file($_FILES['file']['tmp_name'], $v_greeting_dir.'/'.$_REQUEST['greeting']); - $_SESSION["message"] = $text['message-uploaded'].": ".$_REQUEST['greeting']; - } - //set the greeting_id - $sql = "update v_voicemails "; - $sql .= "set greeting_id = '$greeting_id' "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - unset($prep_statement); - } + echo "access denied"; + exit; } //set the greeting @@ -111,112 +198,116 @@ else { //set the greeting_id $sql = "update v_voicemails "; - $sql .= "set greeting_id = '$greeting_id' "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; + $sql .= "set greeting_id = '".$greeting_id."' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); unset($prep_statement); - } -//download the voicemail greeting - if ($_GET['a'] == "download") { // && permission_exists('voicemail_greeting_download')) { - session_cache_limiter('public'); - if ($_GET['type'] = "rec") { - if (file_exists($v_greeting_dir.'/'.base64_decode($_GET['filename']))) { - $fd = fopen($v_greeting_dir.'/'.base64_decode($_GET['filename']), "rb"); - if ($_GET['t'] == "bin") { - header("Content-Type: application/force-download"); - header("Content-Type: application/octet-stream"); - header("Content-Type: application/download"); - header("Content-Description: File Transfer"); - header('Content-Disposition: attachment; filename="'.base64_decode($_GET['filename']).'"'); - } - else { - $file_ext = substr(base64_decode($_GET['filename']), -3); - if ($file_ext == "wav") { - header("Content-Type: audio/x-wav"); - } - if ($file_ext == "mp3") { - header("Content-Type: audio/mp3"); - } - } - header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past - header("Content-Length: " . filesize($v_greeting_dir.'/'.base64_decode($_GET['filename']))); - fpassthru($fd); - } - } + $_SESSION["message"] = $text['message-greeting_selected']; + header("Location: voicemail_greetings.php?id=".$voicemail_id."&order_by=".$order_by."&order=".$order); exit; } -//build a list of voicemail greetings - $config_voicemail_greeting_list = '|'; - $i = 0; - $sql = "select * from v_voicemail_greetings "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; +//get existing greetings + $sql = "select voicemail_greeting_uuid, greeting_filename, greeting_base64 from v_voicemail_greetings "; + $sql .= "where domain_uuid = '".$domain_uuid."' and voicemail_id = '".$voicemail_id."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - $config_greeting_list = "|"; foreach ($result as &$row) { - $config_greeting_list .= $row['greeting_name']."|"; + $array_greetings[$row['voicemail_greeting_uuid']] = $row['greeting_filename']; + $array_base64_exists[$row['voicemail_greeting_uuid']] = ($row['greeting_base64'] != '') ? true : false; + //if not base64, convert back to local files and remove base64 from db + if ($_SESSION['voicemail']['storage_type']['text'] != 'base64' && $row['greeting_base64'] != '') { + if (file_exists($v_greeting_dir.'/'.$row['greeting_filename'])) { + @unlink($v_greeting_dir.'/'.$row['greeting_filename']); + } + $greeting_decoded = base64_decode($row['greeting_base64']); + file_put_contents($v_greeting_dir.'/'.$row['greeting_filename'], $greeting_decoded); + $sql = "update v_voicemail_greetings "; + $sql .= "set greeting_base64 = null "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$row['voicemail_greeting_uuid']."' "; + $db->exec(check_sql($sql)); + unset($sql); + } } unset ($prep_statement); -//add recordings to the database +//add greetings to the database if (is_dir($v_greeting_dir.'/')) { if ($dh = opendir($v_greeting_dir.'/')) { while (($file = readdir($dh)) !== false) { - if (filetype($v_greeting_dir."/".$file) == "file") { - if (strpos($config_greeting_list, "|".$file) === false) { - if (substr($file, 0, 8) == "greeting") { - //file not found add it to the database - $a_file = explode("\.", $file); - $voicemail_greeting_uuid = uuid(); - $sql = "insert into v_voicemail_greetings "; - $sql .= "("; - $sql .= "domain_uuid, "; - $sql .= "voicemail_greeting_uuid, "; - $sql .= "voicemail_id, "; - $sql .= "greeting_name, "; - $sql .= "greeting_description "; - $sql .= ")"; - $sql .= "values "; - $sql .= "("; - $sql .= "'$domain_uuid', "; - $sql .= "'$voicemail_greeting_uuid', "; - $sql .= "'$voicemail_id', "; - $sql .= "'".$a_file[0]."', "; - $sql .= "'' "; - $sql .= ")"; - $db->exec(check_sql($sql)); - unset($sql); + if (filetype($v_greeting_dir."/".$file) == "file" && substr($file, 0, 8) == "greeting" && substr($file, 10, 4) != ".tmp") { + $greeting_number = preg_replace('{\D}', '', $file); + if (!in_array($file, $array_greetings)) { + //file not found, add to database + $greeting_name = $text['label-greeting'].' '.$greeting_number; + $greeting_description = base64_decode($_GET['gd']); + $voicemail_greeting_uuid = uuid(); + $sql = "insert into v_voicemail_greetings "; + $sql .= "( "; + $sql .= "voicemail_greeting_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "voicemail_id, "; + $sql .= "greeting_name, "; + $sql .= "greeting_filename, "; + $sql .= "greeting_description, "; + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + $sql .= "greeting_base64, "; } + $sql .= "greeting_id "; + $sql .= ") "; + $sql .= "values "; + $sql .= "("; + $sql .= "'".$voicemail_greeting_uuid."', "; + $sql .= "'".$domain_uuid."', "; + $sql .= "'".$voicemail_id."', "; + $sql .= "'".$greeting_name."', "; + $sql .= "'".$file."', "; + $sql .= "'".$greeting_description."', "; + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + $greeting_base64 = base64_encode(file_get_contents($v_greeting_dir.'/'.$file)); + $sql .= "'".$greeting_base64."', "; + } + $sql .= $greeting_number." "; + $sql .= ")"; + $db->exec(check_sql($sql)); + unset($sql); } else { - //echo "The $file was found.
"; + //file found, check if base64 present + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { + $found_greeting_uuid = array_search($file, $array_greetings); + if (!$array_base64_exists[$found_greeting_uuid]) { + $greeting_base64 = base64_encode(file_get_contents($v_greeting_dir.'/'.$file)); + $sql = "update v_voicemail_greetings set "; + $sql .= "greeting_base64 = '".$greeting_base64."' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_greeting_uuid = '".$found_greeting_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + } + } + } + + //if base64, remove local file (unless currently selected greeting) + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64' && file_exists($v_greeting_dir.'/'.$file)) { + if ($greeting_number != $selected_greeting_id) { + @unlink($v_greeting_dir.'/'.$file); + } } } - } + } //while closedir($dh); - } - } + } //if + } //if -//get the number of rows in v_extensions - $sql = "select greeting_id from v_voicemails "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - $greeting_id = $row['greeting_id']; - } - unset($prep_statement, $result); //include the header + $document['title'] = $text['title']; require_once "resources/header.php"; //begin the content @@ -227,60 +318,31 @@ else { echo "}\n"; echo ""; - echo "
\n"; - echo "\n"; + echo "\n"; + echo "
\n"; echo " \n"; echo " "; - if (permission_exists('voicemail_greeting_upload')) { - echo " \n"; + echo " \n"; } - echo " "; echo "
\n"; echo " ".$text['title']."\n"; echo "

\n"; echo " ".$text['description']." ".$voicemail_id."\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"; - //get the number of rows in v_voicemail_greetings - $sql = "select count(*) as num_rows from v_voicemail_greetings "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] > 0) { - $num_rows = $row['num_rows']; - } - else { - $num_rows = '0'; - } - } - unset($prep_statement, $result); - - //prepare to page the results - $rows_per_page = 100; - $param = ""; - $page = $_GET['page']; - if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } - list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); - $offset = $rows_per_page * $page; - //get the greetings list $sql = "select * from v_voicemail_greetings "; - $sql .= "where domain_uuid = '$domain_uuid' "; - $sql .= "and voicemail_id = '$voicemail_id' "; - if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } - $sql .= " limit $rows_per_page offset $offset "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and voicemail_id = '".$voicemail_id."' "; + $sql .= "order by ".$order_by." ".$order." "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); @@ -294,62 +356,66 @@ else { echo "\n"; echo "\n"; - echo "\n"; - echo th_order_by('greeting_name', $text['table-name'], $order_by, $order); - if (permission_exists('voicemail_greeting_download')) { + echo "\n"; + echo th_order_by('greeting_id', $text['table-number'], $order_by, $order, '', "width='20'", "id=".$voicemail_id); + echo th_order_by('greeting_name', $text['table-name'], $order_by, $order, '', '', "id=".$voicemail_id); + if ($_SESSION['voicemail']['storage_type']['text'] != 'base64') { + echo th_order_by('greeting_filename', $text['table-filename'], $order_by, $order, '', '', "id=".$voicemail_id); + echo "\n"; + } + if (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download')) { echo "\n"; } - echo "\n"; - echo th_order_by('greeting_description', $text['table-description'], $order_by, $order); + echo th_order_by('greeting_description', $text['table-description'], $order_by, $order, '', '', "id=".$voicemail_id); echo "\n"; echo "\n"; + //calculate colspan for progress bar + $colspan = 7; //max + if ($_SESSION['voicemail']['storage_type']['text'] == 'base64') { $colspan = $colspan - 2; } + if (!(permission_exists('voicemail_greeting_edit') || permission_exists('voicemail_greeting_delete'))) { $colspan = $colspan - 1; } + if ($result_count > 0) { foreach($result as $row) { - $tmp_filesize = filesize($v_greeting_dir.'/'.$row['greeting_name']); - $tmp_filesize = byte_convert($tmp_filesize); - //playback progress bar - echo "\n"; - + if (permission_exists('voicemail_greeting_play')) { + echo "\n"; + } $tr_link = (permission_exists('voicemail_greeting_edit')) ? "href='voicemail_greeting_edit.php?id=".$row['voicemail_greeting_uuid']."&voicemail_id=".$voicemail_id."'" : null; echo "\n"; - echo " \n"; + echo " \n"; echo " \n"; - if (permission_exists('voicemail_greeting_download')) { - if (strlen($row['greeting_name']) > 0) { - echo " \n"; + $tmp_filesize = filesize($v_greeting_dir.'/'.$row['greeting_filename']); + $tmp_filesize = byte_convert($tmp_filesize); + echo " \n"; + } + if (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download')) { + echo " \n"; } - echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } + $c = ($c) ? 0 : 1; } //end foreach unset($sql, $result, $row_count); } //end if results echo "
".$text['table-choose']." ".$text['table-size']."".$text['label-tools']."".$text['table-size']."\n"; - //if (permission_exists('voicemail_greeting_add')) { - // echo " $v_link_label_add\n"; - //} echo "
".$row['greeting_id']."".$row['greeting_name']."".$row['greeting_filename']."".$tmp_filesize.""; - echo " "; + if (permission_exists('voicemail_greeting_download')) { + echo "".$v_link_label_download.""; } echo " ".$tmp_filesize."".$row['greeting_description']." ".$row['greeting_description']." \n"; if (permission_exists('voicemail_greeting_edit')) { echo "$v_link_label_edit"; @@ -360,25 +426,18 @@ else { echo "
\n"; - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls 
\n"; - echo "

"; + echo "
\n"; echo "\n"; echo "
"; + echo "

"; + //include the footer require_once "resources/footer.php"; - ?> \ No newline at end of file diff --git a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua index 28bf9c73ab..f8611c398a 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua @@ -87,29 +87,27 @@ --get the greeting from the database if (storage_type == "base64") then - if (string.len(ivr_menu_greet_long) > 1) then - sql = [[SELECT * FROM v_voicemail_greetings - WHERE domain_uuid = ']] .. domain_uuid ..[[' - AND voicemail_id = ']].. voicemail_id.. [[' - AND greeting_id = ']].. greeting_id.. [[' ]]; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); - end - status = dbh:query(sql, function(row) - --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); - - --set the voicemail message path - greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; - - --save the greeting to the file system - if (string.len(row["greeting_base64"]) > 32) then - local file = io.open(greeting_location, "w"); - file:write(base64.decode(row["greeting_base64"])); - file:close(); - end - end); + sql = [[SELECT * FROM v_voicemail_greetings + WHERE domain_uuid = ']] .. domain_uuid ..[[' + AND voicemail_id = ']].. voicemail_id.. [[' + AND greeting_id = ']].. greeting_id.. [[' ]]; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); end + status = dbh:query(sql, function(row) + --add functions + dofile(scripts_dir.."/resources/functions/base64.lua"); + + --set the voicemail message path + greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; + + --save the greeting to the file system + if (string.len(row["greeting_base64"]) > 32) then + local file = io.open(greeting_location, "w"); + file:write(base64.decode(row["greeting_base64"])); + file:close(); + end + end); elseif (storage_type == "http_cache") then greeting_location = storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; end diff --git a/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua index a934a80c5c..484dc24ef0 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/play_greeting.lua @@ -43,33 +43,35 @@ --get the greeting from the database if (storage_type == "base64") then - sql = [[SELECT * FROM v_voicemail_greetings - WHERE domain_uuid = ']] .. domain_uuid ..[[' - AND voicemail_id = ']].. voicemail_id.. [[' - AND greeting_id = ']].. greeting_id.. [[' ]]; - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); - end - status = dbh:query(sql, function(row) - --add functions - dofile(scripts_dir.."/resources/functions/base64.lua"); + sql = [[SELECT * FROM v_voicemail_greetings + WHERE domain_uuid = ']] .. domain_uuid ..[[' + AND voicemail_id = ']].. voicemail_id.. [[' + AND greeting_id = ']].. greeting_id.. [[' ]]; + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); + end + status = dbh:query(sql, function(row) + --add functions + dofile(scripts_dir.."/resources/functions/base64.lua"); - --set the voicemail message path - greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; + --set the voicemail message path + greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext; - --save the greeting to the file system + --if not found, save greeting to local file system + --if (not file_exists(greeting_location)) then if (string.len(row["greeting_base64"]) > 32) then local file = io.open(greeting_location, "w"); file:write(base64.decode(row["greeting_base64"])); file:close(); end + --end - --play the greeting - session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); + --play the greeting + session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); - --delete the greeting - os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); - end); + --delete the greeting (retain local for better responsiveness) + --os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); + end); elseif (storage_type == "http_cache") then session:streamFile(storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); else diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua index f4cb07cdea..da41ef98fb 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua @@ -24,16 +24,18 @@ -- POSSIBILITY OF SUCH DAMAGE. --define a function to record the greeting - function record_greeting() + function record_greeting(greeting_id) --flush dtmf digits from the input buffer session:flushDigits(); - --Choose a greeting between 1 and 9 - if (session:ready()) then - dtmf_digits = ''; - greeting_id = macro(session, "choose_greeting_choose", 1, 5000, ''); - freeswitch.consoleLog("notice", "[voicemail] greeting_id: " .. greeting_id .. "\n"); + --choose a greeting between 1 and 9 + if (greeting_id == nil) then + if (session:ready()) then + dtmf_digits = ''; + greeting_id = macro(session, "choose_greeting_choose", 1, 5000, ''); + freeswitch.consoleLog("notice", "[voicemail] greeting_id: " .. greeting_id .. "\n"); + end end --validate the greeting_id @@ -53,7 +55,11 @@ end --store the voicemail greeting - if (storage_type == "base64") then + if (storage_type == "http_cache") then + freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. " ".. storage_path .."\n"); + storage_path = storage_path:gsub("${domain_name}", domain_name); + session:execute("record", storage_path .."/"..recording_name); + else --prepare to record the greeting if (session:ready()) then max_len_seconds = 30; @@ -61,97 +67,11 @@ silence_seconds = 5; mkdir(voicemail_dir.."/"..voicemail_id); -- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs) - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds); + result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", max_len_seconds, silence_threshold, silence_seconds); --session:execute("record", voicemail_dir.."/"..uuid.." 180 200"); end - - --include the base64 function - dofile(scripts_dir.."/resources/functions/base64.lua"); - - --show the storage type - --freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); - - --base64 encode the file - local f = io.open(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "rb"); - local file_content = f:read("*all"); - f:close(); - greeting_base64 = base64.encode(file_content); - - --delete the previous recording - sql = "delete from v_voicemail_greetings "; - sql = sql .. "where domain_uuid = '".. domain_uuid .. "' "; - sql = sql .. "and voicemail_id = '".. voicemail_id .."'"; - sql = sql .. "and greeting_id = '".. greeting_id .."'"; - dbh:query(sql); - - --get a new uuid - voicemail_greeting_uuid = api:execute("create_uuid"); - - --save the message to the voicemail messages - local array = {} - table.insert(array, "INSERT INTO v_voicemail_greetings "); - table.insert(array, "("); - table.insert(array, "voicemail_greeting_uuid, "); - table.insert(array, "domain_uuid, "); - table.insert(array, "voicemail_id, "); - table.insert(array, "greeting_id, "); - if (storage_type == "base64") then - table.insert(array, "greeting_base64, "); - end - table.insert(array, "greeting_name "); - table.insert(array, ") "); - table.insert(array, "VALUES "); - table.insert(array, "( "); - table.insert(array, "'"..voicemail_greeting_uuid.."', "); - table.insert(array, "'"..domain_uuid.."', "); - table.insert(array, "'"..voicemail_id.."', "); - table.insert(array, "'"..greeting_id.."', "); - if (storage_type == "base64") then - table.insert(array, "'"..greeting_base64.."', "); - end - table.insert(array, "'greeting_"..greeting_id..".wav' "); - table.insert(array, ") "); - sql = table.concat(array, "\n"); - if (debug["sql"]) then - freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); - end - if (storage_type == "base64") then - array = explode("://", database["system"]); - local luasql = require "luasql.postgres"; - local env = assert (luasql.postgres()); - local db = env:connect(array[2]); - res, serr = db:execute(sql); - db:close(); - env:close(); - else - dbh:query(sql); - end - elseif (storage_type == "http_cache") then - freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. " ".. storage_path .."\n"); - storage_path = storage_path:gsub("${domain_name}", domain_name); - session:execute("record", storage_path .."/"..recording_name); - else - --prepare to record the greeting - if (session:ready()) then - max_len_seconds = 30; - silence_threshold = 30; - silence_seconds = 5; - mkdir(voicemail_dir.."/"..voicemail_id); - -- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs) - result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds); - --session:execute("record", voicemail_dir.."/"..uuid.." 180 200"); - end end - --use the new greeting - local array = {} - table.insert(array, "update v_voicemails "); - table.insert(array, "set greeting_id = '".. greeting_id .."' "); - table.insert(array, "where domain_uuid = '".. domain_uuid .."' "); - table.insert(array, "and voicemail_id = '".. voicemail_id .."' "); - sql = table.concat(array, "\n"); - dbh:query(sql); - --play the greeting --if (session:ready()) then -- if (file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then @@ -162,11 +82,7 @@ --option to play, save, and re-record the greeting if (session:ready()) then timeouts = 0; - record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); - if (storage_type == "base64") then - --delete the greeting - os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); - end + record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", greeting_id); end else --invalid greeting_id @@ -186,4 +102,12 @@ end end end + + --clean up any tmp greeting files + for gid = 1, 9, 1 do + if (file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..gid..".tmp.wav")) then + os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..gid..".tmp.wav"); + end + end + end \ No newline at end of file diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua b/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua index ff1dc96a7b..be468907ea 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_menu.lua @@ -24,7 +24,7 @@ -- POSSIBILITY OF SUCH DAMAGE. --record message menu - function record_menu(type, file) + function record_menu(type, tmp_file, greeting_id) if (session:ready()) then --clear the dtmf digits variable dtmf_digits = ''; @@ -52,10 +52,10 @@ if (session:ready()) then if (dtmf_digits == "1") then --listen to the recording - session:streamFile(file); + session:streamFile(tmp_file); --session:streamFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext); - --record menu 1 listen to the recording, 2 save the recording, 3 re-record - record_menu(type, file); + --record menu (1=listen, 2=save, 3=re-record) + record_menu(type, tmp_file, greeting_id); elseif (dtmf_digits == "2") then --save the message dtmf_digits = ''; @@ -67,6 +67,93 @@ session:hangup(); end if (type == "greeting") then + --remove old greeting file, and rename tmp file + local real_file = string.gsub(tmp_file, ".tmp", ""); + if (file_exists(real_file)) then + os.remove(real_file); + end + if (file_exists(tmp_file)) then + os.rename(tmp_file, real_file); + end + if (storage_type == "base64") then + --delete the greeting (retain local for better responsiveness) + --os.remove(real_file); + end + + --if base64, encode file + if (storage_type == "base64") then + --include the base64 function + dofile(scripts_dir.."/resources/functions/base64.lua"); + --base64 encode the file + local f = io.open(real_file, "rb"); + local file_content = f:read("*all"); + f:close(); + greeting_base64 = base64.encode(file_content); + end + + --delete the previous recording + sql = "delete from v_voicemail_greetings "; + sql = sql .. "where domain_uuid = '".. domain_uuid .. "' "; + sql = sql .. "and voicemail_id = '".. voicemail_id .."' "; + sql = sql .. "and greeting_id = '".. greeting_id .."' "; + --freeswitch.consoleLog("notice", "[SQL] DELETING: " .. greeting_id .. "\n"); + dbh:query(sql); + + --get a new uuid + voicemail_greeting_uuid = api:execute("create_uuid"); + + --save the message to the voicemail messages + local array = {} + table.insert(array, "INSERT INTO v_voicemail_greetings "); + table.insert(array, "("); + table.insert(array, "voicemail_greeting_uuid, "); + table.insert(array, "domain_uuid, "); + table.insert(array, "voicemail_id, "); + table.insert(array, "greeting_id, "); + if (storage_type == "base64") then + table.insert(array, "greeting_base64, "); + end + table.insert(array, "greeting_name, "); + table.insert(array, "greeting_filename "); + table.insert(array, ") "); + table.insert(array, "VALUES "); + table.insert(array, "( "); + table.insert(array, "'"..voicemail_greeting_uuid.."', "); + table.insert(array, "'"..domain_uuid.."', "); + table.insert(array, "'"..voicemail_id.."', "); + table.insert(array, "'"..greeting_id.."', "); + if (storage_type == "base64") then + table.insert(array, "'"..greeting_base64.."', "); + end + table.insert(array, "'Greeting "..greeting_id.."', "); + table.insert(array, "'greeting_"..greeting_id..".wav' "); + table.insert(array, ") "); + sql = table.concat(array, "\n"); + --freeswitch.consoleLog("notice", "[SQL] INSERTING: " .. greeting_id .. "\n"); + if (debug["sql"]) then + freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); + end + if (storage_type == "base64") then + array = explode("://", database["system"]); + local luasql = require "luasql.postgres"; + local env = assert (luasql.postgres()); + local db = env:connect(array[2]); + res, serr = db:execute(sql); + db:close(); + env:close(); + else + dbh:query(sql); + end + + --use the new greeting + local array = {} + table.insert(array, "update v_voicemails "); + table.insert(array, "set greeting_id = '".. greeting_id .."' "); + table.insert(array, "where domain_uuid = '".. domain_uuid .."' "); + table.insert(array, "and voicemail_id = '".. voicemail_id .."' "); + sql = table.concat(array, "\n"); + dbh:query(sql); + advanced(); end if (type == "name") then @@ -80,12 +167,22 @@ record_message(); end if (type == "greeting") then - record_greeting(); + --remove temporary greeting file, if any + if (file_exists(tmp_file)) then + os.remove(tmp_file); + end + record_greeting(greeting_id); end if (type == "name") then record_name(); end elseif (dtmf_digits == "*") then + if (type == "greeting") then + --remove temporary greeting file, if any + if (file_exists(tmp_file)) then + os.remove(tmp_file); + end + end --hangup if (session:ready()) then dtmf_digits = ''; @@ -96,13 +193,19 @@ if (session:ready()) then timeouts = timeouts + 1; if (timeouts < max_timeouts) then - record_menu(type, file); + record_menu(type, tmp_file, greeting_id); else if (type == "message") then + dtmf_digits = ''; + macro(session, "message_saved", 1, 100, ''); macro(session, "goodbye", 1, 1000, ''); session:hangup(); end if (type == "greeting") then + --remove temporary greeting file, if any + if (file_exists(tmp_file)) then + os.remove(tmp_file); + end advanced(); end if (type == "name") then diff --git a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua index 03ddaa27e9..84c7751870 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/send_email.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/send_email.lua @@ -185,7 +185,13 @@ message_waiting(id, domain_uuid); --clear the variable db_voicemail_uuid = ''; + elseif (storage_type == "base64") then + --delete voicemail recording file + if (file_exists(file)) then + os.remove(file); + end end + end end \ No newline at end of file diff --git a/resources/install/scripts/recordings.lua b/resources/install/scripts/recordings.lua index b083ebd1fe..70dc89aa47 100644 --- a/resources/install/scripts/recordings.lua +++ b/resources/install/scripts/recordings.lua @@ -154,7 +154,7 @@ --delete the previous recording sql = "delete from v_recordings "; sql = sql .. "where domain_uuid = '".. domain_uuid .. "' "; - sql = sql .. "and recording_name = '".. recording_name .."'"; + sql = sql .. "and recording_filename = '".. recording_name .."'"; dbh:query(sql); --get a new uuid