#!/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=(.*)/;
    $words = $1 if /keywords=(.*)/;
}
 
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 - Play Clip</TITLE>
</head>
<BODY>
<H3>Error: you haven't selected a clip to play!</H3>
<A HREF="playclipform">
Another chance...</A>
</BODY>
</HTML>
EndOfHTML
die;
}

@capwords = split(/\+/,$words);

print "Content-type: text/html\n\n ";

print <<"EndOfHTML";
<HTML>
<head>
<script>
document.bgColor=top.menu.document.bgColor
</script>
<TITLE>NPAC VoD Database search results</TITLE>
</head>
<BODY>
<HR><h2>NPAC VoD Database query results: </H2><HR>

<FORM ACTION="playclip.nvs" METHOD="POST">
EndOfHTML

if($words eq '') {
  $captionquery = " FRAME=0 ";
  } else {
  foreach(@capwords) {
    push(@capquery,"TEXT like '%$_%'");
  } 
  $captionquery = join(' and ', @capquery);
  print <<"EndOfHTML";
  <h3> You have searched for: @capwords <h3>
  <h4> If this phrase has multiple occurences, you can start video
       playback at any of the associated time codes.<h4>
EndOfHTML
} 

print <<"EndOfHTML";
<h4>If this clip is available on more than one server, you may select 
the video server to deliver the clip.</h4>
EndOfHTML

$lda=&ora_login('',$orauser,$orapass);
$csr=&ora_open
($lda, "select title, length, encoding, filesize, archiveid, 
        fnail, dateinsert, framerate from cliptable where clipid=$clipid ");

($title, $len, $enc, $filsiz, $aid, $fnail, $dateinsert, $framerate ) = 
&ora_fetch($csr);

print <<"EndOfHTML";
<INPUT TYPE="HIDDEN" NAME="clipid" value="$clipid">
<INPUT TYPE="HIDDEN" NAME="len" value="$len">
<INPUT TYPE="HIDDEN" NAME="filsiz" value="$filsiz">
<INPUT TYPE="HIDDEN" NAME="enc" value="$enc">
EndOfHTML

#print "$ora_errstr<BR>";
&ora_close($csr);
$csr=&ora_open
($lda, "select aname, adesc from archivetable where archiveid=$aid ");  
($aname, $adesc) = &ora_fetch($csr);
#print "$ora_errstr<BR>";
&ora_close($csr);

print "<BR>";
print "<CENTER><TABLE BORDER=1 WIDTH=99%> ";
print "<TR><TD align=center>Title</TD>";
print "<TD align=center>Archive</TD>"; 
print "<TD align=center>Duration</TD>";
print "<TD align=center>Playback starts at</TD>";
print "<TD align=center>Codec</TD>"; 
print "<TD align=center>Server</TD></tr>";


print "<TR><TD align=center>";
#print "<A HREF=\"vnsshow.nvs?\n";
#print "$clipid&$server&$fname&$enc&$len&$frame&type.nvs\n";
print "<B>$title</B>";
print "</TD>\n";
print "<TD align=center>$aname</TD>\n";

$len = int($len/$framerate);		
$minute = int($len/60);	
$second = ($len%60);		
print "<TD align=center> $minute min $second sec.\n </TD>";

if ( $words eq "" ) { 
print "<TD align=center>the beginning</TD>"; 
$frame = 0;
print "<INPUT TYPE=\"HIDDEN\" NAME=\"frame\" value=\"$frame\">";
} else {
  $query = " select frame from captions where clipid=$clipid 
             and $captionquery order by frame";
  #print " $query <br>";
  $csr = &ora_open ($lda, $query); 
  print "<TD align=center><SELECT NAME=\"frame\">";
  while ( ($frame) = &ora_fetch($csr) ) {
    $len = int($frame/$framerate);
    $minute = int($len/60);
    $second = ($len%60);	
    print " <OPTION VALUE=\"$frame\">$minute min $second sec.\n ";
  }
  print "</SELECT></TD>";
}

print "<TD align=center>$enc</TD>\n ";

print "<TD align=center><SELECT NAME=\"serverid\">";
$cur = &ora_open
($lda, " select serverid, filename from clipserver where clipid = $clipid
order by serverid ");

while (($sid, $filename) = &ora_fetch($cur))
{
  $cur1  = &ora_open
  ($lda, " select sname from servertable where serverid=$sid " );
  ($sname) = &ora_fetch($cur1);
  print ("<OPTION VALUE=\"$sid\">$sname \n");
  &ora_close($cur1);
}
&ora_close($cur);
print "</SELECT>\n";
print "</TD>";

print "</TABLE></CENTER><BR><BR>\n";
&ora_logoff($lda);

print <<"EndOfHTML";
<INPUT TYPE="SUBMIT" VALUE="PLAY CLIP">
</FORM>
<HR>
<A HREF="vnsqueryform"> Specify Another Search</A> /
<A HREF="playclipform">Select Another Clip to Play</A> 
<HR><ADDRESS>Please report problems to NPAC VoD Group</ADDRESS>
<ADDRESS> Marek Podgorny <A Href="mailto:marek@npac.syr.edu">        
          &lt;marek@npac.syr.edu&gt;</A><BR>                 
          Last Modified on Sun Aug 18 23:12:20 EDT 1996
</address>              
</BODY>
</HTML>
EndOfHTML



