#!/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=(.*)/;
    $title    = $1 if /title=(.*)/;
    $encoding= $1 if /encoding=(.*)/;
    $length = $1 if /length=(.*)/;
    $filesize   = $1 if /filesize=(.*)/;
    $frsname  = $1 if /frsname=(.*)/;
    $archiveid  = $1 if /archiveid=(.*)/;
    $bitrate  = $1 if /bitrate=(.*)/;
    $framerate = $1 if /framerate=(.*)/;
    $accesslevel   = $1 if /accesslevel=(.*)/;
    $downld = $1 if /downld=(.*)/;
    $fnail = $1 if /fnail=(.*)/;
    $dateinsert = $1 if /dateinsert=(.*)/;
}


print ("Content-type: TEXT/HTML\n\n");
print <<"EndOfHTML";
<HTML>
<TITLE>Video News Database - Modify Clip Properties</TITLE>
<BODY bgcolor="gold">
<H1> Result of the Modify a Clip operation</H1>
<HR>
<FONT Size="4"> Input data <BR><BR>
<FONT Size="3">
Clip ID : $clipid <BR>
Clip title : $title <BR>
Archive ID : $archiveid <BR>
Date : $dateinsert <BR>
Accessibility : $accesslevel <BR>
Downloadable : $downld <BR>
FRS file : $frsname   <BR>
Fingernail URL : $fnail <BR>
Encoding :  $encoding <BR>
Length : $length frames  <BR>
Framerate : $framerate fps <BR>
File size : $filesize bytes  <BR>
Bitrate : $bitrate kpbs <BR>
<HR>
<FONT Size="4"> Result <BR><BR>
<FONT Size="3">
EndOfHTML

#### Get/calculate stream parameters ####

if ( $length eq "Auto" || $filesize eq "Auto" || $bitrate eq "Auto" ) {
  if(-r $frsname) {
    $lstlin = `tail -2 $frsname|head -1`;
    ($F,$L) = split(' ', $lstlin, 2);
    print "Got file size: ", $F, " frames, ", $L, " bytes<BR>";
    $t = $F/$framerate;
    print "Calculated duration: ", $t, " sec<BR>";
    $b = 8*$L*$framerate/($F*1000);
    print "Calculated bitrate: ", int($b), " Kbps<BR>";
    $length = $F ;
    $filesize = $L ;
    $bitrate = int($b) ;
  } else {
    print "Cannot read frs file. Could not verify stream parameters.<BR>";
    print "Requested modification failed. Enter stream data manually!";
    print <<"EndOfHTML"; 
    <HR>
    <A HREF="$WSA/vns2index.html">Asset Management Home Page</A> / 
    <A HREF="$WSA/cgi-bin/modclipform">MODIFY ANOTHER</A>
    </BODY>
    </HTML>
EndOfHTML
    die;
  }
}

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

$ret = &ora_do 
($lda, " update CLIPTABLE 
set TITLE='$title', ENCODING='$encoding', LENGTH='$length' ,
FILESIZE='$filesize', BITRATE='$bitrate', FRAMERATE='$framerate',
ARCHIVEID='$archiveid', ACCESSLEVEL='$accesslevel', DOWNLD='$downld',
FNAIL='$fnail', DATEINSERT='$dateinsert', FRSNAME='$frsname'
where CLIPID=$clipid");

if($ret==1) {
  print "CLIPTABLE: $ret row updated.<BR>";
} else {
  print "CLIPTABLE UPDATE: ORACLE error $ora_errno,  $ora_errstr<BR>";
  print <<"EndOfHTML"; 
<HR>
<A HREF="$WSA/vns2index.html">Asset Management Home Page</A> / 
<A HREF="$WSA/cgi-bin/modclipform">MODIFY ANOTHER</A>
</BODY>
</HTML>
EndOfHTML
  die;
}

print "Clip modification has been successful.<BR>";
&ora_commit($lda);
&ora_logoff($lda);

print <<"EndOfHTML"; 
<HR>
<A HREF="$WSA/cgi-bin/modclipform">MODIFY ANOTHER</A>
</BODY>
</HTML>
EndOfHTML


