Bug 10860: Follow-up - fix some template variable issues
[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;
24 use C4::Output;
25 use C4::Auth;
26 use C4::Koha;
27 use C4::NewsChannels; # GetNewsToDisplay
28 use C4::Review qw/numberofreviews/;
29 use C4::Suggestions qw/CountSuggestion/;
30 use C4::Tags qw/get_count_by_tag_status/;
31 use Koha::Borrower::Modifications;
32
33 my $query = new CGI;
34
35 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
36     {
37         template_name   => "intranet-main.tt",
38         query           => $query,
39         type            => "intranet",
40         authnotrequired => 0,
41         flagsrequired   => { catalogue => 1, },
42     }
43 );
44
45 my $homebranch;
46 if (C4::Context->userenv) {
47     $homebranch = C4::Context->userenv->{'branch'};
48 }
49 my $all_koha_news   = &GetNewsToDisplay("koha",$homebranch);
50 my $koha_news_count = scalar @$all_koha_news;
51
52 $template->param(
53     koha_news       => $all_koha_news,
54     koha_news_count => $koha_news_count
55 );
56
57 my $branch =
58   C4::Context->preference("IndependentBranches")
59   && !$flags->{'superlibrarian'}
60   ? C4::Context->userenv()->{'branch'}
61   : undef;
62
63 my $pendingcomments    = numberofreviews(0);
64 my $pendingtags        = get_count_by_tag_status(0);
65 my $pendingsuggestions = CountSuggestion("ASKED");
66 my $pending_borrower_modifications =
67   Koha::Borrower::Modifications->GetPendingModificationsCount( $branch );
68
69 $template->param(
70     pendingcomments                => $pendingcomments,
71     pendingtags                    => $pendingtags,
72     pendingsuggestions             => $pendingsuggestions,
73     pending_borrower_modifications => $pending_borrower_modifications,
74 );
75
76 #
77 # warn user if he is using mysql/admin login
78 #
79 unless ($loggedinuser) {
80     $template->param(adminWarning => 1);
81 }
82
83 output_html_with_http_headers $query, $cookie, $template->output;