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