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