From b3a9bc804071f78db813f336699924345afcbff9 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 6 Dec 2016 01:05:01 +0000 Subject: [PATCH] Bed --- lib/php/db.php | 10 ++--- lib/php/db/table.php | 84 ++++++++++++++++++++++------------------ lib/php/out.php | 6 +++ lib/php/page.php | 11 +++--- www/dbq/html/default.css | 10 ++--- 5 files changed, 64 insertions(+), 57 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 575ef3d9..528653ad 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -549,7 +549,7 @@ class Db extends nb { return '"'.$value.'"'; } - public function out($rows,$head=[]) { + public function out($rows,$head=[],$conf=[]) { if ($this->format) { $format = $this->format; @@ -577,15 +577,11 @@ class Db extends nb { } - if (!empty($this->out_parser)) { - $fct = $this->out_parser; - $fct($rows); - } - $this->out->rows($format,$rows,$head); + $this->out->rows($format,$rows,$head,$conf); return true; } - public function tables_rows($o) { + public function tables_rows($o=[]) { # Options # Filters $type = empty($o['type']) ? '' : $o['type']; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index f1ff7979..6c756d7c 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -32,14 +32,16 @@ Class Table extends nb { public $created; public static $is_admin = true; + public $fields = []; + public $indexes; + + public $itemplate_id; + # hidden, sort, ... fields public static $params = [ 'db', 'table', 'limit', 'debug', 'action' , 'page', 'paged' # wordpress ]; - public $fields = []; - public $indexes; - function __construct($name,$opt=[]) { if (!is_scalar($name)) { @@ -764,7 +766,7 @@ Class Table extends nb { if ($opt['is_html'] and !$opt['use_out']) { foreach ($row as $k=>$v) { - if (!isset($this->extras[$k])) $row[$k] = out::format($v); + if (!isset($this->extras[$k])) $row[$k] = $this->db()->out->format($v); } } @@ -838,11 +840,11 @@ Class Table extends nb { { $opt['use_out'] = true; - if (!($out_conf = out::types($format))) $this->bye("Unknow format `$format`"); + if (!($out_conf = $this->db()->out->types($format))) $this->bye("Unknow format `$format`"); $out_conf = array_merge($opt,$out_conf); # Function name should be format - out::type($format); self::$params += array_values(out::types()); + $this->db()->out->type($format); self::$params += array_values($this->db()->out->types()); if (empty($out_conf['enclose'])) $out_conf['enclose'] = ['','']; debug('Using out module!',3); @@ -867,7 +869,7 @@ Class Table extends nb { if (!$this->p('inc')) echo $this->form_hidden(); } - if ($opt['is_html']) out::type('html'); + if ($opt['is_html']) $this->db()->out->type('html'); # # Rows @@ -916,7 +918,7 @@ Class Table extends nb { } if ($out_conf) { - out::head($out_conf,array_keys($fields),[$row]); + $this->db()->out->head($out_conf,array_keys($fields),[$row]); } else { echo $this->{"rows_begin_$format"}($fields,$opt); @@ -938,7 +940,7 @@ Class Table extends nb { } if ($out_conf) { - out::row($out_conf,$row); + $this->db()->out->row($out_conf,$row); } else { echo $this->{"rows_rec_$format"}($row,$opt); @@ -993,7 +995,7 @@ Class Table extends nb { } if ($out_conf) { - out::end($out_conf); + $this->db()->out->end($out_conf); } else { echo $this->{"rows_end_$format"}(); @@ -1036,7 +1038,7 @@ Class Table extends nb { Template -----------------------------------------------------------------*/ public function rows_begin_template($fields,&$o) { - $id = self::templateid(); + $id = $this->template_id(); $id = preg_replace('/[^\w\._-]/','',$id); @@ -1494,7 +1496,7 @@ Class Table extends nb { return $info['rowCount']; } - public function out($v,$head=[]) { return $this->db()->out($v,$head); } + public function out($v,$head=[],$conf=[]) { return $this->db()->out($v,$head,$conf); } private function url_referer($default='') { if (self::p('referer')) { @@ -1506,37 +1508,42 @@ Class Table extends nb { } } - public function action($action=null) { - #if (empty($action)) return; - #if ($action === null) $action = $this->p('action'); - #debug($action); + public function fields_rows() { + $rows = array_values($this->object2array($this->fields())); - if ($action == 'table.fields') { - $rows = array_values($this->object2array($this->fields())); + list($sql,$where,$limit,$select_count) = $this->rows_sql(); + foreach ([ + 'maxlen' => 'MAX(LENGTH())', + 'max' => 'MAX()', + ] as $name => $select) { + if ($this->p($name)) { + $sql = ''; - list($sql,$where,$limit,$select_count) = $this->rows_sql(); - foreach ([ - 'maxlen' => 'MAX(LENGTH())', - 'max' => 'MAX()', - ] as $name => $select) { - if ($this->p($name)) { - $sql = ''; - - foreach ($this->fields() as $f) { - $sql .= ($sql == '' ? 'SELECT ' : ', '); - $sql .= str_replace('',$f->sql_name(),$select); - } + foreach ($this->fields() as $f) { + $sql .= ($sql == '' ? 'SELECT ' : ', '); + $sql .= str_replace('',$f->sql_name(),$select); + } - $sql .= ' FROM ' . $this->sql_name() . $where . ($limit ? " LIMIT ".$limit : ''); - $len = $this->db()->query($sql)->fetch(PDO::FETCH_NUM); + $sql .= ' FROM ' . $this->sql_name() . $where . ($limit ? " LIMIT ".$limit : ''); + $len = $this->db()->query($sql)->fetch(PDO::FETCH_NUM); - $i = 0; - foreach ($rows as $k => $v) { $rows[$k][$name] = $len[$i]; $i++; } + $i = 0; + foreach ($rows as $k => $v) { $rows[$k][$name] = $len[$i]; $i++; } - } } + } + + #return $this->out(array_values($this->object2array($this->fields()))); + return $rows; + } - #return $this->out(array_values($this->object2array($this->fields()))); + public function action($action=null) { + #if (empty($action)) return; + #if ($action === null) $action = $this->p('action'); + #debug($action); + + if ($action == 'table.fields') { + $rows = $this->fields_rows(); return $this->out($rows); } elseif ($action == 'table.rows') { @@ -1861,16 +1868,17 @@ Class Table extends nb { return $this->status; } - private static function templateid($id=null) { + private function template_id($id=null) { if (empty($id) and !( $id=self::p('table.template.id') ) and !( $id=self::p('idtemplate') ) + and !( $id = $this->template_id ) ) self::bye('Wrong parameter!'); return $id; } public function template($id=null) { - $id = self::templateid($id); + $id = $this->template_id($id); $id = preg_replace('/[^\w\._-]/','',$id); diff --git a/lib/php/out.php b/lib/php/out.php index d619ebd4..292a0abc 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -222,6 +222,9 @@ Class Out extends Nb { unset($opt[$k]); } +# NB 05.12.16 if (isset($opt['format'])) self::type($opt['format']); +# NB 05.12.16 unset($opt['format']); + if (self::type() and !empty($data)) return self::rows(self::type(),$data,$head); return parent::__construct($opt); } @@ -446,6 +449,9 @@ Class Out extends Nb { foreach ($row as $k => $v) { $v = out::format($v,null,$o); } + if (isset($o['row_parse_post'])) { + $o['row_parse_post']($row); + } } public static function format($v,$type=null,$o=[]) { diff --git a/lib/php/page.php b/lib/php/page.php index 57b6d0dd..0480aa59 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -86,8 +86,9 @@ class Page extends nb { parent::__construct($opt); // Defaults - if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title(); - if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title; +# NB 06.12.16 if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title(); +# NB 06.12.16 if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title; + if ( empty($this->title) ) $this->title = !empty($nav) ? join($this->sep,$nav) : $this->filename2title(); // Call / Print if (!empty($this->call)) $this->call($this->call); @@ -179,9 +180,9 @@ class Page extends nb { * Function: tag * Return html code for a tag */ - public static function h1($content='',$attrs='') { return self::tag('h1',$content,$attrs); } - public static function div($content='',$attrs='') { return self::tag('div',$content,$attrs); } - public static function pp($content='',$attrs='') { return self::tag('p',$content,$attrs); } +# NB 06.12.16 public static function h1($content='',$attrs='') { return self::tag('h1',$content,$attrs); } +# NB 06.12.16 public static function div($content='',$attrs='') { return self::tag('div',$content,$attrs); } +# NB 06.12.16 public static function pp($content='',$attrs='') { return self::tag('p',$content,$attrs); } public static function tag($tag,$content='',$attrs='') { static $is_html = null; if ($is_html === null) $is_html = preg_match('/ml$/',self::content_type()) ? true : false; diff --git a/www/dbq/html/default.css b/www/dbq/html/default.css index fc12023e..4d4b6805 100644 --- a/www/dbq/html/default.css +++ b/www/dbq/html/default.css @@ -8,7 +8,6 @@ body { margin-right: auto; padding-left: 1em; padding-right: 1em; - background-color: #E6E6E6; background-color: #009B9C; } @@ -68,8 +67,8 @@ object, iframe, pre { border-collapse: separate; border-spacing: 0; - border-radius: 4px; - border: solid 1px #fff; + border-radius: 2px; + border: solid 1px #ddd; padding: 0.5em 0.2em; margin-bottom: 0.5em; @@ -77,7 +76,7 @@ object, iframe, pre } table.rows { padding: 0; } -table.rows th, table.rows td { border-bottom: solid 1px #fff; } +table.rows th, table.rows td { border-bottom: solid 1px #ddd; } table.rows tr:last-child td { border-bottom: none; } .menu, .nav, .rows, @@ -98,10 +97,7 @@ table.rows tr:last-child td { border-bottom: none; } background-color: #ddd; border: solid 1px #ddd; border-radius: 4px; - -webkit-border-radius: 4px; white-space: nowrap; - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; box-sizing: border-box; color: #ddd; margin: 0; -- 2.47.3