Corrected Restyled Procedures - Part 2 (#1789)
[openemr.git] / interface / fax / fax_view.php
blob3372ccb06b488d6d803c89c7bbc7d9cc7517de98
1 <?php
2 /**
3 * fax_view.php
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Rod Roark <rod@sunsetsystems.com>
8 * @copyright Copyright (c) 2016 Rod Roark <rod@sunsetsystems.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../globals.php");
15 $ffname = '';
16 $jobid = $_GET['jid'];
17 if ($jobid) {
18 $jfname = $GLOBALS['hylafax_basedir'] . "/sendq/q" . check_file_dir_name($jobid);
19 if (!file_exists($jfname)) {
20 $jfname = $GLOBALS['hylafax_basedir'] . "/doneq/q" . check_file_dir_name($jobid);
23 $jfhandle = fopen($jfname, 'r');
24 if (!$jfhandle) {
25 echo "I am in these groups: ";
26 passthru("groups");
27 echo "<br />";
28 die(xlt("Cannot open ") . text($jfname));
31 while (!feof($jfhandle)) {
32 $line = trim(fgets($jfhandle));
33 if (substr($line, 0, 12) == '!postscript:') {
34 $ffname = $GLOBALS['hylafax_basedir'] . '/' .
35 substr($line, strrpos($line, ':') + 1);
36 break;
40 fclose($jfhandle);
41 if (!$ffname) {
42 die(xlt("Cannot find postscript document reference in ") . text($jfname));
44 } else if ($_GET['scan']) {
45 $ffname = $GLOBALS['scanner_output_directory'] . '/' . check_file_dir_name($_GET['scan']);
46 } else {
47 $ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . check_file_dir_name($_GET['file']);
50 if (!file_exists($ffname)) {
51 die(xlt("Cannot find ") . text($ffname));
54 if (!is_readable($ffname)) {
55 die(xlt("I do not have permission to read ") . text($ffname));
58 ob_start();
60 $ext = substr($ffname, strrpos($ffname, '.'));
61 if ($ext == '.ps') {
62 passthru("TMPDIR=/tmp ps2pdf '" . escapeshellarg($ffname) . "' -");
63 } else if ($ext == '.pdf' || $ext == '.PDF') {
64 readfile($ffname);
65 } else {
66 passthru("tiff2pdf '" . escapeshellarg($ffname) . "'");
69 header("Pragma: public");
70 header("Expires: 0");
71 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
72 header("Content-Type: application/pdf");
73 header("Content-Length: " . ob_get_length());
74 header("Content-Disposition: inline; filename=" . basename($ffname, $ext) . '.pdf');
76 ob_end_flush();
78 exit;