Bug 7317: Add partner_code checks to abot page
[koha-equinox.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 List::MoreUtils qw/ any /;
27 use LWP::Simple;
28 use XML::Simple;
29 use Config;
30
31 use C4::Output;
32 use C4::Auth;
33 use C4::Context;
34 use C4::Installer;
35
36 use Koha;
37 use Koha::Acquisition::Currencies;
38 use Koha::Patron::Categories;
39 use Koha::Patrons;
40 use Koha::Caches;
41 use Koha::Config::SysPrefs;
42 use Koha::Illrequest::Config;
43 use C4::Members::Statistics;
44
45 #use Smart::Comments '####';
46
47 my $query = new CGI;
48 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
49     {
50         template_name   => "about.tt",
51         query           => $query,
52         type            => "intranet",
53         authnotrequired => 0,
54         flagsrequired   => { catalogue => 1 },
55         debug           => 1,
56     }
57 );
58
59 my $perl_path = $^X;
60 if ($^O ne 'VMS') {
61     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
62 }
63
64 my $zebraVersion = `zebraidx -V`;
65
66 # Check running PSGI env
67 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
68     $template->param(
69         is_psgi => 1,
70         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
71                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
72                                              'Unknown'
73     );
74 }
75
76 # Memcached configuration
77 my $memcached_servers   = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
78 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
79
80 my $cache = Koha::Caches->get_instance;
81 my $effective_caching_method = ref($cache->cache);
82 # Memcached may have been running when plack has been initialized but could have been stopped since
83 # FIXME What are the consequences of that??
84 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
85
86 my $where_is_memcached_config = 'nowhere';
87 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
88     $where_is_memcached_config = 'both';
89 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
90     $where_is_memcached_config = 'ENV_only';
91 } elsif ( C4::Context->config('memcached_servers') ) {
92     $where_is_memcached_config = 'config_only';
93 }
94
95 $template->param(
96     effective_caching_method => $effective_caching_method,
97     memcached_servers   => $memcached_servers,
98     memcached_namespace => $memcached_namespace,
99     is_memcached_still_active => $is_memcached_still_active,
100     where_is_memcached_config => $where_is_memcached_config,
101     memcached_running   => Koha::Caches->get_instance->memcached_cache,
102 );
103
104 # Additional system information for warnings
105
106 my $warnStatisticsFieldsError;
107 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
108 if ($prefStatisticsFields) {
109     $warnStatisticsFieldsError = $prefStatisticsFields
110         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
111 }
112
113 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
114 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
115 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
116
117 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
118 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
119 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
120 my $warnPrefAnonymousPatron = (
121     C4::Context->preference('OPACPrivacy')
122         and not C4::Context->preference('AnonymousPatron')
123 );
124
125 my $anonymous_patron = Koha::Patrons->find( C4::Context->preference('AnonymousPatron') );
126 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
127
128 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
129
130 my $warnIsRootUser   = (! $loggedinuser);
131
132 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
133
134 my @xml_config_warnings;
135
136 my $context = new C4::Context;
137
138 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
139     push @xml_config_warnings, {
140         error => 'zebra_bib_index_mode_warn'
141     };
142     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
143         push @xml_config_warnings, {
144             error => 'zebra_bib_mode_seems_grs1'
145         };
146     }
147     else {
148         push @xml_config_warnings, {
149             error => 'zebra_bib_mode_seems_dom'
150         };
151     }
152 } else {
153     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
154         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
155 }
156
157 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
158      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
159
160     push @xml_config_warnings, {
161         error => 'zebra_bib_index_mode_mismatch_warn'
162     };
163 }
164
165 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
166      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
167
168     push @xml_config_warnings, {
169         error => 'zebra_bib_index_mode_mismatch_warn'
170     };
171 }
172
173 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
174     push @xml_config_warnings, {
175         error => 'zebra_auth_index_mode_warn'
176     };
177     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
178         push @xml_config_warnings, {
179             error => 'zebra_auth_mode_seems_grs1'
180         };
181     }
182     else {
183         push @xml_config_warnings, {
184             error => 'zebra_auth_mode_seems_dom'
185         };
186     }
187 } else {
188     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
189         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
190 }
191
192 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
193     push @xml_config_warnings, {
194         error => 'zebra_auth_index_mode_mismatch_warn'
195     };
196 }
197
198 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
199     push @xml_config_warnings, {
200         error => 'zebra_auth_index_mode_mismatch_warn'
201     };
202 }
203
204 if ( ! defined C4::Context->config('log4perl_conf') ) {
205     push @xml_config_warnings, {
206         error => 'log4perl_entry_missing'
207     }
208 }
209
210 if ( ! defined C4::Context->config('upload_path') ) {
211     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
212         # OPACBaseURL seems to be set
213         push @xml_config_warnings, {
214             error => 'uploadpath_entry_missing'
215         }
216     } else {
217         push @xml_config_warnings, {
218             error => 'uploadpath_and_opacbaseurl_entry_missing'
219         }
220     }
221 }
222
223 # Test QueryParser configuration sanity
224 if ( C4::Context->preference( 'UseQueryParser' ) ) {
225     # Get the QueryParser configuration file name
226     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
227     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
228     # Check QueryParser is functional
229     my $QParser = C4::Context->queryparser();
230     my $queryparser_error = {};
231     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
232         # Error initializing the QueryParser object
233         # Get the used queryparser.yaml file path to report the user
234         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
235         $queryparser_error->{ file }     = ( defined $queryparser_file )
236                                                 ? $queryparser_file
237                                                 : $queryparser_fallback_file;
238         # Report error data to the template
239         $template->param( QueryParserError => $queryparser_error );
240     } else {
241         # Check for an absent queryparser_config entry in koha-conf.xml
242         if ( ! defined $queryparser_file ) {
243             # Not an error but a warning for the missing entry in koha-conf-xml
244             push @xml_config_warnings, {
245                     error => 'queryparser_entry_missing',
246                     file  => $queryparser_fallback_file
247             };
248         }
249     }
250 }
251
252 # Test Zebra facets configuration
253 if ( !defined C4::Context->config('use_zebra_facets') ) {
254     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
255 } else {
256     if ( C4::Context->config('use_zebra_facets') &&
257          C4::Context->config('zebra_bib_index_mode') ) {
258         # use_zebra_facets works with DOM
259         push @xml_config_warnings, {
260             error => 'use_zebra_facets_needs_dom'
261         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
262     }
263 }
264
265 # ILL module checks
266 if ( C4::Context->preference('ILLModule') ) {
267     my $warnILLConfiguration = 0;
268     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
269     my $ill_config = Koha::Illrequest::Config->new;
270
271     my $available_ill_backends =
272       ( scalar @{ $ill_config->available_backends } > 0 );
273
274     # Check backends
275     if ( !$available_ill_backends ) {
276         $template->param( no_ill_backends => 1 );
277         $warnILLConfiguration = 1;
278     }
279
280     # Check partner_code
281     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
282         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
283         $warnILLConfiguration = 1;
284     }
285
286     if ( !$ill_config_from_file->{partner_code} ) {
287         # partner code not defined
288         $template->param( ill_partner_code_not_defined => 1 );
289         $warnILLConfiguration = 1;
290     }
291
292     $template->param( warnILLConfiguration => $warnILLConfiguration );
293 }
294
295 # Sco Patron should not contain any other perms than circulate => self_checkout
296 if (  C4::Context->preference('WebBasedSelfCheck')
297       and C4::Context->preference('AutoSelfCheckAllowed')
298 ) {
299     my $userid = C4::Context->preference('AutoSelfCheckID');
300     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
301     my ( $has_self_checkout_perm, $has_other_permissions );
302     while ( my ( $module, $permissions ) = each %$all_permissions ) {
303         if ( $module eq 'circulate' ) {
304             while ( my ( $permission, $flag ) = each %$permissions ) {
305                 if ( $permission eq 'self_checkout' ) {
306                     $has_self_checkout_perm = 1;
307                 } else {
308                     $has_other_permissions = 1;
309                 }
310             }
311         } else {
312             $has_other_permissions = 1;
313         }
314     }
315     $template->param(
316         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
317         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
318     );
319 }
320
321 {
322     my $dbh       = C4::Context->dbh;
323     my $patrons = $dbh->selectall_arrayref(
324         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
325         { Slice => {} }
326     );
327     my $biblios = $dbh->selectall_arrayref(
328         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
329         { Slice => {} }
330     );
331     my $items = $dbh->selectall_arrayref(
332         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
333         { Slice => {} }
334     );
335     my $checkouts = $dbh->selectall_arrayref(
336         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
337         { Slice => {} }
338     );
339     my $holds = $dbh->selectall_arrayref(
340         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
341         { Slice => {} }
342     );
343     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
344         $template->param(
345             has_ai_issues => 1,
346             ai_patrons    => $patrons,
347             ai_biblios    => $biblios,
348             ai_items      => $items,
349             ai_checkouts  => $checkouts,
350             ai_holds      => $holds,
351         );
352     }
353 }
354 my %versions = C4::Context::get_versions();
355
356 $template->param(
357     kohaVersion   => $versions{'kohaVersion'},
358     osVersion     => $versions{'osVersion'},
359     perlPath      => $perl_path,
360     perlVersion   => $versions{'perlVersion'},
361     perlIncPath   => [ map { perlinc => $_ }, @INC ],
362     mysqlVersion  => $versions{'mysqlVersion'},
363     apacheVersion => $versions{'apacheVersion'},
364     zebraVersion  => $zebraVersion,
365     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
366     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
367     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
368     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
369     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
370     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
371     errZebraConnection => $errZebraConnection,
372     warnIsRootUser => $warnIsRootUser,
373     warnNoActiveCurrency => $warnNoActiveCurrency,
374     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
375     xml_config_warnings => \@xml_config_warnings,
376     warnStatisticsFieldsError => $warnStatisticsFieldsError,
377 );
378
379 my @components = ();
380
381 my $perl_modules = C4::Installer::PerlModules->new;
382 $perl_modules->versions_info;
383
384 my @pm_types = qw(missing_pm upgrade_pm current_pm);
385
386 foreach my $pm_type(@pm_types) {
387     my $modules = $perl_modules->get_attr($pm_type);
388     foreach (@$modules) {
389         my ($module, $stats) = each %$_;
390         push(
391             @components,
392             {
393                 name    => $module,
394                 version => $stats->{'cur_ver'},
395                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
396                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
397                 current => ($pm_type eq 'current_pm' ? 1 : 0),
398                 require => $stats->{'required'},
399                 reqversion => $stats->{'min_ver'},
400             }
401         );
402     }
403 }
404
405 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
406
407 my $counter=0;
408 my $row = [];
409 my $table = [];
410 foreach (@components) {
411     push (@$row, $_);
412     unless (++$counter % 4) {
413         push (@$table, {row => $row});
414         $row = [];
415     }
416 }
417 # Processing the last line (if there are any modules left)
418 if (scalar(@$row) > 0) {
419     # Extending $row to the table size
420     $$row[3] = '';
421     # Pushing the last line
422     push (@$table, {row => $row});
423 }
424 ## ## $table
425
426 $template->param( table => $table );
427
428
429 ## ------------------------------------------
430 ## Koha time line code
431
432 #get file location
433 my $docdir;
434 if ( defined C4::Context->config('docdir') ) {
435     $docdir = C4::Context->config('docdir');
436 } else {
437     # if no <docdir> is defined in koha-conf.xml, use the default location
438     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
439     $docdir = C4::Context->config('intranetdir') . '/docs';
440 }
441
442 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
443
444     my $i = 0;
445
446     my @rows2 = ();
447     my $row2  = [];
448
449     my @lines = <$file>;
450     close($file);
451
452     shift @lines; #remove header row
453
454     foreach (@lines) {
455         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
456         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
457             ($date, $desc)= ($`, $');
458         }
459         push(
460             @rows2,
461             {
462                 date => $date,
463                 desc => $desc,
464             }
465         );
466     }
467
468     my $table2 = [];
469     #foreach my $row2 (@rows2) {
470     foreach  (@rows2) {
471         push (@$row2, $_);
472         push( @$table2, { row2 => $row2 } );
473         $row2 = [];
474     }
475
476     $template->param( table2 => $table2 );
477 } else {
478     $template->param( timeline_read_error => 1 );
479 }
480
481 output_html_with_http_headers $query, $cookie, $template->output;