From cb8f0530b8258e7f9383beb245d8be2b3d1eca38 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 23 Jun 2015 23:19:24 +0100 Subject: [PATCH] db.php --- lib/php/db.php | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/php/db.php b/lib/php/db.php index 56f838d0..27058f8c 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -298,6 +298,18 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. 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) { @@ -319,7 +331,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. 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; @@ -512,6 +524,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. // 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 = '='; @@ -526,7 +539,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. // 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 = ''; @@ -538,10 +552,18 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $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 ? '<>' : '='; } @@ -692,7 +714,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } - #if ($format == 'table') array_unshift($row,'EDIT'); + #debug($this->url_edit($row)); + if ($format == 'table') array_unshift($row,'EDIT'); echo $this->{"rows_rec_$format"}($row); } @@ -799,7 +822,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $html = ''.PHP_EOL; $html .= ''; - #$html .= ''; + $html .= ''; foreach (array_keys($this->fields()) as $f) { $html .= ''; } -- 2.47.3
'.$this->url_sort($f).'