From: Nicolas Boisselier Date: Thu, 7 Apr 2016 00:40:27 +0000 (+0100) Subject: Bed X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=57445d8a1be15437fa9b16e82b0ae2fa89d75fbf;p=nb.git Bed --- diff --git a/etc/dbs.yaml b/etc/dbs.yaml index eae12cbf..da678f43 100644 --- a/etc/dbs.yaml +++ b/etc/dbs.yaml @@ -97,9 +97,6 @@ _rent: title: 'Rent' notice: 'Micro foncier 4BE' default_table: 'rent' - map: - "SELECT addr FROM addr WHERE id='@id'": ".rows.place td.id, .rows.rent td.idplace" - "SELECT name FROM tenant WHERE id='@id'": ".rows.rent td.idtenant" # NEW- NB 10.01.16 tables: diff --git a/lib/css/db.css b/lib/css/db.css index bea3dbf1..94ca2b2f 100644 --- a/lib/css/db.css +++ b/lib/css/db.css @@ -63,7 +63,7 @@ table.rows tr { vertical-align: top; } vertical-align: top; } -.db div.rows .row span { +.db div.rows label { width: 70%; display: inline-block; white-space: normal; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 698d3ac5..d56fe26d 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -600,7 +600,15 @@ Class Table extends nb { : false ; - if ($opt['is_html'] and !$this->p('action')) echo $this->html_menu(); + if ($opt['is_html'] and !$this->p('action') and !$this->p('inc')) { + echo $this->html_menu(); + + } elseif ($opt['is_html'] and !$this->p('inc')) { + echo $this->form_hidden(); + + } + + if ($opt['is_html']) echo '
'.NB_EOL; # Use the module out when format unknow $out_conf = null; @@ -617,11 +625,18 @@ Class Table extends nb { } + if ($opt['is_html']) out::$type = 'html'; $count = 0; while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) { $count++; + if ($opt['is_html'] and !$out_conf) { + foreach ($row as $k=>$v) { + if (!isset($this->extras[$k])) $row[$k] = out::format($v); + } + } + # # Head # @@ -718,6 +733,10 @@ Class Table extends nb { } # < out + if ($opt['is_html']) { + echo '
'.NB_EOL; + } + $st->closeCursor(); return $count; @@ -946,6 +965,7 @@ Class Table extends nb { } public function rows_end_div($opt=array()) { + return ''.NB_EOL; } public function sql_name($value=null) { @@ -1269,21 +1289,21 @@ Class Table extends nb { )); $r .= ''; - // Dbs + // Dbs - see default.js if you change class if (!empty($this->db()->dbs) and count($this->db()->dbs)>1) { $r .= ''; $r .= ''.html_select_array($this->db()->dbs,array( - 'html' => 'class="dbs" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"', + 'html' => 'class="dbs" id="db" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"', 'selected' => self::p('db'), 'prettyText' => true, )); $r .= ''; } - // Tables + // Tables - see default.js if you change class $r .= ''; $r .= ''.html_select_array(array_keys($this->db()->tables()),array( - 'html' => 'class="tables" name="table" id="table"', + 'html' => 'class="tables" id="table" name="table" id="table"', 'selected' => $this->p('table'), 'prettyText' => true, )); diff --git a/lib/php/nb.php b/lib/php/nb.php index a0580a4c..9dab24fe 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -28,6 +28,12 @@ class NB { #public static function zaza() { return (is_object($this) ? 'TRUE' : 'FALSE'); } public static function test() { return 'TEST'; } + public function __construct($opt = array()) { + foreach ($opt as $k => $v) { + if ( ! array_key_exists($k,$this) ) self::bye("Unknow param $k = `$v`"); + $this->$k = is_array($v) ? $v : trim($v); + } + } public function __sleep() { return array_keys((array)$this); } #public function __wakeup() { } diff --git a/lib/php/out.php b/lib/php/out.php index 076389a4..fd0fc321 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -167,10 +167,21 @@ Class Out extends Nb { } # yaml - if (!self::is_hash($row)) return out_yaml($row,$o); + if (!self::is_hash($row)) { + #bye($row); + } + + if (!self::is_hash($row)) unset($o['head_max_len']); + if (is_array($row) and count($row)>1) $o['head_max_len'] = strlen(count($row)); + #if (!self::is_hash($row)) return out_yaml($row,$o); # text - foreach ($row as $k => $v) { echo sprintf("%-".(!empty($o['head_max_len']) ? $o['head_max_len']+1 : 10)."s: %s\n",$k,self::escape($v)); } + foreach ($row as $k => $v) { + echo sprintf("%" + .(!empty($o['head_max_len']) ? '-'.($o['head_max_len']+1) : '') + ."s: %s\n",$k,self::escape($v) + ); + } #foreach ($row as $k => $v) { echo "$k: ".self::escape($v)."\n"; } return true; @@ -255,19 +266,28 @@ Class Out extends Nb { return; } - public static function escape($v,$type=null) { - static $replace_flags = null; - + public static function format($v) { $is_scalar = is_scalar($v); $v = self::scalar($v); if ($v==='') $is_scalar = true; - if ($replace_flags === null) { + $v = self::escape($v); + + if (!$is_scalar and strpos($type,'html') !== false) $v = '
'.NB_EOL.$v.NB_EOL.'
'; + return $v; + } + + public static function escape($v,$type=null,$charset=null) { + if ($charset === null) $type = self::$charset; + + static $replace_flags = null; + + if ($replace_flags === null and $charset=null and $type=null) { #$replace_flags = ENT_COMPAT | ENT_DISALLOWED; $replace_flags = ENT_COMPAT; - if ($type === null) $type = self::$type; + if (!$type) { return $v; @@ -284,16 +304,14 @@ Class Out extends Nb { $replace_flags = $replace_flags | ENT_HTML5; } else { # text - return str_replace("\n",'|',$v); - return $v; - return preg_replace('/\n/','',$v); +# NB 06.04.16 $v = str_replace("\n",'|',$v); +# NB 06.04.16 $v = preg_replace('/\n/','',$v); } } - $v = htmlspecialchars($v,$replace_flags,strtoupper(self::$charset)); - if (!$is_scalar and strpos($type,'html') !== false) $v = '
'.NB_EOL.$v.NB_EOL.'
'; + $v = htmlspecialchars($v,$replace_flags,strtoupper($charset)); return $v; } @@ -415,5 +433,5 @@ $data = array( ); #$data = array( array('a'=>'A'), array('b'=>'B'), array('c'=>'C') ); $field = array(); -$o = new Out($argv[2] ? $argv[2] : 'yaml',$data,$field); +$o = out::rows($argv[2] ? $argv[2] : 'yaml',$data,$field); ?> diff --git a/lib/php/page.php b/lib/php/page.php index d0c02abb..564d7ab4 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -1,5 +1,6 @@ $v) { @@ -75,11 +76,11 @@ class Page extends nb { /* Funtions */ - function out($v) { + public static function out($v) { echo $v; } - function to_array($v) { + public static function to_array($v) { return (is_array($v) ? $v : array($v)); } @@ -101,11 +102,11 @@ class Page extends nb { return mb_strtoupper(mb_substr($str,0,1)).mb_strtolower(mb_substr($str,1,mb_strlen($str))); } - function js_quote($str) { + public static function js_quote($str) { return "'".str_replace("'","\'",$str)."'"; } - function ansi2html($v) { + public static function ansi2html($v) { $html = array( sprintf('%c[1;',27) => sprintf('%c[0;',27), @@ -134,7 +135,7 @@ class Page extends nb { ); } - function str2txt($v) { + public static function str2txt($v) { static $replace_flags = null; static $charset = null; if ($replace_flags === null) { @@ -214,7 +215,7 @@ class Page extends nb { /* Output */ - function begin() { + public function begin() { $this->headers(); @@ -333,7 +334,7 @@ class Page extends nb { return $doctype; } - function head() { + public function head() { $head = ''; #$head .= ''.NB_EOL; return $head; @@ -346,7 +347,7 @@ class Page extends nb { $head .= ''.NB_EOL; - foreach ($this->to_array($this->css) as $v) { + foreach (self::to_array($this->css) as $v) { $head .= ''.NB_EOL; }