return $return;
}
- /**
- * @copyright NB 05.03.16
- * @param [FILES] $files Files to load
- * @return ARRAY the new/existing value of $this->db
- */
- public static function ar_merge($a,$b) {
+ private static function ar_merge($a,$b) {
return array_replace_recursive($a,$b);
+ #return array_merge_recursive($a,$b);
#return array_combine($a,$b);
+
+ /* From doc
+ */
+ foreach ($b as $key => $value ) {
+
+ if (is_array($value)) {
+ if (!isset($a[$key])) {
+ $a[$key] = [];
+ }
+ $a[$key] = self::ar_merge($a[$key], $value);
+
+ } elseif (isset($a[$key]) and is_array($a[$key])) {
+ if (!isset($value)) {
+ $value = [];
+ }
+ $a[$key] = self::ar_merge($a[$key], $value);
+
+ } else {
+ $a[$key] = $value;
+
+ }
+
+ }
+ return $a;
+
$n = $a;
foreach ($b as $k=>$v) {
- if (!empty($n[$k]) and is_array($v)) {
- $v = array_combine($n[$k],$v);
+
+ if (!empty($n[$k])) {
+ $v = array_merge_recursive($n[$k],(array)$v);
}
+
$n[$k] = $v;
}
return $n;
}
+ /**
+ * @copyright NB 05.03.16
+ * @param [FILES] $files Files to load
+ * @return ARRAY the new/existing value of $this->db
+ */
public static function conf_load($files=[],&$first=false) {
if (empty($files)) return [];
#
# First iteration: Import database conf with key _import
#
+# NB 22.01.19 foreach (self::$dbq as $id=>$params) {
+# NB 22.01.19 $params = (array)$params;
+# NB 22.01.19
+# NB 22.01.19 foreach ($params as $k => $v) {
+# NB 22.01.19 if ($k != '_import') continue;
+# NB 22.01.19
+# NB 22.01.19 $import = is_array($v) ? $v : explode(',',$v);
+# NB 22.01.19 #debug(join(', ',$import));
+# NB 22.01.19 foreach ($import as $v) {
+# NB 22.01.19 if ($id == $v) self::bye("Infinite loop: _import $id = $v");
+# NB 22.01.19 if (empty(self::$dbq[$v])) continue;
+# NB 22.01.19
+# NB 22.01.19 foreach (self::$dbq[$v] as $kk => $vv) {
+# NB 22.01.19 if (!isset($params[$kk])) self::$dbq[$id][$kk] = $vv;
+# NB 22.01.19 }
+# NB 22.01.19 }
+# NB 22.01.19
+# NB 22.01.19 unset(self::$dbq[$id][$k]);
+# NB 22.01.19 }
+# NB 22.01.19 }
+
+ # We use ar_merge
foreach (self::$dbq as $id=>$params) {
- $params = (array)$params;
-
- foreach ($params as $k => $v) {
- if ($k != '_import') continue;
+ if (empty(self::$dbq[$id]['_import'])) continue;
- $import = is_array($v) ? $v : explode(',',$v);
- foreach ($import as $v) {
- if ($id == $v) self::bye("Infinite loop: _import $id = $v");
- if (empty(self::$dbq[$v])) continue;
+ $v = self::$dbq[$id]['_import'];
+ $import = is_array($v) ? $v : explode(',',$v);
- foreach (self::$dbq[$v] as $kk => $vv) {
- if (!isset($params[$kk])) self::$dbq[$id][$kk] = $vv;
- }
- }
+ unset(self::$dbq[$id]['_import']);
- unset(self::$dbq[$id][$k]);
+ foreach ($import as $i) {
+ if (!isset(self::$dbq[$i])) continue;
+ self::$dbq[$id] = self::ar_merge(self::$dbq[$id],self::$dbq[$i]);
+ #debug([$id,self::$dbq[$id]['tables']]);
+ #debug([$id,self::$dbq[$i]['tables']]);
}
+
}
+ /*
+ foreach (self::$dbq as $id=>$params) {
+ unset(self::$dbq[$id]['_import']);
+ }
+ */
$default = isset(self::$dbq['_default']) ? self::$dbq['_default'] : [];
if ($insert === null) $insert = self::p('insert');
if (empty($db_type)) $db_type = self::p('db-type');
- # Params ! dirty !
-# NB 10.01.18 $this->pset('orderby',null);
-# NB 10.01.18 $this->pset('extras','0');
-# NB 10.01.18 $this->pset('format','sql');
-
# Filters
$type = self::p('table-type',''); $type = $type ? explode(',',$type) : $type;
$name = self::p('table-name',''); $name = $name ? explode(',',$name) : $name;
$this->table->html_edit($values, $this->table->base . '/' . ($add ? 'insert' : 'update') ,$add);
}
- public function table_rw() {
+ private function table_rw() {
return (int)(1
and ($this->perm >= self::READ)
and !empty($this->table)
+# NB 22.01.19 and ( $this->table->type() == 'sql' or strpos('table view',$this->table->type()) !== false )
and !empty($this->table->type())
- and ( strpos('table view',$this->table->type()) !== false )
+ and ( strpos('table view',$this->table->type()) !== false )
);
}
$this->row_parse_post();
$opt = ($this->is_html
- and $this->table_rw()
+ #and $this->table_rw()
+ and ($this->perm >= self::READ)
and empty($this->_nopage)
) ? [
'row_parse_pre' => function(&$r){
if ($this->perm < self::DELETE) return;
static $delete = 1;
+
+ # NB 22.01.19: Only table, and view ?
+ if ( strpos('table view',$this->table->type()) === false ) $delete = 0;
+
if (empty($delete)) {
$delete = ($this->db->type == 'sqlite' and !is_writeable($this->db->host));
}