public static function form_hidden($ignore=[]) {
$h = '';
+
foreach (array_diff(self::$params,$ignore) as $p) {
- if ($v=self::p($p)) {
+ if (($v=self::p($p)) or $p=='action') {
if (self::p('debug')) $h .= "<label>$p</label>";
$h .= '<input type="'.(self::p('debug')?'text':'hidden').'" name="'.$p.'" value="'.$v.'"/>'.NB_EOL;
}
}
+
return $h;
}
- public function html_edit($values = null,$form_action='?') {
+ public function html_edit($values = null,$form_action='?',$add=false) {
if ($values === null) $values = $this->p();
if (!is_array($values)) $values = [$values];
$fields = array_filter($this->fields(),function($v){return empty($v->extra);});
#$fields = $this->fields();
#debug($fields);
- $add = false;
$where = $this->where($fields,$values);
if (empty($where)) {
$where = ' WHERE 1=0';
#debug($this->db()->name);
if ($opt['is_html'] and !empty(self::$params) and !$this->p('action') and !$this->p('inc')) {
- echo $this->html_menu();
+ echo $this->html_menu($opt);
}
if ($opt['is_html']) {
self::bye(join(' | ',$err));
}
- public function html_menu() {
+ public function html_menu($opt=[]) {
+
+ $buttons = '<input type="submit" class="button button-small" value="GO"/>';
+ if (!empty($opt['buttons'])) $buttons = $opt['buttons'];
$r = '<form class="menu" method="get" action="?">'.NB_EOL;
# See: http://html5doctor.com/html5-forms-input-types/
$r .= '<div class="options">';
// Hiddens
- if ($this->show_hidden_params) $r .= ''
+ #if ($this->show_hidden_params)
+ $r .= ''#.print_r(self::$params,true)
.self::form_hidden(['db','table','format','limit','download'])
- .'<input type="hidden" name="download" value="0"/>'; // Embed for no html format
+ // Embed for no html format (rent)
+ .'<input type="'.($this->p('debug') ? 'text' : 'hidden').'" name="download" value="0"/>';
;
// Tables - see default.js if you change class
}
// Submit
- $r .= '<input type="submit" class="button button-small" value="GO"/>';
+ $r .= $buttons;
// Order By
/*
}
- if ($this->p('options')==='0') $r .= '<input type="submit" class="button button-small" value="GO"/>';
+ if ($this->p('options')==='0') $r .= $buttons;
$r .= '</div>'; # < Criterias
///
}
public static function encrypt($key,$value) {
- $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
- $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+ static $iv = null;
+ if ($iv === null) {
+ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
+ $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+ }
return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_CBC, $iv));
}
public static function decrypt($key,$value) {
- $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
+ static $iv_size = null;
+ if ($iv_size === null) {
+ $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
+ }
$value = base64_decode($value);
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, substr($value, $iv_size), MCRYPT_MODE_CBC, substr($value, 0, $iv_size)));
}
return $this->db;
}
- public function table_html_edit() {
+ public function table_html_add() {
+ $this->table_html_edit(true);
+ }
+
+ public function table_html_edit($add=false) {
$all = [];
$keys = $this->table->fields_keys($all);
if (!$keys) $keys = $all;
#if (!$keys) return; #$this->not_implemented('Table has no fields');
#bye(array_combine($keys,$values));
- $this->table->html_edit(array_combine($keys,$values));
+ $this->table->html_edit(array_combine($keys,$values),'?',$add);
}
public function table_rows($fct=null) {
+ #$this->pset('action','table.row');
+ #$this->pset('action','');
$opt = ($this->page->is('html')
#and $this->table->type() == 'table'
) ? [
+ 'buttons' => join(' ',[
+ '<input type="submit" class="button button-small" value="GO"/>',
+ #'<input type="button" class="button button-small" onclick="f=this.parentElement.parentElement; f.elements[\'action\'].value=\'edit\'; f.setAttribute(\'method\',\'POST\'); f.submit();" value="Add"/>',
+ '<input type="button" class="button button-small" onclick="window.location=\''.$this->table->base.'add/'.'\'" value="Add"/>',
+ ]),
'row_parse_post' => function(&$r){
if ($this->perm < self::VIEW) return;
'show_hidden_params' => false,
'show_buttons' => false,
#'params' => [],
- 'params' => [
- 'limit'
- ],
+ #'params' => [ 'limit' ],
]);
$this->table->base = $this->db->base.$this->table->name.'/';
} elseif ($action == 'fields') {
$this->page($this->table,'fields_rows');
+ } elseif ($action == 'add') {
+ $this->page($this,'table_html_add');
+
} elseif ($action == 'vi') {
$this->page($this,'table_html_edit');