Hello all,
I am working on a data grid that displays some information from our directory
server. I am using jQuery Javascript Framework on the front end, that makes an
Ajax call to a Perl CGI script on the backend using the Net::LDAP module.
Doing some testing I am able to retrieve some data, but not able to get past
the first page of entries. Could some tell me how to page through using the
Net::LDAP::Control::VLV. I followed the example, but how do I page through
using VLV, to get the next set of entries, returned by the directory.
Thanks
#!/usr/bin/perl
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_text);
use Net::LDAP::Control::Sort;
use Net::LDAP::Constant qw(LDAP_CONTROL_SORTRESULT);
use Net::LDAP::Control::VLV;
use Net::LDAP::Constant qw( LDAP_CONTROL_VLVRESPONSE );
use POSIX qw(ceil);
my $qs = CGI->new;
my $ldap = Net::LDAP->new('myserver.com', port=> '389') || die "Error: $@";
my $pg = $qs->param('page');
my $sidx = $qs->param('sidx');
my $limit = $qs->param('rows');
my $sord = $qs->param('sord');
my $total_pages;
print $qs->header('text/html');
#my $start = $limit*$page - $limit;
#if ($start <0) { $start = 0
; }
# Get the first 30 entries
my $vlv = Net::LDAP::Control::VLV->new(
before => 0, # No entries from before target entry
after => 29, # 29 entries after target entry
content => 0, # List size unknown
offset => 1, # Target entry is the first
);
my $sort = Net::LDAP::Control::Sort->new( order => "$sidx" );
my @args = ( base => "OU=my users,DC=abc,DC=com",
scope => "subtree",
filter => "(&(employeetype=consultant)(divisionname=Information
Technology)(objectClass=inetOrgPerson))",
callback => \&process_entry, # Call this sub for each entry
control => [ $vlv, $sort ],
);
my $mesg = $ldap->search( @args );
my $count = $mesg->count();
print "<p>$count</p>";
# Get VLV response control
my ($resp) = $mesg->control( LDAP_CONTROL_VLVRESPONSE ) or die;
$vlv->response( $resp );
$vlv->scroll_page( 1 );
#---------------------------
#-
#- Functions
#-
#---------------------------
sub process_entry
{
my ( $mesg, $entry) = @_;
if ( !defined($entry) ) {
return;
}
$cn = $entry->get_value('cn');
print "$cn" . '<br/>';
}