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