<?php
/*
    ANISEED, NISEED System and Database
    Copyright (C) 2007 Olivier Tassy, Fabrice Daian, Patrick Lemaire

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
	include("connection.php");
//Title before frames_header
print '<title>ANISEED - All clones FASTA</title>';

    $id=$_POST["id"];
	if(count($id)==0){
	    print"Error: Select the sequences you want to download.";
		return;
	}
	print "<pre>\n";
	for($a=0; $a<count($id); ++$a){
	
		$requete="select A.\"SEQUENCE\", B.\"NAME\" from \"SEQUENCE\" A, \"CLONE_SEQ\" B where A.\"MOL_ID\"=B.\"CLONE_SEQ_ID\" and B.\"GENBANK_ID\"='".$id[$a]."'";
		$stmt = pg_query($c,$requete);
        
		if($row=pg_fetch_array($stmt)){
		    $lob = $row["SEQUENCE"];
		    
		/* DEBUT DE L'AFFICHAGE DU CLOB */

		pg_query ($c, "begin");	/*Debut de la transaction*/
		
		$handle_lo = pg_lo_open($c,$lob,"r");
		$seq=pg_lo_read($handle_lo);

		pg_query($c,"end"); /*fin de la Transaction*/

		/* FIN DE L'AFFICHAGE DU LOB */



			$seq=ereg_replace("<br>","",$seq);
			$seq=ereg_replace("\n","",$seq);

			//$seq = chunk_split($seq, 70, "\n");
		
		    print ">$id[$a] | ".$row["NAME"]."\n$seq\n\n";
		}
	}
	print "</pre>";
?>