*****************************************************************************/
require_once(realpath(dirname(__FILE__).'/nb.php'));
require_once(NB_ROOT.'/lib/php/out.php');
-require_once(NB_ROOT.'/lib/php/db/table.php');
require_once(NB_ROOT.'/lib/php/db/field.php');
require_once(NB_ROOT.'/lib/php/mime.php');
$DB_TYPES = []; # See db/types/*.php
#$arr = ['rent'=>'Rent','nb'=>'Nb'];
#if (!empty($argv) and $argv[1] == 'zaza') bye($arr);
-if (defined('PRODUCTION') and PRODUCTION) {
- define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_SILENT);
-} else {
- define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_EXCEPTION);
- #define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_WARNING);
-}
+define('DB_DEFAUL_ERRMODE',defined('PRODUCTION') and PRODUCTION ? PDO::ERRMODE_SILENT : PDO::ERRMODE_EXCEPTION);
+# NB 15.02.18 if (defined('PRODUCTION') and PRODUCTION) {
+# NB 15.02.18 define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_SILENT);
+# NB 15.02.18 } else {
+# NB 15.02.18 define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_EXCEPTION);
+# NB 15.02.18 #define('DB_DEFAUL_ERRMODE',PDO::ERRMODE_WARNING);
+# NB 15.02.18 }
#const DB::ERRMODE='';
class Db extends nb {
#parent::__construct($opt);
# Out Class
- if (empty($this->out)) $this->out = new Out(['charset'=>$this->charset]);
+ if (empty($this->out)) $this->out = new Out([
+ 'charset' => $this->charset,
+ ]);
# Format
# Set format from client Accept if != html
$params['name'] = $name;
if (empty($this->tables[$name])) {
+
+ static $once = 1;
+ if ($once) require_once(NB_ROOT.'/lib/php/db/table.php');
+ $one = 0;
+
$this->tables[$name] = new Table($name,$params);
} elseif ($params) {
$this->tables[$name]->__construct($name,$params);
}
- $this->out->rows($format,$rows,$head,$conf);
+ $this->out->type($this->format);
+ $this->out->rows($rows,$head,$conf);
return true;
}
}
# NB 09.02.18: needed ?
- #$value = htmlspecialchars($value);
+ #$tag = 'textarea';
$html .= '<'.$tag
.' name="'.$this->preffix.$this->name.$suff.'"'
# NB 06.02.18 .' id="'.$this->name.'"'
.( ($size and $tag != 'textarea') ? ' size="'.$size.'"' : '')
#.' value="'.$value.'"'
- .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.$value.'" />')
+ .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />')
;
}
# NB 29.01.18 return ldap_mod_add($conn, $dn . ',' . $this->base, $data);
}
+ private function update_delete($dn,&$data) {
+ foreach ($data as $k => $v) {
+
+ if (is_array($v)) {
+ $this->update_delete($dn,$data[$k]);
+
+ } elseif ($v === '') {
+ unset($data[$k]);
+ #ldap_mod_del($this->connect(),$dn,[$k=>$v]);
+ if (!ldap_mod_del($this->connect(),$dn,[$k=>[]])) bye(ldap_error($this->connect()));
+ #$this->delete($dn,[$k=>$v]);
+
+ }
+ #if ($data[$k] === null
+ }
+ }
+
public function update($dn,$data) {
# NB 28.01.18 return ldap_mod_add($this->connect(), $dn . ',' . $this->base, $data);
$dn = $this->dnBase($dn);
#debug([$dn,$data]);
#debug(ldap_error($this->connect()));
+ #$this->update_delete($dn,$data);
+ #unset($data['sn']);
+ #bye($data);
return ldap_mod_replace($this->connect(), $dn, $data);
}
if (is_scalar($rows)) {
$rows = array($name => $rows);
}
- out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : []));
+ out::typeRows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : []));
return true;
}
public static $charset = 'utf-8';
+ protected static $type = 'txt';
protected static $types;
- protected static $type;
protected static $header = true;
public static function init() {
unset($opt[$k]);
}
- if (self::type() and !empty($data)) return self::rows(self::type(),$data,$head);
+ if (self::type() and !empty($data)) return self::typeRows(self::type(),$data,$head);
return parent::__construct($opt);
}
public static function rows_get($type,$data,$head=array()) {
ob_start();
- self::rows($type,$data,$head);
+ self::typeRows($type,$data,$head);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
return ob_get_flush();
}
- public static function rows($type,&$data,$head=[],$conf=[]) {
+ public static function typeRows($type,&$data,$head=[],$conf=[]) {
+ return self::rows($type,$data,$head,$conf);
+ }
+
+ public static function rows(&$data,$head=[],$conf=[]) {
+ $type = self::type();
if (is_scalar($data)) $data = [[$data]];
if (!isset(self::$types[$type])) self::bye("Unknown type: `$type`");
$replace_flags = ENT_COMPAT;
if ($type === null) $type = self::type();
- if (!$type) {
+ if (!$type) { # txt
return $v;
} elseif ($type=='xhtml' or (
$replace_flags = $replace_flags | ENT_HTML5;
} else { # txt
-# NB 06.04.16 $v = str_replace("\n",'|',$v);
-# NB 06.04.16 $v = preg_replace('/\n/','',$v);
+ return $v;
}
if ($action == 'page.infos') {
$out = self::infos();
- out::rows($format,$out);
+ out::typeRows($format,$out);
return true;
} elseif ($action == 'page.phpinfo' or $action == 'phpinfo') {
}
if (document.querySelector("body.no-db")) document.querySelectorAll("body > h1 a.db, body > h1 a.table").forEach(function(e) {
+
var base = window._dbq[e.className+'.base'].replace(/\/[^\/]+$/,'');
var url = base + (base == '' ? '/ls' : '') + '.json';
- console.log(url);
var fields = e.className == 'db' ? ['id','id'] : ['name','name'];
+
dbqGet(url,function(o){
- console.log(window._dbq['param.'+e.className]);
+ //console.log(window._dbq['body.no-db param.'+e.className]);
var s = o.select(fields[0],fields[1], window._dbq['param.'+e.className]);
s.onchange = function() {
window.location = base + '/' + this.value + ext;
s.className = e.className;
e.parentNode.replaceChild(s, e);
});
+
});
});