From 48ee1dcb3f835fb8250bcdd781085521411e6c26 Mon Sep 17 00:00:00 2001 From: Ian Walls Date: Mon, 28 Mar 2011 10:21:02 -0400 Subject: [PATCH] Bug 5547: Hide Lost Items dev Adds a Hide Lost Items option to the staff client, as detailed in the enhancement request at http://wiki.koha-community.org/wiki/Hidelostitems_option_for_the_staff_client_RFC Minor edits: Whitespace Signed-off-by: Owen Leonard Signed-off-by: Chris Cormack --- C4/Members.pm | 21 ++++++++++++++++ C4/Search.pm | 4 +++- admin/categorie.pl | 15 +++++++----- catalogue/detail.pl | 16 ++++++++++--- catalogue/moredetail.pl | 24 +++++++++++++++---- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 ++++++ .../prog/en/modules/admin/categorie.tmpl | 12 ++++++++++ .../prog/en/modules/catalogue/detail.tmpl | 7 +++++- .../prog/en/modules/catalogue/moredetail.tmpl | 3 ++- .../prog/en/modules/reserve/request.tmpl | 8 ++++++- reserve/request.pl | 9 ++++++- 12 files changed, 108 insertions(+), 19 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index ace939da2b..9fdb357664 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -70,6 +70,8 @@ BEGIN { &PutPatronImage &RmPatronImage + &GetHideLostItemsPreference + &IsMemberBlocked &GetMemberAccountRecords &GetBorNotifyAcctRecord @@ -1807,6 +1809,25 @@ sub RmPatronImage { return $dberror; } +=head2 GetHideLostItemsPreference + + $hidelostitemspref = &GetHideLostItemsPreference($borrowernumber); + +Returns the HideLostItems preference for the patron category of the supplied borrowernumber +C<&$hidelostitemspref>return value of function, 0 or 1 + +=cut + +sub GetHideLostItemsPreference { + my ($borrowernumber) = @_; + my $dbh = C4::Context->dbh; + my $query = "SELECT hidelostitems FROM borrowers,categories WHERE borrowers.categorycode = categories.categorycode AND borrowernumber = ?"; + my $sth = $dbh->prepare($query); + $sth->execute($borrowernumber); + my $hidelostitems = $sth->fetchrow; + return $hidelostitems; +} + =head2 GetRoadTypeDetails (OUEST-PROVENCE) ($roadtype) = &GetRoadTypeDetails($roadtypeid); diff --git a/C4/Search.pm b/C4/Search.pm index f970caf5c2..35f016665a 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -25,6 +25,7 @@ use Lingua::Stem; use C4::Search::PazPar2; use XML::Simple; use C4::Dates qw(format_date); +use C4::Members qw(GetHideLostItemsPreference); use C4::XSLT; use C4::Branch; use C4::Reserves; # CheckReserves @@ -1593,7 +1594,8 @@ sub searchResults { my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber}; # For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item - if ( $item->{onloan} ) { + my $userenv = C4::Context->userenv; + if ( $item->{onloan} && !(C4::Members::GetHideLostItemsPreference($userenv->{'number'}) && $item->{itemlost}) ) { $onloan_count++; my $key = $prefix . $item->{onloan} . $item->{barcode}; $onloan_items->{$key}->{due_date} = format_date($item->{onloan}); diff --git a/admin/categorie.pl b/admin/categorie.pl index 4a5d68390c..d0211fdb03 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -92,7 +92,7 @@ if ($op eq 'add_form') { my $data; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); + my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); $sth->execute($categorycode); $data=$sth->fetchrow_hashref; $sth->finish; @@ -109,6 +109,7 @@ if ($op eq 'add_form') { overduenoticerequired => $data->{'overduenoticerequired'}, issuelimit => $data->{'issuelimit'}, reservefee => sprintf("%.2f",$data->{'reservefee'}), + hidelostitems => $data->{'hidelostitems'}, category_type => $data->{'category_type'}, DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), "type_".$data->{'category_type'} => 1, @@ -128,12 +129,12 @@ if ($op eq 'add_form') { } if ($is_a_modif) { - my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); - $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type','categorycode')); + my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); + $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode')); $sth->finish; } else { - my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?)"); - $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type')); + my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?)"); + $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type')); $sth->finish; } if (C4::Context->preference('EnhancedMessagingPreferences')) { @@ -156,7 +157,7 @@ if ($op eq 'add_form') { $sth->finish; $template->param(total => $total->{'total'}); - my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); + my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); $sth2->execute($categorycode); my $data=$sth2->fetchrow_hashref; $sth2->finish; @@ -173,6 +174,7 @@ if ($op eq 'add_form') { overduenoticerequired => $data->{'overduenoticerequired'}, issuelimit => $data->{'issuelimit'}, reservefee => sprintf("%.2f",$data->{'reservefee'}), + hidelostitems => $data->{'hidelostitems'}, category_type => $data->{'category_type'}, ); # END $OP eq DELETE_CONFIRM @@ -205,6 +207,7 @@ if ($op eq 'add_form') { overduenoticerequired => $results->[$i]{'overduenoticerequired'}, issuelimit => $results->[$i]{'issuelimit'}, reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), + hidelostitems => $results->[$i]{'hidelostitems'}, category_type => $results->[$i]{'category_type'}, "type_".$results->[$i]{'category_type'} => 1); if (C4::Context->preference('EnhancedMessagingPreferences')) { diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 3d42326fc3..5542163b17 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -64,6 +64,8 @@ if($query->cookie("holdfor")){ my $biblionumber = $query->param('biblionumber'); my $fw = GetFrameworkCode($biblionumber); +my $showallitems = $query->param('showallitems'); + ## get notes and subjects from MARC record my $marcflavour = C4::Context->preference("marcflavour"); my $record = GetMarcBiblio($biblionumber); @@ -109,8 +111,12 @@ my $branches = GetBranches(); my $itemtypes = GetItemTypes(); my $dbh = C4::Context->dbh; -# change back when ive fixed request.pl -my @items = &GetItemsInfo( $biblionumber, 'intra' ); +# 'intra' param included, even though it's not respected in GetItemsInfo currently +my @all_items= GetItemsInfo($biblionumber, 'intra'); +my @items; +for my $itm (@all_items) { + push @items, $itm unless ( $itm->{itemlost} && GetHideLostItemsPreference($borrowernumber) && !$showallitems); +} my $dat = &GetBiblioData($biblionumber); # get count of holds @@ -141,7 +147,11 @@ foreach my $subscription (@subscriptions) { if ( defined $dat->{'itemtype'} ) { $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }{imageurl} ); } -$dat->{'count'} = scalar @items; + +$dat->{'count'} = scalar @all_items; +$dat->{'showncount'} = scalar @items; +$dat->{'hiddencount'} = scalar @all_items - scalar @items; + my $shelflocations = GetKohaAuthorisedValues('items.location', $fw); my $collections = GetKohaAuthorisedValues('items.ccode' , $fw); my (@itemloop, %itemfields); diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 054229f397..d848188ef8 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -34,6 +34,7 @@ use C4::Dates qw/format_date/; use C4::Circulation; # to use itemissues use C4::Members; # to use GetMember use C4::Search; # enabled_staff_search_views +use C4::Members qw/GetHideLostItemsPreference/; my $query=new CGI; @@ -66,8 +67,10 @@ my $biblionumber=$query->param('biblionumber'); my $title=$query->param('title'); my $bi=$query->param('bi'); $bi = $biblionumber unless $bi; +my $itemnumber = $query->param('itemnumber'); my $data=GetBiblioData($biblionumber); my $dewey = $data->{'dewey'}; +my $showallitems = $query->param('showallitems'); #coping with subscriptions my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); @@ -85,16 +88,27 @@ my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); my @results; my $fw = GetFrameworkCode($biblionumber); -my @items= GetItemsInfo($biblionumber); -my $count=@items; -$data->{'count'}=$count; +my @all_items= GetItemsInfo($biblionumber); +my @items; +for my $itm (@all_items) { + push @items, $itm unless ( $itm->{itemlost} && + GetHideLostItemsPreference($loggedinuser) && + !$showallitems && + ($itemnumber != $itm->{itemnumber})); +} + +my $totalcount=@all_items; +my $showncount=@items; +my $hiddencount = $totalcount - $showncount; +$data->{'count'}=$totalcount; +$data->{'showncount'}=$showncount; +$data->{'hiddencount'}=$hiddencount; # can be zero my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw); my $itemtypes = GetItemTypes; $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'}; $results[0]=$data; -my $itemnumber; ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items); foreach my $item (@items){ $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw); @@ -144,7 +158,7 @@ $template->param(loggedinuser => $loggedinuser); $template->param(biblionumber => $biblionumber); $template->param(biblioitemnumber => $bi); $template->param(itemnumber => $itemnumber); -$template->param(ONLY_ONE => 1) if ( $itemnumber && $count != @items ); +$template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items ); $template->param(z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber))); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index a62e07c9fb..b9e4df6316 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -420,6 +420,7 @@ CREATE TABLE `categories` ( `overduenoticerequired` tinyint(1) default NULL, `issuelimit` smallint(6) default NULL, `reservefee` decimal(28,6) default NULL, + `hidelostitems` tinyint(1) NOT NULL default '0' `category_type` varchar(1) NOT NULL default 'A', PRIMARY KEY (`categorycode`), UNIQUE KEY `categorycode` (`categorycode`) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 6528a2a49b..bace1399cc 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4141,6 +4141,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = '3.03.00.XXX'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `categories` ADD `hidelostitems` tinyint(1) NOT NULL default '0' AFTER `reservefee`"); + print "Upgrade to $DBversion done (Add hidelostitems preference to borrower categories)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl index ba9e468b14..52e8657ae8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl @@ -151,6 +151,15 @@ +
  •  
  • " />
  •