PageRenderTime 82ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 1ms

/modules/photolab/uploadphoto.php

https://github.com/timschofield/2.8
PHP | 185 lines | 136 code | 32 blank | 17 comment | 27 complexity | 73829d25f3ba716ea5264b4ab0464f1e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?PHP
  2. require('./roots.php');
  3. require('../../include/helpers/inc_environment_global.php');
  4. require($root_path.'global_conf/inc_remoteservers_conf.php');
  5. $local_user='ck_photolab_user';
  6. require_once($root_path.'modules/photolab/model/class_image.php');
  7. $img=new Image;
  8. $disc_pix_mode = true;
  9. if(!isset($db) || !$db) include_once($root_path.'include/helpers/inc_db_makelink.php');
  10. if(!$dblink_ok) {
  11. print "ERROR: db not ready.\n";
  12. exit;
  13. }
  14. $userid = $_REQUEST['userid'];
  15. $keyword = $_REQUEST['keyword'];
  16. // if $GUI not set, use text/plain for answers
  17. if( !isset($_REQUEST['GUI']) ){
  18. header( "Content-Type: text/plain" );
  19. $CRLF = "\n";
  20. } else {
  21. $CRLF = "<br />\n";
  22. }
  23. $sql='SELECT * FROM care_users WHERE login_id="'.addslashes($userid).'"';
  24. if($ergebnis=$db->Execute($sql))
  25. {
  26. $zeile=$ergebnis->FetchRow();
  27. if( !(($zeile['password']==md5($keyword))&&($zeile['login_id']==$userid)) )
  28. {
  29. print "ERROR: Authorization failed$CRLF";
  30. if( !isset($_REQUEST['GUI']) )
  31. exit;
  32. }
  33. }
  34. if( $_REQUEST["function"]=="save" )
  35. {
  36. // check for encounter
  37. $sql = "SELECT * FROM care_encounter ".
  38. " WHERE encounter_nr='".$_REQUEST["encounter_nr"]."'";
  39. $result = $db->Execute( $sql );
  40. if( !($row = $result->FetchRow()) )
  41. {
  42. print "ERROR$CRLF".
  43. "no patient folder for encounter no '".$_REQUEST["encounter_nr"]."'$CRLF";
  44. if( !isset($_REQUEST['GUI']) )
  45. exit;
  46. }
  47. else
  48. {
  49. // Set the encounter as the directory name
  50. $picdir = $_REQUEST["encounter_nr"];
  51. if($disc_pix_mode){
  52. $d = $root_path.$photoserver_localpath.$picdir;
  53. }
  54. //DEBUG: print "saving to $d ... $CRLF";
  55. // $db->debug=true;
  56. if( $img->isValidUploadedImage($_FILES['imagefile']) )
  57. {
  58. $data=array('encounter_nr'=>$_REQUEST["encounter_nr"],
  59. 'upload_date'=>date('Y-m-d'),
  60. 'history'=>"Upload ".date('Y-m-d H:i:s')." ".$userid."\n",
  61. 'modify_time'=>0,
  62. 'create_id'=>$userid,
  63. 'create_time'=>date('YmdHis'));
  64. $picext = strtolower($img->UploadedImageMimeType());
  65. if(stristr($picext,'gif')||stristr($picext,'jpg')||stristr($picext,'png'))
  66. {
  67. $data['shot_date'] = date("Y-m-d");
  68. $data['shot_nr'] = 1;
  69. $data['mime_type'] = $picext;
  70. if($pknr = $img->saveImageData($data)){
  71. # Find the last inserted primary key based on the db type
  72. /*switch($dbtype){
  73. case "postgres": $picnr=$img->postgre_Insert_ID('care_encounter_image','nr',$pknr); break;
  74. case "postgres7": $picnr=$img->postgre_Insert_ID('care_encounter_image','nr',$pknr); break;
  75. # default is mysql $picnr == $picnr;
  76. }*/
  77. $picnr = $img->LastInsertPK('nr',$pknr);
  78. $picfilename = $picnr.'.'.$picext;
  79. if($disc_pix_mode)
  80. {
  81. if(!is_dir($d)){
  82. // if $d directory not exist create it with CHMOD 777
  83. mkdir($d,0777);
  84. // Copy the trap files to this new directory
  85. copy($root_path.'uploads/photos/encounter/donotremove/index.htm',
  86. $d.'/index.htm');
  87. copy($root_path.'uploads/photos/encounter/donotremove/index.php',
  88. $d.'/index.php');
  89. }
  90. // Store to the newly created directory
  91. $dir_path = $d.'/';
  92. }
  93. else
  94. {
  95. // Store to cache directory
  96. $dir_path = $root_path.'cache/';
  97. }
  98. // Save the uploaded image
  99. $img->saveUploadedImage( $_FILES['imagefile'],
  100. $dir_path, $picfilename );
  101. print "saved to $dir_path$picfilename$CRLF";
  102. } else {
  103. echo $img->getLastQuery();
  104. }
  105. }
  106. if( !isset($_REQUEST['GUI']) )
  107. exit;
  108. } else {
  109. echo "Possible file upload attack:";
  110. }
  111. }
  112. }
  113. else if( $_REQUEST["function"]=="getinfo" )
  114. {
  115. // check for encounter
  116. $sql = "SELECT e.encounter_nr, e.pid, e.encounter_date, ".
  117. " p.name_first, p.name_last, p.date_birth ".
  118. " FROM care_encounter e, care_person p ".
  119. " WHERE p.pid=e.pid ".
  120. " AND e.encounter_nr='".$_REQUEST["encounter_nr"]."'";
  121. $result = $db->Execute( $sql );
  122. if(is_object($result)){
  123. if( ($row = $result->FetchRow()) )
  124. {
  125. print "PID: ".$row['pid']."$CRLF".
  126. $row['name_first']." ".$row['name_last']." (".
  127. $row['date_birth'].")$CRLF".
  128. "at: ".$row['encounter_date']."$CRLF";
  129. if( !isset($_REQUEST['GUI']) )
  130. exit;
  131. }
  132. else
  133. {
  134. print "ERROR: no encounter with id='".$_REQUEST["encounter_nr"]."'$CRLF";
  135. if( !isset($_REQUEST['GUI']) )
  136. exit;
  137. }
  138. }else{
  139. echo "Encounter nr. not found";
  140. exit;
  141. }
  142. }
  143. ?>
  144. <hr>
  145. <h3>uplaod image</h3>
  146. <form method="post" enctype="multipart/form-data">
  147. <INPUT type="hidden" name="GUI" value="yes">
  148. <input type=radio name="function" value="getinfo">info
  149. <input type=radio name="function" value="save">save<br />
  150. encounter_nr: <input name="encounter_nr" value=""><br />
  151. <input type=file size=40 maxlength=2000000 name='imagefile' accept='image/*'><br />
  152. <input type=submit>
  153. </form>