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 "<div class='top'>\n";
28 print '<h1>'.encode( $id ).'</h1>';
29 genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : () ] );
30 print "<div class='clear'></div>\n";
32 genPath( $req, $address, 0 );
34 print '<h2>'.encode( $id ).'</h2>';
35 print htmlDiv( 'name', '<p>Name: '.encode( $name ) );
37 print htmlDiv( 'note', '<p>Note: '.encode( $note ) ) if defined( $note );
40 foreach $history ( @{$tables->history( $address->get() )} ) {
42 print "<div class='discussion'>\n<h2>Discussion</h2>";
45 my( $id, $text, $time, $name, $note, $seen, $user, $email ) = @{$history};
46 my $type = $seen ? 'history' : 'unseen-history';
47 $type = 'main-history' if( defined( $mid ) && ( $id == $mid ) );
48 print "<div class='$type'>\n";
49 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
50 print "<p class='itemname'>Deletion request\n" if( defined $name && $name eq '' );
51 print "<p class='itemnote'>Note: ".encode( $note )."\n" if( defined( $note ) && ( $note ne '' ) );
52 if( defined( $text ) && ( $text ne '' ) ) {
53 $text = encode( $text );
55 print "<p class='discussion-text'>$text\n";
57 ( $user ) = ( $email =~ /^(.*)@/ ) if defined $email && !defined $user;
58 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
59 print "<p class='time'>".encode( $time )."\n";
63 print "<p><a href='".buildExcept( 'action', $args )."?action=newhistory'>Discuss</a>\n";
64 print "</div>\n" if( $diss );
66 my $url_prefix = $args->{'full_links'} ? 'http://'.$req->hostname() : '';
67 unless( $address->leaf() ) {
68 print "<h2>Sub-items</h2>\n";
69 my $restricts = $address->defaultRestrictList();
70 if( scalar @{$restricts} ) {
72 my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
73 foreach( @{$restricts} ) {
74 print "<a href='".$url_prefix.$url.$_->[0]."'>".$_->[1]."</a> ";
77 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
78 my $sort = ( $args->{'sort'} or 'id' );
79 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
80 genTableHead( 'subnodes', [ '<a href="'.$url_prefix.$url.'?sort='.$sort_id.'">Id</a>', '<a href="'.$url_prefix.$url.'?sort='.$sort_name.'">Name</a>', 'Note' ], [ 'id-col', 'name-col', 'note-col' ] );
81 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
82 $tables->nodes( $address->get(), $args, $url_prefix );