1 package PciIds::Html::List;
5 use PciIds::Html::Util;
6 use Apache2::Const qw(:common :http);
9 our @EXPORT = qw(&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 );
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 print '<p><a class="navigation" href="/read/'.$address->parent()->get().'/">'.encode( $address->parent()->pretty() )."</a>" if( defined( $address->parent() ) );
34 foreach $comment ( @{$tables->history( $address->get() )} ) {
36 print "<div class='discussion'>\n<h2>Discussion</h2>";
39 my( $id, $text, $time, $name, $description, $seen, $user ) = @{$comment};
40 my $type = $seen ? 'comment' : 'unseen-comment';
41 $type = 'main-comment' if( defined( $mid ) && ( $id == $mid ) );
42 print "<div class='$type'>\n";
43 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
44 print "<p class='itemdescription'>Description: ".encode( $description )."\n" if( defined( $description ) && ( $description ne '' ) );
45 if( defined( $text ) && ( $text ne '' ) ) {
46 $text = encode( $text );
48 print "<p class='comment-text'>$text\n";
50 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
51 print "<p class='time'>".encode( $time )."\n";
54 print "</div>\n" if( $diss );
55 unless( $address->leaf() ) {
56 print "<h2>Subitems</h2>\n";
57 my $restricts = $address->defaultRestrictList();
58 if( scalar @{$restricts} ) {
60 my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
61 foreach( @{$restricts} ) {
62 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
65 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
66 my $sort = ( $args->{'sort'} or 'id' );
67 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
68 genTableHead( 'subnodes', [ '<a href="'.$url.'?sort='.$sort_id.'">Id</a>', '<a href="'.$url.'?sort='.$sort_name.'">Name</a>', 'Description' ] );
69 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
70 $tables->nodes( $address->get(), $args );