From f06197cbfd0437b1168ea8bbe1a6c0ddda6d61fd Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 3 Aug 2015 02:43:12 +0100 Subject: [PATCH] div, bug extras --- lib/css/button.css | 12 +++--- lib/css/db.css | 83 ++++++++++++++++++++++++++++----------- lib/php/db.php | 2 +- lib/php/db/field.php | 30 +++++++++++++-- lib/php/db/table.php | 92 +++++++++++++++++++++----------------------- lib/php/test.php | 22 +++++++++++ 6 files changed, 159 insertions(+), 82 deletions(-) diff --git a/lib/css/button.css b/lib/css/button.css index c873d39b..c19ab182 100644 --- a/lib/css/button.css +++ b/lib/css/button.css @@ -19,14 +19,14 @@ background-color: #f4f4f4; border: solid 1px #ddd; - color: #666; - - background-color: #888; - border: solid 1px #444; - color: #eee; - /* + box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.1); */ + color: #666; +} + +.button:hover { + background-color: #f0f0f0; } form a.button:visited, diff --git a/lib/css/db.css b/lib/css/db.css index 56b447b8..a2312007 100644 --- a/lib/css/db.css +++ b/lib/css/db.css @@ -1,15 +1,10 @@ /* All -.rows { margin: 0 auto; } -border: solid 1px red !important; */ - -#db { +label:after { + content: ": "; } -/* - All -*/ form .button, form input, form select, @@ -20,41 +15,75 @@ form label form label { display: inline-block; - width: 4em; + width: 8em; text-align: right; } -form label:after { - content: ": "; -} - +/* +*/ /* List */ .rows { - margin: 0 auto; + margin: 0.5em auto; + clear: both; +} + +td.name, +td.email, +td.phone { + white-space: nowrap; } -.rows ul { +/* + List Div + +div.rows { text-align: center; } +div.rows .row { text-align: left; } +*/ + +div.rows .row { + vertical-align: top; + /* margin: 0 0 0.5em 0; + */ + margin-bottom: 0.5em; padding: 0.2em; + display: inline-block; + width: 22em; } -.rows ul .edit { float: right; } -.rows tr.nav td { border: none; } +div.rows .nav { + margin: 0.3em; + padding: 0; +} -td.name, -td.email, -td.phone { - white-space: nowrap; +div.rows .row .buttons { + padding-bottom: 0.5em; +} + +div.rows .row label { + width: 25%; + display: inline-block; + margin: 0 0.5em 0.1em 0; + vertical-align: top; } +div.rows .row span { + width: 70%; + display: inline-block; +} +/* +.rows ul .button { float: right; } +.rows .buttons { text-align: center; } +div.rows div.buttons { float: right; } +*/ + /* Menu */ .db.menu { margin: 0 auto; - padding: 0.8em 0.8em 0.8em 0.5em; padding: 0.5em 0.8em; display: table; } @@ -89,17 +118,25 @@ form.db.edit label { margin-bottom: 0.3em; } +form.db.edit span, form.db.edit input { width: 70%; } -form.db.edit .buttons { +/* +form.db.edit +*/ +.buttons { margin: 0.5em auto 0 auto; text-align: center; clear: both; } +.buttons .button { margin-left: 0.5em; } -form.db.edit .buttons input { +/* +*/ +form.db.edit +.buttons input { width: auto; float: none; } diff --git a/lib/php/db.php b/lib/php/db.php index 25dda23d..c3dd045d 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -278,7 +278,7 @@ EOF; 'table','div','csv','xml','json','yaml' ),array( 'html' => 'class="format" name="format"'.$html, - 'selected' => $this->p('table'), + 'selected' => $this->p('format'), 'prettyText' => true, )); diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 4b7cb09e..59a3ce43 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -13,11 +13,14 @@ class field { public $name; public $type = 'text'; public $default = null; - private $autoincrement = false; public $key = false; public $table = null; + public $extra = null; + + private $autoincrement = false; function __construct($attr=array()) { + if (is_scalar($attr)) $attr = array('name'=>$attr); foreach ($attr as $k => $v) { $this->$k = $v; } } @@ -31,8 +34,12 @@ class field { function html_edit($value) { + $value = htmlspecialchars($value); return '' - .'' + .($this->extra + ? "$value" + : '' + ) .PHP_EOL; } @@ -64,7 +71,10 @@ class field { } function size() { - return preg_match('/\((\d+)\)/',$this->type,$m) ? $m[1] : null; + if (! preg_match('/\((\d+)(?:,(\d+)\))?/',$this->type,$m) ) return null; + array_shift($m); + return count($m) == 1 ? $m[0] : $m; +// NB 02.08.15 return preg_match('/\((\d+)\)/',$this->type,$m) ? $m[1] : null; } function where($values) { @@ -76,7 +86,6 @@ class field { or $v=='~' ) return null; -// NB 03.07.15 $number = preg_match('/int|float|number|currency/',$this->type) ? 1 : 0; $number = $this->numeric(); // Equal / Not Equal @@ -131,5 +140,18 @@ class field { // NB 27.07.15 return $sth->bindParam($name, $value, $this->pdo_type($value)); } + function out($value,$html_escape=false) { + + static $sqlite = null; if ($sqlite === null) $sqlite = $this->db()->type == 'sqlite'; + + # Anoying ! + if ($sqlite and preg_match('/^float\((?:\d+,)?(\d+)\)/',$this->type,$m)) { + $value = sprintf('%.'.$m[1].'f',$value); + } + + if ($html_escape and empty($this->extra)) $row[$f] = htmlspecialchars($row[$f]); + return $value; + } + } ?> diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 009cd9ed..1bfae686 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -55,7 +55,7 @@ class table { $this->name = $name; - if (@$opt['extras']) $this->add_extras($opt['extras']); + if (isset($opt['extras'])) $this->add_extras($opt['extras']); return $this->fields(); } @@ -122,17 +122,14 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($rows as $row) { $field = array( - 'name' => null, + 'name' => $row['name'], 'extra' => null, - 'type' => null, + 'type' => strtolower($row['type']), 'default' => null, 'key' => null, 'autoincrement' => null, ); - $field['name'] = $row['name']; - $field['type'] = strtolower($row['type']); - if (isset($row['notnull'])) { $field['null'] = $row['notnull'] == '0' ? 1 : 0; @@ -389,7 +386,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $criteria = array(); foreach ( array_keys($this->fields()) as $k ) { - $v = @$_REQUEST[$k]; + $v = empty($_REQUEST[$k]) ? '' : $_REQUEST[$k]; $criteria[] = '' . '' @@ -522,12 +519,13 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($extras as $k => $v) { - $this->fields[$k] = array( + $v = new Field( ( is_array($v) ? $v : array() ) + array( + 'name' => $k, 'type' => 'text', - 'null' => 0, 'extra' => $v, - ); + )); + $this->fields[$k] = $v; $this->extras[$k] = $v; } @@ -538,24 +536,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. if (!$this->extras) return ''; - $select = array(); - - foreach ($this->extras as $k => $v) { - - $select[] = "$v AS ".($this->db->type == 'pgsql' - ? '"'.str_replace('"','\"',$k).'"' - : $this->db->quote($k) - ); - /* - $select[] = "$v AS ".$this->db->quote($k); - */ - - /* - $k = $this->db->quote($k); - if ($this->db->type == 'pgsqpl') $k = str_replace( - $select[] = "$v AS $k" - */ - + $select = array(); foreach ($this->extras as $k => $v) { + $select[] = $v->extra." AS ".$v->quote($k,true); } return ','.join(',',$select); @@ -616,6 +598,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($this->fields() as $f => $field) { + #echo '
'; var_dump($field); echo '
'; + $row[$f] = $field->out($row[$f]); +// NB 02.08.15 if ($escape and empty($this->extra)) $row[$f] = htmlspecialchars($row[$f]); + + /* if (!$field->extra) { if ($escape) $row[$f] = htmlspecialchars($row[$f]); } @@ -623,20 +610,12 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. if ($this->db->type == 'sqlite' and preg_match('/^float\((?:\d+,)?(\d+)\)/',$field->type,$m)) { $row[$f] = sprintf('%.'.$m[1].'f',$row[$f]); } - - if ($count_fields === 0) { - #$row[$f] = '' . $row[$f] . ''; - } + */ $count_fields++; } - if ($opt['is_html']) { - array_unshift($row,''.DB_HTML_EDIT.''); - array_push($row,''.DB_HTML_DELETE.''); - } - echo $this->{"rows_rec_$format"}($row); } @@ -743,7 +722,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. function rows_begin_table() { $html = ''; - $html .= ''.PHP_EOL; + $html .= '
'.PHP_EOL; $colspan = 0; if (DB_HTML_EDIT) $colspan++; @@ -754,9 +733,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. . ''#.''.PHP_EOL ; - $html .= ''#''.PHP_EOL - .'' - ; + $html .= ''; if (DB_HTML_EDIT) $html .= ''; @@ -770,7 +747,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } function rows_rec_table($row) { - $html = ''; + + array_unshift($row,''.DB_HTML_EDIT.''); + array_push($row,''.DB_HTML_DELETE.''); + + $html = ''; foreach ($row as $k => $v) { $html .= ''; @@ -805,27 +786,42 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. Html Div -----------------------------------------------------------------*/ function rows_begin_div() { - return '
'.DB_HTML_NAV_TOP.PHP_EOL; + return '
'.DB_HTML_NAV_TOP.PHP_EOL; } function rows_rec_div($row) { $html = ''; - $html .= '
    '; + + $html .= '
      '; + + $html .= '
    • '; + $html .= ''.DB_HTML_EDIT.''; + $html .= ''.DB_HTML_DELETE.''; + $html .= '
    • '; foreach ($row as $k => $v) { $html .= '
    • ' - .( $k == '0' ? '' : ''.$k.': ') - .''.$v.'' + .( $k == '0' ? '' : '') + .''.$v.'' .'
    • '; } $html .= '
    '.PHP_EOL; + +// NB 03.08.15 $html .= '
    '; +// NB 03.08.15 $html .= ''.DB_HTML_EDIT.''; +// NB 03.08.15 $html .= ''.DB_HTML_DELETE.''; +// NB 03.08.15 $html .= '
    '; + + return $html; } - function rows_end_div() { - return "
".PHP_EOL; + function rows_end_div($opt=array()) { + return '' + . "
".PHP_EOL + ; } function sql_name() { diff --git a/lib/php/test.php b/lib/php/test.php index 2fff54c0..f4397726 100644 --- a/lib/php/test.php +++ b/lib/php/test.php @@ -17,6 +17,28 @@ echo $first; exit; */ +function _static() { + static $v = null; + if ($v === null) $v = preg_match('/zaza/','zaza hello') ? true : false; + return $v; +} benchmark('_static'); + +function _glob() { + if (!isset($GLOBALS['ZAZA'])) $GLOBALS['ZAZA'] = preg_match('/zaza/','zaza hello') ? true : false; + return $GLOBALS['ZAZA']; +} benchmark('_glob'); + +function _defined() { + if (!defined('ZAZA')) define('ZAZA',preg_match('/zaza/','zaza hello') ? true : false); + return ZAZA; +} benchmark('_defined'); + +function direct() { + return preg_match('/zaza/','zaza hello'); +} benchmark('direct'); +benchmark(); +exit; + function _f1() { $_REQUEST['zaza'] === null; } benchmark('_f1'); -- 2.47.3
'.$v.'