From 9ed19645768a476e77e1ddbabbf897ee13b992f2 Mon Sep 17 00:00:00 2001 From: tonnesen Date: Thu, 11 Jul 2002 18:05:28 +0000 Subject: [PATCH] Committing changes to add authentication and opac templating to rel-1-2 branch --- C4/Auth.pm | 186 ++++++++++++ C4/Output.pm | 27 ++ C4/Reserves2.pm | 191 +++++++++++- C4/Search.pm | 598 +++++++++++++++++++++++++++---------- acqui.simple/addbooks.pl | 8 +- acqui.simple/marcimport.pl | 8 +- admin-home.pl | 27 ++ admin/templates.pl | 58 ++++ admin/z3950servers.pl | 286 ++++++++++++++++++ catalogue-home.pl | 32 ++ circ/circulation.pl | 9 +- circ/circulation2.pl | 8 +- detail.pl | 336 ++++++--------------- logout.pl | 66 ++++ mainpage.pl | 38 +++ member-password.pl | 72 +++++ memberentry.pl | 3 + members-home.pl | 26 ++ moredetail.pl | 269 ++++++----------- moremember.pl | 3 + reports-home.pl | 26 ++ search.pl | 498 +++++++++++------------------- shelves.pl | 16 +- 23 files changed, 1867 insertions(+), 924 deletions(-) create mode 100644 C4/Auth.pm create mode 100755 admin-home.pl create mode 100755 admin/templates.pl create mode 100755 admin/z3950servers.pl create mode 100755 catalogue-home.pl create mode 100755 logout.pl create mode 100755 mainpage.pl create mode 100755 member-password.pl create mode 100755 members-home.pl create mode 100755 reports-home.pl diff --git a/C4/Auth.pm b/C4/Auth.pm new file mode 100644 index 0000000000..d109cb6578 --- /dev/null +++ b/C4/Auth.pm @@ -0,0 +1,186 @@ +package C4::Auth; + +use strict; +use Digest::MD5 qw(md5_base64); + + +require Exporter; +use C4::Database; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); + +# set the version for version checking +$VERSION = 0.01; + +@ISA = qw(Exporter); +@EXPORT = qw( + &checkauth +); + + + +sub checkauth { + my $query=shift; + # $authnotrequired will be set for scripts which will run without authentication + my $authnotrequired=shift; + if (my $userid=$ENV{'REMOTE_USERNAME'}) { + # Using Basic Authentication, no cookies required + my $cookie=$query->cookie(-name => 'sessionID', + -value => '', + -expires => '+1y'); + return ($userid, $cookie, ''); + } + my $sessionID=$query->cookie('sessionID'); + my $message=''; + + my $dbh=C4Connect(); + my $sth=$dbh->prepare("select userid,ip,lasttime from sessions where sessionid=?"); + $sth->execute($sessionID); + if ($sth->rows) { + my ($userid, $ip, $lasttime) = $sth->fetchrow; + if ($lasttimeprepare("delete from sessions where sessionID=?"); + $sti->execute($sessionID); + my $scriptname=$ENV{'SCRIPT_NAME'}; + my $selfurl=$query->self_url(); + $sti=$dbh->prepare("insert into sessionqueries (sessionID, userid, value) values (?, ?, ?)"); + $sti->execute($sessionID, $userid, $selfurl); + open L, ">>/tmp/sessionlog"; + my $time=localtime(time()); + printf L "%20s from %16s logged out at %30s (inactivity).\n", $userid, $ip, $time; + close L; + } elsif ($ip ne $ENV{'REMOTE_ADDR'}) { + # Different ip than originally logged in from + my $newip=$ENV{'REMOTE_ADDR'}; + + $message="ERROR ERROR ERROR ERROR
Attempt to re-use a cookie from a different ip address.
(authenticated from $ip, this request from $newip)"; + } else { + my $cookie=$query->cookie(-name => 'sessionID', + -value => $sessionID, + -expires => '+1y'); + my $sti=$dbh->prepare("update sessions set lasttime=? where sessionID=?"); + $sti->execute(time(), $sessionID); + return ($userid, $cookie, $sessionID); + } + } + + + + if ($authnotrequired) { + my $cookie=$query->cookie(-name => 'sessionID', + -value => '', + -expires => '+1y'); + return('', $cookie, ''); + } else { + ($sessionID) || ($sessionID=int(rand()*100000).'-'.time()); + my $userid=$query->param('userid'); + my $password=$query->param('password'); + if (checkpw($dbh, $userid, $password)) { + my $sti=$dbh->prepare("delete from sessions where sessionID=? and userid=?"); + $sti->execute($sessionID, $userid); + $sti=$dbh->prepare("insert into sessions (sessionID, userid, ip,lasttime) values (?, ?, ?, ?)"); + $sti->execute($sessionID, $userid, $ENV{'REMOTE_ADDR'}, time()); + $sti=$dbh->prepare("select value from sessionqueries where sessionID=? and userid=?"); + $sti->execute($sessionID, $userid); + if ($sti->rows) { + my $stj=$dbh->prepare("delete from sessionqueries where sessionID=?"); + $stj->execute($sessionID); + my ($selfurl) = $sti->fetchrow; + print $query->redirect($selfurl); + exit; + } + open L, ">>/tmp/sessionlog"; + my $time=localtime(time()); + printf L "%20s from %16s logged in at %30s.\n", $userid, $ENV{'REMOTE_ADDR'}, $time; + close L; + my $cookie=$query->cookie(-name => 'sessionID', + -value => $sessionID, + -expires => '+1y'); + return ($userid, $cookie, $sessionID); + } else { + if ($userid) { + $message="Invalid userid or password entered."; + } + my $parameters; + foreach (param $query) { + $parameters->{$_}=$query->{$_}; + } + my $cookie=$query->cookie(-name => 'sessionID', + -value => $sessionID, + -expires => '+1y'); + print $query->header(-cookie=>$cookie); + print qq| + + +
+

$message

+ +
+ + +
+ + + + + + +
Koha Login
Name:
Password:
+ +
+ + + + + +
Demo Information
+ Log in as librarian/koha or patron/koha. The timeout is set to 40 seconds of + inactivity for the purposes of this demo. You can navigate to the Circulation + or Acquisitions modules and you should see an indicator in the upper left of + the screen saying who you are logged in as. If you want to try it out with + a longer timout period, log in as tonnesen/koha and there will be no + timeout period. +

+ You can also log in using a patron cardnumber. Try V10000008 and + V1000002X with password koha. +

+
+
+ + +|; + exit; + } + } +} + + +sub checkpw { + +# This should be modified to allow a select of authentication schemes (ie LDAP) +# as well as local authentication through the borrowers tables passwd field +# + my ($dbh, $userid, $password) = @_; + my $sth=$dbh->prepare("select password from borrowers where userid=?"); + $sth->execute($userid); + if ($sth->rows) { + my ($md5password) = $sth->fetchrow; + if (md5_base64($password) eq $md5password) { + return 1; + } + } + my $sth=$dbh->prepare("select password from borrowers where cardnumber=?"); + $sth->execute($userid); + if ($sth->rows) { + my ($md5password) = $sth->fetchrow; + if (md5_base64($password) eq $md5password) { + return 1; + } + } + return 0; +} + + +END { } # module clean-up code here (global destructor) diff --git a/C4/Output.pm b/C4/Output.pm index 6b84bf488c..3ae7fbd94c 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -24,6 +24,7 @@ $VERSION = 0.01; &mkform &mkform2 &bold &gotopage &mkformnotable &mkform3 &getkeytableselectoptions + &picktemplate ); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], @@ -74,6 +75,32 @@ my $path=$configfile{'includes'}; ($path) || ($path="/usr/local/www/hdl/htdocs/includes"); # make all your functions, whether exported or not; + +sub picktemplate { + my ($includes, $base) = @_; + my $dbh=C4Connect; + my $templates; + opendir (D, "$includes/templates"); + my @dirlist=readdir D; + foreach (@dirlist) { + (next) if (/^\./); + #(next) unless (/\.tmpl$/); + (next) unless (-e "$includes/templates/$_/$base"); + $templates->{$_}=1; + } + my $sth=$dbh->prepare("select value from systempreferences where + variable='template'"); + $sth->execute; + my ($preftemplate) = $sth->fetchrow; + $sth->finish; + $dbh->disconnect; + if ($templates->{$preftemplate}) { + return $preftemplate; + } else { + return 'default'; + } + +} sub startpage() { return("\n"); diff --git a/C4/Reserves2.pm b/C4/Reserves2.pm index 2c3f0767b2..33ac78bca1 100755 --- a/C4/Reserves2.pm +++ b/C4/Reserves2.pm @@ -12,8 +12,8 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 0.01; @ISA = qw(Exporter); -@EXPORT = qw(&FindReserves &CreateReserve &updatereserves &getreservetitle &Findgroupreserve); - +@EXPORT = qw(&FindReserves &CheckReserves &CheckWaiting &CancelReserve &FillReserve &ReserveWaiting &CreateReserve &updatereserves &getreservetitle &Findgroupreserve); + # make all your functions, whether exported or not; sub FindReserves { @@ -22,7 +22,9 @@ sub FindReserves { my $query="SELECT *,reserves.branchcode,biblio.title AS btitle FROM reserves,borrowers,biblio "; if ($bib ne ''){ - if ($bor ne ''){ + $bib = $dbh->quote($bib); + if ($bor ne ''){ + $bor = $dbh->quote($bor); $query .= " where reserves.biblionumber = $bib and borrowers.borrowernumber = $bor and reserves.borrowernumber = borrowers.borrowernumber @@ -58,6 +60,188 @@ sub FindReserves { return($i,\@results); } +sub CheckReserves { + my ($item) = @_; + my $dbh=C4Connect; + my $qitem=$dbh->quote($item); +# get the biblionumber... + my $sth=$dbh->prepare("select biblionumber, biblioitemnumber from items where itemnumber=$qitem"); + $sth->execute; + my ($biblio, $bibitem) = $sth->fetchrow_array; + $sth->finish; + $dbh->disconnect; +# get the reserves... + my ($count, @reserves) = Findgroupreserve($bibitem, $biblio); + my $priority = 10000000; + my $highest; + if ($count) { + foreach my $res (@reserves) { + if ($res->{'itemnumber'} == $item) { + return ("Waiting", $res); + } else { + if ($res->{'priority'} < $priority) { + $priority = $res->{'priority'}; + $highest = $res; + } + } + } + $highest->{'itemnumber'} = $item; + return ("Reserved", $highest); + } else { + return (0, 0); + } +} + +sub CancelReserve { + my ($biblio, $item, $borr) = @_; + my $dbh=C4Connect; + warn "In CancelReserve"; + if (($item and $borr) and (not $biblio)) { +# removing a waiting reserve record.... + $item = $dbh->quote($item); + $borr = $dbh->quote($borr); +# update the database... + my $query = "update reserves set cancellationdate = now(), + found = Null, + priority = 0 + where itemnumber = $item + and borrowernumber = $borr"; + my $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; + } + if (($biblio and $borr) and (not $item)) { +# removing a reserve record.... + my $q_biblio = $dbh->quote($biblio); + $borr = $dbh->quote($borr); +# fix up the priorities on the other records.... + my $query = "SELECT priority FROM reserves + WHERE biblionumber = $q_biblio + AND borrowernumber = $borr + AND cancellationdate is NULL + AND (found <> 'F' or found is NULL)"; + my $sth=$dbh->prepare($query); + $sth->execute; + my ($priority) = $sth->fetchrow_array; + $sth->finish; +# update the database, removing the record... + my $query = "update reserves set cancellationdate = now(), + found = Null, + priority = 0 + where biblionumber = $q_biblio + and borrowernumber = $borr + and cancellationdate is NULL + and (found <> 'F' or found is NULL)"; + my $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; +# now fix the priority on the others.... + fixpriority($priority, $biblio); + } + $dbh->disconnect; +} + + +sub FillReserve { + my ($res) = @_; + my $dbh=C4Connect; +# removing a waiting reserve record.... + my $biblio = $res->{'biblionumber'}; my $qbiblio = $dbh->quote($biblio); + my $borr = $res->{'borrowernumber'}; $borr = $dbh->quote($borr); + my $resdate = $res->{'reservedate'}; $resdate = $dbh->quote($resdate); +# update the database... + my $query = "UPDATE reserves SET found = 'F', + priority = 0 + WHERE biblionumber = $qbiblio + AND reservedate = $resdate + AND borrowernumber = $borr"; + my $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; + $dbh->disconnect; +# now fix the priority on the others.... + fixpriority($res->{'priority'}, $biblio); +} + +sub fixpriority { + my ($priority, $biblio) = @_; + my $dbh = C4Connect; + my ($count, $reserves) = FindReserves($biblio); + foreach my $rec (@$reserves) { + if ($rec->{'priority'} > $priority) { + my $newpr = $rec->{'priority'}; $newpr = $dbh->quote($newpr - 1); + my $nbib = $rec->{'biblionumber'}; $nbib = $dbh->quote($nbib); + my $nbor = $rec->{'borrowernumber'}; $nbor = $dbh->quote($nbor); + my $nresd = $rec->{'reservedate'}; $nresd = $dbh->quote($nresd); + my $query = "UPDATE reserves SET priority = $newpr + WHERE biblionumber = $nbib + AND borrowernumber = $nbor + AND reservedate = $nresd"; + warn $query; + my $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; + } + } + $dbh->disconnect; +} + + + +sub ReserveWaiting { + my ($item, $borr) = @_; + my $dbh = C4Connect; + $item = $dbh->quote($item); + $borr = $dbh->quote($borr); +# get priority and biblionumber.... + my $query = "SELECT reserves.priority as priority, + reserves.biblionumber as biblionumber, + reserves.branchcode as branchcode + FROM reserves,items + WHERE reserves.biblionumber = items.biblionumber + AND items.itemnumber = $item + AND reserves.borrowernumber = $borr + AND reserves.cancellationdate is NULL + AND (reserves.found <> 'F' or reserves.found is NULL)"; + my $sth = $dbh->prepare($query); + $sth->execute; + my $data = $sth->fetchrow_hashref; + $sth->finish; + my $biblio = $data->{'biblionumber'}; + my $q_biblio = $dbh->quote($biblio); +# update reserves record.... + $query = "UPDATE reserves SET priority = 0, found = 'W', itemnumber = $item + WHERE borrowernumber = $borr AND biblionumber = $q_biblio"; + $sth = $dbh->prepare($query); + $sth->execute; + $sth->finish; + $dbh->disconnect; +# now fix up the remaining priorities.... + fixpriority($data->{'priority'}, $biblio); + my $branchcode = $data->{'branchcode'}; + return $branchcode; +} + +sub CheckWaiting { + my ($borr)=@_; + my $dbh = C4Connect; + $borr = $dbh->quote($borr); + my @itemswaiting; + my $query = "SELECT * FROM reserves + WHERE borrowernumber = $borr + AND reserves.found = 'W' + AND cancellationdate is NULL"; + my $sth = $dbh->prepare($query); + $sth->execute(); + my $cnt=0; + if (my $data=$sth->fetchrow_hashref) { + @itemswaiting[$cnt] =$data; + $cnt ++; + } + $sth->finish; + return ($cnt,\@itemswaiting); +} + sub Findgroupreserve { my ($bibitem,$biblio)=@_; my $dbh=C4Connect; @@ -82,7 +266,6 @@ sub Findgroupreserve { OR reserves.constrainttype='a' ) AND reserves.cancellationdate is NULL AND (reserves.found <> 'F' or reserves.found is NULL)"; -# print $query; my $sth=$dbh->prepare($query); $sth->execute; my $i=0; diff --git a/C4/Search.pm b/C4/Search.pm index 06d7f2d17f..9553234b44 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -18,8 +18,8 @@ $VERSION = 0.02; &borrdata2 &NewBorrowerNumber &bibitemdata &borrissues &getboracctrecord &ItemType &itemissues &subject &subtitle &addauthor &bibitems &barcodes &findguarantees &allissues &systemprefs -&findguarantor &branchname); - +&findguarantor &getwebsites &getwebbiblioitems &catalogsearch &itemcount2 &branchname); +# make all your functions, whether exported or not; sub findguarantees{ my ($bornum)=@_; my $dbh=C4Connect; @@ -80,6 +80,73 @@ sub NewBorrowerNumber { return($data->{'max(borrowernumber)'}); } +sub catalogsearch { + my ($env,$type,$search,$num,$offset)=@_; + my $dbh = C4Connect(); +# foreach my $key (%$search){ +# $search->{$key}=$dbh->quote($search->{$key}); +# } + my ($count,@results); +# print STDERR "Doing a search \n"; + if ($search->{'itemnumber'} ne '' || $search->{'isbn'} ne ''){ + print STDERR "Doing a precise search\n"; + ($count,@results)=CatSearch($env,'precise',$search,$num,$offset); + + } else { + if ($search->{'subject'} ne ''){ + ($count,@results)=CatSearch($env,'subject',$search,$num,$offset); + } else { + if ($search->{'keyword'} ne ''){ + ($count,@results)=&KeywordSearch($env,'keyword',$search,$num,$offset); + } else { + ($count,@results)=CatSearch($env,'loose',$search,$num,$offset); + + } + } + } + if ($env->{itemcount}) { + foreach my $data (@results){ + my ($counts) = itemcount2($env, $data->{'biblionumber'}, 'intra'); + my $subject2=$data->{'subject'}; + $subject2=~ s/ /%20/g; + $data->{'itemcount'}=$counts->{'total'}; + my $totalitemcounts=0; + foreach my $key (keys %$counts){ + if ($key ne 'total'){ + #$data->{'location'}.="$key $counts->{$key} "; + $totalitemcounts+=$counts->{$key}; + $data->{'locationhash'}->{$key}=$counts->{$key}; + } + } + my $locationtext=''; + my $notavailabletext=''; + foreach (sort keys %{$data->{'locationhash'}}) { + if ($_ eq 'notavailable') { + $notavailabletext="Not available"; + my $c=$data->{'locationhash'}->{$_}; + if ($totalitemcounts>1) { + $notavailabletext.=" ($c)"; + } + } else { + $locationtext.="$_"; + my $c=$data->{'locationhash'}->{$_}; + if ($totalitemcounts>1) { + $locationtext.=" ($c), "; + } + } + } + if ($notavailabletext) { + $locationtext.=$notavailabletext; + } else { + $locationtext=~s/, $//; + } + $data->{'location'}=$locationtext; + $data->{'subject2'}=$subject2; + } + } + return ($count,@results); +} + sub KeywordSearch { my ($env,$type,$search,$num,$offset)=@_; @@ -206,7 +273,10 @@ sub KeywordSearch { } # print $i4; if ($i4 <=$end && $i4 > $offset){ - $res2[$i3]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey"; + $data2->{'dewey'}=$dewey; + $res2[$i3]=$data2; + +# $res2[$i3]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey"; $i3++; $i4++; # print "in here $i3
"; @@ -246,8 +316,10 @@ sub KeywordSearch { $dewey=~s/\.*0*$//; ($dewey == 0) && ($dewey=''); ($dewey) && ($dewey.=" $subclass") ; - $sth->finish; - $res2[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey"; + $sth->finish; + $data2->{'dewey'}=$dewey; + $res2[$i]=$data2; +# $res2[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey"; $i++; } $i2++; @@ -467,7 +539,11 @@ sub CatSearch { #$query=$query. " and (title like '%$search->{'title'}%' #or seriestitle like '%$search->{'title'}%')"; } - + if ($search->{'abstract'} ne ''){ + $query.= " and (abstract like '%$search->{'abstract'}%')"; + } + + $query.=" group by biblio.biblionumber"; } else { if ($search->{'title'} ne '') { @@ -510,6 +586,9 @@ sub CatSearch { } $query=$query."))"; } + if ($search->{'abstract'} ne ''){ + $query.= " and (abstract like '%$search->{'abstract'}%')"; + } } elsif ($search->{'class'} ne ''){ $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber"; my @temp=split(/\|/,$search->{'class'}); @@ -530,10 +609,15 @@ sub CatSearch { where biblio.biblionumber=biblioitems.biblionumber and biblioitems.dewey like '$search->{'dewey'}%'"; } elsif ($search->{'illustrator'} ne '') { - $query="select * from biblioitems,biblio + $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber and biblioitems.illus like '%".$search->{'illustrator'}."%'"; - } + } elsif ($search->{'publisher'} ne ''){ + $query.= "Select * from biblio,biblioitems where biblio.biblionumber + =biblioitems.biblionumber and (publishercode like '%$search->{'publisher'}%')"; + } elsif ($search->{'abstract'} ne ''){ + $query.= "Select * from biblio where abstract like '%$search->{'abstract'}%'"; + } $query .=" group by biblio.biblionumber"; } } @@ -559,8 +643,9 @@ sub CatSearch { } } if ($type eq 'precise'){ - $query="select * from items,biblio "; + if ($search->{'item'} ne ''){ + $query="select * from items,biblio "; my $search2=uc $search->{'item'}; $query=$query." where items.biblionumber=biblio.biblionumber @@ -584,7 +669,9 @@ sub CatSearch { $dewey=~s/\.*0*$//; ($dewey == 0) && ($dewey=''); ($dewey) && ($dewey.=" $subclass"); - $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}"; + $data->{'dewey'}=$dewey; + $results[$i2]=$data; +# $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}"; $i2++; $sth->finish; } @@ -626,7 +713,10 @@ while (my $data=$sth->fetchrow_hashref){ if ($search->{'illustrator'} ne ''){ $query.=" and illus like '%".$search->{'illustrator'}."%' "; } -#print $query; + if ($search->{'publisher'} ne ''){ + $query.= " and (publishercode like '%$search->{'publisher'}%')"; + } +#print STDERR "$query\n"; my $sti=$dbh->prepare($query); $sti->execute; my $dewey; @@ -638,19 +728,14 @@ while (my $data=$sth->fetchrow_hashref){ $dewey=~s/\.*0*$//; ($dewey == 0) && ($dewey=''); ($dewey) && ($dewey.=" $subclass"); + $data->{'dewey'}=$dewey; $sti->finish; if ($true == 1){ - if ($count > $offset && $count <= $limit){ - if ($type ne 'subject' && $type ne 'precise'){ - $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}"; - } elsif ($search->{'isbn'} ne '' || $search->{'item'} ne ''){ - $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}"; - } else { - $results[$i]="$data->{'author'}\t$data->{'subject'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}"; + if ($count > $offset && $count <= $limit){ + $results[$i]=$data; + $i++; } - $i++; - } - $count++; + $count++; } } $sth->finish; @@ -670,17 +755,56 @@ sub subsearch { my ($env,$subject)=@_; my $dbh=C4Connect(); $subject=$dbh->quote($subject); - my $query="Select * from biblio,bibliosubject where - biblio.biblionumber=bibliosubject.biblionumber and + my $query="Select * from biblio,biblioitems,bibliosubject where + biblio.biblionumber=bibliosubject.biblionumber and biblio.biblionumber=biblioitems.biblionumber and bibliosubject.subject=$subject group by biblio.biblionumber order by biblio.title"; my $sth=$dbh->prepare($query); $sth->execute; my $i=0; -# print $query; my @results; while (my $data=$sth->fetchrow_hashref){ - $results[$i]="$data->{'title'}\t$data->{'author'}\t$data->{'biblionumber'}"; + #$results[$i]="$data->{'title'}\t$data->{'author'}\t$data->{'biblionumber'}"; + my $dewey= $data->{'dewey'}; + my $subclass=$data->{'subclass'}; + $dewey=~s/\.*0*$//; + ($dewey == 0) && ($dewey=''); + ($dewey) && ($dewey.=" $subclass") ; + $data->{'dewey'}=$dewey; + my ($counts) = itemcount2($env, $data->{'biblionumber'}, 'intra'); + $data->{'itemcount'}=$counts->{'total'}; + my $totalitemcounts=0; + foreach my $key (keys %$counts){ + if ($key ne 'total'){ + #$data->{'location'}.="$key $counts->{$key} "; + $totalitemcounts+=$counts->{$key}; + $data->{'locationhash'}->{$key}=$counts->{$key}; + } + } + my $locationtext=''; + my $notavailabletext=''; + foreach (sort keys %{$data->{'locationhash'}}) { + if ($_ eq 'notavailable') { + $notavailabletext="Not available"; + my $c=$data->{'locationhash'}->{$_}; + if ($totalitemcounts>1) { + $notavailabletext.=" ($c)"; + } + } else { + $locationtext.="$_"; + my $c=$data->{'locationhash'}->{$_}; + if ($totalitemcounts>1) { + $locationtext.=" ($c), "; + } + } + } + if ($notavailabletext) { + $locationtext.=$notavailabletext; + } else { + $locationtext=~s/, $//; + } + $data->{'location'}=$locationtext; + $results[$i]=$data; $i++; } $sth->finish; @@ -690,19 +814,18 @@ sub subsearch { sub ItemInfo { - my ($env,$biblionumber,$type)=@_; - my $dbh = &C4Connect; - my $query="Select * from items,biblio,biblioitems,branches - where (items.biblioitemnumber = biblioitems.biblioitemnumber) - and biblioitems.biblionumber=biblio.biblionumber - and biblio.biblionumber='$biblionumber' and branches.branchcode= - items.holdingbranch "; -# print $type; + my ($env,$biblionumber,$type) = @_; + my $dbh = &C4Connect; + my $query = "SELECT * FROM items, biblio, biblioitems + WHERE items.biblionumber = '$biblionumber' + AND biblioitems.biblioitemnumber = items.biblioitemnumber + AND biblio.biblionumber = items.biblionumber"; if ($type ne 'intra'){ - $query.=" and (items.itemlost<>1 or items.itemlost is NULL) + $query .= " and ((items.itemlost<>1 and items.itemlost <> 2) + or items.itemlost is NULL) and (wthdrawn <> 1 or wthdrawn is NULL)"; } - $query=$query."order by items.dateaccessioned desc"; + $query .= " order by items.dateaccessioned desc"; my $sth=$dbh->prepare($query); $sth->execute; my $i=0; @@ -719,20 +842,29 @@ sub ItemInfo { my @temp=split('-',$idata->{'date_due'}); $datedue = "$temp[2]/$temp[1]/$temp[0]"; } - if ($data->{'itemlost'} eq '1'){ + if ($data->{'itemlost'} eq '1' || $data->{'itemlost'} eq '2'){ $datedue='Itemlost'; } if ($data->{'wthdrawn'} eq '1'){ $datedue="Cancelled"; } if ($datedue eq ''){ - my ($rescount,$reserves)=Findgroupreserve($data->{'biblioitemnumber'},$biblionumber); - - if ($rescount >0){ - $datedue='Request'; + $datedue="Available"; + my ($restype,$reserves)=CheckReserves($data->{'itemnumber'}); + if ($restype){ + $datedue=$restype; } } $isth->finish; +#get branch information..... + my $bquery = "SELECT * FROM branches + WHERE branchcode = '$data->{'holdingbranch'}'"; + my $bsth=$dbh->prepare($bquery); + $bsth->execute; + if (my $bdata=$bsth->fetchrow_hashref){ + $data->{'branchname'} = $bdata->{'branchname'}; + } + my $class = $data->{'classification'}; my $dewey = $data->{'dewey'}; $dewey =~ s/0+$//; @@ -750,8 +882,10 @@ sub ItemInfo { # $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$data->{'dewey'}"; my @temp=split('-',$data->{'datelastseen'}); my $date="$temp[2]/$temp[1]/$temp[0]"; - $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$class\t$data->{'itemnumber'}\t$data->{'itemtype'}\t$date\t$data->{'biblioitemnumber'}\t$data->{'volumeddesc'}"; -# print "$results[$i]
"; + $data->{'datelastseen'}=$date; + $data->{'datedue'}=$datedue; + $data->{'class'}=$class; + $results[$i]=$data; $i++; } $sth->finish; @@ -763,7 +897,9 @@ sub ItemInfo { if ($data=$sth2->fetchrow_hashref){ $ocount=$data->{'quantity'} - $data->{'quantityreceived'}; if ($ocount > 0){ - $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$ocount\tOn Order\t\t$data->{'itemnumber'}\t$data->{'itemtype'}\t\t$data->{'biblioitemnumber'}\t$data->{'volumeddesc'}"; + $data->{'ocount'}=$ocount; + $data->{'order'}="One Order"; + $results[$i]=$data; } } $sth2->finish; @@ -826,48 +962,55 @@ sub itemdata { return($data); } + sub bibdata { - my ($bibnum,$type)=@_; - my $dbh=C4Connect; - my $query="Select *,biblio.notes - from biblio,biblioitems - left join bibliosubtitle on - biblio.biblionumber=bibliosubtitle.biblionumber - - where biblio.biblionumber=$bibnum - and biblioitems.biblionumber=$bibnum"; -# print $query; - my $sth=$dbh->prepare($query); - $sth->execute; - my $data=$sth->fetchrow_hashref; - $sth->finish; - $query="Select * from bibliosubject where biblionumber='$bibnum'"; - $sth=$dbh->prepare($query); - $sth->execute; - while (my $dat=$sth->fetchrow_hashref){ - $data->{'subject'}.=" | $dat->{'subject'}"; + my ($bibnum, $type) = @_; + my $dbh = C4Connect; + my $query = "Select *, biblio.notes + from biblio, biblioitems + left join bibliosubtitle on + biblio.biblionumber = bibliosubtitle.biblionumber + where biblio.biblionumber = $bibnum + and biblioitems.biblionumber = $bibnum"; + my $sth = $dbh->prepare($query); + my $data; + + $sth->execute; + $data = $sth->fetchrow_hashref; + $sth->finish; + + $query = "Select * from bibliosubject where biblionumber = '$bibnum'"; + $sth = $dbh->prepare($query); + $sth->execute; + while (my $dat = $sth->fetchrow_hashref){ + $data->{'subject'} .= " | $dat->{'subject'}"; + } # while + + $sth->finish; + $dbh->disconnect; + return($data); +} # sub bibdata - } - #print $query; - $sth->finish; - $dbh->disconnect; - return($data); -} sub bibitemdata { - my ($bibitem)=@_; - my $dbh=C4Connect; - my $query="Select *,biblioitems.notes as bnotes from biblio,biblioitems,itemtypes where biblio.biblionumber= - biblioitems.biblionumber and biblioitemnumber=$bibitem and - biblioitems.itemtype=itemtypes.itemtype"; -# print $query; - my $sth=$dbh->prepare($query); - $sth->execute; - my $data=$sth->fetchrow_hashref; - $sth->finish; - $dbh->disconnect; - return($data); -} + my ($bibitem) = @_; + my $dbh = C4Connect; + my $query = "Select *,biblioitems.notes as bnotes from biblio, biblioitems,itemtypes +where biblio.biblionumber = biblioitems.biblionumber +and biblioitemnumber = $bibitem +and biblioitems.itemtype = itemtypes.itemtype"; + my $sth = $dbh->prepare($query); + my $data; + + $sth->execute; + + $data = $sth->fetchrow_hashref; + + $sth->finish; + $dbh->disconnect; + return($data); +} # sub bibitemdata + sub subject { my ($bibnum)=@_; @@ -889,9 +1032,9 @@ sub subject { sub addauthor { my ($bibnum)=@_; my $dbh=C4Connect; - my $query="Select * from additionalauthors where biblionumber=?"; + my $query="Select * from additionalauthors where biblionumber=$bibnum"; my $sth=$dbh->prepare($query); - $sth->execute($bibnum); + $sth->execute; my @results; my $i=0; while (my $data=$sth->fetchrow_hashref){ @@ -906,9 +1049,9 @@ sub addauthor { sub subtitle { my ($bibnum)=@_; my $dbh=C4Connect; - my $query="Select * from bibliosubtitle where biblionumber=?"; + my $query="Select * from bibliosubtitle where biblionumber=$bibnum"; my $sth=$dbh->prepare($query); - $sth->execute($bibnum); + $sth->execute; my @results; my $i=0; while (my $data=$sth->fetchrow_hashref){ @@ -923,51 +1066,66 @@ sub subtitle { sub itemissues { - my ($bibitem,$biblio)=@_; - my $dbh=C4Connect; - my $query="Select * from items where - items.biblioitemnumber='$bibitem'"; - my $sth=$dbh->prepare($query) || die $dbh->errstr; - $sth->execute || die $sth->errstr; - my $i=0; - my @results; - while (my $data=$sth->fetchrow_hashref) { - my $query2="select * from issues,borrowers where itemnumber=$data->{'itemnumber'} - and returndate is NULL and issues.borrowernumber=borrowers.borrowernumber"; - my $sth2=$dbh->prepare($query2); - $sth2->execute; - if (my $data2=$sth2->fetchrow_hashref) { - $data->{'date_due'}=$data2->{'date_due'}; - $data->{'card'}=$data2->{'cardnumber'}; - } else { - if ($data->{'wthdrawn'} eq '1') { - $data->{'date_due'}='Cancelled'; - } else { - $data->{'date_due'}='Available'; - } - } - $sth2->finish; - $query2="select * from issues,borrowers where itemnumber='$data->{'itemnumber'}' - and issues.borrowernumber=borrowers.borrowernumber - order by date_due desc"; - $sth2=$dbh->prepare($query2) || die $dbh->errstr; - $sth2->execute || die $sth2->errstr; - for (my $i2=0;$i2<2;$i2++){ - if (my $data2=$sth2->fetchrow_hashref){ - $data->{"timestamp$i2"}=$data2->{'timestamp'}; - $data->{"card$i2"}=$data2->{'cardnumber'}; - $data->{"borrower$i2"}=$data2->{'borrowernumber'}; - } + my ($bibitem, $biblio)=@_; + my $dbh = C4Connect; + my $query = "Select * from items where +items.biblioitemnumber = '$bibitem'"; + my $sth = $dbh->prepare($query) + || die $dbh->errstr; + my $i = 0; + my @results; + + $sth->execute + || die $sth->errstr; + + while (my $data = $sth->fetchrow_hashref) { + my $query2 = "select * from issues,borrowers +where itemnumber = $data->{'itemnumber'} +and returndate is NULL +and issues.borrowernumber = borrowers.borrowernumber"; + my $sth2 = $dbh->prepare($query2); + + $sth2->execute; + if (my $data2 = $sth2->fetchrow_hashref) { + $data->{'date_due'} = $data2->{'date_due'}; + $data->{'card'} = $data2->{'cardnumber'}; + } else { + if ($data->{'wthdrawn'} eq '1') { + $data->{'date_due'} = 'Cancelled'; + } else { + $data->{'date_due'} = 'Available'; + } # else + } # else + + $sth2->finish; + $query2 = "select * from issues, borrowers +where itemnumber = '$data->{'itemnumber'}' +and issues.borrowernumber = borrowers.borrowernumber +order by date_due desc"; + $sth2 = $dbh->prepare($query2) + || die $dbh->errstr; + $sth2->execute + || die $sth2->errstr; + + for (my $i2 = 0; $i2 < 2; $i2++) { + if (my $data2 = $sth2->fetchrow_hashref) { + $data->{"timestamp$i2"} = $data2->{'timestamp'}; + $data->{"card$i2"} = $data2->{'cardnumber'}; + $data->{"borrower$i2"} = $data2->{'borrowernumber'}; + } # if + } # for + + $sth2->finish; + $results[$i] = $data; + $i++; } - $sth2->finish; - $results[$i]=$data; - $i++; - } - $sth->finish; - $dbh->disconnect; - return(@results); + + $sth->finish; + $dbh->disconnect; + return(@results); } + sub itemnodata { my ($env,$dbh,$itemnumber) = @_; $dbh=C4Connect; @@ -1143,13 +1301,14 @@ borrowernumber=$params->{'borrowernumber'} order by date desc,timestamp desc"; return ($numlines,\@acctlines,$total); } + sub itemcount { my ($env,$bibnum,$type)=@_; my $dbh=C4Connect; my $query="Select * from items where biblionumber=$bibnum "; if ($type ne 'intra'){ - $query.=" and (itemlost <>1 or itemlost is NULL) and + $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and (wthdrawn <> 1 or wthdrawn is NULL)"; } my $sth=$dbh->prepare($query); @@ -1164,13 +1323,14 @@ sub itemcount { my $mending=0; my $transit=0; my $ocount=0; - my $branchcount; - while (my $data=$sth->fetchrow_hashref) { + while (my $data=$sth->fetchrow_hashref){ $count++; my $query2="select * from issues,items where issues.itemnumber= '$data->{'itemnumber'}' and returndate is NULL - and items.itemnumber=issues.itemnumber and (items.itemlost <>1 or - items.itemlost is NULL)"; + and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and + items.itemlost <> 2) or items.itemlost is NULL) + and (wthdrawn <> 1 or wthdrawn is NULL)"; + my $sth2=$dbh->prepare($query2); $sth2->execute; if (my $data2=$sth2->fetchrow_hashref){ @@ -1188,30 +1348,78 @@ sub itemcount { if ($data->{'itemlost'} eq '1'){ $lostcount++; } + if ($data->{'itemlost'} eq '2'){ + $lostcount++; + } if ($data->{'holdingbranch'} eq 'FM'){ $mending++; } if ($data->{'holdingbranch'} eq 'TR'){ $transit++; } - unless ($data->{'itemlost'} || $data->{'holdingbranch'} eq 'FM' || $data->{'holdingbranch'} eq 'TR') { - $branchcount->{$data->{'holdingbranch'}}++; - } } $sth2->finish; } +# if ($count == 0){ my $query2="Select * from aqorders where biblionumber=$bibnum"; my $sth2=$dbh->prepare($query2); $sth2->execute; if (my $data=$sth2->fetchrow_hashref){ $ocount=$data->{'quantity'} - $data->{'quantityreceived'}; } +# $count+=$ocount; $sth2->finish; $sth->finish; $dbh->disconnect; - return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount, $branchcount); + return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount); } + +sub itemcount2 { + my ($env,$bibnum,$type)=@_; + my $dbh=C4Connect; + my $query="Select * from items,branches where + biblionumber=$bibnum and items.holdingbranch=branches.branchcode"; + if ($type ne 'intra'){ + $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and + (wthdrawn <> 1 or wthdrawn is NULL)"; + } + my $sth=$dbh->prepare($query); + # print $query; + $sth->execute; + my %counts; + $counts{'total'}=0; + while (my $data=$sth->fetchrow_hashref){ + $counts{'total'}++; + my $query2="select * from issues,items where issues.itemnumber= + '$data->{'itemnumber'}' and returndate is NULL + and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and + items.itemlost <> 2) or items.itemlost is NULL) + and (wthdrawn <> 1 or wthdrawn is NULL)"; + + my $sth2=$dbh->prepare($query2); + $sth2->execute; + if (my $data2=$sth2->fetchrow_hashref){ + $counts{'notavailable'}++; + } else { + $counts{$data->{'branchname'}}++; + } + $sth2->finish; + } + my $query2="Select * from aqorders where biblionumber=$bibnum and + datecancellationprinted is NULL and quantity > quantityreceived"; + my $sth2=$dbh->prepare($query2); + $sth2->execute; + if (my $data=$sth2->fetchrow_hashref){ + $counts{'order'}=$data->{'quantity'} - $data->{'quantityreceived'}; + } + $sth2->finish; + $sth->finish; + $dbh->disconnect; + return (\%counts); +} + + sub ItemType { my ($type)=@_; my $dbh=C4Connect; @@ -1224,31 +1432,41 @@ sub ItemType { return ($dat->{'description'}); } + sub bibitems { - my ($bibnum)=@_; - my $dbh=C4Connect; - my $query="Select * from biblioitems,itemtypes,items where - biblioitems.biblionumber='$bibnum' and biblioitems.itemtype=itemtypes.itemtype and - biblioitems.biblioitemnumber=items.biblioitemnumber group by - items.biblioitemnumber"; - my $sth=$dbh->prepare($query); - $sth->execute; - my $i=0; - my @results; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - $dbh->disconnect; - return($i,@results); -} + my ($bibnum) = @_; + my $dbh = C4Connect; + my $query = "Select * from biblioitems, itemtypes, items +where biblioitems.biblionumber = '$bibnum' +and biblioitems.itemtype = itemtypes.itemtype +and biblioitems.biblioitemnumber = items.biblioitemnumber +group by items.biblioitemnumber"; + my $sth = $dbh->prepare($query); + my $count = 0; + my @results; + + $sth->execute; + + while (my $data = $sth->fetchrow_hashref) { + $results[$count] = $data; + $count++; + } # while + + $sth->finish; + $dbh->disconnect; + return($count, @results); +} # sub bibitems + sub barcodes{ + #called from request.pl my ($biblioitemnumber)=@_; my $dbh=C4Connect; my $query="Select barcode from items where - biblioitemnumber='$biblioitemnumber'"; + biblioitemnumber='$biblioitemnumber' + and ((itemlost <> 1 and itemlost <> 2) or itemlost is NULL) and + (wthdrawn <> 1 or wthdrawn is NULL)"; + my $sth=$dbh->prepare($query); $sth->execute; my @barcodes; @@ -1260,8 +1478,52 @@ sub barcodes{ $sth->finish; $dbh->disconnect; return(@barcodes); + } + +sub getwebsites { + my ($biblionumber) = @_; + my $dbh = C4Connect; + my $query = "Select * from websites where biblionumber = $biblionumber"; + my $sth = $dbh->prepare($query); + my $count = 0; + my @results; + + $sth->execute; + while (my $data = $sth->fetchrow_hashref) { + $data->{'url'} =~ s/^http:\/\///; + $results[$count] = $data; + $count++; + } # while + + $sth->finish; + $dbh->disconnect; + return($count, @results); +} # sub getwebsites + + +sub getwebbiblioitems { + my ($biblionumber) = @_; + my $dbh = C4Connect; + my $query = "Select * from biblioitems where biblionumber = $biblionumber +and itemtype = 'WEB'"; + my $sth = $dbh->prepare($query); + my $count = 0; + my @results; + + $sth->execute; + while (my $data = $sth->fetchrow_hashref) { + $data->{'url'} =~ s/^http:\/\///; + $results[$count] = $data; + $count++; + } # while + + $sth->finish; + $dbh->disconnect; + return($count, @results); +} # sub getwebbiblioitems + sub branchname { my ($branchcode)=@_; my $dbh=C4Connect; @@ -1277,8 +1539,34 @@ sub branchname { END { } # module clean-up code here (global destructor) +=head1 NAME + +C4::Search - Module that provides Catalog searching for Koha + +=head1 SYNOPSIS + + use C4::Search; + my ($count,@results)=catalogsearch($env,$type,$search,$num,$offset); + +=head1 DESCRIPTION + +This module provides the searching facilities for the Catalog. +Here I should go through and document each function thats exported and what it does. But I havent yet. + +my ($count,@results)=catalogsearch($env,$type,$search,$num,$offset); +This is a front end to all the other searches, depending on what is passed +to it, it calls the appropriate search + +=head2 EXPORT + +catalogsearch +=head1 AUTHOR +Koha Developement team +=head1 SEE ALSO +L. +=cut diff --git a/acqui.simple/addbooks.pl b/acqui.simple/addbooks.pl index 0043d95d0f..ba78a91d6d 100755 --- a/acqui.simple/addbooks.pl +++ b/acqui.simple/addbooks.pl @@ -20,17 +20,23 @@ use C4::Acquisitions; use C4::Biblio; use C4::Output; use C4::Circulation::Circ2; +use C4::Auth; my $input = new CGI; +my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($input); + + my $dbh=C4Connect; my $isbn=$input->param('isbn'); my $q_isbn=$dbh->quote($isbn); my $biblioitemnumber; -print $input->header; +print $input->header(-cookie=>$sessioncookie); print startpage(); print startmenu('acquisitions'); +print "

Logged in as: $loggedinuser [Log Out]

\n"; + ($input->param('checkforbiblio')) && (checkforbiblio()); ($input->param('newbiblioitem')) && (newbiblioitem()); diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index e41d9e1bca..37c0dcd981 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -23,8 +23,10 @@ use C4::Input; use C4::Biblio; use C4::SimpleMarc; use C4::Z3950; +use C4::Auth; my $input = new CGI; +my ($loggedinuser, $cookie, $sessionID) = checkauth($input); #------------------ # Constants @@ -43,10 +45,11 @@ my $dbh=C4Connect; #------------- # Display output -print $input->header(); +print $input->header(-cookie => $cookie); print startpage(); print startmenu('acquisitions'); +print "

Logged in as: $loggedinuser [Log Out]

\n"; #------------- # Process input parameters @@ -1146,6 +1149,9 @@ sub FormatMarcText { #--------------- # $Log$ +# Revision 1.6.2.35 2002/07/11 18:05:29 tonnesen +# Committing changes to add authentication and opac templating to rel-1-2 branch +# # Revision 1.6.2.34 2002/07/05 19:30:14 amillar # Second arg of requireDBI is calling subroutine name # diff --git a/admin-home.pl b/admin-home.pl new file mode 100755 index 0000000000..a03e6e9f4f --- /dev/null +++ b/admin-home.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +use strict; +use CGI; +use C4::Auth; +use C4::Output; + +my $query = new CGI; +my ($loggedinuser, $cookie, $sessionID) = checkauth($query); + +print $query->header(-cookie => $cookie); + +print startpage(); +print startmenu('catalogue'); + + +print "

Logged in as: $loggedinuser [Log Out]

\n"; + +open H, "/usr/local/koha/intranet/htdocs/admin/index.html"; +while () { + print $_; +} +close H; + + +print endpage(); +print endmenu('catalogue'); diff --git a/admin/templates.pl b/admin/templates.pl new file mode 100755 index 0000000000..16767735f1 --- /dev/null +++ b/admin/templates.pl @@ -0,0 +1,58 @@ +#!/usr/bin/perl + +#script to administer the systempref table +#written 20/02/2002 by paul.poulain@free.fr +# This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html) + +use strict; +use C4::Output; +use CGI; +use C4::Search; +use C4::Database; +use C4::Auth; + +my $input = new CGI; + + +my $dbh=C4Connect(); + +if ($input->param('settemplate')) { + my $sth=$dbh->prepare("update systempreferences set value=? where variable='template'"); + $sth->execute($input->param('settemplate')); + print $input->redirect('/cgi-bin/koha/catalogue-home.pl'); + exit; +} + +print $input->header(); + +print startpage(); +print startmenu('catalogue'); + +my $sth=$dbh->prepare("select value from systempreferences where variable='template'"); +$sth->execute; +my ($template)=$sth->fetchrow; + +my $templateoptions=''; +opendir D, "/usr/local/koha/intranet/htdocs/includes/templates"; +my @dirlist=readdir D; +foreach (@dirlist) { + (next) if (/^\./); + my $selected=''; + ($_ eq $template) && ($selected=' selected'); + $templateoptions.="