From: Nicolas Boisselier Date: Mon, 26 Feb 2018 20:50:44 +0000 (+0000) Subject: lib/php/db/table.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=78d1a9bd4d509b3e3823c9a5450a106e57a94d68;p=nb.git lib/php/db/table.php --- diff --git a/etc/dbq/ldap.php b/etc/dbq/ldap.php index 503d50cf..926ac649 100644 --- a/etc/dbq/ldap.php +++ b/etc/dbq/ldap.php @@ -102,6 +102,16 @@ $DBQ['ldap'] = $GLOBALS['DBQ_LDAP'] + [ #'userPKCS12', ], ], + 'posixAccount' => [ + 'type' => 'table', + 'sql' => 'objectClass=posixAccount', + 'fields' => ['!dn', 'cn', 'uid', 'gidNumber', 'homeDirectory','loginShell', 'description', 'userPassword'], + ], + 'posixGroup' => [ + 'type' => 'table', + 'sql' => 'objectClass=posixGroup', + 'fields' => ['!dn', 'cn', 'gidNumber', 'memberUid', 'description', 'userPassword'], + ], ], 'default_table' => 'me', ]; diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 6950ad32..f72f456e 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -83,13 +83,13 @@ class field extends nb { if (strpos($this->type,'date') !== false) return 'date'; } - public function htmlValue($value) { + public function htmlValue($value,&$mime=null) { if (strpos($this->type,'bool') !== false) { return preg_match('/^(1|yes|on|true)/i',$value) ? 'Yes' : 'No'; } - $value = Mime::html($value); + $value = Mime::html($value,$value,$mime); return $value; } @@ -125,26 +125,28 @@ class field extends nb { if ($type === null) $type = $this->html_type(); foreach ((array)$values as $value) { - $html .= '
' - .'' - ; + + $h = ''; + $class = [ 'label', $this->name ]; + $mime = Mime::getContent($value); + if ($mime) $class[] = $mime; if ($this->extras) { - $html .= ''.$this->out($value).''; + $h .= ''.$this->out($value).''; } elseif (strpos($this->type,'bool') !== false) { - $html .= $this->htmlYesNo($value); + $h .= $this->htmlYesNo($value); } else { # NB 09.02.18: needed ? if ($tag == 'textarea' and $type != 'text') $tag = 'input'; - if ($media = Mime::html($value,'')) { + if ($media = Mime::html($value,'',$mime)) { $tag = 'input'; $type = 'hidden'; - $html .= $media; + $h .= $media; } - $html .= '<'.$tag + $h .= '<'.$tag .' name="'.$this->preffix.$this->name . ($multi ? '[]' : '') . '"' .( ($size and $tag != 'textarea') ? ' size="'.$size.'"' : '') .($tag == 'textarea' ? '>'.$value.'' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />') @@ -152,7 +154,12 @@ class field extends nb { } - # If more than one value, add js code to add more values + $html .= '
' + .'' + ; + $html .= $h; + + # If more than one value, add js code to add more fields if ($multi) $html .= '+'; $html .= '
'.NB_EOL; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index fe67ba57..d9d9f519 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -556,7 +556,6 @@ Class Table extends nb { }; } $row = $fct($this,$values,$add); - $table = $this; } // Params @@ -1559,23 +1558,26 @@ Class Table extends nb { /*----------------------------------------------------------------- Html Table -----------------------------------------------------------------*/ + private function _rows_table_class($f,$add_class=[]) { + if (!$f) return ''; + $class = []; + + $class[] = $f->name; + $type = preg_replace('/\W.*$/','',$f->type); + if ($type != 'text') $class[] = $type; + if ($f->key) $class[] = 'key'; + if (isset($this->extras[$f->name])) $class[] = 'extra'; + $class = $class + $add_class; + + return $class ? ' class="'.join(' ',$class).'"' : ''; + } + private function rows_begin_table($fields) { $html = ''; $html .= ''.NB_EOL; - $this->__rows_table_attr = []; - foreach ($fields as $name => $f) { - $this->__rows_table_attr[$name] = '' - . ' class="' . $name - . ($f->key ? ' key' : '') - . (isset($this->extras[$name]) ? ' extra' : '') - . ' ' . preg_replace('/\W.*$/','',$f->type) - .'"' - ; - } - if ($this->show_header) { $html .= ''.NB_EOL; @@ -1583,7 +1585,7 @@ Class Table extends nb { $html .= ''.NB_EOL; if ($this->buttons() and DB_HTML_EDIT) $html .= ''.NB_EOL; foreach ($fields as $name => $f) { - $html .= '__rows_table_attr[$name].'>'.$this->url_sort($name).''.NB_EOL; + $html .= '_rows_table_class($f).'>'.$this->url_sort($name).''.NB_EOL; } if ($this->buttons() and DB_HTML_DELETE) $html .= ''.NB_EOL; $html .= ''.NB_EOL; @@ -1603,10 +1605,11 @@ Class Table extends nb { if ($this->buttons() and !empty($buttons[0])) $html .= ''.NB_EOL; foreach ($row as $k => $v) { + $mime = ''; if ( !empty($this->field($k)) ) { - $v = $this->field($k)->htmlValue($v); + $v = $this->field($k)->htmlValue($v,$mime); } - $html .= '__rows_table_attr[$k].'>'.$v.''.NB_EOL; + $html .= '_rows_table_class($this->field($k)).'>'.$v.''.NB_EOL; } if ($this->buttons() and !empty($buttons[1])) $html .= ''.NB_EOL; @@ -1617,7 +1620,6 @@ Class Table extends nb { } private function rows_end_table() { - unset($this->__rows_table_attr); $html = ''; $html .= ''.NB_EOL; $html .= '
'.$buttons[0].''.$buttons[1].'
'.NB_EOL; diff --git a/lib/php/db/types/ldap.php b/lib/php/db/types/ldap.php index c1fd232c..76a9ad3b 100644 --- a/lib/php/db/types/ldap.php +++ b/lib/php/db/types/ldap.php @@ -52,6 +52,7 @@ $DB_TYPES['ldap'] = [ return $r; }, 'html_edit_row' => function(&$table,&$values,$add) { + bye($add); $table->db()->ldap->prepare([ 'base' => $values['dn'], ]); diff --git a/lib/php/mime.php b/lib/php/mime.php index 98d8ab0d..d16f3983 100644 --- a/lib/php/mime.php +++ b/lib/php/mime.php @@ -729,7 +729,7 @@ class Mime { return $m[1]; } - public static function html(&$str,$default=null) { + public static function html(&$str,$default=null,&$mime=null) { if (!$str) return $str; @@ -740,7 +740,7 @@ class Mime { return $str; } - $mime = self::getContent($str); + if ($mime === null) $mime = self::getContent($str); if (preg_match('@^image/@',$mime)) { $v = self::is_base64($str) ? $v : base64_encode($str);