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