2012-06-04 16:58:40 +02:00
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
FusionPBX
|
|
|
|
|
Version: MPL 1.1
|
|
|
|
|
|
|
|
|
|
The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
the License. You may obtain a copy of the License at
|
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
for the specific language governing rights and limitations under the
|
|
|
|
|
License.
|
|
|
|
|
|
|
|
|
|
The Original Code is FusionPBX
|
|
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
2024-05-31 23:00:15 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2024
|
2012-06-04 16:58:40 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
2017-07-18 09:25:47 +02:00
|
|
|
|
2024-05-31 23:00:15 +02:00
|
|
|
//set the max php execution time
|
|
|
|
|
ini_set('max_execution_time', 7200);
|
|
|
|
|
|
2022-10-11 00:35:14 +02:00
|
|
|
//includes files
|
2023-06-15 19:28:23 +02:00
|
|
|
require_once dirname(__DIR__, 2) . "/resources/require.php";
|
2017-07-18 09:25:47 +02:00
|
|
|
require_once "resources/check_auth.php";
|
|
|
|
|
|
2024-01-16 16:45:46 +01:00
|
|
|
//check permissions
|
2019-12-25 17:10:29 +01:00
|
|
|
if (!permission_exists('voicemail_greeting_view') || (!permission_exists('voicemail_view') && !extension_assigned($_REQUEST["id"]))) {
|
2019-12-24 08:13:15 +01:00
|
|
|
echo "access denied";
|
|
|
|
|
return;
|
2017-07-18 09:25:47 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2012-12-26 17:46:56 +01:00
|
|
|
//add multi-lingual support
|
2015-01-18 11:04:43 +01:00
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
2012-10-06 20:00:11 +02:00
|
|
|
|
2024-05-31 23:00:15 +02:00
|
|
|
//add the settings object
|
|
|
|
|
$settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
|
|
|
|
|
$speech_enabled = $settings->get('speech', 'enabled');
|
|
|
|
|
|
2023-05-27 00:13:52 +02:00
|
|
|
//set the defaults
|
|
|
|
|
$sql_file_size = '';
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//get the http get values and set them as php variables
|
2023-05-27 00:13:52 +02:00
|
|
|
$voicemail_id = $_REQUEST["id"] ?? '';
|
|
|
|
|
$order_by = $_GET["order_by"] ?? '';
|
|
|
|
|
$order = $_GET["order"] ?? '';
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2016-07-01 10:53:01 +02:00
|
|
|
//set the back button url
|
2023-06-09 18:51:59 +02:00
|
|
|
$_SESSION['back'][$_SERVER['PHP_SELF']] = !empty($_GET['back']) ? urldecode($_GET['back']) : $_SESSION['back'][$_SERVER['PHP_SELF']];
|
2016-07-01 10:53:01 +02:00
|
|
|
|
2015-04-25 14:26:31 +02:00
|
|
|
//define order by default
|
|
|
|
|
if ($order_by == '') {
|
2024-05-31 23:00:15 +02:00
|
|
|
$order_by = "greeting_id";
|
2015-04-25 14:26:31 +02:00
|
|
|
$order = "asc";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//used (above) to search the array to determine if an extension is assigned to the user
|
2019-12-24 08:13:15 +01:00
|
|
|
function extension_assigned($number) {
|
2012-06-04 16:58:40 +02:00
|
|
|
foreach ($_SESSION['user']['extension'] as $row) {
|
2019-12-24 08:13:15 +01:00
|
|
|
if ((is_numeric($row['number_alias']) && $row['number_alias'] == $number) || $row['user'] == $number) {
|
|
|
|
|
return true;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-24 08:13:15 +01:00
|
|
|
return false;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-25 14:26:31 +02:00
|
|
|
//get currently selected greeting
|
|
|
|
|
$sql = "select greeting_id from v_voicemails ";
|
2019-08-14 23:12:51 +02:00
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and voicemail_id = :voicemail_id ";
|
2022-12-10 02:55:49 +01:00
|
|
|
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
2019-08-14 23:12:51 +02:00
|
|
|
$parameters['voicemail_id'] = $voicemail_id;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$selected_greeting_id = $database->select($sql, $parameters, 'column');
|
|
|
|
|
unset($sql, $parameters);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-04-25 14:26:31 +02:00
|
|
|
//define greeting directory
|
2024-05-31 23:00:15 +02:00
|
|
|
$greeting_dir = $_SESSION['switch']['voicemail']['dir'].'/default/'.$_SESSION['domains'][$domain_uuid]['domain_name'].'/'.$voicemail_id;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2015-04-25 14:26:31 +02:00
|
|
|
//download the greeting
|
2023-06-05 20:41:28 +02:00
|
|
|
if (!empty($_GET['a']) && $_GET['a'] == "download" && (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download'))) {
|
2019-08-14 23:12:51 +02:00
|
|
|
if ($_GET['type'] == "rec") {
|
2022-12-10 02:55:49 +01:00
|
|
|
//get the id
|
2019-08-14 23:12:51 +02:00
|
|
|
$voicemail_greeting_uuid = $_GET['uuid'];
|
2022-12-10 02:55:49 +01:00
|
|
|
|
2015-04-25 14:26:31 +02:00
|
|
|
//get voicemail greeting details from db
|
2019-08-14 23:12:51 +02:00
|
|
|
$sql = "select greeting_filename, greeting_base64, greeting_id ";
|
|
|
|
|
$sql .= "from v_voicemail_greetings ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and voicemail_greeting_uuid = :voicemail_greeting_uuid ";
|
2022-12-10 02:55:49 +01:00
|
|
|
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
2019-08-14 23:12:51 +02:00
|
|
|
$parameters['voicemail_greeting_uuid'] = $voicemail_greeting_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$row = $database->select($sql, $parameters, 'row');
|
|
|
|
|
if (is_array($row) && @sizeof($row) != 0) {
|
|
|
|
|
$greeting_filename = $row['greeting_filename'];
|
|
|
|
|
$greeting_id = $row['greeting_id'];
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] == 'base64' && $row['greeting_base64'] != '') {
|
2019-08-14 23:12:51 +02:00
|
|
|
$greeting_decoded = base64_decode($row['greeting_base64']);
|
2022-12-10 02:55:49 +01:00
|
|
|
file_put_contents($greeting_dir.'/'.$greeting_filename, $greeting_decoded);
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-08-14 23:12:51 +02:00
|
|
|
unset($sql, $row, $greeting_decoded);
|
2022-12-10 02:55:49 +01:00
|
|
|
if (file_exists($greeting_dir.'/'.$greeting_filename)) {
|
2020-03-31 04:08:45 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
$fd = fopen($greeting_dir.'/'.$greeting_filename, "rb");
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($_GET['t']) && $_GET['t'] == "bin") {
|
2012-06-04 16:58:40 +02:00
|
|
|
header("Content-Type: application/force-download");
|
|
|
|
|
header("Content-Type: application/octet-stream");
|
|
|
|
|
header("Content-Type: application/download");
|
|
|
|
|
header("Content-Description: File Transfer");
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-03-31 04:08:45 +02:00
|
|
|
$file_ext = pathinfo($greeting_filename, PATHINFO_EXTENSION);
|
|
|
|
|
switch ($file_ext) {
|
|
|
|
|
case "wav" : header("Content-Type: audio/x-wav"); break;
|
|
|
|
|
case "mp3" : header("Content-Type: audio/mpeg"); break;
|
|
|
|
|
case "ogg" : header("Content-Type: audio/ogg"); break;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
header('Content-Disposition: attachment; filename="'.$greeting_filename.'"');
|
2012-06-04 16:58:40 +02:00
|
|
|
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
|
|
|
|
|
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($_GET['t']) && $_GET['t'] == "bin") {
|
2022-12-10 02:55:49 +01:00
|
|
|
header("Content-Length: ".filesize($greeting_dir.'/'.$greeting_filename));
|
2020-03-31 04:08:45 +02:00
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
ob_clean();
|
2023-06-09 18:51:59 +02:00
|
|
|
|
|
|
|
|
//content-range
|
|
|
|
|
if (isset($_SERVER['HTTP_RANGE']) && (empty($_GET['t']) || $_GET['t'] != "bin")) {
|
|
|
|
|
range_download($greeting_dir.'/'.$greeting_filename);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
fpassthru($fd);
|
|
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
|
|
|
|
|
//if base64, remove temp greeting file (if not currently selected greeting)
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] == 'base64' && $row['greeting_base64'] != '') {
|
2015-04-25 14:26:31 +02:00
|
|
|
if ($greeting_id != $selected_greeting_id) {
|
2022-12-10 02:55:49 +01:00
|
|
|
@unlink($greeting_dir.'/'.$greeting_filename);
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//upload the greeting
|
2023-06-05 20:41:28 +02:00
|
|
|
if (!empty($_POST['a']) && $_POST['a'] == "upload" && permission_exists('voicemail_greeting_upload')
|
2022-12-10 02:55:49 +01:00
|
|
|
&& $_POST['type'] == 'rec' && is_uploaded_file($_FILES['file']['tmp_name'])) {
|
2019-12-13 00:37:42 +01:00
|
|
|
|
|
|
|
|
//validate the token
|
2022-12-10 02:55:49 +01:00
|
|
|
$token = new token;
|
|
|
|
|
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
|
|
|
|
message::add($text['message-invalid_token'],'negative');
|
|
|
|
|
header('Location: voicemail_greetings.php?id='.urlencode($voicemail_id));
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2019-08-14 23:12:51 +02:00
|
|
|
|
2019-12-13 00:37:42 +01:00
|
|
|
//get the file extension
|
2022-12-10 02:55:49 +01:00
|
|
|
$file_ext = $file_ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
|
|
|
|
|
$file_name = $_FILES['file']['name'];
|
2019-12-13 00:37:42 +01:00
|
|
|
|
|
|
|
|
//check file extension
|
2022-12-10 02:55:49 +01:00
|
|
|
if ($file_ext == 'wav' || $file_ext == 'mp3') {
|
2019-12-13 00:37:42 +01:00
|
|
|
|
|
|
|
|
//find the next available
|
2022-12-10 02:55:49 +01:00
|
|
|
for ($i = 1; $i < 10; $i++) {
|
|
|
|
|
//set the file name
|
|
|
|
|
$file_name = 'greeting_'.$i.'.'.$file_ext;
|
|
|
|
|
|
2024-09-07 00:43:42 +02:00
|
|
|
//set the greeting id
|
2022-12-10 02:55:49 +01:00
|
|
|
if (!file_exists($greeting_dir.'/'.$file_name)) {
|
|
|
|
|
//set the greeting id
|
|
|
|
|
$greeting_id = $i;
|
2024-09-07 00:43:42 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//end the loop
|
|
|
|
|
break;
|
2019-12-13 00:37:42 +01:00
|
|
|
}
|
2022-12-10 02:55:49 +01:00
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//move the uploaded greeting
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($greeting_dir) && !file_exists($greeting_dir)) {
|
|
|
|
|
mkdir($greeting_dir, 0770, false);
|
|
|
|
|
}
|
2022-12-10 02:55:49 +01:00
|
|
|
if ($file_ext == 'wav' || $file_ext == 'mp3') {
|
|
|
|
|
move_uploaded_file($_FILES['file']['tmp_name'], $greeting_dir.'/'.$file_name);
|
|
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//set newly uploaded greeting as active greeting for voicemail box
|
2015-04-25 14:26:31 +02:00
|
|
|
$sql = "update v_voicemails ";
|
2019-08-14 23:12:51 +02:00
|
|
|
$sql .= "set greeting_id = :greeting_id ";
|
|
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and voicemail_id = :voicemail_id ";
|
|
|
|
|
$parameters['greeting_id'] = $greeting_id;
|
|
|
|
|
$parameters['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$parameters['voicemail_id'] = $voicemail_id;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->execute($sql, $parameters);
|
|
|
|
|
unset($sql, $parameters);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//build insert array
|
|
|
|
|
$x = 0;
|
|
|
|
|
$array['voicemail_greetings'][$x]['voicemail_greeting_uuid'] = uuid();
|
|
|
|
|
$array['voicemail_greetings'][$x]['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$array['voicemail_greetings'][$x]['voicemail_id'] = $voicemail_id;
|
|
|
|
|
$array['voicemail_greetings'][$x]['greeting_id'] = $greeting_id;
|
|
|
|
|
$array['voicemail_greetings'][$x]['greeting_name'] = $text['label-greeting'].' '.$greeting_id;
|
|
|
|
|
$array['voicemail_greetings'][$x]['greeting_filename'] = $file_name;
|
|
|
|
|
$array['voicemail_greetings'][$x]['greeting_description'] = '';
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] == 'base64') {
|
2024-01-16 16:44:22 +01:00
|
|
|
$array['voicemail_greetings'][$x]['greeting_base64'] = base64_encode(file_get_contents($greeting_dir.'/'.$file_name));
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
2022-12-10 02:55:49 +01:00
|
|
|
|
|
|
|
|
//save the array
|
|
|
|
|
if (is_array($array) && @sizeof($array) != 0) {
|
|
|
|
|
|
|
|
|
|
//grant temporary permissions
|
2024-11-29 21:57:01 +01:00
|
|
|
$p = permissions::new();
|
2022-12-10 02:55:49 +01:00
|
|
|
$p->add('voicemail_greeting_add', 'temp');
|
2019-08-14 23:12:51 +02:00
|
|
|
$p->add('voicemail_greeting_edit', 'temp');
|
2022-12-10 02:55:49 +01:00
|
|
|
|
|
|
|
|
//execute inserts/updates
|
2019-08-14 23:12:51 +02:00
|
|
|
$database = new database;
|
|
|
|
|
$database->app_name = 'voicemail_greetings';
|
|
|
|
|
$database->app_uuid = 'e4b4fbee-9e4d-8e46-3810-91ba663db0c2';
|
|
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
2022-12-10 02:55:49 +01:00
|
|
|
|
|
|
|
|
//revoke temporary permissions
|
|
|
|
|
$p->delete('voicemail_greeting_add', 'temp');
|
2019-08-14 23:12:51 +02:00
|
|
|
$p->delete('voicemail_greeting_edit', 'temp');
|
2022-12-10 02:55:49 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo __line__;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//set message
|
|
|
|
|
message::add($text['message-uploaded'].": ".$_FILES['file']['name']);
|
|
|
|
|
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
2022-12-10 02:55:49 +01:00
|
|
|
|
|
|
|
|
//set the file name to be inserted as the greeting description
|
|
|
|
|
$greeting_description = base64_encode($_FILES['file']['name']);
|
|
|
|
|
header("Location: voicemail_greetings.php?id=".urlencode($voicemail_id)."&order_by=".urlencode($order_by)."&order=".urlencode($order)."&gd=".$greeting_description);
|
|
|
|
|
exit;
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//check the permission
|
|
|
|
|
if (permission_exists('voicemail_greeting_view')) {
|
|
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//set the greeting
|
2023-06-05 20:41:28 +02:00
|
|
|
if (!empty($_REQUEST['action']) && $_REQUEST['action'] == "set") {
|
2022-12-10 02:55:49 +01:00
|
|
|
//save the greeting_id to a variable
|
|
|
|
|
$greeting_id = $_REQUEST['greeting_id'];
|
2019-08-14 23:12:51 +02:00
|
|
|
|
2022-12-10 02:55:49 +01:00
|
|
|
//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 ";
|
|
|
|
|
$parameters['greeting_id'] = $greeting_id;
|
|
|
|
|
$parameters['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$parameters['voicemail_id'] = $voicemail_id;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->execute($sql, $parameters);
|
|
|
|
|
unset($sql, $parameters);
|
|
|
|
|
|
|
|
|
|
//set message
|
|
|
|
|
message::add($text['message-greeting_selected']);
|
|
|
|
|
|
|
|
|
|
//redirect
|
|
|
|
|
header("Location: voicemail_greetings.php?id=".$voicemail_id."&order_by=".$order_by."&order=".$order);
|
|
|
|
|
exit;
|
2019-08-14 23:12:51 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2019-12-13 00:37:42 +01:00
|
|
|
//get the http post data
|
2023-05-27 00:13:52 +02:00
|
|
|
if (!empty($_POST['voicemail_greetings'])) {
|
2019-12-13 00:37:42 +01:00
|
|
|
$action = $_POST['action'];
|
|
|
|
|
$voicemail_id = $_POST['voicemail_id'];
|
|
|
|
|
$voicemail_greetings = $_POST['voicemail_greetings'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//process the http post data by action
|
2023-05-27 00:13:52 +02:00
|
|
|
if (!empty($action) && !empty($voicemail_greetings)) {
|
2019-12-13 00:37:42 +01:00
|
|
|
switch ($action) {
|
|
|
|
|
case 'delete':
|
|
|
|
|
if (permission_exists('voicemail_greeting_delete')) {
|
|
|
|
|
$obj = new voicemail_greetings;
|
|
|
|
|
$obj->voicemail_id = $voicemail_id;
|
|
|
|
|
$obj->delete($voicemail_greetings);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header('Location: voicemail_greetings.php?id='.urlencode($voicemail_id).'&back='.urlencode(PROJECT_PATH.'/app/voicemails/voicemails.php'));
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 09:25:47 +02:00
|
|
|
//get the greetings list
|
2023-06-05 20:41:28 +02:00
|
|
|
if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] == 'base64') {
|
2019-12-13 00:51:12 +01:00
|
|
|
switch ($db_type) {
|
|
|
|
|
case 'pgsql': $sql_file_size = ", length(decode(greeting_base64,'base64')) as greeting_size "; break;
|
|
|
|
|
case 'mysql': $sql_file_size = ", length(from_base64(greeting_base64)) as greeting_size "; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$sql = "select * ".$sql_file_size." from v_voicemail_greetings ";
|
2019-08-14 23:12:51 +02:00
|
|
|
$sql .= "where domain_uuid = :domain_uuid ";
|
|
|
|
|
$sql .= "and voicemail_id = :voicemail_id ";
|
|
|
|
|
$sql .= order_by($order_by, $order);
|
|
|
|
|
$parameters['domain_uuid'] = $domain_uuid;
|
|
|
|
|
$parameters['voicemail_id'] = $voicemail_id;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$greetings = $database->select($sql, $parameters, 'all');
|
2019-12-13 00:37:42 +01:00
|
|
|
$num_rows = is_array($greetings) ? @sizeof($greetings) : 0;
|
2019-08-14 23:12:51 +02:00
|
|
|
unset($sql, $parameters);
|
2017-07-18 09:25:47 +02:00
|
|
|
|
2019-12-13 00:37:42 +01:00
|
|
|
//create token
|
|
|
|
|
$object = new token;
|
|
|
|
|
$token = $object->create($_SERVER['PHP_SELF']);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//include the header
|
2015-04-25 14:26:31 +02:00
|
|
|
$document['title'] = $text['title'];
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/header.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2019-12-13 00:37:42 +01:00
|
|
|
//file type check script
|
2016-07-01 11:18:07 +02:00
|
|
|
echo "<script language='JavaScript' type='text/javascript'>\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " function check_file_type(file_input) {\n";
|
2016-07-01 11:18:07 +02:00
|
|
|
echo " file_ext = file_input.value.substr((~-file_input.value.lastIndexOf('.') >>> 0) + 2);\n";
|
|
|
|
|
echo " if (file_ext != 'mp3' && file_ext != 'wav' && file_ext != 'ogg' && file_ext != '') {\n";
|
|
|
|
|
echo " display_message(\"".$text['message-unsupported_file_type']."\", 'negative', '2750');\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " document.getElementById('form_upload').reset();\n";
|
2016-07-01 11:18:07 +02:00
|
|
|
echo " }\n";
|
|
|
|
|
echo " }\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "</script>";
|
|
|
|
|
|
2019-12-13 00:37:42 +01:00
|
|
|
//show the content
|
|
|
|
|
echo "<div class='action_bar' id='action_bar'>\n";
|
2024-09-07 00:43:42 +02:00
|
|
|
echo " <div class='heading'><b>".$text['title']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <div class='actions'>\n";
|
2024-01-03 23:31:48 +01:00
|
|
|
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>$_SESSION['back'][$_SERVER['PHP_SELF']]]);
|
2024-05-31 23:00:15 +02:00
|
|
|
$margin_left = false;
|
|
|
|
|
if (permission_exists('voicemail_greeting_add') && is_array($greetings) && @sizeof($greetings) < 9 && $speech_enabled == 'true') {
|
|
|
|
|
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','style'=>'margin-left: 15px;','link'=>'voicemail_greeting_edit.php?voicemail_id='.urlencode($voicemail_id)]);
|
|
|
|
|
$margin_left = true;
|
|
|
|
|
}
|
2024-01-03 23:31:48 +01:00
|
|
|
if (permission_exists('voicemail_greeting_upload') && is_array($greetings) && @sizeof($greetings) < 9) {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<form id='form_upload' class='inline' method='post' enctype='multipart/form-data'>\n";
|
|
|
|
|
echo "<input name='a' type='hidden' value='upload'>\n";
|
|
|
|
|
echo "<input type='hidden' name='id' value='".escape($voicemail_id)."'>\n";
|
|
|
|
|
echo "<input type='hidden' name='type' value='rec'>\n";
|
|
|
|
|
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
2024-05-31 23:00:15 +02:00
|
|
|
echo button::create(['type'=>'button','label'=>$text['button-upload'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_upload','style'=>(!$margin_left ? 'margin-left: 15px;' : null),'onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]);
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<span id='form_upload' style='display: none;'>";
|
2024-05-31 23:00:15 +02:00
|
|
|
echo button::create(['label'=>$text['button-cancel'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'type'=>'button','id'=>'btn_upload_cancel','style'=>'margin-left: 15px;','onclick'=>"$('span#form_upload').fadeOut(250, function(){ document.getElementById('form_upload').reset(); $('#btn_upload').fadeIn(250) });"]);
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<input type='text' class='txt' style='width: 100px; cursor: pointer;' id='filename' placeholder='Select...' onclick=\"document.getElementById('ulfile').click(); this.blur();\" onfocus='this.blur();'>";
|
|
|
|
|
echo "<input type='file' id='ulfile' name='file' style='display: none;' accept='.wav,.mp3,.ogg' onchange=\"document.getElementById('filename').value = this.files.item(0).name; check_file_type(this);\">";
|
|
|
|
|
echo button::create(['type'=>'submit','label'=>$text['button-upload'],'icon'=>$_SESSION['theme']['button_icon_upload']]);
|
|
|
|
|
echo "</span>\n";
|
|
|
|
|
echo "</form>";
|
2024-05-31 23:00:15 +02:00
|
|
|
$margin_left = true;
|
2016-07-01 11:18:07 +02:00
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
if (permission_exists('voicemail_greeting_delete') && $greetings) {
|
2024-05-31 23:00:15 +02:00
|
|
|
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; '.(!$margin_left ? 'margin-left: 15px;' : null),'onclick'=>"modal_open('modal-delete','btn_delete');"]);
|
|
|
|
|
$margin_left = true;
|
2014-04-27 05:24:41 +02:00
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " </div>\n";
|
|
|
|
|
echo " <div style='clear: both;'></div>\n";
|
|
|
|
|
echo "</div>\n";
|
|
|
|
|
|
2020-03-26 22:49:32 +01:00
|
|
|
if (permission_exists('voicemail_greeting_delete') && $greetings) {
|
|
|
|
|
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-06 19:35:04 +02:00
|
|
|
echo $text['description']." <strong>".escape($voicemail_id)."</strong>\n";
|
2016-07-01 11:18:07 +02:00
|
|
|
echo "<br /><br />\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<form id='form_list' method='post'>\n";
|
|
|
|
|
echo "<input type='hidden' id='action' name='action' value=''>\n";
|
|
|
|
|
echo "<input type='hidden' id='voicemail_id' name='voicemail_id' value='".escape($voicemail_id)."'>\n";
|
|
|
|
|
|
2024-09-26 23:57:32 +02:00
|
|
|
echo "<div class='card'>\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<table class='list'>\n";
|
|
|
|
|
echo "<tr class='list-header'>\n";
|
|
|
|
|
$col_count = 0;
|
|
|
|
|
if (permission_exists('voicemail_greeting_delete')) {
|
|
|
|
|
echo " <th class='checkbox'>\n";
|
2023-06-09 18:51:59 +02:00
|
|
|
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($greetings) ? "style='visibility: hidden;'" : null).">\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " </th>\n";
|
|
|
|
|
$col_count++;
|
|
|
|
|
}
|
|
|
|
|
echo "<th class='shrink center'>".$text['label-selected']."</th>\n";
|
|
|
|
|
$col_count++;
|
|
|
|
|
echo th_order_by('greeting_id', $text['label-number'], $order_by, $order, null, "class='center shrink'", "id=".urlencode($voicemail_id));
|
|
|
|
|
$col_count++;
|
|
|
|
|
echo th_order_by('greeting_name', $text['label-name'], $order_by, $order, null, null, "id=".urlencode($voicemail_id));
|
|
|
|
|
$col_count++;
|
2023-06-09 18:51:59 +02:00
|
|
|
if (empty($_SESSION['voicemail']['storage_type']['text']) || $_SESSION['voicemail']['storage_type']['text'] != 'base64') {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo th_order_by('greeting_filename', $text['label-filename'], $order_by, $order, null, "class='hide-sm-dn'", "id=".urlencode($voicemail_id));
|
|
|
|
|
$col_count++;
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
|
|
|
|
if (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download')) {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<th class='center'>".$text['label-tools']."</th>\n";
|
|
|
|
|
$col_count++;
|
|
|
|
|
}
|
2019-12-13 00:51:12 +01:00
|
|
|
echo "<th class='center no-wrap hide-xs'>".$text['label-size']."</th>\n";
|
|
|
|
|
$col_count++;
|
2023-06-09 18:51:59 +02:00
|
|
|
if (empty($_SESSION['voicemail']['storage_type']['text']) || $_SESSION['voicemail']['storage_type']['text'] != 'base64') {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<th class='center no-wrap hide-xs'>".$text['label-uploaded']."</th>\n";
|
2019-12-13 00:51:12 +01:00
|
|
|
$col_count++;
|
2019-12-13 00:37:42 +01:00
|
|
|
}
|
|
|
|
|
echo th_order_by('greeting_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn pct-25'", "id=".urlencode($voicemail_id));
|
2024-10-19 03:22:54 +02:00
|
|
|
$col_count++;
|
2025-03-04 19:25:47 +01:00
|
|
|
if (permission_exists('voicemail_greeting_edit') && filter_var($_SESSION['theme']['list_row_edit_button']['boolean'] ?? false, FILTER_VALIDATE_BOOL)) {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='action-button'> </td>\n";
|
2014-09-11 21:48:19 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
2019-08-14 23:12:51 +02:00
|
|
|
if (is_array($greetings) && @sizeof($greetings) != 0) {
|
2019-12-13 00:37:42 +01:00
|
|
|
$x = 0;
|
|
|
|
|
foreach ($greetings as $row) {
|
2015-04-14 00:26:50 +02:00
|
|
|
//playback progress bar
|
2024-02-09 21:12:34 +01:00
|
|
|
if (permission_exists('voicemail_greeting_play')) {
|
2024-10-19 03:22:54 +02:00
|
|
|
echo "<tr class='list-row' id='recording_progress_bar_".escape($row['voicemail_greeting_uuid'])."' onclick=\"recording_seek(event,'".escape($row['voicemail_greeting_uuid'])."')\" style='display: none;'><td id='playback_progress_bar_background_".escape($row['voicemail_greeting_uuid'])."' class='playback_progress_bar_background' style='padding: 0; border: none;' colspan='".$col_count."'><span class='playback_progress_bar' id='recording_progress_".escape($row['voicemail_greeting_uuid'])."'></span></td></tr>\n";
|
2024-02-09 21:12:34 +01:00
|
|
|
echo "<tr class='list-row' style='display: none;'><td></td></tr>\n"; // dummy row to maintain alternating background color
|
|
|
|
|
}
|
2025-02-21 00:30:09 +01:00
|
|
|
$list_row_url = '';
|
2019-12-13 00:37:42 +01:00
|
|
|
if (permission_exists('voicemail_greeting_edit')) {
|
|
|
|
|
$list_row_url = "voicemail_greeting_edit.php?id=".urlencode($row['voicemail_greeting_uuid'])."&voicemail_id=".urlencode($voicemail_id);
|
2025-02-21 00:30:09 +01:00
|
|
|
if ($row['domain_uuid'] != $_SESSION['domain_uuid'] && permission_exists('domain_select')) {
|
|
|
|
|
$list_row_url .= '&domain_uuid='.urlencode($row['domain_uuid']).'&domain_change=true';
|
|
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
}
|
|
|
|
|
echo "<tr class='list-row' href='".$list_row_url."'>\n";
|
|
|
|
|
if (permission_exists('voicemail_greeting_delete')) {
|
|
|
|
|
echo " <td class='checkbox'>\n";
|
2023-06-09 18:51:59 +02:00
|
|
|
echo " <input type='checkbox' name='voicemail_greetings[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; } checkbox_on_change(this);\">\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <input type='hidden' name='voicemail_greetings[$x][uuid]' value='".escape($row['voicemail_greeting_uuid'])."' />\n";
|
|
|
|
|
echo " </td>\n";
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='center no-link'>";
|
2015-04-25 14:26:31 +02:00
|
|
|
$selected = ($row['greeting_id'] == $selected_greeting_id) ? true : false;
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<input type='radio' onclick=\"window.location='".PROJECT_PATH."/app/voicemail_greetings/voicemail_greetings.php?id=".escape($voicemail_id)."&greeting_id=".escape($row['greeting_id'])."&action=set&order_by=".$order_by."&order=".$order."';\" name='greeting_id' value='".escape($row['greeting_id'])."' ".(($selected) ? "checked='checked'" : null)." style='display: block; width: 20px; height: auto; margin: auto calc(50% - 10px);'>\n";
|
|
|
|
|
echo " </td>\n";
|
|
|
|
|
echo " <td class='center'>".escape($row['greeting_id'])."</td>\n";
|
|
|
|
|
echo " <td class='no-wrap'>";
|
|
|
|
|
if (permission_exists('voicemail_greeting_edit')) {
|
|
|
|
|
echo "<a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['greeting_name'])."</a>";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo escape($row['greeting_name']);
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " </td>\n";
|
2023-06-09 18:51:59 +02:00
|
|
|
if (empty($_SESSION['voicemail']['storage_type']['text']) || $_SESSION['voicemail']['storage_type']['text'] != 'base64') {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='hide-sm-dn'>".escape($row['greeting_filename'])."</td>\n";
|
2015-04-25 14:26:31 +02:00
|
|
|
}
|
|
|
|
|
if (permission_exists('voicemail_greeting_play') || permission_exists('voicemail_greeting_download')) {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='middle button center no-link no-wrap'>";
|
2015-04-25 14:26:31 +02:00
|
|
|
if (permission_exists('voicemail_greeting_play')) {
|
|
|
|
|
$greeting_file_path = $row['greeting_filename'];
|
|
|
|
|
$greeting_file_name = strtolower(pathinfo($greeting_file_path, PATHINFO_BASENAME));
|
|
|
|
|
$greeting_file_ext = pathinfo($greeting_file_name, PATHINFO_EXTENSION);
|
|
|
|
|
switch ($greeting_file_ext) {
|
|
|
|
|
case "wav" : $greeting_type = "audio/wav"; break;
|
|
|
|
|
case "mp3" : $greeting_type = "audio/mpeg"; break;
|
|
|
|
|
case "ogg" : $greeting_type = "audio/ogg"; break;
|
2014-09-11 21:48:19 +02:00
|
|
|
}
|
2018-06-06 19:35:04 +02:00
|
|
|
echo "<audio id='recording_audio_".escape($row['voicemail_greeting_uuid'])."' style='display: none;' preload='none' ontimeupdate=\"update_progress('".escape($row['voicemail_greeting_uuid'])."')\" onended=\"recording_reset('".escape($row['voicemail_greeting_uuid'])."');\" src=\"voicemail_greetings.php?id=".escape($voicemail_id)."&a=download&type=rec&uuid=".escape($row['voicemail_greeting_uuid'])."\" type='".$greeting_type."'></audio>";
|
2024-02-09 21:12:34 +01:00
|
|
|
echo button::create(['type'=>'button','title'=>$text['label-play'].' / '.$text['label-pause'],'icon'=>$_SESSION['theme']['button_icon_play'],'id'=>'recording_button_'.escape($row['voicemail_greeting_uuid']),'onclick'=>"recording_play('".escape($row['voicemail_greeting_uuid'])."','".escape($voicemail_id).'|'.escape($row['voicemail_greeting_uuid'])."')"]);
|
2014-09-11 21:48:19 +02:00
|
|
|
}
|
2015-04-25 14:26:31 +02:00
|
|
|
if (permission_exists('voicemail_greeting_download')) {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo button::create(['type'=>'button','title'=>$text['label-download'],'icon'=>$_SESSION['theme']['button_icon_download'],'link'=>"voicemail_greetings.php?a=download&type=rec&t=bin&id=".urlencode($voicemail_id)."&uuid=".escape($row['voicemail_greeting_uuid'])]);
|
2014-09-11 21:48:19 +02:00
|
|
|
}
|
|
|
|
|
echo " </td>\n";
|
2014-04-27 05:24:41 +02:00
|
|
|
}
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($_SESSION['voicemail']['storage_type']['text']) && $_SESSION['voicemail']['storage_type']['text'] == 'base64') {
|
2019-12-13 00:51:12 +01:00
|
|
|
$file_size = byte_convert($row['greeting_size']);
|
|
|
|
|
echo " <td class='center no-wrap hide-xs'>".$file_size."</td>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-12-10 02:55:49 +01:00
|
|
|
$file_size = byte_convert(filesize($greeting_dir.'/'.$row['greeting_filename']));
|
|
|
|
|
$file_date = date("M d, Y H:i:s", filemtime($greeting_dir.'/'.$row['greeting_filename']));
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='center no-wrap hide-xs'>".$file_size."</td>\n";
|
|
|
|
|
echo " <td class='center no-wrap hide-xs'>".$file_date."</td>\n";
|
2014-05-06 02:03:39 +02:00
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='description overflow hide-sm-dn'>".escape($row['greeting_description'])." </td>\n";
|
2025-03-04 19:25:47 +01:00
|
|
|
if (permission_exists('voicemail_greeting_edit') && filter_var($_SESSION['theme']['list_row_edit_button']['boolean'] ?? false, FILTER_VALIDATE_BOOL)) {
|
2019-12-13 00:37:42 +01:00
|
|
|
echo " <td class='action-button'>";
|
|
|
|
|
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
|
|
|
|
|
echo " </td>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
echo "</tr>\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
$x++;
|
2019-08-14 23:12:51 +02:00
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
unset($greetings);
|
2019-08-14 23:12:51 +02:00
|
|
|
}
|
2019-12-13 00:37:42 +01:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "</table>\n";
|
2024-09-26 23:57:32 +02:00
|
|
|
echo "</div>\n";
|
2019-12-13 00:37:42 +01:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
|
|
|
|
echo "</form>\n";
|
2015-04-25 14:26:31 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
//include the footer
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/footer.php";
|
2018-06-06 19:35:04 +02:00
|
|
|
|
2020-03-31 04:08:45 +02:00
|
|
|
//define the download function (helps safari play audio sources)
|
|
|
|
|
function range_download($file) {
|
|
|
|
|
$fp = @fopen($file, 'rb');
|
|
|
|
|
|
|
|
|
|
$size = filesize($file); // File size
|
|
|
|
|
$length = $size; // Content length
|
|
|
|
|
$start = 0; // Start byte
|
|
|
|
|
$end = $size - 1; // End byte
|
|
|
|
|
// Now that we've gotten so far without errors we send the accept range header
|
|
|
|
|
/* At the moment we only support single ranges.
|
|
|
|
|
* Multiple ranges requires some more work to ensure it works correctly
|
|
|
|
|
* and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
|
|
|
|
|
*
|
|
|
|
|
* Multirange support annouces itself with:
|
|
|
|
|
* header('Accept-Ranges: bytes');
|
|
|
|
|
*
|
|
|
|
|
* Multirange content must be sent with multipart/byteranges mediatype,
|
|
|
|
|
* (mediatype = mimetype)
|
|
|
|
|
* as well as a boundry header to indicate the various chunks of data.
|
|
|
|
|
*/
|
|
|
|
|
header("Accept-Ranges: 0-$length");
|
|
|
|
|
// header('Accept-Ranges: bytes');
|
|
|
|
|
// multipart/byteranges
|
|
|
|
|
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2
|
|
|
|
|
if (isset($_SERVER['HTTP_RANGE'])) {
|
|
|
|
|
|
|
|
|
|
$c_start = $start;
|
|
|
|
|
$c_end = $end;
|
|
|
|
|
// Extract the range string
|
|
|
|
|
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
|
|
|
|
|
// Make sure the client hasn't sent us a multibyte range
|
|
|
|
|
if (strpos($range, ',') !== false) {
|
|
|
|
|
// (?) Shoud this be issued here, or should the first
|
|
|
|
|
// range be used? Or should the header be ignored and
|
|
|
|
|
// we output the whole content?
|
|
|
|
|
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
|
|
|
|
header("Content-Range: bytes $start-$end/$size");
|
|
|
|
|
// (?) Echo some info to the client?
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
// If the range starts with an '-' we start from the beginning
|
|
|
|
|
// If not, we forward the file pointer
|
|
|
|
|
// And make sure to get the end byte if spesified
|
2023-06-09 18:51:59 +02:00
|
|
|
if (!empty($range0) && $range0 == '-') {
|
2020-03-31 04:08:45 +02:00
|
|
|
// The n-number of the last bytes is requested
|
|
|
|
|
$c_start = $size - substr($range, 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$range = explode('-', $range);
|
|
|
|
|
$c_start = $range[0];
|
|
|
|
|
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
|
|
|
|
|
}
|
|
|
|
|
/* Check the range and make sure it's treated according to the specs.
|
|
|
|
|
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
|
|
|
|
|
*/
|
|
|
|
|
// End bytes can not be larger than $end.
|
|
|
|
|
$c_end = ($c_end > $end) ? $end : $c_end;
|
|
|
|
|
// Validate the requested range and return an error if it's not correct.
|
|
|
|
|
if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
|
|
|
|
|
|
|
|
|
|
header('HTTP/1.1 416 Requested Range Not Satisfiable');
|
|
|
|
|
header("Content-Range: bytes $start-$end/$size");
|
|
|
|
|
// (?) Echo some info to the client?
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
$start = $c_start;
|
|
|
|
|
$end = $c_end;
|
|
|
|
|
$length = $end - $start + 1; // Calculate new content length
|
|
|
|
|
fseek($fp, $start);
|
|
|
|
|
header('HTTP/1.1 206 Partial Content');
|
|
|
|
|
}
|
|
|
|
|
// Notify the client the byte range we'll be outputting
|
|
|
|
|
header("Content-Range: bytes $start-$end/$size");
|
|
|
|
|
header("Content-Length: $length");
|
|
|
|
|
|
|
|
|
|
// Start buffered download
|
|
|
|
|
$buffer = 1024 * 8;
|
|
|
|
|
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
|
|
|
|
|
if ($p + $buffer > $end) {
|
|
|
|
|
// In case we're only outputtin a chunk, make sure we don't
|
|
|
|
|
// read past the length
|
|
|
|
|
$buffer = $end - $p + 1;
|
|
|
|
|
}
|
|
|
|
|
set_time_limit(0); // Reset time limit for big files
|
|
|
|
|
echo fread($fp, $buffer);
|
|
|
|
|
flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-07 00:43:42 +02:00
|
|
|
?>
|
2025-02-21 00:30:09 +01:00
|
|
|
|