]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Controller/Intel.pm
Search for intel by nick
[ndwebbie.git] / lib / NDWeb / Controller / Intel.pm
index 55f6643ee057f789e51746bff47427703bc32f15..fd844725a0b407eec6ab3f0c7ef69f0eb49f4168 100644 (file)
@@ -159,11 +159,24 @@ sub find : Local {
        my $dbh = $c->model;
 
        local $_ = $find || $c->req->param('coords');
+       $c->stash(searchterm => $_);
 
        if (/(\d+)(?: |:)(\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?/){
                my $planet = $dbh->selectrow_array(q{SELECT planetid($1,$2,$3,$4)}
                        ,undef,$1,$2,$3,$4);
                $c->res->redirect($c->uri_for('planet',$planet));
+       }else{
+               my $query = $dbh->prepare(q{SELECT id,coords(x,y,z),nick
+                       FROM current_planet_stats p
+                       WHERE nick ilike $1
+               });
+               $query->execute($_);
+               my $planets = $query->fetchall_arrayref({});
+               if (@{$planets} == 1){
+                       $c->res->redirect($c->uri_for('planet',$planets->[0]->{id}));
+               }else{
+                       $c->stash(planets => $planets);
+               }
        }
 }