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 // This function builds an array of document categories recursively.
29 // Borrowed from interface/fax/fax_dispatch.php.
31 function getKittens($catid, $catstring, &$categories)
33 $cres = sqlStatement("SELECT id, name FROM categories " .
34 "WHERE parent = ? ORDER BY name", array($catid));
36 while ($crow = sqlFetchArray($cres)) {
38 getKittens($crow['id'], ($catstring ?
"$catstring / " : "") .
39 ($catid ?
$crow['name'] : ''), $categories);
42 // If no kitties, then this is a leaf node and should be listed.
44 $categories[$catid] = $catstring;
48 $postid = empty($_REQUEST['postid' ]) ?
0 : intval($_REQUEST['postid' ]);
49 $messageid = empty($_REQUEST['messageid']) ?
0 : intval($_REQUEST['messageid']);
51 if ($_POST['bn_save']) {
52 $ptid = intval($_POST['ptid']);
53 echo "<html><body>\n";
54 if (is_array($_POST['form_filename'])) {
55 foreach ($_POST['form_filename'] as $uploadid => $filename) {
56 $catid = $_POST['form_category'][$uploadid];
61 echo xlt('Fetching following file from portal') . ": " . $filename . " ...<br />\n";
64 $result = cms_portal_call(array('action' => 'getmsgup', 'uploadid' => $uploadid));
66 $result = cms_portal_call(array('action' => 'getupload', 'uploadid' => $uploadid));
69 if ($result['errmsg']) {
70 die(text($result['errmsg']));
74 // With JSON-over-HTTP we would need to base64_decode the contents.
75 $rc = $d->createDocument(
83 die(text(xl('Error saving document') . ": $rc"));
88 // Finally, delete the request or message from the portal.
90 $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
92 $result = cms_portal_call(array('action' => 'delpost', 'postid' => $postid));
95 if ($result['errmsg']) {
96 die(text($result['errmsg']));
99 echo "<script language='JavaScript'>\n";
100 echo "if (top.restoreSession) top.restoreSession(); else opener.top.restoreSession();\n";
101 echo "document.location.href = 'list_requests.php';\n";
102 echo "</script></body></html>\n";
106 // Get the document categories list.
107 $categories = array();
108 getKittens(0, '', $categories);
110 // Get the portal request data.
111 if (!$postid && !$messageid) {
112 die(xlt('Request ID is missing!'));
116 $result = cms_portal_call(array('action' => 'getmessage', 'messageid' => $messageid));
118 $result = cms_portal_call(array('action' => 'getpost', 'postid' => $postid));
121 if ($result['errmsg']) {
122 die(text($result['errmsg']));
125 // Look up the patient in OpenEMR.
126 $userlogin = $messageid ?
$result['message']['user'] : $result['post']['user'];
127 $ptid = lookup_openemr_patient($userlogin);
131 <?php
html_header_show(); ?
>
132 <link rel
=stylesheet href
="<?php echo $css_header; ?>" type
="text/css">
134 <style type
="text/css">@import
url(../../library
/dynarch_calendar
.css
);</style
>
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 type
="text/javascript" src
="../../library/textformat.js"></script
>
144 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-2-2/index.js"></script
>
146 <script language
="JavaScript">
148 var mypcc
= '<?php echo $GLOBALS['phone_country_code
'] ?>';
150 function myRestoreSession() {
151 if (top
.restoreSession
) top
.restoreSession(); else opener
.top
.restoreSession();
158 <body
class="body_top">
161 <form method
='post' action
='upload_form.php'>
165 echo "<p class='text'><b>" . xlt('Message Title') . ":</b> ";
166 echo htmlspecialchars($result['message']['title']);
168 echo "<textarea style='width:90%;height:144pt;' readonly>";
169 echo htmlspecialchars($result['message']['contents']);
170 echo "</textarea>\n";
171 echo "<p class='text'><i>";
172 echo xlt('This message text is not saved automatically. Copy and save it as appropriate for the content.');
177 <input type
='hidden' name
='ptid' value
='<?php echo attr($ptid); ?>' />
178 <input type
='hidden' name
='postid' value
='<?php echo attr($postid); ?>' />
179 <input type
='hidden' name
='messageid' value
='<?php echo attr($messageid); ?>' />
181 <table width
='100%' cellpadding
='1' cellspacing
='2'>
183 <th align
='left'><?php
echo xlt('MIME Type'); ?
></th
>
184 <th align
='left'><?php
echo xlt('Desired Filename'); ?
></th
>
185 <th align
='left'><?php
echo xlt('Document Category or Discard'); ?
></th
>
188 if (is_array($result['uploads'])) {
189 foreach ($result['uploads'] as $upload) {
190 $id = intval($upload['id']);
191 echo " <tr class='detail'>\n";
192 // MIME type and view link
193 echo " <td><a href='upload_form_show.php?id=$id&messageid=$messageid'>" .
194 text($upload['mimetype']) . "</a></td>\n";
196 echo " <td><input type='text' name='form_filename[$id]' value='" .
197 attr($upload['filename']) . "' size='20' /></td>";
198 // Desired document category with option to discard the file
199 echo " <td><select name='form_category[$id]'>\n";
200 echo "<option value='0'>-- " . xlt('Discard') . " --</option>\n";
202 foreach ($categories as $catkey => $catname) {
203 echo "<option value='" . attr($catkey) . "'";
208 echo ">" . text($catname) . "</option>\n";
211 echo "</select></td>\n";
220 <input type
='submit' name
='bn_save' value
='<?php echo xla('Submit
and Delete Request
'); ?>' />
222 <input type
='button' value
='<?php echo xla('Back
'); ?>'
223 onclick
="myRestoreSession();location='list_requests.php'" />