#! /usr/oracle/bin/oraperl


########  Read the parameters from the stdin ######

$inp_line=<>;
chop $inp_line;


### split the input line ###
@param = split(/\&/, $inp_line );



foreach (@param)
{
    ##### for URL decoding ######
    ### convert plus to space ###
    $_ =~ s/\+/ /g;
    ### convert %XX from hex numbers to alphanumeric ###
    $_ =~ s/%(..)/pack("c", hex($1))/ge;

    $title    = $1 if /title=(.*)/;
    $server   = $1 if /server=(.*)/;
    $filename = $1 if /filename=(.*)/;
    $encoding = $1 if /encoding=(.*)$/;
    $url      = $1 if /url=(.*)/;    

    $length   = $1 if /length=(.*)/;
    $st_frame = $1 if /st_frame=(.*)/;
    $en_frame = $1 if /en_frame=(.*)/;
    $st_offset = $1 if /st_offset=(.*)/;
    $en_offset = $1 if /en_offset=(.*)/;
    $cap_path = $1 if /path=(.*)/;
}

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


print ("<h2>\n");
print (" title: $title <BR>\n");
print (" server: $server <BR>\n");
print (" filename: $filename <BR>\n");
print (" encoding: $encoding <BR>\n");
print (" url foff: $url <BR>\n");
print (" length: $length <BR>\n");
print (" st_frame: $st_frame <BR>\n");
print (" en_frame: $en_frame <BR>\n");
print (" st_offset: $st_offset <BR>\n");
print (" en_offset: $en_offset <BR>\n");
print (" cap_path: $cap_path <BR>\n");
print ("</H2>\n");

##### set Oracle's env variables #####
$ENV{'ORACLE_HOME'}='/usr/oracle';
$ENV{'ORACLE_SID'}='nodb';

##### logon Oracle #####

$lda = &ora_login('','michal','michal');

print ("Login Data Area: $lda <BR>\n");

##### find the max clipid #####

$max = &ora_open($lda, "select max(clipid) from clip ");
$clipid = (&ora_fetch($max))[0];
&ora_close($max);
$clipid++;			# now you have a free clipid to assign value to

##### find & open the cap file #####
#
#
#
##### insert values to Oracle #####

&ora_do($lda, 
"insert into clip values($clipid, '$title', '$server', '$filename', 
'$encoding', $length, $st_frame, $en_frame, $st_offset, $en_offset,
'$url')");

##### logoff Oracle #####
&ora_logoff($lda);
 
