<?php

	include ("connection.php");
	include ("frames_header.php"); 

	if ( (!isset($_SESSION["login"]))or(!isset($_SESSION["pass"])) ) {
	    print "<strong>you need to <a href=\"login.php\">login</a> as an authorised curator to proceed.</strong>";
	    print '</center></body></html>';
		return;
	}


    $id=$_GET["id"]; 	    
	
    $khoueiry = "SELECT * FROM \"SEQUENCE\" WHERE \"MOL_ID\"=".$id.";";	
	$stmt = pg_query($c,$khoueiry);
	
	if($row=pg_fetch_array($stmt)){
	    $comm = $row["COMMENTS"];
	    $lob = $row["SEQUENCE"];		
		pg_query ($c, "begin");		
		$handle_lo = pg_lo_open($c,$lob,"r");
		$seq=pg_lo_read($handle_lo);
		pg_lo_close($handle_lo);
		pg_query($c,"end");			

		echo '<form name="form1" method="POST" action="sequence-edit-result.php">
		<center>';

		print "<p>Sequence: <textarea valign=\"top\" rows=\"10\" name=\"SEQUENCE\" cols=\"80\">$seq</textarea></p>	
		<p>Comments: <textarea rows=\"3\" name=\"COMMENTS\" cols=\"50\">$comm</textarea></p>";		
	
		print "<br><br><img src=\"pictures/button-cur-delete.gif\" title=\"Cancel\"  onClick=\"javascript:self.close();\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
		<input name=\"submit\" type=\"image\" src=\"pictures/button-cur-validate.gif\" onClick=\"submit\" title=\"Ok\">
		<input type=\"hidden\" name=\"ID\" value=\"$id\"/>
		<input type=\"hidden\" name=\"LOB_ID\" value=\"$lob\"/></center></form>";		
	}else{
		//MODIFICATION: case of there is no sequence yet in the database
		echo '<form name="form1" method="POST" action="sequence-edit-result.php">
		<center>';

		print "<p>Sequence: <textarea valign=\"top\" rows=\"10\" name=\"SEQUENCE\" cols=\"80\">$seq</textarea></p>	
		<p>Comments: <textarea rows=\"3\" name=\"COMMENTS\" cols=\"50\">$comm</textarea></p>";		
	
		print "<br><br><img src=\"pictures/button-cur-delete.gif\" title=\"Cancel\"  onClick=\"javascript:self.close();\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
		<input name=\"submit\" type=\"image\" src=\"pictures/button-cur-validate.gif\" onClick=\"submit\" title=\"Ok\">
		<input type=\"hidden\" name=\"ID\" value=\"$id\"/>
		<input type=\"hidden\" name=\"LOB_ID\" value=\"$lob\"/></center></form>";	
		//END OF MODIFICATION

		//SET in comment because of the modification
		/*print "<br><br><h2><strong>No match</strong></h2><br><br>";*/
	}

include ("frames_footer.php"); 

?>