Highway to PSR2
[openemr.git] / interface / fax / fax_view.php
blobd6e0aea180f7a3350ff465916369665070e095c0
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";
19 $jfhandle = fopen($jfname, 'r');
20 if (!$jfhandle) {
21 echo "I am in these groups: ";
22 passthru("groups");
23 echo "<br />";
24 die(xl("Cannot open ") . $jfname);
27 while (!feof($jfhandle)) {
28 $line = trim(fgets($jfhandle));
29 if (substr($line, 0, 12) == '!postscript:') {
30 $ffname = $GLOBALS['hylafax_basedir'] . '/' .
31 substr($line, strrpos($line, ':') + 1);
32 break;
36 fclose($jfhandle);
37 if (!$ffname) {
38 die(xl("Cannot find postscript document reference in ") . $jfname);
40 } else if ($_GET['scan']) {
41 $ffname = $GLOBALS['scanner_output_directory'] . '/' . $_GET['scan'];
42 } else {
43 $ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . $_GET['file'];
46 if (!file_exists($ffname)) {
47 die(xl("Cannot find ") . $ffname);
50 if (!is_readable($ffname)) {
51 die(xl("I do not have permission to read ") . $ffname);
54 ob_start();
56 $ext = substr($ffname, strrpos($ffname, '.'));
57 if ($ext == '.ps') {
58 passthru("TMPDIR=/tmp ps2pdf '$ffname' -");
59 } else if ($ext == '.pdf' || $ext == '.PDF') {
60 readfile($ffname);
61 } else {
62 passthru("tiff2pdf '$ffname'");
65 header("Pragma: public");
66 header("Expires: 0");
67 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
68 header("Content-Type: application/pdf");
69 header("Content-Length: " . ob_get_length());
70 header("Content-Disposition: inline; filename=" . basename($ffname, $ext) . '.pdf');
72 ob_end_flush();
74 exit;