From 26aa0d906e975513920af33336b67bae07d05f7b Mon Sep 17 00:00:00 2001 From: finlayt Date: Mon, 16 Sep 2002 05:42:23 +0000 Subject: [PATCH] dosearch.pl replaces search.pl for the new templated opac. I thought it should have another name because there are so many search.pl around! However dosearch.pl isnt actually that great a name :) detail.pl now uses the new templating mechanism. --- tmpl/detail.pl | 38 ++------- tmpl/dosearch.pl | 108 ++++++++++++++++++++++++ tmpl/search.pl | 212 ----------------------------------------------- 3 files changed, 114 insertions(+), 244 deletions(-) create mode 100755 tmpl/dosearch.pl delete mode 100755 tmpl/search.pl diff --git a/tmpl/detail.pl b/tmpl/detail.pl index dabc97a437..e588530249 100755 --- a/tmpl/detail.pl +++ b/tmpl/detail.pl @@ -1,34 +1,16 @@ #!/usr/bin/perl -use HTML::Template; use strict; require Exporter; -use C4::Database; use C4::Output; # contains picktemplate use CGI; use C4::Search; +use C4::Auth; my $query=new CGI; +my ($loggedinuser, $cookie, $sessionID) = checkauth($query, 1); -my $language='french'; - - -my %configfile; -open (KC, "/etc/koha.conf"); -while () { - chomp; - (next) if (/^\s*#/); - if (/(.*)\s*=\s*(.*)/) { - my $variable=$1; - my $value=$2; - # Clean up white space at beginning and end - $variable=~s/^\s*//g; - $variable=~s/\s*$//g; - $value=~s/^\s*//g; - $value=~s/\s*$//g; - $configfile{$variable}=$value; - } -} +my $template = gettemplate ("detail.tmpl", "opac"); my $biblionumber=$query->param('bib'); my $type='intra'; @@ -56,20 +38,13 @@ my $itemsarray=\@items; my $webarray=\@webbiblioitems; my $sitearray=\@websites; -my $includes=$configfile{'includes'}; -($includes) || ($includes="/usr/local/www/hdl/htdocs/includes"); -my $templatebase="opac/detail.tmpl"; + my $startfrom=$query->param('startfrom'); ($startfrom) || ($startfrom=0); -my $theme=picktemplate($includes, $templatebase); - -my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); my $count=1; # now to get the items into a hash we can use and whack that thru - - $template->param(startfrom => $startfrom+1); $template->param(endat => $startfrom+20); $template->param(numrecords => $count); @@ -77,12 +52,11 @@ my $nextstartfrom=($startfrom+20<$count-20) ? ($startfrom+20) : ($count-20); my $prevstartfrom=($startfrom-20>0) ? ($startfrom-20) : (0); $template->param(nextstartfrom => $nextstartfrom); $template->param(prevstartfrom => $prevstartfrom); -# $template->param(template => $templatename); -# $template->param(search => $search); -$template->param(includesdir => $includes); + $template->param(BIBLIO_RESULTS => $resultsarray); $template->param(ITEM_RESULTS => $itemsarray); $template->param(WEB_RESULTS => $webarray); $template->param(SITE_RESULTS => $sitearray); + print "Content-Type: text/html\n\n", $template->output; diff --git a/tmpl/dosearch.pl b/tmpl/dosearch.pl new file mode 100755 index 0000000000..147f63647f --- /dev/null +++ b/tmpl/dosearch.pl @@ -0,0 +1,108 @@ +#!/usr/bin/perl +use strict; +require Exporter; +use CGI; +use C4::Search; +use C4::Auth; +use C4::Output; # now contains picktemplate + +my $query=new CGI; + +my ($loggedinuser, $cookie, $sessionID) = checkauth($query, 1); + + +my $template; +my $subject=$query->param('subject'); +# if its a subject we need to use the subject.tmpl +if ($subject) { + $template = gettemplate ("subject.tmpl", "opac"); +} else { + $template = gettemplate ("searchresults.tmpl", "opac"); +} + +# get all the search variables +# we assume that C4::Search will validate these values for us +my @fields = ('keyword', 'subject', 'author', 'illustrator', 'itemnumber', 'isbn', 'date-before', 'date-after', 'class', 'dewey', 'branch', 'title', 'abstract', 'publisher'); + + + +# collect all the fields ... +my %search; +my $forminputs; +my $searchdesc = ''; +foreach my $field (@fields) { + $search{$field} = $query->param($field); + if ($search{$field}) { + push @$forminputs, {field => $field, value => $search{$field}}; + $searchdesc .= "$field = $search{$field}, "; + } +} +$search{'ttype'} = $query->param('ttype'); +push @$forminputs, {field => 'ttype', value => $search{'ttype'}}; + +if (my $subjectitems=$query->param('subjectitems')){ + $search{'subject'} = $subjectitems; + $searchdesc.="subject = $subjectitems, "; +} + +@$forminputs=() unless $forminputs; +$template->param(FORMINPUTS => $forminputs); + +# do the searchs .... +my $env; +$env->{itemcount}=1; +my $num=10; +my @results; +my $count; +my $startfrom = $query->param('startfrom'); +my $subjectitems=$query->param('subjectitems'); +if ($subjectitems) { + my $blah; + @results = subsearch(\$blah,$subjectitems, $num, $startfrom); + $count = $#results+1; +} else { + ($count, @results) = catalogsearch($env,'',\%search,$num,$startfrom); +} + +my $startfrom=$query->param('startfrom'); +($startfrom) || ($startfrom=0); + +my $resultsarray=\@results; +($resultsarray) || (@$resultsarray=()); + + +# sorting out which results to display. +$template->param(startfrom => $startfrom+1); +($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count)); +$template->param(numrecords => $count); +my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1); +my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1); +$template->param(nextstartfrom => $nextstartfrom); +my $displaynext=1; +my $displayprev=0; +($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1); +($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1); +$template->param(displaynext => $displaynext); +$template->param(displayprev => $displayprev); +$template->param(prevstartfrom => $prevstartfrom); + +$template->param(searchdesc => $searchdesc); +$template->param(SEARCH_RESULTS => $resultsarray); +$template->param(loggedinuser => $loggedinuser); + +my $numbers; +@$numbers = (); +if ($count>10) { + for (my $i=1; $i<$count/10+1; $i++) { + my $highlight=0; + my $themelang = $template->param('themelang'); + ($startfrom==($i-1)*10) && ($highlight=1); + push @$numbers, { number => $i, highlight => $highlight , startfrom => ($i-1)*10 }; + } +} + +$template->param(numbers => $numbers); + + +print $query->header(-cookie => $cookie), $template->output; + diff --git a/tmpl/search.pl b/tmpl/search.pl deleted file mode 100755 index 34e0587fa9..0000000000 --- a/tmpl/search.pl +++ /dev/null @@ -1,212 +0,0 @@ -#!/usr/bin/perl -use HTML::Template; -use strict; -require Exporter; -use C4::Database; -use CGI; -use C4::Search; -use C4::Auth; -use C4::Output; # now contains picktemplate - -my $query=new CGI; -#my $type=$query->param('type'); -#(-e "opac") && ($type='opac'); -my $type = 'opac'; - -my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0)); - - -my $language='french'; - - -my %configfile; -open (KC, "/etc/koha.conf"); -while () { - chomp; - (next) if (/^\s*#/); - if (/(.*)\s*=\s*(.*)/) { - my $variable=$1; - my $value=$2; - # Clean up white space at beginning and end - $variable=~s/^\s*//g; - $variable=~s/\s*$//g; - $value=~s/^\s*//g; - $value=~s/\s*$//g; - $configfile{$variable}=$value; - } -} -#print $query->header; - -my $includes=$configfile{'includes'}; -($includes) || ($includes="/usr/local/www/hdl/htdocs/includes"); -my $templatebase="opac/searchresults.tmpl"; -my $startfrom=$query->param('startfrom'); -($startfrom) || ($startfrom=0); -my $theme=picktemplate($includes, $templatebase); - -my $subject=$query->param('subject'); -# if its a subject we need to use the subject.tmpl -if ($subject) { - $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/; - $theme=picktemplate($includes, $templatebase); -} - -my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]); - -my $env; -$env->{itemcount}=1; - -# get all the search variables -# we assume that C4::Search will validate these values for us -my %search; -my $keyword=$query->param('keyword'); -$search{'keyword'}=$keyword; - -$search{'subject'}=$subject; -my $author=$query->param('author'); -$search{'author'}=$author; -$search{'authoresc'}=$author; -#$search{'authorhtmlescaped'}=~s/ /%20/g; -my $illustrator=$query->param('illustrator'); -$search{'param'}=$illustrator; -my $itemnumber=$query->param('itemnumber'); -$search{'itemnumber'}=$itemnumber; -my $isbn=$query->param('isbn'); -$search{'isbn'}=$isbn; -my $datebefore=$query->param('date-before'); -$search{'date-before'}=$datebefore; -my $class=$query->param('class'); -$search{'class'}=$class; -my $dewey=$query->param('dewey'); -$search{'dewey'}; -my $branch=$query->param('branch'); -$search{'branch'}=$branch; -my $title=$query->param('title'); -$search{'title'}=$title; -my $abstract=$query->param('abstract'); -$search{'abstract'}=$abstract; -my $publisher=$query->param('publisher'); -$search{'publisher'}=$publisher; - -my $ttype=$query->param('ttype'); -$search{'ttype'}=$ttype; - -my $forminputs; -($keyword) && (push @$forminputs, { line => "keyword=$keyword"}); -($subject) && (push @$forminputs, { line => "subject=$subject"}); -($author) && (push @$forminputs, { line => "author=$author"}); -($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"}); -($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"}); -($isbn) && (push @$forminputs, { line => "isbn=$isbn"}); -($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"}); -($class) && (push @$forminputs, { line => "class=$class"}); -($dewey) && (push @$forminputs, { line => "dewey=$dewey"}); -($branch) && (push @$forminputs, { line => "branch=$branch"}); -($title) && (push @$forminputs, { line => "title=$title"}); -($ttype) && (push @$forminputs, { line => "ttype=$ttype"}); -($abstract) && (push @$forminputs, { line => "abstract=$abstract"}); -($publisher) && (push @$forminputs, { line => "publisher=$publisher"}); -($forminputs) || (@$forminputs=()); -$template->param(FORMINPUTS => $forminputs); -# whats this for? -# I think it is (or was) a search from the "front" page... [st] -$search{'front'}=$query->param('front'); - -my $num=10; -my @results; -my $count; -if (my $subject=$query->param('subjectitems')) { - my $blah; - @results=subsearch(\$blah,$subject); - $count=$#results+1; -} else { - ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom); -} - -#my $resultsarray=\@results; -my $resultsarray; - -foreach my $result (@results) { - $result->{'authorhtmlescaped'}=$result->{'author'}; - $result->{'authorhtmlescaped'}=~s/ /%20/g; - ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}=''); - ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0); - push (@$resultsarray, $result); -} -($resultsarray) || (@$resultsarray=()); -my $search="num=20"; -my $searchdesc=''; -if ($keyword){ - $search=$search."&keyword=$keyword"; - $searchdesc.="keyword $keyword, "; -} -if (my $subjectitems=$query->param('subjectitems')){ - $search=$search."&subjectitems=$subjectitems"; - $searchdesc.="subject $subjectitems, "; -} -if ($subject){ - $search=$search."&subject=$subject"; - $searchdesc.="subject $subject, "; -} -if ($author){ - $search=$search."&author=$author"; - $searchdesc.="author $author, "; -} -if ($class){ - $search=$search."&class=$class"; - $searchdesc.="class $class, "; -} -if ($title){ - $search=$search."&title=$title"; - $searchdesc.="title $title, "; -} -if ($dewey){ - $search=$search."&dewey=$dewey"; - $searchdesc.="dewey $dewey, "; -} -$search.="&ttype=$ttype"; - -$search=~ s/ /%20/g; -$template->param(startfrom => $startfrom+1); -($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count)); -$template->param(numrecords => $count); -my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1); -my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1); -$template->param(nextstartfrom => $nextstartfrom); -my $displaynext=1; -my $displayprev=0; -($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1); -($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1); -$template->param(displaynext => $displaynext); -$template->param(displayprev => $displayprev); -($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0)); -$template->param(prevstartfrom => $prevstartfrom); -$template->param(search => $search); -$template->param(searchdesc => $searchdesc); -$template->param(SEARCH_RESULTS => $resultsarray); -$template->param(includesdir => $includes); -$template->param(loggedinuser => $loggedinuser); - -my $numbers; -@$numbers=(); -if ($count>10) { - for (my $i=1; $i<$count/10+1; $i++) { - ($title) && (push @$forminputs, { line => "title=$title"}); - my $highlight=0; - ($startfrom==($i-1)*10) && ($highlight=1); - my $formelements=''; - foreach (@$forminputs) { - my $line=$_->{line}; - $formelements.="$line&"; - } - $formelements=~s/ /+/g; - push @$numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => $forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))}; - } -} - -$template->param(numbers => $numbers); - - - -print $query->header(-cookie => $cookie), $template->output; - -- 2.39.5