]> git.nbdom.net Git - nb.git/commitdiff
db.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 23 Jun 2015 22:19:24 +0000 (23:19 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 23 Jun 2015 22:19:24 +0000 (23:19 +0100)
lib/php/db.php

index 56f838d02a45d70e9a45f4dab7a0cf945bce8b09..27058f8c2b55c871b111863524c0eac8372a5187 100644 (file)
@@ -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,'<a href="'.$this->url_edit($row).'">EDIT</a>');
       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 = '<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>';
     }