4 * Fetches all entries from the LDAP server and outputs a CSV file
5 * compatible with a Auerswald COMpact 3000's address book upload.
10 * @package auerswald-compact-ldap
11 * @author Christian Weiske <cweiske@cweiske.de>
12 * @license http://www.gnu.org/licenses/agpl.html AGPL v3 or later
14 if (!is_file(__DIR__ . '/config.php')) {
15 echo "Copy config.php.dist to config.php and adjust it.\n";
18 require_once __DIR__ . '/config.php';
19 require_once 'Net/LDAP2.php';
21 $ldap = Net_LDAP2::connect($ldapcfg);
22 if (Net_LDAP2::isError($ldap)) {
23 die('Could not connect to LDAP-server: ' . $ldap->getMessage() . "\n");
26 $numberfields = array(
28 'facsimileTelephoneNumber',
29 'homeFacsimileTelephoneNumber',
37 $search = $ldap->search(
41 'attributes' => array_merge(
42 array('displayName', 'cn'),
47 if (Net_LDAP2::isError($search)) {
48 die('Error searching: ' . $search->getMessage() . "\n");
51 echo "Kurzwahl;Rufnummer;Name\n";
52 while ($entry = $search->shiftEntry()) {
53 $a = $entry->getValues();
57 if (strpos($entry->dn(), ',ou=test,') !== false) {
60 if (isset($a['displayName'])) {
61 $name = $a['displayName'];
66 foreach ($numberfields as $nfield) {
67 if (isset($a[$nfield])) {
68 foreach ((array)$a[$nfield] as $fv) {