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