LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-12-2003, 08:45 PM   #1
crazeinc
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
Perl automatic page generation


Hey guys,
I'm pulling about 800 entries from an LDAP database and printing to a webpage, but I'd like to make a page for about 100 entries a piece. This script is written in perl so I'd like to keep it that way. How do I automatically create additional pages?

Thanks.
 
Old 09-13-2003, 07:54 AM   #2
richhill
LQ Newbie
 
Registered: Sep 2003
Location: Mesa, AZ, USA
Distribution: SuSe 8.1, Mandrake 6.2
Posts: 12

Rep: Reputation: 0
I'm assuming you already have a script that generates a single page from the LDAP database.

I suggest you post that script here. Folks here will be happy to offer suggestions how to adapt it to your specific reqs - even improve its efficiency.
 
Old 09-13-2003, 07:40 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Depends on what you already have.

Basically you'll need to create some basic logic that will select on 100 entries and display 'em per page, the entries picked will depend on the page you are currently on.

You really aught to give us more information (like richhill noted). Like are you familiar with Perl CGI at all?
 
Old 09-16-2003, 04:48 PM   #4
crazeinc
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Original Poster
Rep: Reputation: 0
Here's the code, excuse the mess, this is my first perl project and I've been experimenting with a bunch of different things. If you'd like to see it in action the address is http://its.noctrl.edu/cgi-test/face2

---------------------------------------------------------
#!/usr/bin/perl
use Net::LDAP;
use strict;
#use warnings;
my $path='http://its.noctrl.edu/marcin/';

###HTML HEADER###
print "Content-type: text/html\n\n";
print "<center><font size=5>NCC Online Facebook</font>";

### SEARCH ###
print "<FORM ACTION=http://its.noctrl.edu/cgi-test/facesearch METHOD=POST>";
print "<STRONG>Last Name:</STRONG> <INPUT NAME=name SIZE=30> <input value=Search
type=submit></FORM></center>";

print "<table align=center><tr>";

my $realcount = 0;
my $entry;
my $ldap=Net::LDAP->new('nccmail.nccnet.noctrl.edu') or die "$@";
$ldap->bind; #anonymous bind
my $attrs = ['EmployeeID','fullName','mail','givenname','sn','telephoneNumber','ou'];

my @contexts=('Faclty', 'Admstr');
my $part;

my $unique;
my $lastname;
my $firstname;
my $id;
my $idcheck;
my $email;
my $location;
my $phone;

my @data;
my %ldaphash= ();

my $count = 0;
my @images;
opendir(DIR,"/var/www/localsites/its.noctrl.edu/marcin") or die "couldn't open images directory : $!";
while( defined (my $filename = readdir(DIR)) ) {
@images[$count] = $filename;
$count++;
}
closedir(DIR);


foreach $part (@contexts) {
my $mesg = $ldap->search (
base => "ou=$part, ou=Napvil, o=NCC",
scope => "sub",
#filter => "(&(objectclass=person)!(ou=Stdnts))",
filter => "(&(objectclass=person))",
attrs => $attrs
);
#my $querycount = $mesg->count;
#my $mesg->sorted('sn');
foreach $entry ( $mesg->entries) {

#if statement is for eliminating entries without an id and students
if($entry->get_value('EmployeeID') ne "" && $entry->get_value('sn') ne ""){

$id = $entry->get_value('EmployeeID');
$idcheck = $id.".jpg";

my $check = 0;
for(my $p=0;$p<$count;$p++){
if($idcheck eq @images[$p] && $check == 0){
$check = 1;
}
}

if ($check == 0 ){
$id = "0000000";
}

$email = $entry->get_value('mail');
$location = $entry->get_value('ou');
$phone = $entry->get_value('telephoneNumber');
$firstname = $entry->get_value('givenname');
$lastname = $entry->get_value('sn');
$unique = $lastname . $id;
$ldaphash{$unique} =
[$id,$lastname,$firstname,$phone,$location,$email];

$realcount++;
}
}
}


my $k;
my $d=0;
foreach $k (sort keys %ldaphash) {

$email = $ldaphash{$k}[5];
$location = $ldaphash{$k}[4];
$phone = $ldaphash{$k}[3];
$firstname = $ldaphash{$k}[2];
$lastname = $ldaphash{$k}[1];
$id = $ldaphash{$k}[0];


if ($id != "0000000"){
if ($d%5 == 0){
print "</tr><tr><td align=center><font face=arial size=2><img
src=",$path,$id,".jpg><br>",$firstname," ",$lastname,"<br><font
size=1>",$location,"<br><a href=mailto:",$email,">",$email,"</a><br>Extension: ",$phone,"</font></font></td>";
}else{
print "<td align=center><font face=arial size=2><img
src=",$path,$id,".jpg><br>",$firstname," ",$lastname,"<br><font
size=1>",$location,"<br><a href=mailto:",$email,">",$email,"</a><br>Extension: ",$phone,"</font></font></td>";
}

$d++;
}
}

$ldap->unbind
 
Old 09-21-2003, 11:45 AM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
Just use a counter variable in your loop that prints the details until the counter reaches 100, when it does, send a "last" command to that loop. To decide on what gets displayed on each page when viewed you could pass a value as a query string to serve as the offset when printing results.

Does that make sense to what you want to acheive.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl and Hash automatic PB0711 Programming 3 09-23-2005 03:14 AM
Automatic generation of /dev devices Dave-Bowskill Linux - Hardware 0 09-20-2004 10:45 PM
Cultured Perl: Genetic algorithms, the next generation Debra Linux - Newbie 3 10-08-2002 06:14 PM
Cultured Perl: Genetic algorithms, the next generation Debra Linux - General 2 10-08-2002 04:26 PM
Cultured Perl: Genetic algorithms, the next generation Debra Programming 0 10-08-2002 03:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration