Skip to content

Commit

Permalink
refinements and fixes to scanner support
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsetsystems committed Oct 12, 2006
1 parent c293d05 commit 6d1b0e3
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 55 deletions.
49 changes: 38 additions & 11 deletions interface/fax/fax_dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@
include_once("$srcdir/patient.inc");
include_once("$srcdir/pnotes.inc");

$filename = escapeshellcmd($_GET['file']);
$filepath = $GLOBALS['hylafax_basedir'] . '/recvq/' . $filename;
$filebase = basename("/$filename", '.tif');
$faxcache = "$webserver_root/faxcache/$filebase";
if ($_GET['file']) {
$mode = 'fax';
// $filename = escapeshellcmd($_GET['file']);
$filename = $_GET['file'];
$filepath = $GLOBALS['hylafax_basedir'] . '/recvq/' . $filename;
}
else if ($_GET['scan']) {
$mode = 'scan';
// $filename = escapeshellcmd($_GET['scan']);
$filename = $_GET['scan'];
$filepath = $GLOBALS['scanner_output_directory'] . '/' . $filename;
}
else {
die("No filename was given.");
}

$ext = substr($filename, strrpos($filename, '.'));
$filebase = basename("/$filename", $ext);
$faxcache = "$webserver_root/faxcache/$mode/$filebase";

$info_msg = "";

