preparing for 5.0.1 release in several weeks (#1509)
[openemr.git] / portal / lib / doc_lib.php
blobbbbb77f93a72a0c17214b1a60389153387204820
1 <?php
2 /**
4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
6 * LICENSE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @package OpenEMR
20 * @author Jerry Padgett <sjpadgett@gmail.com>
21 * @link http://www.open-emr.org
23 $ignoreAuth = true;
24 session_start();
25 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
26 $pid = $_SESSION['pid'];
27 $ignoreAuth = true;
28 require_once(dirname(__FILE__) . "/../../interface/globals.php");
29 } else {
30 session_destroy();
31 $ignoreAuth = false;
32 require_once(dirname(__FILE__) . "/../../interface/globals.php");
33 if (! isset($_SESSION['authUserID'])) {
34 $landingpage = "index.php";
35 header('Location: '.$landingpage);
36 exit;
40 require_once("$srcdir/classes/Document.class.php");
41 require_once("$srcdir/classes/Note.class.php");
42 require_once("$srcdir/formatting.inc.php");
43 require_once("$srcdir/htmlspecialchars.inc.php");
44 require_once("$srcdir/html2pdf/vendor/autoload.php");
45 require_once(dirname(__FILE__)."/appsql.class.php");
47 $logit = new ApplicationTable();
48 $htmlin = $_REQUEST['content'];
49 $dispose = $_POST['handler'];
51 try {
52 $form_filename = $_REQUEST['docid'] . '_' . $GLOBALS['pid'] . '.pdf';
53 $templatedir = $GLOBALS['OE_SITE_DIR'] . "/documents/onsite_portal_documents/patient_documents";
54 $templatepath = "$templatedir/$form_filename";
55 $htmlout = '';
56 $pdf = new HTML2PDF(
57 $GLOBALS['pdf_layout'],
58 $GLOBALS['pdf_size'],
59 $GLOBALS['pdf_language'],
60 true,
61 'UTF-8',
62 array ($GLOBALS['pdf_left_margin'],$GLOBALS['pdf_top_margin'],$GLOBALS['pdf_right_margin'],$GLOBALS['pdf_bottom_margin']
65 $pdf->writeHtml($htmlin, false);
66 if ($dispose == 'download') {
67 header('Content-type: application/pdf');
68 header('Content-Disposition: attachment; filename=$form_filename');
69 $pdf->Output($form_filename, 'D');
70 $logit->portalLog('download document', $_SESSION['pid'], ('document:'.$form_filename));
73 if ($dispose == 'view') {
74 Header("Content-type: application/pdf");
75 $pdf->Output($templatepath, 'I');
78 if ($dispose == 'chart') {
79 $data = $pdf->Output($form_filename, 'S');
80 ob_start();
81 $d = new Document();
82 $rc = $d->createDocument($GLOBALS['pid'], 29, $form_filename, 'application/pdf', $data);
83 ob_clean();
84 echo $rc;
85 $logit->portalLog('chart document', $_SESSION['pid'], ('document:'.$form_filename));
87 exit(0);
89 } catch (Exception $e) {
90 echo 'Message: ' .$e->getMessage();
91 die(xlt("no signature in document"));
94 // not currently used but meant to be.
95 function doc_toDoc($htmlin)
97 header("Content-type: application/vnd.oasis.opendocument.text");
98 header("Content-Disposition: attachment;Filename=document_name.html");
99 echo "<html>";
100 echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
101 echo "<body>";
102 echo $htmlin;
103 echo "</body>";
104 echo "</html>";
105 ob_clean();
106 flush();
107 readfile($fname);