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