PSR2 fixes
[openemr.git] / library / documents.php
blob6dadb6e4441a88c76c5754896b1d2df0b5d94df6
1 <?php
2 /**
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>;.
18 * @package OpenEMR
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");
25 /**
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')
43 if (empty($owner)) {
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) {
72 return false;
75 return array ("doc_id" => $v[0]->id, "url" => $v[0]->url);
78 /**
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));
87 if ($ret['id']) {
88 return $ret['id'];
89 } else {
90 return false;
94 /**
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)) {
103 return false;
106 switch ($imagetype) {
107 case 'application/andrew-inset':
108 return '.ez';
109 case 'application/mac-binhex40':
110 return '.hqx';
111 case 'application/mac-compactpro':
112 return '.cpt';
113 case 'application/msword':
114 return '.doc';
115 case 'application/octet-stream':
116 return '.bin';
117 case 'application/octet-stream':
118 return '.dms';
119 case 'application/octet-stream':
120 return '.lha';
121 case 'application/octet-stream':
122 return '.lzh';
123 case 'application/octet-stream':
124 return '.exe';
125 case 'application/octet-stream':
126 return '.class';
127 case 'application/octet-stream':
128 return '.so';
129 case 'application/octet-stream':
130 return '.dll';
131 case 'application/oda':
132 return '.oda';
133 case 'application/pdf':
134 return '.pdf';
135 case 'application/postscript':
136 return '.ai';
137 case 'application/postscript':
138 return '.eps';
139 case 'application/postscript':
140 return '.ps';
141 case 'application/smil':
142 return '.smi';
143 case 'application/smil':
144 return '.smil';
145 case 'application/vnd.wap.wbxml':
146 return '.wbxml';
147 case 'application/vnd.wap.wmlc':
148 return '.wmlc';
149 case 'application/vnd.wap.wmlscriptc':
150 return '.wmlsc';
151 case 'application/x-bcpio':
152 return '.bcpio';
153 case 'application/x-cdlink':
154 return '.vcd';
155 case 'application/x-chess-pgn':
156 return '.pgn';
157 case 'application/x-cpio':
158 return '.cpio';
159 case 'application/x-csh':
160 return '.csh';
161 case 'application/x-director':
162 return '.dcr';
163 case 'application/x-director':
164 return '.dir';
165 case 'application/x-director':
166 return '.dxr';
167 case 'application/x-dvi':
168 return '.dvi';
169 case 'application/x-futuresplash':
170 return '.spl';
171 case 'application/x-gtar':
172 return '.gtar';
173 case 'application/x-hdf':
174 return '.hdf';
175 case 'application/x-javascript':
176 return '.js';
177 case 'application/x-koan':
178 return '.skp';
179 case 'application/x-koan':
180 return '.skd';
181 case 'application/x-koan':
182 return '.skt';
183 case 'application/x-koan':
184 return '.skm';
185 case 'application/x-latex':
186 return '.latex';
187 case 'application/x-netcdf':
188 return '.nc';
189 case 'application/x-netcdf':
190 return '.cdf';
191 case 'application/x-sh':
192 return '.sh';
193 case 'application/x-shar':
194 return '.shar';
195 case 'application/x-shockwave-flash':
196 return '.swf';
197 case 'application/x-stuffit':
198 return '.sit';
199 case 'application/x-sv4cpio':
200 return '.sv4cpio';
201 case 'application/x-sv4crc':
202 return '.sv4crc';
203 case 'application/x-tar':
204 return '.tar';
205 case 'application/x-tcl':
206 return '.tcl';
207 case 'application/x-tex':
208 return '.tex';
209 case 'application/x-texinfo':
210 return '.texinfo';
211 case 'application/x-texinfo':
212 return '.texi';
213 case 'application/x-troff':
214 return '.t';
215 case 'application/x-troff':
216 return '.tr';
217 case 'application/x-troff':
218 return '.roff';
219 case 'application/x-troff-man':
220 return '.man';
221 case 'application/x-troff-me':
222 return '.me';
223 case 'application/x-troff-ms':
224 return '.ms';
225 case 'application/x-ustar':
226 return '.ustar';
227 case 'application/x-wais-source':
228 return '.src';
229 case 'application/xhtml+xml':
230 return '.xhtml';
231 case 'application/xhtml+xml':
232 return '.xht';
233 case 'application/zip':
234 return '.zip';
235 case 'audio/basic':
236 return '.au';
237 case 'audio/basic':
238 return '.snd';
239 case 'audio/midi':
240 return '.mid';
241 case 'audio/midi':
242 return '.midi';
243 case 'audio/midi':
244 return '.kar';
245 case 'audio/mpeg':
246 return '.mpga';
247 case 'audio/mpeg':
248 return '.mp2';
249 case 'audio/mpeg':
250 return '.mp3';
251 case 'audio/x-aiff':
252 return '.aif';
253 case 'audio/x-aiff':
254 return '.aiff';
255 case 'audio/x-aiff':
256 return '.aifc';
257 case 'audio/x-mpegurl':
258 return '.m3u';
259 case 'audio/x-pn-realaudio':
260 return '.ram';
261 case 'audio/x-pn-realaudio':
262 return '.rm';
263 case 'audio/x-pn-realaudio-plugin':
264 return '.rpm';
265 case 'audio/x-realaudio':
266 return '.ra';
267 case 'audio/x-wav':
268 return '.wav';
269 case 'chemical/x-pdb':
270 return '.pdb';
271 case 'chemical/x-xyz':
272 return '.xyz';
273 case 'image/bmp':
274 return '.bmp';
275 case 'image/gif':
276 return '.gif';
277 case 'image/ief':
278 return '.ief';
279 case 'image/jpeg':
280 return '.jpeg';
281 case 'image/jpeg':
282 return '.jpg';
283 case 'image/jpeg':
284 return '.jpe';
285 case 'image/png':
286 return '.png';
287 case 'image/tiff':
288 return '.tiff';
289 case 'image/tif':
290 return '.tif';
291 case 'image/vnd.djvu':
292 return '.djvu';
293 case 'image/vnd.djvu':
294 return '.djv';
295 case 'image/vnd.wap.wbmp':
296 return '.wbmp';
297 case 'image/x-cmu-raster':
298 return '.ras';
299 case 'image/x-portable-anymap':
300 return '.pnm';
301 case 'image/x-portable-bitmap':
302 return '.pbm';
303 case 'image/x-portable-graymap':
304 return '.pgm';
305 case 'image/x-portable-pixmap':
306 return '.ppm';
307 case 'image/x-rgb':
308 return '.rgb';
309 case 'image/x-xbitmap':
310 return '.xbm';
311 case 'image/x-xpixmap':
312 return '.xpm';
313 case 'image/x-windowdump':
314 return '.xwd';
315 case 'model/iges':
316 return '.igs';
317 case 'model/iges':
318 return '.iges';
319 case 'model/mesh':
320 return '.msh';
321 case 'model/mesh':
322 return '.mesh';
323 case 'model/mesh':
324 return '.silo';
325 case 'model/vrml':
326 return '.wrl';
327 case 'model/vrml':
328 return '.vrml';
329 case 'text/css':
330 return '.css';
331 case 'text/html':
332 return '.html';
333 case 'text/html':
334 return '.htm';
335 case 'text/plain':
336 return '.asc';
337 case 'text/plain':
338 return '.txt';
339 case 'text/richtext':
340 return '.rtx';
341 case 'text/rtf':
342 return '.rtf';
343 case 'text/sgml':
344 return '.sgml';
345 case 'text/sgml':
346 return '.sgm';
347 case 'text/tab-seperated-values':
348 return '.tsv';
349 case 'text/vnd.wap.wml':
350 return '.wml';
351 case 'text/vnd.wap.wmlscript':
352 return '.wmls';
353 case 'text/x-setext':
354 return '.etx';
355 case 'text/xml':
356 return '.xml';
357 case 'text/xml':
358 return '.xsl';
359 case 'video/mpeg':
360 return '.mpeg';
361 case 'video/mpeg':
362 return '.mpg';
363 case 'video/mpeg':
364 return '.mpe';
365 case 'video/quicktime':
366 return '.qt';
367 case 'video/quicktime':
368 return '.mov';
369 case 'video/vnd.mpegurl':
370 return '.mxu';
371 case 'video/x-msvideo':
372 return '.avi';
373 case 'video/x-sgi-movie':
374 return '.movie';
375 case 'x-conference-xcooltalk':
376 return '.ice';
377 default:
378 return "";