#!/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 - Clone a Clip </TITLE>
</head>
<BODY >
<H3>Error: you have not selected any clips to clone!</H3>
<A HREF="$WSA/cgi-bin/cloneclipform">
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 - Clone a Clip</TITLE>
</head>
<BODY >
<H1>Clone a Clip</H1>
<HR>
<FORM ACTION="$WSA/cgi-bin/cloneclipdoit" 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 Clone:</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
         order by serverid ");

while (($serverid, $filename) = &ora_fetch($cur))
{
  $fn = $filename;
  push (@sl,$serverid);
  $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 clone the clip:</B>
<SELECT NAME="serverid">
EndOfHTML

$csr = &ora_open ($lda, " select distinct serverid, sname from servertable ");
skip: while ( ($sid, $sname) = &ora_fetch($csr) ) {
        foreach $elem (@sl) {
          if ( $sid == $elem ) {next skip;}
        } 
        print ("<OPTION VALUE=\"$sid\">$sname \n")
}
&ora_close($csr);
&ora_logoff($lda);

print <<"EndOfHTML";
</SELECT></TD></TR>
<BR>
<B>Select the clip file name on this server:</b>
<INPUT NAME="filename" SIZE="35" VALUE="$fn">
<HR>
<INPUT TYPE="SUBMIT" VALUE="CLONE CLIP">
<INPUT TYPE="RESET" VALUE="RESET">
</FORM>
<HR>
<A HREF="$WSA/cgi-bin/cloneclipform">CLONE ANOTHER</A>
</BODY>
</HTML>
EndOfHTML
