Fix CRLF
[openemr.git] / contrib / forms / documents / save.php
blob576932b0e19316a2004747302149e1b788be6993
1 <?
2 # file save.php.
3 # uploads what comes from the new.php file.
4 # the use of modifying inserted values is depreciated.
5 # uploading documents form.
6 # does not support modifying.
8 include_once("../../globals.php");
9 include_once("$srcdir/api.inc");
10 include_once("$srcdir/forms.inc");
11 formHeader('Document Input submitted');
13 //main check to be sure it was finely called.
14 if ($_POST["action"]!="submit" ) {
15 die ("You should send the info from the form.");
16 }//eof main check
18 //echo ("debug passed if<br>");
20 # we are not using the standard function
21 # because of the file being uploaded.
23 // we give the file a unique identifier
24 $file_new_name=date ("Y-m-d-H-i-s-");
25 $file_new_name.=$_SESSION['pid'] ; //add patient id
26 //save the file extension
27 $file_ext=$HTTP_POST_FILES['document_image']['name'];
28 $extension=substr ( $file_ext , -4);
29 $file_new_name.=$extension;
30 // we check for a valid type of file.
31 if (($HTTP_POST_FILES['document_image']['type'] == 'image/gif') ||
32 ($HTTP_POST_FILES['document_image']['type'] == 'image/jpg') ||
33 ($HTTP_POST_FILES['document_image']['type'] == 'image/pjpeg') ||
34 ($HTTP_POST_FILES['document_image']['type'] == 'image/jpeg') ||
35 ($HTTP_POST_FILES['document_image']['type'] == 'image/bmp')){
36 $checktype='ok';
39 if ($checktype!='ok') {
40 echo ("<br><span class=text>Only Jpeg, gif and bmp images accepted.<br></span>");
41 die ();
44 // we check for the patient subdirectory and we create it if it doesn't exist.
45 $document_path="$webserver_root/interface/forms/documents/scanned/";
46 $document_path.= $_SESSION['pid'] ; //add patient id
48 if(!is_dir($document_path)){
49 // if it doesn't exist, then create it.
50 mkdir($document_path, 0777); // will create 755 permission because of umask()
51 // echo ("debug passed checked dir<br>");
54 // we copy the file on the patient id subdirectory.
55 if (!is_file("$document_path/".$file_new_name) ) {
56 if ( copy($HTTP_POST_FILES['document_image']['tmp_name'], "$document_path/".$file_new_name ) ) {
57 echo ("<br><span class=text>File uploaded to patient's document directory<br></span>");
58 // we make that file only readable to avoid mistakes.
59 chmod ("$document_path/$file_new_name", 0444);
60 unlink ($HTTP_POST_FILES['document_image']);
61 } else {
62 echo ("<br><span class=text>Upload Error - please contact administrator<br></span>");
63 die ();
65 } else {
66 echo ("<br><span class=text>There is a file with that name already - please contact administrator<br></span>");
67 die ();
71 // if succesfull we keep going with the form input to the table
73 $document_description=addslashes (trim ($_POST['document_description']) );
74 $document_source=addslashes (trim($_POST['document_source']));
76 $now=date ("Y-m-d H:h:s");
78 $sql = "INSERT INTO `form_documents` SET
79 pid = {$_SESSION['pid']},
80 groupname='".$_SESSION['authProvider']."',
81 user='".$_SESSION['authUser']."',
82 authorized=$userauthorized,
83 activity=1,
84 date ='$now',
85 document_image='$file_new_name' ,
86 document_path='$document_path',
87 document_description='$document_description' ,
88 document_source='$document_source'
91 $result= sqlQuery ($sql); //query passed to db
94 //this function adds the form to a table wich creates a registry
95 // then it may be retrievable by the report menu
96 if ($encounter == "")
97 $encounter = date("Ymd");
98 $newid=mysql_insert_id($GLOBALS['dbh']); // last id
99 addForm($encounter, "Scanned Documents", $newid, "documents", $pid, $userauthorized);
102 // i don't get where this id cames from
103 // formJump("./print.php?id=$id");
104 formJump("./print.php?id=$newid");
106 formFooter();