<?php


$jpg_file_name = $_GET['jpg_file_name'];
$jpg_file_name_tmp = $_GET['jpg_file_name_tmp'];
$marktype = $_GET['marktype'];
$ruid = $_GET['ruid'];
$patid = $_GET['patid'];

?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc_jp">
<title></title>

<script language='JavaScript'>
<!--


function getMouseX(e){
  if(window.opera)
          return e.clientX
  else if(document.all)   
          return document.body.scrollLeft+event.clientX
  else if(document.layers||document.getElementById)
          return e.pageX
}
function getMouseY(e){
  if(window.opera)   
          return e.clientY
  else if(document.all)   
          return document.body.scrollTop+event.clientY
  else if(document.layers||document.getElementById)
          return e.pageY
}






  

//-->
</script>

<body BACKGROUND="./yellow.jpg">




<?php

  include "init.inc";
  $include_path=".";
  require("$include_path/dbconnect.ini");



class myDbConnect extends DbConnect {
      var $dbname = "pacsdb";
}

  $con = new myDbConnect;

//print("$patid<br>");

print("<br><br><br><br><br>");
print("<center>");

$sql = "select 
studylevel.studat AS studat,
  studylevel.stuid as stuid ,
  studylevel.stutim as stutim ,
  serieslevel.mod as mod
  from patientlevel,studylevel,serieslevel 
 where patientlevel.patid = studylevel.patparent
 and studylevel.stuinsuid = serieslevel.stuparent
 and patientlevel.patid = '$patid'
 group by 
  serieslevel.mod ,
  studylevel.stutim ,
  studylevel.stuid  ,
  studylevel.studat
  order by 
  studylevel.studat desc ";

  $rtn = pg_exec($sql);


  for ($n=0;$n < pg_numrows($rtn);$n++) {

//    $study_uid = pg_result($rtn,$n,"stuinsuid");
    $stutim = pg_result($rtn,$n,"stutim");
    $stuid = pg_result($rtn,$n,"stuid");
    $mod = pg_result($rtn,$n,"mod");
    $studat = pg_result($rtn,$n,"studat");

    $date = $studat;
    $fdate = FormatDate($studat);

  $patid_trim = trim($patid);
  $trimed_mod = trim($mod);

//(douto option)
//  if stutim is not valid data form,,,
	if(!fnmatch("*NM*", $mod)){
	  $ruid = "$date"."$trimed_mod"."$stutim";
	}
	if(fnmatch("*NM*", $mod)){
	  $ruid = "$date"."$trimed_mod"."$patid_trim";
	}
//

//ishikai option
//  $ruid = "$date"."$stutim"."$mod";


//	  $ruid = "$patid"."$date"."$mod";

  
  $study_info ="Attach to report of " .  "$fdate" . " and " . "$mod" ;

print("<form action=marking_update.php method=post>");
print("<input type=hidden name=jpg_file_name_tmp value=$jpg_file_name_tmp>");
print("<input type=hidden name=ruid value=$ruid>");
print("<input type=submit value=$study_info>");
print("</form>");

	}

?>







</body>
</html>
