'action' => '',
'args' => '',
];
-# NB 23.12.16 public $params_deep = [];
+ public $params_deep = []; # contain index in case if we decide to use a regexp
# Db
public $limits = [];
public $js = '/default'.(PRODUCTION ? '.min' : '').'.js';
public $ext;
+ # Others
+ public $expode_args = '&';
+
# Object
public $page;
public $table;
//
// Pre defaults values
+ //
+ // Init
+ $this->parse_uri();
+
// Envs -> var
foreach ([
'perm',
if (!empty($_SERVER[$env])) $this->params[$k] = $_SERVER[$env];
}
- //
- // Init
- $this->uri_params();
$run = isset($opt['run']) ? $opt['run'] : false;
unset($opt['run']);
if ($run) $this->run();
}
+ public function json() {
+ $rows = [];
+ foreach ($this->json as $k=>$v) $rows[] = ['name'=>$k,'value'=>$v];
+ return $rows;
+ }
+
public function limit($set=false) {
static $limit=false;
if ($set !== false) return ($limit=$set);
$this->page->headers_no_cache();
$this->page->js = $this->js;
- $this->page->js_code = 'window._dbq = '
- . json_encode([
+ $this->json = [
'db.base' => ( empty($this->db) ? '' : $this->db->base ),
'table.base' => ( empty($this->table) ? '' : $this->table->base ),
'default.format' => $this->format_html,
'param.table' => $this->params['table'],
'param.action' => $this->params['action'],
'param.args' => $this->params['args'],
- ])
- .'';
+ 'param.deep' => $this->params_deep,
+ ];
+ $this->page->js_code = 'window._dbq = '.json_encode($this->json);
list($title,$nav) = $this->title_nav();
$this->page->title = join($this->sep_title,$title);
$this->db->__construct($connect);
$this->id = $this->params['db'];
$this->db->connect();
- $this->db->base = '/'.$this->db->id.'/';
+ $this->db->base = '/'.$this->db->id;
return $this->db;
}
require_once(NB_ROOT.'/lib/php/db/config.php');
}
$this->db = new Db(['conf'=>$DB_CONFS]);
- $this->db->base = '/';
+ $this->db->base = '';
return $this->db;
}
$values = $add ? array_fill(0,count($keys),'') : explode($this->param_args_sep,$this->params['args']);
- $this->table->html_edit(array_combine($keys,$values),$this->table->base.($add ? 'insert/' : 'update/').$this->params['args'],$add);
+ $this->table->html_edit(array_combine($keys,$values),$this->table->base.($add ? 'insert' : 'update').'/'.$this->params['args'],$add);
}
public function table_rows($fct=null) {
$args = $GLOBALS['dbq_args'];
$r = ['Vew' => join(' ',[
- '<a class="button select" href="'.$this->table->base.'vi/'.$args.'">View</a>'
+ '<a class="button select" href="'.$this->table->base.'/vi/'.$args.'">View</a>'
]) ] + $r;
if ($this->perm < self::DELETE) return;
- $rm = $this->table->base.'rm/'.$args;
+ $rm = $this->table->base.'/rm/'.$args;
$r['Delete'] = ''
.'<form action="'.$rm.'" method="post">'
.'<a class="button" href="'.$rm.'" onclick="parentNode.submit();return false;">Delete</a>'
#'params' => [ 'limit' ],
]);
- $this->table->base = $this->db->base.$this->table->name.'/';
+ $this->table->base = $this->db->base.'/'.$this->table->name;
}
$title = array_filter(array_unique(array_slice(array_values($params),1)),
function($v){
return(in_array($v,self::ACTIONS_NO_TITLE) ? '' : $v);
-# NB 07.01.17 return($v==self::PARAM_DB_DEFAULT ? '' : $v);
}
);
return [$title,$nav];
}
- public function uri_params() {
+ public function parse_uri() {
#
# Parse path, respect params order
#
list ($path,$args) = strpos($_SERVER['REQUEST_URI'],'?') ? explode('?',$_SERVER['REQUEST_URI']) : [$_SERVER['REQUEST_URI'],''];
$this->uri = $path;
- $this->uri_params = $args;
+ $this->uri_params = explode($this->expode_args,$args);
if (preg_match('/\.(\w+)$/',$path,$m)) {
$values[] = $m[1];
$i=0;
$count = count($values);
#var_export($values);
+
foreach ($this->params as $p => $default) {
#if ($i>=$count) break;
+
if ($i<$count) {
# Can be overwrite by get request
}
+ $this->params_deep[$p] = $i;
}
+
$i++;
-# NB 23.12.16 $this->params_deep[$p] = $i;
+
}
return $this->params;
exit;
}
- public function status() {
+ public function status() { #$this->perm--;
$rows = [];
+ // Client headers
+ foreach ($this->client_header() as $k=>$v) $rows[] = [
+ 'name' => 'client.header.'.$k,
+ 'value' => ( is_scalar($v) ? $v : json_encode($v) ),
+ ];
+
+ // Server
+ foreach ([
+ 'addr',
+ 'port',
+ 'software',
+ ] as $k) {
+ if ($this->perm < self::ADMIN and $k == 'software') continue;
+
+ $v = 'SERVER_'.strtoupper($k);
+ $v = isset($_SERVER[$v]) ? $_SERVER[$v] : '';
+ if ($v==='') continue;
+
+ $rows[] = [ 'name' => 'server.'.$k, 'value' => $v ];
+ }
+
+ // Admin or bye !
+ if ($this->perm < self::ADMIN) return $rows;
+
+ /*
+ // Headers sent
+ foreach (headers_list() as $v) {
+ list($k,$v) = explode(': ',$v);
+ $rows[] = [
+ 'name' => 'server.header.'.$k,
+ 'value' => ( is_scalar($v) ? $v : json_encode($v) ),
+ ];
+ }
+ */
+
// Dbq
if ($this->client_content_type()) $rows[] = [
'name' => 'dbq.client_content_type',
}
}
- // Client headers
- foreach ([
- 'addr',
- ] as $k) {
- $v = 'REMORE_'.strtoupper($k);
- $v = isset($_SERVER[$v]) ? $_SERVER[$v] : '';
- if ($v==='') continue;
- $rows[] = [ 'name' => 'server.'.$k, 'value' => $v ];
- }
- foreach ($this->client_header() as $k=>$v) $rows[] = [
- 'name' => 'client.header.'.$k,
- 'value' => ( is_scalar($v) ? $v : json_encode($v) ),
- ];
-
- // Envs
- foreach ([
- 'addr',
- 'port',
- 'software',
- ] as $k) {
- $v = 'SERVER_'.strtoupper($k);
- $v = isset($_SERVER[$v]) ? $_SERVER[$v] : '';
- if ($v==='') continue;
- $rows[] = [ 'name' => 'server.'.$k, 'value' => $v ];
- }
-
- // Server headers
- foreach (headers_list() as $v) {
- list($k,$v) = explode(': ',$v);
- $rows[] = [
- 'name' => 'server.header.'.$k,
- 'value' => ( is_scalar($v) ? $v : json_encode($v) ),
- ];
- }
-
return $rows;
}
- public function init() {
+ public function run_init() {
+ $this->db();
// Format first !
if ($this->params['format']) {
[ 'status', 'Status infos page' ],
],['command','description'],function(&$r) {
$r['command'] = $this->page->tag('a',$r['command'],'href="'
- .$this->db->base.($r['command'] == self::PARAM_DB_DEFAULT
+ .$this->db->base.'/'.($r['command'] == self::PARAM_DB_DEFAULT
? ''
: $r['command'].'.'.$this->ext
)
#$this->params += [ 'db' => '', 'table' => '', 'action' => '' ];
#$this->params = array_merge($this->params,[ 'db' => '', 'table' => '', 'action' => '' ]);
$this->page($this->db,'ls',[],function(&$r){
- $r['id'] = $this->page->tag('a',$r['id'],'href="'.$this->db->base.$r['id'].'.'.$this->ext.'"');
+ $r['id'] = $this->page->tag('a',$r['id'],'href="'.$this->db->base.'/'.$r['id'].'.'.$this->ext.'"');
});
} elseif ($action == 'cryptkey') {
} elseif ($this->perm < self::ADMIN) {
// NOW ONLY FOR ADMIN !
+ } elseif ($action == 'json') {
+ $this->page($this,'json');
+
} elseif ($action == 'phpinfo') {
#$this->page(['phpinfo'=>$this->page->phpinfo(true)]);
#$this->page($this->page->phpinfo());
[ 'ls', 'List tables' ],
],['command','description'],function(&$r){
$r['command'] = $this->page->tag('a',$r['command'],'href="'
- .$this->db->base.($r['command'] == self::PARAM_DB_DEFAULT
+ .$this->db->base.'/'.($r['command'] == self::PARAM_DB_DEFAULT
? ''
: $r['command'].'.'.$this->ext
)
} elseif ($action == 'ls') {
$this->page('',$this->db->tables_rows(),[],function(&$r){
- $r['name'] = $this->page->tag('a',$r['name'],'href="'.$this->db->base.$r['name'].'.'.$this->ext.'"');
+ $r['name'] = $this->page->tag('a',$r['name'],'href="'.$this->db->base.'/'.$r['name'].'.'.$this->ext.'"');
});
} elseif ($action == 'status') {
[ 'status', 'Status page' ],
],['command','description'],function(&$r){
$r['command'] = $this->page->tag('a',$r['command'],'href="'
- .$this->table->base.($r['command'] == self::PARAM_DB_DEFAULT
+ .$this->table->base.'/'.($r['command'] == self::PARAM_DB_DEFAULT
? ''
: $r['command'].'.'.$this->ext
)
} elseif ($action == 'insert' and $this->perm >= self::WRITE) {
if (!$this->table->insert($_POST,$info)) $this->error('insert: '.print_r($info,true));
- header('Location: '.$this->table->base);
+ header('Location: '.$this->table->base.'/');
} elseif ($action == 'update' and $this->perm >= self::WRITE) {
# NB 19.12.16: TODO NOT WORKING with update using replace
if (!$this->table->replace($_POST,$info)) $this->error('update: '.print_r($info,true));
- header('Location: '.$this->table->base);
+ header('Location: '.$this->table->base.'/');
} elseif ($action == 'rm' and $this->perm >= self::DELETE) {
if (!$this->table->delete($_POST,$info)) $this->error('rm: '.print_r($info,true));
- header('Location: '.$this->table->base);
+ header('Location: '.$this->table->base.'/');
} else {
public function run() {
#
- # Db Init
+ # Init
#
- $this->db();
- $this->init();
+ $this->run_init();
#
# Root Actions