Reimplement fix for bug 5557 - Link to logs for user with view_system_logs permission
[koha.git] / reports / itemslost.pl
blob547c187e8d9f85d6506ef1ddcaf42c23cfdd1417
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
19 =head1 itemslost
21 This script displays lost items.
23 =cut
25 use strict;
26 use warnings;
28 use CGI;
29 use C4::Auth;
30 use C4::Output;
31 use C4::Biblio;
32 use C4::Items;
33 use C4::Koha; # GetItemTypes
34 use C4::Branch; # GetBranches
35 use C4::Dates qw/format_date/;
37 my $query = new CGI;
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40 template_name => "reports/itemslost.tmpl",
41 query => $query,
42 type => "intranet",
43 authnotrequired => 0,
44 flagsrequired => { reports => '*' },
45 debug => 1,
49 my $params = $query->Vars;
50 my $get_items = $params->{'get_items'};
52 if ( $get_items ) {
53 my $orderbyfilter = $params->{'orderbyfilter'} || undef;
54 my $branchfilter = $params->{'branchfilter'} || undef;
55 my $barcodefilter = $params->{'barcodefilter'} || undef;
56 my $itemtypesfilter = $params->{'itemtypesfilter'} || undef;
57 my $loststatusfilter = $params->{'loststatusfilter'} || undef;
59 my %where;
60 $where{'homebranch'} = $branchfilter if defined $branchfilter;
61 $where{'barcode'} = $barcodefilter if defined $barcodefilter;
62 $where{'authorised_value'} = $loststatusfilter if defined $loststatusfilter;
64 my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype";
65 $where{$itype} = $itemtypesfilter if defined $itemtypesfilter;
67 my $items = GetLostItems( \%where, $orderbyfilter );
68 foreach my $it (@$items) {
69 $it->{'datelastseen'} = format_date($it->{'datelastseen'});
71 $template->param(
72 total => scalar @$items,
73 itemsloop => $items,
74 get_items => $get_items,
75 itype_level => C4::Context->preference('item-level_itypes'),
79 # getting all branches.
80 #my $branches = GetBranches;
81 #my $branch = C4::Context->userenv->{"branchname"};
83 # getting all itemtypes
84 my $itemtypes = &GetItemTypes();
85 my @itemtypesloop;
86 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description}} keys %$itemtypes ) {
87 my %row = (
88 value => $thisitemtype,
89 description => $itemtypes->{$thisitemtype}->{'description'},
91 push @itemtypesloop, \%row;
94 # get lost statuses
95 my $lost_status_loop = C4::Koha::GetAuthorisedValues( 'LOST' );
97 $template->param( branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
98 itemtypeloop => \@itemtypesloop,
99 loststatusloop => $lost_status_loop,
102 # writing the template
103 output_html_with_http_headers $query, $cookie, $template->output;