]> mj.ucw.cz Git - pciids.git/blob - PciIds/Html/List.pm
4e1cdc60a64f15aad4258beadacd535e140e2458
[pciids.git] / PciIds / Html / List.pm
1 package PciIds::Html::List;
2 use strict;
3 use warnings;
4 use PciIds::Address;
5 use PciIds::Html::Util;
6 use Apache2::Const qw(:common :http);
7 use base 'Exporter';
8
9 our @EXPORT = qw(&loadItem);
10
11 sub loadItem( $$ ) {
12         my( $tables, $uri ) = @_;
13         my $address = PciIds::Address::new( $uri );
14         return ( 0 ) unless( defined $address );
15         my $item = $tables->item( $address->get() );
16         return ( 0 ) unless( defined $item );
17         my( $parent, $name, $description, $maincomment ) = @{$item};
18         return ( 1, $parent, $name, $description, $address, $maincomment );
19 }
20
21 sub list( $$$$ ) {
22         my( $req, $args, $tables, $auth ) = @_;
23         my( $ok, $parent, $name, $description, $address, $mid ) = loadItem( $tables, $req->uri() );
24         return NOT_FOUND unless( $ok );
25         my $id = $address->pretty();
26         genHtmlHead( $req, $id, undef );
27         print '<h1>'.encode( $id ).'</h1>';
28         genMenu( $address, $args, $auth );
29         print htmlDiv( 'name', '<p>'.encode( $name ) ) if( defined( $name ) );
30         print htmlDiv( 'description', '<p>'.encode( $description ) ) if( defined( $description ) );
31         if( defined( $address->parent() ) ) {
32                 print '<p><a class="navigation" href="/read/'.$address->parent()->get().'/">'.encode( $address->parent()->pretty() )."</a>";
33         } else {
34                 print '<p><a class="navigation" href="/index.html">Main page</a>';
35         }
36         my $diss = 0;
37         my $comment;
38         foreach $comment ( @{$tables->history( $address->get() )} ) {
39                 unless( $diss ) {
40                         print "<div class='discussion'>\n<h2>Discussion</h2>";
41                         $diss = 1;
42                 }
43                 my( $id, $text, $time, $name, $description, $seen, $user ) = @{$comment};
44                 my $type = $seen ? 'comment' : 'unseen-comment';
45                 $type = 'main-comment' if( defined( $mid ) && ( $id == $mid ) );
46                 print "<div class='$type'>\n";
47                 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
48                 print "<p class='itemdescription'>Description: ".encode( $description )."\n" if( defined( $description ) && ( $description ne '' ) );
49                 if( defined( $text ) && ( $text ne '' ) ) {
50                         $text = encode( $text );
51                         $text =~ s/\n/<br>/g;
52                         print "<p class='comment-text'>$text\n";
53                 }
54                 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
55                 print "<p class='time'>".encode( $time )."\n";
56                 print "</div>\n";
57         }
58         print "</div>\n" if( $diss );
59         unless( $address->leaf() ) {
60                 print "<h2>Subitems</h2>\n";
61                 my $restricts = $address->defaultRestrictList();
62                 if( scalar @{$restricts} ) {
63                         print "<p>";
64                         my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
65                         foreach( @{$restricts} ) {
66                                 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
67                         }
68                 }
69                 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
70                 my $sort = ( $args->{'sort'} or 'id' );
71                 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
72                 genTableHead( 'subnodes', [ '<a href="'.$url.'?sort='.$sort_id.'">Id</a>', '<a href="'.$url.'?sort='.$sort_name.'">Name</a>', 'Description' ] );
73                 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
74                 $tables->nodes( $address->get(), $args );
75                 genTableTail();
76         }
77         genHtmlTail();
78         return OK;
79 }
80
81 1;