]> git.nbdom.net Git - nb.git/commitdiff
table_html_add
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 16 Dec 2016 13:23:45 +0000 (13:23 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 16 Dec 2016 13:23:45 +0000 (13:23 +0000)
lib/php/db/table.php
lib/php/nb.php
www/dbq/dbq.php

index 2d791bd99109585f4397dc8f31f5725399a45065..a0b09033ee9550090437356a970ff9a9085455fe 100644 (file)
@@ -400,23 +400,24 @@ Class Table extends nb {
 
   public static function form_hidden($ignore=[]) {
     $h = '';
+
     foreach (array_diff(self::$params,$ignore) as $p) {
-      if ($v=self::p($p)) {
+      if (($v=self::p($p)) or $p=='action') {
         if (self::p('debug')) $h .= "<label>$p</label>";
         $h .= '<input type="'.(self::p('debug')?'text':'hidden').'" name="'.$p.'" value="'.$v.'"/>'.NB_EOL;
       }
     }
+
     return $h;
   }
 
-  public function html_edit($values = null,$form_action='?') {
+  public function html_edit($values = null,$form_action='?',$add=false) {
     if ($values === null) $values = $this->p();
     if (!is_array($values)) $values = [$values];
     $fields = array_filter($this->fields(),function($v){return empty($v->extra);});
     #$fields = $this->fields();
     #debug($fields);
 
-    $add = false;
     $where = $this->where($fields,$values);
     if (empty($where)) {
       $where = ' WHERE 1=0';
@@ -929,7 +930,7 @@ Class Table extends nb {
 
 #debug($this->db()->name);
     if ($opt['is_html'] and !empty(self::$params) and !$this->p('action') and !$this->p('inc')) {
-      echo $this->html_menu();
+      echo $this->html_menu($opt);
     }
 
     if ($opt['is_html']) {
@@ -1722,7 +1723,10 @@ Class Table extends nb {
     self::bye(join(' | ',$err));
   }
 
-  public function html_menu() {
+  public function html_menu($opt=[]) {
+
+    $buttons = '<input type="submit" class="button button-small" value="GO"/>';
+    if (!empty($opt['buttons'])) $buttons = $opt['buttons'];
 
     $r = '<form class="menu" method="get" action="?">'.NB_EOL;
     # See: http://html5doctor.com/html5-forms-input-types/
@@ -1737,9 +1741,11 @@ Class Table extends nb {
       $r .= '<div class="options">';
 
       // Hiddens
-      if ($this->show_hidden_params) $r .= ''
+      #if ($this->show_hidden_params)
+      $r .= ''#.print_r(self::$params,true)
         .self::form_hidden(['db','table','format','limit','download'])
-        .'<input type="hidden" name="download" value="0"/>'; // Embed for no html format
+        // Embed for no html format (rent)
+        .'<input type="'.($this->p('debug') ? 'text' : 'hidden').'" name="download" value="0"/>';
       ;
 
       // Tables - see default.js if you change class
@@ -1787,7 +1793,7 @@ Class Table extends nb {
       }
 
       // Submit
-      $r .= '<input type="submit" class="button button-small" value="GO"/>';
+      $r .= $buttons;
 
       // Order By
       /*
@@ -1823,7 +1829,7 @@ Class Table extends nb {
 
     }
 
-    if ($this->p('options')==='0') $r .= '<input type="submit" class="button button-small" value="GO"/>';
+    if ($this->p('options')==='0') $r .= $buttons;
     $r .= '</div>'; # < Criterias
 
     ///
index 887bd73e0682485307e6c15224c5ebb2963b5c5a..8d68e2f5f4b4634cbdf68cc2f827a72c6e9fedde 100644 (file)
@@ -853,13 +853,19 @@ class NB {
   }
 
   public static function encrypt($key,$value) {
-    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
-    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+    static $iv = null;
+    if ($iv === null) {
+      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
+      $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+    }
     return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_CBC, $iv));
   }
 
   public static function decrypt($key,$value) {
-    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
+    static $iv_size = null;
+    if ($iv_size === null) {
+      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
+    }
     $value = base64_decode($value);
     return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, substr($value, $iv_size), MCRYPT_MODE_CBC, substr($value, 0, $iv_size)));
   }
index cea3a7f5af2419d0b2e8596f6a1d760d976c0810..1147cf1637551ebf08c1e71c3bdd162b80ba13b5 100644 (file)
@@ -214,7 +214,11 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; }
     return $this->db;
   }
 
-  public function table_html_edit() {
+  public function table_html_add() {
+    $this->table_html_edit(true);
+  }
+
+  public function table_html_edit($add=false) {
     $all = [];
     $keys = $this->table->fields_keys($all);
     if (!$keys) $keys = $all;
@@ -224,13 +228,20 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; }
 
     #if (!$keys) return; #$this->not_implemented('Table has no fields');
     #bye(array_combine($keys,$values));
-    $this->table->html_edit(array_combine($keys,$values));
+    $this->table->html_edit(array_combine($keys,$values),'?',$add);
   }
 
   public function table_rows($fct=null) {
+    #$this->pset('action','table.row');
+    #$this->pset('action','');
     $opt = ($this->page->is('html')
       #and $this->table->type() == 'table'
     ) ? [
+      'buttons' => join('&nbsp;',[
+        '<input type="submit" class="button button-small" value="GO"/>',
+        #'<input type="button" class="button button-small" onclick="f=this.parentElement.parentElement; f.elements[\'action\'].value=\'edit\'; f.setAttribute(\'method\',\'POST\'); f.submit();" value="Add"/>',
+        '<input type="button" class="button button-small" onclick="window.location=\''.$this->table->base.'add/'.'\'" value="Add"/>',
+      ]),
       'row_parse_post' => function(&$r){
 
         if ($this->perm < self::VIEW) return;
@@ -277,9 +288,7 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; }
       'show_hidden_params' => false,
       'show_buttons' => false,
       #'params' => [],
-      'params' => [
-        'limit'
-      ],
+      #'params' => [ 'limit' ],
     ]);
 
     $this->table->base = $this->db->base.$this->table->name.'/';
@@ -502,6 +511,9 @@ table.rows th, table.rows td { border-color: '.$this->colors['body-border'].'; }
     } elseif ($action == 'fields') {
       $this->page($this->table,'fields_rows');
 
+    } elseif ($action == 'add') {
+      $this->page($this,'table_html_add');
+
     } elseif ($action == 'vi') {
       $this->page($this,'table_html_edit');