]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/types/ldap.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 5 Feb 2018 21:16:29 +0000 (21:16 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 5 Feb 2018 21:16:29 +0000 (21:16 +0000)
etc/dbq/ldap.php
lib/php/db/types/ldap.php
lib/php/ldap.php
www/dbq/dbq.php

index edebe26344aee907558fe1af9708026bc6d91a4f..af04172bc186aad4105873cd4a6a0bb7deb8ac42 100644 (file)
@@ -40,14 +40,15 @@ $GLOBALS['DBQ_LDAP'] = [
        'base' => $base,
 ];
 #'(&('.$search['filter'].')(userPassword=*))'
-if (preg_match('/^([^,]+),(.*?)$/',$user,$m)
-) {
+
+if (preg_match('/^([^,]+),(.*?)$/',$user,$m)) {
        $filter = $m[1];
 } else {
        $filter = 'cn='.Http::user();
 }
+
 $filter = '(&('.$filter.')(userPassword=*))';
-$DBQ['ldap2'] = $GLOBALS['DBQ_LDAP'] + [
+$DBQ['ldap'] = $GLOBALS['DBQ_LDAP'] + [
        'type' => 'ldap',
        'tables' => [
                $filter => [
index 6687913df9f187de667f4e3edfd0abba8973078d..ae37ec1ee8891e9c0b4c83d98e0f1289557899c2 100644 (file)
@@ -8,10 +8,18 @@ $DB_TYPES['ldap'] = [
        'quote' => function($v) { return $v; },
        'nosql' => true,
        #'prepare' => function($sql) { return $this->ldap->prepare($sql); },
-       'prepare' => function($table,$sql) { $table->db()->ldap->prepare($sql); return $table->db()->ldap; },
+       'prepare' => function($table,$sql) {
+               $fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only);
+               #foreach (array_keys($table->fields) as $k) { if (!in_array($k,$fields)) unset($table->fields[$k]); }
+               $table->db()->ldap->prepare($sql,['attrs'=>$fields]); return $table->db()->ldap;
+       },
        'fetch' => function($table) {
-               $row = $table->db()->ldap->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT);
-               $row = $table->db()->ldap->ar_filter_keys($row,array_keys($table->fields()));
+               #debug($table->fields_only);
+               #debug($table->fields_only);
+               $row = $table->db()->ldap->fetch();
+               if (!$row) return [];
+               $fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only);
+               $row = $table->db()->ldap->ar_filter_keys($row,$fields);
                return $row;
        },
        '_connect' => function($db) {
index 75d00916000f8c33fe6bad7074c8dda52312da8a..6e687358c80a7480998654a6310bc256628ef8c0 100644 (file)
@@ -26,9 +26,12 @@ class Ldap {
 
        public static function ar_filter_keys($ar,$keys) {
                $new = [];
-               foreach ($keys as $k) {
-                       if (isset($ar[$k])) $new[$k] = $ar[$k];
+               foreach ($ar as $k => $v) {
+                       if (in_array($k,$keys)) $new[$k] = $v;
                }
+# NB 05.02.18          foreach ($keys as $k) {
+# NB 05.02.18                  if (isset($ar[$k])) $new[$k] = $ar[$k];
+# NB 05.02.18          }
                return $new;
        }
 
@@ -155,7 +158,7 @@ class Ldap {
                return $this->read;
        }
 
-       public function fetch($type='',$opt='') {
+       public function fetch($type='',$o='') {
                static $count = 0;
                if ($type === null) {
                        $count = 0;
index f6ef67ffe7bbe66e6a51f9a0871faa9f667f08b5..4e74eda404364a918866ac54408183ae2578e0a5 100644 (file)
@@ -1150,7 +1150,7 @@ EOF;
                        }
                        $this->page($types);
 
-               } elseif ($action == 'ldap') {
+               } elseif ($action == 'ldap2') {
                        $table = $this->params['table'];
                        $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : ['dn','objectClass']);
                        $this->page($this->ldap($table,$attrs));
@@ -1325,6 +1325,7 @@ EOF;
                        $this->notImplemented('Unknown table action'." `$action`");
 
                }
+
        }
 
        public function redirect_if_no_referer($url) {