$values = (array)$values;
$suff = count( $values ) > 1 ? '[]' : '';
+ if ($type === null) $type = $this->html_type();
+
foreach ($values as $value) {
$html .= '<div class="label '.$this->name.'"><label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>';
$html .= $this->htmlYesNo($value);
} else {
- if ($tag == 'textarea' and $this->html_type() != 'text') $tag = 'input';
+ if ($tag == 'textarea' and $type != 'text') $tag = 'input';
+ if ($media = Mime::html($value,'')) {
+ $tag = 'input';
+ $type = 'hidden';
+ $html .= $media;
+ }
+
+ # NB 09.02.18: needed ?
+ $value = htmlspecialchars($value);
$html .= '<'.$tag
.' name="'.$this->preffix.$this->name.$suff.'"'
# NB 06.02.18 .' id="'.$this->name.'"'
.( ($size and $tag != 'textarea') ? ' size="'.$size.'"' : '')
#.' value="'.$value.'"'
- .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'
- .($type ? $type : $this->html_type())
- .'" value="'.$value.'" />')
+ .($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.$value.'" />')
;
}
public $key_preff = '_key_';
public $fields = [];
- public $fields_only = [];
+ public $fields_only = []; # filter for rows
public $indexes = [];
public $idtemplate;
+ public static $params = [
+ 'db', 'table', 'limit', 'debug', 'action',
+ 'page', 'paged', # wordpress
+ ];
+
# hidden, sort, ... fields
public $show_hidden_params = true;
public $show_buttons = true;
public $show_url_sort = true;
public $show_header = true;
- public static $params = [
- 'db', 'table', 'limit', 'debug', 'action',
- 'page', 'paged', # wordpress
- ];
function __construct($name,$opt=[]) {
return html_edit($values,$form_action,true);
}
- private function sql_edit($values = null,&$add=false) {
+ private function _html_edit_sql($values = null,&$add=false) {
$where = $this->where($this->fields(),$values);
if (empty($where)) {
$where = ' WHERE 1=0';
if ($fct = $this->db()->conf_type('html_edit_row')) {
} else {
$fct = function (&$table,&$values) use ($add) {
- $sql = $table->sql_edit($values,$add);
+ $sql = $table->_html_edit_sql($values,$add);
$st = $table->db()->conn->prepare($sql);
$st->execute();
$row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT);
// Form
echo '<form class="db edit form-table" method="post" action="'.$form_action.'">'.NB_EOL;
echo '<div class="fields">'.NB_EOL;
- #if ( $add or ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))) {
if ( $add or $row) {
if (!empty($row)) $this->db()->table_row_decrypt($this,$row);
}
if (!$add and $field->key) {
- echo '<input name="'.$this->key_preff.$name.'" value="'.$row[$name].'" type="hidden" />'.NB_EOL;
+ echo $this->key_preff.'<input name="'.$this->key_preff.$name.'" value="'.$row[$name].'" type="hidden" />'.NB_EOL;
}
+
echo $field->html_edit($row[$name]);
}
}
- //
- // Keep only wanted fields
- //
- $this->fields_only($row);
-
//
// Post
//
$call = $opt['row_parse_post']; $call($row,$this,$opt);
}
+ //
+ // Keep only wanted fields
+ //
+ $this->fields_only($row);
+
return $call;
}
# Fields
#
$opt['fields'] = $fields = $this->fields();
-# NB 07.02.18 $this->fields_only($fields);
# Check fields_only exists
if (!empty($this->fields_only)) foreach ($this->fields_only as $f) {
$file = TABLE_TEMPLATE.'/'.$id.'.php';
if (!is_readable($file)) return false; #$this->bye("Wrong id `$id`");
-# NB 02.12.16 $o['file'] = $file;
$this->__file = $file;
$this->__fields = array_keys($fields);
-# NB 02.12.16 $HEAD = array_keys($fields);
-# NB 02.12.16 $ROWS = [];
-# NB 02.12.16 $ROW = [];
-# NB 02.12.16 require $o['file'];
}
private function rows_rec_template($row,&$o) {
$i++;
}
$this->__rows[] = $row;
-# NB 02.12.16 $HEAD = [];
-# NB 02.12.16 $ROWS = [$row];
-# NB 02.12.16 $ROW = $row;
}
private function rows_end_template() {
private function rows_rec_sql(&$row,&$opt) {
$keys = $values = [];
+ $this->fields_only($row);
+
foreach ($row as $k=>$v) {
if (isset($this->extras[$k])) continue;
$f = $this->field($k);
}
$fields = $this->fields_only ? ' ('.join(',',$keys).')' : '';
- $sql = "INSERT INTO ".$this->sql_name().$fields." VALUES(".join(',',array_values($values)).");";
+ $sql = "INSERT INTO " . $this->sql_name() . $fields . " VALUES(" . join(',',array_values($values)) . ");";
$fct = !empty($opt['fct']) ? $opt['fct'] : null;
if ($fct) $sql = $fct($sql,$this);