forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fax_view.php
72 lines (63 loc) · 1.94 KB
/
fax_view.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// Copyright (C) 2006 Rod Roark <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
require_once("../globals.php");
$ffname = '';
$jobid = $_GET['jid'];
if ($jobid) {
$jfname = $GLOBALS['hylafax_basedir'] . "/sendq/q$jobid";
if (!file_exists($jfname))
$jfname = $GLOBALS['hylafax_basedir'] . "/doneq/q$jobid";
$jfhandle = fopen($jfname, 'r');
if (!$jfhandle) {
echo "I am in these groups: ";
passthru("groups");
echo "<br />";
die(xl("Cannot open ") . $jfname);
}
while (!feof($jfhandle)) {
$line = trim(fgets($jfhandle));
if (substr($line, 0, 12) == '!postscript:') {
$ffname = $GLOBALS['hylafax_basedir'] . '/' .
substr($line, strrpos($line, ':') + 1);
break;
}
}
fclose($jfhandle);
if (!$ffname) {
die(xl("Cannot find postscript document reference in ") . $jfname);
}
}
else if ($_GET['scan']) {
$ffname = $GLOBALS['scanner_output_directory'] . '/' . $_GET['scan'];
}
else {
$ffname = $GLOBALS['hylafax_basedir'] . '/recvq/' . $_GET['file'];
}
if (!file_exists($ffname)) {
die(xl("Cannot find ") . $ffname);
}
if (!is_readable($ffname)) {
die(xl("I do not have permission to read ") . $ffname);
}
ob_start();
$ext = substr($ffname, strrpos($ffname, '.'));
if ($ext == '.ps')
passthru("TMPDIR=/tmp ps2pdf '$ffname' -");
else if ($ext == '.pdf' || $ext == '.PDF')
readfile($ffname);
else
passthru("tiff2pdf '$ffname'");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/pdf");
header("Content-Length: " . ob_get_length());
header("Content-Disposition: inline; filename=" . basename($ffname, $ext) . '.pdf');
ob_end_flush();
exit;
?>