]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoIndex.pm
Display the index pages from within dispatcher.pl. That reduces the complexity
[deb/packages.git] / lib / Packages / DoIndex.pm
1 package Packages::DoIndex;
2
3 use strict;
4 use warnings;
5
6 use CGI qw( :cgi );
7 use Exporter;
8
9 use Deb::Versions;
10 use Packages::Config qw( $TOPDIR );
11 use Packages::I18N::Locale;
12 use Packages::CGI;
13
14 our @ISA = qw( Exporter );
15 our @EXPORT = qw( do_index );
16
17 sub do_index {
18     my ($params, $opts, $html_header) = @_;
19
20     if ($params->{errors}{suite}) {
21         fatal_error( _g( "suite not valid or not specified" ) );
22     }
23     if (@{$opts->{suite}} > 1) {
24         fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) );
25     }
26     if (@{$opts->{subsection}} > 1) {
27         fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) );
28     }
29
30     my $wwwdir = "$TOPDIR/www";
31     my $path = "$opts->{suite}[0]/";
32     $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1;
33     $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}};
34     # we don't have translated index pages for subsections yet
35     $opts->{lang} = 'en' if @{$opts->{subsection}};
36     $path .= "index.$opts->{lang}.html";
37
38     unless (@Packages::CGI::fatal_errors) {
39         my $buffer;
40         if (open( INDEX, '<', "$wwwdir/$path" )) {
41             my $charset = get_charset( $opts->{lang} );
42             print header( -charset => $charset );
43
44             binmode INDEX;
45             while (read INDEX, $buffer, 4096) {
46                 print $buffer;
47             }
48             close INDEX;
49             exit;
50         } else {
51             fatal_error( sprintf( _g( "couldn't read index file %s: %s" ),
52                                   $path, $! ) );
53         }
54     }
55
56     %$html_header = ( title => _g('Error'),
57                       lang => $opts->{lang},
58                       print_title => 1,
59                       print_search_field => 'packages',
60                       search_field_values => { 
61                           keywords => _g('search for a package'),
62                           searchon => 'default',
63                           arch => 'any',
64                           suite => 'all',
65                           section => 'all',
66                           exact => 1,
67                           debug => $Packages::Search::debug,
68                       },
69                       );
70 }
71
72 1;
73