From d788ec6d1b9b5f66328b9a1e45e18635bb52c6f5 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 9 Dec 2017 04:30:11 +0000 Subject: [PATCH] www/dbq/dbq.php template --- lib/php/db/table.php | 11 +++++------ www/dbq/dbq.php | 36 ++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 72c4f190..e3c0abe9 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -39,7 +39,7 @@ Class Table extends nb { public $fields = []; public $indexes; - public $itemplate_id; + public $idtemplate; # hidden, sort, ... fields public $show_hidden_params = true; @@ -1270,7 +1270,7 @@ Class Table extends nb { Template -----------------------------------------------------------------*/ public function rows_begin_template($fields,&$o) { - $id = $this->template_id(); + $id = $this->idtemplate(); $id = preg_replace('/[^\w\._-]/','',$id); @@ -2193,17 +2193,16 @@ Class Table extends nb { return $this->status; } - private function template_id($id=null) { + private function idtemplate($id=null) { if (empty($id) - and !( $id=$this->p('table.template.id') ) and !( $id=$this->p('idtemplate') ) - and !( $id = $this->template_id ) + and !( $id = $this->idtemplate ) ) $this->bye('Wrong parameter!'); return $id; } public function template($id=null) { - $id = $this->template_id($id); + $id = $this->idtemplate($id); $id = preg_replace('/[^\w\._-]/','',$id); diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 8755aad1..0bb9320f 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -79,8 +79,6 @@ class DbQ extends nb { public $table; public $db; - protected $idtemplate; - public function __construct($opt=[]) { // // Pre defaults values @@ -339,7 +337,7 @@ class DbQ extends nb { } } - if ($this->params['format'] == $this->format_cli) $this->db->format = $this->params['format'] = 'txt'; + if ($this->params['format'] == $this->format_cli) $this->format('txt'); $this->db->out->header($this->p('header',false)); $this->db->out($row); return; @@ -403,8 +401,25 @@ class DbQ extends nb { } + public function format($set=null) { + if ($set === null) return $this->params['format']; + $this->db->format = $this->params['format'] = $set; + } + public function table($param=[]) { +# NB 08.12.17 if ($this->format() == 'tmpl') { + #bye($param); + if (preg_match("/^(.*)\.(tmpl)$/",$this->params['table'],$m)) { +#bye($this->params['table']); + $this->params['table'] = $m[1]; + $param['idtemplate'] = $this->format(); + $this->format('template'); +# NB 08.12.17 } else { +# NB 08.12.17 $this->error("Template id is missing"); +# NB 08.12.17 } + } + if (!in_array($this->params['table'],array_keys($this->db->tables()))) { # We Allow SELECT only in admin @@ -423,6 +438,11 @@ class DbQ extends nb { $this->table->base = $this->db->base.'/'.$this->table->name; + if (isset($param['idtemplate'])) { + $this->table->base .= '.tmpl.' . $param['idtemplate']; + #bye([$this->table,$this->db->format]); + } + } public function title_nav() { @@ -687,11 +707,6 @@ EOF; // Format first ! if ($this->params['format']) { $format = $this->params['format']; -# NB 08.12.17: TODO -# NB 08.12.17 if (preg_match("/^(.*)\.tmpl/",$format,$m)) { -# NB 08.12.17 $this->idtemplate = $m[1]; -# NB 08.12.17 $format = 'template'; -# NB 08.12.17 } } else if ($content_type = self::client_content_type() and ( $format=Mime::toExt($content_type) )) { #$format = $format; @@ -719,8 +734,9 @@ EOF; // Affect values to objects if ($format == 'html') $format = $this->format_html; - $this->params['format'] = $format; - $this->db->format = $format; + $this->format($format); +# NB 08.12.17 $this->params['format'] = $format; +# NB 08.12.17 $this->db->format = $format; $this->is_html = strpos($content_type,'html') ? true : false; $this->db->is_html = $this->is_html; -- 2.47.3