koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/catalogue moredetail.pl catalogue-search.pl


From: Tumer Garip
Subject: [Koha-cvs] koha/catalogue moredetail.pl catalogue-search.pl
Date: Fri, 01 Sep 2006 22:25:05 +0000

CVSROOT:        /sources/koha
Module name:    koha
Changes by:     Tumer Garip <tgarip1957>        06/09/01 22:25:05

Modified files:
        catalogue      : moredetail.pl 
Added files:
        catalogue      : catalogue-search.pl 

Log message:
        A basic search script catalogue-search.pl demonstrates the use of 
koha_attr table to create PQF free searches

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/moredetail.pl?cvsroot=koha&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/koha/catalogue/catalogue-search.pl?cvsroot=koha&rev=1.1

Patches:
Index: moredetail.pl
===================================================================
RCS file: /sources/koha/koha/catalogue/moredetail.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- moredetail.pl       1 Aug 2006 08:50:55 -0000       1.4
+++ moredetail.pl       1 Sep 2006 22:25:05 -0000       1.5
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # NOTE: Use standard 8-space tabs for this file (indents are 4 spaces)
 
-# $Id: moredetail.pl,v 1.4 2006/08/01 08:50:55 toins Exp $
+# $Id: moredetail.pl,v 1.5 2006/09/01 22:25:05 tgarip1957 Exp $
 
 # Copyright 2000-2003 Katipo Communications
 #
@@ -20,7 +20,6 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-use HTML::Template;
 use strict;
 require Exporter;
 use C4::Koha;
@@ -31,16 +30,17 @@
 use C4::Auth;
 use C4::Interface::CGI::Output;
 use C4::Date;
-
+use C4::Context;
+use C4::Biblio;
+use C4::Accounts2;
+use C4::Circulation::Circ2;
+use MARC::Record;
+my $dbh=C4::Context->dbh;
 my $query=new CGI;
 
-# FIXME  subject is not exported to the template?
-my $subject=$query->param('subject');
 
-# if its a subject we need to use the subject.tmpl
 my ($template, $loggedinuser, $cookie) = get_template_and_user({
-       template_name   => ($subject? 'catalogue/subject.tmpl':
-                                     'catalogue/moredetail.tmpl'),
+       template_name   => ( 'catalogue/moredetail.tmpl'),
        query           => $query,
        type            => "intranet",
        authnotrequired => 0,
@@ -48,12 +48,17 @@
     });
 
 # 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 $biblionumber=$query->param('bib');
 my $title=$query->param('title');
-my $bi=$query->param('bi');
-
-my $data=bibitemdata($bi);
+my $biblionumber=$query->param('biblionumber');
+my ($record,)=MARCgetbiblio($dbh,$biblionumber);
+my $data=MARCmarc2koha($dbh,$record,"biblios");
 my $dewey = $data->{'dewey'};
 # FIXME Dewey is a string, not a number, & we should use a function
 $dewey =~ s/0+$//;
@@ -68,12 +73,82 @@
 
 my @results;
 
-my (@items)=itemissues($bi);
+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;
+  }
+}
+if ($flag != 0 && $override ne "yes"){
+
+  }else {
+   ##UPDATE here
+my $sth=$dbh->prepare("update items set itemlost=? ,wthdrawn=? where 
itemnumber=?");
+$sth->execute($lost,$withdrawn,$itemnumber);
+$sth->finish;
+MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'wthdrawn',$withdrawn,1);
+MARCmoditemonefield($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;
+    if ($data->{'borrowernumber'} ne '') {
+      #item on issue add replacement cost to borrowers record
+      my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
+      my $item=getiteminformation($env, $itemnumber);
+      my $sth2=$dbh->prepare("Insert into accountlines
+      
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
+      values
+      (?,?,now(),?,?,'L',?,?)");
+      
$sth2->execute($data->{'borrowernumber'},$accountno,$item->{'replacementprice'},
+      "Lost Item $item->{'title'} $item->{'barcode'}",
+      $item->{'replacementprice'},$itemnumber);
+      $sth2->finish;
+    }
+    }
+       if ($flag==1){
+       foreach my $res ($resrec){
+       
C4::Reserves2::CancelReseve(undef,$res->{itemnumber},$res->{borrowernumber});
+       }
+       }
+    
+  }
+}
+my @itemrecords=MARCgetallitems($dbh,$biblionumber);
+foreach my $itemrecord (@itemrecords){
+
+my $items = MARCmarc2koha($dbh,$itemrecord,"holdings");
+$items->{itemtype}=$data->{itemtype};
+$items->{biblionumber}=$biblionumber;
+$items=itemissues($dbh,$items,$biblionumber);
+push @items,$items;
+}
 my address@hidden;
 $data->{'count'}=$count;
