<?php

$ruid = $_GET['ruid'];
$date = $_GET['date'];
$patid = $_GET['patid'];
$studyUID = $_GET['studyUID'];
$patage = $_GET['patage'];
$patsex = $_GET['patsex'];
$name = $_GET['name'];


?>
<!doctype html public "-//w3c//dtd html 3.2//ja">
<html>
<head>
<title>refered image update to server</title>
<meta http-equiv=content-type content="image/jpeg; charset=x-euc-jp">


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

<?php

//
//	2002.1.1
//	DICOM to WWW Gateway :PHP script
//	Made by Norya Yokohama % Medical Division @ WERC
//  2005.3.12
//  added by tadashi tsuchimoto @ MITT belong to yokohamazyuku
//  show/exchange refer image 
//



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


//DB query

$db_handle = db_contact_start($db_type,$target_host,$target_db);




  $sql = "select 
  reportlevel.refimage2 as refimage2,
  reportlevel.refimage3 as refimage3,
  reportlevel.refimage4 as refimage4,
  reportlevel.refimage5 as refimage5,
  reportlevel.refimage6 as refimage6,
  reportlevel.refimage7 as refimage7,
  reportlevel.refimage8 as refimage8,
  reportlevel.refimage9 as refimage9,
  reportlevel.refimage10 as refimage10,
  reportlevel.refimage as refimage from reportlevel 
  where reportlevel.ruid ='$ruid'";


  $rtn_select = $db_handle->prepare($sql);
  $rtn_select->execute();
  
  
  $row_count = $rtn_select->rowCount();

/*
  $rtn2 = pg_exec($sql2);

  $flag = pg_num_rows($rtn2);
*/
//print("$flag<br>");

  if ($row_count>=1){

	while ($rtn_select_row = $rtn_select->fetch(PDO::FETCH_ASSOC)) {
	$refimage = $rtn_select_row['refimage'] ;
    $refimage2 = $rtn_select_row['refimage2'] ;
    $refimage3 = $rtn_select_row['refimage3'] ;
    $refimage4 = $rtn_select_row['refimage4'] ;
    $refimage5 = $rtn_select_row['refimage5'] ;
    $refimage6 = $rtn_select_row['refimage6'] ;
	$refimage7 = $rtn_select_row['refimage7'] ;
	$refimage8 = $rtn_select_row['refimage8'] ;
	$refimage9 = $rtn_select_row['refimage9'] ;
	$refimage10 = $rtn_select_row['refimage10'] ;
	}

  }else{
  print("Not Ready for Reporting.");
  }

print("<p>");





if($refimage){
	if($refimage2){
		if($refimage3){
			if($refimage4){
				if($refimage5){
					$ref_num = 6;
					      }
					$ref_num = 5;
				      }	
				$ref_num = 4;
				}
			$ref_num = 3;
			}
		$ref_num = 2;
	      }

if(!@$ref_num){
  $ref_num = 1;
}

if($refimage){
print("Reference Images<br>");
print("Layout<br>");
print("<table border=1>");
print("<tr><td>No.1</td><td>No.2</td><td>No.3</td></tr>");
print("<tr><td>No.4</td><td>No.5</td></tr>");
print("</table>");

print("<br>");
print("No.1");
print("<img src=\"show_refimage.php?ruid=$ruid&refimage=$refimage\" Width=170>");

}

if($refimage2){
print("No.2");
print("<img src=\"show_refimage.php?ruid=$ruid&refimage=$refimage2\" Width=170>");


}

if($refimage3){
print("No.3");
print("<img src=\"show_refimage.php?ruid=$ruid&refimage=$refimage3\" Width=170>");
}

if($refimage4){
print("<br>");
print("No.4");
print("<img src=\"show_refimage.php?ruid=$ruid&refimage=$refimage4\" Width=170>");
}


if($refimage5){
print("No.5");
print("<img src=\"show_refimage.php?ruid=$ruid&refimage=$refimage5\" Width=170>");
}



//  $con->dbClose;

?>

<form action="update_report_refer_do.php" method="post">
<select name=refer_num1>
<?php
	if($refimage){
		print("<option VALUE=$refimage>Image No.1");
	}
	if($refimage2){
		print("<option VALUE=$refimage2>Image No.2");
	}
	if($refimage3){
		print("<option VALUE=$refimage3>Image No.3");
	}
	if($refimage4){
		print("<option VALUE=$refimage4>Image No.4");
	}
	if($refimage5){
		print("<option VALUE=$refimage5>Image No.5");
	}


?>
   </select>
   
  AND 

<select name=refer_num2>
<?php
	if($refimage){
		print("<option VALUE=$refimage>Image No.1");
	}
	if($refimage2){
		print("<option VALUE=$refimage2>Image No.2");
	}
	if($refimage3){
		print("<option VALUE=$refimage3>Image No.3");
	}
	if($refimage4){
		print("<option VALUE=$refimage4>Image No.4");
	}
	if($refimage5){
		print("<option VALUE=$refimage5>Image No.5");
	}

?>
   </select>

<input type=hidden name=ruid value="<? echo $ruid; ?>">
<input type="submit" value="Swap of the Images">
</form>


<table>

<tr>
<td>

<FORM ENCTYPE="multipart/form-data" ACTION="referimage_do1.php" METHOD=POST >
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Register Image No.1">
</FORM>

</td>

<td>

<FORM action="referimage_del1.php" METHOD=POST>
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT TYPE="submit" VALUE="Erase Image No.1">
</FORM>


</td>

</tr>

<tr>

<td>

<FORM ENCTYPE="multipart/form-data" ACTION="referimage_do2.php" METHOD=POST>
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Register Image No.2">
</FORM>

</td>

<td>


<FORM action="referimage_del2.php" METHOD=POST>
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT TYPE="submit" VALUE="Erase Image No.2">
</FORM>

</td>

</tr>

<tr>

<td>


<FORM ENCTYPE="multipart/form-data" ACTION="referimage_do3.php" METHOD=POST >
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Register Image No.3">
</FORM>

</td>

<td>


<FORM action="referimage_del3.php" METHOD=POST >
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT TYPE="submit" VALUE="Erase Image No.3">
</FORM>


</td>


</tr>

<tr>

<td>


<FORM ENCTYPE="multipart/form-data" ACTION="referimage_do4.php" METHOD=POST >
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Register Image No.4">
</FORM>

</td>

<td>


<FORM action="referimage_del4.php" METHOD=POST>
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT TYPE="submit" VALUE="Erase Image No.4">
</FORM>


</td>


</tr>

<tr>

<td>



<FORM ENCTYPE="multipart/form-data" ACTION="referimage_do5.php" METHOD=POST >
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="10000000">
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Register Image No.5">
</FORM>

</td>

<td>


<FORM action="referimage_del5.php" METHOD=POST >
<input type=hidden name=ruid value="<? echo $ruid; ?>">
<INPUT TYPE="submit" VALUE="Erase Image No.5">
</FORM>


</td>

</tr>

</table>



</body>
</html>
