I am working on a User Search Page that uses Net Daemon to connect to
another system and gather username information. Everything appears to be
working fine except the user search next results option (Code included
below).
Basically the program goes out connects to a daemon on another system to
gather username info and then spills it back into the program. It is
performing this part correctly because it is indeed displaying the user
names and limiting the display to the number the end user is entering on
the web interface.
(Example: User chooses to limit the display to 20 users. The program
then returns all of the usernames (110 total), but only displays the
first 20).
What I am trying to accomplish:
I want the users to then be given a next results option that will let
the end user display the remaining usernames in groups of say 20 as the
example.
The problem is it's giving me a illegal division by zero error for the
following line:
if ($result_count !=0) {
$pagecount = int($result_count / $limit);
if (($pagecount * $limit) != $result_count) { $pagecount++; }
}
Can anyone tell me what I might be doing wrong or possibly suggest an
alternative method of doing this feature.
Thanks,
D.
#!/usr/local/bin/perl
use CGI;
use Net::Telnet;
require "display-module.pl";
require "error-module.pl";
require "groups.ph";
$x = new CGI;
$choice = $x->param(choice);
$type = $x->param(type);
$detail = $x->param(detail);
$strict = $x->param(strict);
$limit = $x->param(limit);
$search_s = $x->param(search_s);
$action = $x->param(action);
print "Content-type: text/html \n\n";
if ($action eq "Search") {
$choice = "$action";
if ($search_s eq "") {
&field_missing;
}
if ($detail eq "") {
$detail = "off";
}
if ($strict eq "") {
$strict = "off";
}
&user_search;
} else {
&display_search;
}
sub user_search {
$reqpage = "0";
$prompt="/^->/";
$string = "$choice#$type#$detail#$strict#$search_s";
$telnet=new Net::Telnet (Telnetmode => 0,Timeout => 60, Errmode =>
"return");
if ($telnet->open(Host=>$server,Port=>9999)) {
$telnet->cmd(String=>"$string",Prompt=>$prompt);
@results = ();
while (defined($line=$telnet->getline())) {
chomp ($line);
$resul = $line;
push(@results, $resul);
$result_count++;
}
}
if ($result_count !=0) {
$pagecount = int($result_count / $limit);
if (($pagecount * $limit) != $result_count) { $pagecount++; }
}
if ($reqpage > 0) {
$reqpage = $reqpage;
} else {
$reqpage = 1;
}
$firstresult = (($reqpage -1)*$limit) + 1;
$lastresult = $firstresult + $limit - 1;
if ($lastresult > $result_count) { $lastresult = $result_count; }
print "<html>\n";
print "<head><title></title></head>\n";
print "<body>\n";
print "<center><table width=400 border=0>\n";
print "<tr><td bgcolor=#74ccba><font size=5><b>Search Results
$firstresult to $lastresult of $result_count</b></font>\n";
print "</td></tr></table>\n";
print "<center><table width=400 border=0>\n";
print "<tr><td bgcolor=#74ccba><b>Email Name</b></td>\n";
print "<td bgcolor=#74ccba><b>Partnership/Account Number</b></td>\n";
print "<td bgcolor=#74ccba><b>Group</b></td></tr>\n";
$lstart = $firstresult - 1;
$lfinish = $lastresult -1;
foreach $result (@results [$lstart..$lfinish]) {
($user,$acctno,$gidnumber) = split(/:/, $result);
print "<tr><td bgcolor=#eeeeee><a
href=/cgi-bin/usermanager_new/user_adm.pl?type=uid&search_s=$user&detail
=on&action=Search>$user</a></td>\n";
print "<td bgcolor=#eeeeee>$acctno</td>\n";
foreach $family ( keys %group ) {
if ($gidnumber eq $family) {
print "<td bgcolor=#eeeeee>@{ $group{$family} }</td></tr>\n";
}
}
}
print "</table></center>\n";
$prev_page = $reqpage -1;
$next_page = $reqpage +1;
if ($reqpage == 1) {
$prev_link = "";
} else {
$prev_link = "<A
HREF=\"/cgi-bin/usermanager_new/user_adm.pl?reqpage=$prev_page&LIMIT=$li
mit&action=Search\" >". "Previous" . "</a>";
}
if ($reqpage == $pagecount) {
$next_link = "";
} else {
$next_link = "<a
href=\"/cgi-bin/usermanager_new/user_adm.pl?action=Search&type=$type&sea
rch_s=$search_s&LIMIT=$limit&reqpage=$next_page\">". "Next $limit
Results" . "</a>";
}
print "$next_link\n";
print "</body>\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]