#!/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 - Modify Clip Properties</TITLE>
</head>
<BODY >
<H3>Error: you have not selected any clips to modify!</H3>
<A HREF="$WSA/cgi-bin/modclipform">
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 - Modify Clip Properties</TITLE>
</head>
<BODY >
<H1>Modify Clip Properties</H1>
<h3>Modify any field you want. New data will be saved in the database.</h3>
<h4> Make sure that all values reported as NULL are filled in. 
Otherwise, update will fail!</h4>
<h4>To get stream parameters from an .frs file, fill in any of the
fields as "Auto"</h4>
<HR>
<FORM ACTION="$WSA/cgi-bin/modclipdoit" METHOD="POST">
EndOfHTML

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

$csr = &ora_open
($lda, "select title, length, encoding, filesize, bitrate,
framerate, archiveid, accesslevel, downld, fnail, dateinsert, frsname
from cliptable where clipid=$clipid ");

($title, $length, $encoding, $filesize, $bitrate, $framerate,
$archiveid, $accesslevel, $downld, $fnail, $dateinsert, 
$frsname) = &ora_fetch($csr);

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

if ( $frsname eq "" ) { $frsnamedef = "$PROJDIR/CP/frs/???.frs" }
if ( $fnail eq "" ) { $fnaildef = "$WSA/fingernails/dummy.gif" }
if ( $dateinsert eq "" ) { $dateinsertdef = "NULL!" }
if ( $filesize eq "" ) { $filesizedef = "Auto" }
if ( $bitrate eq "" ) { $bitratedef = "Auto" }
if ( $length eq "" ) { $lengthdef = "Auto" }

print <<"EndOfHTML";
<CENTER>
<TD><INPUT TYPE="HIDDEN" NAME="clipid" VALUE = "$clipid" SIZE = "0"> 
<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Basic Clip Data:</h3></CAPTION>

<TR><TD>Title:</TD>
<TD><INPUT TYPE="text" NAME="title" VALUE="$title" SIZE="35"></TD>
<TD>Clip ID</TD><TD>$clipid</TD></TR>

<TR><TD>*.frs file:</TD>
<TD><INPUT NAME="frsname" SIZE="38" VALUE="
EndOfHTML
print ($frsname || $frsnamedef ) ;
print <<"EndOfHTML";
"></TD><TD>Encoding</TD><TD><SELECT NAME="encoding">
EndOfHTML

if($encoding eq "MPEG1") { print "<OPTION SELECTED>MPEG1 </OPTION>" }
else { print "<OPTION>MPEG1</OPTION>" }
if($encoding eq "MPEG2") { print "<OPTION SELECTED>MPEG2 </OPTION>" }
else { print "<OPTION>MPEG2</OPTION>" }
if($encoding eq "AVI") { print "<OPTION SELECTED>AVI </OPTION>" }
else { print "<OPTION>AVI</OPTION>" }
if($encoding eq "QT") { print "<OPTION SELECTED>QT </OPTION>" }
else { print "<OPTION>QT</OPTION>" }
if($encoding eq "H263") { print "<OPTION SELECTED>H263 </OPTION>" }
else { print "<OPTION>H263</OPTION>" }

print <<"EndOfHTML";
</SELECT></TD></TR>

<TR><TD>
EndOfHTML

if ( $fnail ne ""  ) {print "<a href=$WSA$fnail> Fingernail URL </a>"}
else {print " Fingernail URL" }
print <<"EndOfHTML";
</TD>
<TD COLSPAN=1><INPUT NAME="fnail" SIZE="35" VALUE="
EndOfHTML
print ( $fnail || $fnaildef );
print <<"EndOfHTML";
">
<TD>Date inserted:</TD>
<TD><INPUT NAME="dateinsert" SIZE="10" VALUE="
EndOfHTML
print ( $dateinsert || $dateinsertdef );
print <<"EndOfHTML";
"></TD></TR>
</TABLE>
<BR>
</center>
EndOfHTML

print <<"EndOfHTML";
<CENTER>
<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Stream Attributes:</h3></CAPTION>
<TR><TD> Clip length (frames):</TD>
<TD><INPUT NAME="length" SIZE="8" VALUE="
EndOfHTML
print ( $length || $lengthdef );
print <<"EndOfHTML";
"></TD>
<TD>Clip file size (bytes):</TD>
<TD><INPUT NAME="filesize" SIZE="12" VALUE="
EndOfHTML
print ( $filesize || $filesizedef );
print <<"EndOfHTML";
"></TD></TR>
<TR><TD> Frame rate (fps):</TD>
<TD><SELECT NAME="framerate">
EndOfHTML
if($framerate == 30) { print "<OPTION SELECTED>30</OPTION>" }
else { print "<OPTION>30</OPTION>" }
if($framerate == 25) { print "<OPTION SELECTED>25</OPTION>" }
else { print "<OPTION>25</OPTION>" }
if($framerate == 24) { print "<OPTION SELECTED>24</OPTION>" }
else { print "<OPTION>24</OPTION>" }
if($framerate == 15) { print "<OPTION SELECTED>15</OPTION>" }
else { print "<OPTION>15</OPTION>" }
if($framerate == 12) { print "<OPTION SELECTED>12</OPTION>" }
else { print "<OPTION>12</OPTION>" }
if($framerate == 10) { print "<OPTION SELECTED>10</OPTION>" }
else { print "<OPTION>10</OPTION>" }
if($framerate == 7) { print "<OPTION SELECTED>7</OPTION>" }
else { print "<OPTION>7</OPTION>" }
print <<"EndOfHTML";
</SELECT></TD>
<TD>Bit rate (Kbps):</TD>
<TD><INPUT NAME="bitrate" SIZE="12" VALUE="
EndOfHTML
print ( $bitrate || $bitratedef );
print <<"EndOfHTML";
"></TD></TR>
</TABLE>
</CENTER>
<BR>
EndOfHTML

print <<"EndOfHTML";
<CENTER>
<TABLE BORDER="2" WIDTH="90%">
<CAPTION><h3>Clip Access Attributes:</h3></CAPTION>
<TR><TD> Archive:</TD>
<TD><SELECT NAME="archiveid">
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 ( $aid eq $archiveid ) {
    print ("<OPTION VALUE=\"$aid\" SELECTED>$aname \n");
  } 
   elsif ( $archiveid eq "" & $aname eq "Default" ) {
      print ("<OPTION VALUE=\"$aid\" SELECTED>$aname \n");
  } 
  else {
      print ("<OPTION VALUE=\"$aid\">$aname \n");
    }
}   
&ora_close($csr);

