'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 => [
'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) {
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;
}
return $this->read;
}
- public function fetch($type='',$opt='') {
+ public function fetch($type='',$o='') {
static $count = 0;
if ($type === null) {
$count = 0;
}
$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));
$this->notImplemented('Unknown table action'." `$action`");
}
+
}
public function redirect_if_no_referer($url) {