#!/oracle/app/oracle/product/7.3.3/bin/oraperl

##### set Oracle's variables #####
$ENV{'ORACLE_HOME'}='/oracle/app/oracle/product/7.3.3';
$ENV{'ORACLE_SID'}='rabbit';
$orauser="vod";
$orapass="vod";

#### set web server address ####
$WSA = "http://clarissa.npac.syr.edu/vod";
$PROJDIR="/project/K136/VOD";




$input = <>;
#chop $input;

@param = split(/\&/, $input );

foreach (@param)
{
    ##### for URL decoding ######
    ### convert plus to space ###
    $_ =~ s/\+/ /g;
    ### convert %XX from hex numbers to alphanumeric ###
    $_ =~ s/%(..)/pack("c", hex($1))/ge;

    $archiveid = $1 if /archiveid=(.*)/;
}

if ( $archiveid eq "" ) {
print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML";
<HTML>
<TITLE>Video News Database - Delete Collection</TITLE>
<BODY bgcolor="coral">
<H3>Error: you have not selected any archive to delete!</H3>
<A HREF="$WSA/cgi-bin/delcollform">
Another chance...</A>
</BODY>
</HTML>
EndOfHTML
die;
}
 
if ( $archiveid eq "" ) {
print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML";
<HTML>
<TITLE>Video News Database - Delete Archive </TITLE>
<BODY bgcolor="coral">
<H3>Error: you have not selected an archive to delete!</H3>
<A HREF="$WSA/cgi-bin/delcollform">
Another chance...</A>
</BODY>
</HTML>
EndOfHTML
die;
}

print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML"; 
<HTML>
<TITLE>Video News Database - Delete Archive </TITLE>
<BODY bgcolor="coral">
<H1> Results of the Delete  Archive operation</H1>
<HR>
EndOfHTML


##### logon oracle #####
$lda = &ora_login('', $orauser, $orapass);

$csr=&ora_open($lda,"select ANAME from ARCHIVETABLE where ARCHIVEID=$archiveid");
($aname) = &ora_fetch($csr);
&ora_close($csr);

$csr=&ora_open($lda,"select ARCHIVEID from ARCHIVETABLE where ANAME='Default'");
($defid) = &ora_fetch($csr);
&ora_close($csr);

print "<FONT Size=\"4\">";
print "Moving clips in the archive '$aname' to archive Default (ID=$defid).<BR>";
print "<FONT Size=\"3\">";
print "From CLIPTABLE : ";
$query  = "update CLIPTABLE set ARCHIVEID='$defid' ";
$query .= "  where ARCHIVEID=$archiveid";
$ret = &ora_do($lda, $query);
if($ret>=1) {
  print "$ret rows are updated.<BR>";
} else {
  print "No rows are updated.<BR>";
}


print "<FONT Size=\"4\">";
print "<B>Deleting the archive named '$aname'.</B><BR>";
print "<FONT Size=\"3\">";
print "From ARCHIVETABLE : ";
$ret = &ora_do ($lda, " delete from ARCHIVETABLE where ARCHIVEID = $archiveid ");
if($ret==1) { 
  print "$ret row deleted successfully.<BR>";
  &ora_commit($lda);
} else { 
  print "Error occured. ORACLE error $ora_errnum: $ora_errstr<BR>"; 
}


##### logoff oracle #####
&ora_commit($lda);
&ora_logoff($lda);

print <<"EndOfHTML"; 
<HR>
<A HREF="$WSA/cgi-bin/delcollform">DELETE ANOTHER</A>
</BODY>
</HTML>
EndOfHTML

