]> git.nbdom.net Git - nb.git/commitdiff
referer
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Dec 2015 20:38:41 +0000 (20:38 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 21 Dec 2015 20:38:41 +0000 (20:38 +0000)
lib/php/db/table.php
lib/php/nb.php

index cd58204b70f482a03f0c2fc5eab00e5e3250b99a..5dad705d909e8063913b0c818c48aa06e3804b68 100644 (file)
@@ -292,14 +292,15 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
     echo ''
       .'<div class="db buttons">'
-      .'<input type="hidden" name="table" value="'.$this->p('table').'"/>'
-      .'<input type="hidden" name="action" value="update"/>'
-      .'<input type="hidden" name="db" value="'.$this->p('db').'"/>'
-      .'<input type="hidden" name="debug" value="'.$this->p('debug').'"/>'
       .( empty($_SERVER['HTTP_REFERER']) ? '' : '<input type="button" onclick="document.location=document.referrer" value="Cancel" />')
       .'<input type="reset" />'
       .'<input type="submit"/>'
       .'</div>'.PHP_EOL
+      .'<input type="hidden" name="table" value="'.$this->name.'"/>'
+      .'<input type="hidden" name="action" value="update"/>'
+      .'<input type="hidden" name="db" value="'.$this->db->name.'"/>'
+      .'<input type="hidden" name="debug" value="'.$this->p('debug').'"/>'
+      .'<input type="hidden" name="referer" value="'.urlencode(@$_SERVER['HTTP_REFERER']).'"/>'
     .'</form>'.PHP_EOL;
 
   }
@@ -943,6 +944,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     foreach ($fields as $name) {
       $field->bindParam($query,$hvalues[$name],":$name");
     }
+
     foreach ($keys as $name) {
       $field->bindParam($query,$hvalues[$name],":key_$name");
     }
@@ -989,14 +991,22 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
     } elseif ($action == 'insert') {
       $this->insert($this->p());
-      header('Location: ?table=' . $this->name);
+      if ($this->p('referer')) {
+        header('Location: '.urldecode($this->p('referer')));
+      } else {
+        header('Location: ?table=' . $this->name . ($this->p('db') ? '&db='.$this->db->name : ''));
+      }
       #header('Location: '.str_replace('&amp;','&',$this->url_list()));
       return true;
 
     } elseif ($action == 'update') {
       #$this->bye($this->p());
       $this->update($this->p());
-      header('Location: ?table=' . $this->name);
+      if ($this->p('referer')) {
+        header('Location: '.urldecode($this->p('referer')));
+      } else {
+        header('Location: ?table=' . $this->name . ($this->p('db') ? '&db='.$this->db->name : ''));
+      }
       #header('Location: '.str_replace('&amp;','&',$this->url_list()));
       return true;
 
index 91fb341bb456846544a104e401666b6db007ea37..e64b49adab81ddca727b68abf372a7775d4550a8 100644 (file)
@@ -5,14 +5,14 @@ class nb {
 
   # Sql: elect type,ext from mime_type where ext in ('json','csv','txt','yaml','xml','html','doc','xls');
   public static $content_types = array(
-    'application/json'         => 'json',
-    'application/msword'       => 'doc',
-    'application/vnd.ms-excel' => 'xls',
-    'application/xml'          => 'xml',
-    'text/csv'                 => 'csv',
-    'text/html'                => 'html',
-    'text/plain'               => 'txt',
-    'text/yaml'                => 'yaml',
+    'json' => 'application/json',
+    'doc'  => 'application/msword',
+    'xls'  => 'application/vnd.ms-excel',
+    'xml'  => 'application/xml',
+    'csv'  => 'text/csv',
+    'html' => 'text/html',
+    'txt'  => 'text/plain',
+    'yaml' => 'text/yaml',
   );
 
   function __destruct() {
@@ -69,7 +69,7 @@ class nb {
    * Does what it says
    */
   static function ext2mime($ext) {
-    foreach (self::$content_types as $c => $e) {
+    foreach (self::$content_types as $e => $c) {
       if ($ext == $e) return $c;
     }
   }