[Koha-cvs] koha/intranet/cgi-bin/catalogue ISBDdetail.pl M... [rel_TG]

Tumer Garip tgarip at neu.edu.tr
Sat Mar 10 02:15:01 CET 2007


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_TG
Changes by:	Tumer Garip <tgarip1957>	07/03/10 01:15:01

Added files:
	intranet/cgi-bin/catalogue: ISBDdetail.pl MARCdetail.pl 
	                            bookcount.pl catalogue-search.pl 
	                            cyprus-search.pl detail.pl 
	                            detailprint.pl moredetail.pl 
	                            newsdetail.pl search.pl 

Log message:
	fresh files for rel_TG

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/ISBDdetail.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/MARCdetail.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/bookcount.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/catalogue-search.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/cyprus-search.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/detail.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/detailprint.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/moredetail.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/newsdetail.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/koha/intranet/cgi-bin/catalogue/search.pl?cvsroot=koha&only_with_tag=rel_TG&rev=1.1.2.1

Patches:
Index: ISBDdetail.pl
===================================================================
RCS file: ISBDdetail.pl
diff -N ISBDdetail.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ISBDdetail.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,152 @@
+#!/usr/bin/perl
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+=head1 NAME
+
+ISBDdetail.pl : script to show a biblio in ISBD format
+
+=head1 SYNOPSIS
+
+
+=head1 DESCRIPTION
+
+This script needs a biblionumber in bib parameter (bibnumber
+from koha style DB.  Automaticaly maps to marc biblionumber).
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
+
+use strict;
+
+use C4::Auth;
+use C4::Context;
+use C4::AuthoritiesMarc;
+use C4::Interface::CGI::Output;
+use CGI;
+use C4::Search;
+use C4::Biblio;
+use C4::Acquisition;
+use C4::Koha;
+
+my $query=new CGI;
+
+my $dbh=C4::Context->dbh;
+
+my $biblionumber=$query->param('biblionumber');
+
+my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber);
+my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
+
+my $record =XMLgetbibliohash($dbh,$biblionumber);
+# open template
+my ($template, $loggedinuser, $cookie)
+		= get_template_and_user({template_name => "catalogue/ISBDdetail.tmpl",
+			     query => $query,
+			     type => "intranet",
+			     authnotrequired => 1,
+			     debug => 1,
+			     });
+
+my $ISBD = C4::Context->preference('ISBD');
+my $res;
+	my $bloc = $ISBD;
+	my $blocres;
+	foreach my $isbdfield (split /#/,$bloc) {
+		$isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
+		my $fieldvalue=$1;
+		my $textbefore=$2;
+		my $analysestring=$3;
+		my $textafter=$4;
+		if ($fieldvalue>0) {
+			my $hasputtextbefore=0;
+			
+				my $calculated = $analysestring;
+				my $tag = $fieldvalue;
+				if ($tag<10) {
+				my $value=XML_readline_onerecord($record,"","",$tag);
+				my $subfieldcode = "@";
+						my $subfieldvalue = get_authorised_value_desc($tag, "", $value, '', $dbh);;
+						my $tagsubf = $tag.$subfieldcode;
+						$calculated =~ s/\{(.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue\{$1$tagsubf$2\}$2/g;
+					
+				} else {
+					my @subf = XML_readline_withtags($record,"","",$tag);
+				
+					for my $i (0..$#subf) {
+						my $subfieldcode = $subf[$i][0];
+						my $subfieldvalue = get_authorised_value_desc($tag, $subf[$i][0], $subf[$i][1], '', $dbh);;
+						my $tagsubf = $tag.$subfieldcode;
+						$calculated =~ s/\{(.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue\{$1$tagsubf$2\}$2/g;
+					}
+					# field builded, store the result
+					if ($calculated && !$hasputtextbefore) { # put textbefore if not done
+						$blocres .=$textbefore;
+						$hasputtextbefore=1
+					}
+					# remove punctuation at start
+					$calculated =~ s/^( |;|:|\.|-)*//g;
+					$blocres.=$calculated;
+				}
+			
+			$blocres .=$textafter if $hasputtextbefore;
+		} else {
+			$blocres.=$isbdfield;
+		}
+	}
+	$res.=$blocres;
+# }
+$res =~ s/\{(.*?)\}//g;
+$res =~ s/\\n/\n/g;
+$res =~ s/\n/<br\/>/g;
+# remove empty ()
+$res =~ s/\(\)//g;
+$template->param(ISBD => $res,
+				biblionumber => $biblionumber);
+
+output_html_with_http_headers $query, $cookie, $template->output;
+
+sub get_authorised_value_desc ($$$$$) {
+   my($tag, $subfield, $value, $framework, $dbh) = @_;
+
+   #---- branch
+    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
+       return getbranchname($value);
+    }
+
+   #---- itemtypes
+   if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
+       return ItemType($value);
+    }
+
+   #---- "true" authorized value
+   my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
+
+   if ($category ne "") {
+       my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
+       $sth->execute($category, $value);
+       my $data = $sth->fetchrow_hashref;
+       return $data->{'lib'};
+   } else {
+       return $value; # if nothing is found return the original value
+   }
+}

Index: MARCdetail.pl
===================================================================
RCS file: MARCdetail.pl
diff -N MARCdetail.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MARCdetail.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,331 @@
+#!/usr/bin/perl
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+=head1 NAME
+
+MARCdetail.pl : script to show a biblio in MARC format
+
+=head1 SYNOPSIS
+
+
+=head1 DESCRIPTION
+
+This script needs a biblionumber in bib parameter (bibnumber
+from koha style DB.  Automaticaly maps to marc biblionumber).
+
+It shows the biblio in a (nice) MARC format depending on MARC
+parameters tables.
+
+The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
+this template must be divided into 11 "tabs".
+
+The first 10 tabs present the biblio, the 11th one presents
+the items attached to the biblio
+
+=head1 FUNCTIONS
+
+=over 2
+
+=cut
+
+
+use strict;
+use C4::Auth;
+use C4::Context;
+use C4::Interface::CGI::Output;
+use CGI;
+use C4::Search;
+use C4::Biblio;
+use C4::Acquisition;
+use C4::Serials; #uses getsubscriptionsfrombiblionumber
+use C4::Koha;
+
+my $query=new CGI;
+
+my $dbh=C4::Context->dbh;
+my $retrieve_from=C4::Context->preference('retrieve_from');
+my $biblionumber=$query->param('biblionumber');
+my $frameworkcode = $query->param('frameworkcode');
+my $popup = $query->param('popup'); # if set to 1, then don't insert links, it's just to show the biblio
+my $record;
+my @itemrecords;
+my $xmlhash;
+$frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
+my $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
+my $itemstagslib = &MARCitemsgettagslib($dbh,1,$frameworkcode);
+
+if ($retrieve_from eq "zebra"){
+($xmlhash, at itemrecords)=ZEBRAgetrecord($biblionumber);
+
+}else{
+ $record =XMLgetbiblio($dbh,$biblionumber);
+$xmlhash=XML_xml2hash_onerecord($record);
+my @itemxmls=XMLgetallitems($dbh,$biblionumber);
+	foreach my $itemrecord(@itemxmls){
+	my $itemhash=XML_xml2hash($itemrecord);
+	push @itemrecords, $itemhash;
+	}
+}
+
+my ($template, $loggedinuser, $cookie)
+		= get_template_and_user({template_name => "catalogue/MARCdetail.tmpl",
+			     query => $query,
+			     type => "intranet",
+			     authnotrequired => 0,
+			     flagsrequired => {catalogue => 1},
+			     debug => 1,
+			     });
+
+#Getting the list of all frameworks
+my $queryfwk =$dbh->prepare("select frameworktext, frameworkcode from biblios_framework");
+$queryfwk->execute;
+my %select_fwk;
+my @select_fwk;
+my $curfwk;
+push @select_fwk,"Default";
+$select_fwk{"Default"} = "Default";
+while (my ($description, $fwk) =$queryfwk->fetchrow) {
+	push @select_fwk, $fwk;
+	$select_fwk{$fwk} = $description;
+}
+$curfwk=$frameworkcode;
+my $framework=CGI::scrolling_list( -name     => 'Frameworks',
+			-id => 'Frameworks',
+			-default => $curfwk,
+			-OnChange => 'Changefwk(this);',
+			-values   => \@select_fwk,
+			-labels   => \%select_fwk,
+			-size     => 1,
+			-multiple => 0 );
+
+$template->param( framework => $framework);
+# fill arrays
+my @loop_data =();
+my $tag;
+# loop through each tab 0 through 9
+##Only attempt to fill the template if we actually received a MARC record
+if ($xmlhash){
+my ($isbntag,$isbnsub)=MARCfind_marc_from_kohafield("isbn","biblios");
+my $biblio=$xmlhash->{'datafield'};
+my $controlfields=$xmlhash->{'controlfield'};
+my $leader=$xmlhash->{'leader'};
+for (my $tabloop = 0; $tabloop<10;$tabloop++) {
+# loop through each tag
+	my @loop_data =();
+	my @subfields_data;
+
+	# deal with leader 
+	unless (($tagslib->{'000'}->{'@'}->{tab}  ne $tabloop)  || (substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
+		
+		my %subfield_data;
+		$subfield_data{marc_value}=$leader->[0] ;
+		push(@subfields_data, \%subfield_data);
+		my %tag_data;
+		$tag_data{tag}='000 -'. $tagslib->{'000'}->{lib};
+		my @tmp = @subfields_data;
+		$tag_data{subfield} = \@tmp;
+		push (@loop_data, \%tag_data);
+		undef @subfields_data;
+	}
+	##Controlfields
+		
+		 foreach my $control (@$controlfields){
+			my %subfield_data;
+			my %tag_data;
+			next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab}  ne $tabloop);
+			next if (substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);			
+			$subfield_data{marc_value}=$control->{'content'} ;
+			push(@subfields_data, \%subfield_data);
+				if (C4::Context->preference('hide_marc')) {
+					$tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib};
+				} else {
+					$tag_data{tag}=$control->{'tag'}.' -'. $tagslib->{$control->{'tag'}}->{lib};
+				}			
+			my @tmp = @subfields_data;
+			$tag_data{subfield} = \@tmp;
+			push (@loop_data, \%tag_data);
+			undef @subfields_data;
+		}
+	my $previoustag;
+	my %datatags;
+	my $i=0;
+	foreach my $data (@$biblio){
+		$datatags{$i++}=$data->{'tag'};
+		 foreach my $subfield ( $data->{'subfield'}){
+		     foreach my $code ( @$subfield){
+			next if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab}  ne $tabloop);
+			next if (substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
+			my %subfield_data;
+			my $value=$code->{'content'};
+			$subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
+			$subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link};
+			if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) {
+				$subfield_data{marc_value}="<a href=\"$value\">$value</a>";
+			} elsif ($data->{'tag'} eq $isbntag && $code->{'code'} eq $isbnsub) {
+				$subfield_data{marc_value}=DisplayISBN($value);
+			} else {
+				if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{authtypecode}) {
+				my ($authtag,$authtagsub)=MARCfind_marc_from_kohafield("auth_biblio_link_subf","biblios");
+				$subfield_data{authority}=XML_readline_onerecord($xmlhash,"","",$data->{'tag'},$authtagsub);
+				}
+			if (length($value) >100) {
+			$subfield_data{marc_value}="<textarea tabindex=\"1\"   cols=\"40\" rows=\"5\" >$value</textarea>";
+			}else{
+			$subfield_data{marc_value}=get_authorised_value_desc($data->{'tag'}, $code->{'code'}, $value, '', $dbh);
+			}
+			}
+			$subfield_data{marc_subfield}=$code->{'code'};
+			$subfield_data{marc_tag}=$data->{'tag'};
+			push(@subfields_data, \%subfield_data);
+		     }### $code
+		
+		
+		if ($#subfields_data==0) {
+		#	$subfields_data[0]->{marc_lib}='';
+		#	$subfields_data[0]->{marc_subfield}='';
+		}
+		if ($#subfields_data>=0) {
+			my %tag_data;
+			if (($datatags{$i} eq $datatags{$i-1}) && (C4::Context->preference('LabelMARCView') eq 'economical')) {
+				$tag_data{tag}="";
+			} else {
+				if (C4::Context->preference('hide_marc')) {
+					$tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
+				} else {
+					$tag_data{tag}=$data->{'tag'}.' -'. $tagslib->{$data->{'tag'}}->{lib};
+				}
+			}
+			my @tmp = @subfields_data;
+			$tag_data{subfield} = \@tmp;
+			push (@loop_data, \%tag_data);
+			undef @subfields_data;
+		}
+	      }### each $subfield
+	}
+
+	$template->param($tabloop."XX" =>\@loop_data);
+}
+# now, build item tab !
+# the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
+# loop through each tag
+# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
+# then construct template.
+my @fields;
+my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
+my @big_array;
+foreach my $itemrecord (@itemrecords){
+my $item=$itemrecord->{'datafield'};
+my $controlfields=$itemrecord->{'controlfield'};
+my $leader=$itemrecord->{'leader'};
+my %this_row;
+		### The leader
+		unless (substr($itemstagslib->{'000'}->{'@'}->{hidden},1,1)>0){
+			my @datasub='000@';
+			$witness{$datasub[0]} = $itemstagslib->{'000'}->{'@'}->{lib};
+			$this_row{$datasub[0]} =$leader->[0];
+		}
+		 foreach my $control (@$controlfields){
+		next if ($itemstagslib->{$control->{'tag'}}->{'@'}->{tab}  ne 10);
+			next if (substr($itemstagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);
+			my @datasub=$control->{'tag'}.'@';
+			$witness{$datasub[0]} = $itemstagslib->{$control->{'tag'}}->{'@'}->{lib};
+			$this_row{$datasub[0]} =$control->{'content'};
+		}
+
+		foreach my $data (@$item){		
+		   foreach my $subfield ( $data->{'subfield'}){
+			foreach my $code ( @$subfield){
+			next if ($itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab}  ne 10);
+			next if (substr($itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
+			$witness{$data->{'tag'}.$code->{'code'}} = $itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
+			$this_row{$data->{'tag'}.$code->{'code'}} =$code->{'content'};
+			}			
+		    }# subfield
+		}## each field
+	if (%this_row) {
+	push(@big_array, \%this_row);
+	}
+}## each record
+my ($holdingbrtagf,$holdingbrtagsubf) = &MARCfind_marc_from_kohafield("holdingbranch","holdings");
+ at big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
+
+#fill big_row with missing datas
+foreach my $subfield_code  (keys(%witness)) {
+	for (my $i=0;$i<=$#big_array;$i++) {
+		$big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
+	}
+}
+# now, construct template !
+my @item_value_loop;
+my @header_value_loop;
+for (my $i=0;$i<=$#big_array; $i++) {
+	my $items_data;
+	foreach my $subfield_code (keys(%witness)) {
+		$items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
+	}
+	my %row_data;
+	$row_data{item_value} = $items_data;
+	push(@item_value_loop,\%row_data);
+}
+foreach my $subfield_code (keys(%witness)) {
+	my %header_value;
+	$header_value{header_value} = $witness{$subfield_code};
+	push(@header_value_loop, \%header_value);
+}
+
+my $subscriptionsnumber = GetSubscriptionsFromBiblionumber($biblionumber);
+$template->param(item_loop => \@item_value_loop,
+						item_header_loop => \@header_value_loop,
+						biblionumber => $biblionumber,
+						subscriptionsnumber => $subscriptionsnumber,
+						popup => $popup,
+						hide_marc => C4::Context->preference('hide_marc'),
+						intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+		intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+		IntranetNav => C4::Context->preference("IntranetNav"),
+						);
+}##if $xmlhash
+$template->param(biblionumber => $biblionumber,);
+output_html_with_http_headers $query, $cookie, $template->output;
+
+sub get_authorised_value_desc ($$$$$) {
+   my($tag, $subfield, $value, $framework, $dbh) = @_;
+
+   #---- branch
+    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
+       return getbranchname($value);
+    }
+
+   #---- itemtypes
+   if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
+       return ItemType($value);
+    }
+
+   #---- "true" authorized value
+   my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
+
+   if ($category ne "") {
+       my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
+       $sth->execute($category, $value);
+       my $data = $sth->fetchrow_hashref;
+       return $data->{'lib'};
+   } else {
+       return $value; # if nothing is found return the original value
+   }
+}

