class field extends nb {
private $table;
public $name;
- public $type;
+ public $type = 'text';
public $null = true;
private $textarea_size = 300;
public $key = 0;
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;
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=[]) {
}
+ 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
*
*/
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) {
} else {
return false;
+
}
return true;
return '</div>'.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);
}
}
- 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(',<h2[^>]*>(.*?)</h2>,',$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(',<td>(.*?)</td>,',$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(',<h2[^>]*>(.*?)</h2>,',$line,$m)) {
+ $section = strtoupper(strip_tags(preg_replace('/\W+/','_',$m[1])));
- $rows[] = [
- 'section' => $_section,
- 'name' => $name,
- 'value' => $value,
- ];
+ } elseif (preg_match_all(',<td>(.*?)</td>,',$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() {
} 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'
$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' ],
text-decoration: none;
}
+a:hover,
+.button:hover {
+ opacity: 0.8;
+}
+
ul {
padding: 0;
margin: 0;
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] {
margin-bottom: 0.5em;
border: solid 1px #DDDDDD;
background-color: #FAFAFA;
+ box-shadow: 0px 1px 2px #EEEEEE;
}
table-layout: fixed;
/*
display: inline-block;
+ width: 100%;
*/
}
display: inline-block;
}
-.menu, .nav, .rows, .buttons, td.button, .center {
- margin-left: auto;
- margin-right: auto;
- display: table;
-}
-
.button {
font: inherit;
display: inline-block;
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 {
form.menu .button.add {
float: right;
+ margin-top: 0.3ex;
+ /*
margin-top: 0.1em;
+ margin-top: 2px;
+ */
+ display: inline;
}
form.menu .criterias {
-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