Changeset 481 for branches/htmlform/cgi-bin/search.cgi
- Timestamp:
- 09/20/10 14:16:51 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/htmlform/cgi-bin/search.cgi
r478 r481 54 54 # Global variables 55 55 my $RESULTS_PER_PAGE = 25; 56 ##fixme - need to autofill this somehow 57 $ENV{HTML_TEMPLATE_ROOT} = '/home/kdeugau/dev/ipdb/trunk/templates'; 56 57 # anyone got a better name? :P 58 my $thingroot = $ENV{SCRIPT_FILENAME}; 59 $thingroot =~ s|cgi-bin/search.cgi||; 58 60 59 61 # Set up the CGI object... … … 70 72 } 71 73 74 # Set up some globals 75 $ENV{HTML_TEMPLATE_ROOT} = $thingroot."templates"; 76 77 my $page; 72 78 if (!defined($webvar{stype})) { 73 79 $webvar{stype} = "<NULL>"; #shuts up the warnings. 80 $page = HTML::Template->new(filename => "search/compsearch.tmpl"); 81 } else { 82 $page = HTML::Template->new(filename => "search/sresults.tmpl"); 74 83 } 75 84 … … 212 221 213 222 if ($count == 0) { 214 printError"No matches found. Try eliminating one of the criteria,".215 " or making one or more criteria more general." ;223 $page->param(errmsg => "No matches found. Try eliminating one of the criteria,". 224 " or making one or more criteria more general."); 216 225 } else { 217 226 # Add the limit/offset clauses … … 236 245 237 246 if ($count == 0) { 238 printError "No customers currently listed as connected through this node."; 247 $page->param(errmsg => "No customers currently listed as connected through this node."); 248 ##fixme: still get the results table header 239 249 } else { 240 250 # Add the limit/offset clauses … … 248 258 } else { # how script was called. General case is to show the search criteria page. 249 259 250 # Display search page. We have to do this here, because otherwise251 # we can't retrieve data from the database for the types and cities. >:(252 my $html;253 open HTML,"<../compsearch.html";254 $html = join('',<HTML>);255 close HTML;256 257 260 # Generate table of types 258 my $typetable = "<table class=regular cellspacing=0>\n<tr>";259 261 $sth = $ip_dbh->prepare("select type,dispname from alloctypes where listorder <500 ". 260 262 "order by listorder"); 261 263 $sth->execute; 262 264 my $i=0; 263 while (my @data = $sth->fetchrow_array) { 264 $typetable .= "<td><input type=checkbox name=type[$data[0]]>$data[1]</td>"; 265 $i++; 266 $typetable .= "</tr>\n<tr>" 267 if ($i % 4 == 0); 268 } 269 if ($i %4 == 0) { 270 $typetable =~ s/<tr>$//; 271 } else { 272 $typetable .= "</tr>\n"; 273 } 274 $typetable .= "</table>\n"; 265 my @typelist; 266 while (my ($type,$dispname) = $sth->fetchrow_array) { 267 my %row = ( 268 newrow => ($i % 4 == 0), 269 type => $type, 270 dispname => $dispname, 271 endrow => ($i++ % 4 == 3) 272 ); 273 push @typelist, \%row; 274 } 275 $page->param(typelist => \@typelist); 275 276 276 277 # Generate table of cities 277 my $citytable = "<table class=regular cellspacing=0>\n<tr>";278 278 $sth = $ip_dbh->prepare("select id,city from cities order by city"); 279 279 $sth->execute; 280 my $i=0; 281 while (my @data = $sth->fetchrow_array) { 282 $citytable .= "<td><input type=checkbox name=city[$data[0]]>$data[1]</td>"; 283 $i++; 284 $citytable .= "</tr>\n<tr>" 285 if ($i % 5 == 0); 286 } 287 if ($i %5 == 0) { 288 $citytable =~ s/<tr>$//; 289 } else { 290 $citytable .= "</tr>\n"; 291 } 292 $citytable .= "</table>\n"; 293 294 $html =~ s/\$\$TYPELIST\$\$/$typetable/; 295 $html =~ s/\$\$CITYLIST\$\$/$citytable/; 296 297 print $html; 280 $i=0; 281 my @citylist; 282 while (my ($id, $city) = $sth->fetchrow_array) { 283 my %row = ( 284 newrow => ($i % 4 == 0), 285 id => $id, 286 city => $city, 287 endrow => ($i++ % 4 == 3) 288 ); 289 push @citylist, \%row; 290 } 291 $page->param(citylist => \@citylist); 292 298 293 } 294 295 print $page->output; 299 296 300 297 # Shut down and clean up. … … 340 337 if ($category eq 'all') { 341 338 342 print qq(<div class="heading">Showing all netblock and static-IP allocations</div><br>\n);343 339 $sql = "select $cols from searchme"; 344 340 my $count = countRows($sql); … … 348 344 } elsif ($category eq 'cust') { 349 345 346 ##fixme: this and other quick-search areas; fix up page heading title similar to first grouping above 350 347 print qq(<div class="heading">Searching for Customer IDs containing '$query'</div><br>\n); 351 348 … … 411 408 } else { 412 409 # This shouldn't happen, but if it does, whoever gets it deserves what they get... 413 printError("Invalid query.");410 $page->param(errmsg => "Invalid query."); 414 411 } 415 412 } else { 416 413 # This shouldn't happen, but if it does, whoever gets it deserves what they get... 417 printError("Invalid searchfor.");414 $page->param(errmsg => "Invalid searchfor."); 418 415 } 419 416 } # viewBy … … 455 452 $sth->execute(); 456 453 457 startTable('Allocation','CustID','Type','City','Description/Name'); 454 $page->param(searchtitle => "Showing all netblock and static-IP allocations"); 455 458 456 my $count = 0; 459 460 while (my @data= $sth->fetchrow_array) {461 462 # cidr,custid,type,city,description,notes 463 # Another bit of HairyPerl(TM) to prefix subblocks with "Sub" 464 my @row = (($data[2] =~ /^.r$/ ? 'Sub ' : ''). 465 qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),466 $data[1], $disp_alloctypes{$data[2]}, $data[3], $data[4]);467 # Allow listing of pool if desired/required. 468 if ($data[2] =~ /^.[pd]$/) { 469 $row[0] .= ' <a href="/ip/cgi-bin/main.cgi?action=listpool'. 470 "&pool=$data[0]\">List IPs</a>";471 }472 printRow(\@row, "row".($count++ % 2), 1);473 }457 my @sresults; 458 while (my ($block, $custid, $type, $city, $desc) = $sth->fetchrow_array) { 459 my %row = ( 460 rowclass => $count++ % 2, 461 issub => ($type =~ /^.r$/ ? 1 : 0), 462 block => $block, 463 ispool => ($type =~ /^.[pd]$/ ? 1 : 0), 464 custid => $custid, 465 disptype => $disp_alloctypes{$type}, 466 city => $city, 467 desc => $desc 468 ); 469 push @sresults, \%row; 470 } 471 $page->param(sresults => \@sresults); 474 472 475 473 # Have to think on this call, it's primarily to clean up unfetched rows from a select. … … 478 476 479 477 my $upper = $offset+$count; 480 print "<tr><td colspan=10 bgcolor=white class=regular>Records found: $rowCount<br><i>Displaying: ".($offset+1)." - $upper</i></td></tr>\n"; 481 print "</table></center>\n"; 478 479 $page->param(resfound => $rowCount); 480 $page->param(resstart => $offset+1); 481 $page->param(resstop => $upper); 482 482 483 483 # print the page thing.. 484 484 if ($RESULTS_PER_PAGE > 0 && $rowCount > $RESULTS_PER_PAGE) { 485 $page->param(multipage => 1); 485 486 my $pages = ceil($rowCount/$RESULTS_PER_PAGE); 486 print qq(<div class="center"> Page: );487 my @pagelist; 487 488 for (my $i = 1; $i <= $pages; $i++) { 489 my %row; 490 $row{pgnum} = $i; 488 491 if ($i == $pageNo) { 489 print "<b>$i </b>\n";492 $row{thispage} = 1; 490 493 } else { 491 print qq(<a href="/ip/cgi-bin/search.cgi?page=$i&stype=$webvar{stype}&);494 $row{stype} = $webvar{stype}; 492 495 if ($webvar{stype} eq 'c') { 493 print"cidr=$webvar{cidr}&custid=$webvar{custid}&desc=$webvar{desc}&".496 $row{extraopts} = "cidr=$webvar{cidr}&custid=$webvar{custid}&desc=$webvar{desc}&". 494 497 "notes=$webvar{notes}&which=$webvar{which}&alltypes=$webvar{alltypes}&". 495 498 "allcities=$webvar{allcities}&"; 496 499 foreach my $key (keys %webvar) { 497 500 if ($key =~ /^(?:type|city)\[/ || $key =~ /exclude$/) { 498 print"$key=$webvar{$key}&";501 $row{extraopts} .= "$key=$webvar{$key}&"; 499 502 } 500 503 } 501 504 } else { 502 print"input=$webvar{input}&";505 $row{extraopts} = "input=$webvar{input}&"; 503 506 } 504 print qq(">$i</a> \n);505 507 } 506 } 507 print "</div>"; 508 } 508 push @pagelist, \%row; 509 } 510 $page->param(pgnums => \@pagelist); 511 } 512 509 513 } # queryResults 510 514
Note:
See TracChangeset
for help on using the changeset viewer.