From: Nicolas Boisselier Date: Fri, 2 Dec 2016 10:35:27 +0000 (+0000) Subject: fix bug X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=efdc86d9d6f8313f147387e1154c6c4624b3d9df;p=nb.git fix bug --- diff --git a/bin/dbq b/bin/dbq index d1533afa..72c74ef3 100755 --- a/bin/dbq +++ b/bin/dbq @@ -109,7 +109,7 @@ if ($ENV{$UC_NAME.'_PARAMS'}) { # #-e $ROOT_DIR.'/lib/php/db/index.php' && die 'OK'; my $url = ($ENV{$UC_NAME.'_URL'} ? $ENV{$UC_NAME.'_URL'} : - ( -e $ROOT_DIR.'/lib/php/db/index.php' ? $ROOT_DIR.'/lib/php/db/index.php' : '/opt/rent/www/index.php' ) + ( -e $ROOT_DIR.'/lib/php/db/dbq.php' ? $ROOT_DIR.'/lib/php/db/dbq.php' : '' ) ); if (!$Opt{ssh} and @ARGV and ($ARGV[0] =~ m|^\w+://| or -e $ARGV[0] )) { $url = shift @ARGV; diff --git a/lib/php/db.php b/lib/php/db.php index 9f1f6ae5..cde8f1ce 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -561,16 +561,15 @@ class Db extends nb { public function action($action,$table=null) { #debug(($this->tables)); - $available = self::$action_help; $actions = explode(',',$action); - $this->pdef('format',($this->php_cli() ? 'csv' : '')); +# NB 02.12.16 $this->pdef('format',($this->php_cli() ? 'csv' : '')); $rows = []; $return = false; foreach($actions as $action) { if ($action == 'db.help') { - $this->out($available,['action','description']); + $this->out(self::$action_help,['action','description']); $return = true; } elseif ($action == 'db.exec') { @@ -810,10 +809,11 @@ class Db extends nb { global $Db, $Table; if (isset($Table)) self::bye("Table.init(): GLOBALS['Table'] already exists !"); if (isset($Db)) self::bye("Db.init(): GLOBALS['Db'] already exists !"); + $Db = new self(); $Db->pinit(); - if (empty($Db)) return false; + $db = $Db->conf_search_db($conf); if ($Db->p('localFile')) { foreach ($Db->localFile($db['name']) as $k=>$v) { @@ -823,9 +823,7 @@ class Db extends nb { # Connection $Db->__construct($db); -# NB 21.09.16 if (empty($Db->_no_connect)) { $Db->connect(); -# NB 21.09.16 } /* Table @@ -834,6 +832,7 @@ class Db extends nb { !self::p('table') and !preg_match('/^(table\.\w+|rows|insert|edit|delete|update)$/',self::p('action')) ) { + } else { # Search default_table @@ -1252,6 +1251,17 @@ class Db extends nb { return $row; } + public static function content_type2format($content_type) { + if (empty($content_type)) $content_type = self::client_content_type(); + switch (self::mime2ext($content_type)) { + case "html": + return 'table'; + case "txt": + return 'human'; + default: + return 'csv'; + } + } #public function default_table() { return $this->default_table; } } # < Class diff --git a/lib/php/db/dbq.php b/lib/php/db/dbq.php new file mode 100644 index 00000000..21be5434 --- /dev/null +++ b/lib/php/db/dbq.php @@ -0,0 +1,12 @@ +pdef('format',$Db->content_type2format()); +return $Db->action($Db->p('action'),$Table); +?> diff --git a/lib/php/db/index.php b/lib/php/db/index.php index 9ba43caf..2fb5bf64 100755 --- a/lib/php/db/index.php +++ b/lib/php/db/index.php @@ -8,22 +8,11 @@ */ #require_once(realpath(dirname(__FILE__).'/page.php')); return; require_once(realpath(dirname(__FILE__).'/init.php')); - if(defined('DB_NO_ACTION') and DB_NO_ACTION) return true; -# Happend when include from a function +# Needed when include from a function if (!isset($Db)) global $Db, $Table; -switch ($Db->mime2ext($Db->client_content_type())) { - case "html": - $Db->pdef('format','table'); - break; - case "txt": - $Db->pdef('format','human'); - break; - default: - #bye($type); - $Db->pdef('format','json'); -} +$Db->pdef('format',$Db->content_type2format()); return $Db->action($Db->p('action'),$Table); ?> diff --git a/lib/php/db/page.php b/lib/php/db/page.php index 422d6f0d..c0ac3812 100644 --- a/lib/php/db/page.php +++ b/lib/php/db/page.php @@ -2,6 +2,7 @@ require_once(dirname(__FILE__).'/init.php'); require_once(dirname(__FILE__).'/../page.php'); + $Page = new Page([ 'title' => ($Db->title ? $Db->title : Db::prettyText($Db->name)), 'css' => [ @@ -26,18 +27,7 @@ $Page = new Page([ function($page){ global $Db, $Table; - #$type = $page->mime2ext($page->content_type()); - switch ($page->mime2ext($page->content_type())) { - case "html": - $page->pdef('format','table'); - break; - case "txt": - $page->pdef('format','human'); - break; - default: - #bye($type); - $page->pdef('format','csv'); - } + $Db->pdef('format',$Db->content_type2format($page->content_type())); if (!$page->action()) return $Db->action($Db->p('action'),$Table); }, diff --git a/lib/php/db/table.php b/lib/php/db/table.php index c51e88b7..705d5b95 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1493,7 +1493,9 @@ Class Table extends nb { } public function action($action=null) { - if ($action === null) $action = $this->p('action'); + #if (empty($action)) return; + #if ($action === null) $action = $this->p('action'); + #debug($action); if ($action == 'table.fields') { $rows = array_values($this->object2array($this->fields())); @@ -1525,7 +1527,8 @@ Class Table extends nb { } elseif ($action == 'table.rows') { $this->db()->print_header($this->p('format')); - $this->rows(); return true; + $this->rows(); + return true; } elseif ($action == 'table.info') { return $this->out($this->info()); @@ -1848,7 +1851,10 @@ Class Table extends nb { } public function template($id=null) { - if (empty($id) and !( $id=self::p('table.template.id') ) ) self::bye('Wrong parameter!'); + if (empty($id) + and !( $id=self::p('table.template.id') ) + and !( $id=self::p('idtemplate') ) + ) self::bye('Wrong parameter!'); $id = preg_replace('/[^\w\._-]/','',$id);