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