<?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'];
$pointy = $_GET['pointy'];
$pointx = $_GET['pointx'];
@$comment = $_GET['comment'];


?>

<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
}


function linkIt(theField) {
	location.replace(theField[theField.selectedIndex].value);
}

function linkradio(theField) {
	location.replace(theField.value);
}

  function mdwn(e){
	location.replace( "marking_tmp.php?pointx=" + getMouseX(e) + "&pointy=" + getMouseY(e) + "&jpg_file_name=" + "<?php echo $jpg_file_name?>&jpg_file_name_tmp=<?php echo $jpg_file_name_tmp?>&ruid=<?php echo $ruid?>&patid=<?php echo $patid ?>&marktype=<?php echo $marktype ?>" );
  }

  

//-->
</script>

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




<?php



$size = 512;


//if($browser == "mozzila"){
//print("$browser<br>");
$pointx = $pointx + 4;
$pointy = $pointy + 9;

//}

if($pointx){
			$font = 7;
        	$im = imagecreatefromjpeg($jpg_file_name_tmp);
        	$white = imagecolorallocate($im,255,255,255);
        	$red = imagecolorallocate($im,255,0,0);
//        	imagestring($im,$font,3,0,$pointx,$white);

        if($marktype == "ul"){
                imagepolygon( $im, array( $pointx-12,$pointy-17, $pointx+30,$pointy+3, $pointx+8,$pointy+23 ), 3,$red );
                imagefilledpolygon( $im, array( $pointx-12,$pointy-17, $pointx+30,$pointy+3, $pointx+8,$pointy+23), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }


        if($marktype == "ur"){
                imagepolygon( $im, array( $pointx-12,$pointy-17, $pointx-52,$pointy+3, $pointx-32,$pointy+23 ), 3,$red );
                imagefilledpolygon( $im, array( $pointx-12,$pointy-17, $pointx-52,$pointy+3, $pointx-32,$pointy+23 ), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }

                if($marktype == "dl"){
                imagepolygon( $im, array(  $pointx-12,$pointy-17, $pointx+30,$pointy-37, $pointx+8,$pointy-57 ), 3,$red );
                imagefilledpolygon( $im, array(  $pointx-12,$pointy-17, $pointx+30,$pointy-37, $pointx+8,$pointy-57 ), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }
                if($marktype == "dr"){
                imagepolygon( $im, array(  $pointx-12,$pointy-17, $pointx-52,$pointy-37, $pointx-32,$pointy-57 ), 3,$red );
                imagefilledpolygon( $im, array(  $pointx-12,$pointy-17, $pointx-52,$pointy-37, $pointx-32,$pointy-57 ), 3,$red );
                imagejpeg($im,$jpg_file_name_tmp);
                        }

                if($marktype == "sround"){
                ImageArc($im, $pointx-12,$pointy-17,50,50,0,360,$red);
                imagejpeg($im,$jpg_file_name_tmp);
                        }
                if($marktype == "lround"){
                ImageArc($im, $pointx-12,$pointy-17,100,100,0,360,$red);
                imagejpeg($im,$jpg_file_name_tmp);
                        }

                if($marktype == "mround"){
                ImageArc($im, $pointx-12,$pointy-17,75,75,0,360,$red);
                imagejpeg($im,$jpg_file_name_tmp);
                        }

        if($marktype == "up"){
                imagepolygon( $im, array( $pointx-12,$pointy-17, $pointx-27,$pointy+18, $pointx+3,$pointy+18 ), 3,$red );
                imagefilledpolygon( $im, array( $pointx-12,$pointy-17, $pointx-27,$pointy+18, $pointx+3,$pointy+18 ), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }


        if($marktype == "down"){
                imagepolygon( $im, array( $pointx-12,$pointy-17, $pointx-27,$pointy-52, $pointx+3,$pointy-52 ), 3,$red );
                imagefilledpolygon( $im, array( $pointx-12,$pointy-17, $pointx-27,$pointy-52, $pointx+3,$pointy-52 ), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }


        if($marktype == "rt"){
                imagepolygon( $im, array( $pointx-12,$pointy-17, $pointx-47,$pointy-32, $pointx-47,$pointy-2 ), 3,$red );
                imagefilledpolygon( $im, array( $pointx-12,$pointy-17, $pointx-47,$pointy-32, $pointx-47,$pointy-2 ), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }
						
       if($marktype == "lt"){
                imagepolygon( $im, array( $pointx-12,$pointy-17, $pointx+20,$pointy-32, $pointx+20,$pointy-2 ), 3,$red );
                imagefilledpolygon( $im, array( $pointx-12,$pointy-17, $pointx+20,$pointy-32, $pointx+20,$pointy-2 ), 3,$red );

                imagejpeg($im,$jpg_file_name_tmp);
                        }

		
		}


	if($comment){


		system("convert -font helvetica -fill white -pointsize 36 -draw 'text 20,40 \"$comment\"' $jpg_file_name_tmp $jpg_file_name_tmp ");

		}

		print("<A ><IMG SRC=$jpg_file_name_tmp name=\"IMG\" WIDTH=\"$size\" ></a>");
		
		
if($marktype == "ul"){
	$mark_str = "Left-up arrow";
}
if($marktype == "ur"){
	$mark_str = "Right-up arrow";
}
if($marktype == "dl"){
	$mark_str = "Left-down arrow";
}
if($marktype == "dr"){
	$mark_str = "Right-down arrow";
}
if($marktype == "sround"){
	$mark_str = "Small circle";
}
if($marktype == "lround"){
	$mark_str = "Big circle";
}
if($marktype == "mround"){
	$mark_str = "Middle circle";
}
if($marktype == "up"){
	$mark_str = "Up arrow";
}
if($marktype == "down"){
	$mark_str = "Down arrow";
}
if($marktype == "rt"){
	$mark_str = "Right arrow";
}
if($marktype == "lt"){
	$mark_str = "Left arrow";
}

print("<br>Current mark type is <font color=red><b>$mark_str</b></font>");

?>

<script language='JavaScript'>
  document.IMG.onmousedown = mdwn
</script>


<br><B>Click to location of marking area</B>
<?php

print("<form action=marking_tmp.php method=post>");
print("Comment)<br><input type=text name=comment size=50>");
?>
<input type=hidden name=jpg_file_name value="<?php echo $jpg_file_name; ?>">
<input type=hidden name=jpg_file_name_tmp value="<?php echo $jpg_file_name_tmp; ?>">
<input type=hidden name=ruid value="<?php echo $ruid; ?>">
<input type=hidden name=patid value="<?php echo $patid; ?>">
<input type=hidden name=marktype value="<?php echo $marktype; ?>">
<input type=hidden name=pointx value="-500">
<input type=hidden name=pointy value="-500">
<input type=hidden name=marktype value="<?php echo $marktype; ?>">
<?php
print("<input type=submit value=Insert comment>");
print("</form>");
?>




<?php


	if($marktype == "ul"){
print("<input type=\"radio\" name=\"marktype\" checked=\"checked\" value=\"ul\"><img src=./img/lu.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=ul&pointx=-500&pointy=-500' )\" ><img src=./img/lu.jpg width=18 height=18>");
	}

	if($marktype == "ur"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\" value=\"ur\"><img src=./img/ru.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=ur&pointx=-500&pointy=-500' )\" ><img src=./img/ru.jpg width=18 height=18>");
	}

	if($marktype == "dl"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\" value=\"dl\"><img src=./img/ld.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=dl&pointx=-500&pointy=-500' )\" ><img src=./img/ld.jpg width=18 height=18>");
	}	

	if($marktype == "dr"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\" value=\"dr\"><img src=./img/dr.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=dr&pointx=-500&pointy=-500' )\" ><img src=./img/rd.jpg width=18 height=18>");
	}

	if($marktype == "sround"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\value=\"sround\">Small circle");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=sround&pointx=-500&pointy=-500' )\" >Small circle");
	}

	if($marktype == "mround"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\"mround\">Middle circle");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=mround&pointx=-500&pointy=-500' )\" >Middle circle");

	}

	if($marktype == "lround"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\"lround\">Big circle");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=lround&pointx=-500&pointy=-500' )\" >Big circle");

	}

	if($marktype == "up"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\"up\"><img src=./img/up.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=up&pointx=-500&pointy=-500' )\" ><img src=./img/up.jpg width=18 height=18>");
	}

	if($marktype == "down"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\"down\"><img src=./img/down.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=down&pointx=-500&pointy=-500' )\" ><img src=./img/down.jpg width=18 height=18>");
	}


	if($marktype == "rt"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\"rt\"><img src=./img/rt.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=rt&pointx=-500&pointy=-500' )\" ><img src=./img/rt.jpg width=18 height=18>");
	}


	if($marktype == "lt"){
	print("<input type=\"radio\" name=\"marktype\" checked=\"checked\"  value=\"lt\"><img src=./img/lt.jpg width=18 height=18>");
	}
	else{
	print("<input type=\"radio\" name=\"marktype\" value=\"ur\" onClick=\"javascript:location.replace( 'marking_tmp.php?jpg_file_name=$jpg_file_name&jpg_file_name_tmp=$jpg_file_name_tmp&ruid=$ruid&patid=$patid&marktype=lt&pointx=-500&pointy=-500' )\" ><img src=./img/lt.jpg width=18 height=18>");
	}
//html



?>








<form action=marking_update.php method=post>
<input type=hidden name=jpg_file_name_tmp value=<?php echo $jpg_file_name_tmp; ?>>
<input type=hidden name=jpg_file_name value=<?php echo $jpg_file_name; ?>>
<input type=hidden name=ruid value=<?php echo $ruid; ?>>
<input type=submit value="Attach image to report">
</form>

<form action=marking_select_report.php method=post>
<input type=hidden name=jpg_file_name_tmp value="<?php echo $jpg_file_name_tmp; ?>">
<input type=hidden name=patid value="<?php echo $patid; ?>">
<input type=submit value="select report">
</form>


</body>
</html>
