From c1e415f41f9573c5d4cbf50d2cd7d5ace774df63 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 28 May 2026 10:26:29 +0200 Subject: [PATCH] lib/php/db/table.php --- lib/php/db/table.php | 13 ++++---- www/dbq/dbq.php | 70 ++++++-------------------------------------- 2 files changed, 16 insertions(+), 67 deletions(-) diff --git a/lib/php/db/table.php b/lib/php/db/table.php index a3cd805d..f917a8c4 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1146,13 +1146,14 @@ Class Table extends nb { private function fields_add_missing(&$fields,$row) { + $new = []; # we reconstruct the array to keep order foreach (array_keys($row) as $name) { - if (isset($fields[$name])) continue; - #if (isset($fields[$name])) debug($fields[$name]->name); - #if (!isset($fields[$name])) debug($name); - #if (!isset($fields[$name])) debug($fields[$name]->type); - $fields[$name] = new Field([ + if (isset($fields[$name])) { + $new[$name] = $fields[$name]; + continue; + } + $new[$name] = new Field([ 'name' => $name, 'dyn' => true, 'table' => $this, @@ -1161,6 +1162,7 @@ Class Table extends nb { } + $fields = $new; return $fields; } @@ -1664,7 +1666,6 @@ Class Table extends nb { $html .= ''.NB_EOL; // Columns names -# NB 12.09.18 $html .= ''.NB_EOL; $html .= ''.NB_EOL; if ($this->buttons() and DB_HTML_EDIT) $html .= ''.NB_EOL; foreach ($fields as $name => $f) { diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index fd2c705b..097e40d7 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -192,65 +192,6 @@ class DbQ extends nb { } - # NB 08.10.24 public function ldap($table='',$attrs=[]) { - # NB 08.10.24 $this->deniedUnless($this->perm >= self::ADMIN); -# NB 08.10.24 - # NB 08.10.24 require_once(NB_ROOT.'/lib/php/ldap.php'); - # NB 08.10.24 #debug($GLOBALS['DBQ_LDAP']); - # NB 08.10.24 $dn = join(',',$attrs); - # NB 08.10.24 $ldap = new Ldap($GLOBALS['DBQ_LDAP']); -# NB 08.10.24 - # NB 08.10.24 if ($table == 'add') { - # NB 08.10.24 $this->deniedUnless($this->perm >= self::WRITE); - # NB 08.10.24 $rows = (int)$ldap->add($dn,$_POST); -# NB 08.10.24 - # NB 08.10.24 } elseif ($table == 'update') { - # NB 08.10.24 $this->deniedUnless($this->perm >= self::WRITE); - # NB 08.10.24 $rows = (int)$ldap->update($dn,$_POST); -# NB 08.10.24 - # NB 08.10.24 } elseif ($table == 'rm') { - # NB 08.10.24 $this->deniedUnless($this->perm >= self::DELETE); - # NB 08.10.24 $rows = (int)$ldap->delete($dn,$_POST); -# NB 08.10.24 - # NB 08.10.24 } else { // ls - # NB 08.10.24 $this->deniedUnless($this->perm >= self::READ); -# NB 08.10.24 - # NB 08.10.24 $filter = ($table ? $table : ''); -# NB 08.10.24 - # NB 08.10.24 if (!empty($table) and !strpos($table,'=')) { - # NB 08.10.24 $filter = ''; - # NB 08.10.24 $attrs = explode(',',$table); - # NB 08.10.24 } -# NB 08.10.24 - # NB 08.10.24 $search = [ - # NB 08.10.24 'filter' => $filter, - # NB 08.10.24 'attrs' => $attrs, - # NB 08.10.24 ]; -# NB 08.10.24 - # NB 08.10.24 if (!$search['filter']) { - # NB 08.10.24 if (1 - # NB 08.10.24 and !empty($GLOBALS['DBQ_LDAP']['user']) - # NB 08.10.24 and preg_match('/^([^,]+),(.*?)$/',$GLOBALS['DBQ_LDAP']['user'],$m) - # NB 08.10.24 ) { - # NB 08.10.24 $search['filter'] = $m[1]; - # NB 08.10.24 $search['base'] = $m[2]; - # NB 08.10.24 } else { - # NB 08.10.24 $search['filter'] = 'cn='.Http::user(); - # NB 08.10.24 } - # NB 08.10.24 $search['filter'] = '(&('.$search['filter'].')(userPassword=*))'; - # NB 08.10.24 } - # NB 08.10.24 $rows = $ldap->search($GLOBALS['DBQ_LDAP'] + $search); -# NB 08.10.24 - # NB 08.10.24 if ($this->is_html - # NB 08.10.24 or ($this->params['format'] == $this->format_cli) - # NB 08.10.24 or ($this->params['format'] == 'csv') - # NB 08.10.24 ) $rows = $this->array_fill_assoc($rows); -# NB 08.10.24 - # NB 08.10.24 } -# NB 08.10.24 - # NB 08.10.24 return $rows; - # NB 08.10.24 } - public function page_table_ls($fields=null) { $this->deniedUnless($this->perm >= self::READ); @@ -587,7 +528,8 @@ class DbQ extends nb { $hidden = $this->form_hidden($r); - $r = $this->ar_unshift($r,'view','' + $r = $this->ar_unshift($r,'Edit','' + # NB 28.05.26 $this->ar_unshift($r,'view','' .'
' .'Edit' .$hidden @@ -609,7 +551,7 @@ class DbQ extends nb { # NB 03.02.18 if ($this->db->type == 'sqlite' and !is_writeable($this->db->host)) return; $rm = $this->uri_add_referer($this->table->base.'/rm'); - $r['delete'] = '' + $r['Delete'] = '' .'' .'Delete' .$hidden @@ -624,6 +566,12 @@ class DbQ extends nb { } private function ar_unshift( array & $array, $key, $val) { + $new = []; + $new[$key] = $val; + foreach ($array as $k=>$v) { + $new[$k] = $v; + } + return $new; # NB 05.01.18: Escape html ??????? we use reverse # NB 05.01.18 return $array + [ $key => $val ]; $array = array_reverse($array, 1); -- 2.47.3