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