some bug fixes and initial support for listing and viewing outgoing faxes
[openemr.git] / interface / fax / fax_view.php
blobfe893b76fdc26123b0b4f300cfba04ffb193120c
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");
11 $ffname = '';
12 $jobid = $_GET['jid'];
13 if ($jobid) {
14 $jfname = $GLOBALS['hylafax_basedir'] . "/sendq/q$jobid";
15 if (!file_exists($jfname))
16 $jfname = $GLOBALS['hylafax_basedir'] . "/doneq/q$jobid";
17 $jfhandle = fopen($jfname, 'r');
18 if (!$jfhandle) {
19 echo "I am in these groups: ";
20 passthru("groups");
21 echo "<br />";
22 die(xl("Cannot open ") . $jfname);
24 while (!feof($jfhandle)) {
25 $line = trim(fgets($jfhandle));
26 if (substr($line, 0, 12) == '!postscript:') {
27 $ffname = $GLOBALS['hylafax_basedir'] . '/' .
28 substr($line, strrpos($line, ':') + 1);
29 break;
32 fclose($jfhandle);
33 if (!$ffname) {
34 die(xl("Cannot find postscript document reference in ") . $jfname);
37 else {
38 $ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . $_GET['file'];
41 if (!file_exists($ffname)) {
42 die(xl("Cannot find ") . $ffname);
45 if (!is_readable($ffname)) {
46 die(xl("I do not have permission to read ") . $ffname);
49 ob_start();
51 $ext = substr($ffname, strrpos($ffname, '.'));
52 if ($ext == '.ps')
53 passthru("TMPDIR=/tmp ps2pdf $ffname -");
54 else
55 passthru("tiff2pdf $ffname");
57 header("Pragma: public");
58 header("Expires: 0");
59 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
60 header("Content-Type: application/pdf");
61 header("Content-Length: " . ob_get_length());
62 header("Content-Disposition: inline; filename=" . basename($ffname, $ext) . '.pdf');
64 ob_end_flush();
66 exit;