chore: ci mariadb stuff - added 11.1 and removed 10.9 (#6834)
[openemr.git] / library / documents.php
blob0c38b644b5fa30c305097299e128e35fd61bf244
1 <?php
3 /**
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>;.
19 * @package OpenEMR
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");
26 /**
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(
43 $name,
44 $type,
45 $tmp_name,
46 $error,
47 $size,
48 $owner = '',
49 $patient_id_or_simple_directory = "00",
50 $category_id = '1',
51 $higher_level_path = '',
52 $path_depth = '1',
53 $skip_acl_check = false
54 ) {
56 if (empty($owner)) {
57 $owner = $_SESSION['authUserID'];
60 // Build the $_FILES array
61 $TEMP_FILES = array();
62 $TEMP_FILES['file']['name'][0] = $name;
63 $TEMP_FILES['file']['type'][0] = $type;
64 $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
65 $TEMP_FILES['file']['error'][0] = $error;
66 $TEMP_FILES['file']['size'][0] = $size;
67 $_FILES = $TEMP_FILES;
69 // Build the parameters
70 $_GET['higher_level_path'] = $higher_level_path;
71 $_GET['patient_id'] = $patient_id_or_simple_directory;
72 $_POST['destination'] = '';
73 $_POST['submit'] = 'Upload';
74 $_POST['path_depth'] = $path_depth;
75 $_POST['patient_id'] = (is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0) ? $patient_id_or_simple_directory : "00";
76 $_POST['category_id'] = $category_id;
77 $_POST['process'] = 'true';
79 // Add the Document and return the newly added document id
80 $cd = new C_Document();
81 $cd->manual_set_owner = $owner;
82 if ($skip_acl_check) {
83 $cd->skipAclCheck();
85 $cd->upload_action_process();
86 $v = $cd->getTemplateVars("file");
87 if (!isset($v) || !$v) {
88 return false;
91 return array("doc_id" => $v[0]->id, "url" => $v[0]->url, "name" => $v[0]->name);
94 /**
95 * Function to return the category id of a category title.
97 * @param string $category_title category title
98 * @return int/boolean category id (returns false if the category title does not exist)
100 function document_category_to_id($category_title)
102 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
103 if ($ret['id']) {
104 return $ret['id'];
105 } else {
106 return false;
111 * Function used in the documents request for patient portal..
113 * @param string $imagetype Image type
114 * @return string File extension Image type (returns false if the Image type does not exist)
116 function get_extension($imagetype)
118 if (empty($imagetype)) {
119 return false;
122 switch ($imagetype) {
123 case 'application/andrew-inset':
124 return '.ez';
125 case 'application/mac-binhex40':
126 return '.hqx';
127 case 'application/mac-compactpro':
128 return '.cpt';
129 case 'application/msword':
130 return '.doc';
131 case 'application/octet-stream':
132 return '.bin';
133 case 'application/octet-stream':
134 return '.dms';
135 case 'application/octet-stream':
136 return '.lha';
137 case 'application/octet-stream':
138 return '.lzh';
139 case 'application/octet-stream':
140 return '.exe';
141 case 'application/octet-stream':
142 return '.class';
143 case 'application/octet-stream':
144 return '.so';
145 case 'application/octet-stream':
146 return '.dll';
147 case 'application/oda':
148 return '.oda';
149 case 'application/pdf':
150 return '.pdf';
151 case 'application/postscript':
152 return '.ai';
153 case 'application/postscript':
154 return '.eps';
155 case 'application/postscript':
156 return '.ps';
157 case 'application/smil':
158 return '.smi';
159 case 'application/smil':
160 return '.smil';
161 case 'application/vnd.wap.wbxml':
162 return '.wbxml';
163 case 'application/vnd.wap.wmlc':
164 return '.wmlc';
165 case 'application/vnd.wap.wmlscriptc':
166 return '.wmlsc';
167 case 'application/x-bcpio':
168 return '.bcpio';
169 case 'application/x-cdlink':
170 return '.vcd';
171 case 'application/x-chess-pgn':
172 return '.pgn';
173 case 'application/x-cpio':
174 return '.cpio';
175 case 'application/x-csh':
176 return '.csh';
177 case 'application/x-director':
178 return '.dcr';
179 case 'application/x-director':
180 return '.dir';
181 case 'application/x-director':
182 return '.dxr';
183 case 'application/x-dvi':
184 return '.dvi';
185 case 'application/x-futuresplash':
186 return '.spl';
187 case 'application/x-gtar':
188 return '.gtar';
189 case 'application/x-hdf':
190 return '.hdf';
191 case 'application/x-javascript':
192 return '.js';
193 case 'application/x-koan':
194 return '.skp';
195 case 'application/x-koan':
196 return '.skd';
197 case 'application/x-koan':
198 return '.skt';
199 case 'application/x-koan':
200 return '.skm';
201 case 'application/x-latex':
202 return '.latex';
203 case 'application/x-netcdf':
204 return '.nc';
205 case 'application/x-netcdf':
206 return '.cdf';
207 case 'application/x-sh':
208 return '.sh';
209 case 'application/x-shar':
210 return '.shar';
211 case 'application/x-shockwave-flash':
212 return '.swf';
213 case 'application/x-stuffit':
214 return '.sit';
215 case 'application/x-sv4cpio':
216 return '.sv4cpio';
217 case 'application/x-sv4crc':
218 return '.sv4crc';
219 case 'application/x-tar':
220 return '.tar';
221 case 'application/x-tcl':
222 return '.tcl';
223 case 'application/x-tex':
224 return '.tex';
225 case 'application/x-texinfo':
226 return '.texinfo';
227 case 'application/x-texinfo':
228 return '.texi';
229 case 'application/x-troff':
230 return '.t';
231 case 'application/x-troff':
232 return '.tr';
233 case 'application/x-troff':
234 return '.roff';
235 case 'application/x-troff-man':
236 return '.man';
237 case 'application/x-troff-me':
238 return '.me';
239 case 'application/x-troff-ms':
240 return '.ms';
241 case 'application/x-ustar':
242 return '.ustar';
243 case 'application/x-wais-source':
244 return '.src';
245 case 'application/xhtml+xml':
246 return '.xhtml';
247 case 'application/xhtml+xml':
248 return '.xht';
249 case 'application/zip':
250 return '.zip';
251 case 'audio/basic':
252 return '.au';
253 case 'audio/basic':
254 return '.snd';
255 case 'audio/midi':
256 return '.mid';
257 case 'audio/midi':
258 return '.midi';
259 case 'audio/midi':
260 return '.kar';
261 case 'audio/mpeg':
262 return '.mpga';
263 case 'audio/mpeg':
264 return '.mp2';
265 case 'audio/mpeg':
266 return '.mp3';
267 case 'audio/x-aiff':
268 return '.aif';
269 case 'audio/x-aiff':
270 return '.aiff';
271 case 'audio/x-aiff':
272 return '.aifc';
273 case 'audio/x-mpegurl':
274 return '.m3u';
275 case 'audio/x-pn-realaudio':
276 return '.ram';
277 case 'audio/x-pn-realaudio':
278 return '.rm';
279 case 'audio/x-pn-realaudio-plugin':
280 return '.rpm';
281 case 'audio/x-realaudio':
282 return '.ra';
283 case 'audio/x-wav':
284 return '.wav';
285 case 'chemical/x-pdb':
286 return '.pdb';
287 case 'chemical/x-xyz':
288 return '.xyz';
289 case 'image/bmp':
290 return '.bmp';
291 case 'image/gif':
292 return '.gif';
293 case 'image/ief':
294 return '.ief';
295 case 'image/jpeg':
296 return '.jpeg';
297 case 'image/jpeg':
298 return '.jpg';
299 case 'image/jpeg':
300 return '.jpe';
301 case 'image/png':
302 return '.png';
303 case 'image/tiff':
304 return '.tiff';
305 case 'image/tif':
306 return '.tif';
307 case 'image/vnd.djvu':
308 return '.djvu';
309 case 'image/vnd.djvu':
310 return '.djv';
311 case 'image/vnd.wap.wbmp':
312 return '.wbmp';
313 case 'image/x-cmu-raster':
314 return '.ras';
315 case 'image/x-portable-anymap':
316 return '.pnm';
317 case 'image/x-portable-bitmap':
318 return '.pbm';
319 case 'image/x-portable-graymap':
320 return '.pgm';
321 case 'image/x-portable-pixmap':
322 return '.ppm';
323 case 'image/x-rgb':
324 return '.rgb';
325 case 'image/x-xbitmap':
326 return '.xbm';
327 case 'image/x-xpixmap':
328 return '.xpm';
329 case 'image/x-windowdump':
330 return '.xwd';
331 case 'model/iges':
332 return '.igs';
333 case 'model/iges':
334 return '.iges';
335 case 'model/mesh':
336 return '.msh';
337 case 'model/mesh':
338 return '.mesh';
339 case 'model/mesh':
340 return '.silo';
341 case 'model/vrml':
342 return '.wrl';
343 case 'model/vrml':
344 return '.vrml';
345 case 'text/css':
346 return '.css';
347 case 'text/html':
348 return '.html';
349 case 'text/html':
350 return '.htm';
351 case 'text/plain':
352 return '.asc';
353 case 'text/plain':
354 return '.txt';
355 case 'text/richtext':
356 return '.rtx';
357 case 'text/rtf':
358 return '.rtf';
359 case 'text/sgml':
360 return '.sgml';
361 case 'text/sgml':
362 return '.sgm';
363 case 'text/tab-seperated-values':
364 return '.tsv';
365 case 'text/vnd.wap.wml':
366 return '.wml';
367 case 'text/vnd.wap.wmlscript':
368 return '.wmls';
369 case 'text/x-setext':
370 return '.etx';
371 case 'text/xml':
372 return '.xml';
373 case 'text/xml':
374 return '.xsl';
375 case 'video/mpeg':
376 return '.mpeg';
377 case 'video/mpeg':
378 return '.mpg';
379 case 'video/mpeg':
380 return '.mpe';
381 case 'video/quicktime':
382 return '.qt';
383 case 'video/quicktime':
384 return '.mov';
385 case 'video/vnd.mpegurl':
386 return '.mxu';
387 case 'video/x-msvideo':
388 return '.avi';
389 case 'video/x-sgi-movie':
390 return '.movie';
391 case 'x-conference-xcooltalk':
392 return '.ice';
393 default:
394 return "";