From 7e5d9c5651d1f53891d6e3b63f09a16d629c8f56 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 8 Aug 2015 14:35:57 +0100 Subject: [PATCH] action --- lib/js/nb.js | 30 ++++++++++++++++++++++++++++++ lib/php/db.php | 35 +++++++++++++++++++++++++++++++++++ lib/php/nb.php | 8 ++++++++ lib/php/page.php | 1 + 4 files changed, 74 insertions(+) diff --git a/lib/js/nb.js b/lib/js/nb.js index f2f07592..48f94bee 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -122,6 +122,36 @@ function NB() { }; + this.json_debug = function(url) { + $.getJSON(url,function(data) { + var tag = ''; + if (typeof(data) == 'string') { + tag = 'span'; + } else if ($.isArray(data)) { + tag = 'ul'; + } else { + tag = 'fieldset'; + } + var items = []; + $.each( data, function( key, val ) { + //console.log(key+' = '+val); + if (tag == 'span') { + tag = 'span class="'+key+'"' + items.push( v ); + } else if (tag == 'ul') { + items.push( '
  • '+val+'
  • ' ); + } else if (tag == 'fieldset') { + items.push( '
    '+key+'
    '+val+'
    ' ); + } + }); + $( '<'+tag+'/>', { + //"class": "my-new-list", + html: items.join( "" ) + }).prependTo( "#msg" ); + //console.log(typeof(data)); + }); + } + }; //NB.prototype.your_method = function() { } diff --git a/lib/php/db.php b/lib/php/db.php index e4f64e06..271481de 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -336,6 +336,41 @@ EOF; return '"'.$value.'"'; } + function action() { + $action = $this->p('action'); + if (strpos($action,'db.') !== 0) return false; + $action = substr($action,3); + + $data = null; + + if ($action == 'tables') { + $data = $this->tables(); + + } elseif ($action == 'html_menu') { + echo $this->html_menu(); + return true; + + } elseif ($action == 'fields') { + $data = $this->table($this->p('table'))->fields(); + + } elseif ($action == 'table' and $this->p('format') and $this->p('table')) { + + $this->print_header($this->p('format')); + $this->table($this->p('table'))->rows(array( 'format' => $this->p('format'),)); + return true; + } + #bye( $action ); + if (isset($data)) { + + $this->print_header('json'); + echo json_encode($data); + return true; + } + + $this->bye("Db.action: Unknow action \"$action\""); + return false; + } + } ?> diff --git a/lib/php/nb.php b/lib/php/nb.php index a7ef8380..bb7389c5 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -28,5 +28,13 @@ class nb { return ($_REQUEST[$name] = $value); } + /* + * Function: bye + * Set a value for param, delete it if null + */ + static function bye($msg='') { + return bye($msg); + } + } ?> diff --git a/lib/php/page.php b/lib/php/page.php index 284a26c5..7665e05c 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -315,6 +315,7 @@ class Page extends nb { } function path() { + if (empty($_SERVER['REQUEST_URI'])) return ''; return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']); } -- 2.47.3