Portions created by the Initial Developer are Copyright (C) 2022-2026
the Initial Developer. All Rights Reserved.
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (!(permission_exists('fax_queue_add') || permission_exists('fax_queue_edit'))) {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
// Set variables from http GET parameters
$page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0;
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'fax_date'));
$order = ($_GET['order'] ?? '') === 'asc' ? 'asc' : 'desc';
$search = $_GET['search'] ?? '';
$show = $_GET['show'] ?? '';
$fax_status = $_GET['fax_status'] ?? '';
// Build the query string
$param = [];
if (!empty($page)) {
$param['page'] = $page;
}
if (!empty($_GET['order_by'])) {
$param['order_by'] = $order_by;
}
if (!empty($_GET['order'])) {
$param['order'] = $order;
}
if (!empty($search)) {
$param['search'] = $search;
}
if (!empty($show) && $show == 'all' && permission_exists('fax_queue_all')) {
$param['show'] = $show;
}
if (!empty($fax_status)) {
$param['fax_status'] = $fax_status;
}
$query_string = http_build_query($param);
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$fax_queue_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (!empty($_POST) && is_array($_POST)) {
//$fax_uuid = $_POST["fax_uuid"];
$fax_date = $_POST["fax_date"];
$hostname = $_POST["hostname"];
$fax_caller_id_name = $_POST["fax_caller_id_name"];
$fax_caller_id_number = $_POST["fax_caller_id_number"];
$fax_number = $_POST["fax_number"];
$fax_prefix = $_POST["fax_prefix"];
$fax_email_address = $_POST["fax_email_address"];
$fax_file = $_POST["fax_file"];
$fax_status = $_POST["fax_status"];
$fax_retry_date = $_POST["fax_retry_date"];
$fax_notify_date = $_POST["fax_notify_date"] ?? null;
$fax_retry_count = $_POST["fax_retry_count"];
$fax_accountcode = $_POST["fax_accountcode"];
$fax_command = $_POST["fax_command"];
$fax_response = $_POST["fax_response"];
}
//process the user data and save it to the database
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: fax_queue.php'.($query_string ? '?'.$query_string : ''));
exit;
}
//process the http post data by submitted action
if (!empty($_POST['action'])) {
//prepare the array(s)
//send the array to the database class
switch ($_POST['action']) {
case 'copy':
if (permission_exists('fax_queue_add')) {
$database->copy($array);
}
break;
case 'delete':
if (permission_exists('fax_queue_delete')) {
$database->delete($array);
}
break;
case 'toggle':
if (permission_exists('fax_queue_update')) {
$database->toggle($array);
}
break;
}
//redirect the user
if (in_array($_POST['action'], array('copy', 'delete', 'toggle')) && is_uuid($id)) {
header('Location: fax_queue_edit.php?id='.$id.($query_string ? '&'.$query_string : ''));
exit;
}
}
//check for all required data
$msg = '';
//if (empty($fax_uuid)) { $msg .= $text['message-required']." ".$text['label-fax_uuid']."
\n"; }
if (empty($fax_date)) { $msg .= $text['message-required']." ".$text['label-fax_date']."
\n"; }
if (empty($hostname)) { $msg .= $text['message-required']." ".$text['label-hostname']."
\n"; }
//if (empty($fax_caller_id_name)) { $msg .= $text['message-required']." ".$text['label-fax_caller_id_name']."
\n"; }
//if (empty($fax_caller_id_number)) { $msg .= $text['message-required']." ".$text['label-fax_caller_id_number']."
\n"; }
if (empty($fax_number)) { $msg .= $text['message-required']." ".$text['label-fax_number']."
\n"; }
//if (empty($fax_prefix)) { $msg .= $text['message-required']." ".$text['label-fax_prefix']."
\n"; }
//if (empty($fax_email_address)) { $msg .= $text['message-required']." ".$text['label-fax_email_address']."
\n"; }
if (empty($fax_file)) { $msg .= $text['message-required']." ".$text['label-fax_file']."
\n"; }
if (empty($fax_status)) { $msg .= $text['message-required']." ".$text['label-fax_status']."
\n"; }
//if (empty($fax_retry_date)) { $msg .= $text['message-required']." ".$text['label-fax_retry_date']."
\n"; }
//if (empty($fax_retry_count)) { $msg .= $text['message-required']." ".$text['label-fax_retry_count']."
\n"; }
//if (empty($fax_accountcode)) { $msg .= $text['message-required']." ".$text['label-fax_accountcode']."
\n"; }
//if (empty($fax_command)) { $msg .= $text['message-required']." ".$text['label-fax_command']."
\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
| \n";
echo $msg." "; echo " |