Bug 24879: Use perl shebang to list the exec
[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 DateTime::TimeZone;
27 use File::Slurp qw( read_file );
28 use List::MoreUtils qw( any );
29 use Module::Load::Conditional qw( can_load );
30 use Config qw( %Config );
31 use Search::Elasticsearch;
32 use Try::Tiny qw( catch try );
33 use YAML::XS;
34 use Encode;
35
36 use C4::Output qw( output_html_with_http_headers );
37 use C4::Auth qw( get_template_and_user get_user_subpermissions );
38 use C4::Context;
39 use C4::Installer;
40 use C4::Installer::PerlModules;
41
42 use Koha;
43 use Koha::DateUtils qw( dt_from_string output_pref );
44 use Koha::Acquisition::Currencies;
45 use Koha::Authorities;
46 use Koha::BackgroundJob;
47 use Koha::BiblioFrameworks;
48 use Koha::Biblios;
49 use Koha::Email;
50 use Koha::I18N;
51 use Koha::Patron::Categories;
52 use Koha::Patrons;
53 use Koha::Caches;
54 use Koha::Config::SysPrefs;
55 use Koha::Illrequest::Config;
56 use Koha::SearchEngine::Elasticsearch;
57 use Koha::Logger;
58 use Koha::Filter::MARC::ViewPolicy;
59
60 use C4::Members::Statistics;
61
62 my $query = CGI->new;
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64     {
65         template_name   => "about.tt",
66         query           => $query,
67         type            => "intranet",
68         flagsrequired   => { catalogue => 1 },
69     }
70 );
71
72 my $config_timezone = C4::Context->config('timezone') // '';
73 my $config_invalid  = !DateTime::TimeZone->is_valid_name( $config_timezone );
74 my $env_timezone    = $ENV{TZ} // '';
75 my $env_invalid     = !DateTime::TimeZone->is_valid_name( $env_timezone );
76 my $actual_bad_tz_fallback = 0;
77
78 if ( $config_timezone ne '' &&
79      $config_invalid ) {
80     # Bad config
81     $actual_bad_tz_fallback = 1;
82 }
83 elsif ( $config_timezone eq '' &&
84         $env_timezone    ne '' &&
85         $env_invalid ) {
86     # No config, but bad ENV{TZ}
87     $actual_bad_tz_fallback = 1;
88 }
89
90 my $time_zone = {
91     actual                 => C4::Context->tz->name,
92     actual_bad_tz_fallback => $actual_bad_tz_fallback,
93     config                 => $config_timezone,
94     config_invalid         => $config_invalid,
95     environment            => $env_timezone,
96     environment_invalid    => $env_invalid
97 };
98
99 { # Logger checks
100     my $log4perl_config = C4::Context->config("log4perl_conf");
101     my @log4perl_errors;
102     if ( ! $log4perl_config ) {
103         push @log4perl_errors, 'missing_config_entry'
104     }
105     else {
106         my @lines = read_file($log4perl_config) or push @log4perl_errors, 'cannot_read_config_file';
107         for my $line ( @lines ) {
108             next unless $line =~ m|log4perl.appender.\w+.filename=(.*)|;
109             push @log4perl_errors, 'logfile_not_writable' unless -w $1;
110         }
111     }
112     eval {Koha::Logger->get};
113     push @log4perl_errors, 'cannot_init_module' and warn $@ if $@;
114     $template->param( log4perl_errors => @log4perl_errors );
115 }
116
117 $template->param(
118     time_zone              => $time_zone,
119     current_date_and_time  => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
120 );
121
122 my $perl_path = $^X;
123 if ($^O ne 'VMS') {
124     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
125 }
126
127 my $zebraVersion = `zebraidx -V`;
128
129 # Check running PSGI env
130 if ( C4::Context->psgi_env ) {
131     $template->param(
132         is_psgi => 1,
133         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
134                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
135                                              'Unknown'
136     );
137 }
138
139 # Memcached configuration
140 my $memcached_servers   = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
141 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
142
143 my $cache = Koha::Caches->get_instance;
144 my $effective_caching_method = ref($cache->cache);
145 # Memcached may have been running when plack has been initialized but could have been stopped since
146 # FIXME What are the consequences of that??
147 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
148
149 my $where_is_memcached_config = 'nowhere';
150 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
151     $where_is_memcached_config = 'both';
152 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
153     $where_is_memcached_config = 'ENV_only';
154 } elsif ( C4::Context->config('memcached_servers') ) {
155     $where_is_memcached_config = 'config_only';
156 }
157
158 $template->param(
159     effective_caching_method => $effective_caching_method,
160     memcached_servers   => $memcached_servers,
161     memcached_namespace => $memcached_namespace,
162     is_memcached_still_active => $is_memcached_still_active,
163     where_is_memcached_config => $where_is_memcached_config,
164     memcached_running   => Koha::Caches->get_instance->memcached_cache,
165 );
166
167 # Additional system information for warnings
168
169 my $warnStatisticsFieldsError;
170 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
171 if ($prefStatisticsFields) {
172     $warnStatisticsFieldsError = $prefStatisticsFields
173         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
174 }
175
176 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
177 my $prefRequireChoosingExistingAuthority = C4::Context->preference('RequireChoosingExistingAuthority');
178 my $warnPrefRequireChoosingExistingAuthority = ( !$prefAutoCreateAuthorities && ( !$prefRequireChoosingExistingAuthority) );
179
180 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
181 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
182 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
183
184 my $AnonymousPatron = C4::Context->preference('AnonymousPatron');
185 my $warnPrefAnonymousPatronOPACPrivacy = (
186     C4::Context->preference('OPACPrivacy')
187         and not $AnonymousPatron
188 );
189 my $warnPrefAnonymousPatronAnonSuggestions = (
190     C4::Context->preference('AnonSuggestions')
191         and not $AnonymousPatron
192 );
193
194 my $anonymous_patron = Koha::Patrons->find( $AnonymousPatron );
195 my $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist = ( $AnonymousPatron && C4::Context->preference('AnonSuggestions') && not $anonymous_patron );
196
197 my $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
198
199 my $warnPrefKohaAdminEmailAddress = !Koha::Email->is_valid(C4::Context->preference('KohaAdminEmailAddress'));
200
201 my $c = Koha::Items->filter_by_visible_in_opac->count;
202 my @warnings = C4::Context->dbh->selectrow_array('SHOW WARNINGS');
203 my $warnPrefOpacHiddenItems = $warnings[2];
204
205 my $invalid_yesno = Koha::Config::SysPrefs->search(
206     {
207         type  => 'YesNo',
208         value => { -or => { 'is' => undef, -not_in => [ "1", "0" ] } }
209     }
210 );
211 $template->param( invalid_yesno => $invalid_yesno );
212
213 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
214
215 my $warnIsRootUser   = (! $loggedinuser);
216
217 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
218
219 my @xml_config_warnings;
220
221 if (    C4::Context->config('zebra_bib_index_mode')
222     and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
223 {
224     push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
225 }
226
227 if (    C4::Context->config('zebra_auth_index_mode')
228     and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
229 {
230     push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
231 }
232
233 my $authorityserver = C4::Context->zebraconfig('authorityserver');
234 if( (   C4::Context->config('zebra_auth_index_mode')
235     and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
236     && ( $authorityserver->{config} !~ /zebra-authorities-dom.cfg/ ) )
237 {
238     push @xml_config_warnings, {
239         error => 'zebra_auth_index_mode_mismatch_warn'
240     };
241 }
242
243 if ( ! defined C4::Context->config('log4perl_conf') ) {
244     push @xml_config_warnings, {
245         error => 'log4perl_entry_missing'
246     }
247 }
248
249 if ( ! defined C4::Context->config('lockdir') ) {
250     push @xml_config_warnings, {
251         error => 'lockdir_entry_missing'
252     }
253 }
254 else {
255     unless ( -w C4::Context->config('lockdir') ) {
256         push @xml_config_warnings, {
257             error   => 'lockdir_not_writable',
258             lockdir => C4::Context->config('lockdir')
259         }
260     }
261 }
262
263 if ( ! defined C4::Context->config('upload_path') ) {
264     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
265         # OPACBaseURL seems to be set
266         push @xml_config_warnings, {
267             error => 'uploadpath_entry_missing'
268         }
269     } else {
270         push @xml_config_warnings, {
271             error => 'uploadpath_and_opacbaseurl_entry_missing'
272         }
273     }
274 }
275
276 if ( ! C4::Context->config('tmp_path') ) {
277     my $temporary_directory = C4::Context::temporary_directory;
278     push @xml_config_warnings, {
279         error             => 'tmp_path_missing',
280         effective_tmp_dir => $temporary_directory,
281     }
282 }
283
284 my $encryption_key = C4::Context->config('encryption_key');
285 if ( !$encryption_key || $encryption_key eq '__ENCRYPTION_KEY__') {
286     push @xml_config_warnings, { error => 'encryption_key_missing' };
287 }
288
289 # Test Zebra facets configuration
290 if ( !defined C4::Context->config('use_zebra_facets') ) {
291     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
292 }
293
294 unless ( Koha::I18N->_base_directory ) {
295     $template->param( warnI18nMissing => 1 );
296 }
297
298 # ILL module checks
299 if ( C4::Context->preference('ILLModule') ) {
300     my $warnILLConfiguration = 0;
301     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
302     my $ill_config = Koha::Illrequest::Config->new;
303
304     my $available_ill_backends =
305       ( scalar @{ $ill_config->available_backends } > 0 );
306
307     # Check backends
308     if ( !$available_ill_backends ) {
309         $template->param( no_ill_backends => 1 );
310         $warnILLConfiguration = 1;
311     }
312
313     # Check partner_code
314     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
315         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
316         $warnILLConfiguration = 1;
317     }
318
319     if ( !$ill_config_from_file->{partner_code} ) {
320         # partner code not defined
321         $template->param( ill_partner_code_not_defined => 1 );
322         $warnILLConfiguration = 1;
323     }
324
325
326     if ( !$ill_config_from_file->{branch} ) {
327         # branch not defined
328         $template->param( ill_branch_not_defined => 1 );
329         $warnILLConfiguration = 1;
330     }
331
332     $template->param( warnILLConfiguration => $warnILLConfiguration );
333 }
334
335 {
336     # XSLT sysprefs
337     my @xslt_prefs = qw(
338         OPACXSLTDetailsDisplay
339         OPACXSLTListsDisplay
340         OPACXSLTResultsDisplay
341         XSLTDetailsDisplay
342         XSLTListsDisplay
343         XSLTResultsDisplay
344     );
345     my @warnXSLT;
346     for my $p ( @xslt_prefs ) {
347         my $xsl_filename = C4::XSLT::get_xsl_filename( $p );
348         next if -e $xsl_filename;
349         push @warnXSLT,
350           {
351             syspref  => $p,
352             value    => C4::Context->preference("$p"),
353             filename => $xsl_filename
354           };
355     }
356
357     $template->param( warnXSLT => \@warnXSLT ) if @warnXSLT;
358 }
359
360 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
361     # Check ES configuration health and runtime status
362
363     my $es_status;
364     my $es_config_error;
365     my $es_running = 1;
366     my $es_has_missing = 0;
367
368     my $es_conf;
369     try {
370         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
371     }
372     catch {
373         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
374             $template->param( elasticsearch_fatal_config_error => $_->message );
375             $es_config_error = 1;
376         }
377     };
378     if ( !$es_config_error ) {
379
380         my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
381         my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
382
383         my @indexes = ($biblios_index_name, $authorities_index_name);
384         # TODO: When new indexes get added, we could have other ways to
385         #       fetch the list of available indexes (e.g. plugins, etc)
386         $es_status->{nodes} = $es_conf->{nodes};
387         my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
388         my $es_status->{version} = $es->info->{version}->{number};
389
390         foreach my $index ( @indexes ) {
391             my $index_count;
392             try {
393                 $index_count = $es->indices->stats( index => $index )
394                       ->{_all}{primaries}{docs}{count};
395             }
396             catch {
397                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
398                     push @{ $es_status->{errors} }, "Index not found ($index)";
399                     $index_count = -1;
400                 }
401                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
402                     $es_running = 0;
403                 }
404                 else {
405                     # TODO: when time comes, we will cover more use cases
406                     die $_;
407                 }
408             };
409
410             my $db_count = -1;
411             my $missing_count = 0;
412             if ( $index eq $biblios_index_name ) {
413                 $db_count = Koha::Biblios->search->count;
414             } elsif ( $index eq $authorities_index_name ) {
415                 $db_count = Koha::Authorities->search->count;
416             }
417             if ( $db_count != -1 && $index_count != -1 ) {
418                 $missing_count = $db_count - $index_count;
419                 $es_has_missing = 1 if $missing_count > 0;
420             }
421             push @{ $es_status->{indexes} },
422               {
423                 index_name    => $index,
424                 index_count   => $index_count,
425                 db_count      => $db_count,
426                 missing_count => $missing_count,
427               };
428         }
429         $es_status->{running} = $es_running;
430
431         $template->param(
432             elasticsearch_status      => $es_status,
433             elasticsearch_has_missing => $es_has_missing,
434         );
435     }
436 }
437
438 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
439     # Do we have the required deps?
440     unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
441         $template->param( oauth2_missing_deps => 1 );
442     }
443 }
444
445 # Sco Patron should not contain any other perms than circulate => self_checkout
446 if (  C4::Context->preference('WebBasedSelfCheck')
447       and C4::Context->preference('AutoSelfCheckAllowed')
448 ) {
449     my $userid = C4::Context->preference('AutoSelfCheckID');
450     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
451     my ( $has_self_checkout_perm, $has_other_permissions );
452     while ( my ( $module, $permissions ) = each %$all_permissions ) {
453         if ( $module eq 'self_check' ) {
454             while ( my ( $permission, $flag ) = each %$permissions ) {
455                 if ( $permission eq 'self_checkout_module' ) {
456                     $has_self_checkout_perm = 1;
457                 } else {
458                     $has_other_permissions = 1;
459                 }
460             }
461         } else {
462             $has_other_permissions = 1;
463         }
464     }
465     $template->param(
466         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
467         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
468     );
469 }
470
471 # Test YAML system preferences
472 # FIXME: This is list of current YAML formatted prefs, should by type of preference
473 my @yaml_prefs = (
474     "UpdateNotForLoanStatusOnCheckin",
475     "OpacHiddenItems",
476     "BibtexExportAdditionalFields",
477     "RisExportAdditionalFields",
478     "UpdateItemWhenLostFromHoldList",
479     "MarcFieldsToOrder",
480     "MarcItemFieldsToOrder",
481     "UpdateitemLocationOnCheckin",
482     "ItemsDeniedRenewal"
483 );
484 my @bad_yaml_prefs;
485 foreach my $syspref (@yaml_prefs) {
486     my $yaml = C4::Context->preference( $syspref );
487     if ( $yaml ) {
488         eval { YAML::XS::Load( Encode::encode_utf8("$yaml\n\n") ); };
489         if ($@) {
490             push @bad_yaml_prefs, $syspref;
491         }
492     }
493 }
494 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
495
496 {
497     my $dbh       = C4::Context->dbh;
498     my $patrons = $dbh->selectall_arrayref(
499         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
500         { Slice => {} }
501     );
502     my $biblios = $dbh->selectall_arrayref(
503         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
504         { Slice => {} }
505     );
506     my $biblioitems = $dbh->selectall_arrayref(
507         q|select bi.biblioitemnumber from biblioitems bi join deletedbiblioitems dbi on bi.biblionumber=dbi.biblionumber|,
508         { Slice => {} }
509     );
510     my $items = $dbh->selectall_arrayref(
511         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
512         { Slice => {} }
513     );
514     my $checkouts = $dbh->selectall_arrayref(
515         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
516         { Slice => {} }
517     );
518     my $holds = $dbh->selectall_arrayref(
519         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
520         { Slice => {} }
521     );
522     if ( @$patrons or @$biblios or @$biblioitems or @$items or @$checkouts or @$holds ) {
523         $template->param(
524             has_ai_issues  => 1,
525             ai_patrons     => $patrons,
526             ai_biblios     => $biblios,
527             ai_biblioitems => $biblioitems,
528             ai_items       => $items,
529             ai_checkouts   => $checkouts,
530             ai_holds       => $holds,
531         );
532     }
533 }
534
535 # Circ rule warnings
536 {
537     my $dbh   = C4::Context->dbh;
538     my $units = Koha::CirculationRules->search({ rule_name => 'lengthunit', rule_value => { -not_in => ['days', 'hours'] } });
539
540     if ( $units->count ) {
541         $template->param(
542             warnIssuingRules => 1,
543             ir_units         => $units,
544         );
545     }
546 }
547
548 # Guarantor relationships warnings
549 {
550     my $dbh   = C4::Context->dbh;
551     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
552         SELECT COUNT(*)
553         FROM (
554             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
555             UNION ALL
556             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
557     });
558
559     $bad_relationships_count = $bad_relationships_count->[0]->[0];
560
561     my $existing_relationships = $dbh->selectall_arrayref(q{
562           SELECT DISTINCT(relationship)
563           FROM (
564               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
565               UNION ALL
566               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
567     });
568
569     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
570     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
571
572     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
573     if ( @$wrong_relationships or $bad_relationships_count ) {
574
575         $template->param(
576             warnRelationships => 1,
577         );
578
579         if ( $wrong_relationships ) {
580             $template->param(
581                 wrong_relationships => $wrong_relationships
582             );
583         }
584         if ($bad_relationships_count) {
585             $template->param(
586                 bad_relationships_count => $bad_relationships_count,
587             );
588         }
589     }
590 }
591
592 {
593     # Test 'bcrypt_settings' config for Pseudonymization
594     $template->param( config_bcrypt_settings_no_set => 1 )
595       if C4::Context->preference('Pseudonymization')
596       and not C4::Context->config('bcrypt_settings');
597 }
598
599 {
600     my @frameworkcodes = Koha::BiblioFrameworks->search->get_column('frameworkcode');
601     my @hidden_biblionumbers;
602     push @frameworkcodes, ""; # it's not in the biblio_frameworks table!
603     my $no_FA_framework = 1;
604     for my $frameworkcode ( @frameworkcodes ) {
605         $no_FA_framework = 0 if $frameworkcode eq 'FA';
606         my $shouldhidemarc_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
607             {
608                 frameworkcode => $frameworkcode,
609                 interface     => "opac"
610             }
611         );
612         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'opac' }
613           if $shouldhidemarc_opac->{biblionumber};
614
615         my $shouldhidemarc_intranet = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
616             {
617                 frameworkcode => $frameworkcode,
618                 interface     => "intranet"
619             }
620         );
621         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'intranet' }
622           if $shouldhidemarc_intranet->{biblionumber};
623     }
624     $template->param( warnHiddenBiblionumbers => \@hidden_biblionumbers );
625     $template->param( warnFastCataloging => $no_FA_framework );
626 }
627
628 {
629     # BackgroundJob - test connection to message broker
630     eval {
631         Koha::BackgroundJob->connect;
632     };
633     if ( $@ ) {
634         warn $@;
635         $template->param( warnConnectBroker => $@ );
636     }
637 }
638
639 #BZ 28267: Warn administrators if there are database rows with a format other than 'DYNAMIC'
640 {
641     $template->param( warnDbRowFormat => C4::Installer->has_non_dynamic_row_format );
642 }
643
644 my %versions = C4::Context::get_versions();
645
646 $template->param(
647     kohaVersion   => $versions{'kohaVersion'},
648     osVersion     => $versions{'osVersion'},
649     perlPath      => $perl_path,
650     perlVersion   => $versions{'perlVersion'},
651     perlIncPath   => [ map { perlinc => $_ }, @INC ],
652     mysqlVersion  => $versions{'mysqlVersion'},
653     apacheVersion => $versions{'apacheVersion'},
654     zebraVersion  => $zebraVersion,
655     prefRequireChoosingExistingAuthority => $prefRequireChoosingExistingAuthority,
656     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
657     warnPrefRequireChoosingExistingAuthority => $warnPrefRequireChoosingExistingAuthority,
658     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
659     warnPrefAnonymousPatronOPACPrivacy        => $warnPrefAnonymousPatronOPACPrivacy,
660     warnPrefAnonymousPatronAnonSuggestions    => $warnPrefAnonymousPatronAnonSuggestions,
661     warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist     => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
662     warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
663     warnPrefKohaAdminEmailAddress => $warnPrefKohaAdminEmailAddress,
664     warnPrefOpacHiddenItems => $warnPrefOpacHiddenItems,
665     errZebraConnection => $errZebraConnection,
666     warnIsRootUser => $warnIsRootUser,
667     warnNoActiveCurrency => $warnNoActiveCurrency,
668     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
669     xml_config_warnings => \@xml_config_warnings,
670     warnStatisticsFieldsError => $warnStatisticsFieldsError,
671 );
672
673 my @components = ();
674
675 my $perl_modules = C4::Installer::PerlModules->new;
676 $perl_modules->versions_info;
677
678 my @pm_types = qw(missing_pm upgrade_pm current_pm);
679
680 foreach my $pm_type(@pm_types) {
681     my $modules = $perl_modules->get_attr($pm_type);
682     foreach (@$modules) {
683         my ($module, $stats) = each %$_;
684         push(
685             @components,
686             {
687                 name    => $module,
688                 version => $stats->{'cur_ver'},
689                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
690                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
691                 current => ($pm_type eq 'current_pm' ? 1 : 0),
692                 require => $stats->{'required'},
693                 reqversion => $stats->{'min_ver'},
694                 maxversion => $stats->{'max_ver'},
695                 excversion => $stats->{'exc_ver'}
696             }
697         );
698     }
699 }
700
701 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
702
703 my $counter=0;
704 my $row = [];
705 my $table = [];
706 foreach (@components) {
707     push (@$row, $_);
708     unless (++$counter % 4) {
709         push (@$table, {row => $row});
710         $row = [];
711     }
712 }
713 # Processing the last line (if there are any modules left)
714 if (scalar(@$row) > 0) {
715     # Extending $row to the table size
716     $$row[3] = '';
717     # Pushing the last line
718     push (@$table, {row => $row});
719 }
720 ## ## $table
721
722 $template->param( table => $table );
723
724
725 ## ------------------------------------------
726 ## Koha contributions
727 my $docdir;
728 if ( defined C4::Context->config('docdir') ) {
729     $docdir = C4::Context->config('docdir');
730 } else {
731     # if no <docdir> is defined in koha-conf.xml, use the default location
732     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
733     $docdir = C4::Context->config('intranetdir') . '/docs';
734 }
735
736 ## Release teams
737 my $teams =
738   -e "$docdir" . "/teams.yaml"
739   ? YAML::XS::LoadFile( "$docdir" . "/teams.yaml" )
740   : {};
741 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
742 my $short_version = substr($versions{'kohaVersion'},0,5);
743 my $minor = substr($versions{'kohaVersion'},3,2);
744 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
745 my $codename;
746 $template->param( short_version => $short_version );
747 $template->param( development_version => $development_version );
748
749 ## Contributors
750 my $contributors =
751   -e "$docdir" . "/contributors.yaml"
752   ? YAML::XS::LoadFile( "$docdir" . "/contributors.yaml" )
753   : {};
754 delete $contributors->{_others_};
755 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
756     for my $role ( keys %{ $teams->{team}->{$version} } ) {
757         my $normalized_role = "$role";
758         $normalized_role =~ s/s$//;
759         if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
760             for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
761                 my $name = $contributor->{name};
762                 # Add role to contributors
763                 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
764                   $version;
765                 # Add openhub to teams
766                 if ( exists( $contributors->{$name}->{openhub} ) ) {
767                     $contributor->{openhub} = $contributors->{$name}->{openhub};
768                 }
769             }
770         }
771         elsif ( $role eq 'release_date' ) {
772             $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
773         }
774         elsif ( $role eq 'codename' ) {
775             if ( $version == $short_version ) {
776                 $codename = $teams->{team}->{$version}->{$role};
777             }
778             next;
779         }
780         else {
781             my $name = $teams->{team}->{$version}->{$role}->{name};
782             # Add role to contributors
783             push @{ $contributors->{$name}->{roles}->{$normalized_role} },
784               $version;
785             # Add openhub to teams
786             if ( exists( $contributors->{$name}->{openhub} ) ) {
787                 $teams->{team}->{$version}->{$role}->{openhub} =
788                   $contributors->{$name}->{openhub};
789             }
790         }
791     }
792 }
793
794 ## Create last name ordered array of people from contributors
795 my @people = map {
796     { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
797 } sort {
798   my ($alast) = $a =~ /(\S+)$/;
799   my ($blast) = $b =~ /(\S+)$/;
800   my $cmp = lc($alast||"") cmp lc($blast||"");
801   return $cmp if $cmp;
802
803   my ($a2last) = $a =~ /(\S+)\s\S+$/;
804   my ($b2last) = $b =~ /(\S+)\s\S+$/;
805   lc($a2last||"") cmp lc($b2last||"");
806 } keys %$contributors;
807
808 $template->param( kohaCodename  => $codename);
809 $template->param( contributors => \@people );
810 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
811 $template->param( release_team => $teams->{team}->{$short_version} );
812
813 ## Timeline
814 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
815
816     my $i = 0;
817
818     my @rows2 = ();
819     my $row2  = [];
820
821     my @lines = <$file>;
822     close($file);
823
824     shift @lines; #remove header row
825
826     foreach (@lines) {
827         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
828         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
829             ($date, $desc)= ($`, $');
830         }
831         push(
832             @rows2,
833             {
834                 date => $date,
835                 desc => $desc,
836             }
837         );
838     }
839
840     my $table2 = [];
841     #foreach my $row2 (@rows2) {
842     foreach  (@rows2) {
843         push (@$row2, $_);
844         push( @$table2, { row2 => $row2 } );
845         $row2 = [];
846     }
847
848     $template->param( table2 => $table2 );
849 } else {
850     $template->param( timeline_read_error => 1 );
851 }
852
853 output_html_with_http_headers $query, $cookie, $template->output;