Bug 11876 [Unit test] Add a diff view to staged MARC Records
[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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23 use strict;
24 use warnings;
25
26 use CGI;
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 Smart::Comments '####';
37
38 my $query = new CGI;
39 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40     {
41         template_name   => "about.tt",
42         query           => $query,
43         type            => "intranet",
44         authnotrequired => 0,
45         flagsrequired   => { catalogue => 1 },
46         debug           => 1,
47     }
48 );
49
50 my $kohaVersion   = C4::Context::KOHAVERSION;
51 my $osVersion     = `uname -a`;
52 my $perl_path = $^X;
53 if ($^O ne 'VMS') {
54     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
55 }
56 my $perlVersion   = $];
57 my $mysqlVersion  = `mysql -V`;
58 my $apacheVersion = `httpd -v 2> /dev/null`;
59 $apacheVersion = `httpd2 -v 2> /dev/null` unless $apacheVersion;
60 $apacheVersion = (`/usr/sbin/apache2 -V`)[0] unless $apacheVersion;
61 my $zebraVersion = `zebraidx -V`;
62
63 # Additional system information for warnings
64 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
65 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
66 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
67
68 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
69 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
70 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
71 my $warnPrefAnonymousPatron = (
72     C4::Context->preference('OPACPrivacy')
73         and not C4::Context->preference('AnonymousPatron')
74 );
75
76 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
77
78 my $warnIsRootUser   = (! $loggedinuser);
79
80 my $warnNoActiveCurrency = (! defined C4::Budgets->GetCurrency());
81 my @xml_config_warnings;
82
83 if ( ! defined C4::Context->config('zebra_bib_index_mode') ) {
84     push @xml_config_warnings, {
85         error => 'zebra_bib_index_mode_warn'
86     };
87 } else {
88     push @xml_config_warnings, { error => 'zebra_bib_grs_warn' }
89         if C4::Context->config('zebra_bib_index_mode') eq 'grs1';
90 }
91
92 if ( ! defined C4::Context->config('zebra_auth_index_mode') ) {
93     push @xml_config_warnings, {
94         error => 'zebra_auth_index_mode_warn'
95     };
96 } else {
97     push @xml_config_warnings, { error => 'zebra_auth_grs_warn' }
98         if C4::Context->config('zebra_auth_index_mode') eq 'grs1';
99 }
100
101 # Test QueryParser configuration sanity
102 if ( C4::Context->preference( 'UseQueryParser' ) ) {
103     # Get the QueryParser configuration file name
104     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
105     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
106     # Check QueryParser is functional
107     my $QParser = C4::Context->queryparser();
108     my $queryparser_error = {};
109     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
110         # Error initializing the QueryParser object
111         # Get the used queryparser.yaml file path to report the user
112         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
113         $queryparser_error->{ file }     = ( defined $queryparser_file )
114                                                 ? $queryparser_file
115                                                 : $queryparser_fallback_file;
116         # Report error data to the template
117         $template->param( QueryParserError => $queryparser_error );
118     } else {
119         # Check for an absent queryparser_config entry in koha-conf.xml
120         if ( ! defined $queryparser_file ) {
121             # Not an error but a warning for the missing entry in koha-conf-xml
122             push @xml_config_warnings, {
123                     error => 'queryparser_entry_missing',
124                     file  => $queryparser_fallback_file
125             };
126         }
127     }
128 }
129
130 # Test Zebra facets configuration
131 if ( !defined C4::Context->config('use_zebra_facets') ) {
132     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
133 } else {
134     if ( C4::Context->config('use_zebra_facets') &&
135          C4::Context->config('zebra_bib_index_mode') ) {
136         # use_zebra_facets works with DOM
137         push @xml_config_warnings, {
138             error => 'use_zebra_facets_needs_dom'
139         } if C4::Context->config('zebra_bib_index_mode') ne 'dom' ;
140     }
141 }
142
143 $template->param(
144     kohaVersion   => $kohaVersion,
145     osVersion     => $osVersion,
146     perlPath      => $perl_path,
147     perlVersion   => $perlVersion,
148     perlIncPath   => [ map { perlinc => $_ }, @INC ],
149     mysqlVersion  => $mysqlVersion,
150     apacheVersion => $apacheVersion,
151     zebraVersion  => $zebraVersion,
152     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
153     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
154     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
155     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
156     warnPrefAnonymousPatron => $warnPrefAnonymousPatron,
157     errZebraConnection => $errZebraConnection,
158     warnIsRootUser => $warnIsRootUser,
159     warnNoActiveCurrency => $warnNoActiveCurrency,
160     xml_config_warnings => \@xml_config_warnings,
161 );
162
163 my @components = ();
164
165 my $perl_modules = C4::Installer::PerlModules->new;
166 $perl_modules->version_info;
167
168 my @pm_types = qw(missing_pm upgrade_pm current_pm);
169
170 foreach my $pm_type(@pm_types) {
171     my $modules = $perl_modules->get_attr($pm_type);
172     foreach (@$modules) {
173         my ($module, $stats) = each %$_;
174         push(
175             @components,
176             {
177                 name    => $module,
178                 version => $stats->{'cur_ver'},
179                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
180                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
181                 current => ($pm_type eq 'current_pm' ? 1 : 0),
182                 require => $stats->{'required'},
183                 reqversion => $stats->{'min_ver'},
184             }
185         );
186     }
187 }
188
189 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
190
191 my $counter=0;
192 my $row = [];
193 my $table = [];
194 foreach (@components) {
195     push (@$row, $_);
196     unless (++$counter % 4) {
197         push (@$table, {row => $row});
198         $row = [];
199     }
200 }
201 # Processing the last line (if there are any modules left)
202 if (scalar(@$row) > 0) {
203     # Extending $row to the table size
204     $$row[3] = '';
205     # Pushing the last line
206     push (@$table, {row => $row});
207 }
208 ## ## $table
209
210 $template->param( table => $table );
211
212
213 ## ------------------------------------------
214 ## Koha time line code
215
216 #get file location
217 my $docdir;
218 if ( defined C4::Context->config('docdir') ) {
219     $docdir = C4::Context->config('docdir');
220 } else {
221     # if no <docdir> is defined in koha-conf.xml, use the default location
222     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
223     $docdir = C4::Context->config('intranetdir') . '/docs';
224 }
225
226 if ( open( my $file, "<", "$docdir" . "/history.txt" ) ) {
227
228     my $i = 0;
229
230     my @rows2 = ();
231     my $row2  = [];
232
233     my @lines = <$file>;
234     close($file);
235
236     shift @lines; #remove header row
237
238     foreach (@lines) {
239         my ( $date, $desc, $tag ) = split(/\t/);
240         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
241             ($date, $desc)= ($`, $');
242         }
243         push(
244             @rows2,
245             {
246                 date => $date,
247                 desc => $desc,
248             }
249         );
250     }
251
252     my $table2 = [];
253     #foreach my $row2 (@rows2) {
254     foreach  (@rows2) {
255         push (@$row2, $_);
256         push( @$table2, { row2 => $row2 } );
257         $row2 = [];
258     }
259
260     $template->param( table2 => $table2 );
261 } else {
262     $template->param( timeline_read_error => 1 );
263 }
264
265 output_html_with_http_headers $query, $cookie, $template->output;