3 * Handles file uploads from the WordPress Patient Portal.
5 * Copyright (C) 2014 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the 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 General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
19 * @author Rod Roark <rod@sunsetsystems.com>
25 require_once("../globals.php");
26 require_once("portal.inc.php");
28 use OpenEMR\Core\Header
;
30 // This function builds an array of document categories recursively.
31 // Borrowed from interface/fax/fax_dispatch.php.
33 function getKittens($catid, $catstring, &$categories)
35 $cres = sqlStatement("SELECT id, name FROM categories " .
36 "WHERE parent = ? ORDER BY name", array($catid));
38 while ($crow = sqlFetchArray($cres)) {
40 getKittens($crow['id'], ($catstring ?
"$catstring / " : "") .
41 ($catid ?
$crow['name'] : ''), $categories);
44 // If no kitties, then this is a leaf node and should be listed.
46 $categories[$catid] = $catstring;
50 $postid = empty($_REQUEST['postid' ]) ?
0 : intval($_REQUEST['postid' ]);
51 $messageid = empty($_REQUEST['messageid']) ?
0 : intval($_REQUEST['messageid']);
53 if ($_POST['bn_save']) {
54 $ptid = intval($_POST['ptid']);
55 echo "<html><body>\n";
56 if (is_array($_POST['form_filename'])) {
57 foreach ($_POST['form_filename'] as $uploadid => $filename) {
58 $catid = $_POST['form_category'][$uploadid];
63 echo xlt('Fetching following file from portal') . ": " . $filename . " ...<br />\n";
66 $result = cms_portal_call(array('action' => 'getmsgup', 'uploadid' => $uploadid));
68 $result = cms_portal_call(array('action' => 'getupload', 'uploadid' => $uploadid));
71 if ($result['errmsg']) {
72 die(text($result['errmsg']));
76 // With JSON-over-HTTP we would need to base64_decode the contents.
77 $rc = $d->createDocument(
85 die(text(xl('Error saving document') . ": $rc"));
90 // Finally, delete the request or message from the portal.
92 $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
94 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
97 if ($result['errmsg']) {
98 die(text($result['errmsg']));
101 echo "<script language='JavaScript'>\n";
102 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
103 echo "document.location.href = 'list_requests.php';\n";
104 echo "</script></body></html>\n";
108 // Get the document categories list.
109 $categories = array();
110 getKittens(0, '', $categories);
112 // Get the portal request data.
113 if (!$postid && !$messageid) {
114 die(xlt('Request ID is missing!'));
118 $result = cms_portal_call(array('action' => 'getmessage', 'messageid' => $messageid));
120 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
123 if ($result['errmsg']) {
124 die(text($result['errmsg']));
127 // Look up the patient in OpenEMR.
128 $userlogin = $messageid ?
$result['message']['user'] : $result['post']['user'];
129 $ptid = lookup_openemr_patient($userlogin);
133 <?php Header
::setupHeader(['no_bootstrap', 'no_fontawesome', 'no_dialog']); ?
>
137 tr
.head
{ font
-size
:10pt
; background
-color
:#cccccc; text-align:center; }
138 tr
.detail
{ font
-size
:10pt
; background
-color
:#ddddff; }
139 td input
{ background
-color
:transparent
; }
143 <script language
="JavaScript">
145 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
147 function myRestoreSession() {
148 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
155 <body
class="body_top">
158 <form method
='post' action
='upload_form.php'>
162 echo "<p class='text'><b>" . xlt('Message Title') . ":</b> ";
163 echo htmlspecialchars($result['message']['title']);
165 echo "<textarea style='width:90%;height:144pt;' readonly>";
166 echo htmlspecialchars($result['message']['contents']);
167 echo "</textarea>\n";
168 echo "<p class='text'><i>";
169 echo xlt('This message text is not saved automatically. Copy and save it as appropriate for the content.');
174 <input type
='hidden' name
='ptid' value
='<?php echo attr($ptid); ?>' />
175 <input type
='hidden' name
='postid' value
='<?php echo attr($postid); ?>' />
176 <input type
='hidden' name
='messageid' value
='<?php echo attr($messageid); ?>' />
178 <table width
='100%' cellpadding
='1' cellspacing
='2'>
180 <th align
='left'><?php
echo xlt('MIME Type'); ?
></th
>
181 <th align
='left'><?php
echo xlt('Desired Filename'); ?
></th
>
182 <th align
='left'><?php
echo xlt('Document Category or Discard'); ?
></th
>
185 if (is_array($result['uploads'])) {
186 foreach ($result['uploads'] as $upload) {
187 $id = intval($upload['id']);
188 echo " <tr class='detail'>\n";
189 // MIME type and view link
190 echo " <td><a href='upload_form_show.php?id=$id&messageid=$messageid'>" .
191 text($upload['mimetype']) . "</a></td>\n";
193 echo " <td><input type='text' name='form_filename[$id]' value='" .
194 attr($upload['filename']) . "' size='20' /></td>";
195 // Desired document category with option to discard the file
196 echo " <td><select name='form_category[$id]'>\n";
197 echo "<option value='0'>-- " . xlt('Discard') . " --</option>\n";
199 foreach ($categories as $catkey => $catname) {
200 echo "<option value='" . attr($catkey) . "'";
205 echo ">" . text($catname) . "</option>\n";
208 echo "</select></td>\n";
217 <input type
='submit' name
='bn_save' value
='<?php echo xla('Submit
and Delete Request
'); ?>' />
219 <input type
='button' value
='<?php echo xla('Back
'); ?>'
220 onclick
="myRestoreSession();location='list_requests.php'" />