Index: bookcount.pl
===================================================================
RCS file: bookcount.pl
diff -N bookcount.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bookcount.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,173 @@
+#!/usr/bin/perl
+
+# $Id: bookcount.pl,v 1.1.2.1 2007/03/10 01:15:01 tgarip1957 Exp $
+
+#written 7/3/2002 by Finlay
+#script to display reports
+
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use CGI;
+use C4::Context;
+use C4::Search;
+use C4::Circulation::Circ2;
+use C4::Interface::CGI::Output;
+use C4::Koha;
+use C4::Auth;
+use C4::Date;
+# get all the data ....
+my %env;
+my $main='#cccc99';
+my $secondary='#ffffcc';
+
+my $input = new CGI;
+my $itemnumber = $input->param('itemnumber');
+my $biblionumber = $input->param('biblionumber');
+my $branches = GetBranches();
+
+my $idata = getiteminformation(undef,$itemnumber);
+
+# my $homebranch = $branches->{$idata->{'homebranch'}}->{'branchname'};
+ my $homebranch = $idata->{'homebranch'};
+my $holdingbranch = $branches->{$idata->{'holdingbranch'}}->{'branchname'};
+
+my ($lastmove, $message) = lastmove($itemnumber);
+
+my $lastdate;
+my $count;
+if (!$lastmove) {
+    $lastdate = $message;
+    $count = issuessince($itemnumber , 0);
+} else {
+    $lastdate = format_date($lastmove->{'datearrived'});
+    $count = issuessince($itemnumber ,$lastdate);
+}
+
+# make the page ...
+
+my ($template, $loggedinuser, $cookie)
+      = get_template_and_user({template_name => "catalogue/bookcount.tmpl",
+	                                 query => $input,
+	                                 type => "intranet",
+	                                 authnotrequired => 0,
+	                                 flagsrequired => {borrowers => 1},
+	                                 debug => 1,
+	                                 });
+
+
+
+my @branchloop;
+
+foreach my $branchcode (keys %$branches) {
+	my %linebranch;
+    $linebranch{issues} = issuesat($itemnumber, $branchcode);
+    my $date = lastseenat($itemnumber, $branchcode);
+    $linebranch{seen} = slashdate($date);
+	$linebranch{branchname}=$branches->{$branchcode}->{'branchname'};
+	push(@branchloop,\%linebranch);
+}
+
+$template->param(	biblionumber => $biblionumber,
+								title => $idata->{'title'},
+								author => $idata->{'author'},
+								barcode => $idata->{'barcode'},
+								homebranch =>$homebranch,
+								holdingbranch => $holdingbranch,
+								lastdate =>  $lastdate,
+								count =>  $count,
+								branchloop => \@branchloop);
+
+output_html_with_http_headers $input, $cookie, $template->output;
+
+
+##############################################
+# This stuff should probably go into C4::Search
+
+
+sub lastmove {
+      my ($itemnumber)=@_;
+      my $dbh = C4::Context->dbh;
+      my $sth =$dbh->prepare("select max(branchtransfers.datearrived) from branchtransfers where branchtransfers.itemnumber=?");
+      $sth->execute($itemnumber);
+      my ($date) = $sth->fetchrow;
+      return(0, "Item has no branch transfers record") unless $date;
+      $sth=$dbh->prepare("Select * from branchtransfers where branchtransfers.itemnumber=? and branchtransfers.datearrived=?");
+      $sth->execute($itemnumber,$date);
+      my ($data) = $sth->fetchrow_hashref;
+      return(0, "Item has no branch transfers record") unless $data;
+      $sth->finish;
+      return($data,"");
+ }
+
+sub issuessince {
+      my ($itemnumber, $date)=@_;
+      my $dbh = C4::Context->dbh;
+      my $sth=$dbh->prepare("Select count(*) from issues where issues.itemnumber=? and issues.timestamp > ?");
+      $sth->execute($itemnumber,$date);
+      my $count=$sth->fetchrow_hashref;
+      $sth->finish;
+      return($count->{'count(*)'});
+}
+
+sub issuesat {
+      my ($itemnumber, $brcd)=@_;
+      my $dbh = C4::Context->dbh;
+      my $sth=$dbh->prepare("Select count(*) from issues where itemnumber=? and branchcode = ?");
+      $sth->execute($itemnumber,$brcd);
+      my ($count)=$sth->fetchrow_array;
+      $sth->finish;
+      return($count);
+}
+
+sub lastseenat {
+      my ($itemnumber, $brc)=@_;
+      my $dbh = C4::Context->dbh;
+      my $sth=$dbh->prepare("Select max(timestamp) from issues where itemnumber=? and branchcode = ?");
+      $sth->execute($itemnumber,$brc);
+      my ($date1)=$sth->fetchrow_array;
+      $sth->finish;
+      $sth=$dbh->prepare("Select max(datearrived) from branchtransfers where itemnumber=? and tobranch = ?");
+      $sth->execute($itemnumber,$brc);
+      my ($date2)=$sth->fetchrow_array;
+      $sth->finish;
+      #FIXME: MJR thinks unsafe
+      $date2 =~ s/-//g;
+      $date2 =~ s/://g;
+      $date2 =~ s/ //g;
+      my $date;
+      if ($date1 < $date2) {
+	  $date = $date2;
+      } else {
+	  $date = $date1;
+      }
+      return($date);
+}
+
+
+#####################################################
+# write date....
+sub slashdate {
+    my ($date) = @_;
+    if (not $date) {
+	return "never";
+    }
+    my ($yr, $hr) = (substr($date, 0, 10),  substr($date, 11, 5));
+    return "$hr  " . format_date($yr);
+}

