From 8c06a341c85466693e52a615052f9a2c3396621c Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 7 Feb 2018 18:26:29 +0000 Subject: [PATCH] lib/php/db/types/ldap.php --- lib/php/db/field.php | 5 +++-- lib/php/db/table.php | 14 +++++++++++++- lib/php/db/types/ldap.php | 2 ++ www/dbq/dbq.php | 7 +------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/php/db/field.php b/lib/php/db/field.php index e71dfba9..84805a2f 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -70,12 +70,12 @@ class field extends nb { public function html_type() { # See: http://www.w3schools.com/html/html_form_input_types.asp - if (strpos($this->name,'password') !== false) return 'password" autocomplete="off'; + if (stripos($this->name,'password') !== false) return 'password" autocomplete="off'; if ($this->numeric() !== false) return 'number" step="any'; if ($this->autoincrement) return 'text" readonly="readonly'; return 'text'; # Html5 only - if (strpos($this->name,'email') !== false) return 'email'; # no safari + if (stripos($this->name,'mail') !== false) return 'email'; # no safari if (strpos($this->name,'color') !== false) return 'color'; # no safari, no ie # NOT READY if (strpos($this->type,'datetime') !== false) return 'datetime'; @@ -129,6 +129,7 @@ class field extends nb { $html .= $this->htmlYesNo($value); } else { + if ($tag == 'textarea' and $this->html_type() != 'text') $tag = 'input'; $html .= '<'.$tag .' name="'.$this->preffix.$this->name.$suff.'"' # NB 06.02.18 .' id="'.$this->name.'"' diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 60645c54..1ae96a42 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -877,6 +877,11 @@ Class Table extends nb { # NB 06.02.18 $this->add_fields($fields); # NB 06.02.18 } + public function replace_fields($fields) { + $this->fields = []; + return $this->add_fields($fields); + } + public function add_fields($fields) { foreach ($fields as $k => $v) { $key = false; @@ -1149,7 +1154,14 @@ Class Table extends nb { } else { $fct = function() use($st) { if ($st->execute()) return $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT); }; } - } + + } # < nosql + + # Check fields_only exists + if (!empty($this->fields_only)) foreach ($this->fields_only as $f) { + if (!$this->field($f)) $this->bye("Unknown field ".$f); + } + if (!empty($opt['query'])) return $st; # # Use the module out when format unknow diff --git a/lib/php/db/types/ldap.php b/lib/php/db/types/ldap.php index 81f9d71a..a56eb28c 100644 --- a/lib/php/db/types/ldap.php +++ b/lib/php/db/types/ldap.php @@ -22,6 +22,8 @@ $DB_TYPES['ldap'] = [ #'prepare' => function($sql) { return $this->ldap->prepare($sql); }, 'rows_prepare' => function($table,$sql) { $fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only); + $table->replace_fields($fields); + #debug(array_keys($table->fields())); #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; }, diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 39d06b71..fdd64913 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -237,12 +237,7 @@ class DbQ extends nb { $this->deniedUnless($this->perm >= self::READ); $fields_only = (string)$args === '' ? [] : explode(',',$args); - if (!empty($fields_only)) { - foreach ($fields_only as $f) { - if (!$this->table->field($f)) $this->error("Unknown field ".$f); - } - $this->table->fields_only = $fields_only; - } + if (!empty($fields_only)) $this->table->fields_only = $fields_only; $this->page($this,'table_rows'); } -- 2.47.3