<?php
require_once('config.php');
if(!isset($_SESSION['user'])||!has_permission('faxdashboard')){header("Location:login.php");exit;}
if(!function_exists('safe_exec')){
function safe_exec(string $cmd,array $args=[]):string{
$allowed=['faxstat'];
if(!in_array($cmd,$allowed))return'';
$escapedArgs=array_map('escapeshellarg',$args);
return trim(shell_exec($cmd.' '.implode(' ',$escapedArgs).' 2>&1')??'');
}}
$faxstatRaw=safe_exec('faxstat',['-s']);
if($faxstatRaw===''||stripos($faxstatRaw,'error')!==false){$faxstatRaw='';}
$sendQueueLines=[];
$inQueue=false;
foreach(explode("\n",$faxstatRaw) as $line){
$line=trim($line);
if(str_starts_with($line,'JID')){$inQueue=true;continue;}
if($inQueue&&$line!==''){$sendQueueLines[]=$line;}
}
$rows=[];
foreach($sendQueueLines as $line){
$parts=preg_split('/\s+/',$line,8);
if(count($parts)>=7){
$rows[]=[
'JID'=>$parts[0],
'Number'=>$parts[4],
'Pages'=>$parts[5],
'Dials'=>$parts[6],
'Status'=>$parts[7]??''
];
}}
?>
<!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('Fax Dashboard');?></title>
<link rel="stylesheet" href="include/css/style.css">
<?php include('include/web/header.php');?>
<script>
window.FAX_LANG={
ok:"<?=ns(__('Ok'))?>",
cancel:"<?=ns(__('Cancel'))?>",
faxMemo:"<?=ns(__('Fax Memo'))?>",
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'))?>"
};
window.PUSH_CONFIG={publicKey:"<?=PUSH_PUBLIC_KEY?>"};
</script>
<script src="include/js/base.js" defer></script>
<script src="include/js/modal.js" defer></script>
</head>
<body>
<div id="menuToggle">≡ <?php _nsl('Menu');?></div>
<div id="container">
<?php include('menu.php');?>
<div id="main">
<h2><?php _nsl('Fax Dashboard');?></h2>
<div class="table-wrapper">
<table>
<thead><tr><th colspan="5"><?php _nsl('Outgoing Queue');?></th></tr></thead>
<tbody>
<?php if(!$rows):?>
<tr class="row-alternate"><td colspan="5" class="web-msg"><?php _nsl('No faxes in the outgoing queue');?></td></tr>
<?php else:foreach($rows as $i=>$r):?>
<tr class="<?=($i%2)?'row-classic':'row-alternate'?>">
<td><?=ns($r['JID'])?></td>
<td><?=ns($r['Number'])?></td>
<td><?=ns($r['Pages'])?></td>
<td><?=ns($r['Dials'])?></td>
<td><small><?=ns($r['Status'])?></small></td>
</tr>
<?php endforeach;endif;?>
</tbody>
<tfoot>
<tr><th colspan="5"><input type="button" value="<?php _nsl('Back');?>" class="send-btn" onclick="location.href='index.php';"></th></tr>
</tfoot>
</table>
</div></div></div>
<?php include('include/web/modal.php');?>
<?php include('include/web/footer.php');?>
</body>
</html>
