/** * Queries public and private addressbooks, combining the * results * * @todo This function should be used where ever possible, replacing * lots of duplicate code */ function ldap_queryabooks($filter, $types) { global $conf; global $LDAP_CON; // make sure $types is an array if (!is_array($types)) { $types = explode(',', $types); $types = array_map('trim', $types); } $results = array(); $result1 = array(); $result2 = array(); $result3 = array(); // public addressbook $sr = @ldap_list($LDAP_CON, $conf['publicbook'], $filter, $types); tpl_ldaperror(); $result1 = ldap_get_binentries($LDAP_CON, $sr); ldap_free_result($sr); // private addressbook if (!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']) { $sr = @ldap_list($LDAP_CON, $conf['privatebook'] . ',' . $_SESSION['ldapab']['binddn'], $filter, $types); if (ldap_errno($LDAP_CON) != 32) { tpl_ldaperror(); } // ignore missing address book $result2 = ldap_get_binentries($LDAP_CON, $sr); } // user account entries if ($conf['displayusertree']) { $sr = @ldap_list($LDAP_CON, $conf['usertree'], $filter, $types); tpl_ldaperror(); $result3 = ldap_get_binentries($LDAP_CON, $sr); ldap_free_result($sr); } // return merged results return array_merge((array) $result1, (array) $result2, (array) $result3); }
/** * saves the data from $_REQUEST['entry'] to the LDAP directory * * returns given or constructed dn */ function _saveData() { global $LDAP_CON; global $conf; global $FIELDS; global $OCLASSES; $entry = $_REQUEST['entry']; $dn = $_REQUEST['dn']; //construct new dn $new_uid = time() . str_pad(mt_rand(0, 99999999), 8, "0", STR_PAD_LEFT); $newdn = 'uid=' . $new_uid; if (empty($_REQUEST['type'])) { $_REQUEST['type'] = 'public'; } if ($_REQUEST['type'] == 'private' && $conf['privatebook']) { $newdn .= ', ' . $conf['privatebook'] . ', ' . $_SESSION['ldapab']['binddn']; } else { $newdn .= ', ' . $conf['publicbook']; } $entry['displayname'] = $entry['givenname'] . ' ' . $entry['name']; $entry = prepare_ldap_entry($entry); /* print '<pre>'; print_r($entry); print '</pre>'; */ if (empty($dn)) { //new entry $entry['uid'][] = $new_uid; $r = ldap_add($LDAP_CON, $newdn, $entry); tpl_ldaperror(); return $newdn; } else { // update the objectClasses ldap_store_objectclasses($dn, $OCLASSES); unset($entry['objectclass']); //modify entry attribute by attribute - this ensure we don't delete unknown stuff foreach (array_values($FIELDS) as $key) { if ($key == 'dn') { continue; } elseif (empty($entry[$key])) { // field is empty -> handle deletion (except for photo unless deletion triggered) if (empty($_REQUEST['delphoto'])) { $_REQUEST['delphoto'] = 0; } if ($key == 'jpegPhoto' && !$_REQUEST['delphoto']) { continue; } unset($del); $del[$key] = array(); $r = @ldap_mod_replace($LDAP_CON, $dn, $del); tpl_ldaperror("del {$key}"); } else { unset($add); $add[$key] = $entry[$key]; $r = @ldap_mod_replace($LDAP_CON, $dn, $add); tpl_ldaperror("mod {$key}"); } } // special tag handling for Thunderbird if ($conf['tbtaghack'] && in_array('contactPerson', $OCLASSES)) { for ($i = 1; $i < 5; $i++) { if (empty($entry["custom{$i}"])) { // deletion unset($del); $del["custom{$i}"] = array(); $r = @ldap_mod_replace($LDAP_CON, $dn, $del); tpl_ldaperror("del custom{$i}"); } else { // modification unset($add); $add["custom{$i}"] = $entry["custom{$i}"]; $r = @ldap_mod_replace($LDAP_CON, $dn, $add); tpl_ldaperror("mod custom{$i}"); } } } return $dn; } }