]> git.koha-community.org Git - koha.git/blob - mainpage.pl
Bug 29346: (follow-up) Build holds queue when AlterPriority or RevertWaitingStatus...
[koha.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::ProblemReports;
34 use Koha::Quotes;
35 use Koha::Suggestions;
36 use Koha::BackgroundJobs;
37
38 my $query = CGI->new;
39
40 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
41     {
42         template_name   => "intranet-main.tt",
43         query           => $query,
44         type            => "intranet",
45         flagsrequired   => { catalogue => 1, },
46     }
47 );
48
49 my $logged_in_user = Koha::Patrons->find($loggedinuser);
50
51 my $homebranch;
52 if (C4::Context->userenv) {
53     $homebranch = C4::Context->userenv->{'branch'};
54 }
55 my $koha_news = Koha::AdditionalContents->search_for_display(
56     {
57         category   => 'news',
58         location   => [ 'staff_only', 'staff_and_opac' ],
59         lang       => $template->lang,
60         library_id => $homebranch
61     }
62 );
63
64 $template->param(
65     koha_news   => $koha_news,
66     daily_quote => Koha::Quotes->get_daily_quote(),
67 );
68
69 my $branch =
70   (      C4::Context->preference("IndependentBranchesPatronModifications")
71       || C4::Context->preference("IndependentBranches") )
72   && !$flags->{'superlibrarian'}
73   ? C4::Context->userenv()->{'branch'}
74   : undef;
75
76 my $pendingcomments    = Koha::Reviews->search_limited({ approved => 0 })->count;
77 my $pendingtags        = get_count_by_tag_status(0);
78
79 # Get current branch count and total viewable count, if they don't match then pass
80 # both to template
81
82 if( C4::Context->only_my_library ){
83     my $local_pendingsuggestions_count = Koha::Suggestions->search({ status => "ASKED", branchcode => C4::Context->userenv()->{'branch'} })->count();
84     $template->param( pendingsuggestions => $local_pendingsuggestions_count );
85 } else {
86     my $pendingsuggestions = Koha::Suggestions->search({ status => "ASKED" });
87     my $local_pendingsuggestions_count = $pendingsuggestions->search({ 'me.branchcode' => C4::Context->userenv()->{'branch'} })->count();
88     my $pendingsuggestions_count = $pendingsuggestions->count();
89     $template->param(
90         all_pendingsuggestions => $pendingsuggestions_count != $local_pendingsuggestions_count ? $pendingsuggestions_count : 0,
91         pendingsuggestions => $local_pendingsuggestions_count
92     );
93 }
94
95 my $pending_borrower_modifications = Koha::Patron::Modifications->pending_count( $branch );
96 my $pending_discharge_requests = Koha::Patron::Discharge::count({ pending => 1 });
97 my $pending_article_requests = Koha::ArticleRequests->search_limited(
98     {
99         status => Koha::ArticleRequest::Status::Requested,
100         $branch ? ( 'me.branchcode' => $branch ) : (),
101     }
102 )->count;
103 my $pending_problem_reports = Koha::ProblemReports->search({ status => 'New' });
104
105 unless ( $logged_in_user->has_permission( { parameters => 'manage_background_jobs' } ) ) {
106     my $already_ran_jobs = Koha::BackgroundJobs->search(
107         { borrowernumber => $logged_in_user->borrowernumber } )->count ? 1 : 0;
108     $template->param( already_ran_jobs => $already_ran_jobs );
109 }
110
111 $template->param(
112     pendingcomments                => $pendingcomments,
113     pendingtags                    => $pendingtags,
114     pending_borrower_modifications => $pending_borrower_modifications,
115     pending_discharge_requests     => $pending_discharge_requests,
116     pending_article_requests       => $pending_article_requests,
117     pending_problem_reports        => $pending_problem_reports
118 );
119
120 output_html_with_http_headers $query, $cookie, $template->output;