Highway to PSR2
[openemr.git] / interface / fax / faxq.php
blob2fc249ac03579e6eabf3164987bc5a50d69ee6a6
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' => xl('Blocked'),
14 'D' => xl('Sent successfully'),
15 'F' => xl('Failed'),
16 'P' => xl('Pending'),
17 'R' => xl('Send in progress'),
18 'S' => xl('Sleeping'),
19 'T' => xl('Suspended'),
20 'W' => xl('Waiting')
23 $mlines = array();
24 $dlines = array();
25 $slines = array();
27 if ($GLOBALS['enable_hylafax']) {
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;
40 ksort($mlines);
42 // Get the doneq entries, parse and sort by job ID
43 /* for example:
44 JID Pri S Owner Number Pages Dials TTS Status
45 155 123 D nobody 6158898622 1:1 5:12
46 153 124 D nobody 6158896439 1:1 4:12
47 154 124 F nobody 6153551807 0:1 4:12 No carrier detected
49 $donelines = array();
50 exec("faxstat -s -d -l -h " . $GLOBALS['hylafax_server'], $donelines);
51 foreach ($donelines as $line) {
52 // This gets jobid, priority, statchar, owner, phone, pages, dials and tts/status.
53 if (preg_match('/^(\d+)\s+(\d+)\s+(\S)\s+(\S+)\s+(\S+)\s+(\d+:\d+)\s+(\d+:\d+)(.*)$/', $line, $matches)) {
54 $dlines[$matches[1]] = $matches;
58 ksort($dlines);
61 $scandir = $GLOBALS['scanner_output_directory'];
62 if ($scandir && $GLOBALS['enable_scanner']) {
63 // Get the directory entries, parse and sort by date and time.
64 $dh = opendir($scandir);
65 if (! $dh) {
66 die("Cannot read $scandir");
69 while (false !== ($sfname = readdir($dh))) {
70 if (substr($sfname, 0, 1) == '.') {
71 continue;
74 $tmp = stat("$scandir/$sfname");
75 $tmp[0] = $sfname; // put filename in slot 0 which we don't otherwise need
76 $slines[$tmp[9] . $tmp[1]] = $tmp; // key is file mod time and inode number
79 closedir($dh);
80 ksort($slines);
84 <html>
86 <head>
87 <?php html_header_show();?>
89 <link rel="stylesheet" href='<?php echo $css_header ?>' type='text/css'>
90 <title><?php xl('Received Faxes', 'e'); ?></title>
92 <style>
93 td {
94 font-family: Arial, Helvetica, sans-serif;
95 padding-left: 4px;
96 padding-right: 4px;
98 a, a:visited, a:hover {
99 color:#0000cc;
101 tr.head {
102 font-size:10pt;
103 background-color:#cccccc;
104 font-weight: bold;
106 tr.detail {
107 font-size:10pt;
109 td.tabhead {
110 font-size: 11pt;
111 font-weight: bold;
112 height: 20pt;
113 text-align: center;
115 </style>
117 <script type="text/javascript" src="../../library/dialog.js?v=<?php echo $v_js_includes; ?>"></script>
119 <script language="JavaScript">
121 // Process click on a tab.
122 function tabclick(tabname) {
123 var tabs = new Array('faxin', 'faxout', 'scanin');
124 var visdisp = document.getElementById('bigtable').style.display;
125 for (var i in tabs) {
126 var thistd = document.getElementById('td_tab_' + tabs[i]);
127 var thistable = document.getElementById('table_' + tabs[i]);
128 if (tabs[i] == tabname) {
129 // thistd.style.borderBottom = '0px solid #000000';
130 thistd.style.borderBottom = '2px solid transparent';
131 thistd.style.color = '#cc0000';
132 thistd.style.cursor = 'default';
133 thistable.style.display = visdisp;
134 } else {
135 thistd.style.borderBottom = '2px solid #000000';
136 thistd.style.color = '#777777';
137 thistd.style.cursor = 'pointer';
138 thistable.style.display = 'none';
143 // Callback from popups to refresh this display.
144 function refreshme() {
145 location.reload();
148 // Process click on filename to view.
149 function dodclick(ffname) {
150 cascwin('fax_view.php?file=' + ffname, '_blank', 600, 475,
151 "resizable=1,scrollbars=1");
152 return false;
155 // Process click on Job ID to view.
156 function dojclick(jobid) {
157 cascwin('fax_view.php?jid=' + jobid, '_blank', 600, 475,
158 "resizable=1,scrollbars=1");
159 return false;
162 // Process scanned document filename to view.
163 function dosvclick(sfname) {
164 cascwin('fax_view.php?scan=' + sfname, '_blank', 600, 475,
165 "resizable=1,scrollbars=1");
166 return false;
169 // Process click to pop up the fax dispatch window.
170 function domclick(ffname) {
171 cascwin('fax_dispatch.php?file=' + ffname, '_blank', 850, 550,
172 "resizable=1,scrollbars=1");
175 // Process click to pop up the scanned document dispatch window.
176 function dosdclick(sfname) {
177 cascwin('fax_dispatch.php?scan=' + sfname, '_blank', 850, 550,
178 "resizable=1,scrollbars=1");
181 </script>
183 </head>
185 <body class="body_top">
186 <table cellspacing='0' cellpadding='0' style='margin: 0 0 0 0; border: 2px solid #000000;'
187 id='bigtable' width='100%' height='100%'>
188 <tr style='height: 20px;'>
189 <td width='33%' id='td_tab_faxin' class='tabhead'
190 <?php if ($GLOBALS['enable_hylafax']) { ?>
191 style='color: #cc0000; border-right: 2px solid #000000; border-bottom: 2px solid transparent;'
192 <?php } else { ?>
193 style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer; display:none;'
194 <?php } ?>
195 onclick='tabclick("faxin")'><?php xl('Faxes In', 'e'); ?></td>
196 <td width='33%' id='td_tab_faxout' class='tabhead'
197 <?php if ($GLOBALS['enable_hylafax']) { ?>
198 style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer;'
199 <?php } else { ?>
200 style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer; display:none;'
201 <?php } ?>
202 onclick='tabclick("faxout")'><?php xl('Faxes Out', 'e'); ?></td>
203 <td width='34%' id='td_tab_scanin' class='tabhead'
204 <?php if ($GLOBALS['enable_scanner']) { ?>
205 style='color: #777777; border-bottom: 2px solid #000000; cursor: pointer;'
206 <?php } else { ?>
207 style='color: #cc0000; border-bottom: 2px solid transparent; display:none;'
208 <?php } ?>
209 onclick='tabclick("scanin")'><?php xl('Scanner In', 'e'); ?></td>
210 </tr>
211 <tr>
212 <td colspan='3' style='padding: 5px;' valign='top'>
214 <form method='post' action='faxq.php'>
216 <table width='100%' cellpadding='1' cellspacing='2' id='table_faxin'
217 <?php if (!$GLOBALS['enable_hylafax']) {
218 echo "style='display:none;'";
219 } ?>>
220 <tr class='head'>
221 <td colspan='2' title='Click to view'><?php xl('Document', 'e'); ?></td>
222 <td><?php xl('Received', 'e'); ?></td>
223 <td><?php xl('From', 'e'); ?></td>
224 <td align='right'><?php xl('Pages', 'e'); ?></td>
225 </tr>
226 <?php
228 $encount = 0;
229 foreach ($mlines as $matches) {
230 ++$encount;
231 $ffname = $matches[4];
232 $ffbase = basename("/$ffname", '.tif');
233 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
234 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
235 echo " <td onclick='dodclick(\"$ffname\")'>";
236 echo "<a href='fax_view.php?file=$ffname' onclick='return false'>$ffbase</a></td>\n";
237 echo " <td onclick='domclick(\"$ffname\")'>";
238 echo "<a href='fax_dispatch.php?file=$ffname' onclick='return false'>" . xl('Dispatch', 'e') . "</a></td>\n";
239 echo " <td>" . htmlentities($matches[3]) . "</td>\n";
240 echo " <td>" . htmlentities($matches[2]) . "</td>\n";
241 echo " <td align='right'>" . htmlentities($matches[1]) . "</td>\n";
242 echo " </tr>\n";
245 </table>
247 <table width='100%' cellpadding='1' cellspacing='2' id='table_faxout'
248 style='display:none;'>
249 <tr class='head'>
250 <td title='Click to view'><?php xl('Job ID', 'e'); ?></td>
251 <td><?php xl('To', 'e'); ?></td>
252 <td><?php xl('Pages', 'e'); ?></td>
253 <td><?php xl('Dials', 'e'); ?></td>
254 <td><?php xl('TTS', 'e'); ?></td>
255 <td><?php xl('Status', 'e'); ?></td>
256 </tr>
257 <?php
258 $encount = 0;
259 foreach ($dlines as $matches) {
260 ++$encount;
261 $jobid = $matches[1];
262 $ffstatus = $faxstats[$matches[3]];
263 $fftts = '';
264 $ffstatend = trim($matches[8]);
265 if (preg_match('/^(\d+:\d+)\s*(.*)$/', $ffstatend, $tmp)) {
266 $fftts = $tmp[1];
267 $ffstatend = $tmp[2];
270 if ($ffstatend) {
271 $ffstatus .= ': ' . $ffstatend;
274 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
275 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
276 echo " <td onclick='dojclick(\"$jobid\")'>" .
277 "<a href='fax_view.php?jid=$jobid' onclick='return false'>" .
278 "$jobid</a></td>\n";
279 echo " <td>" . htmlentities($matches[5]) . "</td>\n";
280 echo " <td>" . htmlentities($matches[6]) . "</td>\n";
281 echo " <td>" . htmlentities($matches[7]) . "</td>\n";
282 echo " <td>" . htmlentities($fftts) . "</td>\n";
283 echo " <td>" . htmlentities($ffstatus) . "</td>\n";
284 echo " </tr>\n";
287 </table>
289 <table width='100%' cellpadding='1' cellspacing='2' id='table_scanin'
290 <?php if ($GLOBALS['enable_hylafax']) {
291 echo "style='display:none;'";
292 } ?>>
293 <tr class='head'>
294 <td colspan='2' title='Click to view'><?php xl('Filename', 'e'); ?></td>
295 <td><?php xl('Scanned', 'e'); ?></td>
296 <td align='right'><?php xl('Length', 'e'); ?></td>
297 </tr>
298 <?php
299 $encount = 0;
300 foreach ($slines as $sline) {
301 ++$encount;
302 $bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
303 $sfname = $sline[0]; // filename
304 $sfdate = date('Y-m-d H:i', $sline[9]);
305 echo " <tr class='detail' bgcolor='$bgcolor'>\n";
306 echo " <td onclick='dosvclick(\"$sfname\")'>" .
307 "<a href='fax_view.php?scan=$sfname' onclick='return false'>" .
308 "$sfname</a></td>\n";
309 echo " <td onclick='dosdclick(\"$sfname\")'>";
310 echo "<a href='fax_dispatch.php?scan=$sfname' onclick='return false'>" . xl('Dispatch', 'e') . "</a></td>\n";
311 echo " <td>$sfdate</td>\n";
312 echo " <td align='right'>" . $sline[7] . "</td>\n";
313 echo " </tr>\n";
316 </table>
318 </form>
320 </td>
321 </tr>
322 </table>
323 </body>
324 </html>