]> git.nbdom.net Git - nb.git/commitdiff
dbq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 27 Dec 2016 19:20:33 +0000 (19:20 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 27 Dec 2016 19:20:33 +0000 (19:20 +0000)
lib/php/db/table.php
lib/php/nb.php
lib/php/out.php
www/dbq/dbq.php

index 0939f1968d87bb2cbe8a7dfc70a5b96f0c7458a1..146831153cdcf3be82ea559f449625f6dcf3eeaf 100644 (file)
@@ -945,7 +945,7 @@ Class Table extends nb {
     $opt['use_out'] = false;
 
     if ($this->p('out') or !preg_match('/^('.join('|',
-      [ '','template','table','sql','div','wp' ] # local
+      [ '','template','table','sql','_div','wp' ] # local
     ).')$/',$format))
     {
 
@@ -1347,13 +1347,14 @@ Class Table extends nb {
     #if (!empty($opt)) $html .= '<caption>' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '</caption>' .NB_EOL;
 
     $this->__rows_table_attr = [];
-    $this->__rows_table_keys = [];
+# NB 27.12.16     $this->__rows_table_keys = [];
     foreach ($fields as $name => $f) {
       $this->__rows_table_attr[$name] = ''
         . ' class="' . $name . ($f->key?' key':'') . (isset($this->extras[$name])?' extra':'') . '"'
       ;
-      if ($f->key) $this->__rows_table_keys[] = $name;
+# NB 27.12.16       if ($f->key) $this->__rows_table_keys[] = $name;
     }
+# NB 27.12.16     if (empty($this->__rows_table_keys)) $this->__rows_table_keys = array_keys($fields);
 
     if ($this->show_header) {
       $html .= '<thead>'.NB_EOL;
@@ -1393,13 +1394,13 @@ Class Table extends nb {
 
     $buttons = $this->html_row_buttons($row);
 
-    $id = [];
-    foreach ($this->__rows_table_keys as $k) {
-      $id[] = $row[$k];
-    }
-    $id = empty($id) ? '' : ' '.'__'.join('__',$id).'__';
-
-    $html = '<tr class="row'.$id.'">'.NB_EOL;
+# NB 27.12.16     $id = [];
+# NB 27.12.16     foreach ($this->__rows_table_keys as $k) {
+# NB 27.12.16       $id[] = $row[$k];
+# NB 27.12.16     }
+# NB 27.12.16     $id = empty($id) ? '' : ' '.'__'.join('__',$id).'__';
+# NB 27.12.16     $html = '<tr class="row'.$id.'">'.NB_EOL;
+    $html = '<tr class="row">'.NB_EOL;
 
     if ($this->buttons() and !empty($buttons[0])) $html .= '<td class="action">'.$buttons[0].'</td>'.NB_EOL;
 
@@ -1415,7 +1416,8 @@ Class Table extends nb {
   }
 
   public function rows_end_table() {
-    unset($this->__rows_table_attr,$this->__rows_table_keys);
+    unset($this->__rows_table_attr);
+# NB 27.12.16     unset($this->__rows_table_keys);
     $html = '';
     $html .= '</tbody>'.NB_EOL;
     $html .= '</table>'.NB_EOL;
index 972d768b37eda461d9efe456b7a8ed1e3565bd65..54749a0dca3c0142939f42e063177c5312df6c62 100644 (file)
@@ -591,18 +591,14 @@ class NB {
     if (in_array($name,get_class_methods($class))) $rows = $class->$name();
     elseif (in_array($name,get_class_vars($class_name))) $rows = $class->$name;
     else self::bye("Unknown action: `$action`");
-    #else $rows = $class->$name;
+
     if (is_array($rows) and !$rows) return $rows;
     if (!$rows) return false;
     if ($rows === true) return true;
 
-    #bye($rows);
     if (is_scalar($rows)) {
-      #echo "$rows\n";
       $rows = array($name => $rows);
-      #return true;
     }
-    #debug($action.' '.$class_name.' '.$name);
     out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : []));
     return true;
   }
index 77fe99569d5667b5f4035f8fc84b473d4c0f9ec5..16712b0103b7707eae09359c3aecb9f3c850d3dd 100644 (file)
@@ -67,8 +67,8 @@ Class Out extends Nb {
                 if ($size) {
                   $align = $size>0 ? STR_PAD_LEFT : STR_PAD_RIGHT;
                   $size = abs($size);
-                  if ($count>1) $size -= mb_strlen($o['sep'],out::$charset);
-                  $v = out::mb_str_pad($v, $size, ' ',$align);
+                  if ($count>1) $size -= mb_strlen($o['sep'],self::$charset);
+                  $v = self::mb_str_pad($v, $size, ' ',$align);
                 }
 
                 return $v;
@@ -162,7 +162,7 @@ Class Out extends Nb {
         'row' => function (&$o,&$row) {
           echo ($o['eol'] ? '  ' : '')."<row>".$o['eol'];
           foreach ($row as $k => $v) {
-            echo ($o['eol'] ? '    ' : '')."<$k><![CDATA[".out::scalar($v)."]]></$k>".$o['eol'];
+            echo ($o['eol'] ? '    ' : '')."<$k><![CDATA[".self::scalar($v)."]]></$k>".$o['eol'];
           }
           echo ($o['eol'] ? '  ' : '')."</row>".$o['eol'];
         },
@@ -184,7 +184,7 @@ Class Out extends Nb {
       'yaml' => [
         'enclose' => ["---\n",""],
         'row' => function (&$o,&$row) {
-          $yaml = '- '.out::yaml_encode($row);
+          $yaml = '- '.self::yaml_encode($row);
           $yaml = preg_replace("/^(?!-)/m","  ",$yaml);
           echo $yaml;
         }
@@ -256,7 +256,6 @@ Class Out extends Nb {
   }
 
   public static function type_call($k,&$o,&$row=[]) {
-
     static $methods;
 
     if (!isset($o[$k])) {
@@ -277,6 +276,11 @@ Class Out extends Nb {
       $call = $o[$k];
       echo $call($o,$row);
 
+    # Internal method
+    } elseif(is_scalar($o[$k]) and preg_match('/^out_tag|out_human/',$o[$k])) {
+      $f = $o[$k];
+      echo self::$f($o,$row);
+
     # String
     } elseif(is_scalar($o[$k])) {
       echo $o[$k];
@@ -344,7 +348,7 @@ Class Out extends Nb {
 
     # Assume html/xml tag style
     } elseif (isset($o['tag'])) {
-      $ret = out_tag($o,$row);
+      $ret = self::out_tag($o,$row);
 
     } else {
       # txt
@@ -446,7 +450,7 @@ Class Out extends Nb {
    */
   public static function row_parse(&$row,$o=[]) {
     foreach ($row as $k => $v) {
-      $row[$k] = out::format($v,null,$o);
+      $row[$k] = self::format($v,null,$o);
     }
     if (isset($o['row_parse_post'])) {
       $o['row_parse_post']($row);
@@ -553,7 +557,7 @@ Class Out extends Nb {
       if (!empty($o['quote'])) $v = $o['quote'] .
         str_replace($o['quote'],$o['quote_escape'].$o['quote'],$v)
       . $o['quote'];
-      $values[] = str_replace("\n",'\\n',out::scalar($v));
+      $values[] = str_replace("\n",'\\n',self::scalar($v));
     }
 
     if (!empty($o['return'])) return join($o['sep'],$values);
@@ -576,164 +580,160 @@ Class Out extends Nb {
     );
   }
 
-} Out::init() ; # < Class
-/*--------------------------------------------------------------------------*/
-// Functions
-/*--------------------------------------------------------------------------*/
-
-//
-// Tag
-//
-function out_tag_head($o,&$data) {
-  if (isset($o['tag_head'])) $o['tag'] = $o['tag_head'];
-  $row = out::ar_first($data);
-  if (!out::is_hash($row)) $row = $data;
-  if (!is_array($row)) return 0;
-
-  # For object
-  if (out::is_hash($row)) $row =  array_combine(array_keys($row),array_keys($row));
-
-  # Avoid: <th class="0">name</th>
-  if (!out::is_hash($row)) $row =  array_combine(array_values($row),array_values($row));
-  out_tag($o,$row);
-}
-
-function out_tag(&$o,&$row) {
-  if (isset($o['tag_enclose'])) echo (NB_EOL ? '  ' : '').'<'.$o['tag_enclose'].'>'.NB_EOL;
-
-  out::row_parse($row,$o);
-  foreach ($row as $k => $v) {
-
-    # Inside tag, ex: label
-    if (isset($o['tag_key'])) {
-      $v = '<'.$o['tag_key'].'>'.$k.'</'.preg_replace('/ .*$/','',$o['tag_key']).'>'.$v;
-    }
-
-    # Tag = o[tag] or key
-    if (isset($o['tag'])) {
-      $class = is_numeric($k) ? '' : ' class="'.$k.'"';
-      $k = $o['tag'];
-    } else {
-      $class = '';
-    }
-
-    echo ''
-      .(NB_EOL ? '    ' : '')
-      ."<$k$class>$v</$k>"
-      .NB_EOL
-    ;
+  //
+  // Tag
+  //
+  public static function out_tag_head($o,&$data) {
+    if (isset($o['tag_head'])) $o['tag'] = $o['tag_head'];
+    $row = self::ar_first($data);
+    if (!self::is_hash($row)) $row = $data;
+    if (!is_array($row)) return 0;
+
+    # For object
+    if (self::is_hash($row)) $row =  array_combine(array_keys($row),array_keys($row));
+
+    # Avoid: <th class="0">name</th>
+    if (!self::is_hash($row)) $row =  array_combine(array_values($row),array_values($row));
+    self::out_tag($o,$row);
   }
 
-  if (isset($o['tag_enclose'])) echo (NB_EOL ? '  ' : '').'</'.preg_replace('/ .*$/','',$o['tag_enclose']).'>'.NB_EOL;
-}
+  public static function out_tag(&$o,&$row) {
+    if (isset($o['tag_enclose'])) echo (NB_EOL ? '  ' : '').'<'.$o['tag_enclose'].'>'.NB_EOL;
 
-//
-// Human
-//
-function out_human_head(&$o,$head) {
-  #$line = "a\tb\tc\t\t\tg"; bye(explode("\t",$line));
-
-  if (!out::header()) return '';
-  $o['_human'] = [
-    'head' => 1,
-  ];
-  if (out::is_hash($head)) $head = array_keys($head);
-  return out_human($o,$head);
-}
+    self::row_parse($row,$o);
+    foreach ($row as $k => $v) {
 
-function out_human(&$o,&$row) {
+      # Inside tag, ex: label
+      if (isset($o['tag_key'])) {
+        $v = '<'.$o['tag_key'].'>'.$k.'</'.preg_replace('/ .*$/','',$o['tag_key']).'>'.$v;
+      }
 
-  # Init options
-  if (empty($o['_human'])) $o['_human'] = [];
-  if (!isset($o['_human']['len'])) {
-    $o['_human']['len'] = [];
+      # Tag = o[tag] or key
+      if (isset($o['tag'])) {
+        $class = is_numeric($k) ? '' : ' class="'.$k.'"';
+        $k = $o['tag'];
+      } else {
+        $class = '';
+      }
 
-    $o['_human']['sep'] = $o['sep'];
-    $o['sep'] = "\t";
+      echo ''
+        .(NB_EOL ? '    ' : '')
+        ."<$k$class>$v</$k>"
+        .NB_EOL
+      ;
+    }
 
-    $o['_human']['eol'] = $o['eol'];
-    $o['eol'] = "";
+    if (isset($o['tag_enclose'])) echo (NB_EOL ? '  ' : '').'</'.preg_replace('/ .*$/','',$o['tag_enclose']).'>'.NB_EOL;
+  }
 
-    $o['tmpfile'] = tmpfile();
+  //
+  // Human
+  //
+  public static function out_human_head(&$o,$head) {
+    #$line = "a\tb\tc\t\t\tg"; bye(explode("\t",$line));
 
-    # no csv echo call
-    $o['return'] = true;
-    $o['_human']['len'] = [];
+    if (!self::header()) return '';
+    $o['_human'] = [
+      'head' => 1,
+    ];
+    if (self::is_hash($head)) $head = array_keys($head);
+    return self::out_human($o,$head);
   }
 
-  $line = out::row_csv($o,$row);
-  $line = str_replace('\n',' ',$line);
+  public static function out_human(&$o,&$row) {
 
-  # Search max length string
-  $i = 0;
-  foreach (explode($o['sep'],$line) as $v) {
-    $len = mb_strlen($v,out::$charset);
+    # Init options
+    if (empty($o['_human'])) $o['_human'] = [];
+    if (!isset($o['_human']['len'])) {
+      $o['_human']['len'] = [];
 
-    if (0
-      or empty($o['_human']['len'][$i])
-      or $len > $o['_human']['len'][$i]
-    ) $o['_human']['len'][$i] = $len;
+      $o['_human']['sep'] = $o['sep'];
+      $o['sep'] = "\t";
 
-    $i++;
-  }
+      $o['_human']['eol'] = $o['eol'];
+      $o['eol'] = "";
 
-  if (!isset($o['tmpfile'])) {
-    echo "\n";
-    out::bye("Option tmpfile is missing, wrong uage of this funtion!");
-  }
+      $o['tmpfile'] = tmpfile();
 
-  fwrite($o['tmpfile'],$line."\n");
+      # no csv echo call
+      $o['return'] = true;
+      $o['_human']['len'] = [];
+    }
 
-}
+    $line = self::row_csv($o,$row);
+    $line = str_replace('\n',' ',$line);
 
-function out_human_end(&$o) {
-  $len = $o['_human']['len'];
-  fseek($o['tmpfile'], 0);
+    # Search max length string
+    $i = 0;
+    foreach (explode($o['sep'],$line) as $v) {
+      $len = mb_strlen($v,self::$charset);
+
+      if (0
+        or empty($o['_human']['len'][$i])
+        or $len > $o['_human']['len'][$i]
+      ) $o['_human']['len'][$i] = $len;
 
-  $sep_line = '';
-  if (out::p('sep_line') !== '0') {
+      $i++;
+    }
 
-    foreach ($len as $i) {
-      $sep_line .= $o['corner'].str_repeat($o['line'],$i+strlen($o['_human']['sep'])-1);
+    if (!isset($o['tmpfile'])) {
+      echo "\n";
+      self::bye("Option tmpfile is missing, wrong uage of this funtion!");
     }
-    $sep_line .= $o['corner'].$o['_human']['eol'];
+
+    fwrite($o['tmpfile'],$line."\n");
+
   }
 
-  $header = empty($o['_human']['head']) ? 0 : 1;
-  $count = 0;
-  while (($line = fgets($o['tmpfile'])) !== false) {
+  public static function out_human_end(&$o) {
+    $len = $o['_human']['len'];
+    fseek($o['tmpfile'], 0);
 
-    $values = [];
-    $i = 0;
-    foreach (explode($o['sep'],rtrim($line,"\n")) as $v) {
-      $values[] = out::mb_str_pad($v, $len[$i], ' ', STR_PAD_RIGHT);
-      $i++;
+    $sep_line = '';
+    if (self::p('sep_line') !== '0') {
+
+      foreach ($len as $i) {
+        $sep_line .= $o['corner'].str_repeat($o['line'],$i+strlen($o['_human']['sep'])-1);
+      }
+      $sep_line .= $o['corner'].$o['_human']['eol'];
     }
 
-    # header
-    if (!$count) echo $sep_line;
+    $header = empty($o['_human']['head']) ? 0 : 1;
+    $count = 0;
+    while (($line = fgets($o['tmpfile'])) !== false) {
 
-    if ($header or $count>0) echo ''
-      . ltrim($o['_human']['sep'])
-      . join($o['_human']['sep'],$values)
-      . rtrim($o['_human']['sep'])
-    .$o['_human']['eol'];
+      $values = [];
+      $i = 0;
+      foreach (explode($o['sep'],rtrim($line,"\n")) as $v) {
+        $values[] = self::mb_str_pad($v, $len[$i], ' ', STR_PAD_RIGHT);
+        $i++;
+      }
 
-    if ($header and !$count) echo $sep_line;
-    $count++;
-  }
+      # header
+      if (!$count) echo $sep_line;
+
+      if ($header or $count>0) echo ''
+        . ltrim($o['_human']['sep'])
+        . join($o['_human']['sep'],$values)
+        . rtrim($o['_human']['sep'])
+      .$o['_human']['eol'];
+
+      if ($header and !$count) echo $sep_line;
+      $count++;
+    }
 
-  fclose($o['tmpfile']);
-  unset($o['_human']);
+    fclose($o['tmpfile']);
+    unset($o['_human']);
 
-  if ($header) $count--;
-  if (!$count) return;
+    if ($header) $count--;
+    if (!$count) return;
 
-  echo $sep_line;
-  if ($header) echo "$count Records\n";
+    echo $sep_line;
+    if ($header) echo "$count Records\n";
 
-}
-# < Functions
+  }
+
+} Out::init() ; # < Class
 /****************************************************************************/
 
 #die("A NB_EOL B \n");
@@ -757,5 +757,5 @@ $data = array(
 */
 #$data = array( array('a'=>'A'), array('b'=>'B'), array('c'=>'C') );
 $field = array();
-$o = out::rows(!empty($argv[2]) ? $argv[2] : 'csv',$data,$field);
+$o = self::rows(!empty($argv[2]) ? $argv[2] : 'csv',$data,$field);
 ?>
index 4db08e7a10469be0e4f6eac25cff124d13a8a822..1fc658d5b7b7c13d1f7cad6ae7dcbe5167a643e6 100644 (file)
@@ -245,13 +245,13 @@ class DbQ extends nb {
 
         $args = $GLOBALS['dbq_args'];
 
-        $r = ['@' => join(' ',[
+        $r = ['Vew' => join(' ',[
           '<a class="button select" href="'.$this->table->base.'vi/'.$args.'">View</a>'
         ]) ] + $r;
 
         if ($this->perm < self::DELETE) return;
         $rm = $this->table->base.'rm/'.$args;
-        $r['-'] = ''
+        $r['Delete'] = ''
           .'<form action="'.$rm.'" method="post">'
           .'<a class="button" href="'.$rm.'" onclick="parentNode.submit();return false;">Delete</a>'
           .$this->form_hidden($r)