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