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