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


# builds a form for clip addition
# TO DO:
# 1. automatic upload of the fingernail gif from stage to server


$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;

    $archiveid = $1 if /archiveid=(.*)/;
}

$Date = `date +%d-%b-%y`;

print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML"; 
<HTML>
<head>
<script>
document.bgColor=top.menu.document.bgColor
</script>
<TITLE>Add  clip to the Video Database</TITLE>
</head>
<BODY>
<H1>Add  clip to the Video Database</H1>
<HR>
EndOfHTML

print "<FORM ACTION=\"addclip\" NAME=\"addfm\" METHOD=\"POST\">";

print <<"EndOfHTML";
<CENTER>
<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Basic Clip Data:</h3></CAPTION>
<TR><TD> Title:</TD>
<TD><INPUT TYPE="text" NAME="title" SIZE="35"></TD>
<SCRIPT>
var enc = '.mpg'
</SCRIPT>
<TD>Clip encoding:</TD>
<TD><SELECT NAME="encoding" 
onChange="
if(document.addfm.encoding.options[2].selected) { enc = '.avi' }
if(document.addfm.encoding.options[3].selected) { enc = '.mov' }
if(document.addfm.encoding.options[4].selected) { enc = '.263' }
">
<OPTION VALUE="MPEG1" SELECTED>MPEG1</OPTION>
<OPTION VALUE="MPEG2">MPEG2</OPTION>
<OPTION VALUE="AVI">AVI</OPTION>
<OPTION VALUE="QT">QuickTime</OPTION>
<OPTION VALUE="H263">H263</OPTION>
</SELECT></TD></TR>
<TR><TD>Clip file:</TD>
<TD><INPUT NAME="filename" SIZE="35" VALUE="d:/movies/"
onBlur="var lg=document.addfm.filename.value.length;
          var li=document.addfm.filename.value.lastIndexOf('/');
          var filnam=document.addfm.filename.value.substring(li+1,lg);
          document.addfm.filename.value += enc;
"></TD>
<TD> Select a server: </TD>
<TD><SELECT NAME="serverid">
EndOfHTML

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

#print "lda : $lda\n";
$csr = &ora_open ($lda, " select distinct serverid, sname from servertable ");
#print "$ora_errstr\n";
while ( ($sid, $sname) = &ora_fetch($csr) ) {
  print ("<OPTION VALUE=\"$sid\">$sname \n");
}
&ora_close($csr);
#&ora_logoff($lda);

print <<"EndOfHTML";
</SELECT></TD></TR>
<TR><TD>*.frs file name:</TD>
<TD COLSPAN=1><INPUT NAME="frsfile" SIZE="38" VALUE="$PROJDIR/CP/frs/"></TD>
<TD>Date inserted:</TD>
<TD><INPUT NAME="dateinsert" SIZE="15" VALUE=
EndOfHTML

print $Date, "\n";

print <<"EndOfHTML";
</TD></TR>
</TABLE>
<BR>

<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Stream Attributes:</h3></CAPTION>
<TR><TD> Clip length (frames):</TD>
<TD><INPUT NAME="length" SIZE="8" VALUE="Auto"></TD>
<TD>Clip file size (bytes):</TD>
<TD><INPUT NAME="filsiz" SIZE="12" VALUE="Auto"></TD></TR>
<TR><TD> Frame rate (fps):</TD>
<TD><SELECT NAME="framerate">
<OPTION>30
<OPTION>25
<OPTION>24
<OPTION>15
<OPTION>12
<OPTION>10
<OPTION>7
</SELECT></TD>
<TD>Bit rate (Kbps):</TD>
<TD><INPUT NAME="bitrate" SIZE="12" VALUE="Auto"></TD></TR>
</TABLE>
<BR>

<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Clip Access Attributes:</h3></CAPTION>
<TR><TD> Archive:</TD>
<TD><SELECT NAME="archive">
EndOfHTML

$csr = &ora_open 
($lda, " select distinct archiveid, aname from archivetable order by aname ");
#print "$ora_errstr\n";
while ( ($aid, $aname) = &ora_fetch($csr) ) {
  if ( ($archiveid eq 0 && $aname eq "Default") || $aid eq $archiveid ) {
    print ("<OPTION VALUE=\"$aid\" SELECTED>$aname \n");
  } else {
    print ("<OPTION VALUE=\"$aid\">$aname \n");
  }
}
&ora_close($csr);
&ora_logoff($lda);

print <<"EndOfHTML";
</SELECT></TD>
<TD>Access level:</TD>
<TD><SELECT NAME="access">
<OPTION>ALL
<OPTION>SUBSCRIB
<OPTION>INTERNAL
<OPTION>ADMIN
</SELECT></TD>
<TD> Downloadable: </TD>
<TD><SELECT NAME="downloadable">
<OPTION>NO
<OPTION>YES
</SELECT></TD></TR>
</TABLE>
</CENTER>
<BR>
The following entries are <B>optional:</B><P>
<LI>Caption file name (*.cap) : 
<INPUT NAME="capfile" SIZE="45" VALUE=
"$PROJDIR/CP/cap/empty.cap"><BR>

<LI>Fingernail file name (*.gif) : 
<INPUT NAME="fnailfile" SIZE="45" VALUE=
"$PROJDIR/CP/fnail/dummy.gif"><BR>

<LI>Fingernail URL on the server :
<INPUT NAME="fnailurl" SIZE="25" VALUE=
"$WSA/fingernails/dummy.gif"><BR>

<LI>Annotations to the clip: <BR>
Where this annotation starts (enter frame number (0-start)):
<INPUT NAME="ann_start" SIZE="10" VALUE="0"><BR>
Select data type : 
<SELECT NAME="datatype">
<OPTION>NO ANNOTATION
<OPTION>TEXT
<OPTION>HTML
<OPTION>IMAGE
<OPTION>SOUND
</SELECT><BR>
For textual annotations only:
<TEXTAREA NAME="annotations" ROWS="3" COLS="60">
</TEXTAREA>
<P>
<INPUT TYPE="Submit" VALUE="ADD CLIP">
<INPUT TYPE="Reset" VALUE="RESET">
</FORM>
<HR>
</BODY>
</HTML> 
EndOfHTML
