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