Translation updates for Koha 18.11.04
[koha.git] / about.pl
blob349dfc966848b07023961a031ba711d4b5d955dd
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;
36 use C4::Output;
37 use C4::Auth;
38 use C4::Context;
39 use C4::Installer;
41 use Koha;
42 use Koha::DateUtils qw(dt_from_string output_pref);
43 use Koha::Acquisition::Currencies;
44 use Koha::Patron::Categories;
45 use Koha::Patrons;
46 use Koha::Caches;
47 use Koha::Config::SysPrefs;
48 use Koha::Illrequest::Config;
49 use Koha::SearchEngine::Elasticsearch;
51 use C4::Members::Statistics;
54 #use Smart::Comments '####';
56 my $query = new CGI;
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
59 template_name => "about.tt",
60 query => $query,
61 type => "intranet",
62 authnotrequired => 0,
63 flagsrequired => { catalogue => 1 },
64 debug => 1,
68 my $config_timezone = C4::Context->config('timezone') // '';
69 my $config_invalid = !DateTime::TimeZone->is_valid_name( $config_timezone );
70 my $env_timezone = $ENV{TZ} // '';
71 my $env_invalid = !DateTime::TimeZone->is_valid_name( $env_timezone );
72 my $actual_bad_tz_fallback = 0;
74 if ( $config_timezone ne '' &&
75 $config_invalid ) {
76 # Bad config
77 $actual_bad_tz_fallback = 1;
79 elsif ( $config_timezone eq '' &&
80 $env_timezone ne '' &&
81 $env_invalid ) {
82 # No config, but bad ENV{TZ}
83 $actual_bad_tz_fallback = 1;
86 my $time_zone = {
87 actual => C4::Context->tz->name,
88 actual_bad_tz_fallback => $actual_bad_tz_fallback,
89 config => $config_timezone,
90 config_invalid => $config_invalid,
91 environment => $env_timezone,
92 environment_invalid => $env_invalid
95 $template->param(
96 time_zone => $time_zone,
97 current_date_and_time => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
100 my $perl_path = $^X;
101 if ($^O ne 'VMS') {
102 $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
105 my $zebraVersion = `zebraidx -V`;
107 # Check running PSGI env
108 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
109 $template->param(
110 is_psgi => 1,
111 psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
112 ($ENV{ MOD_PERL }) ? "mod_perl ($ENV{MOD_PERL})" :
113 'Unknown'
117 # Memcached configuration
118 my $memcached_servers = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
119 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
121 my $cache = Koha::Caches->get_instance;
122 my $effective_caching_method = ref($cache->cache);
123 # Memcached may have been running when plack has been initialized but could have been stopped since
124 # FIXME What are the consequences of that??
125 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
127 my $where_is_memcached_config = 'nowhere';
128 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
129 $where_is_memcached_config = 'both';
130 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
131 $where_is_memcached_config = 'ENV_only';
132 } elsif ( C4::Context->config('memcached_servers') ) {
133 $where_is_memcached_config = 'config_only';
136 $template->param(
137 effective_caching_method => $effective_caching_method,
138 memcached_servers => $memcached_servers,
139 memcached_namespace => $memcached_namespace,
140 is_memcached_still_active => $is_memcached_still_active,
141 where_is_memcached_config => $where_is_memcached_config,
142 memcached_running => Koha::Caches->get_instance->memcached_cache,
145 # Additional system information for warnings
147 my $warnStatisticsFieldsError;
148 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
149 if ($prefStatisticsFields) {
150 $warnStatisticsFieldsError = $prefStatisticsFields
151 unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
154 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
155 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
156 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
158 my $prefEasyAnalyticalRecords = C4::Context->preference('EasyAnalyticalRecords');
159 my $prefUseControlNumber = C4::Context->preference('UseControlNumber');
160 my $warnPrefEasyAnalyticalRecords = ( $prefEasyAnalyticalRecords && $prefUseControlNumber );
161 my $warnPrefAnonymousPatron = (
162 C4::Context->preference('OPACPrivacy')
163 and not C4::Context->preference('AnonymousPatron')
166 my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
167 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
169 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
171 my $warnIsRootUser = (! $loggedinuser);
173 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
175 my @xml_config_warnings;
177 my $context = new C4::Context;
179 if ( C4::Context->config('zebra_bib_index_mode')
180 and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
182 push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
185 if ( C4::Context->config('zebra_auth_index_mode')
186 and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
188 push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
191 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
192 push @xml_config_warnings, {
193 error => 'zebra_auth_index_mode_mismatch_warn'
197 if ( ! defined C4::Context->config('log4perl_conf') ) {
198 push @xml_config_warnings, {
199 error => 'log4perl_entry_missing'
203 if ( ! defined C4::Context->config('upload_path') ) {
204 if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
205 # OPACBaseURL seems to be set
206 push @xml_config_warnings, {
207 error => 'uploadpath_entry_missing'
209 } else {
210 push @xml_config_warnings, {
211 error => 'uploadpath_and_opacbaseurl_entry_missing'
216 if ( ! C4::Context->config('tmp_path') ) {
217 my $temporary_directory = C4::Context::temporary_directory;
218 push @xml_config_warnings, {
219 error => 'tmp_path_missing',
220 effective_tmp_dir => $temporary_directory,
224 # Test QueryParser configuration sanity
225 if ( C4::Context->preference( 'UseQueryParser' ) ) {
226 # Get the QueryParser configuration file name
227 my $queryparser_file = C4::Context->config( 'queryparser_config' );
228 my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
229 # Check QueryParser is functional
230 my $QParser = C4::Context->queryparser();
231 my $queryparser_error = {};
232 if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
233 # Error initializing the QueryParser object
234 # Get the used queryparser.yaml file path to report the user
235 $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
236 $queryparser_error->{ file } = ( defined $queryparser_file )
237 ? $queryparser_file
238 : $queryparser_fallback_file;
239 # Report error data to the template
240 $template->param( QueryParserError => $queryparser_error );
241 } else {
242 # Check for an absent queryparser_config entry in koha-conf.xml
243 if ( ! defined $queryparser_file ) {
244 # Not an error but a warning for the missing entry in koha-conf-xml
245 push @xml_config_warnings, {
246 error => 'queryparser_entry_missing',
247 file => $queryparser_fallback_file
253 # Test Zebra facets configuration
254 if ( !defined C4::Context->config('use_zebra_facets') ) {
255 push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
258 # ILL module checks
259 if ( C4::Context->preference('ILLModule') ) {
260 my $warnILLConfiguration = 0;
261 my $ill_config_from_file = C4::Context->config("interlibrary_loans");
262 my $ill_config = Koha::Illrequest::Config->new;
264 my $available_ill_backends =
265 ( scalar @{ $ill_config->available_backends } > 0 );
267 # Check backends
268 if ( !$available_ill_backends ) {
269 $template->param( no_ill_backends => 1 );
270 $warnILLConfiguration = 1;
273 # Check partner_code
274 if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
275 $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
276 $warnILLConfiguration = 1;
279 if ( !$ill_config_from_file->{partner_code} ) {
280 # partner code not defined
281 $template->param( ill_partner_code_not_defined => 1 );
282 $warnILLConfiguration = 1;
286 if ( !$ill_config_from_file->{branch} ) {
287 # branch not defined
288 $template->param( ill_branch_not_defined => 1 );
289 $warnILLConfiguration = 1;
292 $template->param( warnILLConfiguration => $warnILLConfiguration );
295 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
296 # Check ES configuration health and runtime status
298 my $es_status;
299 my $es_config_error;
300 my $es_running = 1;
302 my $es_conf;
303 try {
304 $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
306 catch {
307 if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
308 $template->param( elasticsearch_fatal_config_error => $_->message );
309 $es_config_error = 1;
312 if ( !$es_config_error ) {
314 my $biblios_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
315 my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
317 my @indexes = ($biblios_index_name, $authorities_index_name);
318 # TODO: When new indexes get added, we could have other ways to
319 # fetch the list of available indexes (e.g. plugins, etc)
320 $es_status->{nodes} = $es_conf->{nodes};
321 my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
323 foreach my $index ( @indexes ) {
324 my $count;
325 try {
326 $count = $es->indices->stats( index => $index )
327 ->{_all}{primaries}{docs}{count};
329 catch {
330 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
331 push @{ $es_status->{errors} }, "Index not found ($index)";
332 $count = -1;
334 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
335 $es_running = 0;
337 else {
338 # TODO: when time comes, we will cover more use cases
339 die $_;
343 push @{ $es_status->{indexes} },
345 index_name => $index,
346 count => $count
349 $es_status->{running} = $es_running;
351 $template->param( elasticsearch_status => $es_status );
355 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
356 # Do we have the required deps?
357 unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
358 $template->param( oauth2_missing_deps => 1 );
362 # Sco Patron should not contain any other perms than circulate => self_checkout
363 if ( C4::Context->preference('WebBasedSelfCheck')
364 and C4::Context->preference('AutoSelfCheckAllowed')
366 my $userid = C4::Context->preference('AutoSelfCheckID');
367 my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
368 my ( $has_self_checkout_perm, $has_other_permissions );
369 while ( my ( $module, $permissions ) = each %$all_permissions ) {
370 if ( $module eq 'self_check' ) {
371 while ( my ( $permission, $flag ) = each %$permissions ) {
372 if ( $permission eq 'self_checkout_module' ) {
373 $has_self_checkout_perm = 1;
374 } else {
375 $has_other_permissions = 1;
378 } else {
379 $has_other_permissions = 1;
382 $template->param(
383 AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
384 AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
389 my $dbh = C4::Context->dbh;
390 my $patrons = $dbh->selectall_arrayref(
391 q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
392 { Slice => {} }
394 my $biblios = $dbh->selectall_arrayref(
395 q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
396 { Slice => {} }
398 my $items = $dbh->selectall_arrayref(
399 q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
400 { Slice => {} }
402 my $checkouts = $dbh->selectall_arrayref(
403 q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
404 { Slice => {} }
406 my $holds = $dbh->selectall_arrayref(
407 q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
408 { Slice => {} }
410 if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
411 $template->param(
412 has_ai_issues => 1,
413 ai_patrons => $patrons,
414 ai_biblios => $biblios,
415 ai_items => $items,
416 ai_checkouts => $checkouts,
417 ai_holds => $holds,
421 my %versions = C4::Context::get_versions();
423 $template->param(
424 kohaVersion => $versions{'kohaVersion'},
425 osVersion => $versions{'osVersion'},
426 perlPath => $perl_path,
427 perlVersion => $versions{'perlVersion'},
428 perlIncPath => [ map { perlinc => $_ }, @INC ],
429 mysqlVersion => $versions{'mysqlVersion'},
430 apacheVersion => $versions{'apacheVersion'},
431 zebraVersion => $zebraVersion,
432 prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
433 prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
434 warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
435 warnPrefEasyAnalyticalRecords => $warnPrefEasyAnalyticalRecords,
436 warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
437 warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
438 errZebraConnection => $errZebraConnection,
439 warnIsRootUser => $warnIsRootUser,
440 warnNoActiveCurrency => $warnNoActiveCurrency,
441 warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
442 xml_config_warnings => \@xml_config_warnings,
443 warnStatisticsFieldsError => $warnStatisticsFieldsError,
446 my @components = ();
448 my $perl_modules = C4::Installer::PerlModules->new;
449 $perl_modules->versions_info;
451 my @pm_types = qw(missing_pm upgrade_pm current_pm);
453 foreach my $pm_type(@pm_types) {
454 my $modules = $perl_modules->get_attr($pm_type);
455 foreach (@$modules) {
456 my ($module, $stats) = each %$_;
457 push(
458 @components,
460 name => $module,
461 version => $stats->{'cur_ver'},
462 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
463 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
464 current => ($pm_type eq 'current_pm' ? 1 : 0),
465 require => $stats->{'required'},
466 reqversion => $stats->{'min_ver'},
472 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
474 my $counter=0;
475 my $row = [];
476 my $table = [];
477 foreach (@components) {
478 push (@$row, $_);
479 unless (++$counter % 4) {
480 push (@$table, {row => $row});
481 $row = [];
484 # Processing the last line (if there are any modules left)
485 if (scalar(@$row) > 0) {
486 # Extending $row to the table size
487 $$row[3] = '';
488 # Pushing the last line
489 push (@$table, {row => $row});
491 ## ## $table
493 $template->param( table => $table );
496 ## ------------------------------------------
497 ## Koha time line code
499 #get file location
500 my $docdir;
501 if ( defined C4::Context->config('docdir') ) {
502 $docdir = C4::Context->config('docdir');
503 } else {
504 # if no <docdir> is defined in koha-conf.xml, use the default location
505 # this is a work-around to stop breakage on upgraded Kohas, bug 8911
506 $docdir = C4::Context->config('intranetdir') . '/docs';
509 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
511 my $i = 0;
513 my @rows2 = ();
514 my $row2 = [];
516 my @lines = <$file>;
517 close($file);
519 shift @lines; #remove header row
521 foreach (@lines) {
522 my ( $epoch, $date, $desc, $tag ) = split(/\t/);
523 if(!$desc && $date=~ /(?<=\d{4})\s+/) {
524 ($date, $desc)= ($`, $');
526 push(
527 @rows2,
529 date => $date,
530 desc => $desc,
535 my $table2 = [];
536 #foreach my $row2 (@rows2) {
537 foreach (@rows2) {
538 push (@$row2, $_);
539 push( @$table2, { row2 => $row2 } );
540 $row2 = [];
543 $template->param( table2 => $table2 );
544 } else {
545 $template->param( timeline_read_error => 1 );
548 output_html_with_http_headers $query, $cookie, $template->output;