Some new features
[openemr.git] / portal / lib / doc_lib.php
blobfdcc795c53f543feaef8c7dddb936df3121fa5d1
1 <?php
2 /**
3 * doc_lib.php
5 * @package OpenEMR
6 * @link https://www.open-emr.org
7 * @author Jerry Padgett <sjpadgett@gmail.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2016-2018 Jerry Padgett <sjpadgett@gmail.com>
10 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 // Will start the (patient) portal OpenEMR session/cookie.
16 require_once(dirname(__FILE__) . "/../../src/Common/Session/SessionUtil.php");
17 OpenEMR\Common\Session\SessionUtil::portalSessionStart();
19 if (isset($_SESSION['pid']) && isset($_SESSION['patient_portal_onsite_two'])) {
20 $pid = $_SESSION['pid'];
21 $ignoreAuth = true;
22 require_once(dirname(__FILE__) . "/../../interface/globals.php");
23 } else {
24 OpenEMR\Common\Session\SessionUtil::portalSessionCookieDestroy();
25 $ignoreAuth = false;
26 require_once(dirname(__FILE__) . "/../../interface/globals.php");
27 if (!isset($_SESSION['authUserID'])) {
28 $landingpage = "index.php";
29 header('Location: ' . $landingpage);
30 exit;
34 require_once("$srcdir/classes/Document.class.php");
35 require_once("$srcdir/classes/Note.class.php");
36 require_once(dirname(__FILE__) . "/appsql.class.php");
38 use Mpdf\Mpdf;
40 $logit = new ApplicationTable();
41 $htmlin = $_POST['content'];
42 $dispose = $_POST['handler'];
43 $cpid = $_POST['cpid'] ? $_POST['cpid'] : $GLOBALS['pid'];
44 $category = isset($_POST['catid']) ? $_POST['catid'] : 0;
46 try {
47 if (!$category) {
48 $result = sqlQuery("SELECT id FROM categories WHERE name LIKE ?", array("Reviewed"));
49 $category = $result['id'] ? $result['id'] : 3;
51 $form_filename = convert_safe_file_dir_name($_REQUEST['docid']) . '_' . convert_safe_file_dir_name($cpid) . '.pdf';
52 $templatedir = $GLOBALS['OE_SITE_DIR'] . "/documents/onsite_portal_documents/patient_documents";
53 $templatepath = "$templatedir/$form_filename";
54 $htmlout = '';
55 $config_mpdf = array(
56 'tempDir' => $GLOBALS['MPDF_WRITE_DIR'],
57 'mode' => $GLOBALS['pdf_language'],
58 'format' => $GLOBALS['pdf_size'],
59 'default_font_size' => '9',
60 'default_font' => 'dejavusans',
61 'margin_left' => $GLOBALS['pdf_left_margin'],
62 'margin_right' => $GLOBALS['pdf_right_margin'],
63 'margin_top' => $GLOBALS['pdf_top_margin'],
64 'margin_bottom' => $GLOBALS['pdf_bottom_margin'],
65 'margin_header' => '',
66 'margin_footer' => '',
67 'orientation' => $GLOBALS['pdf_layout'],
68 'shrink_tables_to_fit' => 1,
69 'use_kwt' => true,
70 'autoScriptToLang' => true,
71 'keep_table_proportions' => true
73 $pdf = new mPDF($config_mpdf);
74 if ($_SESSION['language_direction'] == 'rtl') {
75 $pdf->SetDirectionality('rtl');
77 $htmlin = "<html><body>$htmlin</body></html>";
78 // need custom stylesheet for templates
79 $pdf->writeHtml($htmlin);
80 if ($dispose == 'download') {
81 header('Content-type: application/pdf');
82 header("Content-Disposition: attachment; filename=$form_filename");
83 $pdf->Output($form_filename, 'D');
84 $logit->portalLog('download document', $cpid, ('document:' . $form_filename));
87 if ($dispose == 'view') {
88 Header("Content-type: application/pdf");
89 $pdf->Output($templatepath, 'I');
92 if ($dispose == 'chart') {
93 if (!$cpid) {
94 echo xla("ERROR Missing Patient ID");
95 exit();
97 $data = $pdf->Output($form_filename, 'S');
98 ob_start();
99 $d = new Document();
100 $rc = $d->createDocument($cpid, $category, $form_filename, 'application/pdf', $data);
101 ob_clean();
102 echo $rc;
103 $logit->portalLog('chart document', $cpid, ('document:' . $form_filename));
105 exit(0);
107 } catch (Exception $e) {
108 echo 'Message: ' . $e->getMessage();
109 die(xlt("no signature in document"));