public $extras;
public $preffix = '';
public $html_edit_hide_min_size = 500;
+ public $html_textarea_min_size = 300;
public function __sleep() { return [
'name',
public function string() {
if ($this->numeric()) return false;
- if (strpos($this->type,'bool') !== false) return false;
+ if ($this->bool()) return false;
return true;
}
return preg_match('/signed|(small|tiny)?int|float|decimal|numeric|number|currency/i',$this->type) ? true : false;
}
+ public function bool() {
+ return (strpos($this->type,'bool') !== false);
+ }
+
public function unsigned() {
return ( stripos($this->type,'unsigned') !== false ? true : false );
}
public function html_type() {
# See: http://www.w3schools.com/html/html_form_input_types.asp
if (stripos($this->name,'password') !== false) return 'password" autocomplete="off';
- if ($this->numeric() !== false) return 'number" step="any';
- return 'text';
+ if ($this->numeric()) return 'number" step="any';
# Html5 only
+ if (preg_match('/((^|_)tel|(^|_)mobile|(^|_)phone)/',$this->name)) return 'tel';
+ if (preg_match('/((^|_)month($|_))/',$this->name)) return 'month';
+ if (preg_match('/^passw*/',$this->name)) return 'tel';
if (stripos($this->name,'mail') !== false) return 'email'; # no safari
if (strpos($this->name,'color') !== false) return 'color'; # no safari, no ie
# NOT READY
- if (strpos($this->type,'datetime') !== false) return 'datetime';
+ #if (strpos($this->type,'datetime') !== false) return 'datetime';
+ if (preg_match('/^(timestamp|datetime)/',$this->type)) return 'datetime';
if (strpos($this->type,'time') !== false) return 'time';
if (strpos($this->type,'date') !== false) return 'date';
+ return 'text';
}
# NB 14.09.18 public function sqlValue($value) {
public function htmlValue($value,&$mime=null) {
#if (strpos($this->type,'bool') !== false) re
- if (strpos($this->type,'bool') !== false) {
- return preg_match('/^(1|yes|on|true)/i',$value) ? 'Yes' : 'No';
- }
+ if ($this->bool()) return preg_match('/^(1|yes|on|true)/i',$value) ? 'Yes' : 'No';
$value = Mime::html($value,$value,$mime);
return $value;
private function _html_textarea($size=0) {
#$size = ($this->size() and is_scalar($this->size())) ? $this->size() : 0;
- return ( ($size>300) or preg_match('/^(\w*text|binary|blob|varchar)/i',$this->type) ) ? true : false;
+ #debug ( ( ($size>300) or preg_match('/^(\w*text|binary|blob|varchar)/i',$this->type) ) ? true : false );
+ return ( ($size >= $this->html_textarea_min_size) or preg_match('/^(\w*text|binary|blob|varchar)/i',$this->type) ) ? true : false;
}
public function html_edit($values,$type=null) {
$size = ($this->size() and is_scalar($this->size())) ? $this->size() : 0;
$tag = $this->_html_textarea($size) ? 'textarea' : 'input';
+ #debug((int)($this->_html_textarea($size)));
+ #$tag = ( ($size >= 300) or preg_match('/^(\w*text|binary|blob|varchar)/i',$this->type) ) ? 'textarea' : 'input';
$html = '';
if ($db = $this->db() and $fct=$db->conf_type('html_edit_multi')) $multi = $fct($this);
$suff = $multi ? '[]' : '';
if ($type === null) $type = $this->html_type();
+ #if (empty($type)) $type = 'text';
foreach ((array)$values as $value) {
if ($this->extras) {
$h .= '<span class="extra '.$this->name.'">'.$this->out($value).'</span>';
- } elseif (strpos($this->type,'bool') !== false) {
+ } elseif ($this->bool()) {
$h .= $this->htmlYesNo($value);
} else {
# NB 09.02.18: needed ?
- if ($tag == 'textarea' and $type != 'text') $tag = 'input';
+# NB 02.10.18 if ($tag == 'textarea' and $type != 'text') $tag = 'input';
# Trim CHAR type
if (preg_match('/^\s+$/',$value)) $value = '';
+ # Html friendly
+ if ($media = Mime::html($value,'',$mime,$media_type)) {
+
+ if (!empty($media_type)) {
+ $type = $media_type;
+ $tag = 'input';
+ }
+ #debug([$this->name,$type]);
+ if ($this->html_edit_hide_min_size
+ and $this->html_edit_hide_min_size <= mb_strlen($value)
+ ) {
+ $tag = 'input';
+ $type = 'hidden';
+ }
+
+ $media = '<span class="media">'.$media.'</span>';
+ }
+
# Tag
$h .= '<'.$tag
.' name="'.$this->preffix.$this->name . ($multi ? '[]' : '') . '"'
. ($this->autoincrement ? ' readonly="readonly"' : '')
. ($this->null ? '' : ' required="required"')
.($tag == 'textarea' ? '>'.$value.'</textarea>' : ' type="'.$type.'" value="'.htmlspecialchars($value).'" />')
- ;
-
- # Html friendly
- if ($media = Mime::html($value,'',$mime)) {
- if ($this->html_edit_hide_min_size
- and $this->html_edit_hide_min_size <= mb_strlen($value)
- ) {
- $tag = 'input';
- $type = 'hidden';
- }
- #$h .= $media;
- $h .= '<div class="media">'.$media.'</div>';
- }
+ .$media;
}
} else { # Not a string
# NB 14.09.18: Ok with all databases types ?
- if (strpos($this->type,'bool') !== false) $value = preg_match('/^(f.*|no|0)?\s*$/i',$value) ? 'false' : 'true';
+ if ($this->bool()) $value = preg_match('/^(f.*|no|0)?\s*$/i',$value) ? 'false' : 'true';
if (strcmp($value,'') == 0) $value = 'NULL';
}
}
*/
+ public function sql_where($value) {
+ #if ($this->bool()) $value = preg_match('/^(f.*|no|0)?\s*$/i',$value) ? 'false' : 'true';
+ #if ($this->bool()) return ( preg_match('/^(f.*|no|0)?\s*$/i',$value) ? ' NOT' : '' ) . $this->sql_name();
+ if ($this->bool()) return ( preg_match('/^(yes|1|on|t)/i',$value) ? '' : 'NOT ' ) . $this->sql_name();
+ return $this->sql_name() . '=' . $this->quote($value);
+ }
+
public static function pdo2type($pdo) {
if ($pdo === PDO::PARAM_BOOL) return 'bool';
if ($pdo === PDO::PARAM_LOB) return 'blob';
public function type2pdo() {
if (func_get_args()>0 and func_get_arg(0) === null) return PDO::PARAM_NULL;
if ($this->numeric()) return PDO::PARAM_INT;
- if (strpos($this->type,'bool') !== false ) return PDO::PARAM_BOOL;
+ if ($this->bool()) return PDO::PARAM_BOOL;
if (strpos($this->type,'blob') !== false ) return PDO::PARAM_LOB; # not a bug LOB
return PDO::PARAM_STR;
}
if (!empty($ignore) and in_array($k,$ignore)) continue;
if (isset($v) or $k=='action') {
if (self::p('debug')) $h .= "<label>$k:</label>";
- $h .= '<input type="'.(self::p('debug')?'text':'hidden').'" name="'.$k.'" value="'.$v.'"/>'.NB_EOL;
+ $h .= '<input type="'.(self::p('debug')?'text':'hidden').'" name="'.$k.'" value="'.$v.'" class="form-control"/>'.NB_EOL;
}
}
}
// Form
- echo '<form class="container db edit '.($add ? 'add ' : '' ).'form-table" method="post" action="'.$form_action.'">'.NB_EOL;
+ echo '<form class="container db-edit db edit '.($add ? 'add ' : '' ).'form-table" method="post" action="'.$form_action.'">'.NB_EOL;
echo '<div class="fields insert-bottom">'.NB_EOL;
if ($add or $row) {
$title = $this->prettyText($name).': ';
# Asc
- $sel = ( $this->p('orderby')=="$name asc") ? " sel" : "";
+ $sel = ( $this->p('orderby')=="$name asc") ? " sel active" : "";
$html .= '<a title="'.$title.'first In (asc)" class="sort asc'.$sel.'" href="'.$this->url_list('orderby',"$name asc").'">'
.'<span class="asc">↓</span>'
.'</a>';
#$html .= ' ';
# Desc
- $sel = ( $this->p('orderby')=="$name desc") ? " sel" : "";
+ $sel = ( $this->p('orderby')=="$name desc") ? " sel active" : "";
$html .= '<a title="'.$title.'last In (desc)" class="sort desc'.$sel.'" href="'.$this->url_list('orderby',"$name desc").'">'
.'<span class="desc">↑</span>'
.'</a>';
if ($need_all_values) return null;
continue;
}
- $where[] = $field->sql_name() . '=' . $field->quote($hvalues[$k]);
+ $where[] = $field->sql_where($hvalues[$k]);
+ /*
+ if ($field->bool()) {
+ $where[] = $field->sql_name() . '=' . $field->quote($hvalues[$k]);
+ } else {
+ $where[] = $field->sql_name() . '=' . $field->quote($hvalues[$k]);
+ }
+ */
}
return empty($where) ? '' : ' WHERE ' . join(' AND ',$where);
} else {
// Integer
- if ($field->numeric()) {
+ if ($field->bool()) {
+ } elseif ($field->numeric()) {
if (strtolower($v)=='null') $v = '0';
#$k = "COLAESCE($k,0)";
} elseif ($match) {
if ($field->null) $k = 'COALESCE('.$name.','.$this->db()->quote('').")";
+ } elseif (true and $field->bool()) {
+ $k = $field->sql_where($v);
+ $v = '';
+ $equal = '';
+
} elseif ($field->numeric()) {
$name = $field->sql_name();
if ($field->null) $k = 'COALESCE('.$name.",0)";