Fix edi.inc encoding and correct uninitialized variables in modified files
[openemr.git] / library / documents.php
blob2bfd1b53d833f2b3070c8cd783e9bfb6fee7771d
1 <?php
2 /**
3 * Functions for documents.
5 * Copyright (C) 2013 Brady Miller <brady@sparmy.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@sparmy.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') {
42 if (empty($owner)) {
43 $owner = $_SESSION['authUserID'];
46 // Build the $_FILES array
47 $TEMP_FILES = array();
48 $TEMP_FILES['file']['name'][0]=$name;
49 $TEMP_FILES['file']['type'][0]=$type;
50 $TEMP_FILES['file']['tmp_name'][0]=$tmp_name;
51 $TEMP_FILES['file']['error'][0]=$error;
52 $TEMP_FILES['file']['size'][0]=$size;
53 $_FILES = $TEMP_FILES;
55 // Build the parameters
56 $_GET['higher_level_path']=$higher_level_path;
57 $_GET['patient_id']=$patient_id_or_simple_directory;
58 $_POST['destination']='';
59 $_POST['submit']='Upload';
60 $_POST['path_depth']=$path_depth;
61 $_POST['patient_id']=(is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory>0) ? $patient_id_or_simple_directory : "00";
62 $_POST['category_id']=$category_id;
63 $_POST['process']='true';
65 // Add the Document and return the newly added document id
66 $cd = new C_Document();
67 $cd->upload_action_process($owner);
68 $v = $cd->get_template_vars("file");
69 if (!isset($v) || !$v) return false;
70 return array ("doc_id" => $v[0]->id, "url" => $v[0]->url);
73 /**
74 * Function to return the category id of a category title.
76 * @param string $category_title category title
77 * @return int/boolean category id (returns false if the category title does not exist)
79 function document_category_to_id($category_title) {
80 $ret = sqlQuery("SELECT `id` FROM `categories` WHERE `name`=?", array($category_title) );
81 if ($ret['id']) {
82 return $ret['id'];
84 else {
85 return false;