chore: update ci and dev environments to use mariadb 11.4 (#7545)
[openemr.git] / interface / fax / fax_view.php
blob77f5a82d94c54e8efdc95d8d38b2c9fa783b6d6b
1 <?php
3 /**
4 * fax_view.php
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Rod Roark <rod@sunsetsystems.com>
9 * @copyright Copyright (c) 2016 Rod Roark <rod@sunsetsystems.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 require_once("../globals.php");
15 use OpenEMR\Common\Csrf\CsrfUtils;
17 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
18 CsrfUtils::csrfNotVerified();
21 $ffname = '';
22 $jobid = $_GET['jid'];
23 if ($jobid) {
24 $jfname = $GLOBALS['hylafax_basedir'] . "/sendq/q" . check_file_dir_name($jobid);
25 if (!file_exists($jfname)) {
26 $jfname = $GLOBALS['hylafax_basedir'] . "/doneq/q" . check_file_dir_name($jobid);
29 $jfhandle = fopen($jfname, 'r');
30 if (!$jfhandle) {
31 echo "I am in these groups: ";
32 passthru("groups");
33 echo "<br />";
34 die(xlt("Cannot open ") . text($jfname));
37 while (!feof($jfhandle)) {
38 $line = trim(fgets($jfhandle));
39 if (substr($line, 0, 12) == '!postscript:') {
40 $ffname = $GLOBALS['hylafax_basedir'] . '/' .
41 substr($line, strrpos($line, ':') + 1);
42 break;
46 fclose($jfhandle);
47 if (!$ffname) {
48 die(xlt("Cannot find postscript document reference in ") . text($jfname));
50 } elseif ($_GET['scan']) {
51 $ffname = $GLOBALS['scanner_output_directory'] . '/' . check_file_dir_name($_GET['scan']);
52 } else {
53 $ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . check_file_dir_name($_GET['file']);
56 if (!file_exists($ffname)) {
57 die(xlt("Cannot find ") . text($ffname));
60 if (!is_readable($ffname)) {
61 die(xlt("I do not have permission to read ") . text($ffname));
64 ob_start();
66 $ext = substr($ffname, strrpos($ffname, '.'));
67 if ($ext == '.ps') {
68 passthru("TMPDIR=/tmp ps2pdf '" . escapeshellarg($ffname) . "' -");
69 } elseif ($ext == '.pdf' || $ext == '.PDF') {
70 readfile($ffname);
71 } else {
72 passthru("tiff2pdf '" . escapeshellarg($ffname) . "'");
75 header("Pragma: public");
76 header("Expires: 0");
77 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
78 header("Content-Type: application/pdf");
79 header("Content-Length: " . ob_get_length());
80 header("Content-Disposition: inline; filename=" . basename($ffname, $ext) . '.pdf');
82 ob_end_flush();
84 exit;