dump db version
[openemr.git] / interface / fax / fax_view.php
blobe9acc710984ce2d2ac41141f2970cbc897326840
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 if (!verifyCsrfToken($_GET["csrf_token_form"])) {
16 csrfNotVerified();
19 $ffname = '';
20 $jobid = $_GET['jid'];
21 if ($jobid) {
22 $jfname = $GLOBALS['hylafax_basedir'] . "/sendq/q" . check_file_dir_name($jobid);
23 if (!file_exists($jfname)) {
24 $jfname = $GLOBALS['hylafax_basedir'] . "/doneq/q" . check_file_dir_name($jobid);
27 $jfhandle = fopen($jfname, 'r');
28 if (!$jfhandle) {
29 echo "I am in these groups: ";
30 passthru("groups");
31 echo "<br />";
32 die(xlt("Cannot open ") . text($jfname));
35 while (!feof($jfhandle)) {
36 $line = trim(fgets($jfhandle));
37 if (substr($line, 0, 12) == '!postscript:') {
38 $ffname = $GLOBALS['hylafax_basedir'] . '/' .
39 substr($line, strrpos($line, ':') + 1);
40 break;
44 fclose($jfhandle);
45 if (!$ffname) {
46 die(xlt("Cannot find postscript document reference in ") . text($jfname));
48 } else if ($_GET['scan']) {
49 $ffname = $GLOBALS['scanner_output_directory'] . '/' . check_file_dir_name($_GET['scan']);
50 } else {
51 $ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . check_file_dir_name($_GET['file']);
54 if (!file_exists($ffname)) {
55 die(xlt("Cannot find ") . text($ffname));
58 if (!is_readable($ffname)) {
59 die(xlt("I do not have permission to read ") . text($ffname));
62 ob_start();
64 $ext = substr($ffname, strrpos($ffname, '.'));
65 if ($ext == '.ps') {
66 passthru("TMPDIR=/tmp ps2pdf '" . escapeshellarg($ffname) . "' -");
67 } else if ($ext == '.pdf' || $ext == '.PDF') {
68 readfile($ffname);
69 } else {
70 passthru("tiff2pdf '" . escapeshellarg($ffname) . "'");
73 header("Pragma: public");
74 header("Expires: 0");
75 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
76 header("Content-Type: application/pdf");
77 header("Content-Length: " . ob_get_length());
78 header("Content-Disposition: inline; filename=" . basename($ffname, $ext) . '.pdf');
80 ob_end_flush();
82 exit;