refinements and fixes to scanner support
[openemr.git] / interface / fax / faxq.php
blob593845ade590165c27fad8b6a10b0d77039ac80b
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 $faxstats = array(
13 'B' => 'Blocked',
14 'D' => 'Sent successfully',
15 'F' => 'Failed',
16 'P' => 'Pending',
17 'R' => 'Send in progress',
18 'S' => 'Sleeping',
19 'T' => 'Suspended',
20 'W' => 'Waiting',
23 $mlines = array();
24 $dlines = array();
25 $slines = array();
27 if ($GLOBALS['hylafax_server']) {
28 // Get the recvq entries, parse and sort by filename.
29 $statlines = array();
30 exec("faxstat -r -l -h " . $GLOBALS['hylafax_server'], $statlines);
31 foreach ($statlines as $line) {
32 // This gets pagecount, sender, time, filename. We are expecting the
33 // string to start with "-rw-rw-" so as to exclude faxes not yet fully
34 // received, for which permissions are "-rw----".
35 if (preg_match('/^-r\S\Sr\S\S\s+(\d+)\s+\S+\s+(.+)\s+(\S+)\s+(\S+)\s*$/', $line, $matches)) {
36 $mlines[$matches[4]] = $matches;
39 ksort($mlines);
41 // Get the doneq entries, parse and sort by job ID
42 /* for example:
43 JID Pri S Owner Number Pages Dials TTS Status
44 155 123 D nobody 6158898622 1:1 5:12
45 153 124 D nobody 6158896439 1:1 4:12
46 154 124 F nobody 6153551807 0:1 4:12 No carrier detected
48 $donelines = array();
49 exec("faxstat -s -d -l -h " . $GLOBALS['hylafax_server'], $donelines);
50 foreach ($donelines as $line) {
51 // This gets jobid, priority, statchar, owner, phone, pages, dials and tts/status.
52 if (preg_match('/^(\d+)\s+(\d+)\s+(\S)\s+(\S+)\s+(\S+)\s+(\d+:\d+)\s+(\d+:\d+)(.*)$/', $line, $matches)) {
53 $dlines[$matches[1]] = $matches;
56 ksort($dlines);
59 $scandir = $GLOBALS['scanner_output_directory'];
60 if ($scandir) {
61 // Get the directory entries, parse and sort by date and time.
62 $dh = opendir($scandir);
63 if (! $dh) die("Cannot read $scandir");
64 while (false !== ($sfname = readdir($dh))) {
65 if (substr($sfname, 0, 1) == '.') continue;
66 $tmp = stat("$scandir/$sfname");
67 $tmp[0] = $sfname; // put filename in slot 0 which we don't otherwise need
68 $slines[$tmp[9]] = $tmp; // key is file mod time
70 closedir($dh);
71 ksort($slines);
75 <html>
77 <head>
79 <link rel=stylesheet href='<? echo $css_header ?>' type='text/css'>
80 <title><? xl('Received Faxes','e'); ?></title>
82 <style>
83 td {
84 font-family: Arial, Helvetica, sans-serif;
85 padding-left: 4px;
86 padding-right: 4px;
88 a, a:visited, a:hover {
89 color:#0000cc;
91 tr.head {
92 font-size:10pt;
93 background-color:#cccccc;
94 font-weight: bold;
96 tr.detail {
97 font-size:10pt;
99 td.tabhead {
100 font-size: 11pt;
101 font-weight: bold;
102 height: 20pt;
103 text-align: center;
105 </style>
107 <script type="text/javascript" src="../../library/dialog.js"></script>
109 <script language="JavaScript">
111 // Process click on a tab.
112 function tabclick(tabname) {
113 var tabs = new Array('faxin', 'faxout', 'scanin');
114 var visdisp = document.getElementById('bigtable').style.display;
115 for (var i in tabs) {
116 var thistd = document.getElementById('td_tab_' + tabs[i]);
117 var thistable = document.getElementById('table_' + tabs[i]);
118 if (tabs[i] == tabname) {
119 // thistd.style.borderBottom = '0px solid #000000';
120 thistd.style.borderBottom = '2px solid transparent';
121 thistd.style.color = '#cc0000';
122 thistd.style.cursor = 'default';
123 thistable.style.display = visdisp;
124 } else {
125 thistd.style.borderBottom = '2px solid #000000';
126 thistd.style.color = '#777777';
127 thistd.style.cursor = 'pointer';
128 thistable.style.display = 'none';
133 // Callback from popups to refresh this display.
134 function refreshme() {
135 location.reload();
138 // Process click on filename to view.
139 function dodclick(ffname) {
140 cascwin('fax_view.php?file=' + ffname, '_blank', 600, 475,
141 "resizable=1,scrollbars=1");
142 return false;
145 // Process click on Job ID to view.
146 function dojclick(jobid) {
147 cascwin('fax_view.php?jid=' + jobid, '_blank', 600, 475,
148 "resizable=1,scrollbars=1");
149 return false;
152 // Process scanned document filename to view.
153 function dosvclick(sfname) {
154 cascwin('fax_view.php?scan=' + sfname, '_blank', 600, 475,
155 "resizable=1,scrollbars=1");
156 return false;
159 // Process click to pop up the fax dispatch window.
160 function domclick(ffname) {
161 dlgopen('fax_dispatch.php?file=' + ffname, '_blank', 850, 550);
164 // Process click to pop up the scanned document dispatch window.
165 function dosdclick(sfname) {
166 dlgopen('fax_dispatch.php?scan=' + sfname, '_blank', 850, 550);
169 </script>
171 </head>
173 <body <?echo $top_bg_line;?>>
174 <table cellspacing='0' cellpadding='0' style='margin: 0 0 0 0; border: 2px solid #000000;'
175 id='bigtable' width='100%' height='100%'>
176 <tr style='height: 20px;'>
177 <td width='33%' id='td_tab_faxin' class='tabhead'
178 <?php if ($GLOBALS['hylafax_server']) { ?>
179 style='color: #cc0000; border-right: 2px solid #000000; border-bottom: 2px solid transparent;'
180 <?php } else { ?>
181 style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer;'
182 <?php } ?>
183 onclick='tabclick("faxin")'>Faxes In</td>
184 <td width='33%' id='td_tab_faxout' class='tabhead'
185 style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer;'
186 onclick='tabclick("faxout")'>Faxes Out</td>
187 <td width='34%' id='td_tab_scanin' class='tabhead'
188 <?php if ($GLOBALS['hylafax_server']) { ?>
189 style='color: #777777; border-bottom: 2px solid #000000; cursor: pointer;'
190 <?php } else { ?>
191 style='color: #cc0000; border-bottom: 2px solid transparent;'
192 <?php } ?>
193 onclick='tabclick("scanin")'>Scanner In</td>
194 </tr>
195 <tr>
196 <td colspan='3' style='padding: 5px;' valign='top'>
198 <form method='post' action='faxq.php'>
200 <table width='100%' cellpadding='1' cellspacing='2' id='table_faxin'
201 <?php if (!$GLOBALS['hylafax_server']) echo "style='display:none;'"; ?>>
202 <tr class='head'>
203 <td colspan='2' title='Click to view'><? xl('Document','e'); ?></td>
204 <td><? xl('Received','e'); ?></td>
205 <td><? xl('From','e'); ?></td>
206 <td align='right'><? xl('Pages','e'); ?></td>
207 </tr>
209 $encount = 0;
210 foreach ($mlines as $matches) {
211 ++$encount;
212 $ffname = $matches[4];
213 $ffbase = basename("/$ffname", '.tif');
214 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
215 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
216 echo " <td onclick='dodclick(\"$ffname\")'>";
217 echo "<a href='fax_view.php?file=$ffname' onclick='return false'>$ffbase</a></td>\n";
218 echo " <td onclick='domclick(\"$ffname\")'>";
219 echo "<a href='fax_dispatch.php?file=$ffname' onclick='return false'>Dispatch</a></td>\n";
220 echo " <td>" . htmlentities($matches[3]) . "</td>\n";
221 echo " <td>" . htmlentities($matches[2]) . "</td>\n";
222 echo " <td align='right'>" . htmlentities($matches[1]) . "</td>\n";
223 echo " </tr>\n";
226 </table>
228 <table width='100%' cellpadding='1' cellspacing='2' id='table_faxout'
229 style='display:none;'>
230 <tr class='head'>
231 <td title='Click to view'><? xl('Job ID','e'); ?></td>
232 <td><? xl('To','e'); ?></td>
233 <td><? xl('Pages','e'); ?></td>
234 <td><? xl('Dials','e'); ?></td>
235 <td><? xl('TTS','e'); ?></td>
236 <td><? xl('Status','e'); ?></td>
237 </tr>
239 $encount = 0;
240 foreach ($dlines as $matches) {
241 ++$encount;
242 $jobid = $matches[1];
243 $ffstatus = $faxstats[$matches[3]];
244 $fftts = '';
245 $ffstatend = trim($matches[8]);
246 if (preg_match('/^(\d+:\d+)\s*(.*)$/', $ffstatend, $tmp)) {
247 $fftts = $tmp[1];
248 $ffstatend = $tmp[2];
250 if ($ffstatend) $ffstatus .= ': ' . $ffstatend;
251 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
252 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
253 echo " <td onclick='dojclick(\"$jobid\")'>" .
254 "<a href='fax_view.php?jid=$jobid' onclick='return false'>" .
255 "$jobid</a></td>\n";
256 echo " <td>" . htmlentities($matches[5]) . "</td>\n";
257 echo " <td>" . htmlentities($matches[6]) . "</td>\n";
258 echo " <td>" . htmlentities($matches[7]) . "</td>\n";
259 echo " <td>" . htmlentities($fftts) . "</td>\n";
260 echo " <td>" . htmlentities($ffstatus) . "</td>\n";
261 echo " </tr>\n";
264 </table>
266 <table width='100%' cellpadding='1' cellspacing='2' id='table_scanin'
267 <?php if ($GLOBALS['hylafax_server']) echo "style='display:none;'"; ?>>
268 <tr class='head'>
269 <td colspan='2' title='Click to view'><? xl('Filename','e'); ?></td>
270 <td><? xl('Scanned','e'); ?></td>
271 <td align='right'><? xl('Length','e'); ?></td>
272 </tr>
274 $encount = 0;
275 foreach ($slines as $sline) {
276 ++$encount;
277 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
278 $sfname = $sline[0]; // filename
279 $sfdate = date('Y-m-d H:i', $sline[9]);
280 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
281 echo " <td onclick='dosvclick(\"$sfname\")'>" .
282 "<a href='fax_view.php?scan=$sfname' onclick='return false'>" .
283 "$sfname</a></td>\n";
284 echo " <td onclick='dosdclick(\"$sfname\")'>";
285 echo "<a href='fax_dispatch.php?scan=$sfname' onclick='return false'>Dispatch</a></td>\n";
286 echo " <td>$sfdate</td>\n";
287 echo " <td align='right'>" . $sline[7] . "</td>\n";
288 echo " </tr>\n";
291 </table>
293 </form>
295 </td>
296 </tr>
297 </table>
298 </body>
299 </html>