Index: catalogue-search.pl
===================================================================
RCS file: catalogue-search.pl
diff -N catalogue-search.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ catalogue-search.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,393 @@
+#!/usr/bin/perl
+use strict;
+
+use CGI ;
+
+use C4::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Biblio;
+use C4::Koha;
+use POSIX qw(ceil floor);
+my $query = CGI->new();
+my $dbh = C4::Context->dbh;
+my $op = $query->param('op'); #show the search form or execute the search
+
+my $format=$query->param('MARC');
+my ($template, $borrowernumber, $cookie);
+
+# get all the common search variables, 
+my @value=$query->param('value');
+my @kohafield=$query->param('kohafield');
+my @and_or=$query->param('and_or');
+my @relation=$query->param('relation');
+my $order=$query->param('order');
+my $reorder=$query->param('reorder');
+my $number_of_results=$query->param('number_of_results');
+my $zoom=$query->param('zoom');
+my $ascend=$query->param('asc');
+my $searchtype=$query->param('searchtype'); ## this is actual query type
+my $serverid=$query->param('serverid');
+$serverid=-1 unless($serverid eq "0"  || $serverid>0);
+my @marclist = $query->param('marclist');
+# collect all the fields ...
+my %search;
+my @forminputs;		#this is for the links to navigate among the results
+my (@searchdesc, %hashdesc,$facetsdesc); 	#this is to show the description of the current search
+my @fields = ('value', 'kohafield', 'and_or', 'relation','order','barcode','biblionumber','itemnumber','asc','from','searchtype');
+
+###Collect all the marclist values coming from old Koha MARCdetails
+## Although we can not search on all marc fields- if any is matched in Zebra we can use it 
+my $sth=$dbh->prepare("Select kohafield from koha_attr where tagfield=? and tagsubfield=? and intrashow=1");
+foreach my $marc (@marclist) {
+		if ($marc) {
+		$sth->execute(substr($marc,0,3),substr($marc,3,1));
+			if ((my $kohafield)=$sth->fetchrow){
+			push @kohafield,$kohafield;
+			push @and_or,"\@or";
+			push @value, at value[0] if @kohafield>1;
+			push @relation ,"\@attr 5=1";
+			}
+		}
+}
+#### Now   normal search routine
+foreach my $field (@fields) {
+	$search{$field} = $query->param($field);
+	my @fieldvalue = $query->param($field);
+	foreach my $fvalue (@fieldvalue) {
+		push @forminputs, { field=>$field ,value=> $fvalue} unless ($field eq 'reorder');
+		
+	  }
+}
+## Build the query for facets as well
+ for (my $i=0;$i<@value;$i++){
+$facetsdesc.="&value=".$value[$i];
+$facetsdesc.="&kohafield=".$kohafield[$i];
+$facetsdesc.="&relation=".$relation[$i];
+$facetsdesc.="&and_or=".$and_or[$i];
+}
+$facetsdesc.="&order=".$order;
+$hashdesc{'query'} = join " , ", @value;
+push @searchdesc,\%hashdesc;
+
+
+############################################################################
+if ($op eq "do_search"){
+ 
+#this fields is just to allow the user come back to the search form with all the values  previously entered
+$search{'search_type'} = $query->param('search_type');# this is the panel type
+push @forminputs, {field => 'search_type', value => $search{'search_type'}};
+
+
+	($template, $borrowernumber, $cookie)
+		= get_template_and_user({template_name => "catalogue/catalogue_searchresults.tmpl",
+					 query => $query,
+					 type => "intranet",
+					 authnotrequired => 1,
+	});
+
+	$search{'from'} = 'intranet';
+	$search{'borrowernumber'} = $borrowernumber;
+	$search{'remote_IP'} = $query->remote_addr();
+	$search{'remote_URL'} = $query->url(-query=>1);
+	$search{'searchdesc'} = \@searchdesc;
+	$template->param(FORMINPUTS => \@forminputs);
+	$template->param(reorder => $query->param('reorder'));
+	$template->param(facetsdesc=>$facetsdesc);
+	# do the searchs ....
+	 $number_of_results = 10 unless $number_of_results;
+	my $startfrom=$query->param('startfrom');
+	($startfrom) || ($startfrom=0);
+my ($count, at results,$facets);
+if ($serverid>0){
+ my $sth=$dbh->prepare("select * from online_databases where serverid=?");
+  $sth->execute($serverid);
+
+  my  $server=$sth->fetchrow_hashref ;
+
+my	$serverquery=$server->{search_string};
+	if ($server->{$kohafield[0]} ne ""){
+	$serverquery.=$server->{$kohafield[0]."_query"}.$value[0];
+	}else{
+	$serverquery.=$server->{"any_query"}.$value[0]."&relation=$relation[0]";
+	}
+print $query->redirect($serverquery);
+  
+}##serverid>0
+if ($serverid eq "0"){
+use ZOOM;
+my @oConnection;
+my @oResult;
+my $s=0;
+my $server;							
+my @serverhost;
+my @serverquery;
+my @query;							
+my @onlineloop;
+my $numberpending;
+my $even=1;			
+  my $sth=$dbh->prepare("select * from online_databases ");
+  $sth->execute();
+
+    while ($server=$sth->fetchrow_hashref) {
+	my $noconnection=0;
+	
+							
+	my $option1=new ZOOM::Options();
+	$option1->option(async=>1);
+	$option1->option('elementSetName', 'F');
+	$option1->option('databaseName',$server->{db})  ;
+	$option1->option('user',$server->{userid})  ;
+	$option1->option('password',$server->{password})  ;
+	 $oConnection[$s]=create ZOOM::Connection($option1);
+	$oConnection[$s]->connect($server->{host}, $server->{port});
+	$serverhost[$s]=$server->{server};
+	$serverquery[$s]=$server->{search_string};
+	if ($server->{$kohafield[0]} ne ""){
+	$serverquery[$s].=$server->{$kohafield[0]."_query"}.$value[0];
+	}else{
+	$serverquery[$s].=$server->{"any_query"}.$value[0];
+	}
+ $query[$s]=$server->{$kohafield[0]}." \"".$value[0]."\"";	
+
+	$s++;
+    }## while fetch
+
+ 
+my $nremaining = $s;
+my $firstresult=1;
+ for (my $z=0 ;$z<$s;$z++){
+$oResult[$z] = $oConnection[$z]->search_pqf($query[$z]);
+
+}
+AGAIN:
+ my $k;
+my $event;
+  while (($k = ZOOM::event(\@oConnection)) != 0) {
+	$event = $oConnection[$k-1]->last_event();
+# warn ("connection ", $k-1, ": event $event (", ZOOM::event_str($event), ")\n");
+	last if $event == ZOOM::Event::ZEND;
+   }
+if ($k != 0) {
+	$k--;
+#warn $serverhost[$k];
+	 my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
+   	if ($error) {
+	warn "$k $serverhost[$k] error $query[$k]: $errmsg ($error) $addinfo\n";
+	goto MAYBE_AGAIN;
+  	}
+	
+	my $numresults=$oResult[$k]->size() ;								
+ 									
+
+	if ($numresults>0){
+	
+		
+
+			my %row_data;
+ 	
+	$row_data{even} = $even;
+	$row_data{server} = $serverhost[$k];
+	$row_data{numresults} = $numresults;
+
+	$row_data{search_string} =$serverquery[$k];
+	
+	$even=!$even;
+	push (@onlineloop, \%row_data);
+
+						
+}# $numresults
+
+}# if $k !=0
+
+
+$numberpending=$nremaining-1;
+
+MAYBE_AGAIN:
+if (--$nremaining > 0) {
+    goto AGAIN;
+}
+$template->param(onlineloop=>\@onlineloop,);
+}##serverid==0
+if (!$zoom){
+## using sql search for barcode,biblionumber or itemnumber only useful for libraian interface
+	($count, @results) =sqlsearch($dbh,\%search);
+}else{
+my $sortorder=$order.$ascend if $order;
+ ($count,$facets, at results) =ZEBRAsearch_kohafields(\@kohafield,\@value, \@relation,$sortorder, \@and_or, 1,$reorder,$startfrom, $number_of_results,"intranet",$searchtype);
+}
+my $timetaken=$results[0]->{timetaken} if $count>0;
+	if ( $count eq "error"){
+	$template->param(error =>1);
+	goto "show";
+	}
+	my $num = scalar(@results) - 1;
+if ( $count == 1){
+    # if its a barcode search by definition we will only have one result.
+    # And if we have a result
+    # lets jump straight to the detail.pl page
+	if ($format eq '1') {
+    print $query->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?type=intra&biblionumber=$results[0]->{'biblionumber'}");
+	}else{
+    print $query->redirect("/cgi-bin/koha/catalogue/detail.pl?type=intra&biblionumber=$results[0]->{'biblionumber'}");
+	}
+}
+	# sorting out which results to display.
+		# the total results searched
+	$template->param(numrecords => $count);
+	$template->param(FORMINPUTS => \@forminputs );
+	$template->param(searchdesc => \@searchdesc );
+if ($serverid==-1){
+	# the result number to star to show
+	$template->param(startfrom => $startfrom);
+	$template->param(beginning => $startfrom+1);
+	# the result number to end to show
+	($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num+1)) : ($template->param(endat => $count));
+
+	
+ 	$template->param(SEARCH_RESULTS => \@results,timetaken=>$timetaken,);
+
+$template->param(facets_loop => $facets,) if $facets;
+	#this is to show the images numbers to navigate among the results, if it has to show the number highlighted or not
+	my $numbers;
+	@$numbers = ();
+	my $pg = 1;
+	if (defined($query->param('pg'))) {
+		$pg = $query->param('pg');
+	}
+	my $start = 0;
+	
+	$start = ($pg - 1) * $number_of_results;
+	my $pages = ceil($count / $number_of_results);
+	my $total_pages = ceil($count / $number_of_results);
+
+	if ($pg > 1) {
+		my $url = $pg - 1;
+		push @$numbers, { number => "&lt;&lt;",  forminputs=>\@forminputs,
+					      highlight => 0 , 
+					      startfrom => 1, 
+					      pg => '1' };
+		push @$numbers, { number => "&lt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($url-1)*$number_of_results+1, 
+						  pg => $url };
+	}
+	my $current_ten = $pg / 10;
+	if ($current_ten == 0) {
+		 $current_ten = 0.1;           # In case it´s in ten = 0
+	} 
+	my $from = $current_ten * 10; # Calculate the initial page
+	my $end_ten = $from + 9;
+	my $to;
+	if ($pages > $end_ten) {
+		$to = $end_ten;
+	} else {
+		$to = $pages;
+	}
+	for (my $i = $from; $i <= $to ; $i++) {
+		if ($i == $pg) {   
+			if ($count > $number_of_results) {
+				push @$numbers, { number => $i, 
+								  highlight => 1 , forminputs=>\@forminputs,
+								  startfrom => ($i-1)*$number_of_results , 
+								  pg => $i };
+			}
+		} else {
+			push @$numbers, { number => $i, 
+							  highlight => 0 , forminputs=>\@forminputs,
+							  startfrom => ($i-1)*$number_of_results , 
+							  pg => $i };
+		}
+	}	        					
+	if ($pg < $pages) {
+		my $url = $pg + 1;
+		push @$numbers, { number => "&gt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($url-1)*$number_of_results, 
+						  pg => $url };
+		push @$numbers, { number => "&gt;&gt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($total_pages-1)*$number_of_results, 
+						  pg => $total_pages};
+	}
+#	push @$numbers,{forminputs=>@forminputs};
+	$template->param(numbers =>$numbers,
+			);
+	#show the virtual shelves
+	#my $results = &GetShelfList($borrowernumber);
+	#$template->param(shelvescount => scalar(@{$results}));
+	#$template->param(shelves => $results);
+ 
+########
+if ($format eq '1') {
+	$template->param(script => "catalogue/MARCdetail.pl");
+}else{
+	$template->param(script => "catalogue/detail.pl");
+}
+}#serverid==-1
+}else{ ## No search yet
+($template, $borrowernumber, $cookie)
+		= get_template_and_user({template_name => "catalogue/catalogue_search.tmpl",
+					query => $query,
+					type => "intranet",
+					authnotrequired => 1,
+				});
+#show kohafields
+	my $kohafield = $query->param('kohafield');
+	my ($fieldcount, at kohafields)=getkohafields();
+	foreach my $row (@kohafields) {
+		if ($kohafield eq $row->{'kohafield'}) {
+			$row->{'sel'} = 1;
+		}
+	}
+	$template->param(kohafields => \@kohafields);
+##show sorting fields
+my @sorts;
+ $order=$query->param('order');
+	foreach my $sort (@kohafields) {
+	    if ($sort->{sorts}){
+		push @sorts,$sort;
+		if ($order eq $sort->{'kohafield'}) {
+			$sort->{'sel'} = 1;
+		}
+	   }
+	}
+	$template->param(sorts => \@sorts);
+# load the branches
+my @branches = GetallBranches();
+$template->param(branchloop => \@branches,);
+
+# load the itemtypes 
+my $itemtypes=GetItemTypes();
+my (@item_type_loop);
+foreach my $thisitemtype (sort keys %$itemtypes) {
+    my %row =(itemtype => $thisitemtype,
+                 description => $itemtypes->{$thisitemtype}->{'description'},
+            );
+    push @item_type_loop, \%row;
+}
+##Show catalogues
+my $sth=$dbh->prepare("select serverid,server from online_databases");
+$sth->execute();
+my @serverloop;
+while (my $server=$sth->fetchrow_hashref) {
+my %temploop;
+$temploop{server}=$server->{server};
+$temploop{serverid}=$server->{serverid};
+
+push (@serverloop, \%temploop);
+}
+$sth->finish;
+$template->param(	servers => \@serverloop,);
+$template->param(itemtypeloop=>\@item_type_loop,);
+my $search_type = $query->param('search_type');
+	if ((!$search_type) || ($search_type eq 'zoom'))  {
+		$template->param(zoom_search => 1);
+	} else{
+		$template->param(sql_search => 1);
+	} 
+}
+
+show:
+output_html_with_http_headers($query, $cookie, $template->output());
+

