#!/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;

    $serverid = $1 if /serverid=(.*)/;
    $sname = $1 if /sname=(.*)/;
}

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

print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML"; 
<HTML>
<TITLE>Video News Database - Delete Server </TITLE>
<BODY bgcolor="tan">
<H1> Delete a Server  - operation results</H1>
<HR>
EndOfHTML
##### logon oracle #####
$lda = &ora_login('', $orauser, $orapass);

$csr=&ora_open($lda,"select SNAME from SERVERTABLE where SERVERID=$serverid");
($sname) = &ora_fetch($csr);
&ora_close($csr);
#
# WRONG IDEA!
#
print "<FONT Size=\"4\">";
print "Deleting clips in the server '$sname'.<BR>";
print "<FONT Size=\"3\">";
#print "From CLIPTABLE : ";
#$query  = "delete from CLIPTABLE where CLIPID in ";
#$query .= "  (select CLIPID from CLIPSERVER where SERVERID=$serverid)"; 
#$ret = &ora_do($lda, $query);
#if($ret>=1) {
#  print "$ret rows are deleted.<BR>";
#  &ora_commit($lda);
#} else {
#  print "No rows are deleted.<BR>";
#}

#print "From CAPTIONS : ";
#$query  = "delete from CAPTIONS where CLIPID in ";
#$query .=   "(select CLIPID from CLIPSERVER where SERVERID=$serverid)"; 
#$ret = &ora_do($lda, $query);
#if($ret>=1) {
#  print "$ret rows are deleted.<BR>";
#  &ora_commit($lda);
#} else {
#  print "No rows are deleted.<BR>";
#}

print "From CLIPSERVER : ";
$ret = &ora_do($lda, " delete from clipserver where serverid = $serverid ");
if($ret>=1) {
  print "$ret rows are deleted.<BR>";
  &ora_commit($lda);
} else {
  print "No rows are deleted.<BR>";
}
print "<BR>";

print "<FONT Size=\"4\">";
print "<B>Deleting the server named '$sname'.</B><BR>";
print "<FONT Size=\"3\">";
print "From SERVERTABLE : ";
$ret = &ora_do ($lda, " delete from SERVERTABLE where SERVERID = $serverid ");
if($ret==1) { 
  print "$ret row deleted successfully.<BR>";
  &ora_commit($lda);
} else { 
  print "Error occured.<BR>$ora_errstr<BR>"; 
}


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

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

