]> git.nbdom.net Git - nb.git/commitdiff
lib/php/ldap.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 15 Feb 2018 04:30:39 +0000 (04:30 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 15 Feb 2018 04:30:39 +0000 (04:30 +0000)
lib/php/db.php
lib/php/db/field.php
lib/php/ldap.php
lib/php/nb.php
lib/php/out.php
lib/php/page.php
www/dbq/html/default.js

index 59f3b4d27340dd39f2fec14dbb2d020e2a8ff6d5..2c0d97e7a5007a890042b334cd8bff8887f15cea 100644 (file)
@@ -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;
        }
 
index eec74ac4046ba6453d05e89810749ddacdb481ab..5772fa78852a8f279c4828f4509a44cf55b61d01 100644 (file)
@@ -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.'</textarea>' : ' type="'.$type.'" value="'.$value.'" />')
+               .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />')
        ;
 
        }
index 8d59ede1c33136ad990057aa28584cb8544a70a7..83c478d34efbaf3a72470567c7eadb600b2b073b 100644 (file)
@@ -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);
        }
 
index dfc0368f74eed4b9f997587ab9eebf61d5f6efaf..11ff93066b31f15295d699ac1ec7baf2d484bda8 100644 (file)
@@ -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;
        }
 
index c9933abdc5477e1405e4fc5c1aa01aa0a3315438..cf0b29f7cc23a01c7c0d61d838797b2af71d559f 100644 (file)
@@ -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;
 
       }
 
index 23e9d789bab53bd762bcdade17ff6815ecff2ba7..3361b7a37a5337079542f006970600dc16493ec5 100644 (file)
@@ -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') {
index 44dd7a052b664ee3191e145daf5bff9368f73f3c..5dcad7d4ec1400cdbbade0af7a30fe4f95ee94af 100644 (file)
@@ -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);
                });
+
        });
 
 });