PageRenderTime 61ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/library/documents.php

https://github.com/mdsupport/openemr
PHP | 381 lines | 320 code | 11 blank | 50 comment | 8 complexity | 492912aaed8ea4b7c6a2ee674aa0c937 MD5 | raw file
  1. <?php
  2. /**
  3. * Functions for documents.
  4. *
  5. * Copyright (C) 2013 Brady Miller <brady.g.miller@gmail.com>
  6. *
  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>;.
  17. *
  18. * @package OpenEMR
  19. * @author Brady Miller <brady.g.miller@gmail.com>
  20. * @link https://www.open-emr.org
  21. */
  22. require_once($GLOBALS['fileroot'] . "/controllers/C_Document.class.php");
  23. /**
  24. * Function to add a document via the C_Document class.
  25. *
  26. * @param string $name Name of the document
  27. * @param string $type Mime type of file
  28. * @param string $tmp_name Temporary file name
  29. * @param string $error Errors in file upload
  30. * @param string $size Size of file
  31. * @param int $owner Owner/user/service that imported the file
  32. * @param string $patient_id_or_simple_directory Patient id or simple directory for storage when patient id not known (such as '00' or 'direct')
  33. * @param int $category_id Document category id
  34. * @param string $higher_level_path Can set a higher level path here (and then place the path depth in $path_depth)
  35. * @param int $path_depth Path depth when using the $higher_level_path feature
  36. * @return array/boolean Array(doc_id,url) of the file as stored in documents table, false = failure
  37. */
  38. function addNewDocument($name, $type, $tmp_name, $error, $size, $owner = '', $patient_id_or_simple_directory = "00", $category_id = '1', $higher_level_path = '', $path_depth = '1')
  39. {
  40. if (empty($owner)) {
  41. $owner = $_SESSION['authUserID'];
  42. }
  43. // Build the $_FILES array
  44. $TEMP_FILES = array();
  45. $TEMP_FILES['file']['name'][0] = $name;
  46. $TEMP_FILES['file']['type'][0] = $type;
  47. $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
  48. $TEMP_FILES['file']['error'][0] = $error;
  49. $TEMP_FILES['file']['size'][0] = $size;
  50. $_FILES = $TEMP_FILES;
  51. // Build the parameters
  52. $_GET['higher_level_path'] = $higher_level_path;
  53. $_GET['patient_id'] = $patient_id_or_simple_directory;
  54. $_POST['destination'] = '';
  55. $_POST['submit'] = 'Upload';
  56. $_POST['path_depth'] = $path_depth;
  57. $_POST['patient_id'] = (is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0) ? $patient_id_or_simple_directory : "00";
  58. $_POST['category_id'] = $category_id;
  59. $_POST['process'] = 'true';
  60. // Add the Document and return the newly added document id
  61. $cd = new C_Document();
  62. $cd->manual_set_owner = $owner;
  63. $cd->upload_action_process();
  64. $v = $cd->get_template_vars("file");
  65. if (!isset($v) || !$v) {
  66. return false;
  67. }
  68. return array ("doc_id" => $v[0]->id, "url" => $v[0]->url);
  69. }
  70. /**
  71. * Function to return the category id of a category title.
  72. *
  73. * @param string $category_title category title
  74. * @return int/boolean category id (returns false if the category title does not exist)
  75. */
  76. function document_category_to_id($category_title)
  77. {
  78. $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title));
  79. if ($ret['id']) {
  80. return $ret['id'];
  81. } else {
  82. return false;
  83. }
  84. }
  85. /**
  86. * Function used in the documents request for patient portal..
  87. *
  88. * @param string $imagetype Image type
  89. * @return File extension Image type (returns false if the Image type does not exist)
  90. */
  91. function get_extension($imagetype)
  92. {
  93. if (empty($imagetype)) {
  94. return false;
  95. }
  96. switch ($imagetype) {
  97. case 'application/andrew-inset':
  98. return '.ez';
  99. case 'application/mac-binhex40':
  100. return '.hqx';
  101. case 'application/mac-compactpro':
  102. return '.cpt';
  103. case 'application/msword':
  104. return '.doc';
  105. case 'application/octet-stream':
  106. return '.bin';
  107. case 'application/octet-stream':
  108. return '.dms';
  109. case 'application/octet-stream':
  110. return '.lha';
  111. case 'application/octet-stream':
  112. return '.lzh';
  113. case 'application/octet-stream':
  114. return '.exe';
  115. case 'application/octet-stream':
  116. return '.class';
  117. case 'application/octet-stream':
  118. return '.so';
  119. case 'application/octet-stream':
  120. return '.dll';
  121. case 'application/oda':
  122. return '.oda';
  123. case 'application/pdf':
  124. return '.pdf';
  125. case 'application/postscript':
  126. return '.ai';
  127. case 'application/postscript':
  128. return '.eps';
  129. case 'application/postscript':
  130. return '.ps';
  131. case 'application/smil':
  132. return '.smi';
  133. case 'application/smil':
  134. return '.smil';
  135. case 'application/vnd.wap.wbxml':
  136. return '.wbxml';
  137. case 'application/vnd.wap.wmlc':
  138. return '.wmlc';
  139. case 'application/vnd.wap.wmlscriptc':
  140. return '.wmlsc';
  141. case 'application/x-bcpio':
  142. return '.bcpio';
  143. case 'application/x-cdlink':
  144. return '.vcd';
  145. case 'application/x-chess-pgn':
  146. return '.pgn';
  147. case 'application/x-cpio':
  148. return '.cpio';
  149. case 'application/x-csh':
  150. return '.csh';
  151. case 'application/x-director':
  152. return '.dcr';
  153. case 'application/x-director':
  154. return '.dir';
  155. case 'application/x-director':
  156. return '.dxr';
  157. case 'application/x-dvi':
  158. return '.dvi';
  159. case 'application/x-futuresplash':
  160. return '.spl';
  161. case 'application/x-gtar':
  162. return '.gtar';
  163. case 'application/x-hdf':
  164. return '.hdf';
  165. case 'application/x-javascript':
  166. return '.js';
  167. case 'application/x-koan':
  168. return '.skp';
  169. case 'application/x-koan':
  170. return '.skd';
  171. case 'application/x-koan':
  172. return '.skt';
  173. case 'application/x-koan':
  174. return '.skm';
  175. case 'application/x-latex':
  176. return '.latex';
  177. case 'application/x-netcdf':
  178. return '.nc';
  179. case 'application/x-netcdf':
  180. return '.cdf';
  181. case 'application/x-sh':
  182. return '.sh';
  183. case 'application/x-shar':
  184. return '.shar';
  185. case 'application/x-shockwave-flash':
  186. return '.swf';
  187. case 'application/x-stuffit':
  188. return '.sit';
  189. case 'application/x-sv4cpio':
  190. return '.sv4cpio';
  191. case 'application/x-sv4crc':
  192. return '.sv4crc';
  193. case 'application/x-tar':
  194. return '.tar';
  195. case 'application/x-tcl':
  196. return '.tcl';
  197. case 'application/x-tex':
  198. return '.tex';
  199. case 'application/x-texinfo':
  200. return '.texinfo';
  201. case 'application/x-texinfo':
  202. return '.texi';
  203. case 'application/x-troff':
  204. return '.t';
  205. case 'application/x-troff':
  206. return '.tr';
  207. case 'application/x-troff':
  208. return '.roff';
  209. case 'application/x-troff-man':
  210. return '.man';
  211. case 'application/x-troff-me':
  212. return '.me';
  213. case 'application/x-troff-ms':
  214. return '.ms';
  215. case 'application/x-ustar':
  216. return '.ustar';
  217. case 'application/x-wais-source':
  218. return '.src';
  219. case 'application/xhtml+xml':
  220. return '.xhtml';
  221. case 'application/xhtml+xml':
  222. return '.xht';
  223. case 'application/zip':
  224. return '.zip';
  225. case 'audio/basic':
  226. return '.au';
  227. case 'audio/basic':
  228. return '.snd';
  229. case 'audio/midi':
  230. return '.mid';
  231. case 'audio/midi':
  232. return '.midi';
  233. case 'audio/midi':
  234. return '.kar';
  235. case 'audio/mpeg':
  236. return '.mpga';
  237. case 'audio/mpeg':
  238. return '.mp2';
  239. case 'audio/mpeg':
  240. return '.mp3';
  241. case 'audio/x-aiff':
  242. return '.aif';
  243. case 'audio/x-aiff':
  244. return '.aiff';
  245. case 'audio/x-aiff':
  246. return '.aifc';
  247. case 'audio/x-mpegurl':
  248. return '.m3u';
  249. case 'audio/x-pn-realaudio':
  250. return '.ram';
  251. case 'audio/x-pn-realaudio':
  252. return '.rm';
  253. case 'audio/x-pn-realaudio-plugin':
  254. return '.rpm';
  255. case 'audio/x-realaudio':
  256. return '.ra';
  257. case 'audio/x-wav':
  258. return '.wav';
  259. case 'chemical/x-pdb':
  260. return '.pdb';
  261. case 'chemical/x-xyz':
  262. return '.xyz';
  263. case 'image/bmp':
  264. return '.bmp';
  265. case 'image/gif':
  266. return '.gif';
  267. case 'image/ief':
  268. return '.ief';
  269. case 'image/jpeg':
  270. return '.jpeg';
  271. case 'image/jpeg':
  272. return '.jpg';
  273. case 'image/jpeg':
  274. return '.jpe';
  275. case 'image/png':
  276. return '.png';
  277. case 'image/tiff':
  278. return '.tiff';
  279. case 'image/tif':
  280. return '.tif';
  281. case 'image/vnd.djvu':
  282. return '.djvu';
  283. case 'image/vnd.djvu':
  284. return '.djv';
  285. case 'image/vnd.wap.wbmp':
  286. return '.wbmp';
  287. case 'image/x-cmu-raster':
  288. return '.ras';
  289. case 'image/x-portable-anymap':
  290. return '.pnm';
  291. case 'image/x-portable-bitmap':
  292. return '.pbm';
  293. case 'image/x-portable-graymap':
  294. return '.pgm';
  295. case 'image/x-portable-pixmap':
  296. return '.ppm';
  297. case 'image/x-rgb':
  298. return '.rgb';
  299. case 'image/x-xbitmap':
  300. return '.xbm';
  301. case 'image/x-xpixmap':
  302. return '.xpm';
  303. case 'image/x-windowdump':
  304. return '.xwd';
  305. case 'model/iges':
  306. return '.igs';
  307. case 'model/iges':
  308. return '.iges';
  309. case 'model/mesh':
  310. return '.msh';
  311. case 'model/mesh':
  312. return '.mesh';
  313. case 'model/mesh':
  314. return '.silo';
  315. case 'model/vrml':
  316. return '.wrl';
  317. case 'model/vrml':
  318. return '.vrml';
  319. case 'text/css':
  320. return '.css';
  321. case 'text/html':
  322. return '.html';
  323. case 'text/html':
  324. return '.htm';
  325. case 'text/plain':
  326. return '.asc';
  327. case 'text/plain':
  328. return '.txt';
  329. case 'text/richtext':
  330. return '.rtx';
  331. case 'text/rtf':
  332. return '.rtf';
  333. case 'text/sgml':
  334. return '.sgml';
  335. case 'text/sgml':
  336. return '.sgm';
  337. case 'text/tab-seperated-values':
  338. return '.tsv';
  339. case 'text/vnd.wap.wml':
  340. return '.wml';
  341. case 'text/vnd.wap.wmlscript':
  342. return '.wmls';
  343. case 'text/x-setext':
  344. return '.etx';
  345. case 'text/xml':
  346. return '.xml';
  347. case 'text/xml':
  348. return '.xsl';
  349. case 'video/mpeg':
  350. return '.mpeg';
  351. case 'video/mpeg':
  352. return '.mpg';
  353. case 'video/mpeg':
  354. return '.mpe';
  355. case 'video/quicktime':
  356. return '.qt';
  357. case 'video/quicktime':
  358. return '.mov';
  359. case 'video/vnd.mpegurl':
  360. return '.mxu';
  361. case 'video/x-msvideo':
  362. return '.avi';
  363. case 'video/x-sgi-movie':
  364. return '.movie';
  365. case 'x-conference-xcooltalk':
  366. return '.ice';
  367. default:
  368. return "";
  369. }
  370. }