#!/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=(.*)/;
}

if ( $clipid eq "" ) {
print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML"; 
<HTML>
<head>
<script>
document.bgColor=top.menu.document.bgColor
</script>
<TITLE>Video News Database - Delete a Clip </TITLE>
</head>
<BODY >
<H3>Error: you have not selected any clips to delete!</H3>
<A HREF="$WSA/cgi-bin/delclipform">
Another chance...</A>
</BODY>
</HTML>
EndOfHTML
die;
}

print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML"; 
<HTML>
<head>
<script>
document.bgColor=top.menu.document.bgColor
</script>
<TITLE>Video News Database - Delete a Clip</TITLE>
</head>
<BODY >
<H1>Delete a Clip</H1>
<HR>
<FORM ACTION="$WSA/cgi-bin/delclipdoit" METHOD="POST">
EndOfHTML

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

$csr = &ora_open
($lda, "select title from cliptable where clipid=$clipid ");

($title)=&ora_fetch($csr);

if ( $ora_errno ) {
print "CLIPTABLE SELECT: ORACLE error, $ora_errstr , error $ora_errno  <BR>";
}
&ora_close($csr);

print <<"EndOfHTML";
<CENTER>
<TD><INPUT TYPE="HIDDEN" NAME="clipid" VALUE = "$clipid" SIZE = "0"> 
<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Clip to Delete:</h3></CAPTION>
<TR><TD>Title:</TD> <TD><B>$title</B></TD>
<TD>Clip ID</TD><TD><B>$clipid</B></TD>
</TR>
</TABLE>
<BR>
</center>
EndOfHTML


print <<"EndOfHTML";
<CENTER>
<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Currently available on the following server(s):</h3></CAPTION>
EndOfHTML

$cur = &ora_open
($lda, " select serverid, filename from clipserver where clipid = $clipid ");

$lastentry = 0;
while (($serverid, $filename) = &ora_fetch($cur))
{
  $lastentry++;
  $fn = $filename;
  $csr  = &ora_open
  ($lda, " select sname from servertable where serverid=$serverid " );
  ($sname) = &ora_fetch($csr);
  print <<"EndOfHTML";
  <TR><TD>Server:</TD><TD><B>$sname</B></TD>
  <TD>Filename:</TD><TD><B>$filename</B></TD></TR>
EndOfHTML
}
print <<"EndOfHTML";
  </TABLE>
  <BR>
  </center>
EndOfHTML
&ora_close($csr);
&ora_close($cur);
 
print <<"EndOfHTML";
<B>Select a server to delete the clip from:</B>
<INPUT TYPE="HIDDEN" NAME="lastentry"  VALUE="$lastentry">
<SELECT NAME="serverid">
<OPTION VALUE=\"-1\">ALL SERVERS
EndOfHTML

$cur = &ora_open ($lda, " select serverid, filename from clipserver 
where clipid = $clipid order by serverid ");

$count = 0;
while ( ($sid, $filename) = &ora_fetch($cur) ) {
  $csr = &ora_open ($lda, " select sname from servertable 
                            where serverid=$sid ");
  ($sname) = &ora_fetch($csr);
  $count++;

  if ($count) {
    print ("<OPTION VALUE=\"$sid\" SELECTED>$sname \n");
  } else {
    print ("<OPTION VALUE=\"$sid\">$sname \n");
  }
}

&ora_close($csr);
&ora_logoff($lda);

print <<"EndOfHTML";
</SELECT></TD></TR>
<HR>
<INPUT TYPE="SUBMIT" VALUE="DELETE CLIP">
<INPUT TYPE="RESET" VALUE="RESET">
</FORM>
<HR>
<A HREF="$WSA/cgi-bin/delclipform">Delete Another</A>
</BODY>
</HTML>
EndOfHTML
