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, $note, $mainhistory ) = @{$item};
18 return ( 1, $parent, $name, $note, $address, $mainhistory );
22 my( $req, $args, $tables, $auth ) = @_;
23 my( $ok, $parent, $name, $note, $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( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : () ] );
29 genPath( $req, $address, 0 );
30 print htmlDiv( 'name', '<p>'.encode( $name ) ) if( defined( $name ) );
31 print htmlDiv( 'note', '<p>'.encode( $note ) ) if( defined( $note ) );
34 foreach $history ( @{$tables->history( $address->get() )} ) {
36 print "<div class='discussion'>\n<h2>Discussion</h2>";
39 my( $id, $text, $time, $name, $note, $seen, $user ) = @{$history};
40 my $type = $seen ? 'history' : 'unseen-history';
41 $type = 'main-history' 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='itemnote'>Note: ".encode( $note )."\n" if( defined( $note ) && ( $note ne '' ) );
45 if( defined( $text ) && ( $text ne '' ) ) {
46 $text = encode( $text );
48 print "<p class='discussion-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>Sub-items</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>', 'Note' ], [ 'id-col', 'name-col', 'note-col' ] );
69 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
70 $tables->nodes( $address->get(), $args );