4 * Functions for documents.
6 * Copyright (C) 2013 Brady Miller <brady.g.miller@gmail.com>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @author Brady Miller <brady.g.miller@gmail.com>
21 * @link https://www.open-emr.org
24 require_once($GLOBALS['fileroot'] . "/controllers/C_Document.class.php");
27 * Function to add a document via the C_Document class.
29 * @param string $name Name of the document
30 * @param string $type Mime type of file
31 * @param string $tmp_name Temporary file name
32 * @param string $error Errors in file upload
33 * @param string $size Size of file
34 * @param int $owner Owner/user/service that imported the file
35 * @param string $patient_id_or_simple_directory Patient id or simple directory for storage when patient id not known (such as '00' or 'direct')
36 * @param int $category_id Document category id
37 * @param string $higher_level_path Can set a higher level path here (and then place the path depth in $path_depth)
38 * @param int $path_depth Path depth when using the $higher_level_path feature
39 * @param boolean $skip_acl_check This needs to be set to true for when uploading via services that piggyback on any user (ie. the background services) or uses cron/cli
40 * @return array/boolean Array(doc_id,url) of the file as stored in documents table, false = failure
42 function addNewDocument($name, $type, $tmp_name, $error, $size, $owner = '', $patient_id_or_simple_directory = "00", $category_id = '1', $higher_level_path = '', $path_depth = '1', $skip_acl_check = false)
46 $owner = $_SESSION['authUserID'];
49 // Build the $_FILES array
50 $TEMP_FILES = array();
51 $TEMP_FILES['file']['name'][0] = $name;
52 $TEMP_FILES['file']['type'][0] = $type;
53 $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
54 $TEMP_FILES['file']['error'][0] = $error;
55 $TEMP_FILES['file']['size'][0] = $size;
56 $_FILES = $TEMP_FILES;
58 // Build the parameters
59 $_GET['higher_level_path'] = $higher_level_path;
60 $_GET['patient_id'] = $patient_id_or_simple_directory;
61 $_POST['destination'] = '';
62 $_POST['submit'] = 'Upload';
63 $_POST['path_depth'] = $path_depth;
64 $_POST['patient_id'] = (is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0) ?
$patient_id_or_simple_directory : "00";
65 $_POST['category_id'] = $category_id;
66 $_POST['process'] = 'true';
68 // Add the Document and return the newly added document id
69 $cd = new C_Document();
70 $cd->manual_set_owner
= $owner;
71 if ($skip_acl_check) {
74 $cd->upload_action_process();
75 $v = $cd->getTemplateVars("file");
76 if (!isset($v) ||
!$v) {
80 return array ("doc_id" => $v[0]->id
, "url" => $v[0]->url
);
84 * Function to return the category id of a category title.
86 * @param string $category_title category title
87 * @return int/boolean category id (returns false if the category title does not exist)
89 function document_category_to_id($category_title)
91 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
100 * Function used in the documents request for patient portal..
102 * @param string $imagetype Image type
103 * @return File extension Image type (returns false if the Image type does not exist)
105 function get_extension($imagetype)
107 if (empty($imagetype)) {
111 switch ($imagetype) {
112 case 'application/andrew-inset':
114 case 'application/mac-binhex40':
116 case 'application/mac-compactpro':
118 case 'application/msword':
120 case 'application/octet-stream':
122 case 'application/octet-stream':
124 case 'application/octet-stream':
126 case 'application/octet-stream':
128 case 'application/octet-stream':
130 case 'application/octet-stream':
132 case 'application/octet-stream':
134 case 'application/octet-stream':
136 case 'application/oda':
138 case 'application/pdf':
140 case 'application/postscript':
142 case 'application/postscript':
144 case 'application/postscript':
146 case 'application/smil':
148 case 'application/smil':
150 case 'application/vnd.wap.wbxml':
152 case 'application/vnd.wap.wmlc':
154 case 'application/vnd.wap.wmlscriptc':
156 case 'application/x-bcpio':
158 case 'application/x-cdlink':
160 case 'application/x-chess-pgn':
162 case 'application/x-cpio':
164 case 'application/x-csh':
166 case 'application/x-director':
168 case 'application/x-director':
170 case 'application/x-director':
172 case 'application/x-dvi':
174 case 'application/x-futuresplash':
176 case 'application/x-gtar':
178 case 'application/x-hdf':
180 case 'application/x-javascript':
182 case 'application/x-koan':
184 case 'application/x-koan':
186 case 'application/x-koan':
188 case 'application/x-koan':
190 case 'application/x-latex':
192 case 'application/x-netcdf':
194 case 'application/x-netcdf':
196 case 'application/x-sh':
198 case 'application/x-shar':
200 case 'application/x-shockwave-flash':
202 case 'application/x-stuffit':
204 case 'application/x-sv4cpio':
206 case 'application/x-sv4crc':
208 case 'application/x-tar':
210 case 'application/x-tcl':
212 case 'application/x-tex':
214 case 'application/x-texinfo':
216 case 'application/x-texinfo':
218 case 'application/x-troff':
220 case 'application/x-troff':
222 case 'application/x-troff':
224 case 'application/x-troff-man':
226 case 'application/x-troff-me':
228 case 'application/x-troff-ms':
230 case 'application/x-ustar':
232 case 'application/x-wais-source':
234 case 'application/xhtml+xml':
236 case 'application/xhtml+xml':
238 case 'application/zip':
262 case 'audio/x-mpegurl':
264 case 'audio/x-pn-realaudio':
266 case 'audio/x-pn-realaudio':
268 case 'audio/x-pn-realaudio-plugin':
270 case 'audio/x-realaudio':
274 case 'chemical/x-pdb':
276 case 'chemical/x-xyz':
296 case 'image/vnd.djvu':
298 case 'image/vnd.djvu':
300 case 'image/vnd.wap.wbmp':
302 case 'image/x-cmu-raster':
304 case 'image/x-portable-anymap':
306 case 'image/x-portable-bitmap':
308 case 'image/x-portable-graymap':
310 case 'image/x-portable-pixmap':
314 case 'image/x-xbitmap':
316 case 'image/x-xpixmap':
318 case 'image/x-windowdump':
344 case 'text/richtext':
352 case 'text/tab-seperated-values':
354 case 'text/vnd.wap.wml':
356 case 'text/vnd.wap.wmlscript':
358 case 'text/x-setext':
370 case 'video/quicktime':
372 case 'video/quicktime':
374 case 'video/vnd.mpegurl':
376 case 'video/x-msvideo':
378 case 'video/x-sgi-movie':
380 case 'x-conference-xcooltalk':