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