Bug 14655: Add a warning on the about page if patrons have requested privacy
[koha-equinox.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 use Koha::Config::SysPrefs;
39
40 #use Smart::Comments '####';
41
42 my $query = new CGI;
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44     {
45         template_name   => "about.tt",
46         query           => $query,
47         type            => "intranet",
48         authnotrequired => 0,
49         flagsrequired   => { catalogue => 1 },
50         debug           => 1,
51     }
52 );
53
54 my $kohaVersion   = Koha::version();
55 my $osVersion     = `uname -a`;
56 my $perl_path = $^X;
57 if ($^O ne 'VMS') {
58     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
59 }
60 my $perlVersion   = $];
61 my $mysqlVersion  = `mysql -V`;
62 # Get Apache version
63 my $apacheVersion = (`apache2ctl -v`)[0];
64 $apacheVersion    = `httpd2 -v 2> /dev/null` unless $apacheVersion;
65 $apacheVersion    = `httpd -v 2> /dev/null` unless $apacheVersion;
66 my $zebraVersion = `zebraidx -V`;
67
68 # Additional system information for warnings
69 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
70 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
71 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
72
73 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
74 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
75 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
76 my $warnPrefAnonymousPatron = (
77     C4::Context->preference('OPACPrivacy')
78         and not C4::Context->preference('AnonymousPatron')
79 );
80
81 my $anonymous_patron = Koha::Borrowers->find( C4::Context->preference('AnonymousPatron') );
82 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Borrowers->search({ privacy => 2 })->count );
83
84 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
85
86 my $warnIsRootUser   = (! $loggedinuser);
87
88 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
89 my @xml_config_warnings;
90
91 my $context = new C4::Context;
92
93 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
94     push @xml_config_warnings, {
95         error => 'zebra_bib_index_mode_warn'
96     };
97     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
98         push @xml_config_warnings, {
99             error => 'zebra_bib_mode_seems_grs1'
100         };
101     }
102     else {
103         push @xml_config_warnings, {
104             error => 'zebra_bib_mode_seems_dom'
105         };
106     }
107 } else {
108     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
109         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
110 }
111
112 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
113      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
114
115     push @xml_config_warnings, {
116         error => 'zebra_bib_index_mode_mismatch_warn'
117     };
118 }
119
120 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
121      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
122
123     push @xml_config_warnings, {
124         error => 'zebra_bib_index_mode_mismatch_warn'
125     };
126 }
127
128 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
129     push @xml_config_warnings, {
130         error => 'zebra_auth_index_mode_warn'
131     };
132     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
133         push @xml_config_warnings, {
134             error => 'zebra_auth_mode_seems_grs1'
135         };
136     }
137     else {
138         push @xml_config_warnings, {
139             error => 'zebra_auth_mode_seems_dom'
140         };
141     }
142 } else {
143     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
144         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
145 }
146
147 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
148     push @xml_config_warnings, {
149         error => 'zebra_auth_index_mode_mismatch_warn'
150     };
151 }
152
153 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
154     push @xml_config_warnings, {
155         error => 'zebra_auth_index_mode_mismatch_warn'
156     };
157 }
158
159 if ( ! defined C4::Context->config('log4perl_conf') ) {
160     push @xml_config_warnings, {
161         error => 'log4perl_entry_missing'
162     }
163 }
164
165 if ( ! defined C4::Context->config('upload_path') ) {
166     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
167         # OPACBaseURL seems to be set
168         push @xml_config_warnings, {
169             error => 'uploadpath_entry_missing'
170         }
171     } else {
172         push @xml_config_warnings, {
173             error => 'uploadpath_and_opacbaseurl_entry_missing'
174         }
175     }
176 }
177
178 # Test QueryParser configuration sanity
179 if ( C4::Context->preference( 'UseQueryParser' ) ) {
180     # Get the QueryParser configuration file name
181     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
182     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
183     # Check QueryParser is functional
184     my $QParser = C4::Context->queryparser();
185     my $queryparser_error = {};
186     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
187         # Error initializing the QueryParser object
188         # Get the used queryparser.yaml file path to report the user
189         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
190         $queryparser_error->{ file }     = ( defined $queryparser_file )
191                                                 ? $queryparser_file
192                                                 : $queryparser_fallback_file;
193         # Report error data to the template
194         $template->param( QueryParserError => $queryparser_error );
195     } else {
196         # Check for an absent queryparser_config entry in koha-conf.xml
197         if ( ! defined $queryparser_file ) {
198             # Not an error but a warning for the missing entry in koha-conf-xml
199             push @xml_config_warnings, {
200                     error => 'queryparser_entry_missing',
201                     file  => $queryparser_fallback_file
202             };
203         }
204     }
205 }
206
207 # Test Zebra facets configuration
208 if ( !defined C4::Context->config('use_zebra_facets') ) {
209     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
210 } else {
211     if ( C4::Context->config('use_zebra_facets') &&
212          C4::Context->config('zebra_bib_index_mode') ) {
213         # use_zebra_facets works with DOM
214         push @xml_config_warnings, {
215             error => 'use_zebra_facets_needs_dom'
216         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
217     }
218 }
219
220 $template->param(
221     kohaVersion   => $kohaVersion,
222     osVersion     => $osVersion,
223     perlPath      => $perl_path,
224     perlVersion   => $perlVersion,
225     perlIncPath   => [ map { perlinc => $_ }, @INC ],
226     mysqlVersion  => $mysqlVersion,
227     apacheVersion => $apacheVersion,
228     zebraVersion  => $zebraVersion,
229     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
230     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
231     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
232     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
233     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
234     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
235     errZebraConnection => $errZebraConnection,
236     warnIsRootUser => $warnIsRootUser,
237     warnNoActiveCurrency => $warnNoActiveCurrency,
238     xml_config_warnings => \@xml_config_warnings,
239 );
240
241 my @components = ();
242
243 my $perl_modules = C4::Installer::PerlModules->new;
244 $perl_modules->version_info;
245
246 my @pm_types = qw(missing_pm upgrade_pm current_pm);
247
248 foreach my $pm_type(@pm_types) {
249     my $modules = $perl_modules->get_attr($pm_type);
250     foreach (@$modules) {
251         my ($module, $stats) = each %$_;
252         push(
253             @components,
254             {
255                 name    => $module,
256                 version => $stats->{'cur_ver'},
257                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
258                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
259                 current => ($pm_type eq 'current_pm' ? 1 : 0),
260                 require => $stats->{'required'},
261                 reqversion => $stats->{'min_ver'},
262             }
263         );
264     }
265 }
266
267 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
268
269 my $counter=0;
270 my $row = [];
271 my $table = [];
272 foreach (@components) {
273     push (@$row, $_);
274     unless (++$counter % 4) {
275         push (@$table, {row => $row});
276         $row = [];
277     }
278 }
279 # Processing the last line (if there are any modules left)
280 if (scalar(@$row) > 0) {
281     # Extending $row to the table size
282     $$row[3] = '';
283     # Pushing the last line
284     push (@$table, {row => $row});
285 }
286 ## ## $table
287
288 $template->param( table => $table );
289
290
291 ## ------------------------------------------
292 ## Koha time line code
293
294 #get file location
295 my $docdir;
296 if ( defined C4::Context->config('docdir') ) {
297     $docdir = C4::Context->config('docdir');
298 } else {
299     # if no <docdir> is defined in koha-conf.xml, use the default location
300     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
301     $docdir = C4::Context->config('intranetdir') . '/docs';
302 }
303
304 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
305
306     my $i = 0;
307
308     my @rows2 = ();
309     my $row2  = [];
310
311     my @lines = <$file>;
312     close($file);
313
314     shift @lines; #remove header row
315
316     foreach (@lines) {
317         my ( $date, $desc, $tag ) = split(/\t/);
318         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
319             ($date, $desc)= ($`, $');
320         }
321         push(
322             @rows2,
323             {
324                 date => $date,
325                 desc => $desc,
326             }
327         );
328     }
329
330     my $table2 = [];
331     #foreach my $row2 (@rows2) {
332     foreach  (@rows2) {
333         push (@$row2, $_);
334         push( @$table2, { row2 => $row2 } );
335         $row2 = [];
336     }
337
338     $template->param( table2 => $table2 );
339 } else {
340     $template->param( timeline_read_error => 1 );
341 }
342
343 output_html_with_http_headers $query, $cookie, $template->output;