return $this->fields;
}
+ function url_edit($values=null) {
+ if ($values === null) $values = $_REQUEST;
+ $url_edit = array();
+
+ foreach ($this->fields_keys() as $name => $spec) {
+ $url_edit[] = $name . '=' .urlencode($values[$name]);
+ }
+
+ return $url_edit ? 'edit/?table='.$_REQUEST['table'].'&'.join('&',$url_edit) : '';
+
+ }
+
function fields_keys() {
if (!$this->fields_keys) {
if (!is_array($values)) $values = array($values);
$sql = "SELECT *" . $this->select_extras();
- $sql .= " FROM $this->name".$this->where_criterias($values);
+ $sql .= " FROM $this->name".str_replace(' LIKE ','=',$this->where_criterias($values));
$sql .= " LIMIT 1";
$this->sql = $sql;
// No empty values
$v = @$values[$k];
if (strcmp($v,'')==0 or $v=='!' or $v=='~') continue;
+ $number = preg_match('/int|float|number|currency/',$spec['type']) ? 1 : 0;
// Equal / Not Equal
$equal = '=';
// Text
} elseif (preg_match('/text|char|blob/',$spec['type'])
- or !preg_match('/^\d+(\.\d*)?$/',$v) # text criteria
+ or !preg_match('/^\d+(\.\d*)?$/',$v) # text criteria value
+
) {
if (strtolower($v)=='null') $v = '';
$v = $this->db->conn->quote($v);
$equal = ' '.($not ? 'NOT ' : '').'LIKE ';
- // Integer
+ // Others
} else {
- if (preg_match('/date|time/',$spec['type'])) $v = $this->db->conn->quote($v);
- if (strtolower($v)=='null') $v = '0';
+
+ // Integer
+ if ($number) {
+ if (strtolower($v)=='null') $v = '0';
+
+ // Date, Time
+ } else {
+ $v = $this->db->conn->quote($v);
+
+ }
$equal = $not ? '<>' : '=';
}
}
- #if ($format == 'table') array_unshift($row,'EDIT');
+ #debug($this->url_edit($row));
+ if ($format == 'table') array_unshift($row,'<a href="'.$this->url_edit($row).'">EDIT</a>');
echo $this->{"rows_rec_$format"}($row);
}
$html = '<table class="'.$this->name.' rows border">'.PHP_EOL;
$html .= '<tr class="'.$this->name.' row bold">';
- #$html .= '<th class="EDIT"></th>';
+ $html .= '<th class="EDIT"></th>';
foreach (array_keys($this->fields()) as $f) {
$html .= '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
}