Expand Down Expand Up @@ -208,13 +223,24 @@ function mergeTiffs() {
// If we get this far then we are displaying the form.

// If the image cache does not yet exist for this fax, build it.
// This will contain a .tif image as well as a .jpg image for each page.
if (! is_dir($faxcache)) {
$tmp0 = exec("mkdir -p '$faxcache'", $tmp1, $tmp2);
if ($tmp2) die("mkdir returned $tmp2: $tmp0");
$tmp0 = exec("cd '$faxcache'; tiffsplit '$filepath'", $tmp1, $tmp2);
if ($tmp2) die("tiffsplit returned $tmp2: $tmp0");
if (strtolower($ext) != '.tif') {
// convert's default density for PDF-to-TIFF conversion is 72 dpi which is
// not very good, so we upgrade it to "fine mode" fax quality. It's really
// better and faster if the scanner produces TIFFs instead of PDFs.
$tmp0 = exec("convert -density 203x196 '$filepath' '$faxcache/deleteme.tif'", $tmp1, $tmp2);
if ($tmp2) die("convert returned $tmp2: $tmp0");
$tmp0 = exec("cd '$faxcache'; tiffsplit 'deleteme.tif'; rm -f 'deleteme.tif'", $tmp1, $tmp2);
if ($tmp2) die("tiffsplit/rm returned $tmp2: $tmp0");
} else {
$tmp0 = exec("cd '$faxcache'; tiffsplit '$filepath'", $tmp1, $tmp2);
if ($tmp2) die("tiffsplit returned $tmp2: $tmp0");
}
$tmp0 = exec("cd '$faxcache'; mogrify -resize 750x970 -format jpg *.tif", $tmp1, $tmp2);
if ($tmp2) die("mogrify returned $tmp2: $tmp0");
if ($tmp2) die("mogrify returned $tmp2: $tmp0; ext is '$ext'; filepath is '$filepath'");
}

// Get the categories list.
Expand Down Expand Up @@ -361,7 +387,8 @@ function validate() {

<center><h2>Dispatch Received Document</h2></center>

<form method='post' name='theform' action='fax_dispatch.php?file=<? echo $filename ?>'
<form method='post' name='theform'
action='fax_dispatch.php?<?php echo ($mode == 'fax') ? 'file' : 'scan'; ?>=<?php echo $filename ?>'
onsubmit='return validate()'>

<p><input type='checkbox' name='form_cb_copy' value='1'
Expand Down Expand Up @@ -396,7 +423,7 @@ function validate() {
<td class='itemtitle' nowrap>Filename</td>
<td>
<input type='text' size='10' name='form_filename' style='width:100%'
value='<? echo $filename ?>'
value='<? echo "$filebase.pdf" ?>'
title='Name for this document in the patient chart' />
</td>
</tr>
Expand Down Expand Up @@ -495,7 +522,7 @@ function validate() {
</div><!-- end div_forward -->

<p><input type='checkbox' name='form_cb_delete' value='1' />
<b>Delete Fax from Queue</b></p>
<b>Delete Document from Queue</b></p>

<center>
<p>
Expand All @@ -517,7 +544,7 @@ function validate() {
$jfnamebase = $matches[1];
echo " <tr>\n";
echo " <td valign='top'>\n";
echo " <img src='../../faxcache/$filebase/$jfname' />\n";
echo " <img src='../../faxcache/$mode/$filebase/$jfname' />\n";
echo " </td>\n";
echo " <td align='center' valign='top'>\n";
echo " <input type='checkbox' name='form_images[]' value='$jfnamebase' />\n";
Expand Down
9 changes: 7 additions & 2 deletions interface/fax/fax_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
die(xl("Cannot find postscript document reference in ") . $jfname);
}
}
else if ($_GET['scan']) {
$ffname = $GLOBALS['scanner_output_directory'] . '/' . $_GET['scan'];
}
else {
$ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . $_GET['file'];
}
Expand All @@ -50,9 +53,11 @@

$ext = substr($ffname, strrpos($ffname, '.'));
if ($ext == '.ps')
passthru("TMPDIR=/tmp ps2pdf $ffname -");
passthru("TMPDIR=/tmp ps2pdf '$ffname' -");
else if ($ext == '.pdf' || $ext == '.PDF')
readfile($ffname);
else
passthru("tiff2pdf $ffname");
passthru("tiff2pdf '$ffname'");

header("Pragma: public");
header("Expires: 0");
Expand Down
128 changes: 93 additions & 35 deletions interface/fax/faxq.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,56 @@
'W' => 'Waiting',
);

// Get the recvq entries, parse and sort by filename.
//
$statlines = array();
exec("faxstat -r -l -h " . $GLOBALS['hylafax_server'], $statlines);
$mlines = array();
foreach ($statlines as $line) {
// This gets pagecount, sender, time, filename. We are expecting the
// string to start with "-rw-rw-" so as to exclude faxes not yet fully
// received, for which permissions are "-rw----".
if (preg_match('/^-r\S\Sr\S\S\s+(\d+)\s+\S+\s+(.+)\s+(\S+)\s+(\S+)\s*$/', $line, $matches)) {
$mlines[$matches[4]] = $matches;
$dlines = array();
$slines = array();

if ($GLOBALS['hylafax_server']) {
// Get the recvq entries, parse and sort by filename.
$statlines = array();
exec("faxstat -r -l -h " . $GLOBALS['hylafax_server'], $statlines);
foreach ($statlines as $line) {
// This gets pagecount, sender, time, filename. We are expecting the
// string to start with "-rw-rw-" so as to exclude faxes not yet fully
// received, for which permissions are "-rw----".
if (preg_match('/^-r\S\Sr\S\S\s+(\d+)\s+\S+\s+(.+)\s+(\S+)\s+(\S+)\s*$/', $line, $matches)) {
$mlines[$matches[4]] = $matches;
}
}
}
ksort($mlines);
ksort($mlines);

// Get the doneq entries, parse and sort by job ID
//
/* for example:
JID Pri S Owner Number Pages Dials TTS Status
155 123 D nobody 6158898622 1:1 5:12
153 124 D nobody 6158896439 1:1 4:12
154 124 F nobody 6153551807 0:1 4:12 No carrier detected
*/
$donelines = array();
exec("faxstat -s -d -l -h " . $GLOBALS['hylafax_server'], $donelines);
$dlines = array();
foreach ($donelines as $line) {
// This gets jobid, priority, statchar, owner, phone, pages, dials and tts/status.
if (preg_match('/^(\d+)\s+(\d+)\s+(\S)\s+(\S+)\s+(\S+)\s+(\d+:\d+)\s+(\d+:\d+)(.*)$/', $line, $matches)) {
$dlines[$matches[1]] = $matches;
// Get the doneq entries, parse and sort by job ID
/* for example:
JID Pri S Owner Number Pages Dials TTS Status
155 123 D nobody 6158898622 1:1 5:12
153 124 D nobody 6158896439 1:1 4:12
154 124 F nobody 6153551807 0:1 4:12 No carrier detected
*/
$donelines = array();
exec("faxstat -s -d -l -h " . $GLOBALS['hylafax_server'], $donelines);
foreach ($donelines as $line) {
// This gets jobid, priority, statchar, owner, phone, pages, dials and tts/status.
if (preg_match('/^(\d+)\s+(\d+)\s+(\S)\s+(\S+)\s+(\S+)\s+(\d+:\d+)\s+(\d+:\d+)(.*)$/', $line, $matches)) {
$dlines[$matches[1]] = $matches;
}
}
ksort($dlines);
}
ksort($dlines);

// echo "<!--\n"; print_r($statlines); echo "-->\n"; // debugging
$scandir = $GLOBALS['scanner_output_directory'];
if ($scandir) {
// Get the directory entries, parse and sort by date and time.
$dh = opendir($scandir);
if (! $dh) die("Cannot read $scandir");
while (false !== ($sfname = readdir($dh))) {
if (substr($sfname, 0, 1) == '.') continue;
$tmp = stat("$scandir/$sfname");
$tmp[0] = $sfname; // put filename in slot 0 which we don't otherwise need
$slines[$tmp[9]] = $tmp; // key is file mod time
}
closedir($dh);
ksort($slines);
}

?>
<html>
Expand Down Expand Up @@ -134,11 +149,23 @@ function dojclick(jobid) {
return false;
}

// Process click to pop up the dispatch window.
// Process scanned document filename to view.
function dosvclick(sfname) {
cascwin('fax_view.php?scan=' + sfname, '_blank', 600, 475,
"resizable=1,scrollbars=1");
return false;
}

// Process click to pop up the fax dispatch window.
function domclick(ffname) {
dlgopen('fax_dispatch.php?file=' + ffname, '_blank', 850, 550);
}

// Process click to pop up the scanned document dispatch window.
function dosdclick(sfname) {
dlgopen('fax_dispatch.php?scan=' + sfname, '_blank', 850, 550);
}

</script>

</head>
Expand All @@ -148,21 +175,30 @@ function domclick(ffname) {
id='bigtable' width='100%' height='100%'>
<tr style='height: 20px;'>
<td width='33%' id='td_tab_faxin' class='tabhead'
<?php if ($GLOBALS['hylafax_server']) { ?>
style='color: #cc0000; border-right: 2px solid #000000; border-bottom: 2px solid transparent;'
<?php } else { ?>
style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer;'
<?php } ?>
onclick='tabclick("faxin")'>Faxes In</td>
<td width='33%' id='td_tab_faxout' class='tabhead'
style='color: #777777; border-right: 2px solid #000000; border-bottom: 2px solid #000000; cursor: pointer;'
onclick='tabclick("faxout")'>Faxes Out</td>
<td width='34%' id='td_tab_scanin' class='tabhead'
<?php if ($GLOBALS['hylafax_server']) { ?>
style='color: #777777; border-bottom: 2px solid #000000; cursor: pointer;'
<?php } else { ?>
style='color: #cc0000; border-bottom: 2px solid transparent;'
<?php } ?>
onclick='tabclick("scanin")'>Scanner In</td>
</tr>
<tr>
<td colspan='3' style='padding: 5px;' valign='top'>

<form method='post' action='faxq.php'>

<table width='100%' cellpadding='1' cellspacing='2' id='table_faxin'>
<table width='100%' cellpadding='1' cellspacing='2' id='table_faxin'
<?php if (!$GLOBALS['hylafax_server']) echo "style='display:none;'"; ?>>
<tr class='head'>
<td colspan='2' title='Click to view'><? xl('Document','e'); ?></td>
<td><? xl('Received','e'); ?></td>
Expand All @@ -189,7 +225,8 @@ function domclick(ffname) {
?>
</table>

<table width='100%' cellpadding='1' cellspacing='2' id='table_faxout' style='display:none;'>
<table width='100%' cellpadding='1' cellspacing='2' id='table_faxout'
style='display:none;'>
<tr class='head'>
<td title='Click to view'><? xl('Job ID','e'); ?></td>
<td><? xl('To','e'); ?></td>
Expand Down Expand Up @@ -226,10 +263,31 @@ function domclick(ffname) {
?>
</table>

<table width='100%' cellpadding='1' cellspacing='2' id='table_scanin' style='display:none;'>
<tr class='detail'>
<td>Not yet implemented.</td>
<table width='100%' cellpadding='1' cellspacing='2' id='table_scanin'
<?php if ($GLOBALS['hylafax_server']) echo "style='display:none;'"; ?>>
<tr class='head'>
<td colspan='2' title='Click to view'><? xl('Filename','e'); ?></td>
<td><? xl('Scanned','e'); ?></td>
<td align='right'><? xl('Length','e'); ?></td>
</tr>
<?
$encount = 0;
foreach ($slines as $sline) {
++$encount;
$bgcolor = "#" . (($encount & 1) ? "ddddff" : "ffdddd");
$sfname = $sline[0]; // filename
$sfdate = date('Y-m-d H:i', $sline[9]);
echo " <tr class='detail' bgcolor='$bgcolor'>\n";
echo " <td onclick='dosvclick(\"$sfname\")'>" .
"<a href='fax_view.php?scan=$sfname' onclick='return false'>" .
"$sfname</a></td>\n";
echo " <td onclick='dosdclick(\"$sfname\")'>";
echo "<a href='fax_dispatch.php?scan=$sfname' onclick='return false'>Dispatch</a></td>\n";
echo " <td>$sfdate</td>\n";
echo " <td align='right'>" . $sline[7] . "</td>\n";
echo " </tr>\n";
}
?>
</table>

</form>
Expand Down
7 changes: 7 additions & 0 deletions interface/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,17 @@

// If you want Hylafax support then uncomment and customize the following
// statements, and also customize custom/faxcover.txt:
//
// $GLOBALS['hylafax_server'] = 'localhost';
// $GLOBALS['hylafax_basedir'] = '/var/spool/fax';
// $GLOBALS['hylafax_enscript'] = 'enscript -M Letter -B -e^ --margins=36:36:36:36';

// For scanner support, uncomment and customize the following. This is
// the directory in which scanned-in documents may be found, and may for
// example be a smbfs-mounted share from the PC supporting the scanner:
//
// $GLOBALS['scanner_output_directory'] = '/mnt/scan_docs';

// Customize these if you are using SQL-Ledger with OpenEMR.
$sl_cash_acc = '1060'; // sql-ledger account number for checking account
$sl_ar_acc = '1200'; // sql-ledger account number for accounts receivable
Expand Down
16 changes: 9 additions & 7 deletions interface/main/main_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,20 @@
</td>

<?php
if ($GLOBALS['hylafax_server']) {
// Count the number of faxes in the recvq:
$statlines = array();
exec("faxstat -r -l -h " . $GLOBALS['hylafax_server'], $statlines);
if ($GLOBALS['hylafax_server'] || $GLOBALS['scanner_output_directory']) {
$faxcount = 0;
foreach ($statlines as $line) {
if (substr($line, 0, 1) == '-') ++$faxcount;
if ($GLOBALS['hylafax_server']) {
// Count the number of faxes in the recvq:
$statlines = array();
exec("faxstat -r -l -h " . $GLOBALS['hylafax_server'], $statlines);
foreach ($statlines as $line) {
if (substr($line, 0, 1) == '-') ++$faxcount;
}
}
$faxcount = $faxcount ? "($faxcount)" : "";
?>
<td align="center" nowrap>
&nbsp;<a href="../fax/faxq.php" target="Main" class="menu"><?php echo xl('Fax') . $faxcount; ?></a>&nbsp;
&nbsp;<a href="../fax/faxq.php" target="Main" class="menu"><?php echo xl('Docs') . $faxcount; ?></a>&nbsp;
</td>
<?php } ?>

Expand Down

0 comments on commit 6d1b0e3

Please sign in to comment.