2007-10-11 17:06:08 +00:00
|
|
|
require "functions.pl";
|
2007-10-10 21:48:12 +00:00
|
|
|
|
|
|
|
CGI::Session->name($session_name);
|
|
|
|
$query = CGI->new(\&hook);
|
|
|
|
$session = new CGI::Session;
|
|
|
|
|
2007-10-11 17:26:39 +00:00
|
|
|
sub hook
|
2007-10-16 19:52:53 +00:00
|
|
|
{
|
2007-10-10 21:48:12 +00:00
|
|
|
#this is going to become an ajax progress bar
|
2007-10-15 00:25:23 +00:00
|
|
|
#alternatively, reloading every N seconds (mozilla doesn't flicker)
|
2007-10-10 21:48:12 +00:00
|
|
|
my ($filename, $buffer, $bytes_read, $data) = @_;
|
2007-10-11 10:57:52 +00:00
|
|
|
#print $ENV{'CONTENT_LENGTH'};
|
|
|
|
#print sha256_hex($buffer);
|
2007-10-10 21:48:12 +00:00
|
|
|
#open(TEMP, ">>/var/www/perl/videos/temp.temp") or die "cannot open";
|
2007-10-11 10:57:52 +00:00
|
|
|
#print "Read $bytes_read bytes of $filename\n";
|
2007-10-10 21:48:12 +00:00
|
|
|
#close TEMP;
|
|
|
|
}
|
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
@userinfo = get_userinfo_from_sid($session->id);
|
2007-10-10 21:48:12 +00:00
|
|
|
|
2007-10-29 15:00:40 +00:00
|
|
|
@page = get_page_array(@userinfo);
|
2007-10-27 09:17:30 +00:00
|
|
|
|
2007-12-11 15:05:33 +00:00
|
|
|
if($userinfo->{'id'}&&$query->param("DC.Title") && $query->param("DC.Description") && $query->param("DC.Subject"))
|
2007-10-11 17:26:39 +00:00
|
|
|
{
|
2007-10-11 10:00:38 +00:00
|
|
|
#connect to db
|
|
|
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
|
|
|
|
2007-10-17 12:55:35 +00:00
|
|
|
#make new entry for video into the databse
|
2007-10-21 19:17:36 +00:00
|
|
|
#FIXME: contributor, rights
|
2007-10-24 11:25:18 +00:00
|
|
|
$dbh->do(qq{insert into uploaded (title, description, userid, timestamp,
|
|
|
|
creator, subject, contributor, source, language, coverage, rights)
|
|
|
|
values ( ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ? )}, undef,
|
2007-10-29 15:00:40 +00:00
|
|
|
$query->param("DC.Title"), $query->param("DC.Description"), $userinfo->{'id'},
|
2007-10-24 11:25:18 +00:00
|
|
|
$query->param("DC.Creator"), $query->param("DC.Subject"), '', $query->param("DC.Source"),
|
|
|
|
$query->param("DC.Language"), $query->param("DC.Coverage"), '') or die $dbh->errstr;
|
2007-10-12 00:34:32 +00:00
|
|
|
|
2007-10-17 12:55:35 +00:00
|
|
|
#get the id of the inserted db entry
|
2007-10-12 00:34:32 +00:00
|
|
|
$sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
2007-10-11 10:57:52 +00:00
|
|
|
$sth->execute() or die $dbh->errstr;
|
|
|
|
my ($id) = $sth->fetchrow_array() or die $dbh->errstr;
|
|
|
|
$sth->finish() or die $dbh->errstr;
|
|
|
|
|
|
|
|
#save uploaded file into temppath
|
2007-10-10 21:48:12 +00:00
|
|
|
$upload_filehandle = $query->upload("file");
|
2007-10-29 21:26:39 +00:00
|
|
|
open(TEMPFILE, ">$root/tmp/$id") or die "cannot open";
|
2007-10-10 21:48:12 +00:00
|
|
|
while ( <$upload_filehandle> )
|
|
|
|
{
|
2007-10-11 10:57:52 +00:00
|
|
|
print TEMPFILE;
|
2007-10-10 21:48:12 +00:00
|
|
|
}
|
2007-10-11 10:57:52 +00:00
|
|
|
close TEMPFILE;
|
2007-10-11 10:00:38 +00:00
|
|
|
|
2007-10-27 09:17:30 +00:00
|
|
|
$page->{'message'}->{'type'} = "information";
|
|
|
|
$page->{'message'}->{'text'} = "information_uploaded";
|
2007-10-11 10:00:38 +00:00
|
|
|
|
|
|
|
#disconnect db
|
|
|
|
$dbh->disconnect() or die $dbh->errstr;
|
2007-10-11 17:26:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-21 22:55:29 +00:00
|
|
|
$page->{'message'}->{'type'} = "error";
|
|
|
|
$page->{'message'}->{'text'} = "error_202c";
|
2007-10-10 21:48:12 +00:00
|
|
|
}
|
2007-10-27 09:17:30 +00:00
|
|
|
#print xml http header along with session cookie
|
|
|
|
print $session->header(-type=>'text/xml', -charset=>'UTF-8');
|
|
|
|
|
|
|
|
#print xml
|
|
|
|
print XMLout($page, KeyAttr => {}, XMLDecl => $XMLDecl, RootName => 'page', AttrIndent => '1');
|