Index: cyprus-search.pl
===================================================================
RCS file: cyprus-search.pl
diff -N cyprus-search.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ cyprus-search.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,302 @@
+#!/usr/bin/perl
+use strict;
+
+use CGI;
+#use C4::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Biblio;
+use C4::Koha;
+use POSIX qw(ceil floor);
+use C4::Date;
+use utf8;
+my $query = new CGI;
+my $dbh = C4::Context->dbh;
+
+my $op = $query->param('op'); #show the search form or execute the search
+
+my $format=$query->param('MARC');
+my ($template, $borrowernumber, $cookie);
+
+# get all the common search variables, 
+my @value=$query->param('value');
+my @kohafield=$query->param('kohafield');
+my @and_or=$query->param('and_or');
+my @relation=$query->param('relation');
+my $order=$query->param('order');
+my $reorder=$query->param('reorder');
+my $number_of_results=$query->param('number_of_results');
+my $zoom=$query->param('zoom');
+my $ascend=$query->param('asc');
+my $searchtype=$query->param('searchtype'); ## this is actual query type
+my $serverid=$query->param('serverid');
+$serverid=-1 unless($serverid eq "0"  || $serverid>0);
+my @marclist = $query->param('marclist');
+# collect all the fields ...
+my %search;
+my @forminputs;		#this is for the links to navigate among the results
+my (@searchdesc, %hashdesc,$facetsdesc); 	#this is to show the description of the current search
+my @fields = ('value', 'kohafield', 'and_or', 'relation','order','barcode','biblionumber','itemnumber','asc','from','searchtype');
+
+###Collect all the marclist values coming from old Koha MARCdetails
+## Although we can not search on all marc fields- if any is matched in Zebra we can use it 
+my $sth=$dbh->prepare("Select kohafield from koha_attr where tagfield=? and tagsubfield=? and intrashow=1");
+foreach my $marc (@marclist) {
+		if ($marc) {
+		$sth->execute(substr($marc,0,3),substr($marc,3,1));
+			if ((my $kohafield)=$sth->fetchrow){
+			push @kohafield,$kohafield;
+			push @and_or,"\@or";
+			push @value, at value[0] if @kohafield>1;
+			push @relation ,"\@attr 5=1";
+			}
+		}
+}
+#### Now   normal search routine
+foreach my $field (@fields) {
+	$search{$field} = $query->param($field);
+	my @fieldvalue = $query->param($field);
+	foreach my $fvalue (@fieldvalue) {
+		push @forminputs, { field=>$field ,value=> $fvalue} unless ($field eq 'reorder');
+		
+	  }
+}
+## Build the query for facets as well
+ for (my $i=0;$i<@value;$i++){
+$facetsdesc.="&value=".$value[$i];
+$facetsdesc.="&kohafield=".$kohafield[$i];
+$facetsdesc.="&relation=".$relation[$i];
+$facetsdesc.="&and_or=".$and_or[$i];
+}
+$facetsdesc.="&order=".$order;
+ for (my $i=0;$i<@value;$i++){
+$hashdesc{$kohafield[$i]}.=$value[$i].", " if $value[$i];
+}
+push @searchdesc,\%hashdesc;
+
+
+############################################################################
+if ($op eq "do_search"){
+ 
+#this fields is just to allow the user come back to the search form with all the values  previously entered
+$search{'search_type'} = $query->param('search_type');# this is the panel type
+push @forminputs, {field => 'search_type', value => $search{'search_type'}};
+
+
+	($template, $borrowernumber, $cookie)
+		= get_template_and_user({template_name => "catalogue/news_searchresults.tmpl",
+					 query => $query,
+					 type => "intranet",
+					 authnotrequired => 1,
+	});
+
+	$search{'from'} = 'intranet';
+	$search{'borrowernumber'} = $borrowernumber;
+	$search{'remote_IP'} = $query->remote_addr();
+	$search{'remote_URL'} = $query->url(-query=>1);
+	$search{'searchdesc'} = \@searchdesc;
+	$template->param(FORMINPUTS => \@forminputs);
+	$template->param(reorder => $query->param('reorder'));
+	$template->param(facetsdesc=>$facetsdesc);
+	# do the searchs ....
+	 $number_of_results = 10 unless $number_of_results;
+	my $startfrom=$query->param('startfrom');
+	($startfrom) || ($startfrom=0);
+my ($count, at results,$facets);
+
+
+
+my @oConnection;
+my $oResult;
+my $s=0;
+my $server;							
+my @serverhost;
+my @serverquery;
+my $serverquery;							
+my @onlineloop;
+my $numberpending;
+my $even=1;			
+ 	my $noconnection=0;
+	
+							
+	
+	 $oConnection[0]=C4::Context->Zconn("cyprus");
+	
+my $keyattr=MARCfind_attr_from_kohafield($kohafield[0]) if ($kohafield[0]);
+	if (!$keyattr){$keyattr=" \@attr 1=any";}
+ $serverquery=$keyattr." ".$relation[0]." \"".$value[0]."\"";		
+
+$serverquery=new ZOOM::Query::PQF($serverquery);
+
+my $firstresult=1;
+ 
+
+if ($reorder){
+$serverquery->sortby($reorder);
+}else{
+$serverquery->sortby("date i>");
+}
+$oResult = $oConnection[0]->search($serverquery);
+AGAIN:
+ my $k;
+my $event;
+  while (($k = ZOOM::event(\@oConnection)) != 0) {
+	$event = $oConnection[$k-1]->last_event();
+# warn ("connection ", $k-1, ": event $event (", ZOOM::event_str($event), ")\n");
+	last if $event == ZOOM::Event::ZEND;
+   }
+if ($k != 0) {
+	$k--;
+#warn $serverhost[$k];
+	 my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
+   	if ($error) {
+	warn "newsquery error $serverquery: $errmsg ($error) $addinfo\n";
+  	}
+	
+	my $numresults=$oResult->size() ;								
+ 									
+
+	if ($numresults>0){
+	$count=$numresults;
+		
+my $ri=0;
+	my $z=0;
+
+	$ri=$startfrom if $startfrom;
+		for ( $ri; $ri<$numresults ; $ri++){
+
+		my $xmlrecord=$oResult->record($ri)->raw();
+		$xmlrecord=Encode::decode("utf8",$xmlrecord);
+			 $xmlrecord=XML_xml2hash_news($xmlrecord);
+			$z++;
+#warn unpack('U',$xmlrecord->{title});
+
+			$xmlrecord->{title}="No title" if ( unpack('U',$xmlrecord->{title})==65279) ;
+			$xmlrecord->{date}=format_date($xmlrecord->{date});
+			push @results,$xmlrecord;
+			last if ($number_of_results &&  $z>=$number_of_results);
+			
+	
+		}## for #numresults	
+
+						
+	}# $numresults
+
+}# if $k !=0
+
+
+
+
+
+
+	if ( $count eq "error"){
+	$template->param(error =>1);
+	goto "show";
+	}
+	my $num = scalar(@results) - 1;
+if ( $count == 1){
+    # if its a barcode search by definition we will only have one result.
+    # And if we have a result
+    # lets jump straight to the detail.pl page
+
+    print $query->redirect("/cgi-bin/koha/catalogue/newsdetail.pl?type=intra&id=$results[0]->{'id'}");
+	
+}
+	# sorting out which results to display.
+		# the total results searched
+	$template->param(numrecords => $count);
+	$template->param(FORMINPUTS => \@forminputs );
+	$template->param(searchdesc => \@searchdesc );
+
+	# the result number to star to show
+	$template->param(startfrom => $startfrom);
+	$template->param(beginning => $startfrom+1);
+	# the result number to end to show
+	($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num+1)) : ($template->param(endat => $count));
+
+	
+ 	$template->param(SEARCH_RESULTS => \@results,
+			);
+
+	#this is to show the images numbers to navigate among the results, if it has to show the number highlighted or not
+	my $numbers;
+	@$numbers = ();
+	my $pg = 1;
+	if (defined($query->param('pg'))) {
+		$pg = $query->param('pg');
+	}
+	my $start = 0;
+	
+	$start = ($pg - 1) * $number_of_results;
+	my $pages = ceil($count / $number_of_results);
+	my $total_pages = ceil($count / $number_of_results);
+
+	if ($pg > 1) {
+		my $url = $pg - 1;
+		push @$numbers, { number => "&lt;&lt;",  forminputs=>\@forminputs,
+					      highlight => 0 , 
+					      startfrom => 1, 
+					      pg => '1' };
+		push @$numbers, { number => "&lt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($url-1)*$number_of_results+1, 
+						  pg => $url };
+	}
+	my $current_ten = $pg / 10;
+	if ($current_ten == 0) {
+		 $current_ten = 0.1;           # In case it´s in ten = 0
+	} 
+	my $from = $current_ten * 10; # Calculate the initial page
+	my $end_ten = $from + 9;
+	my $to;
+	if ($pages > $end_ten) {
+		$to = $end_ten;
+	} else {
+		$to = $pages;
+	}
+	for (my $i = $from; $i <= $to ; $i++) {
+		if ($i == $pg) {   
+			if ($count > $number_of_results) {
+				push @$numbers, { number => $i, 
+								  highlight => 1 , forminputs=>\@forminputs,
+								  startfrom => ($i-1)*$number_of_results , 
+								  pg => $i };
+			}
+		} else {
+			push @$numbers, { number => $i, 
+							  highlight => 0 , forminputs=>\@forminputs,
+							  startfrom => ($i-1)*$number_of_results , 
+							  pg => $i };
+		}
+	}	        					
+	if ($pg < $pages) {
+		my $url = $pg + 1;
+		push @$numbers, { number => "&gt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($url-1)*$number_of_results, 
+						  pg => $url };
+		push @$numbers, { number => "&gt;&gt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($total_pages-1)*$number_of_results, 
+						  pg => $total_pages};
+	}
+#	push @$numbers,{forminputs=>@forminputs};
+	$template->param(numbers =>$numbers,
+			);
+	#show the virtual shelves
+	#my $results = &GetShelfList($borrowernumber);
+	#$template->param(shelvescount => scalar(@{$results}));
+	#$template->param(shelves => $results);
+ 
+########
+
+	$template->param(script => "catalogue/newsdetail.pl");
+
+
+}else{ ## No search yet
+print $query->redirect("/cgi-bin/koha/catalogue/catalogue-search.pl");
+}
+
+show:
+output_html_with_http_headers $query, $cookie, $template->output();
+

