Fix translations for Koha 19.05.13
[koha.git] / about.pl
blobc2b82d7be723c5022bd88206d0bd76211e0e6dda
1 #!/usr/bin/perl
3 # Copyright Pat Eyler 2003
4 # Copyright Biblibre 2006
5 # Parts Copyright Liblime 2008
6 # Parts Copyright Chris Nighswonger 2010
8 # This file is part of Koha.
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.
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.
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>.
23 use Modern::Perl;
25 use CGI qw ( -utf8 );
26 use DateTime::TimeZone;
27 use File::Spec;
28 use List::MoreUtils qw/ any /;
29 use LWP::Simple;
30 use Module::Load::Conditional qw(can_load);
31 use XML::Simple;
32 use Config;
33 use Search::Elasticsearch;
34 use Try::Tiny;
35 use YAML qw/LoadFile/;
37 use C4::Output;
38 use C4::Auth;
39 use C4::Context;
40 use C4::Installer;
42 use Koha;
43 use Koha::DateUtils qw(dt_from_string output_pref);
44 use Koha::Acquisition::Currencies;
45 use Koha::Patron::Categories;
46 use Koha::Patrons;
47 use Koha::Caches;
48 use Koha::Config::SysPrefs;
49 use Koha::Illrequest::Config;
50 use Koha::SearchEngine::Elasticsearch;
52 use C4::Members::Statistics;
55 #use Smart::Comments '####';
57 my $query = new CGI;
58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60 template_name => "about.tt",
61 query => $query,
62 type => "intranet",
63 authnotrequired => 0,
64 flagsrequired => { catalogue => 1 },
65 debug => 1,
69 my $config_timezone = C4::Context->config('timezone') // '';
70 my $config_invalid = !DateTime::TimeZone->is_valid_name( $config_timezone );
71 my $env_timezone = $ENV{TZ} // '';
72 my $env_invalid = !DateTime::TimeZone->is_valid_name( $env_timezone );
73 my $actual_bad_tz_fallback = 0;
75 if ( $config_timezone ne '' &&
76 $config_invalid ) {
77 # Bad config
78 $actual_bad_tz_fallback = 1;
80 elsif ( $config_timezone eq '' &&
81 $env_timezone ne '' &&
82 $env_invalid ) {
83 # No config, but bad ENV{TZ}
84 $actual_bad_tz_fallback = 1;
87 my $time_zone = {
88 actual => C4::Context->tz->name,
89 actual_bad_tz_fallback => $actual_bad_tz_fallback,
90 config => $config_timezone,
91 config_invalid => $config_invalid,
92 environment => $env_timezone,
93 environment_invalid => $env_invalid
96 $template->param(
97 time_zone => $time_zone,
98 current_date_and_time => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
101 my $perl_path = $^X;
102 if ($^O ne 'VMS') {
103 $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
106 my $zebraVersion = `zebraidx -V`;
108 # Check running PSGI env
109 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
110 $template->param(
111 is_psgi => 1,
112 psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
113 ($ENV{ MOD_PERL }) ? "mod_perl ($ENV{MOD_PERL})" :
114 'Unknown'
118 # Memcached configuration
119 my $memcached_servers = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
120 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
122 my $cache = Koha::Caches->get_instance;
123 my $effective_caching_method = ref($cache->cache);
124 # Memcached may have been running when plack has been initialized but could have been stopped since
125 # FIXME What are the consequences of that??
126 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
128 my $where_is_memcached_config = 'nowhere';
129 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
130 $where_is_memcached_config = 'both';
131 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
132 $where_is_memcached_config = 'ENV_only';
133 } elsif ( C4::Context->config('memcached_servers') ) {
134 $where_is_memcached_config = 'config_only';
137 $template->param(
138 effective_caching_method => $effective_caching_method,
139 memcached_servers => $memcached_servers,
140 memcached_namespace => $memcached_namespace,
141 is_memcached_still_active => $is_memcached_still_active,
142 where_is_memcached_config => $where_is_memcached_config,
143 memcached_running => Koha::Caches->get_instance->memcached_cache,
146 # Additional system information for warnings
148 my $warnStatisticsFieldsError;
149 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
150 if ($prefStatisticsFields) {
151 $warnStatisticsFieldsError = $prefStatisticsFields
152 unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
155 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
156 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
157 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
159 my $prefEasyAnalyticalRecords = C4::Context->preference('EasyAnalyticalRecords');
160 my $prefUseControlNumber = C4::Context->preference('UseControlNumber');
161 my $warnPrefEasyAnalyticalRecords = ( $prefEasyAnalyticalRecords && $prefUseControlNumber );
162 my $warnPrefAnonymousPatron = (
163 C4::Context->preference('OPACPrivacy')
164 and not C4::Context->preference('AnonymousPatron')
167 my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
168 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
170 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
172 my $warnIsRootUser = (! $loggedinuser);
174 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
176 my @xml_config_warnings;
178 my $context = new C4::Context;
180 if ( C4::Context->config('zebra_bib_index_mode')
181 and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
183 push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
186 if ( C4::Context->config('zebra_auth_index_mode')
187 and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
189 push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
192 if( ( C4::Context->config('zebra_auth_index_mode')
193 and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
194 && ( $context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/ ) )
196 push @xml_config_warnings, {
197 error => 'zebra_auth_index_mode_mismatch_warn'
201 if ( ! defined C4::Context->config('log4perl_conf') ) {
202 push @xml_config_warnings, {
203 error => 'log4perl_entry_missing'
207 if ( ! defined C4::Context->config('upload_path') ) {
208 if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
209 # OPACBaseURL seems to be set
210 push @xml_config_warnings, {
211 error => 'uploadpath_entry_missing'
213 } else {
214 push @xml_config_warnings, {
215 error => 'uploadpath_and_opacbaseurl_entry_missing'
220 if ( ! C4::Context->config('tmp_path') ) {
221 my $temporary_directory = C4::Context::temporary_directory;
222 push @xml_config_warnings, {
223 error => 'tmp_path_missing',
224 effective_tmp_dir => $temporary_directory,
228 # Test QueryParser configuration sanity
229 if ( C4::Context->preference( 'UseQueryParser' ) ) {
230 # Get the QueryParser configuration file name
231 my $queryparser_file = C4::Context->config( 'queryparser_config' );
232 my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
233 # Check QueryParser is functional
234 my $QParser = C4::Context->queryparser();
235 my $queryparser_error = {};
236 if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
237 # Error initializing the QueryParser object
238 # Get the used queryparser.yaml file path to report the user
239 $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
240 $queryparser_error->{ file } = ( defined $queryparser_file )
241 ? $queryparser_file
242 : $queryparser_fallback_file;
243 # Report error data to the template
244 $template->param( QueryParserError => $queryparser_error );
245 } else {
246 # Check for an absent queryparser_config entry in koha-conf.xml
247 if ( ! defined $queryparser_file ) {
248 # Not an error but a warning for the missing entry in koha-conf-xml
249 push @xml_config_warnings, {
250 error => 'queryparser_entry_missing',
251 file => $queryparser_fallback_file
257 # Test Zebra facets configuration
258 if ( !defined C4::Context->config('use_zebra_facets') ) {
259 push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
262 # ILL module checks
263 if ( C4::Context->preference('ILLModule') ) {
264 my $warnILLConfiguration = 0;
265 my $ill_config_from_file = C4::Context->config("interlibrary_loans");
266 my $ill_config = Koha::Illrequest::Config->new;
268 my $available_ill_backends =
269 ( scalar @{ $ill_config->available_backends } > 0 );
271 # Check backends
272 if ( !$available_ill_backends ) {
273 $template->param( no_ill_backends => 1 );
274 $warnILLConfiguration = 1;
277 # Check partner_code
278 if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
279 $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
280 $warnILLConfiguration = 1;
283 if ( !$ill_config_from_file->{partner_code} ) {
284 # partner code not defined
285 $template->param( ill_partner_code_not_defined => 1 );
286 $warnILLConfiguration = 1;
290 if ( !$ill_config_from_file->{branch} ) {
291 # branch not defined
292 $template->param( ill_branch_not_defined => 1 );
293 $warnILLConfiguration = 1;
296 $template->param( warnILLConfiguration => $warnILLConfiguration );
299 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
300 # Check ES configuration health and runtime status
302 my $es_status;
303 my $es_config_error;
304 my $es_running = 1;
306 my $es_conf;
307 try {
308 $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
310 catch {
311 if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
312 $template->param( elasticsearch_fatal_config_error => $_->message );
313 $es_config_error = 1;
316 if ( !$es_config_error ) {
318 my $biblios_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
319 my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
321 my @indexes = ($biblios_index_name, $authorities_index_name);
322 # TODO: When new indexes get added, we could have other ways to
323 # fetch the list of available indexes (e.g. plugins, etc)
324 $es_status->{nodes} = $es_conf->{nodes};
325 my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
327 foreach my $index ( @indexes ) {
328 my $count;
329 try {
330 $count = $es->indices->stats( index => $index )
331 ->{_all}{primaries}{docs}{count};
333 catch {
334 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
335 push @{ $es_status->{errors} }, "Index not found ($index)";
336 $count = -1;
338 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
339 $es_running = 0;
341 else {
342 # TODO: when time comes, we will cover more use cases
343 die $_;
347 push @{ $es_status->{indexes} },
349 index_name => $index,
350 count => $count
353 $es_status->{running} = $es_running;
355 $template->param( elasticsearch_status => $es_status );
359 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
360 # Do we have the required deps?
361 unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
362 $template->param( oauth2_missing_deps => 1 );
366 # Sco Patron should not contain any other perms than circulate => self_checkout
367 if ( C4::Context->preference('WebBasedSelfCheck')
368 and C4::Context->preference('AutoSelfCheckAllowed')
370 my $userid = C4::Context->preference('AutoSelfCheckID');
371 my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
372 my ( $has_self_checkout_perm, $has_other_permissions );
373 while ( my ( $module, $permissions ) = each %$all_permissions ) {
374 if ( $module eq 'self_check' ) {
375 while ( my ( $permission, $flag ) = each %$permissions ) {
376 if ( $permission eq 'self_checkout_module' ) {
377 $has_self_checkout_perm = 1;
378 } else {
379 $has_other_permissions = 1;
382 } else {
383 $has_other_permissions = 1;
386 $template->param(
387 AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
388 AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
392 # Test YAML system preferences
393 # FIXME: This is list of current YAML formatted prefs, should by type of preference
394 my @yaml_prefs = (
395 "UpdateNotForLoanStatusOnCheckin",
396 "OpacHiddenItems",
397 "BibtexExportAdditionalFields",
398 "RisExportAdditionalFields",
399 "UpdateItemWhenLostFromHoldList",
400 "MarcFieldsToOrder",
401 "MarcItemFieldsToOrder",
402 "UpdateitemLocationOnCheckin",
403 "ItemsDeniedRenewal"
405 my @bad_yaml_prefs;
406 foreach my $syspref (@yaml_prefs) {
407 my $yaml = C4::Context->preference( $syspref );
408 if ( $yaml ) {
409 eval { YAML::Load( "$yaml\n\n" ); };
410 if ($@) {
411 push @bad_yaml_prefs, $syspref;
415 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
418 my $dbh = C4::Context->dbh;
419 my $patrons = $dbh->selectall_arrayref(
420 q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
421 { Slice => {} }
423 my $biblios = $dbh->selectall_arrayref(
424 q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
425 { Slice => {} }
427 my $items = $dbh->selectall_arrayref(
428 q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
429 { Slice => {} }
431 my $checkouts = $dbh->selectall_arrayref(
432 q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
433 { Slice => {} }
435 my $holds = $dbh->selectall_arrayref(
436 q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
437 { Slice => {} }
439 if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
440 $template->param(
441 has_ai_issues => 1,
442 ai_patrons => $patrons,
443 ai_biblios => $biblios,
444 ai_items => $items,
445 ai_checkouts => $checkouts,
446 ai_holds => $holds,
451 # Circ rule warnings
453 my $dbh = C4::Context->dbh;
454 my $units = $dbh->selectall_arrayref(
455 q|SELECT branchcode, categorycode, itemtype, lengthunit FROM issuingrules WHERE lengthunit NOT IN ( 'days', 'hours' ); |,
456 { Slice => {} }
459 if (@$units) {
460 $template->param(
461 warnIssuingRules => 1,
462 ir_units => $units,
466 my %versions = C4::Context::get_versions();
468 $template->param(
469 kohaVersion => $versions{'kohaVersion'},
470 osVersion => $versions{'osVersion'},
471 perlPath => $perl_path,
472 perlVersion => $versions{'perlVersion'},
473 perlIncPath => [ map { perlinc => $_ }, @INC ],
474 mysqlVersion => $versions{'mysqlVersion'},
475 apacheVersion => $versions{'apacheVersion'},
476 zebraVersion => $zebraVersion,
477 prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
478 prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
479 warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
480 warnPrefEasyAnalyticalRecords => $warnPrefEasyAnalyticalRecords,
481 warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
482 warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
483 errZebraConnection => $errZebraConnection,
484 warnIsRootUser => $warnIsRootUser,
485 warnNoActiveCurrency => $warnNoActiveCurrency,
486 warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
487 xml_config_warnings => \@xml_config_warnings,
488 warnStatisticsFieldsError => $warnStatisticsFieldsError,
491 my @components = ();
493 my $perl_modules = C4::Installer::PerlModules->new;
494 $perl_modules->versions_info;
496 my @pm_types = qw(missing_pm upgrade_pm current_pm);
498 foreach my $pm_type(@pm_types) {
499 my $modules = $perl_modules->get_attr($pm_type);
500 foreach (@$modules) {
501 my ($module, $stats) = each %$_;
502 push(
503 @components,
505 name => $module,
506 version => $stats->{'cur_ver'},
507 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
508 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
509 current => ($pm_type eq 'current_pm' ? 1 : 0),
510 require => $stats->{'required'},
511 reqversion => $stats->{'min_ver'},
517 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
519 my $counter=0;
520 my $row = [];
521 my $table = [];
522 foreach (@components) {
523 push (@$row, $_);
524 unless (++$counter % 4) {
525 push (@$table, {row => $row});
526 $row = [];
529 # Processing the last line (if there are any modules left)
530 if (scalar(@$row) > 0) {
531 # Extending $row to the table size
532 $$row[3] = '';
533 # Pushing the last line
534 push (@$table, {row => $row});
536 ## ## $table
538 $template->param( table => $table );
541 ## ------------------------------------------
542 ## Koha contributions
543 my $docdir;
544 if ( defined C4::Context->config('docdir') ) {
545 $docdir = C4::Context->config('docdir');
546 } else {
547 # if no <docdir> is defined in koha-conf.xml, use the default location
548 # this is a work-around to stop breakage on upgraded Kohas, bug 8911
549 $docdir = C4::Context->config('intranetdir') . '/docs';
552 ## Release teams
553 my $teams =
554 -e "$docdir" . "/teams.yaml"
555 ? LoadFile( "$docdir" . "/teams.yaml" )
556 : {};
557 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
558 my $short_version = substr($versions{'kohaVersion'},0,5);
559 my $minor = substr($versions{'kohaVersion'},3,2);
560 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
561 $template->param( short_version => $short_version );
562 $template->param( development_version => $development_version );
564 ## Contributors
565 my $contributors =
566 -e "$docdir" . "/contributors.yaml"
567 ? LoadFile( "$docdir" . "/contributors.yaml" )
568 : {};
569 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
570 for my $role ( keys %{ $teams->{team}->{$version} } ) {
571 my $normalized_role = "$role";
572 $normalized_role =~ s/s$//;
573 if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
574 for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
575 my $name = $contributor->{name};
576 # Add role to contributors
577 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
578 $version;
579 # Add openhub to teams
580 if ( exists( $contributors->{$name}->{openhub} ) ) {
581 $contributor->{openhub} = $contributors->{$name}->{openhub};
585 elsif ( $role ne 'release_date' ) {
586 my $name = $teams->{team}->{$version}->{$role}->{name};
587 # Add role to contributors
588 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
589 $version;
590 # Add openhub to teams
591 if ( exists( $contributors->{$name}->{openhub} ) ) {
592 $teams->{team}->{$version}->{$role}->{openhub} =
593 $contributors->{$name}->{openhub};
596 else {
597 $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
602 ## Create last name ordered array of people from contributors
603 my @people = map {
604 { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
605 } sort {
606 my ($alast) = ( split( /\s/, $a ) )[-1];
607 my ($blast) = ( split( /\s/, $b ) )[-1];
608 lc($alast) cmp lc($blast)
609 } keys %{$contributors};
611 $template->param( contributors => \@people );
612 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
613 $template->param( release_team => $teams->{team}->{$short_version} );
615 ## Timeline
616 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
618 my $i = 0;
620 my @rows2 = ();
621 my $row2 = [];
623 my @lines = <$file>;
624 close($file);
626 shift @lines; #remove header row
628 foreach (@lines) {
629 my ( $epoch, $date, $desc, $tag ) = split(/\t/);
630 if(!$desc && $date=~ /(?<=\d{4})\s+/) {
631 ($date, $desc)= ($`, $');
633 push(
634 @rows2,
636 date => $date,
637 desc => $desc,
642 my $table2 = [];
643 #foreach my $row2 (@rows2) {
644 foreach (@rows2) {
645 push (@$row2, $_);
646 push( @$table2, { row2 => $row2 } );
647 $row2 = [];
650 $template->param( table2 => $table2 );
651 } else {
652 $template->param( timeline_read_error => 1 );
655 output_html_with_http_headers $query, $cookie, $template->output;