3 * Functions for documents.
5 * Copyright (C) 2013 Brady Miller <brady.g.miller@gmail.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 3
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 Brady Miller <brady.g.miller@gmail.com>
20 * @link http://www.open-emr.org
23 require_once($GLOBALS['fileroot']."/controllers/C_Document.class.php");
26 * Function to add a document via the C_Document class.
28 * @param string $name Name of the document
29 * @param string $type Mime type of file
30 * @param string $tmp_name Temporary file name
31 * @param string $error Errors in file upload
32 * @param string $size Size of file
33 * @param int $owner Owner/user/service that imported the file
34 * @param string $patient_id_or_simple_directory Patient id or simple directory for storage when patient id not known (such as '00' or 'direct')
35 * @param int $category_id Document category id
36 * @param string $higher_level_path Can set a higher level path here (and then place the path depth in $path_depth)
37 * @param int $path_depth Path depth when using the $higher_level_path feature
38 * @return array/boolean Array(doc_id,url) of the file as stored in documents table, false = failure
40 function addNewDocument($name, $type, $tmp_name, $error, $size, $owner = '', $patient_id_or_simple_directory = "00", $category_id = '1', $higher_level_path = '', $path_depth = '1')
44 $owner = $_SESSION['authUserID'];
47 // Build the $_FILES array
48 $TEMP_FILES = array();
49 $TEMP_FILES['file']['name'][0]=$name;
50 $TEMP_FILES['file']['type'][0]=$type;
51 $TEMP_FILES['file']['tmp_name'][0]=$tmp_name;
52 $TEMP_FILES['file']['error'][0]=$error;
53 $TEMP_FILES['file']['size'][0]=$size;
54 $_FILES = $TEMP_FILES;
56 // Build the parameters
57 $_GET['higher_level_path']=$higher_level_path;
58 $_GET['patient_id']=$patient_id_or_simple_directory;
59 $_POST['destination']='';
60 $_POST['submit']='Upload';
61 $_POST['path_depth']=$path_depth;
62 $_POST['patient_id']=(is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory>0) ?
$patient_id_or_simple_directory : "00";
63 $_POST['category_id']=$category_id;
64 $_POST['process']='true';
66 // Add the Document and return the newly added document id
67 $cd = new C_Document();
68 $cd->manual_set_owner
=$owner;
69 $cd->upload_action_process();
70 $v = $cd->get_template_vars("file");
71 if (!isset($v) ||
!$v) {
75 return array ("doc_id" => $v[0]->id
, "url" => $v[0]->url
);
79 * Function to return the category id of a category title.
81 * @param string $category_title category title
82 * @return int/boolean category id (returns false if the category title does not exist)
84 function document_category_to_id($category_title)
86 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
95 * Function used in the documents request for patient portal..
97 * @param string $imagetype Image type
98 * @return File extension Image type (returns false if the Image type does not exist)
100 function get_extension($imagetype)
102 if (empty($imagetype)) {
106 switch ($imagetype) {
107 case 'application/andrew-inset':
109 case 'application/mac-binhex40':
111 case 'application/mac-compactpro':
113 case 'application/msword':
115 case 'application/octet-stream':
117 case 'application/octet-stream':
119 case 'application/octet-stream':
121 case 'application/octet-stream':
123 case 'application/octet-stream':
125 case 'application/octet-stream':
127 case 'application/octet-stream':
129 case 'application/octet-stream':
131 case 'application/oda':
133 case 'application/pdf':
135 case 'application/postscript':
137 case 'application/postscript':
139 case 'application/postscript':
141 case 'application/smil':
143 case 'application/smil':
145 case 'application/vnd.wap.wbxml':
147 case 'application/vnd.wap.wmlc':
149 case 'application/vnd.wap.wmlscriptc':
151 case 'application/x-bcpio':
153 case 'application/x-cdlink':
155 case 'application/x-chess-pgn':
157 case 'application/x-cpio':
159 case 'application/x-csh':
161 case 'application/x-director':
163 case 'application/x-director':
165 case 'application/x-director':
167 case 'application/x-dvi':
169 case 'application/x-futuresplash':
171 case 'application/x-gtar':
173 case 'application/x-hdf':
175 case 'application/x-javascript':
177 case 'application/x-koan':
179 case 'application/x-koan':
181 case 'application/x-koan':
183 case 'application/x-koan':
185 case 'application/x-latex':
187 case 'application/x-netcdf':
189 case 'application/x-netcdf':
191 case 'application/x-sh':
193 case 'application/x-shar':
195 case 'application/x-shockwave-flash':
197 case 'application/x-stuffit':
199 case 'application/x-sv4cpio':
201 case 'application/x-sv4crc':
203 case 'application/x-tar':
205 case 'application/x-tcl':
207 case 'application/x-tex':
209 case 'application/x-texinfo':
211 case 'application/x-texinfo':
213 case 'application/x-troff':
215 case 'application/x-troff':
217 case 'application/x-troff':
219 case 'application/x-troff-man':
221 case 'application/x-troff-me':
223 case 'application/x-troff-ms':
225 case 'application/x-ustar':
227 case 'application/x-wais-source':
229 case 'application/xhtml+xml':
231 case 'application/xhtml+xml':
233 case 'application/zip':
257 case 'audio/x-mpegurl':
259 case 'audio/x-pn-realaudio':
261 case 'audio/x-pn-realaudio':
263 case 'audio/x-pn-realaudio-plugin':
265 case 'audio/x-realaudio':
269 case 'chemical/x-pdb':
271 case 'chemical/x-xyz':
291 case 'image/vnd.djvu':
293 case 'image/vnd.djvu':
295 case 'image/vnd.wap.wbmp':
297 case 'image/x-cmu-raster':
299 case 'image/x-portable-anymap':
301 case 'image/x-portable-bitmap':
303 case 'image/x-portable-graymap':
305 case 'image/x-portable-pixmap':
309 case 'image/x-xbitmap':
311 case 'image/x-xpixmap':
313 case 'image/x-windowdump':
339 case 'text/richtext':
347 case 'text/tab-seperated-values':
349 case 'text/vnd.wap.wml':
351 case 'text/vnd.wap.wmlscript':
353 case 'text/x-setext':
365 case 'video/quicktime':
367 case 'video/quicktime':
369 case 'video/vnd.mpegurl':
371 case 'video/x-msvideo':
373 case 'video/x-sgi-movie':
375 case 'x-conference-xcooltalk':