<?php
require_once('config.php');
if(!isset($_SESSION['user'])||!has_permission('faxsend')){header("Location:login.php");exit;}
$msg=ns($_GET['msg']??'');
$rowCount=0;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title><?=ns(APP_NAME)?> - <?php _nsl('Send Fax');?></title>
<link rel="stylesheet" href="include/css/style.css">
<?php include('include/web/header.php');?>
<script>
window.FAX_LANG={
cancel:"<?=ns(__('Cancel'))?>",
ok:"<?=ns(__('Ok'))?>",
selected:"<?=ns(__('Add Selected'))?>",
addressbook:"<?=ns(__('Select Contacts'))?>",
keyword:"<?=ns(__('Enter keyword'))?>",
alert:"<?=ns(__('Alert'))?>",
pushTitle:"<?=ns(__('Push Notification'))?>",
pushDesc:"<?=ns(__('You can register or test push notifications'))?>",
pushRegister:"<?=ns(__('Subscribe'))?>",
pushTest:"<?=ns(__('Test'))?>",
pushNotSupported:"<?=ns(__('Push is not supported in this browser'))?>",
pushNeedPermission:"<?=ns(__('Notification permission is required'))?>",
pushAlready:"<?=ns(__('Already subscribed'))?>",
pushSuccess:"<?=ns(__('Push subscription completed'))?>",
pushTestSuccess:"<?=ns(__('Test notification sent'))?>",
pushTestFail:"<?=ns(__('Test failed'))?>",
help:"<?=ns(__('Help'))?>",
help1:"<?=ns(__('Shows fax system status. Green:Running and idle, orange:Initializing, yellow:In use, red:Error'))?>",
help2:"<?=ns(__('Select one or more files to send by fax'))?>",
help3:"<?=ns(__('Enter a fax number or select from your contacts'))?>",
help4:"<?=ns(__('Add a memo to the fax'))?>",
help5:"<?=ns(__('Set a date and time to send the fax later'))?>",
help6:"<?=ns(__('Set the fax priority, Quick priority sends faster than normal'))?>"
};
window.PUSH_CONFIG={publicKey:"<?=PUSH_PUBLIC_KEY?>"};
</script>
<script src="include/js/base.js" defer></script>
<script src="include/js/modal.js" defer></script>
<script src="include/js/fax_send.js" defer></script>
<script>
const tAlertTitle=<?=json_encode(__('Alert'),JSON_UNESCAPED_UNICODE)?>;
const tSendFaxTitle=<?=json_encode(__('Send Fax'),JSON_UNESCAPED_UNICODE)?>;
const tErrorMsg=<?=json_encode(__('Error occurred'),JSON_UNESCAPED_UNICODE)?>;
const tSelectFileMsg=<?=json_encode(__('Please select at least one file'),JSON_UNESCAPED_UNICODE)?>;
const tEnterNumMsg=<?=json_encode(__('Please enter at least one fax number'),JSON_UNESCAPED_UNICODE)?>;
const tConfirmSendMsg=<?=json_encode(__('Do you want to send this fax?'),JSON_UNESCAPED_UNICODE)?>;
const tPublicText=<?=json_encode(__('Public'),JSON_UNESCAPED_UNICODE)?>;
const tUsersText=<?=json_encode(__('Users'),JSON_UNESCAPED_UNICODE)?>;
</script>
</head>
<body>
<div id="menuToggle">≡ <?php _nsl('Menu');?></div>
<div id="container">
<?php include('menu.php');?>
<div id="main">
<h2><?php _nsl('Send Fax');?></h2>
<div class="table-wrapper">
<form id="faxForm" enctype="multipart/form-data">
<input type="hidden" name="csrf" id="csrf_input" value="<?=$_SESSION['csrf']??''?>">
<input type="hidden" name="pagename" value="fax_send">
<table>
<thead><tr class="faxlist-top"><th colspan="2" class="send_status" style="position:relative;"><?php _nsl('Fax sending');?> <span class="help-text" data-help="help1"><span class="fax-status-badge"></span></span></th></tr></thead>
<tbody>
<tr class="<?=($rowCount++%2===0)?'row-alternate':'row-classic'?>">
<td class="label"><span class="help-text" data-help="help2"><?php _nsl('Files');?></span></span></td>
<td class="field">
<label for="fileInput" class="file-label"><?php _nsl('Select files');?></label>
<input type="file" id="fileInput" accept=".pdf,.jpg,.jpeg,.png,.gif,.heic,.svg,.bmp,.avif,.jfif,.webp,.tif,.tiff" multiple onchange="handleFiles(this)">
<div id="file-list" class="list-container"></div>
</td>
</tr>
<tr class="<?=($rowCount++%2===0)?'row-alternate':'row-classic'?>">
<td class="label"><span class="help-text" data-help="help3"><?php _nsl('Fax Number');?></span></td>
<td class="field">
<div class="input-group">
<input type="text" id="numInput" 
placeholder="<?=ns(__('Enter number or name'))?>" 
onkeypress="if(event.keyCode===13){addNumber();return false;}">
<div class="numinput_button_pc">
<button type="button" onclick="addNumber()"><?php _nsl('Add');?></button>
<?php if(has_permission('faxcontacts')):?>
<button type="button" onclick="openAddressBook()"><?php _nsl('Contacts');?></button>
<?php endif;?>
</div>
<div class="numinput_button_mobile">
<button type="button" onclick="addNumber()">A</button>
<?php if(has_permission('faxcontacts')):?>
<button type="button" onclick="openAddressBook()">C</button>
<?php endif;?>
</div>
</div>
<div id="num-list" class="list-container"></div>
</td>
</tr>
<?php if(has_permission('faxmemo')):?>
<tr class="<?=($rowCount++%2===0)?'row-alternate':'row-classic'?>">
<td class="label"><span class="help-text" data-help="help4"><?php _nsl('Fax Memo');?></span></td>
<td class="field">
<div class="input-group">
<input type="text" name="faxmemo" id="faxmemo" placeholder="<?=ns(__('Enter memo (optional)'))?>">
</div>
</td>
</tr>
<?php endif;?>
<?php if(has_permission('faxschedule')):?>
<tr class="<?=($rowCount++%2===0)?'row-alternate':'row-classic'?>">
<td class="label"><span class="help-text" data-help="help5"><?php _nsl('Schedule');?></span></td>
<td class="field"><input type="datetime-local" name="scheduletime" id="scheduletime"></td>
</tr>
<?php endif;?>
<?php if(has_permission('faxpriority')):?>
<tr class="<?=($rowCount++%2===0)?'row-alternate':'row-classic'?>">
<td class="label"><span class="help-text" data-help="help6"><?php _nsl('Priority');?></span></td>
<td class="field">
<label><input type="radio" name="priority" value="default" checked><?php _nsl('Normal');?></label>
<label><input type="radio" name="priority" value="high"><?php _nsl('Quick');?></label>
</td>
</tr>
<?php endif;?>
<tr><th colspan="2"><input type="button" value="<?=ns(__('Fax sending'))?>" class="send-btn" onclick="submitForm()"></th></tr>
</tbody>
</table>
</form>
</div></div></div>
<?php include('include/web/modal.php');?>
<?php include('include/web/footer.php');?>
</body>
</html>
