]> git.nbdom.net Git - nb.git/commitdiff
dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 21 Dec 2016 15:06:42 +0000 (15:06 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 21 Dec 2016 15:06:42 +0000 (15:06 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/nb.php
www/dbq/dbq.php

index 3f614c1bbc360d27a7abb0b154e60c98ba3cc62b..0155b62c39872a49ea65a63bd5cdd64af0af4daa 100644 (file)
@@ -620,6 +620,7 @@ class Db extends nb {
 
     $rows = self::array_fill_assoc($rows);
     usort($rows,function($a,$b) { return strcmp($a['name'],$b['name']); });
+
     return $rows;
   }
 
index 7ee5614d795a390b6f96af66af824360f9c990b1..ed292cfb6a226432b876a3251a3e1f641e8753ff 100644 (file)
@@ -1775,7 +1775,7 @@ Class Table extends nb {
       $r .= '<div class="options">';
 
       // Hiddens
-      #if ($this->show_hidden_params)
+      if ($this->show_hidden_params)
       $r .= ''#.print_r(self::$params,true)
         .self::form_hidden(['db','table','format','limit','download'])
         // Embed for no html format (rent)
index a0b151de3a871678007dc9a8fe5f08efe88ccb3f..4cb85e899dbdb10a48c6c941c9a9795b20ee4827 100644 (file)
@@ -838,28 +838,27 @@ class NB {
   public static function client_content_type($default='') {
     $v = explode(',', self::client_header('Accept'));
     return ( ($v and $v[0] != '*/*') ? $v[0] : $default );
-# NB 19.12.16     $headers = self::client_header();
-# NB 19.12.16     if (0
-# NB 19.12.16       or !isset($headers['Accept'])
-# NB 19.12.16       or $headers['Accept'] == '*/*'
-# NB 19.12.16     ) return '';
-# NB 19.12.16     $v = explode(',', $headers['Accept']);
-# NB 19.12.16     return $v ? $v[0] : '';
   }
 
-  public static function array_fill_assoc($rows) {
-    $keys = [];
-
-    foreach($rows as $k=>$v) {
-      $keys = array_merge_recursive(array_keys($v),$keys);
+  public static function array_fill_assoc($rows,$keys=null) {
+    if ($keys === null) {
+      $keys = [];
+      foreach(array_reverse($rows) as $v) {
+        foreach ($v as $k=>$vv) $keys[$k] = 1;
+      }
+      $keys = array_keys($keys);
     }
 
+    # NB 21.12.16: to keep order we need a new array 
+    $new = [];
     foreach($rows as $k=>$v) {
       foreach ($keys as $key) {
-        if (empty($v[$key])) $rows[$k][$key] = '';
+        $new[$k][$key] = isset($v[$key]) ? $v[$key] : '';
+        if (!isset($v[$key])) $rows[$k][$key] = '';
       }
     }
 
+    return $new;
     return $rows;
   }
 
index 78e7aa21bd45aebd16d6b2c8b077c8a9e9844a41..c5e6d56f0b403d2f8603e98f91810d7619dcc0b7 100644 (file)
@@ -162,16 +162,51 @@ function form_clean(form) {
       e.value = ""
     }
 }
+function form_submit_clean(f) {
+  var i = 0;
+  var url = "";
+  var action = f.getAttribute("action");
+  var method = f.getAttribute("method");
+  if (method != "get") return true;
+
+  //if (typeof(action) == "undefined") action = "";
+
+  for(i=0;i<f.length;i++) {
+    var p = f[i];
+    if (!p.name) continue;
+    if (p.value=="") continue;
+    if (p.value=="undefined") continue;
+// NB 02.09.13                 url += (url ? "&" : "?") + escape(p.name) + "=" + escape(p.value);
+    url += (url ? "&" : "?") + encodeURI(p.name) + "=" + encodeURI(p.value);
+  }
+
+  url = (action == "?" ? "" : action) + url;
+
+  //document.location = url;
+
+  //if (url == window.location) return false;
+  window.location = url;
+  return false;
+}
 document.addEventListener("DOMContentLoaded", function() {
+  for (var e of document.querySelectorAll("form")) {
+    e.onsubmit = function() {
+      form_submit_clean(this);
+      return false;
+    };
+  }
+
   for (var e of document.querySelectorAll(".menu select.limit")) {
     e.onchange = function() {
       this.form.submit();
       return false;
     };
   }
+  document.getElementById("table").removeAttribute("name");
+  document.getElementById("format").removeAttribute("name");
   for (var e of document.querySelectorAll(".menu select.tables, .menu select.format")) {
     e.onchange = function() {
-      window.location =  "./" + this.form.elements["table"].value + "." + this.form.elements["format"].value;
+      window.location =  "./" + document.getElementById("table").value + "." + document.getElementById("format").value;
       return false;
     };
   }
@@ -270,9 +305,6 @@ document.addEventListener("DOMContentLoaded", function() {
 
   public function table_rows($fct=null) {
 
-    if ($this->page->is('html')) {
-      #debug($this->page->content_type());
-    }
     $opt = ($this->page->is('html')
       and ($this->perm >= self::VIEW)
       and $this->table->type() != 'sql'
@@ -283,7 +315,6 @@ document.addEventListener("DOMContentLoaded", function() {
         '<input type="button" class="button button-small" onclick="form_clean(this.form)" value="X"/>',
       ]),
       'row_parse_pre' => function(&$r){
-
         $GLOBALS['dbq_args'] = urlencode( join(self::PARAM_ARGS_SEP,$this->table->fields_keys_values($r)) );
       },
       'row_parse_post' => function(&$r){