-
-my $ordernum = GetOrderNumber($biblionumber,$bi);
-my $order = GetOrder($ordernum);
+my ($order,$ordernum)=GetOrder($biblionumber,$barcode);
 
 my $env;
 $env->{itemcount}=1;
@@ -88,13 +163,14 @@
     $item->{'ordernumber'} = $ordernum;
     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
 
-    if ($item->{'date_due'} eq 'Available'){
-               $item->{'issue'}= 0;
-    } else {
+    if ($item->{'date_due'} gt '0000-00-00'){
                $item->{'date_due'} = format_date($item->{'date_due'});
-               $item->{'issue'}= 1;
-               $item->{'borrowernumber'} = $item->{'borrower'};
+$item->{'issue'}= 1;
+               $item->{'borrowernumber'} = $item->{'borrowernumber'};
                $item->{'cardnumber'} = $item->{'card'};
+                       
+    } else {
+       $item->{'issue'}= 0;
     }
 }
 

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 1 Sep 2006 22:25:05 -0000       1.1
@@ -0,0 +1,228 @@
+#!/usr/bin/perl
+use strict;
+require Exporter;
+use CGI;
+#use C4::Interface::CGI::KOHACGI;
+use C4::Search;
+use C4::Auth;
+use C4::Interface::CGI::Output;
+use C4::Biblio;
+use C4::Koha;
+use POSIX qw(ceil floor);
+
+my $query = new CGI;
+my $dbh = C4::Context->dbh;
+$query->charset('UTF8');
+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');
+# collect all the fields ...
+my %search;
+my @forminputs;                #this is for the links to navigate among the 
results
+my (@searchdesc, %hashdesc);   #this is to show the description of the current 
search
+my @fields = ('value', 'kohafield', 'and_or', 
'relation','order','barcode','biblionumber','itemnumber','asc','from');
+
+foreach my $field (@fields) {
+       $search{$field} = $query->param($field);
+       if ($search{$field}) {
+               push @forminputs, { field=>$field ,value=> $search{$field}} 
unless ($field eq 'reorder');
+               }
+}
+
+
+$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');
+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'} = address@hidden;
+       $template->param(FORMINPUTS => address@hidden);
+       $template->param(reorder => $query->param('reorder'));
+
+       # do the searchs ....
+        $number_of_results = 10 unless $number_of_results;
+       my $startfrom=$query->param('startfrom');
+       ($startfrom) || ($startfrom=0);
+my ($count,@results);
+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,@results) =ZEBRAsearch_kohafields(address@hidden,address@hidden, 
address@hidden,$sortorder, address@hidden, 1,$reorder,$startfrom, 
$number_of_results,"intranet");
+}
+       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 result number to star to show
+       $template->param(starting => $startfrom+$number_of_results);
+       $template->param(endinging => $startfrom+1);
+       $template->param(startfrom => $startfrom+1);
+       # the result number to end to show
+       ($startfrom+$num<=$count) ? ($template->param(endat => 
$startfrom+$num+1)) : ($template->param(endat => $count));
+       # the total results searched
+       $template->param(numrecords => $count);
+
+       $template->param(searchdesc => address@hidden );
+       $template->param(SEARCH_RESULTS => address@hidden);
+
+       #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;", 
+                                             highlight => 0 , 
+                                             startfrom => 0, 
+                                             pg => '1' };
+               push @$numbers, { number => "&lt;", 
+                                                 highlight => 0 , 
forminputs=>address@hidden,
+                                                 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=>address@hidden,
+                                                                 startfrom => 
($i-1)*$number_of_results , 
+                                                                 pg => $i };
+                       }
+               } else {
+                       push @$numbers, { number => $i, 
+                                                         highlight => 0 , 
forminputs=>address@hidden,
+                                                         startfrom => 
($i-1)*$number_of_results , 
+                                                         pg => $i };
+               }
+       }                                                       
+       if ($pg < $pages) {
+               my $url = $pg + 1;
+               push @$numbers, { number => "&gt;", 
+                                                 highlight => 0 , 
forminputs=>address@hidden,
+                                                 startfrom => 
($url-1)*$number_of_results, 
+                                                 pg => $url };
+               push @$numbers, { number => "&gt;&gt;", 
+                                                 highlight => 0 , 
forminputs=>address@hidden,
+                                                 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");
+}
+
+}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,@kohafields)=getkohafields();
+       foreach my $row (@kohafields) {
+               if ($kohafield eq $row->{'marctokoha'}) {
+                       $row->{'sel'} = 1;
+               }
+       }
+       $template->param(kohafields => address@hidden);
+##show sorting fields
+my @sorts;
+ $order=$query->param('order');
+       foreach my $sort (@kohafields) {
+           if ($sort->{sorts}){
+               push @sorts,$sort;
+               if ($order eq $sort->{'marctokoha'}) {
+                       $sort->{'sel'} = 1;
+               }
+          }
+       }
+       $template->param(sorts => address@hidden);
+
+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();
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]