Fully responsive globals.php with vertical menu (#2460)
[openemr.git] / interface / cmsportal / upload_form.php
blob9b927ed27951c792c77c975d2e6f4ae54396c805
1 <?php
2 /**
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>;.
18 * @package OpenEMR
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));
37 $childcount = 0;
38 while ($crow = sqlFetchArray($cres)) {
39 ++$childcount;
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.
45 if (!$childcount) {
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];
59 if (!$catid) {
60 continue;
63 echo xlt('Fetching following file from portal') . ": " . $filename . " ...<br />\n";
64 flush();
65 if ($messageid) {
66 $result = cms_portal_call(array('action' => 'getmsgup', 'uploadid' => $uploadid));
67 } else {
68 $result = cms_portal_call(array('action' => 'getupload', 'uploadid' => $uploadid));
71 if ($result['errmsg']) {
72 die(text($result['errmsg']));
75 $d = new Document();
76 // With JSON-over-HTTP we would need to base64_decode the contents.
77 $rc = $d->createDocument(
78 $ptid,
79 $catid,
80 $filename,
81 $result['mimetype'],
82 $result['contents']
84 if ($rc) {
85 die(text(xl('Error saving document') . ": $rc"));
90 // Finally, delete the request or message from the portal.
91 if ($messageid) {
92 $result = cms_portal_call(array('action' => 'delmessage', 'messageid' => $messageid));
93 } else {
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";
105 exit();
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!'));
117 if ($messageid) {
118 $result = cms_portal_call(array('action' => 'getmessage', 'messageid' => $messageid));
119 } else {
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);
131 <html>
132 <head>
133 <?php Header::setupHeader(['no_bootstrap', 'no_fontawesome', 'no_dialog']); ?>
135 <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; }
141 </style>
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();
149 return true;
152 </script>
153 </head>
155 <body class="body_top">
156 <center>
158 <form method='post' action='upload_form.php'>
160 <?php
161 if ($messageid) {
162 echo "<p class='text'><b>" . xlt('Message Title') . ":</b> ";
163 echo htmlspecialchars($result['message']['title']);
164 echo "</p>\n";
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.');
170 echo "</i></p>\n";
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'>
179 <tr class='head'>
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>
183 </tr>
184 <?php
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";
192 // Desired file name
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";
198 $i = 0;
199 foreach ($categories as $catkey => $catname) {
200 echo "<option value='" . attr($catkey) . "'";
201 if (++$i == 1) {
202 echo " selected";
205 echo ">" . text($catname) . "</option>\n";
208 echo "</select></td>\n";
210 echo " </tr>\n";
214 </table>
217 <input type='submit' name='bn_save' value='<?php echo xla('Submit and Delete Request'); ?>' />
218 &nbsp;
219 <input type='button' value='<?php echo xla('Back'); ?>'
220 onclick="myRestoreSession();location='list_requests.php'" />
221 </p>
223 </form>
224 </center>
225 </body>
226 </html>