#!/usr/bin/perl
# Perl script for directory display. Includes generation of the
# standard appearance COM-FSM web page.
use CGI qw(:all);
use Net::LDAP;
sub searchresults;
# Set parameters for this specific page here
#
$page_title="Staff and Faculty Directory";
$BlueBar=" "; # Contents of the blue bar (use for an empty field)
# PageInfo is displayed right below the blue bar. Any html may be used
# here; it will be displayed in a page-wide table cell.
#
$PageInfo='COM-FSM Staff and Faculty Directory
Campus mailing address and
phone numbers · Submit new
or updated directory information
Enter part of a name, title, or other information and press
Search to locate COM-FSM staff members
';
$doSearch=0; # Do search first time called?
$offerSearch=1; # Show the search block?
$departmentLimit=0; # Only display/search for a single department
# Defaults to use when searching on this page.
#
$nameWant='';
$titleWant='';
$emailWant='';
$phoneWant='';
$departmentWant='';
$campusWant='';
# Locations of files and such
#
$DepartmentData="department.dat";
$departmentLimit &= $departmentWant ne ''; # Can't limit if not specified
if (!$departmentLimit) {
# Read the DepartmentData file for the contents of it's pop-up menu.
#
push @departmentName, 'Any'; # an ALL choice to not limit selection.
$departmentDesc{'Any'}='Any department';
push @departmentName, 'OTHER'; # Possible to have non-specified div.
$departmentDesc{'OTHER'}='Division Not Specified';
open(PF,$DepartmentData);
while () {
chomp;
($dname, $ddesc)=split /:/, $_;
push @departmentName, $dname;
$departmentDesc{$dname}=$ddesc;
}
close(PF);
}
$CampusData="campus.dat";
$campusLimit &= $campusWant ne ''; # Can't limit if not specified
if (!$campusLimit) {
# Read the campusData file for the contents of it's pop-up menu.
#
push @campusName, 'Any'; # an ALL choice to not limit selection.
$campusDesc{'Any'}='Any campus';
open(PF,$CampusData);
while () {
chomp;
($cname, $cdesc)=split /:/, $_;
push @campusName, $cname;
$campusDesc{$cname}=$cdesc;
}
close(PF);
}
# The standard top table with logo, name, and navigation links
#
@pageTop=(
table({-width=>645, -summary=>'Seal and Title', -border=>0},
Tr(
td({-align=>'left', -width=>80, -rowspan=>3},
img{-src=>'/images/logo80.gif', -alt=>'COM-FSM Seal',
-width=>80, -height=>80}),
td({-align=>'center'},
(font{-size=>'+2'}, 'College of Micronesia-FSM'),
br,
'Federated States of Micronesia'),
td({-width=>80, -rowspan=>3}, ' ')),
Tr(
td(' ')),
Tr(
td({-align=>'center'},
a({-href=>'/computing/'}, 'Computing'), '·',
a({-href=>'/directory/'}, 'Directory'), '·',
a({-href=>'/'}, 'Home'), '·',
a({-href=>'/jobs/'}, 'Employment'), '·',
a({-href=>'/library/'}, 'Library'), '·',
a({-href=>'/news/'}, 'News')))));
# The remainder of the page is contained in a nested table
# structure. We need a form for searching too. We'll build the
# pieces ahead of time and then print them all at once later.
# We may have been called with a search already. Check and see.
#
if (param()) {
if (defined(param('Search'))) { # Pushed the Search button
$doSearch=1; # Perform the search later
$nameWant=param('nameWant');
$titleWant=param('titleWant');
$emailWant=param('emailWant');
$phoneWant=param('phoneWant');
$departmentWant=param('departmentWant');
$campusWant=param('campusWant');
}
}
if ($offerSearch) {
@searchBlock=(Tr({-align=>'left'},td(
table({-border=>0},
Tr(
td({-align=>'right'}, 'Name:'),
td({-align=>'left'},
textfield(
-name=>'nameWant',
-size=>17,
-default=>$nameWant)),
td({-align=>'right'}, 'Title:'),
td({-align=>'left', -colspan=>2},
textfield(
-name=>'titleWant',
-size=>30,
-default=>$titleWant))
),
Tr(
td({-align=>'right'}, 'E-Mail:'),
td({-align=>'left'},
textfield(
-name=>'emailWant',
-size=>17,
-default=>$emailWant)),
($departmentLimit)?
td({-colspan=>2}, hidden(
-name=>'departmentWant',
-default=>$departmentWant)):
(td({-align=>RIGHT}, 'Division:'),
td({-align=>LEFT}, popup_menu(
-name=>'departmentWant',
-values=>\@departmentName,
-labels=>\%departmentDesc,
-default=>$departmentWant))),
($campusLimit)?
td({-colspan=>2}, hidden(
-name=>'campusWant',
-default=>$campusWant)):
(td({-align=>RIGHT}, 'Campus:'),
td({-align=>LEFT}, popup_menu(
-name=>'campusWant',
-values=>\@campusName,
-labels=>\%campusDesc,
-default=>$campusWant)))
),
Tr(
td(' '),
td(submit(-name=>'Search', -value=>'Search'))
)),
"\n")));
}
# Print everything out that we generated above
#
print header,
start_html(
-title=>"COM-FSM $page_title",
-bgcolor=>'white',
-text=>'black',
-vlink=>'#0000ce'),
center(
@pageTop,
start_form,
table({-width=>645, -border=>0},
Tr(td({-bgcolor=>'#0000ce'}, (font{-color=>'white'},$BlueBar))),
(length($PageInfo))?Tr(td($PageInfo)):'',
@searchBlock,
end_form,
($doSearch)?searchresults:'',
Tr(
td(
a({-href=>'/'}, img{-src=>'/images/navigate.gif', -border=>0},
small('To COM-FSM Home Page'))))),
),
end_html;
# searchresults returns a table of matching persons in the directory,
# formatted for nesting into the outside table
#
sub searchresults {
my @ROrder, $match, $matchCount;
my $ldap;
$filter=""; # Build search filter
if (length($nameWant)) {
$filter.='(cn=*'.$nameWant.'*)';
}
if (length($titleWant)) {
$filter.='(title=*'.$titleWant.'*)';
}
if (length($emailWant)) {
$filter.='(mail=*'.$emailWant.'*)';
}
if (length($phoneWant)) {
$filter.='(telephoneNumber=*'.$phoneWant.'*)';
}
if (length($departmentWant) && !($departmentWant eq 'Any')) {
$filter.='(departmentNumber='.$departmentWant.')';
}
if (length($campusWant) && !($campusWant eq 'Any')) {
$filter.='(l='.$campusWant.')';
}
$matchCount=0;
if (length($filter)) { # Finish filter construction and do search
$filter='(&'.$filter.')';
$ldap=Net::LDAP->new('ldap://localhost');
$ldap->bind; # Anonymous bind; read-only
$m=$ldap->search(base=>'ou=Directory,dc=comfsm,dc=fm',filter=>$filter);
foreach $entry ($m->entries) {
$idx=substr(uc($entry->get_value('sn').$entry->get_value('givenName')),0,10);
$shortCampus=$campusDesc{$entry->get_value('l')};
$shortCampus=~s/ State| Campus//;
push @ROrder, "\n".
Tr(
td($entry->get_value('cn'),
($entry->exists('mail'))?
(br, a({-href=>'mailto:'.$entry->get_value('mail')},$entry->get_value('mail'))):''),
td({-valign=>'top'}, $entry->exists('title')?$entry->get_value('title'):' '),
td({-valign=>'top'}, $entry->exists('telephoneNumber')?$entry->get_value('telephoneNumber'):' '),
td({-valign=>'top'}, $shortCampus)
);
$matchCount++;
}
$ldap->unbind;
} else {
return Tr(td((font{-color=>'#0000ce'}, $filter, strong('No search criteria?'))));
}
if ($matchCount) { # Sort the data we found and then print.
@RSorted=sort @ROrder;
return Tr(td(
table({-width=>645, -border=>1},
Tr(
td({-width=>160, -bgcolor=>'#0000ce'},
(font{-color=>white}, 'Name / E-mail address')),
td({-width=>200, -bgcolor=>'#0000ce'},
(font{-color=>white}, 'Title')),
td({-width=>140, -bgcolor=>'#0000ce'},
(font{-color=>white}, 'Telephone')),
td({-width=>60, -bgcolor=>'#0000ce'},
(font{-color=>white}, 'Campus'))
),
@RSorted
)));
}
else {
return Tr(td((font{-color=>'#0000ce'}, strong('No records found.'))));
}
}