From: Nicolas Boisselier Date: Thu, 15 Feb 2018 04:30:39 +0000 (+0000) Subject: lib/php/ldap.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=0d0a1186bed8c15a521b189b54515bba15220642;p=nb.git lib/php/ldap.php --- diff --git a/lib/php/db.php b/lib/php/db.php index 59f3b4d2..2c0d97e7 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -8,19 +8,19 @@ *****************************************************************************/ 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 { @@ -165,7 +165,9 @@ 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 @@ -381,6 +383,11 @@ class Db extends nb { $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); @@ -582,7 +589,8 @@ class Db extends nb { } - $this->out->rows($format,$rows,$head,$conf); + $this->out->type($this->format); + $this->out->rows($rows,$head,$conf); return true; } diff --git a/lib/php/db/field.php b/lib/php/db/field.php index eec74ac4..5772fa78 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -139,13 +139,13 @@ class field extends nb { } # 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.'' : ' type="'.$type.'" value="'.$value.'" />') + .($tag == 'textarea' ? '>'.$value.'' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />') ; } diff --git a/lib/php/ldap.php b/lib/php/ldap.php index 8d59ede1..83c478d3 100644 --- a/lib/php/ldap.php +++ b/lib/php/ldap.php @@ -122,11 +122,31 @@ class Ldap { # 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); } diff --git a/lib/php/nb.php b/lib/php/nb.php index dfc0368f..11ff9306 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -711,7 +711,7 @@ class NB { 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; } diff --git a/lib/php/out.php b/lib/php/out.php index c9933abd..cf0b29f7 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -5,8 +5,8 @@ Class Out extends Nb { public static $charset = 'utf-8'; + protected static $type = 'txt'; protected static $types; - protected static $type; protected static $header = true; public static function init() { @@ -32,7 +32,7 @@ Class Out extends Nb { 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); } @@ -227,14 +227,19 @@ Class Out extends Nb { 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`"); @@ -347,7 +352,7 @@ Class Out extends Nb { $replace_flags = ENT_COMPAT; if ($type === null) $type = self::type(); - if (!$type) { + if (!$type) { # txt return $v; } elseif ($type=='xhtml' or ( @@ -363,8 +368,7 @@ Class Out extends Nb { $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; } diff --git a/lib/php/page.php b/lib/php/page.php index 23e9d789..3361b7a3 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -568,7 +568,7 @@ class Page extends nb { if ($action == 'page.infos') { $out = self::infos(); - out::rows($format,$out); + out::typeRows($format,$out); return true; } elseif ($action == 'page.phpinfo' or $action == 'phpinfo') { diff --git a/www/dbq/html/default.js b/www/dbq/html/default.js index 44dd7a05..5dcad7d4 100644 --- a/www/dbq/html/default.js +++ b/www/dbq/html/default.js @@ -134,12 +134,13 @@ document.addEventListener("DOMContentLoaded", function() { } 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; @@ -150,6 +151,7 @@ document.addEventListener("DOMContentLoaded", function() { s.className = e.className; e.parentNode.replaceChild(s, e); }); + }); });