minor improvement to tabs style
[openemr.git] / portal / lib / doc_lib.php
blobf53cf0b9e7c1b2581023dccaa0fa42e9969e7a16
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" );
30 else {
31 session_destroy();
32 $ignoreAuth = false;
33 require_once ( dirname( __FILE__ ) . "/../../interface/globals.php" );
34 if ( ! isset($_SESSION['authUserID']) ){
35 $landingpage = "index.php";
36 header('Location: '.$landingpage);
37 exit;
41 require_once ( "$srcdir/classes/Document.class.php" );
42 require_once ( "$srcdir/classes/Note.class.php" );
43 require_once ( "$srcdir/formatting.inc.php" );
44 require_once ( "$srcdir/htmlspecialchars.inc.php" );
45 require_once ( "$srcdir/html2pdf/vendor/autoload.php" );
46 require_once (dirname( __FILE__ )."/appsql.class.php" );
48 $logit = new ApplicationTable();
49 $htmlin = $_REQUEST['content'];
50 $dispose = $_POST['handler'];
52 try{
53 $form_filename = $_REQUEST['docid'] . '_' . $GLOBALS['pid'] . '.pdf';
54 $templatedir = $GLOBALS['OE_SITE_DIR'] . "/documents/onsite_portal_documents/patient_documents";
55 $templatepath = "$templatedir/$form_filename";
56 $htmlout = '';
57 $pdf = new HTML2PDF( $GLOBALS['pdf_layout'], $GLOBALS['pdf_size'], $GLOBALS['pdf_language'], true,
58 'UTF-8', array ($GLOBALS['pdf_left_margin'],$GLOBALS['pdf_top_margin'],$GLOBALS['pdf_right_margin'],$GLOBALS['pdf_bottom_margin']
59 ) );
60 $pdf->writeHtml( $htmlin, false );
61 if( $dispose == 'download' ){
62 header( 'Content-type: application/pdf' );
63 header( 'Content-Disposition: attachment; filename=$form_filename' );
64 $pdf->Output( $form_filename, 'D' );
65 $logit->portalLog('download document',$_SESSION['pid'],('document:'.$form_filename));
67 if( $dispose == 'view' ){
68 Header( "Content-type: application/pdf" );
69 $pdf->Output( $templatepath, 'I' );
71 if( $dispose == 'chart' ){
72 $data = $pdf->Output( $form_filename, 'S' );
73 ob_start();
74 $d = new Document();
75 $rc = $d->createDocument( $GLOBALS['pid'], 29, $form_filename, 'application/pdf', $data );
76 ob_clean();
77 echo $rc;
78 $logit->portalLog('chart document',$_SESSION['pid'],('document:'.$form_filename));
80 exit(0);
83 catch(Exception $e){
84 echo 'Message: ' .$e->getMessage();
85 die(xlt("no signature in document"));
87 // not currently used but meant to be.
88 function doc_toDoc( $htmlin ){
89 header( "Content-type: application/vnd.oasis.opendocument.text" );
90 header( "Content-Disposition: attachment;Filename=document_name.html" );
91 echo "<html>";
92 echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
93 echo "<body>";
94 echo $htmlin;
95 echo "</body>";
96 echo "</html>";
97 ob_clean();
98 flush();
99 readfile( $fname );