Bug 13877 - Fix QA issues
[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 strict;
24 use warnings;
25
26 use CGI qw ( -utf8 );
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::Borrowers;
38 use Koha::Config::SysPrefs;
39 use C4::Members::Statistics;
40
41 #use Smart::Comments '####';
42
43 my $query = new CGI;
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45     {
46         template_name   => "about.tt",
47         query           => $query,
48         type            => "intranet",
49         authnotrequired => 0,
50         flagsrequired   => { catalogue => 1 },
51         debug           => 1,
52     }
53 );
54
55 my $perl_path = $^X;
56 if ($^O ne 'VMS') {
57     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
58 }
59
60 my $zebraVersion = `zebraidx -V`;
61
62 # Additional system information for warnings
63
64 my $warnStatisticsFieldsError;
65 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
66 if ($prefStatisticsFields) {
67     $warnStatisticsFieldsError = $prefStatisticsFields
68         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
69 }
70
71 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
72 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
73 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
74
75 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
76 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
77 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
78 my $warnPrefAnonymousPatron = (
79     C4::Context->preference('OPACPrivacy')
80         and not C4::Context->preference('AnonymousPatron')
81 );
82
83 my $anonymous_patron = Koha::Borrowers->find( C4::Context->preference('AnonymousPatron') );
84 my $warnPrefAnonymousPatron_PatronDoesNotExist = ( not $anonymous_patron and Koha::Borrowers->search({ privacy => 2 })->count );
85
86 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
87
88 my $warnIsRootUser   = (! $loggedinuser);
89
90 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
91 my @xml_config_warnings;
92
93 my $context = new C4::Context;
94
95 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
96     push @xml_config_warnings, {
97         error => 'zebra_bib_index_mode_warn'
98     };
99     if ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) {
100         push @xml_config_warnings, {
101             error => 'zebra_bib_mode_seems_grs1'
102         };
103     }
104     else {
105         push @xml_config_warnings, {
106             error => 'zebra_bib_mode_seems_dom'
107         };
108     }
109 } else {
110     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
111         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
112 }
113
114 if ( (C4::Context->config('zebra_bib_index_mode') eq 'dom') &&
115      ($context->{'server'}->{'biblioserver'}->{'config'} !~ /zebra-biblios-dom.cfg/) ) {
116
117     push @xml_config_warnings, {
118         error => 'zebra_bib_index_mode_mismatch_warn'
119     };
120 }
121
122 if ( (C4::Context->config('zebra_bib_index_mode') eq 'grs1') &&
123      ($context->{'server'}->{'biblioserver'}->{'config'} =~ /zebra-biblios-dom.cfg/) ) {
124
125     push @xml_config_warnings, {
126         error => 'zebra_bib_index_mode_mismatch_warn'
127     };
128 }
129
130 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
131     push @xml_config_warnings, {
132         error => 'zebra_auth_index_mode_warn'
133     };
134     if ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) {
135         push @xml_config_warnings, {
136             error => 'zebra_auth_mode_seems_grs1'
137         };
138     }
139     else {
140         push @xml_config_warnings, {
141             error => 'zebra_auth_mode_seems_dom'
142         };
143     }
144 } else {
145     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
146         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
147 }
148
149 if ( (C4::Context->config('zebra_auth_index_mode') eq 'dom') && ($context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/) ) {
150     push @xml_config_warnings, {
151         error => 'zebra_auth_index_mode_mismatch_warn'
152     };
153 }
154
155 if ( (C4::Context->config('zebra_auth_index_mode') eq 'grs1') && ($context->{'server'}->{'authorityserver'}->{'config'} =~ /zebra-authorities-dom.cfg/) ) {
156     push @xml_config_warnings, {
157         error => 'zebra_auth_index_mode_mismatch_warn'
158     };
159 }
160
161 # Test QueryParser configuration sanity
162 if ( C4::Context->preference( 'UseQueryParser' ) ) {
163     # Get the QueryParser configuration file name
164     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
165     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
166     # Check QueryParser is functional
167     my $QParser = C4::Context->queryparser();
168     my $queryparser_error = {};
169     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
170         # Error initializing the QueryParser object
171         # Get the used queryparser.yaml file path to report the user
172         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
173         $queryparser_error->{ file }     = ( defined $queryparser_file )
174                                                 ? $queryparser_file
175                                                 : $queryparser_fallback_file;
176         # Report error data to the template
177         $template->param( QueryParserError => $queryparser_error );
178     } else {
179         # Check for an absent queryparser_config entry in koha-conf.xml
180         if ( ! defined $queryparser_file ) {
181             # Not an error but a warning for the missing entry in koha-conf-xml
182             push @xml_config_warnings, {
183                     error => 'queryparser_entry_missing',
184                     file  => $queryparser_fallback_file
185             };
186         }
187     }
188 }
189
190 # Test Zebra facets configuration
191 if ( !defined C4::Context->config('use_zebra_facets') ) {
192     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
193 } else {
194     if ( C4::Context->config('use_zebra_facets') &&
195          C4::Context->config('zebra_bib_index_mode') ) {
196         # use_zebra_facets works with DOM
197         push @xml_config_warnings, {
198             error => 'use_zebra_facets_needs_dom'
199         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
200     }
201 }
202
203 # Sco Patron should not contain any other perms than circulate => self_checkout
204 if (  C4::Context->preference('WebBasedSelfCheck')
205       and C4::Context->preference('AutoSelfCheckAllowed')
206 ) {
207     my $userid = C4::Context->preference('AutoSelfCheckID');
208     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
209     my ( $has_self_checkout_perm, $has_other_permissions );
210     while ( my ( $module, $permissions ) = each %$all_permissions ) {
211         if ( $module eq 'circulate' ) {
212             while ( my ( $permission, $flag ) = each %$permissions ) {
213                 if ( $permission eq 'self_checkout' ) {
214                     $has_self_checkout_perm = 1;
215                 } else {
216                     $has_other_permissions = 1;
217                 }
218             }
219         } else {
220             $has_other_permissions = 1;
221         }
222     }
223     $template->param(
224         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
225         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
226     );
227
228
229 }
230
231 my %versions = C4::Context::get_versions();
232
233 $template->param(
234     kohaVersion   => $versions{'kohaVersion'},
235     osVersion     => $versions{'osVersion'},
236     perlPath      => $perl_path,
237     perlVersion   => $versions{'perlVersion'},
238     perlIncPath   => [ map { perlinc => $_ }, @INC ],
239     mysqlVersion  => $versions{'mysqlVersion'},
240     apacheVersion => $versions{'apacheVersion'},
241     zebraVersion  => $zebraVersion,
242     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
243     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
244     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
245     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
246     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
247     warnPrefAnonymousPatron_PatronDoesNotExist => $warnPrefAnonymousPatron_PatronDoesNotExist,
248     errZebraConnection => $errZebraConnection,
249     warnIsRootUser => $warnIsRootUser,
250     warnNoActiveCurrency => $warnNoActiveCurrency,
251     xml_config_warnings => \@xml_config_warnings,
252     warnStatisticsFieldsError => $warnStatisticsFieldsError,
253 );
254
255 my @components = ();
256
257 my $perl_modules = C4::Installer::PerlModules->new;
258 $perl_modules->version_info;
259
260 my @pm_types = qw(missing_pm upgrade_pm current_pm);
261
262 foreach my $pm_type(@pm_types) {
263     my $modules = $perl_modules->get_attr($pm_type);
264     foreach (@$modules) {
265         my ($module, $stats) = each %$_;
266         push(
267             @components,
268             {
269                 name    => $module,
270                 version => $stats->{'cur_ver'},
271                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
272                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
273                 current => ($pm_type eq 'current_pm' ? 1 : 0),
274                 require => $stats->{'required'},
275                 reqversion => $stats->{'min_ver'},
276             }
277         );
278     }
279 }
280
281 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
282
283 my $counter=0;
284 my $row = [];
285 my $table = [];
286 foreach (@components) {
287     push (@$row, $_);
288     unless (++$counter % 4) {
289         push (@$table, {row => $row});
290         $row = [];
291     }
292 }
293 # Processing the last line (if there are any modules left)
294 if (scalar(@$row) > 0) {
295     # Extending $row to the table size
296     $$row[3] = '';
297     # Pushing the last line
298     push (@$table, {row => $row});
299 }
300 ## ## $table
301
302 $template->param( table => $table );
303
304
305 ## ------------------------------------------
306 ## Koha time line code
307
308 #get file location
309 my $docdir;
310 if ( defined C4::Context->config('docdir') ) {
311     $docdir = C4::Context->config('docdir');
312 } else {
313     # if no <docdir> is defined in koha-conf.xml, use the default location
314     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
315     $docdir = C4::Context->config('intranetdir') . '/docs';
316 }
317
318 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
319
320     my $i = 0;
321
322     my @rows2 = ();
323     my $row2  = [];
324
325     my @lines = <$file>;
326     close($file);
327
328     shift @lines; #remove header row
329
330     foreach (@lines) {
331         my ( $date, $desc, $tag ) = split(/\t/);
332         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
333             ($date, $desc)= ($`, $');
334         }
335         push(
336             @rows2,
337             {
338                 date => $date,
339                 desc => $desc,
340             }
341         );
342     }
343
344     my $table2 = [];
345     #foreach my $row2 (@rows2) {
346     foreach  (@rows2) {
347         push (@$row2, $_);
348         push( @$table2, { row2 => $row2 } );
349         $row2 = [];
350     }
351
352     $template->param( table2 => $table2 );
353 } else {
354     $template->param( timeline_read_error => 1 );
355 }
356
357 output_html_with_http_headers $query, $cookie, $template->output;