Bug 18398: Update C4::Message enqueue to use $patron->notice_email_address
[koha-ffzg.git] / mainpage.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright Paul Poulain 2002
6 # Parts Copyright Liblime 2007
7 # Copyright (C) 2013  Mark Tompsett
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Koha;
27 use C4::Tags qw( get_count_by_tag_status );
28 use Koha::AdditionalContents;
29 use Koha::Patron::Modifications;
30 use Koha::Patron::Discharge;
31 use Koha::Reviews;
32 use Koha::ArticleRequests;
33 use Koha::BiblioFrameworks;
34 use Koha::ProblemReports;
35 use Koha::Quotes;
36 use Koha::Suggestions;
37 use Koha::BackgroundJobs;
38 use Koha::CurbsidePickups;
39 use Koha::Tickets;
40
41 my $query = CGI->new;
42
43 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
44     {
45         template_name   => "intranet-main.tt",
46         query           => $query,
47         type            => "intranet",
48         flagsrequired   => { catalogue => 1, },
49     }
50 );
51
52 my $logged_in_user = Koha::Patrons->find($loggedinuser);
53
54 # Checking if there is a Fast Cataloging Framework
55 $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
56
57 my $homebranch;
58 if (C4::Context->userenv) {
59     $homebranch = C4::Context->userenv->{'branch'};
60 }
61 my $koha_news = Koha::AdditionalContents->search_for_display(
62     {
63         category   => 'news',
64         location   => [ 'staff_only', 'staff_and_opac' ],
65         lang       => $template->lang,
66         library_id => $homebranch
67     }
68 );
69
70 $template->param(
71     koha_news   => $koha_news,
72     daily_quote => Koha::Quotes->get_daily_quote(),
73 );
74
75 my $branch =
76   (      C4::Context->preference("IndependentBranchesPatronModifications")
77       || C4::Context->preference("IndependentBranches") )
78   && !$flags->{'superlibrarian'}
79   ? C4::Context->userenv()->{'branch'}
80   : undef;
81
82 my $pendingcomments    = Koha::Reviews->search_limited({ approved => 0 })->count;
83 my $pendingtags        = get_count_by_tag_status(0);
84
85 # Get current branch count and total viewable count, if they don't match then pass
86 # both to template
87
88 if( C4::Context->only_my_library ){
89     my $local_pendingsuggestions_count = Koha::Suggestions->search({ status => "ASKED", branchcode => C4::Context->userenv()->{'branch'} })->count();
90     $template->param( pendingsuggestions => $local_pendingsuggestions_count );
91 } else {
92     my $pendingsuggestions = Koha::Suggestions->search({ status => "ASKED" });
93     my $local_pendingsuggestions_count = $pendingsuggestions->search({ 'me.branchcode' => C4::Context->userenv()->{'branch'} })->count();
94     my $pendingsuggestions_count = $pendingsuggestions->count();
95     $template->param(
96         all_pendingsuggestions => $pendingsuggestions_count != $local_pendingsuggestions_count ? $pendingsuggestions_count : 0,
97         pendingsuggestions => $local_pendingsuggestions_count
98     );
99 }
100
101 my $pending_borrower_modifications = Koha::Patron::Modifications->pending_count( $branch );
102 my $pending_discharge_requests = Koha::Patron::Discharge::count({ pending => 1 });
103 my $pending_article_requests = Koha::ArticleRequests->search_limited(
104     {
105         status => Koha::ArticleRequest::Status::Requested,
106         $branch ? ( 'me.branchcode' => $branch ) : (),
107     }
108 )->count;
109 my $pending_problem_reports = Koha::ProblemReports->search({ status => 'New' });
110
111 if ( C4::Context->preference('OpacCatalogConcerns') || C4::Context->preference('CatalogConcerns') ) {
112     my $pending_biblio_tickets = Koha::Tickets->search(
113         {
114             resolved_date => undef,
115             biblio_id     => { '!=' => undef }
116         }
117     );
118     $template->param(
119         pending_biblio_tickets => $pending_biblio_tickets->count );
120 }
121
122 unless ( $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ) ) {
123     my $already_ran_jobs = Koha::BackgroundJobs->search(
124         { borrowernumber => $logged_in_user->borrowernumber } )->count ? 1 : 0;
125     $template->param( already_ran_jobs => $already_ran_jobs );
126 }
127
128 if ( C4::Context->preference('CurbsidePickup') ) {
129     $template->param(
130         new_curbside_pickups => Koha::CurbsidePickups->search(
131             {
132                 branchcode                => $homebranch,
133             }
134         )->filter_by_to_be_staged->filter_by_scheduled_today,
135     );
136 }
137
138 $template->param(
139     pendingcomments                => $pendingcomments,
140     pendingtags                    => $pendingtags,
141     pending_borrower_modifications => $pending_borrower_modifications,
142     pending_discharge_requests     => $pending_discharge_requests,
143     pending_article_requests       => $pending_article_requests,
144     pending_problem_reports        => $pending_problem_reports
145 );
146
147 output_html_with_http_headers $query, $cookie, $template->output;