Bug 14655: Add a warning on the about page if patrons have requested privacy
[koha.git] / about.pl
1 #!/usr/bin/perl
2
3 # Copyright Pat Eyler 2003
4 # Copyright Biblibre 2006
5 # Parts Copyright Liblime 2008
6 # Parts Copyright Chris Nighswonger 2010
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
27 use LWP::Simple;
28 use XML::Simple;
29 use Config;
30
31 use C4::Output;
32 use C4::Auth;
33 use C4::Context;
34 use C4::Installer;
35
36 use Koha;
37 use Koha::Borrowers;
38
39 #use Smart::Comments '####';
40
41 my $query = new CGI;
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "about.tt",
45         query           => $query,
46         type            => "intranet",
47         authnotrequired => 0,
48         flagsrequired   => { catalogue => 1 },
49         debug           => 1,
50     }
51 );
52
53 my $kohaVersion   = Koha::version();
54 my $osVersion     = `uname -a`;
55 my $perl_path = $^X;
56 if ($^O ne 'VMS') {
57     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
58 }
59 my $perlVersion   = $];
60 my $mysqlVersion  = `mysql -V`;
61 # Get Apache version
62 my $apacheVersion = (`apache2ctl -v`)[0];
63 $apacheVersion    = `httpd2 -v 2> /dev/null` unless $apacheVersion;
64 $apacheVersion    = `httpd -v 2> /dev/null` unless $apacheVersion;
65 my $zebraVersion = `zebraidx -V`;
66
67 # Additional system information for warnings
68 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
69 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
70 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
71
72 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
73 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
74 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
75 my $warnPrefAnonymousPatron = (
76     C4::Context->preference('OPACPrivacy')
77         and not C4::Context->preference('AnonymousPatron')
78 );
79
80 my $anonymous_patron = Koha::Borrowers->find( C4::Context->preference('AnonymousPatron') );
81 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Borrowers->search({ privacy => 2 })->count );
82
83 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
84
85 my $warnIsRootUser   = (! $loggedinuser);
86
87 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
88 my @xml_config_warnings;
89
90 my $context = new C4::Context;
91
92 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
93     push @xml_config_warnings, {
94         error => 'zebra_bib_index_mode_warn'
95     };
96     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
97         push @xml_config_warnings, {
98             error => 'zebra_bib_mode_seems_grs1'
99         };
100     }
101     else {
102         push @xml_config_warnings, {
103             error => 'zebra_bib_mode_seems_dom'
104         };
105     }
106 } else {
107     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
108         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
109 }
110
111 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
112      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
113
114     push @xml_config_warnings, {
115         error => 'zebra_bib_index_mode_mismatch_warn'
116     };
117 }
118
119 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
120      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
121
122     push @xml_config_warnings, {
123         error => 'zebra_bib_index_mode_mismatch_warn'
124     };
125 }
126
127 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
128     push @xml_config_warnings, {
129         error => 'zebra_auth_index_mode_warn'
130     };
131     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
132         push @xml_config_warnings, {
133             error => 'zebra_auth_mode_seems_grs1'
134         };
135     }
136     else {
137         push @xml_config_warnings, {
138             error => 'zebra_auth_mode_seems_dom'
139         };
140     }
141 } else {
142     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
143         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
144 }
145
146 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
147     push @xml_config_warnings, {
148         error => 'zebra_auth_index_mode_mismatch_warn'
149     };
150 }
151
152 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
153     push @xml_config_warnings, {
154         error => 'zebra_auth_index_mode_mismatch_warn'
155     };
156 }
157
158 # Test QueryParser configuration sanity
159 if ( C4::Context->preference( 'UseQueryParser' ) ) {
160     # Get the QueryParser configuration file name
161     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
162     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
163     # Check QueryParser is functional
164     my $QParser = C4::Context->queryparser();
165     my $queryparser_error = {};
166     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
167         # Error initializing the QueryParser object
168         # Get the used queryparser.yaml file path to report the user
169         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
170         $queryparser_error->{ file }     = ( defined $queryparser_file )
171                                                 ? $queryparser_file
172                                                 : $queryparser_fallback_file;
173         # Report error data to the template
174         $template->param( QueryParserError => $queryparser_error );
175     } else {
176         # Check for an absent queryparser_config entry in koha-conf.xml
177         if ( ! defined $queryparser_file ) {
178             # Not an error but a warning for the missing entry in koha-conf-xml
179             push @xml_config_warnings, {
180                     error => 'queryparser_entry_missing',
181                     file  => $queryparser_fallback_file
182             };
183         }
184     }
185 }
186
187 # Test Zebra facets configuration
188 if ( !defined C4::Context->config('use_zebra_facets') ) {
189     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
190 } else {
191     if ( C4::Context->config('use_zebra_facets') &&
192          C4::Context->config('zebra_bib_index_mode') ) {
193         # use_zebra_facets works with DOM
194         push @xml_config_warnings, {
195             error => 'use_zebra_facets_needs_dom'
196         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
197     }
198 }
199
200 $template->param(
201     kohaVersion   => $kohaVersion,
202     osVersion     => $osVersion,
203     perlPath      => $perl_path,
204     perlVersion   => $perlVersion,
205     perlIncPath   => [ map { perlinc => $_ }, @INC ],
206     mysqlVersion  => $mysqlVersion,
207     apacheVersion => $apacheVersion,
208     zebraVersion  => $zebraVersion,
209     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
210     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
211     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
212     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
213     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
214     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
215     errZebraConnection => $errZebraConnection,
216     warnIsRootUser => $warnIsRootUser,
217     warnNoActiveCurrency => $warnNoActiveCurrency,
218     xml_config_warnings => \@xml_config_warnings,
219 );
220
221 my @components = ();
222
223 my $perl_modules = C4::Installer::PerlModules->new;
224 $perl_modules->version_info;
225
226 my @pm_types = qw(missing_pm upgrade_pm current_pm);
227
228 foreach my $pm_type(@pm_types) {
229     my $modules = $perl_modules->get_attr($pm_type);
230     foreach (@$modules) {
231         my ($module, $stats) = each %$_;
232         push(
233             @components,
234             {
235                 name    => $module,
236                 version => $stats->{'cur_ver'},
237                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
238                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
239                 current => ($pm_type eq 'current_pm' ? 1 : 0),
240                 require => $stats->{'required'},
241                 reqversion => $stats->{'min_ver'},
242             }
243         );
244     }
245 }
246
247 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
248
249 my $counter=0;
250 my $row = [];
251 my $table = [];
252 foreach (@components) {
253     push (@$row, $_);
254     unless (++$counter % 4) {
255         push (@$table, {row => $row});
256         $row = [];
257     }
258 }
259 # Processing the last line (if there are any modules left)
260 if (scalar(@$row) > 0) {
261     # Extending $row to the table size
262     $$row[3] = '';
263     # Pushing the last line
264     push (@$table, {row => $row});
265 }
266 ## ## $table
267
268 $template->param( table => $table );
269
270
271 ## ------------------------------------------
272 ## Koha time line code
273
274 #get file location
275 my $docdir;
276 if ( defined C4::Context->config('docdir') ) {
277     $docdir = C4::Context->config('docdir');
278 } else {
279     # if no <docdir> is defined in koha-conf.xml, use the default location
280     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
281     $docdir = C4::Context->config('intranetdir') . '/docs';
282 }
283
284 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
285
286     my $i = 0;
287
288     my @rows2 = ();
289     my $row2  = [];
290
291     my @lines = <$file>;
292     close($file);
293
294     shift @lines; #remove header row
295
296     foreach (@lines) {
297         my ( $date, $desc, $tag ) = split(/\t/);
298         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
299             ($date, $desc)= ($`, $');
300         }
301         push(
302             @rows2,
303             {
304                 date => $date,
305                 desc => $desc,
306             }
307         );
308     }
309
310     my $table2 = [];
311     #foreach my $row2 (@rows2) {
312     foreach  (@rows2) {
313         push (@$row2, $_);
314         push( @$table2, { row2 => $row2 } );
315         $row2 = [];
316     }
317
318     $template->param( table2 => $table2 );
319 } else {
320     $template->param( timeline_read_error => 1 );
321 }
322
323 output_html_with_http_headers $query, $cookie, $template->output;