print <<"EndOfHTML";
</SELECT></TD>
<TD>Access level:</TD>
<TD><SELECT NAME="accesslevel">
EndOfHTML
if($accesslevel eq "ALL") { print "<OPTION SELECTED>ALL</OPTION>" }
else { print "<OPTION>ALL</OPTION>" }
if($accesslevel eq "SUBSCRIB") { print "<OPTION SELECTED>SUBSCRIB</OPTION>" }
else { print "<OPTION>SUBSCRIB</OPTION>" }
if($accesslevel eq "INTERNAL") { print "<OPTION SELECTED>INTERNAL</OPTION>" }
else { print "<OPTION>INTERNAL</OPTION>" }
if($accesslevel eq "ADMIN") { print "<OPTION SELECTED>ADMIN</OPTION>" }
else { print "<OPTION>ADMIN</OPTION>" }
print <<"EndOfHTML";
</SELECT></TD>
<TD> Downloadable: </TD>
<TD><SELECT NAME="downld">
EndOfHTML
print "<OPTION>$downld";
if($downld eq  "NO" ) { print "<OPTION SELECTED>NO" }
else { print "<OPTION>NO" }
if($downld eq "YES" ) { print "<OPTION SELECTED>YES" }
else { print "<OPTION>YES" }
print <<"EndOfHTML";
</SELECT></TD></TR>
</TABLE>
</CENTER>
<BR>
EndOfHTML

print <<"EndOfHTML";
<P>
Currently available on the following server(s):<P>
EndOfHTML

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

while (($serverid, $filename) = &ora_fetch($cur))
{
    $csr  = &ora_open
    ($lda, " select sname from servertable where serverid=$serverid " );
    while (($sname) = &ora_fetch($csr))
    {
	print "<LI> <B>$sname</B> \n";
    }
    &ora_close($csr);
}

&ora_close($cur);

print <<"EndOfHTML";
<BR>  To delete clip from a server, use <a href=delclipform>Delete clip</a> 
procedure.
<BR>  To modify file name on a server, use <a href=chanclipform>
Modify clip/server</a> procedure.
<HR>
<INPUT TYPE="SUBMIT" VALUE="MODIFY CLIP">
<INPUT TYPE="RESET" VALUE="RESET">
</FORM>
<HR>
<A HREF="$WSA/cgi-bin/modclipform">MODIFY ANOTHER</A>
</BODY>
</HTML>
EndOfHTML