Index: detail.pl
===================================================================
RCS file: detail.pl
diff -N detail.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ detail.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+use strict;
+use C4::Search;
+use C4::Auth;
+use C4::Serials; #uses getsubscriptionfrom biblionumber
+use C4::Interface::CGI::Output;
+use CGI;
+use C4::Biblio;
+use C4::Context;
+
+my $dbh=C4::Context->dbh;
+my $query=new CGI;
+my ($template, $borrowernumber, $cookie) 
+    = get_template_and_user({template_name => "catalogue/detail.tmpl",
+			     query => $query,
+			     type => "intranet",
+			     authnotrequired => 1,
+			     flagsrequired => {borrow => 1},
+			     });
+
+my $biblionumber=$query->param('biblionumber');
+
+$template->param(biblionumber => $biblionumber,);
+my $retrieve_from=C4::Context->preference('retrieve_from');
+my ($record,$frameworkcode);
+my @itemrecords;
+my @items;
+if ($retrieve_from eq "zebra"){
+($record, at itemrecords)=ZEBRAgetrecord($biblionumber);
+}else{
+ $record =XMLgetbiblio($dbh,$biblionumber);
+$record=XML_xml2hash_onerecord($record);
+my @itemxmls=XMLgetallitems($dbh,$biblionumber);
+	foreach my $itemrecord(@itemxmls){
+	my $itemhash=XML_xml2hash_onerecord($itemrecord);
+	push @itemrecords, $itemhash;
+	}
+}	
+
+my $dat = XMLmarc2koha_onerecord($dbh,$record,"biblios");
+$dat->{biblionumber}=$biblionumber unless $dat->{biblionumber};
+my $norequests = 1;
+foreach my $itemrecord (@itemrecords){
+
+my $item= XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings");
+$item=ItemInfo($dbh,$item);
+$item->{itemtype}=$dat->{itemtype};
+  $norequests = 0 unless $item->{'notforloan'};
+   $item->{$item->{'publictype'}} = 1; ## NOT sure what this is kept from old db probably useless now
+push @items,$item;
+}
+
+my $subscriptionsnumber = GetSubscriptionsFromBiblionumber($biblionumber);
+
+$dat->{'count'}=@items;
+$template->param(count =>$dat->{'count'});
+$template->param(norequests => $norequests);
+
+  ## get notes subjects and URLS from MARC record
+	
+	my $marcflavour = C4::Context->preference("marcflavour");
+	my $marcnotesarray = &getMARCnotes($dbh,$record,$marcflavour);
+	my $marcsubjctsarray = &getMARCsubjects($dbh,$record,$marcflavour);
+	my $marcurlssarray = &getMARCurls($dbh,$record,$marcflavour);
+	$template->param(MARCURLS => $marcurlssarray);
+	$template->param(MARCNOTES => $marcnotesarray);
+	$template->param(MARCSUBJCTS => $marcsubjctsarray);
+
+
+my @results = ($dat,);
+
+my $resultsarray=\@results;
+my $itemsarray=\@items;
+
+
+$template->param(BIBLIO_RESULTS => $resultsarray,
+				ITEM_RESULTS => $itemsarray,
+				subscriptionsnumber => $subscriptionsnumber,
+);
+
+output_html_with_http_headers $query, $cookie, $template->output;

