From 19dfc0d3f88afa7c15d80c9de66f64b734800da9 Mon Sep 17 00:00:00 2001 From: josch Date: Sun, 21 Oct 2007 16:41:29 +0000 Subject: [PATCH] added additional rescue functionality git-svn-id: http://yolanda.mister-muffin.de/svn@109 7eef14d0-6ed0-489d-bf55-20463b2d70db --- trunk/video.pl | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/trunk/video.pl b/trunk/video.pl index 337899c..3ef99fa 100644 --- a/trunk/video.pl +++ b/trunk/video.pl @@ -6,7 +6,7 @@ CGI::Session->name($session_name); $query = new CGI; $session = new CGI::Session; -#check if query is set +#check if id or title is passed if($query->param('title') or $query->param('id')) { %page = (); @@ -24,25 +24,40 @@ if($query->param('title') or $query->param('id')) if($query->param('id')) { - #prepare query + #if id is passed ignore title and check for the id $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), creator, subject, contributor, source, language, coverage, rights, license from videos where id = ? }) or die $dbh->errstr; - #execute it $rowcount = $sth->execute($query->param('id')) or die $dbh->errstr; } else { - #prepare query + #if no id was passed there has to be a title we search for $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), creator, subject, contributor, source, language, coverage, rights, license from videos where title = ? }) or die $dbh->errstr; - #execute it $rowcount = $sth->execute($query->param('title')) or die $dbh->errstr; } - if($rowcount == 1) + #if the args are wrong there my be zero results + #if there was a title passed, then perform a search + if($rowcount == 0 and $query->param('title')) { + $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ), + creator, subject, contributor, source, language, coverage, rights, license + from videos where match(title, description, subject) against( ? ) }) or die $dbh->errstr; + $rowcount = $sth->execute($query->param('title')) or die $dbh->errstr; + } + + if($rowcount == 0) + { + #still no results + #there is nothing we can do now - this video doesn't exist... + #TODO: insert error output + } + elsif($rowcount == 1) + { + #if there was a single result, display the video my ($id, $title, $description, $userid, $timestamp, $creator, $subject, $contributor, $source, $language, $coverage, $rights, $license,) = $sth->fetchrow_array(); @@ -77,6 +92,7 @@ if($query->param('title') or $query->param('id')) } else { + #when an ambigous title was passed there may me many results - display them like search.pl does $page->{results}->{query} = decode_utf8($query->param('title')); #get every returned value while (my ($id, $title, $description, $userid, $timestamp) = $sth->fetchrow_array())