Revert "Bug 28409: Comprehensively validate category in opac-shelves.pl"
[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 Modern::Perl;
24
25 use CGI qw ( -utf8 );
26 use DateTime::TimeZone;
27 use File::Spec;
28 use List::MoreUtils qw/ any /;
29 use LWP::Simple;
30 use Module::Load::Conditional qw(can_load);
31 use XML::Simple;
32 use Config;
33 use Search::Elasticsearch;
34 use Try::Tiny;
35 use YAML qw/LoadFile/;
36
37 use C4::Output;
38 use C4::Auth;
39 use C4::Context;
40 use C4::Installer;
41
42 use Koha;
43 use Koha::DateUtils qw(dt_from_string output_pref);
44 use Koha::Acquisition::Currencies;
45 use Koha::BiblioFrameworks;
46 use Koha::Patron::Categories;
47 use Koha::Patrons;
48 use Koha::Caches;
49 use Koha::Config::SysPrefs;
50 use Koha::Illrequest::Config;
51 use Koha::SearchEngine::Elasticsearch;
52 use Koha::Filter::MARC::ViewPolicy;
53
54 use C4::Members::Statistics;
55
56
57 #use Smart::Comments '####';
58
59 my $query = new CGI;
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61     {
62         template_name   => "about.tt",
63         query           => $query,
64         type            => "intranet",
65         flagsrequired   => { catalogue => 1 },
66         debug           => 1,
67     }
68 );
69
70 my $config_timezone = C4::Context->config('timezone') // '';
71 my $config_invalid  = !DateTime::TimeZone->is_valid_name( $config_timezone );
72 my $env_timezone    = $ENV{TZ} // '';
73 my $env_invalid     = !DateTime::TimeZone->is_valid_name( $env_timezone );
74 my $actual_bad_tz_fallback = 0;
75
76 if ( $config_timezone ne '' &&
77      $config_invalid ) {
78     # Bad config
79     $actual_bad_tz_fallback = 1;
80 }
81 elsif ( $config_timezone eq '' &&
82         $env_timezone    ne '' &&
83         $env_invalid ) {
84     # No config, but bad ENV{TZ}
85     $actual_bad_tz_fallback = 1;
86 }
87
88 my $time_zone = {
89     actual                 => C4::Context->tz->name,
90     actual_bad_tz_fallback => $actual_bad_tz_fallback,
91     config                 => $config_timezone,
92     config_invalid         => $config_invalid,
93     environment            => $env_timezone,
94     environment_invalid    => $env_invalid
95 };
96
97 $template->param(
98     time_zone              => $time_zone,
99     current_date_and_time  => output_pref({ dt => dt_from_string(), dateformat => 'iso' })
100 );
101
102 my $perl_path = $^X;
103 if ($^O ne 'VMS') {
104     $perl_path .= $Config{_exe} unless $perl_path =~ m/$Config{_exe}$/i;
105 }
106
107 my $zebraVersion = `zebraidx -V`;
108
109 # Check running PSGI env
110 if ( any { /(^psgi\.|^plack\.)/i } keys %ENV ) {
111     $template->param(
112         is_psgi => 1,
113         psgi_server => ($ENV{ PLACK_ENV }) ? "Plack ($ENV{PLACK_ENV})" :
114                        ($ENV{ MOD_PERL })  ? "mod_perl ($ENV{MOD_PERL})" :
115                                              'Unknown'
116     );
117 }
118
119 # Memcached configuration
120 my $memcached_servers   = $ENV{MEMCACHED_SERVERS} || C4::Context->config('memcached_servers');
121 my $memcached_namespace = $ENV{MEMCACHED_NAMESPACE} || C4::Context->config('memcached_namespace') // 'koha';
122
123 my $cache = Koha::Caches->get_instance;
124 my $effective_caching_method = ref($cache->cache);
125 # Memcached may have been running when plack has been initialized but could have been stopped since
126 # FIXME What are the consequences of that??
127 my $is_memcached_still_active = $cache->set_in_cache('test_for_about_page', "just a simple value");
128
129 my $where_is_memcached_config = 'nowhere';
130 if ( $ENV{MEMCACHED_SERVERS} and C4::Context->config('memcached_servers') ) {
131     $where_is_memcached_config = 'both';
132 } elsif ( $ENV{MEMCACHED_SERVERS} and not C4::Context->config('memcached_servers') ) {
133     $where_is_memcached_config = 'ENV_only';
134 } elsif ( C4::Context->config('memcached_servers') ) {
135     $where_is_memcached_config = 'config_only';
136 }
137
138 $template->param(
139     effective_caching_method => $effective_caching_method,
140     memcached_servers   => $memcached_servers,
141     memcached_namespace => $memcached_namespace,
142     is_memcached_still_active => $is_memcached_still_active,
143     where_is_memcached_config => $where_is_memcached_config,
144     memcached_running   => Koha::Caches->get_instance->memcached_cache,
145 );
146
147 # Additional system information for warnings
148
149 my $warnStatisticsFieldsError;
150 my $prefStatisticsFields = C4::Context->preference('StatisticsFields');
151 if ($prefStatisticsFields) {
152     $warnStatisticsFieldsError = $prefStatisticsFields
153         unless ( $prefStatisticsFields eq C4::Members::Statistics->get_fields() );
154 }
155
156 my $prefAutoCreateAuthorities = C4::Context->preference('AutoCreateAuthorities');
157 my $prefBiblioAddsAuthorities = C4::Context->preference('BiblioAddsAuthorities');
158 my $warnPrefBiblioAddsAuthorities = ( $prefAutoCreateAuthorities && ( !$prefBiblioAddsAuthorities) );
159
160 my $prefEasyAnalyticalRecords  = C4::Context->preference('EasyAnalyticalRecords');
161 my $prefUseControlNumber  = C4::Context->preference('UseControlNumber');
162 my $warnPrefEasyAnalyticalRecords  = ( $prefEasyAnalyticalRecords  && $prefUseControlNumber );
163
164 my $AnonymousPatron = C4::Context->preference('AnonymousPatron');
165 my $warnPrefAnonymousPatronOPACPrivacy = (
166     C4::Context->preference('OPACPrivacy')
167         and not $AnonymousPatron
168 );
169 my $warnPrefAnonymousPatronAnonSuggestions = (
170     C4::Context->preference('AnonSuggestions')
171         and not $AnonymousPatron
172 );
173
174 my $anonymous_patron = Koha::Patrons->find( $AnonymousPatron );
175 my $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist = ( $AnonymousPatron && C4::Context->preference('AnonSuggestions') && not $anonymous_patron );
176
177 my $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist = ( not $anonymous_patron and Koha::Patrons->search({ privacy => 2 })->count );
178
179 my $errZebraConnection = C4::Context->Zconn("biblioserver",0)->errcode();
180
181 my $warnIsRootUser   = (! $loggedinuser);
182
183 my $warnNoActiveCurrency = (! defined Koha::Acquisition::Currencies->get_active);
184
185 my @xml_config_warnings;
186
187 my $context = new C4::Context;
188
189 if (    C4::Context->config('zebra_bib_index_mode')
190     and C4::Context->config('zebra_bib_index_mode') eq 'grs1' )
191 {
192     push @xml_config_warnings, { error => 'zebra_bib_index_mode_is_grs1' };
193 }
194
195 if (    C4::Context->config('zebra_auth_index_mode')
196     and C4::Context->config('zebra_auth_index_mode') eq 'grs1' )
197 {
198     push @xml_config_warnings, { error => 'zebra_auth_index_mode_is_grs1' };
199 }
200
201 if( (   C4::Context->config('zebra_auth_index_mode')
202     and C4::Context->config('zebra_auth_index_mode') eq 'dom' )
203     && ( $context->{'server'}->{'authorityserver'}->{'config'} !~ /zebra-authorities-dom.cfg/ ) )
204 {
205     push @xml_config_warnings, {
206         error => 'zebra_auth_index_mode_mismatch_warn'
207     };
208 }
209
210 if ( ! defined C4::Context->config('log4perl_conf') ) {
211     push @xml_config_warnings, {
212         error => 'log4perl_entry_missing'
213     }
214 }
215
216 if ( ! defined C4::Context->config('upload_path') ) {
217     if ( Koha::Config::SysPrefs->find('OPACBaseURL')->value ) {
218         # OPACBaseURL seems to be set
219         push @xml_config_warnings, {
220             error => 'uploadpath_entry_missing'
221         }
222     } else {
223         push @xml_config_warnings, {
224             error => 'uploadpath_and_opacbaseurl_entry_missing'
225         }
226     }
227 }
228
229 if ( ! C4::Context->config('tmp_path') ) {
230     my $temporary_directory = C4::Context::temporary_directory;
231     push @xml_config_warnings, {
232         error             => 'tmp_path_missing',
233         effective_tmp_dir => $temporary_directory,
234     }
235 }
236
237 # Test QueryParser configuration sanity
238 if ( C4::Context->preference( 'UseQueryParser' ) ) {
239     # Get the QueryParser configuration file name
240     my $queryparser_file          = C4::Context->config( 'queryparser_config' );
241     my $queryparser_fallback_file = '/etc/koha/searchengine/queryparser.yaml';
242     # Check QueryParser is functional
243     my $QParser = C4::Context->queryparser();
244     my $queryparser_error = {};
245     if ( ! defined $QParser || ref($QParser) ne 'Koha::QueryParser::Driver::PQF' ) {
246         # Error initializing the QueryParser object
247         # Get the used queryparser.yaml file path to report the user
248         $queryparser_error->{ fallback } = ( defined $queryparser_file ) ? 0 : 1;
249         $queryparser_error->{ file }     = ( defined $queryparser_file )
250                                                 ? $queryparser_file
251                                                 : $queryparser_fallback_file;
252         # Report error data to the template
253         $template->param( QueryParserError => $queryparser_error );
254     } else {
255         # Check for an absent queryparser_config entry in koha-conf.xml
256         if ( ! defined $queryparser_file ) {
257             # Not an error but a warning for the missing entry in koha-conf-xml
258             push @xml_config_warnings, {
259                     error => 'queryparser_entry_missing',
260                     file  => $queryparser_fallback_file
261             };
262         }
263     }
264 }
265
266 # Test Zebra facets configuration
267 if ( !defined C4::Context->config('use_zebra_facets') ) {
268     push @xml_config_warnings, { error => 'use_zebra_facets_entry_missing' };
269 }
270
271 # ILL module checks
272 if ( C4::Context->preference('ILLModule') ) {
273     my $warnILLConfiguration = 0;
274     my $ill_config_from_file = C4::Context->config("interlibrary_loans");
275     my $ill_config = Koha::Illrequest::Config->new;
276
277     my $available_ill_backends =
278       ( scalar @{ $ill_config->available_backends } > 0 );
279
280     # Check backends
281     if ( !$available_ill_backends ) {
282         $template->param( no_ill_backends => 1 );
283         $warnILLConfiguration = 1;
284     }
285
286     # Check partner_code
287     if ( !Koha::Patron::Categories->find($ill_config->partner_code) ) {
288         $template->param( ill_partner_code_doesnt_exist => $ill_config->partner_code );
289         $warnILLConfiguration = 1;
290     }
291
292     if ( !$ill_config_from_file->{partner_code} ) {
293         # partner code not defined
294         $template->param( ill_partner_code_not_defined => 1 );
295         $warnILLConfiguration = 1;
296     }
297
298
299     if ( !$ill_config_from_file->{branch} ) {
300         # branch not defined
301         $template->param( ill_branch_not_defined => 1 );
302         $warnILLConfiguration = 1;
303     }
304
305     $template->param( warnILLConfiguration => $warnILLConfiguration );
306 }
307
308 if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
309     # Check ES configuration health and runtime status
310
311     my $es_status;
312     my $es_config_error;
313     my $es_running = 1;
314
315     my $es_conf;
316     try {
317         $es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
318     }
319     catch {
320         if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
321             $template->param( elasticsearch_fatal_config_error => $_->message );
322             $es_config_error = 1;
323         }
324     };
325     if ( !$es_config_error ) {
326
327         my $biblios_index_name     = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
328         my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
329
330         my @indexes = ($biblios_index_name, $authorities_index_name);
331         # TODO: When new indexes get added, we could have other ways to
332         #       fetch the list of available indexes (e.g. plugins, etc)
333         $es_status->{nodes} = $es_conf->{nodes};
334         my $es = Search::Elasticsearch->new({ nodes => $es_conf->{nodes} });
335         my $es_status->{version} = $es->info->{version}->{number};
336
337         foreach my $index ( @indexes ) {
338             my $count;
339             try {
340                 $count = $es->indices->stats( index => $index )
341                       ->{_all}{primaries}{docs}{count};
342             }
343             catch {
344                 if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
345                     push @{ $es_status->{errors} }, "Index not found ($index)";
346                     $count = -1;
347                 }
348                 elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
349                     $es_running = 0;
350                 }
351                 else {
352                     # TODO: when time comes, we will cover more use cases
353                     die $_;
354                 }
355             };
356
357             push @{ $es_status->{indexes} },
358               {
359                 index_name => $index,
360                 count      => $count
361               };
362         }
363         $es_status->{running} = $es_running;
364
365         $template->param( elasticsearch_status => $es_status );
366     }
367 }
368
369 if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
370     # Do we have the required deps?
371     unless ( can_load( modules => { 'Net::OAuth2::AuthorizationServer' => undef }) ) {
372         $template->param( oauth2_missing_deps => 1 );
373     }
374 }
375
376 # Sco Patron should not contain any other perms than circulate => self_checkout
377 if (  C4::Context->preference('WebBasedSelfCheck')
378       and C4::Context->preference('AutoSelfCheckAllowed')
379 ) {
380     my $userid = C4::Context->preference('AutoSelfCheckID');
381     my $all_permissions = C4::Auth::get_user_subpermissions( $userid );
382     my ( $has_self_checkout_perm, $has_other_permissions );
383     while ( my ( $module, $permissions ) = each %$all_permissions ) {
384         if ( $module eq 'self_check' ) {
385             while ( my ( $permission, $flag ) = each %$permissions ) {
386                 if ( $permission eq 'self_checkout_module' ) {
387                     $has_self_checkout_perm = 1;
388                 } else {
389                     $has_other_permissions = 1;
390                 }
391             }
392         } else {
393             $has_other_permissions = 1;
394         }
395     }
396     $template->param(
397         AutoSelfCheckPatronDoesNotHaveSelfCheckPerm => not ( $has_self_checkout_perm ),
398         AutoSelfCheckPatronHasTooManyPerm => $has_other_permissions,
399     );
400 }
401
402 # Test YAML system preferences
403 # FIXME: This is list of current YAML formatted prefs, should by type of preference
404 my @yaml_prefs = (
405     "UpdateNotForLoanStatusOnCheckin",
406     "OpacHiddenItems",
407     "BibtexExportAdditionalFields",
408     "RisExportAdditionalFields",
409     "UpdateItemWhenLostFromHoldList",
410     "MarcFieldsToOrder",
411     "MarcItemFieldsToOrder",
412     "UpdateitemLocationOnCheckin",
413     "ItemsDeniedRenewal"
414 );
415 my @bad_yaml_prefs;
416 foreach my $syspref (@yaml_prefs) {
417     my $yaml = C4::Context->preference( $syspref );
418     if ( $yaml ) {
419         eval { YAML::Load( "$yaml\n\n" ); };
420         if ($@) {
421             push @bad_yaml_prefs, $syspref;
422         }
423     }
424 }
425 $template->param( 'bad_yaml_prefs' => \@bad_yaml_prefs ) if @bad_yaml_prefs;
426
427 {
428     my $dbh       = C4::Context->dbh;
429     my $patrons = $dbh->selectall_arrayref(
430         q|select b.borrowernumber from borrowers b join deletedborrowers db on b.borrowernumber=db.borrowernumber|,
431         { Slice => {} }
432     );
433     my $biblios = $dbh->selectall_arrayref(
434         q|select b.biblionumber from biblio b join deletedbiblio db on b.biblionumber=db.biblionumber|,
435         { Slice => {} }
436     );
437     my $items = $dbh->selectall_arrayref(
438         q|select i.itemnumber from items i join deleteditems di on i.itemnumber=di.itemnumber|,
439         { Slice => {} }
440     );
441     my $checkouts = $dbh->selectall_arrayref(
442         q|select i.issue_id from issues i join old_issues oi on i.issue_id=oi.issue_id|,
443         { Slice => {} }
444     );
445     my $holds = $dbh->selectall_arrayref(
446         q|select r.reserve_id from reserves r join old_reserves o on r.reserve_id=o.reserve_id|,
447         { Slice => {} }
448     );
449     if ( @$patrons or @$biblios or @$items or @$checkouts or @$holds ) {
450         $template->param(
451             has_ai_issues => 1,
452             ai_patrons    => $patrons,
453             ai_biblios    => $biblios,
454             ai_items      => $items,
455             ai_checkouts  => $checkouts,
456             ai_holds      => $holds,
457         );
458     }
459 }
460
461 # Circ rule warnings
462 {
463     my $dbh   = C4::Context->dbh;
464     my $units = $dbh->selectall_arrayref(
465         q|SELECT branchcode, categorycode, itemtype, lengthunit FROM issuingrules WHERE lengthunit NOT IN ( 'days', 'hours' ); |,
466         { Slice => {} }
467     );
468
469     if (@$units) {
470         $template->param(
471             warnIssuingRules => 1,
472             ir_units         => $units,
473         );
474     }
475 }
476
477 # Guarantor relationships warnings
478 {
479     my $dbh   = C4::Context->dbh;
480     my ($bad_relationships_count) = $dbh->selectall_arrayref(q{
481         SELECT COUNT(*)
482         FROM (
483             SELECT relationship FROM borrower_relationships WHERE relationship='_bad_data'
484             UNION ALL
485             SELECT relationship FROM borrowers WHERE relationship='_bad_data') a
486     });
487
488     $bad_relationships_count = $bad_relationships_count->[0]->[0];
489
490     my $existing_relationships = $dbh->selectall_arrayref(q{
491           SELECT DISTINCT(relationship)
492           FROM (
493               SELECT relationship FROM borrower_relationships WHERE relationship IS NOT NULL
494               UNION ALL
495               SELECT relationship FROM borrowers WHERE relationship IS NOT NULL) a
496     });
497
498     my %valid_relationships = map { $_ => 1 } split( /,|\|/, C4::Context->preference('borrowerRelationship') );
499     $valid_relationships{ _bad_data } = 1; # we handle this case in another way
500
501     my $wrong_relationships = [ grep { !$valid_relationships{ $_->[0] } } @{$existing_relationships} ];
502     if ( @$wrong_relationships or $bad_relationships_count ) {
503
504         $template->param(
505             warnRelationships => 1,
506         );
507
508         if ( $wrong_relationships ) {
509             $template->param(
510                 wrong_relationships => $wrong_relationships
511             );
512         }
513         if ($bad_relationships_count) {
514             $template->param(
515                 bad_relationships_count => $bad_relationships_count,
516             );
517         }
518     }
519 }
520
521 {
522     my @frameworkcodes = Koha::BiblioFrameworks->search->get_column('frameworkcode');
523     my @hidden_biblionumbers;
524     push @frameworkcodes, ""; # it's not in the biblio_frameworks table!
525     for my $frameworkcode ( @frameworkcodes ) {
526         my $shouldhidemarc_opac = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
527             {
528                 frameworkcode => $frameworkcode,
529                 interface     => "opac"
530             }
531         );
532         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'opac' }
533           if $shouldhidemarc_opac->{biblionumber};
534
535         my $shouldhidemarc_intranet = Koha::Filter::MARC::ViewPolicy->should_hide_marc(
536             {
537                 frameworkcode => $frameworkcode,
538                 interface     => "intranet"
539             }
540         );
541         push @hidden_biblionumbers, { frameworkcode => $frameworkcode, interface => 'intranet' }
542           if $shouldhidemarc_intranet->{biblionumber};
543     }
544     $template->param( warnHiddenBiblionumbers => \@hidden_biblionumbers );
545 }
546
547 my %versions = C4::Context::get_versions();
548
549 $template->param(
550     kohaVersion   => $versions{'kohaVersion'},
551     osVersion     => $versions{'osVersion'},
552     perlPath      => $perl_path,
553     perlVersion   => $versions{'perlVersion'},
554     perlIncPath   => [ map { perlinc => $_ }, @INC ],
555     mysqlVersion  => $versions{'mysqlVersion'},
556     apacheVersion => $versions{'apacheVersion'},
557     zebraVersion  => $zebraVersion,
558     prefBiblioAddsAuthorities => $prefBiblioAddsAuthorities,
559     prefAutoCreateAuthorities => $prefAutoCreateAuthorities,
560     warnPrefBiblioAddsAuthorities => $warnPrefBiblioAddsAuthorities,
561     warnPrefEasyAnalyticalRecords  => $warnPrefEasyAnalyticalRecords,
562     warnPrefAnonymousPatronOPACPrivacy        => $warnPrefAnonymousPatronOPACPrivacy,
563     warnPrefAnonymousPatronAnonSuggestions    => $warnPrefAnonymousPatronAnonSuggestions,
564     warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist     => $warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist,
565     warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist => $warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist,
566     errZebraConnection => $errZebraConnection,
567     warnIsRootUser => $warnIsRootUser,
568     warnNoActiveCurrency => $warnNoActiveCurrency,
569     warnNoTemplateCaching => ( C4::Context->config('template_cache_dir') ? 0 : 1 ),
570     xml_config_warnings => \@xml_config_warnings,
571     warnStatisticsFieldsError => $warnStatisticsFieldsError,
572 );
573
574 my @components = ();
575
576 my $perl_modules = C4::Installer::PerlModules->new;
577 $perl_modules->versions_info;
578
579 my @pm_types = qw(missing_pm upgrade_pm current_pm);
580
581 foreach my $pm_type(@pm_types) {
582     my $modules = $perl_modules->get_attr($pm_type);
583     foreach (@$modules) {
584         my ($module, $stats) = each %$_;
585         push(
586             @components,
587             {
588                 name    => $module,
589                 version => $stats->{'cur_ver'},
590                 missing => ($pm_type eq 'missing_pm' ? 1 : 0),
591                 upgrade => ($pm_type eq 'upgrade_pm' ? 1 : 0),
592                 current => ($pm_type eq 'current_pm' ? 1 : 0),
593                 require => $stats->{'required'},
594                 reqversion => $stats->{'min_ver'},
595             }
596         );
597     }
598 }
599
600 @components = sort {$a->{'name'} cmp $b->{'name'}} @components;
601
602 my $counter=0;
603 my $row = [];
604 my $table = [];
605 foreach (@components) {
606     push (@$row, $_);
607     unless (++$counter % 4) {
608         push (@$table, {row => $row});
609         $row = [];
610     }
611 }
612 # Processing the last line (if there are any modules left)
613 if (scalar(@$row) > 0) {
614     # Extending $row to the table size
615     $$row[3] = '';
616     # Pushing the last line
617     push (@$table, {row => $row});
618 }
619 ## ## $table
620
621 $template->param( table => $table );
622
623
624 ## ------------------------------------------
625 ## Koha contributions
626 my $docdir;
627 if ( defined C4::Context->config('docdir') ) {
628     $docdir = C4::Context->config('docdir');
629 } else {
630     # if no <docdir> is defined in koha-conf.xml, use the default location
631     # this is a work-around to stop breakage on upgraded Kohas, bug 8911
632     $docdir = C4::Context->config('intranetdir') . '/docs';
633 }
634
635 ## Release teams
636 my $teams =
637   -e "$docdir" . "/teams.yaml"
638   ? LoadFile( "$docdir" . "/teams.yaml" )
639   : {};
640 my $dev_team = (sort {$b <=> $a} (keys %{$teams->{team}}))[0];
641 my $short_version = substr($versions{'kohaVersion'},0,5);
642 my $minor = substr($versions{'kohaVersion'},3,2);
643 my $development_version = ( $minor eq '05' || $minor eq '11' ) ? 0 : 1;
644 $template->param( short_version => $short_version );
645 $template->param( development_version => $development_version );
646
647 ## Contributors
648 my $contributors =
649   -e "$docdir" . "/contributors.yaml"
650   ? LoadFile( "$docdir" . "/contributors.yaml" )
651   : {};
652 for my $version ( sort { $a <=> $b } keys %{$teams->{team}} ) {
653     for my $role ( keys %{ $teams->{team}->{$version} } ) {
654         my $normalized_role = "$role";
655         $normalized_role =~ s/s$//;
656         if ( ref( $teams->{team}->{$version}->{$role} ) eq 'ARRAY' ) {
657             for my $contributor ( @{ $teams->{team}->{$version}->{$role} } ) {
658                 my $name = $contributor->{name};
659                 # Add role to contributors
660                 push @{ $contributors->{$name}->{roles}->{$normalized_role} },
661                   $version;
662                 # Add openhub to teams
663                 if ( exists( $contributors->{$name}->{openhub} ) ) {
664                     $contributor->{openhub} = $contributors->{$name}->{openhub};
665                 }
666             }
667         }
668         elsif ( $role ne 'release_date' ) {
669             my $name = $teams->{team}->{$version}->{$role}->{name};
670             # Add role to contributors
671             push @{ $contributors->{$name}->{roles}->{$normalized_role} },
672               $version;
673             # Add openhub to teams
674             if ( exists( $contributors->{$name}->{openhub} ) ) {
675                 $teams->{team}->{$version}->{$role}->{openhub} =
676                   $contributors->{$name}->{openhub};
677             }
678         }
679         else {
680             $teams->{team}->{$version}->{$role} = DateTime->from_epoch( epoch => $teams->{team}->{$version}->{$role});
681         }
682     }
683 }
684
685 ## Create last name ordered array of people from contributors
686 my @people = map {
687     { name => $_, ( $contributors->{$_} ? %{ $contributors->{$_} } : () ) }
688 } sort {
689     my ($alast) = ( split( /\s/, $a ) )[-1];
690     my ($blast) = ( split( /\s/, $b ) )[-1];
691     lc($alast) cmp lc($blast)
692 } keys %{$contributors};
693
694 $template->param( contributors => \@people );
695 $template->param( maintenance_team => $teams->{team}->{$dev_team} );
696 $template->param( release_team => $teams->{team}->{$short_version} );
697
698 ## Timeline
699 if ( open( my $file, "<:encoding(UTF-8)", "$docdir" . "/history.txt" ) ) {
700
701     my $i = 0;
702
703     my @rows2 = ();
704     my $row2  = [];
705
706     my @lines = <$file>;
707     close($file);
708
709     shift @lines; #remove header row
710
711     foreach (@lines) {
712         my ( $epoch, $date, $desc, $tag ) = split(/\t/);
713         if(!$desc && $date=~ /(?<=\d{4})\s+/) {
714             ($date, $desc)= ($`, $');
715         }
716         push(
717             @rows2,
718             {
719                 date => $date,
720                 desc => $desc,
721             }
722         );
723     }
724
725     my $table2 = [];
726     #foreach my $row2 (@rows2) {
727     foreach  (@rows2) {
728         push (@$row2, $_);
729         push( @$table2, { row2 => $row2 } );
730         $row2 = [];
731     }
732
733     $template->param( table2 => $table2 );
734 } else {
735     $template->param( timeline_read_error => 1 );
736 }
737
738 output_html_with_http_headers $query, $cookie, $template->output;