<html><head><title>Feature Noting</title></head><body>
<?php
include '../../../lib/ConnectSatellite_images.php';
$conn =  new Connect();
$dbconn = $conn->db_handle();

$feat = $HTTP_POST_VARS['feat'];
$file_id = $HTTP_POST_VARS['id'];
$filename = $HTTP_POST_VARS['filename'];
$newfeat = $HTTP_POST_VARS['newfeat'];

foreach ($feat as $feat_id) {
$query = "insert into feat_on_file (featonfile_id, file_id, feat_id) values (nextval('feat_on_file_featonfile_id_seq'), $file_id, $feat_id)";

if (pg_query($dbconn, $query)) {
echo '<P>Feature(s) noted.<P>'; 
}

} #endfor

if (!empty($newfeat)) {

$query1 = "insert into features (feat_id, featname) values (nextval('features_feat_id_seq'), '$newfeat')";
if (pg_query($dbconn, $query1)) {echo "New feature added.<P>"; }
else {echo "<P>Something went wrong. Here's the query that didn't work: $query1<P>";}

$query2 = "select feat_id from features where featname = '$newfeat'";
$getnewfeat = pg_query($dbconn, $query2);
$newfeat_id = pg_fetch_object($getnewfeat,0);

$query3 = "insert into feat_on_file (featonfile_id, file_id, feat_id) values (nextval('feat_on_file_featonfile_id_seq'),$file_id, $newfeat_id->feat_id)";
if (pg_query($dbconn, $query3)) {echo "New feature noted.<P>"; }
else {echo "<P>Something went wrong. Here's the query that didn't work: $query3<P>";}

} #endif

echo '<hr><a href="'.substr($filename, 0, -4).'.php">Back to image</a><P></body></html>';

?>
