1 package PciIds::Html::Jump;
5 use PciIds::Html::Forms;
6 use PciIds::Html::Users;
7 use PciIds::Html::Util;
9 use Apache2::Const qw(:common :http);
11 our @EXPORT = qw(&jumpWindow);
13 sub jumpWindow( $$ ) {
14 my( $req, $args ) = @_;
15 print "<form id='jump' class='jump' name='jump' method='POST' action='".buildExcept( 'action', $args )."?action=jump".( defined $args->{'action'} ? "?origin=".$args->{'action'} : "" )."'>\n";
17 print "<input type='text' class='jump' name='where'><input type='submit' value='Jump'>\n";
22 my( $req, $args, $addr ) = @_;
23 my $prefix = ( !defined $args->{'action'} || $args->{'action'} eq '' || $args->{'action'} eq 'list' ) ? 'read' : 'mods';
24 my $url = "http://".$req->hostname()."/$prefix/$addr".buildArgs( $args );
25 return HTTPRedirect( $req, $url );
28 sub itemExists( $$ ) {
29 my( $tables, $addr ) = @_;
30 return defined $tables->item( $addr );
33 sub tryDirect( $$$$ ) {
34 my( $req, $args, $tables, $search ) = @_;
35 my $address = PciIds::Address::new( $req->uri() );
36 #Is it absolute address?
39 my( $top ) = $address->get() =~ /^([^\/]+)/;
40 $search =~ s/^\//$top\//;
41 my $saddr = PciIds::Address::new( $search );
42 return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
43 while( defined $address ) {
44 $saddr = PciIds::Address::new( $address->get()."/$search" );
45 return redirect( $req, $args, $saddr->get() ) if( defined $saddr && itemExists( $tables, $saddr->get() ) );
46 $address = $address->parent();
52 my( $req, $args, $tables, $auth ) = @_;
53 $args->{'action'} = delete $args->{'origin'};
54 my $search = getFormValue( 'where', '' );
55 my $idOnly = $search =~ s/^#//;
56 my $direct = tryDirect( $req, $args, $tables, $search );
57 return $direct if defined $direct;
58 unless( $idOnly ) {#Try extended search
61 genHtmlHead( $req, 'No matches', undef );
62 print "<div class='top'>\n";
63 print '<h1>No matches</h1>';
64 my $address = PciIds::Address::new( $req->uri() );
65 genMenu( $req, $address, $args, $auth, [ [ 'Help', 'help', 'jump' ] ] );
66 print "<div class='clear'></div>\n";
68 genPath( $req, $address, 1 );
69 print "<p>Your search request matches no item. Would you like to try again?\n<p>\n";
70 jumpWindow( $req, $args );