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