Bug 21983: DBRev 22.11.00.005
[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;
40 use C4::Installer::PerlModules;
41
42 use Koha;
43 use Koha::DateUtils qw( dt_from_string output_pref );
44 use Koha::Acquisition::Currencies;
45 use Koha::Authorities;
46 use Koha::BackgroundJob;
47 use Koha::BiblioFrameworks;
48 use Koha::Biblios;
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 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 ( C4::Context->psgi_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 $prefRequireChoosingExistingAuthority = C4::Context->preference('RequireChoosingExistingAuthority');
177 my $warnPrefRequireChoosingExistingAuthority = ( !$prefAutoCreateAuthorities && ( !$prefRequireChoosingExistingAuthority) );
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 = !Koha::Email->is_valid(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 if( ! C4::Context->config('encryption_key') ) {
284     push @xml_config_warnings, { error => 'encryption_key_missing' };
285 }
286
287 # Test Zebra facets configuration
288 if ( !defined C4::Context->config('use_zebra_facets') ) {
289     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
290 }
291
292 # ILL module checks
293 if ( C4::Context->preference('ILLModule') ) {
294     my $warnILLConfiguration = 0;
295     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
296     my $ill_config = Koha::Illrequest::Config->new;
297
298     my $available_ill_backends =
299       ( scalar @{ $ill_config->available_backends } > 0 );
300
301     # Check backends
302     if ( !$available_ill_backends ) {
303         $template->param( no_ill_backends => 1 );
304         $warnILLConfiguration = 1;
305     }
306
307     # Check partner_code
308     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
309         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
310         $warnILLConfiguration = 1;
311     }
312
313     if ( !$ill_config_from_file->{partner_code} ) {
314         # partner code not defined
315         $template->param( ill_partner_code_not_defined => 1 );
316         $warnILLConfiguration = 1;
317     }
318
319
320     if ( !$ill_config_from_file->{branch} ) {
321         # branch not defined
322         $template->param( ill_branch_not_defined => 1 );
323         $warnILLConfiguration = 1;
324     }
325
326     $template->param( warnILLConfiguration => $warnILLConfiguration );
327 }
328
329 {
330     # XSLT sysprefs
331     my @xslt_prefs = qw(
332         OPACXSLTDetailsDisplay
333         OPACXSLTListsDisplay
334         OPACXSLTResultsDisplay
335         XSLTDetailsDisplay
336         XSLTListsDisplay
337         XSLTResultsDisplay
338     );
339     my @warnXSLT;
340     for my $p ( @xslt_prefs ) {
341         my $xsl_filename = C4::XSLT::get_xsl_filename( $p );
342         next if -e $xsl_filename;
343         push @warnXSLT,
344           {
345             syspref  => $p,
346             value    => C4::Context->preference("$p"),
347             filename => $xsl_filename
348           };
349     }
350
351     $template->param( warnXSLT => \@warnXSLT ) if @warnXSLT;
352 }
353
354 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
355     # Check ES configuration health and runtime status
356
357     my $es_status;
358     my $es_config_error;
359     my $es_running = 1;
360     my $es_has_missing = 0;
361
362     my $es_conf;
363     try {
364         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
365     }
366     catch {
367         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
368             $template->param( elasticsearch_fatal_config_error => $_->message );
369             $es_config_error = 1;
370         }
371     };
372     if ( !$es_config_error ) {
373
374         my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
375         my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
376
377         my @indexes = ($biblios_index_name, $authorities_index_name);
378         # TODO: When new indexes get added, we could have other ways to
379         #       fetch the list of available indexes (e.g. plugins, etc)
380         $es_status->{nodes} = $es_conf->{nodes};
381         my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
382         my $es_status->{version} = $es->info->{version}->{number};
383
384         foreach my $index ( @indexes ) {
385             my $index_count;
386             try {
387                 $index_count = $es->indices->stats( index => $index )
388                       ->{_all}{primaries}{docs}{count};
389             }
390             catch {
391                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
392                     push @{ $es_status->{errors} }, "Index not found ($index)";
393                     $index_count = -1;
394                 }
395                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
396                     $es_running = 0;
397                 }
398                 else {
399                     # TODO: when time comes, we will cover more use cases
400                     die $_;
401                 }
402             };
403
404             my $db_count = -1;
405             my $missing_count = 0;
406             if ( $index eq $biblios_index_name ) {
407                 $db_count = Koha::Biblios->search->count;
408             } elsif ( $index eq $authorities_index_name ) {
409                 $db_count = Koha::Authorities->search->count;
410             }
411             if ( $db_count != -1 && $index_count != -1 ) {
412                 $missing_count = $db_count - $index_count;
413                 $es_has_missing = 1 if $missing_count > 0;
414             }
415             push @{ $es_status->{indexes} },
416               {
417                 index_name    => $index,
418                 index_count   => $index_count,
419                 db_count      => $db_count,
420                 missing_count => $missing_count,
421               };
422         }
423         $es_status->{running} = $es_running;
424
425         $template->param(
426             elasticsearch_status      => $es_status,
427             elasticsearch_has_missing => $es_has_missing,
428         );
429     }
430 }
431
432 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
433     # Do we have the required deps?
434     unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
435         $template->param( oauth2_missing_deps => 1 );
436     }
437 }
438
439 # Sco Patron should not contain any other perms than circulate => self_checkout
440 if (  C4::Context->preference('WebBasedSelfCheck')
441       and C4::Context->preference('AutoSelfCheckAllowed')
442 ) {
443     my $userid = C4::Context->preference('AutoSelfCheckID');
444     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
445     my ( $has_self_checkout_perm, $has_other_permissions );
446     while ( my ( $module, $permissions ) = each %$all_permissions ) {
447         if ( $module eq 'self_check' ) {
448             while ( my ( $permission, $flag ) = each %$permissions ) {
449                 if ( $permission eq 'self_checkout_module' ) {
450                     $has_self_checkout_perm = 1;
451                 } else {
452                     $has_other_permissions = 1;
453                 }
454             }
455         } else {
456             $has_other_permissions = 1;
457         }
458     }
459     $template->param(
460         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
461         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
462     );
463 }
464
465 # Test YAML system preferences
466 # FIXME: This is list of current YAML formatted prefs, should by type of preference
467 my @yaml_prefs = (
468     "UpdateNotForLoanStatusOnCheckin",
469     "OpacHiddenItems",
470     "BibtexExportAdditionalFields",
471     "RisExportAdditionalFields",
472     "UpdateItemWhenLostFromHoldList",
473     "MarcFieldsToOrder",
474     "MarcItemFieldsToOrder",
475     "UpdateitemLocationOnCheckin",
476     "ItemsDeniedRenewal"
477 );
478 my @bad_yaml_prefs;
479 foreach my $syspref (@yaml_prefs) {
480     my $yaml = C4::Context->preference( $syspref );
481     if ( $yaml ) {
482         eval { YAML::XS::Load( Encode::encode_utf8("$yaml\n\n") ); };
483         if ($@) {
484             push @bad_yaml_prefs, $syspref;
485         }
486     }
487 }
488 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
489
490 {
491     my $dbh       = C4::Context->dbh;
492     my $patrons = $dbh->selectall_arrayref(
493         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
494         { Slice => {} }
495     );
496     my $biblios = $dbh->selectall_arrayref(
497         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
498         { Slice => {} }
499     );
500     my $items = $dbh->selectall_arrayref(
501         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
502         { Slice => {} }
503     );
504     my $checkouts = $dbh->selectall_arrayref(
505         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
506         { Slice => {} }
507     );
508     my $holds = $dbh->selectall_arrayref(
509         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
510         { Slice => {} }
511     );
512     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
513         $template->param(
514             has_ai_issues => 1,
515             ai_patrons    => $patrons,
516             ai_biblios    => $biblios,
517             ai_items      => $items,
518             ai_checkouts  => $checkouts,
519             ai_holds      => $holds,
520         );
521     }
522 }
523
524 # Circ rule warnings
525 {
526     my $dbh   = C4::Context->dbh;
527     my $units = Koha::CirculationRules->search({ rule_name => 'lengthunit', rule_value => { -not_in => ['days', 'hours'] } });
528
529     if ( $units->count ) {
530         $template->param(
531             warnIssuingRules => 1,
532             ir_units         => $units,
533         );
534     }
535 }
536
537 # Guarantor relationships warnings
538 {
539     my $dbh   = C4::Context->dbh;
540     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
541         SELECT COUNT(*)
542         FROM (
543             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
544             UNION ALL
545             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
546     });
547
548     $bad_relationships_count = $bad_relationships_count->[0]->[0];
549
550     my $existing_relationships = $dbh->selectall_arrayref(q{
551           SELECT DISTINCT(relationship)
552           FROM (
553               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
554               UNION ALL
555               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
556     });
557
558     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
559     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
560
561     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
562     if ( @$wrong_relationships or $bad_relationships_count ) {
563
564         $template->param(
565             warnRelationships => 1,
566         );
567
568         if ( $wrong_relationships ) {
569             $template->param(
570                 wrong_relationships => $wrong_relationships
571             );
572         }
573         if ($bad_relationships_count) {
574             $template->param(
575                 bad_relationships_count => $bad_relationships_count,
576             );
577         }
578     }
579 }
580
581 {
582     # Test 'bcrypt_settings' config for Pseudonymization
583     $template->param( config_bcrypt_settings_no_set => 1 )
584       if C4::Context->preference('Pseudonymization')
585       and not C4::Context->config('bcrypt_settings');
586 }
587
588 {
589     my @frameworkcodes = Koha::BiblioFrameworks->search->get_column('frameworkcode');
590     my @hidden_biblionumbers;
591     push @frameworkcodes, ""; # it's not in the biblio_frameworks table!
592     my $no_FA_framework = 1;
593     for my $frameworkcode ( @frameworkcodes ) {
594         $no_FA_framework = 0 if $frameworkcode eq 'FA';
595         my $shouldhidemarc_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
596             {
597                 frameworkcode => $frameworkcode,
598                 interface     => "opac"
599             }
600         );
601         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'opac' }
602           if $shouldhidemarc_opac->{biblionumber};
603
604         my $shouldhidemarc_intranet = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
605             {
606                 frameworkcode => $frameworkcode,
607                 interface     => "intranet"
608             }
609         );
610         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'intranet' }
611           if $shouldhidemarc_intranet->{biblionumber};
612     }
613     $template->param( warnHiddenBiblionumbers => \@hidden_biblionumbers );
614     $template->param( warnFastCataloging => $no_FA_framework );
615 }
616
617 {
618     # BackgroundJob - test connection to message broker
619     eval {
620         Koha::BackgroundJob->connect;
621     };
622     if ( $@ ) {
623         warn $@;
624         $template->param( warnConnectBroker => $@ );
625     }
626 }
627
628 #BZ 28267: Warn administrators if there are database rows with a format other than 'DYNAMIC'
629 {
630     $template->param( warnDbRowFormat => C4::Installer->has_non_dynamic_row_format );
631 }
632
633 my %versions = C4::Context::get_versions();
634
635 $template->param(
636     kohaVersion   => $versions{'kohaVersion'},
637     osVersion     => $versions{'osVersion'},
638     perlPath      => $perl_path,
639     perlVersion   => $versions{'perlVersion'},
640     perlIncPath   => [ map { perlinc => $_ }, @INC ],
641     mysqlVersion  => $versions{'mysqlVersion'},
642     apacheVersion => $versions{'apacheVersion'},
643     zebraVersion  => $zebraVersion,
644     prefRequireChoosingExistingAuthority => $prefRequireChoosingExistingAuthority,
645     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
646     warnPrefRequireChoosingExistingAuthority => $warnPrefRequireChoosingExistingAuthority,
647     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
648     warnPrefAnonymousPatronOPACPrivacy        => $warnPrefAnonymousPatronOPACPrivacy,
649     warnPrefAnonymousPatronAnonSuggestions    => $warnPrefAnonymousPatronAnonSuggestions,
650     warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist     => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
651     warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
652     warnPrefKohaAdminEmailAddress => $warnPrefKohaAdminEmailAddress,
653     warnPrefOpacHiddenItems => $warnPrefOpacHiddenItems,
654     errZebraConnection => $errZebraConnection,
655     warnIsRootUser => $warnIsRootUser,
656     warnNoActiveCurrency => $warnNoActiveCurrency,
657     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
658     xml_config_warnings => \@xml_config_warnings,
659     warnStatisticsFieldsError => $warnStatisticsFieldsError,
660 );
661
662 my @components = ();
663
664 my $perl_modules = C4::Installer::PerlModules->new;
665 $perl_modules->versions_info;
666
667 my @pm_types = qw(missing_pm upgrade_pm current_pm);
668
669 foreach my $pm_type(@pm_types) {
670     my $modules = $perl_modules->get_attr($pm_type);
671     foreach (@$modules) {
672         my ($module, $stats) = each %$_;
673         push(
674             @components,
675             {
676                 name    => $module,
677                 version => $stats->{'cur_ver'},
678                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
679                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
680                 current => ($pm_type eq 'current_pm' ? 1 : 0),
681                 require => $stats->{'required'},
682                 reqversion => $stats->{'min_ver'},
683                 maxversion => $stats->{'max_ver'},
684                 excversion => $stats->{'exc_ver'}
685             }
686         );
687     }
688 }
689
690 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
691
692 my $counter=0;
693 my $row = [];
694 my $table = [];
695 foreach (@components) {
696     push (@$row, $_);
697     unless (++$counter % 4) {
698         push (@$table, {row => $row});
699         $row = [];
700     }
701 }
702 # Processing the last line (if there are any modules left)
703 if (scalar(@$row) > 0) {
704     # Extending $row to the table size
705     $$row[3] = '';
706     # Pushing the last line
707     push (@$table, {row => $row});
708 }
709 ## ## $table
710
711 $template->param( table => $table );
712
713
714 ## ------------------------------------------
715 ## Koha contributions
716 my $docdir;
717 if ( defined C4::Context->config('docdir') ) {
718     $docdir = C4::Context->config('docdir');
719 } else {
720     # if no <docdir> is defined in koha-conf.xml, use the default location
721     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
722     $docdir = C4::Context->config('intranetdir') . '/docs';
723 }
724
725 ## Release teams
726 my $teams =
727   -e "$docdir" . "/teams.yaml"
728   ? YAML::XS::LoadFile( "$docdir" . "/teams.yaml" )
729   : {};
730 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
731 my $short_version = substr($versions{'kohaVersion'},0,5);
732 my $minor = substr($versions{'kohaVersion'},3,2);
733 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
734 my $codename;
735 $template->param( short_version => $short_version );
736 $template->param( development_version => $development_version );
737
738 ## Contributors
739 my $contributors =
740   -e "$docdir" . "/contributors.yaml"
741   ? YAML::XS::LoadFile( "$docdir" . "/contributors.yaml" )
742   : {};
743 delete $contributors->{_others_};
744 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
745     for my $role ( keys %{ $teams->{team}->{$version} } ) {
746         my $normalized_role = "$role";
747         $normalized_role =~ s/s$//;
748         if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
749             for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
750                 my $name = $contributor->{name};
751                 # Add role to contributors
752                 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
753                   $version;
754                 # Add openhub to teams
755                 if ( exists( $contributors->{$name}->{openhub} ) ) {
756                     $contributor->{openhub} = $contributors->{$name}->{openhub};
757                 }
758             }
759         }
760         elsif ( $role eq 'release_date' ) {
761             $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
762         }
763         elsif ( $role eq 'codename' ) {
764             if ( $version == $short_version ) {
765                 $codename = $teams->{team}->{$version}->{$role};
766             }
767             next;
768         }
769         else {
770             my $name = $teams->{team}->{$version}->{$role}->{name};
771             # Add role to contributors
772             push @{ $contributors->{$name}->{roles}->{$normalized_role} },
773               $version;
774             # Add openhub to teams
775             if ( exists( $contributors->{$name}->{openhub} ) ) {
776                 $teams->{team}->{$version}->{$role}->{openhub} =
777                   $contributors->{$name}->{openhub};
778             }
779         }
780     }
781 }
782
783 ## Create last name ordered array of people from contributors
784 my @people = map {
785     { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
786 } sort {
787   my ($alast) = $a =~ /(\S+)$/;
788   my ($blast) = $b =~ /(\S+)$/;
789   my $cmp = lc($alast||"") cmp lc($blast||"");
790   return $cmp if $cmp;
791
792   my ($a2last) = $a =~ /(\S+)\s\S+$/;
793   my ($b2last) = $b =~ /(\S+)\s\S+$/;
794   lc($a2last||"") cmp lc($b2last||"");
795 } keys %$contributors;
796
797 $template->param( kohaCodename  => $codename);
798 $template->param( contributors => \@people );
799 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
800 $template->param( release_team => $teams->{team}->{$short_version} );
801
802 ## Timeline
803 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
804
805     my $i = 0;
806
807     my @rows2 = ();
808     my $row2  = [];
809
810     my @lines = <$file>;
811     close($file);
812
813     shift @lines; #remove header row
814
815     foreach (@lines) {
816         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
817         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
818             ($date, $desc)= ($`, $');
819         }
820         push(
821             @rows2,
822             {
823                 date => $date,
824                 desc => $desc,
825             }
826         );
827     }
828
829     my $table2 = [];
830     #foreach my $row2 (@rows2) {
831     foreach  (@rows2) {
832         push (@$row2, $_);
833         push( @$table2, { row2 => $row2 } );
834         $row2 = [];
835     }
836
837     $template->param( table2 => $table2 );
838 } else {
839     $template->param( timeline_read_error => 1 );
840 }
841
842 output_html_with_http_headers $query, $cookie, $template->output;