From f167ca2a0d6e88cc1445556dcedde0c9fa9934bc Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 17 Jan 2017 00:54:54 +0000 Subject: [PATCH] Bed --- lib/php/db/field.php | 2 +- lib/php/db/table.php | 69 +++++++++++++++++++-- www/dbq/dbq.php | 112 ++++++++++++++++++++++------------- www/dbq/html/default.css | 49 +++++++++++---- www/dbq/html/default.min.css | 2 +- 5 files changed, 175 insertions(+), 59 deletions(-) diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 6ddc1912..a7e5d344 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -12,7 +12,7 @@ $DB_FIELD_TYPES = array( class field extends nb { private $table; public $name; - public $type; + public $type = 'text'; public $null = true; private $textarea_size = 300; public $key = 0; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index e8ca3335..30a4b0a2 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -22,8 +22,9 @@ Class Table extends nb { public $name; public $type; # table, view, sql public $sql; - public $replace = []; # replace by javascript + public $replace = []; # to be process by by javascript (id="db-table-replace") public $extras = []; + public $rows = []; # array inserted into temporary table public $row_parse_pre; # Function to call in rows() public $row_parse_post; # Function to call in rows() public $count; @@ -42,8 +43,7 @@ Class Table extends nb { public $show_url_sort = true; public $show_header = true; public static $params = [ 'db', 'table', 'limit', 'debug', 'action' - # wordpress - , 'page', 'paged' + , 'page', 'paged' # wordpress ]; function __construct($name,$opt=[]) { @@ -111,6 +111,54 @@ Class Table extends nb { } + public function create_temporary_rows() { + // For static rows + if(empty($this->rows)) return null; + + $fields = array_keys($this->rows[0]); + $sql_names = $this->sql_names($fields); + + $this->db()->conn->query("CREATE TEMPORARY TABLE $this->name (" + .join(',',$this->ar_map('"$a text"',$sql_names)) + .')'); + $sql = 'INSERT INTO '. $this->sql_name("$this->name") + . ' (' . join(',',array_values($sql_names)).')' + .' VALUES (' . join(',',$this->ar_map('":$a"',$fields)) . ')' + ; + + #debug($sql); + if (!($query = $this->db()->conn->prepare($sql))) { + $this->err_sql($sql); + return false; + } + + $this->fields = []; + foreach ($fields as $name) { + $this->fields[$name] = new Field([ + 'name' => $name, + 'table' => $this, + ]); + } + $this->_fields = 1; + + foreach ($this->rows as $row) { + foreach ($row as $k=>$v) { + $field = $this->fields($k); + #debug("$v:$k"); + $field->bindParam($query,$v,":$k"); + #$query->bindParam($k, $v, $this->type2pdo('text')); + } + + if (!($execute = $query->execute())) { + $this->err_sql($sql); + return false; + } + + } + + return true; + } + /* * Function create_temporary * @@ -119,7 +167,9 @@ Class Table extends nb { */ public function create_temporary() { if (!empty($this->_create_temporary)) return; - $this->_create_temporary = 1; + $this->_create_temporary = true; + + $this->create_temporary_rows(); // Name, could be a select if (DB_TABLE_QUERY_NAME and stripos($this->name,'SELECT ')===0) { @@ -136,6 +186,7 @@ Class Table extends nb { } else { return false; + } return true; @@ -1463,7 +1514,17 @@ Class Table extends nb { return ''.NB_EOL; } + public function sql_names($value) { + + $new = []; + foreach ($value as $k=>$v) { + $new[$k] = $this->sql_name($v); + } + return $new; + } + public function sql_name($value=null) { + return $this->db()->sql_name($value === null ? $this->name : $value); } diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 93327fa2..e446b19c 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -539,57 +539,58 @@ class DbQ extends nb { } - public function page_phpinfo() { + public function phpinfo_rows() { $txt = $this->page->is('html') ? 0 : 1; - if (1 or $txt) { - $rows = []; - $row = []; - $section = ''; - $p = [ - 'section' => $this->p('section',''), - 'name' => $this->p('name',''), - 'value' => $this->p('value',''), - ]; - - foreach (explode("\n",$this->page->phpinfo()) as $line) { - if (preg_match(',]*>(.*?),',$line,$m)) { - $section = strtoupper(strip_tags(preg_replace('/\W+/','_',$m[1]))); + if (0 and !$this->page->is('html')) { + return $this->page->phpinfo(); + #return $this->page($this->page->phpinfo($txt)); + } - } elseif (preg_match_all(',(.*?),',$line,$m)) { - $name = strip_tags($m[1][0]); - $value = isset($m[1][1]) ? strip_tags($m[1][1]) : ''; + $rows = []; + $row = []; + $section = ''; + $p = [ + 'section' => $this->p('section',''), + 'name' => $this->p('name',''), + 'value' => $this->p('value',''), + ]; - if (preg_match('/^\$_([A-Z_]+)\[["\']([^"\']+)["\']\]/',$name,$m)) { - $_section = $m[1]; - $name = $m[2]; - } else { - $_section = $section; - } + foreach (explode("\n",$this->page->phpinfo()) as $line) { - #debug($m); - if ($p['name'] and !$this->str_match($name,$p['name'])) continue; - if ($p['value'] and !$this->str_match($value,$p['value'])) continue; - if ($p['section'] and !$this->str_match($_section,$p['section'])) continue; + if (preg_match(',]*>(.*?),',$line,$m)) { + $section = strtoupper(strip_tags(preg_replace('/\W+/','_',$m[1]))); - $rows[] = [ - 'section' => $_section, - 'name' => $name, - 'value' => $value, - ]; + } elseif (preg_match_all(',(.*?),',$line,$m)) { + $name = strip_tags($m[1][0]); + $value = isset($m[1][1]) ? strip_tags($m[1][1]) : ''; + if (preg_match('/^\$_([A-Z_]+)\[["\']([^"\']+)["\']\]/',$name,$m)) { + $_section = $m[1]; + $name = $m[2]; } else { - #debug($sec." ".$line); + $_section = $section; } + #debug($m); + if ($p['name'] and !$this->str_match($name,$p['name'])) continue; + if ($p['value'] and !$this->str_match($value,$p['value'])) continue; + if ($p['section'] and !$this->str_match($_section,$p['section'])) continue; + + $rows[] = [ + 'section' => $_section, + 'name' => $name, + 'value' => $value, + ]; + + } else { + #debug($sec." ".$line); } - return $rows; - #return $this->page($rows); } - return $this->page->phpinfo(); - #return $this->page($this->page->phpinfo($txt)); + return $rows; + #return $this->page($rows); } public function run_root() { @@ -635,8 +636,27 @@ class DbQ extends nb { } elseif ($action == 'phpinfo') { #$this->page(['phpinfo'=>$this->page->phpinfo(true)]); #$this->page($this->page->phpinfo()); - $this->page($this,'page_phpinfo'); - #$this->page_phpinfo(); + if (0) { + $this->params['table'] = 'phpinfo'; + /* + $this->params['db'] = 'mem'; + $this->db = new Db([ + 'name' => 'mem', + 'name' => 'id', + 'type' => 'sqlite', + 'host' => ':memory:', + ]); + */ + $this->params['db'] = 'sys'; + $this->db->table($this->params['table'],[ + 'rows' => $this->phpinfo_rows(), + 'type' => 'table', + ]); + return true; + #$this->page($this,'table_rows'); + } + $this->page($this,'phpinfo_rows'); + #$this->phpinfo_rows(); } elseif (0 or $action == '_SERVER' @@ -696,10 +716,22 @@ class DbQ extends nb { $action = $this->params['action']; if (!$action and self::PARAM_DB_DEFAULT) $action = self::PARAM_DB_DEFAULT; + if (0) { + $this->table->name = 'zaza'; + $this->table->rows = [ + [ + 'name' => 'Name 1', + ], + [ + 'name' => 'Name 2', + ], + ]; + } + #bye([$this->params,$action]); if ($action == 'help') { $this->page($this->table,[ - [ 'help', 'This help' ], + [ 'help', 'Table help' ], [ 'ls', 'List records' ], [ 'fields', 'List fields' ], [ 'status', 'Status page' ], diff --git a/www/dbq/html/default.css b/www/dbq/html/default.css index badf3191..6496cea2 100644 --- a/www/dbq/html/default.css +++ b/www/dbq/html/default.css @@ -37,6 +37,11 @@ a, a:visited { text-decoration: none; } +a:hover, +.button:hover { + opacity: 0.8; +} + ul { padding: 0; margin: 0; @@ -64,8 +69,9 @@ input[type='email'], input[type='url'], input[type=''] { border-radius: 3px; - border: solid 1px #ddd; + border: solid 1px #DDDDDD; padding: 0.3em 0.4em; + box-shadow: 0px 1px 1px #EEEEEE; } input[size] { @@ -97,6 +103,7 @@ object, iframe, pre margin-bottom: 0.5em; border: solid 1px #DDDDDD; background-color: #FAFAFA; + box-shadow: 0px 1px 2px #EEEEEE; } @@ -109,6 +116,7 @@ table.rows { table-layout: fixed; /* display: inline-block; + width: 100%; */ } @@ -161,12 +169,6 @@ ul.row li label, div.row div label { display: inline-block; } -.menu, .nav, .rows, .buttons, td.button, .center { - margin-left: auto; - margin-right: auto; - display: table; -} - .button { font: inherit; display: inline-block; @@ -179,16 +181,32 @@ ul.row li label, div.row div label { margin: 0; padding: 0 0.1em; cursor: pointer; - color: #EEEEEE; - background-color: #444444; - background-color: #CE7F00; padding: 0.1em 0.3em; border: none; + + /* + color: #EEEEEE; + background-color: #444444; + + border: solid 1px #ccc; + box-shadow: 1px 1px 1px #888888; + border-top: solid 1px #EEEEEE; + border: solid 1px #EEEEEE; + */ + color: #E59B24; + background-color: #EEEEEE; + background: linear-gradient(to bottom right, #EEEEEE, #DDDDDD); + + margin-right: 0.1em; + box-shadow: 0px 1px 1px #BBBBBB; + + font-weight: bold; } -a:hover, -.button:hover { - opacity: 0.8; +.menu, .nav, .rows, .buttons, td.button, .center { + margin-left: auto; + margin-right: auto; + display: table; } form.menu { @@ -198,7 +216,12 @@ form.menu { form.menu .button.add { float: right; + margin-top: 0.3ex; + /* margin-top: 0.1em; + margin-top: 2px; + */ + display: inline; } form.menu .criterias { diff --git a/www/dbq/html/default.min.css b/www/dbq/html/default.min.css index 514c8a7e..b34cefc6 100644 --- a/www/dbq/html/default.min.css +++ b/www/dbq/html/default.min.css @@ -1 +1 @@ -html{font:90% 'Trebuchet MS',sans-serif;background-color:#EEE}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}h1{margin:0 0 0.2em 0;font-size:180%;padding-bottom:0.3em;margin-bottom:0.5em;border-bottom:dashed 1px #444}a{color:inherit}p a,div > a,li a,td a{color:#E59B24}a,a:visited{text-decoration:none}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 0.3em}table{border-collapse:collapse}td,th{padding:0.2em 0.7em}th a.sort{padding:0 0.3em}textarea,select,input:not([type]),input[type='text'],input[type='password'],input[type='date'],input[type='email'],input[type='url'],input[type='']{border-radius:3px;border:solid 1px #ddd;padding:0.3em 0.4em}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form label,form input,form select{vertical-align:middle;margin:0.2em 0.4em 0.2em 0}table.rows,div.row,ul.row,form.edit,.menu,.block,object,iframe,pre{border-radius:4px;border-spacing:0;padding:0.5em 0.2em;margin-bottom:0.5em;border:solid 1px #DDD;background-color:#FAFAFA}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #DDD;table-layout:fixed;width:99%}table.rows tr:nth-child(even) td{background-color:#FEFEFE}ul.row li,div.row div,table.rows th,table.rows td{border-bottom:solid 1px #DDD}ul.row li,div.row div,table.rows tr:last-child td{border-bottom:none}table.rows td{padding:0.3em 0.3em;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows tr > *{border-right:solid 1px #FEFEFE;text-align:left}div.row div{margin:0}ul.row li label,div.row div label{padding:0.1em 0.5em 0.1em 0;min-width:20%;display:inline-block}.menu,.nav,.rows,.buttons,.center{margin-left:auto;margin-right:auto;display:table}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.5em;cursor:pointer;border-radius:4px;white-space:nowrap;box-sizing:border-box;margin:0;padding:0 0.1em;cursor:pointer;color:#EEE;background-color:#666;padding:0.1em 0.3em;border:none}a:hover,.button:hover{opacity:0.8}form.menu{padding:0.5em;background-color:#FAFAFA}form.menu .button.add{float:right;margin-top:0.1em}form.menu .criterias{border-top:dashed 1px #DDD;margin-top:0.3em;padding-top:0.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:0.2em 0.1em;margin:0.2em 0.2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left}form.edit .fields input,form.edit .fields textarea,form.edit .fields select{width:65%}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left} \ No newline at end of file +html{font:90% 'Trebuchet MS',sans-serif;background-color:#EEE}body{display:table;margin-left:auto;margin-right:auto;padding-left:1em;padding-right:1em;color:#444}h1{margin:0 0 0.2em 0;font-size:180%;padding-bottom:0.3em;margin-bottom:0.5em;border-bottom:dashed 1px #444}a{color:inherit}p a,div > a,li a,td a{color:#E59B24}a,a:visited{text-decoration:none}ul{padding:0;margin:0}li{list-style:none;padding:0 0 0 0.3em}table{border-collapse:collapse}td,th{padding:0.2em 0.7em}th a.sort{padding:0 0.3em}textarea,select,input:not([type]),input[type='text'],input[type='password'],input[type='date'],input[type='email'],input[type='url'],input[type='']{border-radius:3px;border:solid 1px #ddd;padding:0.3em 0.4em}input[size]{max-width:70%}div.row div label:after,form label:after{content:':'}form label,form input,form select{vertical-align:middle;margin:0.2em 0.4em 0.2em 0}table.rows,div.row,ul.row,form.edit,.menu,.block,object,iframe,pre{border-radius:4px;border-spacing:0;padding:0.5em 0.2em;margin-bottom:0.5em;border:solid 1px #DDD;background-color:#FAFAFA}.rows{padding:0}table.rows{border-style:hidden;border-collapse:collapse;box-shadow:0 0 0 1px #DDD;table-layout:fixed;width:99%}table.rows tr:nth-child(even) td{background-color:#FEFEFE}ul.row li,div.row div,table.rows th,table.rows td{border-bottom:solid 1px #DDD}ul.row li,div.row div,table.rows tr:last-child td{border-bottom:none}table.rows tr > *{border-right:solid 1px #FEFEFE}table.rows td{padding:0.3em 0.3em;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}table.rows th{text-align:left}div.row div{margin:0}ul.row li label,div.row div label{padding:0.1em 0.5em 0.1em 0;min-width:20%;display:inline-block}.menu,.nav,.rows,.buttons,td.button,.center{margin-left:auto;margin-right:auto;display:table}.button{font:inherit;display:inline-block;text-decoration:none;line-height:1.5em;cursor:pointer;border-radius:4px;white-space:nowrap;box-sizing:border-box;margin:0;padding:0 0.1em;cursor:pointer;color:#EEE;background-color:#666;padding:0.1em 0.3em;border:none}a:hover,.button:hover{opacity:0.8}form.menu{padding:0.5em;background-color:#FAFAFA}form.menu .button.add{float:right;margin-top:0.1em}form.menu .criterias{border-top:dashed 1px #DDD;margin-top:0.3em;padding-top:0.3em}form.menu .criterias span.label{border-right:solid 1px #fff;padding:0.2em 0.1em;margin:0.2em 0.2em 0 0;border-radius:3px}form.menu .criterias span.label:last-child{border-right:none}form.menu select:focus{max-width:auto}form.menu select{max-width:20%}form.menu .criterias input[type=text]:focus{width:auto}form.menu .criterias input[type=text]{width:4em}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left}form.edit .fields input,form.edit .fields textarea,form.edit .fields select{width:65%}form.edit .fields label{width:25%;text-align:right;display:inline-block;margin-right:1em;vertical-align:top}form.edit .fields .label span{width:54%;display:inline-block;text-align:left} \ No newline at end of file -- 2.47.3