]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/table.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 26 Feb 2018 20:50:44 +0000 (20:50 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 26 Feb 2018 20:50:44 +0000 (20:50 +0000)
etc/dbq/ldap.php
lib/php/db/field.php
lib/php/db/table.php
lib/php/db/types/ldap.php
lib/php/mime.php

index 503d50cff89559c50117742f794968bf7525caad..926ac6494f2b160a6070899dc0b2c15a39c2827e 100644 (file)
@@ -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',
 ];
index 6950ad3239a32879d691e01aa5c57295726eb235..f72f456e682bd75310884fd4a43f374457c4e465 100644 (file)
@@ -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 .= '<div class="label '.$this->name.'">'
-                               .'<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
-                       ;
+
+                       $h = '';
+                       $class = [ 'label', $this->name ];
+                       $mime = Mime::getContent($value);
+                       if ($mime) $class[] = $mime;
 
        if ($this->extras) {
-       $html .= '<span class="extra '.$this->name.'">'.$this->out($value).'</span>';
+       $h .= '<span class="extra '.$this->name.'">'.$this->out($value).'</span>';
 
        } 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.'</textarea>' : ' 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 .= '<div class="'.join(' ',$class).'">'
+                               .'<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
+                       ;
+                       $html .= $h;
+
+                       # If more than one value, add js code to add more fields
                        if ($multi) $html .= '<a href="#" onclick="var i=this.parentNode;var j=i.cloneNode(true);j.querySelectorAll(\'input, textarea, select\').forEach(function(e) {e.value=\'\';}); i.parentNode.insertBefore(j, i.nextSibling);console.log(i.className); return false;">+</a>';
 
        $html .= '</div>'.NB_EOL;
index fe67ba5752ac39afe80cbe5bc49a17551205a341..d9d9f5190cd9a9f81e71b2441060847eb12d3297 100644 (file)
@@ -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 .= '<table class="rows wp-list-table widefat striped">'.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 .= '<thead>'.NB_EOL;
 
@@ -1583,7 +1585,7 @@ Class Table extends nb {
                        $html .= '<tr class="head">'.NB_EOL;
                        if ($this->buttons() and DB_HTML_EDIT) $html .= '<th class="edit"></th>'.NB_EOL;
                        foreach ($fields as $name => $f) {
-                               $html .= '<th'.$this->__rows_table_attr[$name].'>'.$this->url_sort($name).'</th>'.NB_EOL;
+                               $html .= '<th'.$this->_rows_table_class($f).'>'.$this->url_sort($name).'</th>'.NB_EOL;
                        }
                        if ($this->buttons() and DB_HTML_DELETE) $html .= '<th class="delete"></th>'.NB_EOL;
                        $html .= '</tr>'.NB_EOL;
@@ -1603,10 +1605,11 @@ Class Table extends nb {
                if ($this->buttons() and !empty($buttons[0])) $html .= '<td class="action">'.$buttons[0].'</td>'.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 .= '<td'.$this->__rows_table_attr[$k].'>'.$v.'</td>'.NB_EOL;
+                       $html .= '<td'.$this->_rows_table_class($this->field($k)).'>'.$v.'</td>'.NB_EOL;
                }
 
                if ($this->buttons() and !empty($buttons[1])) $html .= '<td class="action">'.$buttons[1].'</td>'.NB_EOL;
@@ -1617,7 +1620,6 @@ Class Table extends nb {
        }
 
        private function rows_end_table() {
-               unset($this->__rows_table_attr);
                $html = '';
                $html .= '</tbody>'.NB_EOL;
                $html .= '</table>'.NB_EOL;
index c1fd232c45a50dcac3f7817bbff39e827b9662a9..76a9ad3ba8f74e3cd3bb933447274ae2d45db84d 100644 (file)
@@ -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'],
                ]);
index 98d8ab0d40bf5c8ecb606fc38f7282347a37f943..d16f39837b9d4d26c3339d2218d397a5bb169a3f 100644 (file)
@@ -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);