Index: detailprint.pl
===================================================================
RCS file: detailprint.pl
diff -N detailprint.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ detailprint.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,97 @@
+#!/usr/bin/perl
+# NOTE: Use standard 8-space tabs for this file (indents are 4 spaces)
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+use strict;
+use C4::Search;
+use C4::Auth;
+use C4::Serials; #uses getsubscriptionfrom biblionumber
+use C4::Interface::CGI::Output;
+use CGI;
+use C4::Biblio;
+use C4::Context;
+
+my $dbh=C4::Context->dbh;
+my $query=new CGI;
+my ($template, $borrowernumber, $cookie) 
+    = get_template_and_user({template_name => "catalogue/detailprint.tmpl",
+			     query => $query,
+			     type => "intranet",
+			     authnotrequired => 1,
+			     flagsrequired => {borrow => 1},
+			     });
+
+my $biblionumber=$query->param('biblionumber');
+$template->param(biblionumber => $biblionumber);
+my $retrieve_from=C4::Context->preference('retrieve_from');
+my ($record,$frameworkcode);
+my @itemrecords;
+my @items;
+if ($retrieve_from eq "zebra"){
+($record, at itemrecords)=ZEBRAgetrecord($biblionumber);
+}else{
+ $record =XMLgetbiblio($dbh,$biblionumber);
+$record=XML_xml2hash_onerecord($record);
+my @itemxmls=XMLgetallitems($dbh,$biblionumber);
+	foreach my $itemrecord(@itemxmls){
+	my $itemhash=XML_xml2hash_onerecord($itemrecord);
+	push @itemrecords, $itemhash;
+	}
+}	
+
+my $dat = XMLmarc2koha_onerecord($dbh,$record,"biblios");
+my $norequests = 1;
+foreach my $itemrecord (@itemrecords){
+
+my $item= XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings");
+$item=ItemInfo($dbh,$item);
+$item->{itemtype}=$dat->{itemtype};
+  $norequests = 0 unless $item->{'notforloan'};
+   $item->{$item->{'publictype'}} = 1; ## NOT sure what this is kept from old db probably useless now
+push @items,$item;
+}
+
+my $subscriptionsnumber = GetSubscriptionsFromBiblionumber($biblionumber);
+
+$dat->{'count'}=@items;
+$template->param(count =>$dat->{'count'});
+$template->param(norequests => $norequests);
+
+  ## get notes subjects and URLS from MARC record
+	
+	my $marcflavour = C4::Context->preference("marcflavour");
+	my $marcnotesarray = &getMARCnotes($dbh,$record,$marcflavour);
+	my $marcsubjctsarray = &getMARCsubjects($dbh,$record,$marcflavour);
+	my $marcurlssarray = &getMARCurls($dbh,$record,$marcflavour);
+	$template->param(MARCURLS => $marcurlssarray);
+	$template->param(MARCNOTES => $marcnotesarray);
+	$template->param(MARCSUBJCTS => $marcsubjctsarray);
+
+
+my @results = ($dat,);
+
+my $resultsarray=\@results;
+my $itemsarray=\@items;
+
+
+$template->param(BIBLIO_RESULTS => $resultsarray,
+				ITEM_RESULTS => $itemsarray,
+				subscriptionsnumber => $subscriptionsnumber,
+);
+
+output_html_with_http_headers $query, $cookie, $template->output;

