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->top()->pretty();
26 genHtmlHead( $req, $id, "<style type='text/css' media='screen,print'>col.id-col { width: ".$address->subIdSize()*1.25."ex; }</style>\n" );
27 print "<div class='top'>\n";
28 genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : (), [ '', 'jump' ] ] );
29 print '<h1>'.encode( $id ).'</h1>';
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 && $note ne '';
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 unless( $address->leaf() ) {
67 print "<h2>".encode( $address->subName() )."</h2>\n";
68 my $restricts = $address->defaultRestrictList();
69 if( scalar @{$restricts} ) {
71 my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
72 foreach( @{$restricts} ) {
73 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
76 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
77 my $sort = ( $args->{'sort'} or 'id' );
78 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
79 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' ] );
80 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
81 $tables->nodes( $address->get(), $args );
83 print "<p><a href='".buildExcept( 'action', $args )."?action=newitem'>Add item</a>\n";