Scott M. Mcdermott

UNIX Systems & Network Administrator
available for contract or salaried positions

groups.php

<?

include("common.php");

/*****************************************************************************/

$attrs = array(
        "owner"         => "owner",
        "desc"          => "description",
        "member"        => "uniqueMember",
        "name"          => "cn",
        "address"       => "corpMailLocalAddress",
);
$sortkey = "name";

define("LDAP_FILTER_GROUPS", "(&(objectclass=groupOfUniqueNames)" .
                               "(objectClass=corpMailRecipient))");

if (!($search = ldap_search($_SESSION["bind_linkid"], LDAP_BASE_DN_GROUPS,
                            LDAP_FILTER_GROUPS, array_values($attrs))))
        die("ldap search returned failure");

if (!($allgroups = _ldap_get_entries($_SESSION["bind_linkid"], $search)))
        die("search succeeded but returned no entries!");

/* ldap_get_entries() prepends a `count' associative index to each of the
 * dimensioned arrays it constructs; we get rid of it here before calling the
 * sort function because otherwise it will get confused. */
if (!isset($allgroups["count"]))
        die("_ldap_get_entries had nothing to find!");
unset($allgroups["count"]);
uasort($allgroups, "sortcallback");
reset($allgroups);

/*****************************************************************************/

pagehead("Company Directory - Groups", "Group Directory",
         MENU_NAVBAR_HEADER);

?>
<table valign=top align=left border=0 width="100%" cellspacing=0 cellpadding=2>
<tr> <td> &nbsp; </td> </tr>
<tr>
        <td nowrap class=tablehead> group name </td>
        <td nowrap class=tablehead> email enabled? &nbsp; &nbsp; </td>
        <td nowrap class=tablehead> owner </td>
        <td nowrap class=tablehead> description </td>
<?
$rowclasses = array("tablecell", "tablealtcell");
foreach ($allgroups as $group) {
        $rowclass = next($rowclasses);
        $rowclass = $rowclass? $rowclass: reset($rowclasses);
?>      <tr valign=top class=<?echo($rowclass)?>>
<?      printf("<td nowrap> <a href=\"/groupedit.php?cn=%s\"> %s </a> </td>\n",
               $group[$attrs["name"]][0], $group[$attrs["name"]][0]);
        if (isset($group[$attrs["address"]][0]))
                $mail = "yes";
        else
                $mail = "no";
        printf("<td nowrap align=center> %s &nbsp; &nbsp; </td>\n", $mail);
        printf("<td nowrap> %s &nbsp; &nbsp; </td>\n",
               trim_dn_to_firstval($group[$attrs["owner"]][0]));
        printf("<td> %s </td>\n", $group[$attrs["desc"]][0]);
}
?>
</table>
<?

pagefoot();

/*****************************************************************************/

function
trim_dn_to_firstval ($s)
{
        /* a DN of form "anything=blah,whatever=something,..." becomes "blah" */
        return array_pop(split("=", array_shift(split(",", $s))));
}

?>