Index: moredetail.pl
===================================================================
RCS file: moredetail.pl
diff -N moredetail.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ moredetail.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,201 @@
+#!/usr/bin/perl
+# NOTE: Use standard 8-space tabs for this file (indents are 4 spaces)
+
+# $Id: moredetail.pl,v 1.1.2.1 2007/03/10 01:15:01 tgarip1957 Exp $
+
+# Copyright 2000-2003 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use C4::Koha;
+use CGI;
+use C4::Search;
+use C4::Acquisition;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Date;
+use C4::Context;
+use C4::Biblio;
+use C4::Accounts2;
+use C4::Circulation::Circ2;
+
+my $dbh=C4::Context->dbh;
+my $query=new CGI;
+
+
+my ($template, $loggedinuser, $cookie) = get_template_and_user({
+	template_name   => ( 'catalogue/moredetail.tmpl'),
+	query           => $query,
+	type            => "intranet",
+	authnotrequired => 0,
+	flagsrequired   => {catalogue => 1},
+    });
+
+# get variables
+my $op=$query->param('op');
+my $lost=$query->param('lost');
+my $withdrawn=$query->param('withdrawn');
+my $override=$query->param('override');
+my $itemnumber=$query->param('itemnumber');
+my $barcode=$query->param('barcode');
+
+my $title=$query->param('title');
+my $biblionumber=$query->param('biblionumber');
+my ($record)=XMLgetbibliohash($dbh,$biblionumber);
+my $data=XMLmarc2koha_onerecord($dbh,$record,"biblios");
+my $dewey = $data->{'dewey'};
+# FIXME Dewey is a string, not a number, & we should use a function
+$dewey =~ s/0+$//;
+if ($dewey eq "000.") { $dewey = "";};
+if ($dewey < 10){$dewey='00'.$dewey;}
+if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
+if ($dewey <= 0){
+      $dewey='';
+}
+$dewey=~ s/\.$//;
+$data->{'dewey'}=$dewey;
+
+my @results;
+
+my @items;
+if ($op eq "update"){
+my $env;
+##Do Lost or Withdraw here
+my $flag=0;
+  my ($resbor,$resrec)=C4::Reserves2::CheckReserves($env,$dbh,$itemnumber);
+if ($override ne "yes"){
+  if ($resbor){
+#    print $query->header;
+    $template->param(error => "This item   has a reserve on it");
+ $template->param(biblionumber =>$biblionumber);
+ $template->param(itemnumber =>$itemnumber);
+ $template->param(lost =>$lost);
+ $template->param(withdrawn =>$withdrawn);
+    $flag=1;
+  }
+  my $sth=$dbh->prepare("Select * from issues where (itemnumber=?) and (returndate is null)");
+  $sth->execute($itemnumber);
+ 
+  if (my $data=$sth->fetchrow_hashref) {
+   $template->param(biblionumber =>$biblionumber);
+ $template->param(itemnumber =>$itemnumber);
+ $template->param(error => "This item   is On Loan to a member");
+ $template->param(lost =>$lost);
+ $template->param(withdrawn =>$withdrawn);
+    $flag=2;
+  }
+  my $sth=$dbh->prepare("Select * from reserveissue where (itemnumber=?) and (rettime is null)");
+  $sth->execute($itemnumber);
+ 
+  if (my $data=$sth->fetchrow_hashref) {
+   $template->param(biblionumber =>$biblionumber);
+ $template->param(itemnumber =>$itemnumber);
+ $template->param(error => "This item   is On Loan to a member");
+ $template->param(lost =>$lost);
+ $template->param(withdrawn =>$withdrawn);
+    $flag=2;
+  }
+}
+if ($flag != 0 && $override ne "yes"){
+
+  }else {
+   ##UPDATE here
+
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'wthdrawn',$withdrawn,1);
+XMLmoditemonefield($dbh,$biblionumber,$itemnumber,'itemlost',$lost);
+
+     if ($lost ==1 && $flag ==2){
+    my $sth=$dbh->prepare("Select * from issues where (itemnumber=?) and (returndate is null)");
+    $sth->execute($itemnumber);
+    my $data=$sth->fetchrow_hashref;
+my $sth3=$dbh->prepare("Select * from reserveissue where (itemnumber=?) and (rettime is null)");
+    $sth3->execute($itemnumber);
+    my $data2=$sth3->fetchrow_hashref;
+    if ($data->{'borrowernumber'} ne '' || $data2->{'borrowernumber'} ne '') {
+my $borrowernumber=$data->{'borrowernumber'} if $data->{'borrowernumber'};
+$borrowernumber=$data2->{'borrowernumber'} if $data2->{'borrowernumber'};
+      #item on issue add replacement cost to borrowers record
+      my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
+      my $item=getiteminformation($env, $itemnumber);
+	my $replacementprice=60 unless $item->{'replacementprice'};
+      my $sth2=$dbh->prepare("Insert into accountlines
+      (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
+      values
+      (?,?,now(),?,?,'L',?,?)");
+      $sth2->execute($borrowernumber,$accountno,$replacementprice,
+      "Lost Item $item->{'title'} $item->{'barcode'}",
+      $replacementprice,$itemnumber);
+      $sth2->finish;
+       $sth3->finish;
+     $sth->finish;
+    }
+    }
+	if ($flag==1){
+	foreach my $res ($resrec){
+	C4::Reserves2::CancelReseve(undef,$res->{itemnumber},$res->{borrowernumber});
+	}
+	}
+    
+  }
+}
+my @itemrecords=XMLgetallitems($dbh,$biblionumber);
+foreach my $itemrecord (@itemrecords){
+$itemrecord=XML_xml2hash_onerecord($itemrecord);
+my $items = XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings");
+$items->{itemtype}=$data->{itemtype};
+$items->{biblionumber}=$biblionumber;
+$items=itemissues($dbh,$items,$items->{'itemnumber'});
+push @items,$items;
+}
+my $count=@items;
+$data->{'count'}=$count;
+my ($order,$ordernum)=GetOrder($biblionumber,$barcode);
+
+my $env;
+$env->{itemcount}=1;
+
+$results[0]=$data;
+
+foreach my $item (@items){
+    $item->{'replacementprice'}=sprintf("%.2f", $item->{'replacementprice'});
+    $item->{'datelastborrowed'}= format_date($item->{'datelastborrowed'});
+    $item->{'dateaccessioned'} = format_date($item->{'dateaccessioned'});
+    $item->{'datelastseen'} = format_date($item->{'datelastseen'});
+    $item->{'ordernumber'} = $ordernum;
+    $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
+
+    if ($item->{'date_due'} gt '0000-00-00'){
+	$item->{'date_due'} = format_date($item->{'date_due'});		
+$item->{'issue'}= 1;
+		$item->{'borrowernumber'} = $item->{'borrower'};
+		$item->{'cardnumber'} = $item->{'card'};
+			
+    } else {
+	$item->{'issue'}= 0;
+    }
+}
+
+$template->param(BIBITEM_DATA => \@results);
+$template->param(ITEM_DATA => \@items);
+$template->param(loggedinuser => $loggedinuser);
+
+output_html_with_http_headers $query, $cookie, $template->output;
+
+
+# Local Variables:
+# tab-width: 8
+# End:

Index: newsdetail.pl
===================================================================
RCS file: newsdetail.pl
diff -N newsdetail.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ newsdetail.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,92 @@
+#!/usr/bin/perl
+use strict;
+
+use CGI;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Biblio;
+use C4::Koha;
+use C4::Date;
+my $query = new CGI;
+my $dbh = C4::Context->dbh;
+
+my $id = $query->param('id'); #show the search form or execute the search
+my ($template, $borrowernumber, $cookie);
+
+
+
+
+	($template, $borrowernumber, $cookie)
+		= get_template_and_user({template_name => "catalogue/newsdetail.tmpl",
+					 query => $query,
+					 type => "intranet",
+					 authnotrequired => 1,
+	});
+
+	
+my ($count, at results,$facets);
+
+
+
+my @oConnection;
+my $oResult;
+
+my $serverquery;							
+
+	
+							
+	
+	 $oConnection[0]=C4::Context->Zconn("cyprus");
+	
+ $serverquery="\@attr 1=local-number"." \"".$id."\"";	
+
+
+$oResult = $oConnection[0]->search_pqf($serverquery);
+
+ my $k;
+my $event;
+  while (($k = ZOOM::event(\@oConnection)) != 0) {
+	$event = $oConnection[$k-1]->last_event();
+# warn ("connection ", $k-1, ": event $event (", ZOOM::event_str($event), ")\n");
+	last if $event == ZOOM::Event::ZEND;
+   }
+if ($k != 0) {
+	$k--;
+	 my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
+   	if ($error) {
+	warn "newsquery error $serverquery: $errmsg ($error) $addinfo\n";
+  	}
+	
+	my $numresults=$oResult->size() ;								
+ 									
+
+	if ($numresults>0){
+	
+		
+
+
+		my $xmlrecord=$oResult->record(0)->raw();
+		$xmlrecord=Encode::decode("utf8",$xmlrecord);
+			 $xmlrecord=XML_xml2hash_news($xmlrecord);
+			
+			$xmlrecord->{date}=format_date($xmlrecord->{date});
+			$xmlrecord->{news}=~s/\n/<br>/g;
+			$xmlrecord->{news}=~s/(<br><br>)/<br>/g;
+$template->param(title=>$xmlrecord->{title},
+		date=>$xmlrecord->{date},
+		source=>$xmlrecord->{source},
+		news=>$xmlrecord->{news});
+	
+	}# $numresults
+
+}# if $k !=0
+
+
+
+
+
+
+
+show:
+output_html_with_http_headers $query, $cookie, $template->output();
+

Index: search.pl
===================================================================
RCS file: search.pl
diff -N search.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ search.pl	10 Mar 2007 01:15:01 -0000	1.1.2.1
@@ -0,0 +1,419 @@
+#!/usr/bin/perl
+use strict;
+
+use CGI;
+use C4::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Biblio;
+use C4::Koha;
+use POSIX qw(ceil floor);
+#binmode ">:utf8";
+my $query = new CGI;
+my $dbh = C4::Context->dbh;
+
+my $op = $query->param('op'); #show the search form or execute the search
+
+my $format=$query->param('MARC');
+my ($template, $borrowernumber, $cookie);
+
+# get all the common search variables, 
+my @value=$query->param('value');
+my @kohafield=$query->param('kohafield');
+my @and_or=$query->param('and_or');
+my @relation=$query->param('relation');
+my $order=$query->param('order');
+my $reorder=$query->param('reorder');
+my $number_of_results=$query->param('number_of_results');
+my $zoom=$query->param('zoom');
+my $ascend=$query->param('asc');
+my $searchtype=$query->param('searchtype'); ## this is actual query type
+my $serverid=$query->param('serverid');
+$serverid=-1 unless($serverid eq "0"  || $serverid>0);
+my @marclist = $query->param('marclist');
+my $basename=$query->param('basename');
+# collect all the fields ...
+my %search;
+my @forminputs;		#this is for the links to navigate among the results
+my (@searchdesc, %hashdesc,$facetsdesc); 	#this is to show the description of the current search
+my @fields = ('value', 'kohafield', 'and_or', 'relation','order','barcode','biblionumber','itemnumber','asc','from','searchtype');
+
+###Collect all the marclist values coming from old Koha MARCdetails
+## Although we can not search on all marc fields- if any is matched in Zebra we can use it 
+my $sth=$dbh->prepare("Select kohafield from koha_attr where tagfield=? and tagsubfield=? and intrashow=1");
+foreach my $marc (@marclist) {
+		if ($marc) {
+		$sth->execute(substr($marc,0,3),substr($marc,3,1));
+			if ((my $kohafield)=$sth->fetchrow){
+			push @kohafield,$kohafield;
+			push @and_or,"\@or";
+			push @value, at value[0] if @kohafield>1;
+			push @relation ,"\@attr 5=1";
+			}
+		}
+}
+#### Now   normal search routine
+foreach my $field (@fields) {
+	$search{$field} = $query->param($field);
+	my @fieldvalue = $query->param($field);
+	foreach my $fvalue (@fieldvalue) {
+		push @forminputs, { field=>$field ,value=> $fvalue} unless ($field eq 'reorder');
+		
+	  }
+}
+## Build the query for facets as well
+ for (my $i=0;$i<@value;$i++){
+$facetsdesc.="&value=".$value[$i];
+$facetsdesc.="&kohafield=".$kohafield[$i];
+$facetsdesc.="&relation=".$relation[$i];
+$facetsdesc.="&and_or=".$and_or[$i];
+}
+$facetsdesc.="&order=".$order;
+$hashdesc{'query'} = join " , ", @value;
+push @searchdesc,\%hashdesc;
+
+
+############################################################################
+if ($op eq "do_search"){
+ 
+#this fields is just to allow the user come back to the search form with all the values  previously entered
+$search{'search_type'} = $query->param('search_type');# this is the panel type
+push @forminputs, {field => 'search_type', value => $search{'search_type'}};
+
+
+	($template, $borrowernumber, $cookie)
+		= get_template_and_user({template_name => "catalogue/searchresults.tmpl",
+					 query => $query,
+					 type => "intranet",
+					 authnotrequired => 1,
+	});
+
+	$search{'from'} = 'intranet';
+	$search{'borrowernumber'} = $borrowernumber;
+	$search{'remote_IP'} = $query->remote_addr();
+	$search{'remote_URL'} = $query->url(-query=>1);
+	$search{'searchdesc'} = \@searchdesc;
+	$template->param(FORMINPUTS => \@forminputs);
+	$template->param(reorder => $query->param('reorder'));
+	$template->param(facetsdesc=>$facetsdesc);
+	# do the searchs ....
+	 $number_of_results = 50 unless $number_of_results;
+	my $startfrom=$query->param('startfrom');
+	($startfrom) || ($startfrom=0);
+my ($count, at results,$facets);
+if ($serverid>0){
+ my $sth=$dbh->prepare("select * from online_databases where serverid=?");
+  $sth->execute($serverid);
+
+  my  $server=$sth->fetchrow_hashref ;
+
+my	$serverquery=$server->{search_string};
+	if ($server->{$kohafield[0]} ne ""){
+	$serverquery.=$server->{$kohafield[0]."_query"}.$value[0];
+	}else{
+	$serverquery.=$server->{"any_query"}.$value[0];
+	}
+print $query->redirect($serverquery);
+  
+}##serverid>0
+if ($serverid eq "0"){
+use ZOOM;
+my @oConnection;
+my @oResult;
+my $s=0;
+my $server;							
+my @serverhost;
+my @serverquery;
+my @query;							
+my @onlineloop;
+my $numberpending;
+my $even=1;			
+  my $sth=$dbh->prepare("select * from online_databases ");
+  $sth->execute();
+
+    while ($server=$sth->fetchrow_hashref) {
+	my $noconnection=0;
+	
+							
+	my $option1=new ZOOM::Options();
+	$option1->option(async=>1);
+	$option1->option('elementSetName', 'F');
+	$option1->option('databaseName',$server->{db})  ;
+	$option1->option('user',$server->{userid})  ;
+	$option1->option('password',$server->{password})  ;
+	 $oConnection[$s]=create ZOOM::Connection($option1);
+	$oConnection[$s]->connect($server->{host}, $server->{port});
+	$serverhost[$s]=$server->{server};
+	$serverquery[$s]=$server->{search_string};
+	if ($server->{$kohafield[0]} ne ""){
+	$serverquery[$s].=$server->{$kohafield[0]."_query"}.$value[0];
+	}else{
+	$serverquery[$s].=$server->{"any_query"}.$value[0];
+	}
+ $query[$s]=$server->{$kohafield[0]}." \"".$value[0]."\"";	
+
+	$s++;
+    }## while fetch
+
+ 
+my $nremaining = $s;
+my $firstresult=1;
+ for (my $z=0 ;$z<$s;$z++){
+$oResult[$z] = $oConnection[$z]->search_pqf($query[$z]);
+
+}
+AGAIN:
+ my $k;
+my $event;
+  while (($k = ZOOM::event(\@oConnection)) != 0) {
+	$event = $oConnection[$k-1]->last_event();
+# warn ("connection ", $k-1, ": event $event (", ZOOM::event_str($event), ")\n");
+	last if $event == ZOOM::Event::ZEND;
+   }
+if ($k != 0) {
+	$k--;
+#warn $serverhost[$k];
+	 my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
+   	if ($error) {
+	warn "$k $serverhost[$k] error $query[$k]: $errmsg ($error) $addinfo\n";
+	goto MAYBE_AGAIN;
+  	}
+	
+	my $numresults=$oResult[$k]->size() ;								
+ 									
+
+	if ($numresults>0){
+	
+		
+
+			my %row_data;
+ 	
+	$row_data{even} = $even;
+	$row_data{server} = $serverhost[$k];
+	$row_data{numresults} = $numresults;
+
+	$row_data{search_string} =$serverquery[$k];
+	
+	$even=!$even;
+	push (@onlineloop, \%row_data);
+
+						
+}# $numresults
+
+}# if $k !=0
+
+
+$numberpending=$nremaining-1;
+
+MAYBE_AGAIN:
+if (--$nremaining > 0) {
+    goto AGAIN;
+}
+$template->param(onlineloop=>\@onlineloop,);
+}##serverid==0
+if (!$zoom){
+## using sql search for barcode,biblionumber or itemnumber only useful for libraian interface
+	($count, @results) =sqlsearch($dbh,\%search);
+}else{
+my $sortorder=$order.$ascend if $order;
+ ($count,$facets, at results) =ZEBRAsearch_kohafields(\@kohafield,\@value, \@relation,$sortorder, \@and_or, 1,$reorder,$startfrom, $number_of_results,"intranet",$searchtype);
+}
+	if ( $count eq "error"){
+	$template->param(error =>1);
+	goto "show";
+	}
+	my $num = scalar(@results) - 1;
+if ( $count == 1){
+    # if its a barcode search by definition we will only have one result.
+    # And if we have a result
+    # lets jump straight to the detail.pl page
+	if ($format eq '1') {
+    print $query->redirect("/cgi-bin/koha/catalogue/MARCdetail.pl?type=intra&biblionumber=$results[0]->{'biblionumber'}");
+	}else{
+    print $query->redirect("/cgi-bin/koha/catalogue/detail.pl?type=intra&biblionumber=$results[0]->{'biblionumber'}");
+	}
+}
+	# sorting out which results to display.
+		# the total results searched
+	$template->param(numrecords => $count);
+	$template->param(FORMINPUTS => \@forminputs );
+	$template->param(searchdesc => \@searchdesc );
+if ($basename){
+# Printing to a csv file
+open(OUT,">:utf8" ,"$basename.csv") or die $!;
+#		print $query->header(-type => 'application/EXCEL',-charset=>"utf-8",
+#			-attachment=>"$basename.csv",
+#			-filename=>"$basename.csv" );
+#		
+		my $sep;
+		$sep =C4::Context->preference("delimiter");
+
+			print OUT "Title".$sep."Author".$sep."Issuecount";
+		print OUT "\n";
+# Table
+		foreach my $line ( @results) {
+		
+			print OUT $line->{title}.$sep.$line->{author}.$sep.$line->{totalissue};
+
+ 			print OUT "\n";
+	 	}
+close(OUT);
+    print $query->redirect("/cgi-bin/koha/catalogue/search.pl");
+
+}
+
+if ($serverid==-1){
+	# the result number to star to show
+	$template->param(startfrom => $startfrom);
+	$template->param(beginning => $startfrom+1);
+	# the result number to end to show
+	($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num+1)) : ($template->param(endat => $count));
+
+	
+ 	$template->param(SEARCH_RESULTS => \@results,
+			facets_loop => $facets,
+			);
+
+	#this is to show the images numbers to navigate among the results, if it has to show the number highlighted or not
+	my $numbers;
+	@$numbers = ();
+	my $pg = 1;
+	if (defined($query->param('pg'))) {
+		$pg = $query->param('pg');
+	}
+	my $start = 0;
+	
+	$start = ($pg - 1) * $number_of_results;
+	my $pages = ceil($count / $number_of_results);
+	my $total_pages = ceil($count / $number_of_results);
+
+	if ($pg > 1) {
+		my $url = $pg - 1;
+		push @$numbers, { number => "&lt;&lt;", , forminputs=>\@forminputs,
+					      highlight => 0 , 
+					      startfrom =>0, 
+					      pg => '1' };
+		push @$numbers, { number => "&lt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($url-1)*$number_of_results+1, 
+						  pg => $url };
+	}
+	my $current_ten = $pg / 10;
+	if ($current_ten == 0) {
+		 $current_ten = 0.1;           # In case it´s in ten = 0
+	} 
+	my $from = $current_ten * 10; # Calculate the initial page
+	my $end_ten = $from + 9;
+	my $to;
+	if ($pages > $end_ten) {
+		$to = $end_ten;
+	} else {
+		$to = $pages;
+	}
+	for (my $i = $from; $i <= $to ; $i++) {
+		if ($i == $pg) {   
+			if ($count > $number_of_results) {
+				push @$numbers, { number => $i, 
+								  highlight => 1 , forminputs=>\@forminputs,
+								  startfrom => ($i-1)*$number_of_results , 
+								  pg => $i };
+			}
+		} else {
+			push @$numbers, { number => $i, 
+							  highlight => 0 , forminputs=>\@forminputs,
+							  startfrom => ($i-1)*$number_of_results , 
+							  pg => $i };
+		}
+	}	        					
+	if ($pg < $pages) {
+		my $url = $pg + 1;
+		push @$numbers, { number => "&gt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($url-1)*$number_of_results, 
+						  pg => $url };
+		push @$numbers, { number => "&gt;&gt;", 
+						  highlight => 0 , forminputs=>\@forminputs,
+						  startfrom => ($total_pages-1)*$number_of_results, 
+						  pg => $total_pages};
+	}
+#	push @$numbers,{forminputs=>@forminputs};
+	$template->param(numbers =>$numbers,
+			);
+	#show the virtual shelves
+	#my $results = &GetShelfList($borrowernumber);
+	#$template->param(shelvescount => scalar(@{$results}));
+	#$template->param(shelves => $results);
+ 
+########
+if ($format eq '1') {
+	$template->param(script => "catalogue/MARCdetail.pl");
+}else{
+	$template->param(script => "catalogue/detail.pl");
+}
+}#serverid==-1
+}else{ ## No search yet
+($template, $borrowernumber, $cookie)
+		= get_template_and_user({template_name => "catalogue/search.tmpl",
+					query => $query,
+					type => "intranet",
+					authnotrequired => 1,
+				});
+#show kohafields
+	my $kohafield = $query->param('kohafield');
+	my ($fieldcount, at kohafields)=getkohafields();
+	foreach my $row (@kohafields) {
+		if ($kohafield eq $row->{'kohafield'}) {
+			$row->{'sel'} = 1;
+		}
+	}
+	$template->param(kohafields => \@kohafields);
+##show sorting fields
+my @sorts;
+ $order=$query->param('order');
+	foreach my $sort (@kohafields) {
+	    if ($sort->{sorts}){
+		push @sorts,$sort;
+		if ($order eq $sort->{'kohafield'}) {
+			$sort->{'sel'} = 1;
+		}
+	   }
+	}
+	$template->param(sorts => \@sorts);
+# load the branches
+my @branches = GetallBranches();
+$template->param(branchloop => \@branches,);
+
+# load the itemtypes 
+my $itemtypes=GetItemTypes();
+my (@item_type_loop);
+foreach my $thisitemtype (sort keys %$itemtypes) {
+    my %row =(itemtype => $thisitemtype,
+                 description => $itemtypes->{$thisitemtype}->{'description'},
+            );
+    push @item_type_loop, \%row;
+}
+##Show catalogues
+my $sth=$dbh->prepare("select serverid,server from online_databases");
+$sth->execute();
+my @serverloop;
+while (my $server=$sth->fetchrow_hashref) {
+my %temploop;
+$temploop{server}=$server->{server};
+$temploop{serverid}=$server->{serverid};
+
+push (@serverloop, \%temploop);
+}
+$sth->finish;
+$template->param(	servers => \@serverloop,);
+$template->param(itemtypeloop=>\@item_type_loop,);
+my $search_type = $query->param('search_type');
+	if ((!$search_type) || ($search_type eq 'zoom'))  {
+		$template->param(zoom_search => 1);
+	} else{
+		$template->param(sql_search => 1);
+	} 
+}
+
+show:
+output_html_with_http_headers $query, $cookie, $template->output();
+1;





More information about the Koha-cvs mailing list