]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 3 Sep 2016 02:42:03 +0000 (03:42 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 3 Sep 2016 02:42:03 +0000 (03:42 +0100)
etc/dbs.php
etc/dbs/nb.php
etc/dbs/owncloud.php
etc/dbs/rent.php [deleted file]
lib/php/db.php
lib/php/db/table.php
lib/php/db/types/sqlite.php
lib/php/functions.php
lib/php/nb.php
lib/php/out.php

index 11a7c7e72397df94b770253c3e9ce2ccaf0249a9..7fc09237ad9d52971976f7cd01cadd8c8975f8d2 100644 (file)
@@ -22,6 +22,12 @@ if ($DIR_SQLITE) $DIR_SQLITE .= '/var/lib/sqlite';
 
 # Includes
 $dir = dirname(__FILE__).'/dbs';
+#debug(nb::ls_dir($dir,'\.php$'));
+foreach (nb::ls_dir($dir,'\.php$') as $file) {
+  require_once("$dir/$file");
+  #if (file_exists("$dir/$file.php")) echo("$dir/$file.php\n");
+}
+return;
 foreach (array(
   'postfix',
   'nb',
@@ -31,6 +37,7 @@ foreach (array(
   'wp',
 ) as $file) {
   if (file_exists("$dir/$file.php")) require_once("$dir/$file.php");
+  #if (file_exists("$dir/$file.php")) echo("$dir/$file.php\n");
 }
 
 ?>
index e3a442d9d5d668a23050338e6053b43a02a5a23c..50bdbad501b45a7ac8d6576ba90e59fba99396fc 100644 (file)
@@ -6,17 +6,129 @@ $CONF['nb'] = array(
   'name' => 'nb',
   #'order' => ($LOCAL_DB ? null : 1),
   'order' => 1,
-  '_import' => array('_rent','_nico'),
+  '_import' => array('_nb','_nico'),
 );
 
 $CONF['nb-sqlite'] = array (
   'host' => "$DIR_SQLITE/nb.db",
   'type' => 'sqlite',
-  '_import' => '_rent',
+  '_import' => '_nb',
 );
 
 if ($LOCAL_DB and !empty($CONF['nb-sqlite'])) {
   $CONF['nb-sqlite']['order'] = isset($CONF['nb']['order']) ? $CONF['nb']['order'] : 1;
   unset($CONF['nb']['order']);
 }
+/*****************************************************************************
+*****************************************************************************/
+#die(print_r(posix_getpwnam('nico'),true));
+#die(print_r(posix_getpwuid(posix_getuid()),true));
+#die(print_r(pathinfo('~/.gitconfig'),true));
+#die(file_exists(realpath('~/.gitconfig')) ? 'yes' : 'no');
+$CONF['_nb'] = array(
+  'title' => 'Nb',
+  'notice' => 'Micro foncier 4BE',
+  'default_table' => 'rent',
+
+  'tables' => array(
+
+    'agency' => [ 'row_parse_post' => function(&$r) { return rent_doc('agency',$r); }, ],
+
+    'place' => array(
+      #'replace' => [ 'id' => 'addr.addr' ],
+      'row_parse_post' => 'place_doc',
+    ),
+
+    'tenant' => array(
+      'row_parse_post' => 'tenant_doc',
+    ),
+
+    'test' => array(
+      'sql' => "SELECT 'Test sql table'",
+    ),
+
+    'rent' => array(
+      'orderby' => 'start desc, end desc',
+      #'replace' => [ 'idtenant' => 'tenant.name', 'idplace' => 'addr.addr' ],
+
+      'row_parse_pre' => function(&$r) {
+        $r['month'] = $r['rent'] + $r['charge'];
+
+        $start_month = date('m',strtotime($r['start']));
+        $end_month = date('m',strtotime($r['end']));
+        if (date('Y',strtotime($r['end'])) > date('Y',strtotime($r['start']))) $end_month = 12;
+        $r['months'] = (1 + $end_month - $start_month);
+
+        $r['total'] = sprintf('%d',$r['rent'] * $r['months']);
+      },
+
+      'row_parse_post' => ((empty($GLOBALS['Db']) or Db::php_cli()) ? null : function(&$r) {
+        static $templates;
+        if (!isset($templates)) {
+          $templates = $GLOBALS['Db']->rows("SELECT id FROM template",PDO::FETCH_NUM);
+          foreach ($templates as $k=>$t) {
+            $templates[$k] = '<a class="small revision" href="template/?id='.$t[0].'&amp;idplace=:idplace&amp;idtenant=:idtenant&amp;start=:start">'.preg_replace('/\.\w+$/','',$t[0]).'</a>';
+          }
+        }
+
+        tenant_doc($r);
+        $revision = '';
+        foreach ($templates as $t) {
+          $revision .= preg_replace_callback('/:(\w+)/',function($m) use(&$r) {return $r[$m[1]];},$t).' ';
+        }
+        $r['doc'] = preg_replace('@^(?:<div[^>]+>)?(.*?)(?:</div>)?$@','<div class="list">'.trim($revision).'\1</div>',$r['doc']);
+
+      }),
+    ),
+
+  ),
+);
+
+return 1;
+
+function tenant_doc(&$r) { return rent_doc('tenant',$r); }
+function place_doc(&$r) { return rent_doc('place',$r); }
+
+function rent_doc($table,&$r) {
+  if (empty($_SERVER['DOCUMENT_ROOT'])) return;
+
+  #if (!empty($r['end']) and date('Ymd') > $r['end']) return $r['doc'] = isset($r['doc']) ? $r['doc'] : '';
+
+  $url = '';
+  foreach (['id'.$table,'id'] as $k) {
+    if (isset($r[$k])) {
+      $url = '/data/'.$table.'/'.$r[$k];
+      break;
+    }
+  }
+  if (!$url) return;
+
+  if (!isset($r['doc'])) $r['doc'] = '';
+#debug($_SERVER['DOCUMENT_ROOT'].$url);
+  if (
+
+    # Web url
+    (
+      empty($r['doc']) and file_exists( $dir = $_SERVER['DOCUMENT_ROOT'].$url )
+    )
+
+    # Absolute path
+    or (
+      ( $dir = nb::untilde($r['doc']) ) 
+      and file_exists($dir) and is_dir($dir)
+      and ($url='' or 1)
+    )
+
+  ) {
+
+    foreach (ls_dir($dir,true) as $p) {
+      $r['doc'] .= sprintf('<a href="%s" class="small">%s</a> ',"$url/$p",
+        nb::prettyText(preg_replace('@^.*?([^/\.]+).*?$@','\1',$p))
+      );
+    }
+
+  }
+
+  if (!empty($r['doc'])) $r['doc'] = '<div class="list">'.$r['doc'].'</div>';
+}
 ?>
index d36d8f850610c5e62266ce41d29730e66bf418ad..0fdb37f2a48245ca14e030ed77a77ebbdf49d7d0 100644 (file)
@@ -1,7 +1,16 @@
 <?php
 $CONF['owncloud'] = [
-  'host' => '/home/owncloud/data/owncloud.db',
+  'host' => "$DIR_SQLITE/owncloud.db",
   'type' => 'sqlite',
   'default_table' => 'oc_users',
+  'default_table' => 'last_files',
+  'tables' => [
+    'last_files' => [
+      'sql' => "SELECT path,mtime FROM oc_filecache WHERE path NOT LIKE 'files_versions/%' ORDER BY fileid DESC LIMIT 10",
+      'row_parse_pre' => function(&$r) {
+        $r['mtime'] = date ("Y-m-d H:i:s",$r['mtime']);
+      }
+    ],
+  ],
 ];
 ?>
diff --git a/etc/dbs/rent.php b/etc/dbs/rent.php
deleted file mode 100644 (file)
index b3c0964..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-<?php
-#die(print_r(posix_getpwnam('nico'),true));
-#die(print_r(posix_getpwuid(posix_getuid()),true));
-#die(print_r(pathinfo('~/.gitconfig'),true));
-#die(file_exists(realpath('~/.gitconfig')) ? 'yes' : 'no');
-$CONF['_rent'] = array(
-  'title' => 'Rent',
-  'notice' => 'Micro foncier 4BE',
-  'default_table' => 'rent',
-
-  'tables' => array(
-
-    'agency' => [ 'row_parse_post' => function(&$r) { return rent_doc('agency',$r); }, ],
-
-    'place' => array(
-      #'replace' => [ 'id' => 'addr.addr' ],
-      'row_parse_post' => 'place_doc',
-    ),
-
-    'tenant' => array(
-      'row_parse_post' => 'tenant_doc',
-    ),
-
-    'test' => array(
-      'sql' => "SELECT 'Test sql table'",
-    ),
-
-    'rent' => array(
-      'orderby' => 'start desc, end desc',
-      #'replace' => [ 'idtenant' => 'tenant.name', 'idplace' => 'addr.addr' ],
-
-      'row_parse_pre' => function(&$r) {
-        $r['month'] = $r['rent'] + $r['charge'];
-
-        $start_month = date('m',strtotime($r['start']));
-        $end_month = date('m',strtotime($r['end']));
-        if (date('Y',strtotime($r['end'])) > date('Y',strtotime($r['start']))) $end_month = 12;
-        $r['months'] = (1 + $end_month - $start_month);
-
-        $r['total'] = sprintf('%d',$r['rent'] * $r['months']);
-      },
-
-      'row_parse_post' => ((empty($GLOBALS['Db']) or Db::php_cli()) ? null : function(&$r) {
-        static $templates;
-        if (!isset($templates)) {
-          $templates = $GLOBALS['Db']->rows("SELECT id FROM template",PDO::FETCH_NUM);
-          foreach ($templates as $k=>$t) {
-            $templates[$k] = '<a class="small revision" href="template/?id='.$t[0].'&amp;idplace=:idplace&amp;idtenant=:idtenant&amp;start=:start">'.preg_replace('/\.\w+$/','',$t[0]).'</a>';
-          }
-        }
-
-        tenant_doc($r);
-        $revision = '';
-        foreach ($templates as $t) {
-          $revision .= preg_replace_callback('/:(\w+)/',function($m) use(&$r) {return $r[$m[1]];},$t).' ';
-        }
-        $r['doc'] = preg_replace('@^(?:<div[^>]+>)?(.*?)(?:</div>)?$@','<div class="list">'.trim($revision).'\1</div>',$r['doc']);
-
-      }),
-    ),
-
-  ),
-);
-
-return 1;
-
-function tenant_doc(&$r) { return rent_doc('tenant',$r); }
-function place_doc(&$r) { return rent_doc('place',$r); }
-
-function rent_doc($table,&$r) {
-  if (empty($_SERVER['DOCUMENT_ROOT'])) return;
-
-  #if (!empty($r['end']) and date('Ymd') > $r['end']) return $r['doc'] = isset($r['doc']) ? $r['doc'] : '';
-
-  $url = '';
-  foreach (['id'.$table,'id'] as $k) {
-    if (isset($r[$k])) {
-      $url = '/data/'.$table.'/'.$r[$k];
-      break;
-    }
-  }
-  if (!$url) return;
-
-  if (!isset($r['doc'])) $r['doc'] = '';
-#debug($_SERVER['DOCUMENT_ROOT'].$url);
-  if (
-
-    # Web url
-    (
-      empty($r['doc']) and file_exists( $dir = $_SERVER['DOCUMENT_ROOT'].$url )
-    )
-
-    # Absolute path
-    or (
-      ( $dir = nb::untilde($r['doc']) ) 
-      and file_exists($dir) and is_dir($dir)
-      and ($url='' or 1)
-    )
-
-  ) {
-
-    foreach (ls_dir($dir,true) as $p) {
-      $r['doc'] .= sprintf('<a href="%s" class="small">%s</a> ',"$url/$p",
-        nb::prettyText(preg_replace('@^.*?([^/\.]+).*?$@','\1',$p))
-      );
-    }
-
-  }
-
-  if (!empty($r['doc'])) $r['doc'] = '<div class="list">'.$r['doc'].'</div>';
-}
-
-?>
index bfec23962071645cda0e1462cb9e527d5d8dcd3b..e1b9a5e61020394a018aa63c09c821ebd71107b6 100644 (file)
@@ -10,7 +10,7 @@ require_once(realpath(dirname(__FILE__).'/nb.php'));
 require_once(realpath(dirname(__FILE__).'/out.php'));
 require_once(realpath(dirname(__FILE__).'/db/table.php'));
 require_once(realpath(dirname(__FILE__).'/db/field.php'));
-$DB_TYPES = array(); # See db/types/*.php
+$DB_TYPES = []; # See db/types/*.php
 #$arr = ['rent'=>'Rent','nb'=>'Nb'];
 #if (!empty($argv) and $argv[1] == 'zaza') bye($arr);
 
@@ -44,23 +44,17 @@ class Db extends nb {
 
   function __construct($opt = '') {
 
-    # Args
-    if ($opt==='') $opt = array();
-    $opt = is_scalar($opt) ? array('pdo' => $opt) : $opt;
+    # Args defaults
+    if ($opt==='') $opt = [];
+    $opt = is_scalar($opt) ? ['pdo' => $opt] : $opt;
 
-    # Tables - We dont want to affect $this
+    # Tables
     if (isset($opt['tables'])) {
       foreach ($opt['tables'] as $name=>$param) $this->table($name,$param);
       unset($opt['tables']);
     }
 
-    # Statics
-    #$this->type = null;
-    if (isset($opt['Ztype'])) {
-      $this->type = $opt['type'];
-      unset($opt['type']);
-    }
-    # Args
+    # Args into this
     foreach ($opt as $k=>$v) $this->$k = $v;
 
     # id
@@ -151,10 +145,6 @@ class Db extends nb {
     if (!$this->type(null)) $this->bye("Unknow type = `".$this->type."`");
 
     # Connect
-    if ($this->type('use_path') and ($this->host!=':memory:') and !is_readable($this->host)) {
-      $this->bye("Can't read database path `".$this->host."` type=`".$this->type."`",false);
-    }
-
     try {
       $this->conn = new PDO($this->pdo,$this->user,$this->password,$this->options);
       #$this->conn = new PDO($this->pdo,$this->user,$this->password,$this->pdo_error);
@@ -272,10 +262,15 @@ class Db extends nb {
   * @author NB 12.08.16
   * Return a table instance
   */
-  public function table($name,$params=array()) {
-    if (!array_key_exists($name,$this->tables)) $this->tables[$name] = new Table($name,['db'=>$this]+$params);
-    elseif ($params) $this->tables[$name]->__construct($name,$params);
+  public function table($name,$params=[]) {
+    #if (!array_key_exists($name,$this->tables)) {
+    if (empty($this->tables[$name])) {
+      $this->tables[$name] = new Table($name,['db'=>$this]+$params);
+    } elseif ($params) {
+      $this->tables[$name]->__construct($name,$params);
+    }
 
+    #if (empty($this->tables[$name]->type)) debug($this->tables[$name]);
     return $this->tables[$name];
   }
 
@@ -285,9 +280,9 @@ class Db extends nb {
 
     $config[1] = str_replace('<NAME>',($name ? $name : $this->name),$config[1]);
 
-    if (!file_exists($config[0])) return array();
+    if (!file_exists($config[0])) return [];
 
-    $return = array();
+    $return = [];
     foreach (explode("\n",file_get_contents($config[0])) as $line) {
 #bye($line);
       if (!preg_match('/'.($config[1]).'/',$line,$m)) continue;
@@ -314,13 +309,19 @@ class Db extends nb {
     return str_replace(array_keys($replace),array_values($replace),$value);
   }
 
+  public function info($key=null,$die=false,$type=null) {
+    $info = $this->type($key,$die,$type);
+    if (is_callable($info)) return $info($this);
+    return $this->unvar($info);
+  }
+
   public function type($key=null,$die=false,$type=null) {
     global $DB_TYPES;
     if (!$type) $type = $this->type;
     if ($key == 'type') return $type;
 
     # Load php file
-    static $require = array();
+    static $require = [];
     if (empty($require[$type])) {
       if (empty($type)) self::bye('Db::$type is required');
       require_once(dirname(__FILE__).'/db/types/'.$type.'.php');
@@ -367,6 +368,7 @@ class Db extends nb {
       if (is_callable($sql)) $sql = $sql($this);
 
       foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) {
+        #debug($row);
         $name = current($row);
         $this->table($name,$row);
       }
@@ -396,7 +398,7 @@ class Db extends nb {
     return '"'.$value.'"';
   }
 
-  public function out($rows,$head=array()) {
+  public function out($rows,$head=[]) {
     out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
     return true;
   }
@@ -419,7 +421,7 @@ class Db extends nb {
     ];
     $actions = explode(',',$action);
     $this->pdef('format',($this->php_cli() ? 'csv' : ''));
-    $rows = array();
+    $rows = [];
     $return = false;
 
     foreach($actions as $action) {
@@ -476,12 +478,12 @@ class Db extends nb {
   * @param [FILES] $files Files to load
   * @return ARRAY the new/existing value of $this->db
   */
-  public static function conf_dbs($files=array(),&$first=false) {
-    if (empty($files)) return array();
+  public static function conf_dbs($files=[],&$first=false) {
+    if (empty($files)) return [];
 
     # Load all files into a $h if #files is not a hash
 
-    $h = array();
+    $h = [];
       if (is_scalar($files)) $files = array($files);
 
     foreach ($files as $file) {
@@ -755,7 +757,7 @@ class Db extends nb {
 
   public function status() {
 
-    $status = $new = array();
+    $status = $new = [];
 
     $new = []
     #+( empty($this->id) ? [] : ['id' => $this->id])
@@ -768,7 +770,7 @@ class Db extends nb {
       #'conf' => count(array_keys($this->conf)),
       'tables' => count($this->tables()),
     ]
-    +($this->type('use_path') ? array() : array(
+    +($this->type('use_path') ? [] : array(
       'port' => $this->port,
       'user' => $this->user,
     ))
@@ -812,7 +814,7 @@ class Db extends nb {
 
   public function fields($st) {
     # See: http://php.net/manual/en/pdostatement.getcolumnmeta.php
-    $fields = array();
+    $fields = [];
     #debug($st->columnCount());
     #debug($st->getColumnMeta(0));
 
index 03038b0b3b40bc1969675d9edfd2443dc9b86174..32de0541737000c901c6626e88ead6ce9432df25 100644 (file)
@@ -146,7 +146,7 @@ Class Table extends nb {
 
     if ($from_sql) return $sql_replace($this->sql());
 
-    if ($this->type == 'view') {
+    if ($this->type() == 'view') {
       return $sql_replace('CREATE VIEW '.$this->sql_name().' AS SELECT'.preg_replace('/^CREATE\s+.*?\s+AS\s+.*?SELECT/i','',$this->sql()));
     }
 
@@ -164,7 +164,7 @@ Class Table extends nb {
       ;
     };
 
-    $sql = 'CREATE '.strtoupper($this->type).' '.$this->sql_name()
+    $sql = 'CREATE '.strtoupper($this->type()).' '.$this->sql_name()
       .' ('
       .join(",",array_map(function($f) use ($_create) {return $_create($f);},array_values($this->fields())))
       # done at the end for primary keys .')'
@@ -459,7 +459,7 @@ Class Table extends nb {
 
   public function url_sort($name) {
 
-    if ($this->p('buttons')==='0' or !($f=$this->fields($name)) or !empty($f->dyn)) return self::prettyText($name);
+    if (!$this->buttons() or !($f=$this->fields($name)) or !empty($f->dyn)) return self::prettyText($name);
     #debug($f);
 
     # See: http://dev.w3.org/html5/html-author/charref
@@ -720,15 +720,20 @@ Class Table extends nb {
     // Get results
     //
 # NB 28.03.16     $this->sql = $sql;
-    $this->debug(preg_replace('/(,|FROM|WHERE|HAVING|GROUP|ORDER)/i',"\n\\1",$sql),1);
+    $this->debug(preg_replace('/[\r\n]+[ ]*/',' ',$sql),1);
+# NB 03.09.16     $this->debug(preg_replace('/(,|FROM|WHERE|HAVING|GROUP|ORDER)/i',"\n\\1",$sql),1);
     return array($sql,$where,$limit,$select_count);
   }
 
+  public function buttons() {
+    if ($this->type() != 'table') return false;
+    return true;
+  }
+
   public function rows(&$opt=array(),$opt_by_val=null) {
 
     $this->create_temporary();
 
-    if (empty($this->type) or $this->type != 'table') $this->pset('buttons','0');;
     if ($opt_by_val !== null) $opt = $opt_by_val;
 
     $format = $this->p('format');
@@ -772,7 +777,7 @@ Class Table extends nb {
       self::$params += array_values(out::$types);
 
       if (empty($out_conf['enclose'])) $out_conf['enclose'] = array('','');
-      debug('Using out module!',1);
+      debug('Using out module!',3);
 
     }
 
@@ -1100,13 +1105,12 @@ Class Table extends nb {
     if ($this->p('header')!=="0") {
       $html .= '<thead>'.NB_EOL.'<tr class="head">'.NB_EOL;
 
-      if ($this->p('buttons')!=='0' and DB_HTML_EDIT) $html .= '<th class="edit"></th>'.NB_EOL;
+      if ($this->buttons() and DB_HTML_EDIT) $html .= '<th class="edit"></th>'.NB_EOL;
 
       foreach ($fields as $name => $f) {
-        #$html .= '<th class="'.$f.'">'.($this->p('buttons')==='0' ? $f : $this->url_sort($f)).'</th>'.NB_EOL;
         $html .= '<th class="'.$name.($f->key?' key':'').'">'.$this->url_sort($name).'</th>'.NB_EOL;
       }
-      if ($this->p('buttons')!=='0' and DB_HTML_DELETE) $html .= '<th class="delete"></th>'.NB_EOL;
+      if ($this->buttons() and DB_HTML_DELETE) $html .= '<th class="delete"></th>'.NB_EOL;
       $html .= '</tr>'.NB_EOL.'</thead>'.NB_EOL;
     }
 
@@ -1120,14 +1124,14 @@ Class Table extends nb {
 
     $html = '<tr class="row">'.NB_EOL;
 
-    if ($this->p('buttons')!=='0') $html .= '<td class="action">'.$buttons[0].'</td>'.NB_EOL;
+    if ($this->buttons()) $html .= '<td class="action">'.$buttons[0].'</td>'.NB_EOL;
 
     foreach ($row as $k => $v) {
       if (isset($this->extras[$k])) $k .= " extra";
       $html .= '<td class="'.$k.'">'.$v.'</td>'.NB_EOL;
     }
 
-    if ($this->p('buttons')!=='0') $html .= '<td class="action">'.$buttons[1].'</td>'.NB_EOL;
+    if ($this->buttons()) $html .= '<td class="action">'.$buttons[1].'</td>'.NB_EOL;
 
     $html .= '</tr>'.NB_EOL;
 
@@ -1154,7 +1158,7 @@ Class Table extends nb {
 
     $html .= '<ul class="row">'.NB_EOL;
 
-    if ($this->p('buttons')!=='0') {
+    if ($this->buttons()) {
       $html .= '<li class="buttons">'.NB_EOL;
       $html .= join('',$this->html_row_buttons($row));
       $html .= '</li>'.NB_EOL;
@@ -1348,6 +1352,7 @@ Class Table extends nb {
   public function out($v,$head=array()) { return $this->db()->out($v,$head); }
 
   public function infos() {
+    $this->type();
     return
       array(
         "name" => $this->name,
@@ -1659,5 +1664,26 @@ Class Table extends nb {
     return var_export($o,true);
   }
 
+  public function type() {
+    if (isset($this->type)) return $this->type;
+    return $this->type = $this->status('type');
+  }
+
+  public function status($key=null) {
+    if (!isset($this->status)) {
+      $this->status = [];
+
+      $sql = $this->db()->type('tables');
+      if (is_callable($sql)) $sql = $sql($this);
+      #$sql .= ' AND name='.$this->db()->quote($this->name);
+      $sql = "SELECT * FROM ($sql) t WHERE name=".$this->db()->quote($this->name);
+
+      $this->status = $this->db()->conn->query($sql,PDO::FETCH_ASSOC);
+      if (!empty($this->status)) $this->status = $this->status->fetch();
+    }
+    if (!empty($key)) return ( empty($this->status[$key]) ? '' : $this->status[$key] );
+    return $this->status;
+  }
+
 } # < Class
 ?>
index ee32fc60070528ad77292d8b3978866a11988225..cef379a8eb14da67297fa42d3fa6d41ed67b38f4 100644 (file)
@@ -65,8 +65,8 @@ $DB_TYPES['sqlite'] = array (
   ,2),
 ),
 
-#'tables' => "SELECT name,type FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type IN('table','view') AND name NOT LIKE 'sqlite_%'",
-'tables' => function($Db) {
+'tables' => "SELECT name,type FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type IN('table','view') AND name NOT LIKE 'sqlite_%'",
+'_tables' => function($Db) {
   #debug($Db->databases());
   $sql = "SELECT name,type FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type IN('table','view') AND name NOT LIKE 'sqlite_%'";
   $dbs = $Db->databases();
index dfadfb089f23ecfaa11bbbc561e72026fa6764d1..7366c378c1ce397141fea41dc7b5e2adb525033a 100644 (file)
@@ -29,41 +29,6 @@ function file_write($file,$data,$mode='w') {
 
 }
 
-function ls_dir($path,$recurse=false,$exp='') {
-
-  $ls = array();
-  $rep = opendir($path);
-  #die(">>>".$exp);
-
-  while($file = readdir($rep)) {
-
-    if ($file == '.' or $file == '..') continue;
-
-    if (!$exp or preg_match('#\.('.$exp.')$#',$file)) {
-      $ls[] = $file;
-    }
-
-    if ($recurse and is_dir("$path/$file")) {
-#print ">>>$path/$file\n";
-
-      foreach (ls_dir("$path/$file",$recurse,$exp) as $l) {
-#print ">>>$path/$file << $l\n";
-        $ls[] = "$file/$l";
-      }
-
-    }
-
-    #echo "<div>$file</div>\n";
-
-  }
-
-  closedir($rep);
-
-#print ">>>$path: ".print_r($ls,true)."\n";
-  return $ls;
-
-}
-
 function ar_first($ar) { return (is_array($ar) and count($ar)) ? $ar[0] : false; }
 
 function ar_map($return,$array,$as_hash=false) {
index 0c4d8ba365a27808e89c93ced1cb03d0f4dd103e..e242ec6352251c1bc91d4d4736695490dc9a257d 100644 (file)
@@ -676,5 +676,56 @@ class NB {
     return strtolower(php_uname('s'));
     return strtolower(preg_replace('/\s+.*$/','', php_uname()));
   }
+
+  public static function ls_dir($path,$exp='',$recurse=false) {
+
+    $ls = array();
+    $rep = opendir($path);
+    #die(">>>".$exp);
+
+    while($file = readdir($rep)) {
+
+      if ($file == '.' or $file == '..') continue;
+
+      if (!$exp or preg_match('#'.$exp.'#',$file)) {
+        $ls[] = $file;
+        #$ls[] = "$path/$file";
+      }
+
+      if ($recurse and is_dir("$path/$file")) {
+  #print ">>>$path/$file\n";
+
+        foreach (ls_dir("$path/$file",$recurse,$exp) as $l) {
+  #print ">>>$path/$file << $l\n";
+          $ls[] = "$file/$l";
+          #$ls[] = $l;
+        }
+
+      }
+
+      #echo "<div>$file</div>\n";
+
+    }
+
+    closedir($rep);
+
+  #print ">>>$path: ".print_r($ls,true)."\n";
+    return $ls;
+
+  }
+
+  public static function http_user() {
+    if (!empty($_SERVER['REMOTE_USER'])) return $_SERVER['REMOTE_USER']; # empty since jessie
+    if (!empty($_SERVER['PHP_AUTH_USER'])) return $_SERVER['PHP_AUTH_USER'];
+    return '';
+  }
+
+  public static function http_login_header($msg_box='My Realm',$msg_cancel='Please login!') {
+    header('WWW-Authenticate: Basic realm="'.$msg_box.'"');
+    header('HTTP/1.0 401 Unauthorized');
+    echo $msg_cancel;
+    exit;
+  }
+
 } # < Class
 ?>
index 6b5d2edc930187bf16f4e1655f3cac858a258187..d7fb52479bc1bc3ad996dea5d02a095e224b9dec 100644 (file)
@@ -315,7 +315,7 @@ Class Out extends Nb {
 
         $new = array(); $i = 0;
         foreach ($head as $k => $h) {
-          $new[$h] = $row[$i];
+          $new[$h] = isset($row[$i]) ? $row[$i] : null;
           $i++;
         }
         $row = $new;