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 * @return array/boolean Array(doc_id,url) of the file as stored in documents table, false = failure
41 function addNewDocument($name, $type, $tmp_name, $error, $size, $owner = '', $patient_id_or_simple_directory = "00", $category_id = '1', $higher_level_path = '', $path_depth = '1')
45 $owner = $_SESSION['authUserID'];
48 // Build the $_FILES array
49 $TEMP_FILES = array();
50 $TEMP_FILES['file']['name'][0] = $name;
51 $TEMP_FILES['file']['type'][0] = $type;
52 $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
53 $TEMP_FILES['file']['error'][0] = $error;
54 $TEMP_FILES['file']['size'][0] = $size;
55 $_FILES = $TEMP_FILES;
57 // Build the parameters
58 $_GET['higher_level_path'] = $higher_level_path;
59 $_GET['patient_id'] = $patient_id_or_simple_directory;
60 $_POST['destination'] = '';
61 $_POST['submit'] = 'Upload';
62 $_POST['path_depth'] = $path_depth;
63 $_POST['patient_id'] = (is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0) ?
$patient_id_or_simple_directory : "00";
64 $_POST['category_id'] = $category_id;
65 $_POST['process'] = 'true';
67 // Add the Document and return the newly added document id
68 $cd = new C_Document();
69 $cd->manual_set_owner
= $owner;
70 $cd->upload_action_process();
71 $v = $cd->get_template_vars("file");
72 if (!isset($v) ||
!$v) {
76 return array ("doc_id" => $v[0]->id
, "url" => $v[0]->url
);
80 * Function to return the category id of a category title.
82 * @param string $category_title category title
83 * @return int/boolean category id (returns false if the category title does not exist)
85 function document_category_to_id($category_title)
87 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
96 * Function used in the documents request for patient portal..
98 * @param string $imagetype Image type
99 * @return File extension Image type (returns false if the Image type does not exist)
101 function get_extension($imagetype)
103 if (empty($imagetype)) {
107 switch ($imagetype) {
108 case 'application/andrew-inset':
110 case 'application/mac-binhex40':
112 case 'application/mac-compactpro':
114 case 'application/msword':
116 case 'application/octet-stream':
118 case 'application/octet-stream':
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/oda':
134 case 'application/pdf':
136 case 'application/postscript':
138 case 'application/postscript':
140 case 'application/postscript':
142 case 'application/smil':
144 case 'application/smil':
146 case 'application/vnd.wap.wbxml':
148 case 'application/vnd.wap.wmlc':
150 case 'application/vnd.wap.wmlscriptc':
152 case 'application/x-bcpio':
154 case 'application/x-cdlink':
156 case 'application/x-chess-pgn':
158 case 'application/x-cpio':
160 case 'application/x-csh':
162 case 'application/x-director':
164 case 'application/x-director':
166 case 'application/x-director':
168 case 'application/x-dvi':
170 case 'application/x-futuresplash':
172 case 'application/x-gtar':
174 case 'application/x-hdf':
176 case 'application/x-javascript':
178 case 'application/x-koan':
180 case 'application/x-koan':
182 case 'application/x-koan':
184 case 'application/x-koan':
186 case 'application/x-latex':
188 case 'application/x-netcdf':
190 case 'application/x-netcdf':
192 case 'application/x-sh':
194 case 'application/x-shar':
196 case 'application/x-shockwave-flash':
198 case 'application/x-stuffit':
200 case 'application/x-sv4cpio':
202 case 'application/x-sv4crc':
204 case 'application/x-tar':
206 case 'application/x-tcl':
208 case 'application/x-tex':
210 case 'application/x-texinfo':
212 case 'application/x-texinfo':
214 case 'application/x-troff':
216 case 'application/x-troff':
218 case 'application/x-troff':
220 case 'application/x-troff-man':
222 case 'application/x-troff-me':
224 case 'application/x-troff-ms':
226 case 'application/x-ustar':
228 case 'application/x-wais-source':
230 case 'application/xhtml+xml':
232 case 'application/xhtml+xml':
234 case 'application/zip':
258 case 'audio/x-mpegurl':
260 case 'audio/x-pn-realaudio':
262 case 'audio/x-pn-realaudio':
264 case 'audio/x-pn-realaudio-plugin':
266 case 'audio/x-realaudio':
270 case 'chemical/x-pdb':
272 case 'chemical/x-xyz':
292 case 'image/vnd.djvu':
294 case 'image/vnd.djvu':
296 case 'image/vnd.wap.wbmp':
298 case 'image/x-cmu-raster':
300 case 'image/x-portable-anymap':
302 case 'image/x-portable-bitmap':
304 case 'image/x-portable-graymap':
306 case 'image/x-portable-pixmap':
310 case 'image/x-xbitmap':
312 case 'image/x-xpixmap':
314 case 'image/x-windowdump':
340 case 'text/richtext':
348 case 'text/tab-seperated-values':
350 case 'text/vnd.wap.wml':
352 case 'text/vnd.wap.wmlscript':
354 case 'text/x-setext':
366 case 'video/quicktime':
368 case 'video/quicktime':
370 case 'video/vnd.mpegurl':
372 case 'video/x-msvideo':
374 case 'video/x-sgi-movie':
376 case 'x-conference-xcooltalk':