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 if( defined( $address->parent() ) ) {
32 print '<p><a class="navigation" href="/read/'.$address->parent()->get().'/">'.encode( $address->parent()->pretty() )."</a>";
34 print '<p><a class="navigation" href="/index.html">Main page</a>';
38 foreach $comment ( @{$tables->history( $address->get() )} ) {
40 print "<div class='discussion'>\n<h2>Discussion</h2>";
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 );
52 print "<p class='comment-text'>$text\n";
54 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
55 print "<p class='time'>".encode( $time )."\n";
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} ) {
64 my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
65 foreach( @{$restricts} ) {
66 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
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' ], [ 'id-col', 'name-col', 'desc-col' ] );
73 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
74 $tables->nodes( $address->get(), $args );