print '<tr class="liste_titre">'; print '<td>' . $langs->trans("LDAPAttributes") . '</td>'; print '<td>' . $langs->trans("Value") . '</td>'; print '</tr>'; // Lecture LDAP $ldap = new Ldap(); $result = $ldap->connect_bind(); if ($result > 0) { $info = $contact->_load_ldap_info(); $dn = $contact->_load_ldap_dn($info, 1); $search = "(" . $contact->_load_ldap_dn($info, 2) . ")"; $records = $ldap->getAttribute($dn, $search); //var_dump($records); // Affichage arbre if (count($records) && $records != false && (!isset($records['count']) || $records['count'] > 0)) { if (!is_array($records)) { print '<tr ' . $bc[false] . '><td colspan="2"><font class="error">' . $langs->trans("ErrorFailedToReadLDAP") . '</font></td></tr>'; } else { $result = show_ldap_content($records, 0, $records['count'], true); } } else { print '<tr ' . $bc[false] . '><td colspan="2">' . $langs->trans("LDAPRecordNotFound") . ' (dn=' . $dn . ' - search=' . $search . ')</td></tr>'; } $ldap->unbind(); $ldap->close(); } else { dol_print_error('', $ldap->error); } print '</table>'; $db->close(); llxFooter();
/** * Show a LDAP array into an HTML output array. * * @param string $result Array to show. This array is already encoded into charset_output * @param int $level Level * @param int $count Count * @param string $var Var * @param int $hide Hide * @param int $subcount Subcount * @return int */ function show_ldap_content($result, $level, $count, $var, $hide = 0, $subcount = 0) { global $bc, $conf; $count--; if ($count == 0) { return -1; } // To stop loop if (!is_array($result)) { return -1; } foreach ($result as $key => $val) { if ("{$key}" == "objectclass") { continue; } if ("{$key}" == "count") { continue; } if ("{$key}" == "dn") { continue; } if ("{$val}" == "objectclass") { continue; } $lastkey[$level] = $key; if (is_array($val)) { $hide = 0; if (!is_numeric($key)) { $var = !$var; print '<tr ' . $bc[$var] . ' valign="top">'; print '<td>'; print $key; print '</td><td>'; if (strtolower($key) == 'userpassword') { $hide = 1; } } show_ldap_content($val, $level + 1, $count, $var, $hide, $val["count"]); } else { if ($subcount) { $subcount--; $newstring = dol_htmlentitiesbr($val); if ($hide) { print preg_replace('/./i', '*', $newstring); } else { print $newstring; } print '<br>'; } } if ("{$val}" != $lastkey[$level] && !$subcount) { print '</td></tr>'; } } return 1; }