Ejemplo n.º 1
0
/**
 * Function to add a document via the C_Document class.
 *
 * @param  string         $name                            Name of the document
 * @param  string         $type                            Mime type of file
 * @param  string         $tmp_name                        Temporary file name
 * @param  string         $error                           Errors in file upload
 * @param  string         $size                            Size of file
 * @param  int            $owner                           Owner/user/service that imported the file
 * @param  string         $patient_id_or_simple_directory  Patient id or simple directory for storage when patient id not known (such as '00' or 'direct')
 * @param  int            $category_id                     Document category id
 * @param  string         $higher_level_path               Can set a higher level path here (and then place the path depth in $path_depth)
 * @param  int            $path_depth                      Path depth when using the $higher_level_path feature
 * @return array/boolean                                   Array(doc_id,url) of the file as stored in documents table, false = failure
 */
function addNewDocument($name, $type, $tmp_name, $error, $size, $owner = '', $patient_id_or_simple_directory = "00", $category_id = '1', $higher_level_path = '', $path_depth = '1')
{
    if (empty($owner)) {
        $owner = $_SESSION['authUserID'];
    }
    // Build the $_FILES array
    $TEMP_FILES = array();
    $TEMP_FILES['file']['name'][0] = $name;
    $TEMP_FILES['file']['type'][0] = $type;
    $TEMP_FILES['file']['tmp_name'][0] = $tmp_name;
    $TEMP_FILES['file']['error'][0] = $error;
    $TEMP_FILES['file']['size'][0] = $size;
    $_FILES = $TEMP_FILES;
    // Build the parameters
    $_GET['higher_level_path'] = $higher_level_path;
    $_GET['patient_id'] = $patient_id_or_simple_directory;
    $_POST['destination'] = '';
    $_POST['submit'] = 'Upload';
    $_POST['path_depth'] = $path_depth;
    $_POST['patient_id'] = is_numeric($patient_id_or_simple_directory) && $patient_id_or_simple_directory > 0 ? $patient_id_or_simple_directory : "00";
    $_POST['category_id'] = $category_id;
    $_POST['process'] = 'true';
    // Add the Document and return the newly added document id
    $cd = new C_Document();
    $cd->manual_set_owner = $owner;
    $cd->upload_action_process();
    $v = $cd->get_template_vars("file");
    if (!isset($v) || !$v) {
        return false;
    }
    return array("doc_id" => $v[0]->id, "url" => $v[0]->url);
}