Add release notes for Koha 16.05.19
[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 Modern::Perl;
24
25 use CGI qw ( -utf8 );
26 use List::MoreUtils qw/ any /;
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::Acquisition::Currencies;
38 use Koha::Patrons;
39 use Koha::Config::SysPrefs;
40 use C4::Members::Statistics;
41
42 #use Smart::Comments '####';
43
44 my $query = new CGI;
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46     {
47         template_name   => "about.tt",
48         query           => $query,
49         type            => "intranet",
50         authnotrequired => 0,
51         flagsrequired   => { catalogue => 1 },
52         debug           => 1,
53     }
54 );
55
56 my $perl_path = $^X;
57 if ($^O ne 'VMS') {
58     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
59 }
60
61 my $zebraVersion = `zebraidx -V`;
62
63 # Check running PSGI env
64 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
65     $template->param(
66         is_psgi => 1,
67         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
68                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
69                                              'Unknown'
70     );
71 }
72
73 # Additional system information for warnings
74
75 my $warnStatisticsFieldsError;
76 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
77 if ($prefStatisticsFields) {
78     $warnStatisticsFieldsError = $prefStatisticsFields
79         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
80 }
81
82 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
83 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
84 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
85
86 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
87 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
88 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
89 my $warnPrefAnonymousPatron = (
90     C4::Context->preference('OPACPrivacy')
91         and not C4::Context->preference('AnonymousPatron')
92 );
93
94 my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
95 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
96
97 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
98
99 my $warnIsRootUser   = (! $loggedinuser);
100
101 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
102
103 my @xml_config_warnings;
104
105 my $context = new C4::Context;
106
107 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
108     push @xml_config_warnings, {
109         error => 'zebra_bib_index_mode_warn'
110     };
111     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
112         push @xml_config_warnings, {
113             error => 'zebra_bib_mode_seems_grs1'
114         };
115     }
116     else {
117         push @xml_config_warnings, {
118             error => 'zebra_bib_mode_seems_dom'
119         };
120     }
121 } else {
122     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
123         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
124 }
125
126 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
127      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
128
129     push @xml_config_warnings, {
130         error => 'zebra_bib_index_mode_mismatch_warn'
131     };
132 }
133
134 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
135      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
136
137     push @xml_config_warnings, {
138         error => 'zebra_bib_index_mode_mismatch_warn'
139     };
140 }
141
142 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
143     push @xml_config_warnings, {
144         error => 'zebra_auth_index_mode_warn'
145     };
146     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
147         push @xml_config_warnings, {
148             error => 'zebra_auth_mode_seems_grs1'
149         };
150     }
151     else {
152         push @xml_config_warnings, {
153             error => 'zebra_auth_mode_seems_dom'
154         };
155     }
156 } else {
157     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
158         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
159 }
160
161 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
162     push @xml_config_warnings, {
163         error => 'zebra_auth_index_mode_mismatch_warn'
164     };
165 }
166
167 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
168     push @xml_config_warnings, {
169         error => 'zebra_auth_index_mode_mismatch_warn'
170     };
171 }
172
173 if ( ! defined C4::Context->config('log4perl_conf') ) {
174     push @xml_config_warnings, {
175         error => 'log4perl_entry_missing'
176     }
177 }
178
179 if ( ! defined C4::Context->config('upload_path') ) {
180     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
181         # OPACBaseURL seems to be set
182         push @xml_config_warnings, {
183             error => 'uploadpath_entry_missing'
184         }
185     } else {
186         push @xml_config_warnings, {
187             error => 'uploadpath_and_opacbaseurl_entry_missing'
188         }
189     }
190 }
191
192 # Test QueryParser configuration sanity
193 if ( C4::Context->preference( 'UseQueryParser' ) ) {
194     # Get the QueryParser configuration file name
195     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
196     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
197     # Check QueryParser is functional
198     my $QParser = C4::Context->queryparser();
199     my $queryparser_error = {};
200     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
201         # Error initializing the QueryParser object
202         # Get the used queryparser.yaml file path to report the user
203         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
204         $queryparser_error->{ file }     = ( defined $queryparser_file )
205                                                 ? $queryparser_file
206                                                 : $queryparser_fallback_file;
207         # Report error data to the template
208         $template->param( QueryParserError => $queryparser_error );
209     } else {
210         # Check for an absent queryparser_config entry in koha-conf.xml
211         if ( ! defined $queryparser_file ) {
212             # Not an error but a warning for the missing entry in koha-conf-xml
213             push @xml_config_warnings, {
214                     error => 'queryparser_entry_missing',
215                     file  => $queryparser_fallback_file
216             };
217         }
218     }
219 }
220
221 # Test Zebra facets configuration
222 if ( !defined C4::Context->config('use_zebra_facets') ) {
223     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
224 } else {
225     if ( C4::Context->config('use_zebra_facets') &&
226          C4::Context->config('zebra_bib_index_mode') ) {
227         # use_zebra_facets works with DOM
228         push @xml_config_warnings, {
229             error => 'use_zebra_facets_needs_dom'
230         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
231     }
232 }
233
234 # Sco Patron should not contain any other perms than circulate => self_checkout
235 if (  C4::Context->preference('WebBasedSelfCheck')
236       and C4::Context->preference('AutoSelfCheckAllowed')
237 ) {
238     my $userid = C4::Context->preference('AutoSelfCheckID');
239     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
240     my ( $has_self_checkout_perm, $has_other_permissions );
241     while ( my ( $module, $permissions ) = each %$all_permissions ) {
242         if ( $module eq 'circulate' ) {
243             while ( my ( $permission, $flag ) = each %$permissions ) {
244                 if ( $permission eq 'self_checkout' ) {
245                     $has_self_checkout_perm = 1;
246                 } else {
247                     $has_other_permissions = 1;
248                 }
249             }
250         } else {
251             $has_other_permissions = 1;
252         }
253     }
254     $template->param(
255         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
256         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
257     );
258 }
259
260 {
261     my $dbh       = C4::Context->dbh;
262     my $patrons = $dbh->selectall_arrayref(
263         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
264         { Slice => {} }
265     );
266     my $biblios = $dbh->selectall_arrayref(
267         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
268         { Slice => {} }
269     );
270     my $items = $dbh->selectall_arrayref(
271         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
272         { Slice => {} }
273     );
274     my $checkouts = $dbh->selectall_arrayref(
275         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
276         { Slice => {} }
277     );
278     my $holds = $dbh->selectall_arrayref(
279         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
280         { Slice => {} }
281     );
282     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
283         $template->param(
284             has_ai_issues => 1,
285             ai_patrons    => $patrons,
286             ai_biblios    => $biblios,
287             ai_items      => $items,
288             ai_checkouts  => $checkouts,
289             ai_holds      => $holds,
290         );
291     }
292 }
293 my %versions = C4::Context::get_versions();
294
295 $template->param(
296     kohaVersion   => $versions{'kohaVersion'},
297     osVersion     => $versions{'osVersion'},
298     perlPath      => $perl_path,
299     perlVersion   => $versions{'perlVersion'},
300     perlIncPath   => [ map { perlinc => $_ }, @INC ],
301     mysqlVersion  => $versions{'mysqlVersion'},
302     apacheVersion => $versions{'apacheVersion'},
303     zebraVersion  => $zebraVersion,
304     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
305     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
306     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
307     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
308     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
309     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
310     errZebraConnection => $errZebraConnection,
311     warnIsRootUser => $warnIsRootUser,
312     warnNoActiveCurrency => $warnNoActiveCurrency,
313     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
314     xml_config_warnings => \@xml_config_warnings,
315     warnStatisticsFieldsError => $warnStatisticsFieldsError,
316 );
317
318 my @components = ();
319
320 my $perl_modules = C4::Installer::PerlModules->new;
321 $perl_modules->versions_info;
322
323 my @pm_types = qw(missing_pm upgrade_pm current_pm);
324
325 foreach my $pm_type(@pm_types) {
326     my $modules = $perl_modules->get_attr($pm_type);
327     foreach (@$modules) {
328         my ($module, $stats) = each %$_;
329         push(
330             @components,
331             {
332                 name    => $module,
333                 version => $stats->{'cur_ver'},
334                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
335                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
336                 current => ($pm_type eq 'current_pm' ? 1 : 0),
337                 require => $stats->{'required'},
338                 reqversion => $stats->{'min_ver'},
339             }
340         );
341     }
342 }
343
344 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
345
346 my $counter=0;
347 my $row = [];
348 my $table = [];
349 foreach (@components) {
350     push (@$row, $_);
351     unless (++$counter % 4) {
352         push (@$table, {row => $row});
353         $row = [];
354     }
355 }
356 # Processing the last line (if there are any modules left)
357 if (scalar(@$row) > 0) {
358     # Extending $row to the table size
359     $$row[3] = '';
360     # Pushing the last line
361     push (@$table, {row => $row});
362 }
363 ## ## $table
364
365 $template->param( table => $table );
366
367
368 ## ------------------------------------------
369 ## Koha time line code
370
371 #get file location
372 my $docdir;
373 if ( defined C4::Context->config('docdir') ) {
374     $docdir = C4::Context->config('docdir');
375 } else {
376     # if no <docdir> is defined in koha-conf.xml, use the default location
377     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
378     $docdir = C4::Context->config('intranetdir') . '/docs';
379 }
380
381 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
382
383     my $i = 0;
384
385     my @rows2 = ();
386     my $row2  = [];
387
388     my @lines = <$file>;
389     close($file);
390
391     shift @lines; #remove header row
392
393     foreach (@lines) {
394         my ( $date, $desc, $tag ) = split(/\t/);
395         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
396             ($date, $desc)= ($`, $');
397         }
398         push(
399             @rows2,
400             {
401                 date => $date,
402                 desc => $desc,
403             }
404         );
405     }
406
407     my $table2 = [];
408     #foreach my $row2 (@rows2) {
409     foreach  (@rows2) {
410         push (@$row2, $_);
411         push( @$table2, { row2 => $row2 } );
412         $row2 = [];
413     }
414
415     $template->param( table2 => $table2 );
416 } else {
417     $template->param( timeline_read_error => 1 );
418 }
419
420 output_html_with_http_headers $query, $cookie, $template->output;