Fixes for restoreSession logic. (#4378)
[openemr.git] / interface / fax / faxq.php
blob9d8747095a0efb54af4a007e4a258c8b7e420e55
1 <?php
3 // Copyright (C) 2006 Rod Roark <rod@sunsetsystems.com>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 require_once("../globals.php");
12 use OpenEMR\Common\Csrf\CsrfUtils;
13 use OpenEMR\Core\Header;
15 $faxstats = array(
16 'B' => xl('Blocked'),
17 'D' => xl('Sent successfully'),
18 'F' => xl('Failed'),
19 'P' => xl('Pending'),
20 'R' => xl('Send in progress'),
21 'S' => xl('Sleeping'),
22 'T' => xl('Suspended'),
23 'W' => xl('Waiting')
26 $mlines = array();
27 $dlines = array();
28 $slines = array();
30 if ($GLOBALS['enable_hylafax']) {
31 // Get the recvq entries, parse and sort by filename.
32 $statlines = array();
33 exec("faxstat -r -l -h " . escapeshellarg($GLOBALS['hylafax_server']), $statlines);
34 foreach ($statlines as $line) {
35 // This gets pagecount, sender, time, filename. We are expecting the
36 // string to start with "-rw-rw-" so as to exclude faxes not yet fully
37 // received, for which permissions are "-rw----".
38 if (preg_match('/^-r\S\Sr\S\S\s+(\d+)\s+\S+\s+(.+)\s+(\S+)\s+(\S+)\s*$/', $line, $matches)) {
39 $mlines[$matches[4]] = $matches;
43 ksort($mlines);
45 // Get the doneq entries, parse and sort by job ID
46 /* for example:
47 JID Pri S Owner Number Pages Dials TTS Status
48 155 123 D nobody 6158898622 1:1 5:12
49 153 124 D nobody 6158896439 1:1 4:12
50 154 124 F nobody 6153551807 0:1 4:12 No carrier detected
52 $donelines = array();
53 exec("faxstat -s -d -l -h " . escapeshellarg($GLOBALS['hylafax_server']), $donelines);
54 foreach ($donelines as $line) {
55 // This gets jobid, priority, statchar, owner, phone, pages, dials and tts/status.
56 if (preg_match('/^(\d+)\s+(\d+)\s+(\S)\s+(\S+)\s+(\S+)\s+(\d+:\d+)\s+(\d+:\d+)(.*)$/', $line, $matches)) {
57 $dlines[$matches[1]] = $matches;
61 ksort($dlines);
64 $scandir = $GLOBALS['scanner_output_directory'];
65 if ($scandir && $GLOBALS['enable_scanner']) {
66 // Get the directory entries, parse and sort by date and time.
67 $dh = opendir($scandir);
68 if (! $dh) {
69 die("Cannot read " . text($scandir));
72 while (false !== ($sfname = readdir($dh))) {
73 if (substr($sfname, 0, 1) == '.') {
74 continue;
77 $tmp = stat("$scandir/$sfname");
78 $tmp[0] = $sfname; // put filename in slot 0 which we don't otherwise need
79 $slines[$tmp[9] . $tmp[1]] = $tmp; // key is file mod time and inode number
82 closedir($dh);
83 ksort($slines);
87 <html>
89 <head>
91 <?php Header::setupHeader(['opener']);?>
92 <title><?php echo xlt('Received Faxes'); ?></title>
94 <style>
95 td {
96 font-family: "Arial", "Helvetica", sans-serif;
97 padding-left: 4px;
98 padding-right: 4px;
100 tr.head {
101 font-size: 0.8125rem;
102 background-color: var(--light);
103 font-weight: bold;
105 tr.detail {
106 font-size: 0.8125rem;
108 td.tabhead {
109 font-size: 0.9375rem;
110 font-weight: bold;
111 height: 1.6875rem;
112 text-align: center;
114 </style>
116 <script>
118 // Process click on a tab.
119 function tabclick(tabname) {
120 var tabs = new Array('faxin', 'faxout', 'scanin');
121 var visdisp = document.getElementById('bigtable').style.display;
122 for (var i in tabs) {
123 var thistd = document.getElementById('td_tab_' + tabs[i]);
124 var thistable = document.getElementById('table_' + tabs[i]);
125 if (tabs[i] == tabname) {
126 // thistd.style.borderBottom = '0px solid var(--black)';
127 thistd.style.borderBottom = '2px solid transparent';
128 thistd.style.color = 'var(--danger)';
129 thistd.style.cursor = 'default';
130 thistable.style.display = visdisp;
131 } else {
132 thistd.style.borderBottom = '2px solid var(--black)';
133 thistd.style.color = 'var(--gray)';
134 thistd.style.cursor = 'pointer';
135 thistable.style.display = 'none';
140 // Callback from popups to refresh this display.
141 function refreshme() {
142 location.reload();
145 // Process click on filename to view.
146 function dodclick(ffname) {
147 cascwin('fax_view.php?file=' + encodeURIComponent(ffname) + '&csrf_token_form=' + <?php echo js_url(CsrfUtils::collectCsrfToken()); ?>, '_blank', 600, 475,
148 "resizable=1,scrollbars=1");
149 return false;
152 // Process click on Job ID to view.
153 function dojclick(jobid) {
154 cascwin('fax_view.php?jid=' + encodeURIComponent(jobid) + '&csrf_token_form=' + <?php echo js_url(CsrfUtils::collectCsrfToken()); ?>, '_blank', 600, 475,
155 "resizable=1,scrollbars=1");
156 return false;
159 // Process scanned document filename to view.
160 function dosvclick(sfname) {
161 cascwin('fax_view.php?scan=' + encodeURIComponent(sfname) + '&csrf_token_form=' + <?php echo js_url(CsrfUtils::collectCsrfToken()); ?>, '_blank', 600, 475,
162 "resizable=1,scrollbars=1");
163 return false;
166 // Process click to pop up the fax dispatch window.
167 function domclick(ffname) {
168 dlgopen('fax_dispatch.php?file=' + encodeURIComponent(ffname) + '&csrf_token_form=' + <?php echo js_url(CsrfUtils::collectCsrfToken()); ?>, '_blank', 850, 550, '', 'Fax Dispatch');
171 // Process click to pop up the scanned document dispatch window.
172 function dosdclick(sfname) {
173 dlgopen('fax_dispatch.php?scan=' + encodeURIComponent(sfname) + '&csrf_token_form=' + <?php echo js_url(CsrfUtils::collectCsrfToken()); ?>, '_blank', 850, 550, '', 'Scanned Dispatch');
176 </script>
178 </head>
180 <body class="body_top">
181 <table class='w-100 h-100' cellspacing='0' cellpadding='0' style='margin: 0; border: 2px solid var(--black);' id='bigtable'>
182 <tr style='height: 20px;'>
183 <td width='33%' id='td_tab_faxin' class='tabhead'
184 <?php if ($GLOBALS['enable_hylafax']) { ?>
185 style='color: var(--danger); border-right: 2px solid var(--black); border-bottom: 2px solid transparent;'
186 <?php } else { ?>
187 style='color: var(--gray); border-right: 2px solid var(--black); border-bottom: 2px solid var(--black); cursor: pointer; display:none;'
188 <?php } ?>
189 onclick='tabclick("faxin")'><?php echo xlt('Faxes In'); ?></td>
190 <td width='33%' id='td_tab_faxout' class='tabhead'
191 <?php if ($GLOBALS['enable_hylafax']) { ?>
192 style='color: var(--gray); border-right: 2px solid var(--black); border-bottom: 2px solid var(--black); cursor: pointer;'
193 <?php } else { ?>
194 style='color: var(--gray); border-right: 2px solid var(--black); border-bottom: 2px solid var(--black); cursor: pointer; display:none;'
195 <?php } ?>
196 onclick='tabclick("faxout")'><?php echo xlt('Faxes Out'); ?></td>
197 <td width='34%' id='td_tab_scanin' class='tabhead'
198 <?php if ($GLOBALS['enable_scanner']) { ?>
199 style='color: var(--gray); border-bottom: 2px solid var(--black); cursor: pointer;'
200 <?php } else { ?>
201 style='color: var(--danger); border-bottom: 2px solid transparent; display:none;'
202 <?php } ?>
203 onclick='tabclick("scanin")'><?php echo xlt('Scanner In'); ?></td>
204 </tr>
205 <tr>
206 <td colspan='3' style='padding: 5px;' valign='top'>
208 <form method='post' action='faxq.php'>
210 <table class='w-100' cellpadding='1' cellspacing='2' id='table_faxin'
211 <?php if (!$GLOBALS['enable_hylafax']) {
212 echo "style='display:none;'";
213 } ?>>
214 <tr class='head'>
215 <td colspan='2' title='Click to view'><?php echo xlt('Document'); ?></td>
216 <td><?php echo xlt('Received'); ?></td>
217 <td><?php echo xlt('From'); ?></td>
218 <td align='right'><?php echo xlt('Pages'); ?></td>
219 </tr>
220 <?php
222 $encount = 0;
223 foreach ($mlines as $matches) {
224 ++$encount;
225 $ffname = $matches[4];
226 $ffbase = basename("/$ffname", '.tif');
227 $bgcolor = (($encount & 1) ? "#ddddff" : "#ffdddd");
228 echo " <tr class='detail' bgcolor='" . attr($bgcolor) . "'>\n";
229 echo " <td onclick='dodclick(\"" . attr(addslashes($ffname)) . "\")'>";
230 echo "<a href='fax_view.php?file=" . attr_url($ffname) . "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "' onclick='return false'>" . text($ffbase) . "</a></td>\n";
231 echo " <td onclick='domclick(\"" . attr(addslashes($ffname)) . "\")'>";
232 echo "<a href='fax_dispatch.php?file=" . attr_url($ffname) . "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "' onclick='return false'>" . xlt('Dispatch') . "</a></td>\n";
233 echo " <td>" . text($matches[3]) . "</td>\n";
234 echo " <td>" . text($matches[2]) . "</td>\n";
235 echo " <td align='right'>" . text($matches[1]) . "</td>\n";
236 echo " </tr>\n";
239 </table>
241 <table class='w-100' cellpadding='1' cellspacing='2' id='table_faxout'
242 style='display:none;'>
243 <tr class='head'>
244 <td title='Click to view'><?php echo xlt('Job ID'); ?></td>
245 <td><?php echo xlt('To{{Destination}}'); ?></td>
246 <td><?php echo xlt('Pages'); ?></td>
247 <td><?php echo xlt('Dials'); ?></td>
248 <td><?php echo xlt('TTS'); ?></td>
249 <td><?php echo xlt('Status'); ?></td>
250 </tr>
251 <?php
252 $encount = 0;
253 foreach ($dlines as $matches) {
254 ++$encount;
255 $jobid = $matches[1];
256 $ffstatus = $faxstats[$matches[3]];
257 $fftts = '';
258 $ffstatend = trim($matches[8]);
259 if (preg_match('/^(\d+:\d+)\s*(.*)$/', $ffstatend, $tmp)) {
260 $fftts = $tmp[1];
261 $ffstatend = $tmp[2];
264 if ($ffstatend) {
265 $ffstatus .= ': ' . $ffstatend;
268 $bgcolor = (($encount & 1) ? "#ddddff" : "#ffdddd");
269 echo " <tr class='detail' bgcolor='" . attr($bgcolor) . "'>\n";
270 echo " <td onclick='dojclick(\"" . attr(addslashes($jobid)) . "\")'>" .
271 "<a href='fax_view.php?jid=" . attr_url($jobid) . "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "' onclick='return false'>" .
272 "$jobid</a></td>\n";
273 echo " <td>" . text($matches[5]) . "</td>\n";
274 echo " <td>" . text($matches[6]) . "</td>\n";
275 echo " <td>" . text($matches[7]) . "</td>\n";
276 echo " <td>" . text($fftts) . "</td>\n";
277 echo " <td>" . text($ffstatus) . "</td>\n";
278 echo " </tr>\n";
281 </table>
283 <table class='w-100' cellpadding='1' cellspacing='2' id='table_scanin'
284 <?php if ($GLOBALS['enable_hylafax']) {
285 echo "style='display:none;'";
286 } ?>>
287 <tr class='head'>
288 <td colspan='2' title='Click to view'><?php echo xlt('Filename'); ?></td>
289 <td><?php echo xlt('Scanned'); ?></td>
290 <td align='right'><?php echo xlt('Length'); ?></td>
291 </tr>
292 <?php
293 $encount = 0;
294 foreach ($slines as $sline) {
295 ++$encount;
296 $bgcolor = (($encount & 1) ? "#ddddff" : "#ffdddd");
297 $sfname = $sline[0]; // filename
298 $sfdate = date('Y-m-d H:i', $sline[9]);
299 echo " <tr class='detail' bgcolor='" . attr($bgcolor) . "'>\n";
300 echo " <td onclick='dosvclick(\"" . attr(addslashes($sfname)) . "\")'>" .
301 "<a href='fax_view.php?scan=" . attr_url($sfname) . "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "' onclick='return false'>" .
302 "$sfname</a></td>\n";
303 echo " <td onclick='dosdclick(\"" . attr(addslashes($sfname)) . "\")'>";
304 echo "<a href='fax_dispatch.php?scan=" . attr_url($sfname) . "&csrf_token_form=" . attr_url(CsrfUtils::collectCsrfToken()) . "' onclick='return false'>" . xlt('Dispatch') . "</a></td>\n";
305 echo " <td>" . text($sfdate) . "</td>\n";
306 echo " <td align='right'>" . text($sline[7]) . "</td>\n";
307 echo " </tr>\n";
310 </table>
312 </form>
314 </td>
315 </tr>
316 </table>
317 </body>
318 </html>