public $field_preff = '';
public $fields = [];
- public $indexes;
+ public $fields_only = [];
+ public $indexes = [];
public $idtemplate;
}
public function field($name) { return $this->fields($name); }
+# NB 14.12.17 public function field_del($name) { unset($this->fields[$name]); }
/*
* Function db.fields
#
$fields = $this->fields();
$fields_filter = [];
- if ($this->p('rows_fields')) {
- $fields_filter = preg_split('/[^\w_]/',$this->p('rows_fields'));
+ if ($this->fields_only) {
+ $fields_filter = $this->fields_only;
$new_fields = [];
foreach ($fields_filter as $k) {
$new_fields[$k] = $fields[$k];
// Connect
if (!empty($connect)) {
- if (!$this->params['db']) $this->not_implemented('Params db missing');
+ if (!$this->params['db']) $this->notImplemented('Params db missing');
if (!isset($this->db)) $this->db = $this->db();
# From conf
exit;
}
- public function not_implemented($admin_msg='') {
+ public function deniedUnless($bool,$msg='Unauthorized') {
+ if ($bool) return;
+ header('Content-type: text/plain');
+ header('HTTP/1.1 401 Unauthorized');
+ echo $msg;
+ exit;
+ }
+
+ public function notImplemented($admin_msg='') {
header('Content-type: text/plain');
$msg = '501 Not Implemented';
if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
.'"');
});
- } elseif ($action == 'ls' and $this->perm >= self::READ) {
+ } elseif ($action == 'ls') {
+ $this->deniedUnless($this->perm >= self::READ);
+ $fields_only = [];
+ if (!strpos($this->params['args'],'=')) $this->table->fields_only = explode(',',$this->params['args']);
$this->page($this,'table_rows');
} elseif ($action == 'fields') {
} elseif ($action == 'status') {
$this->page($this->table->status()+$this->table->status(['fields']));
- } elseif ($action == 'vi' and $this->perm >= self::READ) {
+ } elseif ($action == 'vi') {
+ $this->deniedUnless($this->perm >= self::READ);
$this->page($this,'vi');
- } elseif ($action == 'add' and $this->perm >= self::WRITE) {
+ } elseif ($action == 'add') {
+ $this->deniedUnless($this->perm >= self::WRITE);
$this->page($this,'add');
- } elseif ($action == 'insert' and $this->perm >= self::WRITE) {
+ } elseif ($action == 'insert') {
+ $this->deniedUnless($this->perm >= self::WRITE);
if (!$this->table->insert($_POST,$info)) $this->error('insert: '.print_r($info,true));
header('Location: '.$this->table->base.'/');
$this->page($info);
- } elseif ($action == 'update' and $this->perm >= self::WRITE) {
+ } elseif ($action == 'update') {
+ $this->deniedUnless($this->perm >= self::WRITE);
if (!$this->table->update($_POST,$info)) $this->error('update: '.print_r($info,true));
$this->redirect_if_no_referer($this->table->base.'/');
$this->page($info);
- } elseif ($action == 'replace' and $this->perm >= self::WRITE) {
+ } elseif ($action == 'replace') {
+ $this->deniedUnless($this->perm >= self::WRITE);
if (!$this->table->replace($_POST,$info)) $this->error('replace: '.print_r($info,true));
-# NB 13.12.17 header('Location: '.$this->table->base.'/');
$this->redirect_if_no_referer($this->table->base.'/');
$this->page($info);
} 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.'/');
$this->redirect_if_no_referer($this->table->base.'/');
$this->page($info);
} else {
- $this->not_implemented('Unknown table action'." `$action`");
+ $this->notImplemented('Unknown table action'." `$action`");
}
}
$this->run_table();
#$this->error("Page error");
- $this->not_implemented('Nothing here!');
+ $this->notImplemented('Nothing here!');
return true;
}