X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=acqui%2Fneworderbiblio.pl;h=bc782afe46e89fb06581edff965e1e1b8ca1066e;hb=568f32606c2c9c247b2b477193a2d6814f738fa6;hp=d1efba0fb61f1a9a3f377052b031b4bad0b5adff;hpb=baf5ee015e45d8726c7b0abd0c8297ec50307ccb;p=koha.git diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl index d1efba0fb6..bc782afe46 100755 --- a/acqui/neworderbiblio.pl +++ b/acqui/neworderbiblio.pl @@ -4,6 +4,7 @@ #now script to do searching for acquisitions # Copyright 2000-2002 Katipo Communications +# Copyright 2008-2009 BibLibre SARL # # This file is part of Koha. # @@ -16,15 +17,16 @@ # 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 +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. =head1 NAME neworderbiblio.pl =head1 DESCRIPTION + this script allows to perform a new order from an existing record. =head1 CGI PARAMETERS @@ -34,18 +36,14 @@ this script allows to perform a new order from an existing record. =item search the title the librarian has typed to search an existing record. -=item type -To know if this script is called from intranet or from the opac. - -=item d +=item q the keyword the librarian has typed to search an existing record. =item author the author of the new record. -=item offset - =item num +the number of result per page to display =item booksellerid the id of the bookseller this script has to add an order. @@ -53,302 +51,95 @@ the id of the bookseller this script has to add an order. =item basketno the basket number to know on which basket this script have to add a new order. -=item sub -FIXME : is this param still used ? - =back =cut - use strict; +#use warnings; FIXME - Bug 2505 + use C4::Search; use CGI; -use C4::Output; -use C4::Bookseller; +use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Biblio; -use HTML::Template; use C4::Auth; -use C4::Interface::CGI::Output; - - -#use Data::Dumper; +use C4::Output; +use C4::Koha; +use C4::Members qw/ GetMember /; +use C4::Budgets qw/ GetBudgetHierarchy /; -my $env; my $input = new CGI; -#print $input->header; - -#whether it is called from the opac of the intranet -my $type = $input->param('type'); -if ( $type eq '' ) { - $type = 'intra'; -} - -#print $input->dump; -my $blah; -my %search; - -#build hash of users input -my $title = $input->param('search'); -$search{'title'} = $title; -my $keyword = $input->param('d'); -$search{'keyword'} = $keyword; -my $author = $input->param('author'); -$search{'author'} = $author; - -my @results; -my $offset = $input->param('offset'); - -#default value for offset -my $offset = 0 unless $offset; - -my $num = $input->param('num'); - -#default value for num -my $num = 10 unless $num; - -my $donation; -my $booksellerid = $input->param('booksellerid'); -if ( $booksellerid == 72 ) { - $donation = 'yes'; -} -my $basketno = $input->param('basketno'); -my $sub = $input->param('sub'); +#getting all CGI params into a hash. +my $params = $input->Vars; -#print $sub; -my @booksellers = GetBookSeller($booksellerid); -my $count = scalar @booksellers; +my $page = $params->{'page'} || 1; +my $query = $params->{'q'}; +my $results_per_page = $params->{'num'} || 20; +my $booksellerid = $params->{'booksellerid'}; +my $basketno = $params->{'basketno'}; +my $sub = $params->{'sub'}; +my $bookseller = GetBookSellerFromId($booksellerid); +# getting the template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "acqui/neworderbiblio.tmpl", query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => { order => 1 }, - debug => 1, + flagsrequired => { acquisition => 'order_manage' }, } ); -#my $template = gettemplate("acqui/neworderbiblio.tmpl"); -#print startpage(); -#print startmenu('acquisitions'); -my $invalidsearch; +# Searching the catalog. -if ( $keyword ne '' ) { - ( $count, @results ) = - KeywordSearch( undef, 'intra', \%search, $num, $offset ); -} -elsif ( $search{'front'} ne '' ) { - ( $count, @results ) = - FrontSearch( undef, 'intra', \%search, $num, $offset ); -} -elsif ( $search{'author'} || $search{'title'} ) { - ( $count, @results ) = CatSearch( undef, 'loose', \%search, $num, $offset ); -} -else { - $invalidsearch = 1; -} - -my @loopsearch; + # find results +my ( $error, $marcresults, $total_hits ) = SimpleSearch( $query, $results_per_page * ( $page - 1 ), $results_per_page ); -while ( my ( $key, $value ) = each %search ) { - if ( $value ne '' ) { - my %linesearch; - $value =~ s/\\//g; - $linesearch{key} = $key; - $linesearch{value} = $value; - push( @loopsearch, \%linesearch ); - } +if (defined $error) { + $template->param( + query_error => $error, + basketno => $basketno, + booksellerid => $bookseller->{'id'}, + name => $bookseller->{'name'}, + ); + output_html_with_http_headers $input, $cookie, $template->output; + exit; } -my $offset2 = $num + $offset; -my $dispnum = $offset + 1; -if ( $offset2 > $count ) { - $offset2 = $count; -} +my @results; -my $count2 = @results; -if ( $keyword ne '' && $offset > 0 ) { - $count2 = $count - $offset; - if ( $count2 > 10 ) { - $count2 = 10; - } -} -my $i = 0; -my $colour = 0; - -my @loopresult; - -while ( $i < $count2 ) { - my %lineres; - my $toggle; - - my $result = $results[$i]; - $result->{'title'} =~ s/\`/\\\'/g; - my $title2 = $result->{'title'}; - my $author2 = $result->{'author'}; - $author2 =~ s/ /%20/g; - $title2 =~ s/ /%20/g; - $title2 =~ s/\#/\&\#x23;/g; - $title2 =~ s/\"/\"\;/g; - - my $itemcount; - my $location = ''; - my $location_only = ''; - my $word = $result->{'author'}; - $word =~ s/([a-z]) +([a-z])/$1%20$2/ig; - $word =~ s/ //g; - $word =~ s/ /%20/g; - $word =~ s/\,/\,%20/g; - $word =~ s/\n//g; - $lineres{word} = $word; - $lineres{type} = $type; - - my ( $counts, $branchcounts ) = - C4::Search::itemcount( $env, $result->{'biblionumber'}, $type ); - - if ( $counts->{'nacount'} > 0 ) { - $location .= "On Loan"; - if ( $counts->{'nacount'} > 1 ) { - $location .= "=($counts->{'nacount'})"; - } - $location .= " "; - $lineres{'on-loan-p'} = 1; - } - foreach my $key ( keys %$branchcounts ) { - if ( $branchcounts->{$key} > 0 ) { - $location .= $key; - $location_only .= $key; - - if ( $branchcounts->{$key} > 1 ) { - $location .= "=$branchcounts->{$key}"; - $location_only .= "=$branchcounts->{$key}"; - } - $location .= " "; - $location_only .= " "; - } - } - if ( $counts->{'lostcount'} > 0 ) { - $location .= "Lost"; - if ( $counts->{'lostcount'} > 1 ) { - $location .= "=($counts->{'lostcount'})"; - } - $location .= " "; - $lineres{'lost-p'} = 1; - } - if ( $counts->{'mending'} > 0 ) { - $location .= "Mending"; - if ( $counts->{'mending'} > 1 ) { - $location .= "=($counts->{'mending'})"; - } - $location .= " "; - $lineres{'mending-p'} = 1; - } - if ( $counts->{'transit'} > 0 ) { - $location .= "In Transit"; - if ( $counts->{'transit'} > 1 ) { - $location .= "=($counts->{'transit'})"; - } - $location .= " "; - $lineres{'in-transit-p'} = 1; - } - if ( $colour eq 0 ) { - $toggle = 1; - $colour = 1; - } - else { - $colour = 0; - $toggle = 0; - } - $lineres{author2} = $author2; - $lineres{title2} = $title2; - $lineres{copyright} = $result->{'copyrightdate'}; - $lineres{booksellerid} = $booksellerid; - $lineres{basketno} = $basketno; - $lineres{sub} = $sub; - $lineres{biblionumber} = $result->{biblionumber}; - $lineres{title} = $result->{title}; - $lineres{author} = $result->{author}; - $lineres{toggle} = $toggle; - $lineres{itemcount} = $counts->{'count'}; - $lineres{location} = $location; - $lineres{'location-only'} = $location_only; - - # lets get a list on existing orders for all bibitems. - my @bibitems = GetBiblioItemByBiblioNumber( $result->{biblionumber} ); - my $count1 = scalar @bibitems; - my $order, my $ordernumber; - - my $i1 = 0; - - my @ordernumbers; - foreach my $bibitem (@bibitems) { - my $ordernumber = GetOrderNumber($result->{biblionumber},$bibitem->{biblioitemnumber}); - $order = &GetOrder($ordernumber); - - #only show order if its current; - my %order; - $order{'number'} = $ordernumber; - if ( ( !$order->{cancelledby} ) - && ( $order->{quantityreceived} < $order->{quantity} ) ) - { - push @ordernumbers, \%order; - } - } - $lineres{existingorder} = \@ordernumbers; - push( @loopresult, \%lineres ); - $i++; -} +foreach my $result ( @{$marcresults} ) { + my $marcrecord = MARC::File::USMARC::decode( $result ); + my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' ); + + $biblio->{booksellerid} = $booksellerid; + push @results, $biblio; -my $prevoffset = $offset - $num; -my $offsetprev = 1; -if ( $prevoffset < 0 ) { - $offsetprev = 0; } -$offset = $num + $offset; - -my @numbers = (); -if ( $count > 10 ) { - for ( my $i = 0 ; $i < ( $count / $num ) ; $i++ ) { - my $highlight = 0; - my $numberoffset = $i * $num; - if ( ( $numberoffset + $num ) == $offset ) { $highlight = 1 } - - # warn "I $i | N $num | O $offset | NO $numberoffset | H $highlight"; - push @numbers, - { - number => ( $i + 1 ), - highlight => $highlight, - numberoffset => $numberoffset - }; +my $borrower= GetMember('borrowernumber' => $loggedinuser); +my $budgets = GetBudgetHierarchy(q{},$borrower->{branchcode},$borrower->{borrowernumber}); +my $has_budgets = 0; +foreach my $r (@{$budgets}) { + if (!defined $r->{budget_amount} || $r->{budget_amount} == 0) { + next; } + $has_budgets = 1; + last; } $template->param( - bookselname => $booksellers[0]->{'name'}, - booksellerid => $booksellerid, - basketno => $basketno, - parsub => $sub, - count => $count, - offset2 => $offset2, - dispnum => $dispnum, - offsetover => ( $offset < $count ), - num => $num, - offset => $prevoffset, - offsetprev => $offsetprev, - type => $type, - title => $title, - author => $author, - donation => $donation, - loopsearch => \@loopsearch, - loopresult => \@loopresult, - numbers => \@numbers, - invalidsearch => $invalidsearch, - 'use-location-flags-p' => 1 + has_budgets => $has_budgets, + basketno => $basketno, + booksellerid => $bookseller->{'id'}, + name => $bookseller->{'name'}, + resultsloop => \@results, + total => $total_hits, + query => $query, + pagination_bar => pagination_bar( "$ENV{'SCRIPT_NAME'}?q=$query&booksellerid=$booksellerid&basketno=$basketno&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ), ); +# BUILD THE TEMPLATE output_html_with_http_headers $input, $cookie, $template->output; -