2 # Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # he Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package PciIds::Html::List;
23 use PciIds::Html::Util;
24 use Apache2::Const qw(:common :http);
27 our @EXPORT = qw(&loadItem);
30 my( $tables, $uri ) = @_;
31 my $address = PciIds::Address::new( $uri );
32 return ( 0 ) unless( defined $address );
33 my $item = $tables->item( $address->get() );
34 return ( 0 ) unless( defined $item );
35 my( $parent, $name, $note, $mainhistory ) = @{$item};
36 return ( 1, $parent, $name, $note, $address, $mainhistory );
40 my( $req, $args, $tables, $auth ) = @_;
41 my( $ok, $parent, $name, $note, $address, $mid ) = loadItem( $tables, $req->uri() );
42 return NOT_FOUND unless( $ok );
43 my $id = $address->top()->pretty();
44 genHtmlHead( $req, $id, "<style type='text/css' media='screen,print'>col.id-col { width: ".$address->subIdSize()*1.25."ex; }</style>\n" );
45 print "<div class='top'>\n";
46 genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'list' ], $address->helpName() ? [ 'ID syntax', 'help', $address->helpName() ] : () ] );
47 print '<div class="bluesquare"><h1>The PCI ID Repository</h1><p class="home">The home of the <code>pci.ids</code> file</div>';
48 print "<div class='clear'></div></div>\n";
49 genPath( $req, $address, 0 );
50 print htmlDiv( 'name', '<p>Name: '.encode( $name ) ) if defined $name && $name ne '';
51 print htmlDiv( 'note', '<p>Note: '.encode( $note ) ) if defined $note && $note ne '';
54 foreach $history ( @{$tables->history( $address->get() )} ) {
56 print "<div class='discussion'>\n<h2>Discussion</h2>";
59 my( $id, $text, $time, $name, $note, $seen, $user, $email ) = @{$history};
60 my $type = $seen ? 'history' : 'unseen-history';
61 $type = 'main-history' if( defined( $mid ) && ( $id == $mid ) );
62 print "<div class='$type'>\n";
63 print "<p class='itemname'>Name: ".encode( $name )."\n" if( defined( $name ) && ( $name ne '' ) );
64 print "<p class='itemname'>Deletion request\n" if( defined $name && $name eq '' );
65 print "<p class='itemnote'>Note: ".encode( $note )."\n" if( defined( $note ) && ( $note ne '' ) );
66 if( defined( $text ) && ( $text ne '' ) ) {
67 $text = encode( $text );
69 print "<p class='discussion-text'>$text\n";
71 ( $user ) = ( $email =~ /^(.*)@/ ) if defined $email && !defined $user;
72 print "<p class='author'>".encode( $user )."\n" if( defined( $user ) );
73 print "<p class='time'>".encode( $time )."\n";
77 print "<p><a href='".buildExcept( 'action', $args )."?action=newhistory'>Discuss</a>\n";
78 print "</div>\n" if( $diss );
80 unless( $address->leaf() ) {
81 print "<h2>".encode( $address->subName() )."</h2>\n";
82 my $restricts = $address->defaultRestrictList();
83 if( scalar @{$restricts} ) {
85 my $url = '/read/'.$address->get().buildExcept( 'restrict', $args ).'?restrict=';
86 foreach( @{$restricts} ) {
87 print "<a href='".$url.$_->[0]."'>".$_->[1]."</a> ";
90 my $url = '/read/'.$address->get().buildExcept( 'sort', $args );
91 my $sort = ( $args->{'sort'} or 'id' );
92 my( $sort_id, $sort_name ) = ( ( $sort eq 'id' ? 'rid' : 'id' ), ( $sort eq 'name' ? 'rname' : 'name' ) );
93 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' ] );
94 $args->{'restrict'} = $address->defaultRestrict() unless( defined( $args->{'restrict'} ) );
95 $tables->nodes( $address->get(), $args );
97 print "<p><a href='".buildExcept( 'action', $args )."?action=newitem'>Add item</a>\n";
99 genHtmlFooter( 1, $req, $args );