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