update readme
[auerswald-compact-ldap.git] / ldap2csv.php
old mode 100644 (file)
new mode 100755 (executable)
index 788495a..dd779a6
@@ -1,3 +1,4 @@
+#!/usr/bin/env php
 <?php
 /**
  * Fetches all entries from the LDAP server and outputs a CSV file
@@ -38,7 +39,7 @@ $search = $ldap->search(
     array(
         'scope' => 'sub',
         'attributes' => array_merge(
-            array('displayName', 'cn',),
+            array('displayName', 'cn'),
             $numberfields
         )
     )
@@ -50,6 +51,12 @@ if (Net_LDAP2::isError($search)) {
 echo "Kurzwahl;Rufnummer;Name\n";
 while ($entry = $search->shiftEntry()) {
     $a = $entry->getValues();
+    if (count($a) == 0) {
+        continue;
+    }
+    if (strpos($entry->dn(), ',ou=test,') !== false) {
+        continue;
+    }
     if (isset($a['displayName'])) {
         $name = $a['displayName'];
     } else {
@@ -58,7 +65,17 @@ while ($entry = $search->shiftEntry()) {
 
     foreach ($numberfields as $nfield) {
         if (isset($a[$nfield])) {
-            echo sprintf(";%s;%s\n", $a[$nfield], $name);
+            foreach ((array)$a[$nfield] as $fv) {
+                echo sprintf(
+                    ";%s;%s\n",
+                    str_replace(
+                        array(' ', '+'),
+                        array('', '00'),
+                        $fv
+                    ),
+                    utf8_decode($name)
+                );
+            }
         }
     }
 }