'title' => 'created by dbs.php',
'_import' => $name
];
+ #if (!empty($CONF[$name])) $CONF[$id] = array_merge_recursive($CONF[$name],$CONF[$id]);
}
}
],
];
-#debug($CONF['postfix']);
foreach ($CONF as $id => $db) {
- #debug($db);
if (0
or empty($db['type'] )
or $db['type']!='sqlite'
#or !is_readable($fname)
or !is_readable($db['host'])
) continue;
- #debug(basename($db['host'],'.db'));
$fname = basename($db['host'],'.db');
$CONF['all']['types']['exec'][] = "ATTACH DATABASE '".$db['host']."' as ".$fname."";
conf_merge($CONF[$id],$CONF['all']);
}
-conf_merge($CONF['_nb'],$CONF['all']);
conf_merge($CONF['nb'],$CONF['all']);
+return 1;
+
function conf_merge(&$c1,&$c2) {
- if (!empty($c1['tables']))
+ if (!empty($c1['tables'])) {
#debug('zaza');
#$c2['tables'] = array_merge($c2['tables'],$c1['tables']);
#$c2['tables']
#$c1['tables']
+ if (empty($c1['tables'])) $c1['tables'] = [];
foreach ($c1['tables'] as $k=>$v) {
+ #debug($k);
$c2['tables'][$k] = $v;
}
- ;
+ }
foreach ([
'default_table',
'host' => 'admin.izideal.vpn',
'type' => 'mysql',
'name' => 'nb',
- #'order' => ($LOCAL_DB ? null : 1),
- #'order' => 1,
- '_import' => ['_nb','_nico'],
-);
-if (strpos(php_uname("n"),'ovh.net')!==false) $CONF['nb']['order'] = 1;
+ '_import' => ['_nico'],
-/*****************************************************************************
-if ($LOCAL_DB and !empty($CONF['nb-sqlite']) and isset($CONF['nb']['order'])) {
- $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',
),
);
+if (strpos(php_uname("n"),'ovh.net')!==false) $CONF['nb']['order'] = 1;
return 1;
function tenant_doc(&$r) { return rent_doc('tenant',$r); }
'type' => 'mysql',
'host' => 'admin.izideal.vpn',
#'default_table' => 'oc_users',
- 'default_table' => 'last_files',
+ 'default_table' => 'oc_last_files',
'tables' => [
- 'view_contact' => [
+ 'oc_contact' => [
#'sql' => "SELECT * FROM oc_contacts_cards_properties",
'sql' => "SELECT c.id"
#.",org.value as org"
,
'row_parse_pre' => 'owncloud_row_parse',
],
- 'last_files' => [
+ 'oc_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']);
# Tables
if (isset($opt['tables'])) {
+ #debug($opt['tables']);
+ #foreach ($opt['tables'] as $name=>$param) debug($name);
foreach ($opt['tables'] as $name=>$param) $this->table($name,$param);
unset($opt['tables']);
}
*/
public function table($name,$params=[]) {
#if (!array_key_exists($name,$this->tables)) {
- if (!$name) bye('empty name');
+ if (!$name) bye('table name is empty');
if (empty($this->tables[$name])) {
$this->tables[$name] = new Table($name,['db'=>$this]+$params);
} elseif ($params) {
#if (!isset($this->tables)) {
$this->_tables = true;
-# NB 09.09.16 $sql = $this->type('tables',true,$this->type);
-# NB 09.09.16 if (is_callable($sql)) $sql = $sql($this);
-# NB 09.09.16 $sql = $this->unvar($sql);
$sql = $this->method('tables');
foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) {
}
public function action($action,$table=null) {
+ #debug(($this->tables));
$available = [
['(db.)?help','This help'],
['(db.)?ls','List databases from conf'],
#if ($count = $this->p('count','')) $this->pset('count',1);
$engine = $this->p('engine','');
+ #var_dump ($this->tables());
foreach ($this->tables() as $t) {
+ #debug($t->name);
if (!empty($name) and !$this->str_match($t->name,$name)) continue;
if (!empty($type) and !$this->str_match($t->type,$type)) continue;
if (!empty($count) and !$this->str_match($t->count,$count)) continue;
$rows[] = $t->status();
}
+ #bye($rows);
+ $rows = self::array_fill_assoc($rows);
usort($rows,function($a,$b) { return strcmp($a['name'],$b['name']); });
$return = $this->out($rows);
public $type; # table, view, sql
public $sql;
# NB 28.03.16 public $fields_keys;
- public $replace = array(); # replace by javascript
- public $extras = array();
+ public $replace = []; # replace by javascript
+ public $extras = [];
public $row_parse_pre; # Function to call in rows()
public $row_parse_post; # Function to call in rows()
public $count;
public static $is_admin = true;
# hidden, sort, ... fields
- public static $params = array( 'db', 'table', 'limit', 'debug', 'action'
+ public static $params = [ 'db', 'table', 'limit', 'debug', 'action'
, 'page', 'paged' # wordpress
- );
+ ];
public $fields;
public $indexes;
- function __construct($name,$opt=array()) {
+ function __construct($name,$opt=[]) {
if (!is_scalar($name)) {
$opt = $name;
public function out($v,$head=array()) { return $this->db()->out($v,$head); }
public function infos() {
+ debug('TODEL');
return ['TODEL'];
# TODEL - NB 07.09.16
$this->type();
}
public function status($key=null) {
+ #if ($this->type!='table' and $this->type=!'view') { }
if (!isset($this->status)) {
- $this->status = [];
+ $this->create_temporary();
- $sql = $this->db()->type('tables');
- if (is_callable($sql)) $sql = $sql($this->db());
- #$sql .= ' AND name='.$this->db()->quote($this->name);
+ $sql = $this->db()->method('tables');
$sql = "SELECT * FROM ($sql) t WHERE name=".$this->db()->quote($this->name);
$sth = $this->db()->conn->query($sql,PDO::FETCH_ASSOC);
if (!empty($sth)) $this->status = $sth->fetch();
+ if (empty($this->status)) $this->status = [];
+ # Add to status array
+ foreach ([
+ 'name',
+ 'type',
+ ] as $k) {
+ if (!empty($this->$k) and empty($this->status[$k])) $this->status[$k] = $this->$k;
+ }
+
+ # Add from status array
foreach ([
'engine',
'created',
if (is_array($this->status[$k])) $this->status[$k] = count($this->status[$k]);
}
+ #debug([$this->name,$this->status,$this->sql()]);
if (!empty($key)) return ( empty($this->status[$key]) ? '' : $this->status[$key] );
return $this->status;
}
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);
+ }
+ foreach($rows as $k=>$v) {
+ foreach ($keys as $key) {
+ if (empty($v[$key])) $rows[$k][$key] = '';
+ }
+ }
+ return $rows;
+ }
} # < Class
?>