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

    $clipid = $1 if /clipid=(.*)/;
    $serverid = $1 if /serverid=(.*)/;
    $lastentry = $1 if /lastentry=(.*)/;
}
print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML";
<HTML>
<TITLE>Video News Database - Delete Clip - Clip: $clipid</TITLE>
<BODY bgcolor="gold">
<H1>Results of the Delete Clip operation:</H1>
<HR>
EndOfHTML
##### logon oracle #####
$lda = &ora_login('', $orauser, $orapass);

print "Clip ID : $clipid.<BR>";
print "Server ID : $serverid.<BR>";

if ( $serverid < 0 ) {
  $ret = &ora_do ($lda, " delete from CLIPSERVER 
  where clipid = $clipid ");
  $lastentry = 1;
} else {
  $ret = &ora_do ($lda, " delete from CLIPSERVER 
  where clipid = $clipid and serverid = $serverid ");
}

print "CLIPSERVER : ";
if($ret >= 1) {
  print "$ret row are deleted.<BR>";
} else {
  print "No rows are deleted.<BR>";
  print ("$ora_errstr<BR>\n");
  $lastentry = 2;
}

if ( $lastentry > 1 ) {
  &ora_commit($lda);
  &ora_logoff($lda);
  print <<"EndOfHTML"; 
  <HR>
  <A HREF="$WSA/cgi-bin/delclipform">DELETE ANOTHER</A>
  </B></BODY></HTML>
EndOfHTML
  die;
}

$ret = &ora_do ($lda, " delete from CLIPTABLE where clipid = $clipid ");
print "CLIPTABLE : ";
if($ret >= 1) {
  print "$ret row is deleted.<BR>";
} else {
  print "No rows are deleted.<BR>";
  print ("$ora_errstr<BR>\n");
}

$ret = &ora_do ($lda, " delete from CAPTIONS where clipid = $clipid ");
print "CAPTIONS : ";
if($ret >= 1) {
  print "$ret rows are deleted.<BR>";
} else {
  print "No rows are deleted.<BR>";
  print ("$ora_errstr<BR>\n");
}

$ret = &ora_do ($lda, " delete from ANNOTATIONS where clipid = $clipid ");
print "ANNOTATIONS : ";
if($ret >= 1) {
  print "$ret rows are deleted.<BR>";
} else {
  print "No rows are deleted.<BR>";
  print ("$ora_errstr<BR>\n");
}

&ora_commit($lda);
&ora_logoff($lda);

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

