]> git.nbdom.net Git - nb.git/commitdiff
update to new php version
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 7 Oct 2024 10:27:06 +0000 (12:27 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 7 Oct 2024 10:27:06 +0000 (12:27 +0200)
lib/php/db/field.php
lib/php/ldap.php
lib/php/nb.php
www/dbq/dbq.php

index 93d4a10c92eb12ccf760399f95b17416398dc17a..8019eb0fe8bbd2d4b290bf5afbacc08ae48c0fcd 100644 (file)
@@ -32,9 +32,10 @@ class field extends nb {
 
   public function __construct($attr=[]) {
     if (is_scalar($attr)) $attr = ['name'=>$attr];
-    foreach ($attr as $k => $v) { $this->$k = $v; }
-    #if (isset($attr['type'])) debug($attr['type']);
-    #debug($this->name.'='.$this->type.nb::debug_backtrace_msg());
+    # NB 07.10.24 foreach ($attr as $k => $v) { $this->$k = $v; }
+               foreach ($attr as $k => $v) {
+                       if (property_exists($this,$k)) $this->$k = $v;
+               }
   }
 
   public function default2str($default=null) {
index de8e9595158c7e71662bc82385238d92ab69b25b..bfe82b4768bcd403581ac07efa7872b2be8cee7d 100644 (file)
@@ -17,7 +17,10 @@ class Ldap {
   public function base() { return $this->base; }
 
   public function __construct($opt = []) {
-               foreach ($opt as $k => $v) if ((string)$v !== '') $this->$k = $v;
+               # NB 07.10.24 foreach ($opt as $k => $v) if ((string)$v !== '') $this->$k = $v;
+               foreach ($opt as $k => $v) {
+                       if ((string)$v !== '' and property_exists($this,$k)) $this->$k = $v;
+               }
        }
 
   public function __destruct() {
index 175c97cd8305aac131f2ad5e0d0e777b0f5dc8c0..5d28310cd33a7e1483c6fd0854a341f6b2578f27 100644 (file)
@@ -42,9 +42,6 @@ class Nb {
 
        public function __sleep() {
                return(get_class_vars(get_class($this))); # get all
-# NB 09.04.16     return array_keys((array)$this);
-               #debug((array)$this); # publics + private in a weird way !
-               #debug(get_object_vars($this)); # non static
        }
        #public function __wakeup() { }
 
@@ -581,7 +578,6 @@ class Nb {
        }
 
        public static function php_cli() {
-# NB 05.03.16 define('NB_CLI', PHP_SAPI === 'cli');
                static $php_cli;
                if ($php_cli===null or $php_cli==='') $php_cli= (
                        !isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))
index bf717f4f514dcab04862ee00bd28eaed8b11f20b..6f6dd5015f888ca55df34955ca97b2b24bd09507 100644 (file)
@@ -194,9 +194,6 @@ class DbQ extends nb {
        public function ldap($table='',$attrs=[]) {
                $this->deniedUnless($this->perm >= self::ADMIN);
 
-# NB 28.01.18          if (!$table) $table = $this->params['table'];
-# NB 28.01.18          if (!$attrs) $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []);
-
                require_once(NB_ROOT.'/lib/php/ldap.php');
                #debug($GLOBALS['DBQ_LDAP']);
                $dn = join(',',$attrs);
@@ -452,8 +449,10 @@ class DbQ extends nb {
        }
 
        private function vi_extract_fields() {
-               $sep = $this->param_args_sep . $this->param_args_sep;
-               #$sep ='@';
+#debug($_REQUEST);
+               #bye($this->params);
+               # NB 07.10.24 why double ??? $sep = $this->param_args_sep . $this->param_args_sep;
+               $sep = $this->param_args_sep;
 
                $fields = [];
                if (strpos($this->params['args'],$sep) !== false) {
@@ -465,22 +464,28 @@ class DbQ extends nb {
        }
 
        public function vi($add=false) {
-               $all = [];
                $nosql = $this->db->conf_type('nosql');
 
                $fields = $this->vi_extract_fields();
 
+               $all = [];
                $keys = $this->table->fields_keys($all);
                if (!$keys) $keys = $all;
                $keys = array_keys($keys);
 
+               $values = [];
                # NB 26.08.24 $values = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : explode($this->param_args_sep,$this->params['args']);
                if (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] == 'POST') {
                        $values = $_POST;
+               } elseif (!empty($_GET)) {
                } elseif($this->params['args']) {
-                       $values = explode($this->param_args_sep,$this->params['args']);
-               } else {
-                       $values = $_GET;
+                       # NB 07.10.24 $values = explode($this->param_args_sep,$this->params['args']);
+                       $args = explode($this->param_args_sep,$this->params['args']);
+                       # NB 07.10.24: Handle case: /DB/TABLE/vi/VALUE
+                       for ($i=0;$i<count($keys);$i++) {
+                               $k = $keys[$i];
+                               $values[$k] = $args[$i];
+                       }
                }
 
                foreach ($values as $k=>$v) {
@@ -873,7 +878,8 @@ class DbQ extends nb {
        }
 
        public function error($admin_msg='') {
-               header('Content-type: text/plain');
+               $type = $this->is_html ? 'text/html' : 'text/plain';
+               header("Content-type: $type");
                $msg = '500 Internal Server Error';
 
                if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
@@ -1443,10 +1449,9 @@ EOF;
                        $this->page_table_ls($m[1]);
 
                } elseif ($action == 'vi'
-                       # NB 29.08.24 or $action!=""
+                       # NB 29.08.24 or $action!="" # default action will be vi
                ) {
                        if ($action != 'vi') $this->params['args'] = $action;
-               #bye($this->params);
                        $this->deniedUnless($this->perm >= self::READ);
                        $this->page($this,'vi');
 
@@ -1515,6 +1520,7 @@ EOF;
 #die($_SERVER['REQUEST_URI']."\n");
 #die($_SERVER['QUERY_STRING']."\n");
 #phpinfo(); exit;
+#debug($this->params['args']);
 $DBQ = new DbQ([
        'run' => true,
        'base' => (($base = Dbq::client_header('Dbq-Base')) ?  preg_replace(',/+$,','',$base) : ''),