]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 9 Mar 2016 03:08:54 +0000 (03:08 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 9 Mar 2016 03:08:54 +0000 (03:08 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/functions.php
lib/php/out.php

index 17fd8d906552d8c376eed9ff9b4b9b34dd49ba33..ae97db0b746ed5660961a8c00bcc52c17452798b 100644 (file)
@@ -536,13 +536,15 @@ EOF;
 
   function out2($rows,$head=array()) {
     #if (is_scalar($head)) bye(var_dump($head,true));
-    if (is_scalar($head)) $head = array($head);
-      #var_dump($head);
-      #return;
+
     if ($this->p('header') === '0' ) $head = false;
-    #self::bye($head);
-    #self::bye($this->p('header'));
-    #self::bye($this->p('format'));
+    elseif (is_scalar($head)) $head = array($head);
+# NB 09.03.16     elseif (count($rows)) {
+# NB 09.03.16       $first = self::ar_first($row);
+# NB 09.03.16       #if (self::is_hash($first))
+# NB 09.03.16       $head = array($head);
+# NB 09.03.16     }
+
     out::rows($this->p('format','csv'),$rows,$head);
     return true;
   }
@@ -573,16 +575,22 @@ EOF;
       return true;
 
     } elseif ($action == 'db.tables' or $action == 'tables') {
+
       foreach ($this->tables(true) as $name => $t) { $row=array('name'=>$t['name']);
-        if ($this->p('count')==='1') $row['count'] = $this->table($name)->count();
         foreach (array(
           'type',
+          'count',
           'engine',
           'created',
-        ) as $f) { if (isset($t[$f])) $row[$f] = $t[$f]; }
+        ) as $f) {
+          if (isset($t[$f])) $row[$f] = $t[$f];
+          if ($f=='count' and $this->p('count')==='1') $row['count'] = $this->table($name)->count();
+        }
         $rows[] = $row;
       }
+
       return $this->out2($rows);
+      return $this->out2($rows,array_keys($row));
       return $this->out2(array_values($this->tables(true)));
       return $this->out2($this->tables(),array('name'));
 
index bd7e7afcaf364fd8ac7992b5085ecf9b2ca8a7ee..764a77f9bdacba2fbbf78a9ab113bc9ba04c7095 100644 (file)
@@ -650,7 +650,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       #
       # Row
       #
-      if ($out_conf and $count !== 1) out::row_end($out_conf);
+      if ($out_conf and $count !== 1) out::concat($out_conf);
 
       $count_fields = 0;
 
index 04045f0791cde19d4cdacd35761f5cd1723ce9ed..26576cf707dcf0e0bb8990a5f3b85078b43d20cd 100644 (file)
@@ -154,7 +154,7 @@ function rtf2html($rtf) {
 }
 
 function html2pdf($html) {
-       $cmd="iconv -f utf-8 -t iso-8859-1 -c|htmldoc --encryption --webpage --no-title --header '...' --footer '...'";
+       $cmd="iconv -f utf-8 -t iso-8859-1 -c|htmldoc --encryption --webpage --no-title --header '...' --footer '...' -";
        $cmd .= " -t pdf -";
   return cmd2str($cmd,$html);
 }
index 51f3afefb1cec9b70b8421298aa1f0cb1a3601a4..ad9c2073cb0ca4646723aaa3315be11408aba8c1 100644 (file)
@@ -59,10 +59,16 @@ class Out extends Nb {
     if (!empty($o['enclose'])) echo $o['enclose'][0];
     if (!isset($o['head'])) return;
 
+#var_dump($head); return;
     if ($head === false) return;
-    if (empty($head) and self::is_hash($data[0])) {
-      $head = array_keys($data[0]);
+    if (empty($head)) {
+      if (self::is_hash($data[0])) {
+        $head = array_keys($data[0]);
+      } else {
+        return;
+      }
     }
+
     echo $o['head']($head,$o) . empty($o['eol']) ? '' : $o['eol'];
 
   }
@@ -84,7 +90,7 @@ class Out extends Nb {
     return false;
   }
 
-  public static function row_end($o) {
+  public static function concat($o) {
     if (!empty($o['rec'])) echo $o['rec'];
     if (!empty($o['eol'])) echo $o['eol'];
   }
@@ -94,6 +100,7 @@ class Out extends Nb {
   }
 
   public static function rows($type,&$data,$head=array()) {
+    #if (empty($head)) $head = array_fill(0,count($data[0]),'?');
     if (!isset(self::$types[$type])) self::bye("Unknow type: `$type`");
     $conf = self::$types[$type];
 
@@ -113,7 +120,7 @@ class Out extends Nb {
     self::begin($conf,$head);
 
     foreach ($data as $row) {
-      if ($count>0) out::row_end($conf);
+      if ($count>0) out::concat($conf);
       $count++;
 
       # Transform simple array into hash
@@ -166,7 +173,6 @@ function out_tag_head(&$data,$o) {
   $o['tag'] = isset($o['tag_head']) ? $o['tag_head'] : $o['tag'];
   $row = out::ar_first($data);
   if (!out::is_hash($row)) $row = $data;
-  #if (!is_array($row)) return out_csv(array_fill(0,count($row),'?'));
   if (!is_array($row)) return 0;
   if (out::is_hash($row)) $row = array_keys($row);
   echo out_tag($row,$o);