PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/photolab/photolab-pic-save.php

https://github.com/timschofield/2.8
PHP | 287 lines | 192 code | 45 blank | 50 comment | 28 complexity | 58e15e4669cca94f274b52a9c76456b1 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, GPL-2.0
  1. <?php
  2. error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
  3. require('./roots.php');
  4. require('../../include/helpers/inc_environment_global.php');
  5. /**
  6. * CARE2X Integrated Hospital Information System Deployment 2.1 - 2004-10-02
  7. * GNU General Public License
  8. * Copyright 2002,2003,2004,2005 Elpidio Latorilla
  9. * elpidio@care2x.org,
  10. *
  11. * See the file "copy_notice.txt" for the licence notice
  12. */
  13. define('MODULE','photolab');
  14. define('LANG_FILE_MODULAR','photolab.php');
  15. $local_user='ck_photolab_user';
  16. require_once($root_path.'include/helpers/inc_front_chain_lang.php');
  17. # Load date formatter
  18. include_once($root_path.'include/helpers/inc_date_format_functions.php');
  19. # If data incomplete go back to select page
  20. if(!$patnum||!$firstname||!$lastname||!$bday||!$maxpic) {
  21. header("Location:photolab-dir-select.php?sid=$sid&lang=$lang&maxpic=$maxpic&nopatdata=1");
  22. exit;
  23. };
  24. require($root_path.'global_conf/inc_remoteservers_conf.php');
  25. require_once($root_path.'modules/photolab/model/class_image.php');
  26. $img=new Image;
  27. $dirselectfile='photolab-dir-select.php';
  28. $breakfile="javascript:window.parent.location.replace('".$root_path."main/plugin.php?sid=$sid&lang=$lang')";
  29. # Start Smarty templating here
  30. /**
  31. * LOAD Smarty
  32. */
  33. # Note: it is advisable to load this after the inc_front_chain_lang.php so
  34. # that the smarty script can use the user configured template theme
  35. require_once(CARE_BASE.'/include/helpers/smarty_care.class.php');
  36. $smarty = new smarty_care('system_admin');
  37. # Title in toolbar
  38. $smarty->assign('sToolbarTitle',$LDFotoLab);
  39. $smarty->assign('LDBack', $LDBack);
  40. $smarty->assign('LDHelp', $LDHelp);
  41. $smarty->assign('LDClose', $LDClose);
  42. # href for help button
  43. $smarty->assign('pbHelp',CARE_GUI . "modules/" . MODULE . "/help/" . $lang . "/photolab.html");
  44. # href for close button
  45. $smarty->assign('breakfile',$breakfile);
  46. # Window bar title
  47. $smarty->assign('sWindowTitle',$LDFotoLab);
  48. # Collect js code
  49. ob_start();
  50. ?>
  51. <script language="javascript">
  52. <!--
  53. function previewpic(fn) {
  54. if(fn=="") return;
  55. else parent.PREVIEWFRAME.document.previewpic.src=fn;
  56. }
  57. // -->
  58. </script>
  59. <?php
  60. $sTemp = ob_get_contents();
  61. ob_end_clean();
  62. $smarty->append('JavaScript',$sTemp);
  63. # Buffer page output
  64. ob_start();
  65. ?>
  66. <p>
  67. <?php
  68. echo "[$patnum] $lastname, $firstname ($bday)<p>";
  69. echo "<font color=\"#cc0000\">$LDPicsSaved</font>";
  70. ?><p>
  71. <?php
  72. $picfilename=array();
  73. if($maxpic){
  74. ?>
  75. <table border=0>
  76. <?php
  77. # Set the encounter as the directory name
  78. $picdir=$patnum;
  79. if($disc_pix_mode){
  80. $d=$root_path.$photoserver_localpath.$picdir;
  81. }
  82. $data=array('encounter_nr'=>$patnum,
  83. 'upload_date'=>date('Y-m-d'),
  84. 'history'=>"Upload ".date('Y-m-d H:i:s')." ".$_SESSION['sess_user_name']."\n",
  85. 'modify_id'=>'',
  86. 'modify_time'=>0,
  87. 'create_id'=>$_SESSION['sess_user_name'],
  88. 'create_time'=>date('YmdHis'));
  89. for ($i=0;$i<$maxpic;$i++)
  90. {
  91. $picfile='picfile'.$i;
  92. $shotdate='sdate'.$i;
  93. $shotnr='nr'.$i;//echo $shotnr."<br>";
  94. //echo $picfile.' '.$shotdate.' '.$shotnr;
  95. # Check the image
  96. if(!$img->isValidUploadedImage($_FILES[$picfile])) continue;
  97. # Get the file extension
  98. $picext=$img->UploadedImageMimeType();
  99. $picext=strtolower($picext);
  100. if(stristr($picext,'gif')||stristr($picext,'jpg')||stristr($picext,'png'))
  101. {
  102. $data['shot_date']=formatDate2Std($$shotdate,$date_format);
  103. $data['shot_nr']=$$shotnr;
  104. $data['mime_type']=$picext;
  105. if($insid=$img->saveImageData($data)){
  106. # Get the last inserted primary key
  107. $picnr = $img->LastInsertPK('nr',$insid);
  108. $picfilename[$i]=$picnr.'.'.$picext;
  109. echo '<tr><td>'.$_FILES[$picfile]['name'].'</td><td> <img '.createComIcon($root_path,'fwd.gif','0','absmiddle').'> ';
  110. if($disc_pix_mode)
  111. {
  112. if(!is_dir($d)){
  113. # if $d directory not exist create it with CHMOD 777
  114. mkdir($d,0777);
  115. # Copy the trap files to this new directory
  116. copy($root_path.'uploads/photos/encounter/donotremove/index.htm',$d.'/index.htm');
  117. copy($root_path.'uploads/photos/encounter/donotremove/index.php',$d.'/index.php');
  118. }
  119. # Store to the newly created directory
  120. $dir_path=$d.'/';
  121. }
  122. else
  123. {
  124. # Store to cache directory
  125. $dir_path=$root_path.'cache/';
  126. }
  127. # Save the uploaded image
  128. $img->saveUploadedImage($_FILES[$picfile],$dir_path,$picfilename[$i]);
  129. echo '<font color="#cc0000"><a href="javascript:previewpic(\'';
  130. if($disc_pix_mode) echo $root_path.$photoserver_localpath; else echo $photoserver_http;
  131. echo $picdir.'/'.$picfilename[$i].'\')">'.$picfilename[$i].'</a></font>';
  132. echo '</td></tr>';
  133. //echo '<hr>';
  134. }else{
  135. echo $img->getLastQuery();
  136. }
  137. }
  138. }
  139. $filelist=array();
  140. /**
  141. * If the variable disc_pix_mode in the inc_remoteservers_conf.php file is not set
  142. * send the pictures to a server via ftp protocol
  143. * Note: the ftp server address must set configured in the inc_remoteservers_conf.php
  144. */
  145. if(!$disc_pix_mode)
  146. {
  147. # The ftp username and password should be set here
  148. $user='maryhospital_photolabor';
  149. $pw='bong';
  150. $conn_id = ftp_connect($ftp_server);
  151. if($conn_id)
  152. {
  153. // login with username and password
  154. $login_result = ftp_login($conn_id, $user, $pw);
  155. if($login_result)
  156. {
  157. $curdir=ftp_pwd($conn_id);
  158. //ftp_chdir($conn_id,"$curdir/");
  159. //echo $curdir."<br>";
  160. // now attempt to cd to picdir
  161. $filelist=ftp_nlist($conn_id,"$curdir/");
  162. if($filelist)
  163. {
  164. //while(list($x,$v)=each($filelist)) echo $v."<br>";
  165. if(in_array(strtolower($picdir),$filelist))
  166. {
  167. if(ftp_chdir($conn_id,"$picdir/")) $cdok=1;
  168. else
  169. {
  170. if(ftp_mkdir($conn_id,$picdir))
  171. {
  172. if(ftp_chdir($conn_id,"$picdir/")) $cdok=1;
  173. }
  174. }
  175. }
  176. else
  177. {
  178. if(ftp_mkdir($conn_id,$picdir))
  179. {
  180. if(ftp_chdir($conn_id,"$picdir/")) $cdok=1;
  181. }
  182. }
  183. if($cdok)
  184. {
  185. reset($picfilename);
  186. for($i=0;$i<$maxpic;$i++)
  187. {
  188. if($picfilename[$i]=='') continue;
  189. if (ftp_put($conn_id,$picfilename[$i],$root_path.'cache/'.$picfilename[$i],FTP_BINARY))
  190. {
  191. if(empty($mainidx)||($i<>$mainidx))
  192. {
  193. # If the ftp save was successful, remove the image file from the cache
  194. $removefile='unlink("'.$root_path.'cache/'.$picfilename[$i].'");';
  195. eval($removefile);
  196. }
  197. }
  198. }
  199. }
  200. }
  201. else echo $LDLinkBroken;
  202. ftp_quit($conn_id);
  203. }
  204. }
  205. }
  206. ?>
  207. </table>
  208. <?php
  209. }
  210. ?>
  211. &nbsp;
  212. <p>
  213. <font color="#cc0000"><b><?php echo "$LDSave $LDOptions:" ?></b></font>
  214. <form action="<?php echo $dirselectfile ?>" method="post">
  215. <img <?php echo createComIcon($root_path,'video.gif','0') ?>><br><?php echo "$LDSave " ?><?php echo $LDAdditional ?>
  216. <input type="text" name="maxpic" size=1 maxlength=2 value="<?php echo $maxpic ?>"> <?php echo $LDMorePics ?>:<input type="submit" value="<?php echo $LDGO ?>">
  217. <input type="hidden" name="sid" value="<?php echo $sid ?>">
  218. <input type="hidden" name="lang" value="<?php echo $lang ?>">
  219. <input type="hidden" name="patnum" value="<?php echo $patnum ?>">
  220. <input type="hidden" name="lastname" value="<?php echo $lastname ?>">
  221. <input type="hidden" name="firstname" value="<?php echo $firstname ?>">
  222. <input type="hidden" name="bday" value="<?php echo $bday ?>">
  223. <input type="hidden" name="lastnr" value="<?php $lastnr='nr'.($maxpic-1); echo $$lastnr; ?>">
  224. <input type="hidden" name="same_pat" value="1">
  225. </form>
  226. <p>
  227. <form action="upload_search_patient.php" method="post">
  228. <img <?php echo createComIcon($root_path,'video.gif','0') ?>><br><?php echo $LDSave ?><input type="text" name="aux1" size=1 maxlength=2 value="<?php echo $maxpic ?>">
  229. <?php echo $LDNewPics ?>:<input type="submit" value="<?php echo $LDGO ?>">
  230. <input type="hidden" name="sid" value="<?php echo $sid ?>">
  231. <input type="hidden" name="lang" value="<?php echo $lang ?>">
  232. </form>
  233. <?php
  234. $sTemp = ob_get_contents();
  235. ob_end_clean();
  236. # Assign page output to the mainframe template
  237. $smarty->assign('sMainFrameBlockData',$sTemp);
  238. /**
  239. * show Template
  240. */
  241. $smarty->display(CARE_BASE . 'main/view/mainframe.tpl');
  242. ?>