Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl use CGI; use Net::LDAP qw(:all); use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; print $q->header; if($q->param('looking') eq 'yes'){ $ldap = Net::LDAP->new('ldapserver') or die "$@"; $ldap->bind; # an anonymous bind my $base = "c=us"; my @Attrs = (); my $search = "(&"; if($q->param('first') ne ''){ $search = "$search (givenName=" . $q->param('first') . ")" +; } if($q->param('last') ne ''){ $search = "$search (sn=" . $q->param('last') . ")"; } if($q->param('dept') ne ''){ $search = "$search (Department=" . $q->param('dept') . ")" +; } if($q->param('phone') ne ''){ $search = "$search (telephoneNumber=" . $q->param('phone') + . ")"; } if($q->param('fax') ne ''){ $search = "$search (facsimileTelephoneNumber=" . $q->param +('fax') . ")"; } $search = $search . ")"; $result = LDAPsearch($ldap, $search,\@Attrs); @entries = $result->entries; $ldap->unbind; # take down session } print <<EODUMP; header goes here <form method="post" action="directory.pl"> <input type=hidden name=looking value=yes> <table width="85%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"><font size="2">Use this form to find a emp +loyee. Enter as much information as you know.</font></td> </tr> <tr> <td width="20%"><font size="2">first Name</font></td> <td width="80%"> <input type="text" name="first" size="25"> </td> </tr> <tr> <td width="20%"><font size="2">Last Name</font></td> <td width="80%"> <input type="text" name="last" size="25" value="$user"> </td> </tr> <tr> <td width="20%"><font size="2">Department Name</font></td> <td width="80%"> <input type="text" name="dept" size="25"> </td> </tr> <tr> <td width="20%"><font size="2">Phone</font></td> <td width="80%"> <input type="text" name="phone" size="25"> </td> </tr> <tr> <td width="20%"><font size="2">Fax</font></td> <td width="80%"> <input type="text" name="fax" size="25"> </td> </tr> <tr align="center"> <td colspan="2"><input type=image src="images/go.gif" widt +h="30" height="20" border=0 alt="submit button"></a></td> </tr> </table> </form> EODUMP PRINTRESULTS(); print <<EODUMP; footer goes here EODUMP sub PRINTRESULTS { print "<table>"; foreach $entr (@entries) { $phone = $entr->get('telephoneNumber'); $user = $entr->get('cn'); $email = $entr->get('mail'); $department = $entr->get('Department'); $address = $entr->get('address'); $address = $address->[0]; $department = $department->[0]; $phone = $phone->[0]; $user = $user->[0]; $email = $email->[0]; $title = $entr->get('title'); $title = $title->[0]; $street = $entr->get('postalAddress'); $street = $street->[0]; print "<tr><td><a href=\"mailto:$email\">$user</a></td>\n +"; print "<td>$phone</td></tr>\n"; print "<tr><td>$department, $title\n</td></tr>\n"; print "<tr><td>$street</td>\n"; print "<tr><td>&nbsp;</td></tr>\n"; } print "</table>"; } sub LDAPsearch { my ($ldap,$searchString,$attrs) = @_ ; my $result = $ldap->search ( base => "$base", scope => "sub", filter => "$searchString", attrs => $attrs, sizelimit => $size_limit ); }

In reply to LDAP Searcher by BigJoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (8)
    As of 2015-07-08 03:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (93 votes), past polls