]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/table.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 28 May 2026 08:26:29 +0000 (10:26 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 28 May 2026 08:26:29 +0000 (10:26 +0200)
lib/php/db/table.php
www/dbq/dbq.php

index a3cd805d0660a0eee2939fe9ccfc014c231ea40a..f917a8c45e90f8369ccbee93a362035c90216d3b 100644 (file)
@@ -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 .= '<thead>'.NB_EOL;
 
                        // Columns names
-# NB 12.09.18                  $html .= '<tr class="head">'.NB_EOL;
                        $html .= '<tr>'.NB_EOL;
                        if ($this->buttons() and DB_HTML_EDIT) $html .= '<th class="edit"></th>'.NB_EOL;
                        foreach ($fields as $name => $f) {
index fd2c705b87e67ce625dab8d61ce80cc032e2ba02..097e40d7d70eb6560d27362c2726305a1d855e9d 100644 (file)
@@ -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',''
                                        .'<form action="'.$this->table->base.'/vi'.'" method="post" class="vi">'
                                        .'<a class="button select vi btn btn-sm btn-secondary" href="'.$this->table->base.'/vi'.'" onclick="parentNode.submit();return false;">Edit</a>'
                                        .$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'] = ''
                                        .'<form action="'.$rm.'" method="post" class="rm">'
                                        .'<a class="button rm btn btn-sm btn-danger" href="'.$rm.'" onclick="parentNode.submit();return false;">Delete</a>'
                                        .$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);