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