<?php
    include("connection.php");
    include("frames_header.php");
?>
<?php
     $del=$_POST["fatelist"];
     $fate=$_POST["newfate"];
	 if(strlen($fate)>0){
		 $requete= "SELECT * from \"FATE_KW\" where \"KEYWORDS\"='$fate'";
		 $stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
		 if(!$row=pg_fetch_array($stmt)){
			 $requete= "insert into \"FATE_KW\" (\"KEYWORDS\") values('$fate')";
			pg_query($c,"begin"); 
			$stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
			pg_query($c,"commit");
			 
			 
		 }
	 }
	 if(strlen($del)>0){
			 $requete= "delete from \"FATE_KW\" where \"KEYWORDS\"='$del'";
			pg_query($c,"begin"); 
			$stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
			 pg_query($c,"commit");
	 }
?>
<form  target="_self" action="anatomy-new_fate.php" method="post">
<center>
<table width="99%" cellspacing="0" cellpadding="0" background="pictures/barre.jpg">
    <TR>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</TR><TR>
		<td>New fate keyword*:&nbsp;<input type="text" name="newfate">
		<td>&nbsp;</td>

		<td align="right">Available fates:&nbsp;</td>
		<td align="left"><select name="fatelist" size="10">
        <?php
			 $requete= "SELECT \"KEYWORDS\" from \"FATE_KW\" order by \"KEYWORDS\"";
			 $stmt = pg_query($c,$requete) or die("<strong>Error</strong> ".pg_last_error($c));
			 while($row=pg_fetch_array($stmt))
				print "<option value=\"".$row["KEYWORDS"]."\">".$row["KEYWORDS"]."</option>\n";
		?>
        </select>
		</td>
        <td align="center"><em><font size="-1">Select to delete.<br>this keyword must not be in use</font></em></td>
    </TR><TR>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</TR><TR>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td><input name="submit" type="image" src="pictures/button-submit.jpg" onClick="submit">&nbsp;&nbsp;&nbsp;</td>
	</TR>
</table>
</center>
</form>
<br><br><br>
<!--*Separate multiple entries with a space.-->

<?php
    include("frames_footer.php");
?>