]> git.nbdom.net Git - nb.git/commitdiff
div, bug extras
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 3 Aug 2015 01:43:12 +0000 (02:43 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 3 Aug 2015 01:43:12 +0000 (02:43 +0100)
lib/css/button.css
lib/css/db.css
lib/php/db.php
lib/php/db/field.php
lib/php/db/table.php
lib/php/test.php

index c873d39bea335d7e75998c289c9d7c012ed56079..c19ab182327139699286e6d396f25d3f5c85d756 100644 (file)
 
   background-color: #f4f4f4;
   border: solid 1px #ddd;
-  color: #666;
-
-  background-color: #888;
-  border: solid 1px #444;
-  color: #eee;
-
   /*
+  box-shadow: 0px 1px 0px rgba(0, 0, 0, 0.1);
   */
+  color: #666;
+}
+
+.button:hover {
+  background-color: #f0f0f0;
 }
 
 form a.button:visited,
index 56b447b8d9509ee11e507f04e0f52cb54a83acdb..a2312007b128e052f45abe322d8644d247fa13c2 100644 (file)
@@ -1,15 +1,10 @@
 /*
   All
-.rows { margin: 0 auto; }
-border: solid  1px red !important;
 */
-
-#db {
+label:after {
+  content: ": ";
 }
 
-/*
-  All
-*/
 form .button,
 form input,
 form select,
@@ -20,41 +15,75 @@ form label
 
 form label {
   display: inline-block;
-  width: 4em;
+  width: 8em;
   text-align: right;
 }
 
-form label:after {
-  content: ": ";
-}
-
+/*
+*/
 /*
   List
 */
 .rows {
-  margin: 0 auto;
+  margin: 0.5em auto;
+  clear: both;
+}
+
+td.name,
+td.email,
+td.phone {
+  white-space: nowrap;
 }
 
-.rows ul {
+/*
+  List Div
+
+div.rows { text-align: center; }
+div.rows .row { text-align: left; }
+*/
+
+div.rows .row {
+  vertical-align: top;
+  /*
   margin: 0 0 0.5em 0;
+  */
+  margin-bottom: 0.5em;
   padding: 0.2em;
+  display: inline-block;
+  width: 22em;
 }
 
-.rows ul .edit { float: right; }
-.rows tr.nav td { border: none; }
+div.rows .nav {
+  margin: 0.3em;
+  padding: 0;
+}
 
-td.name,
-td.email,
-td.phone {
-  white-space: nowrap;
+div.rows .row .buttons {
+  padding-bottom: 0.5em;
+}
+
+div.rows .row label {
+  width: 25%;
+  display: inline-block;
+  margin: 0 0.5em 0.1em 0;
+  vertical-align: top;
 }
 
+div.rows .row span {
+  width: 70%;
+  display: inline-block;
+}
+/*
+.rows ul .button { float: right; }
+.rows .buttons { text-align: center; }
+div.rows div.buttons { float: right; }
+*/
+
 /*
   Menu
 */
 .db.menu {
   margin: 0 auto;
-  padding: 0.8em 0.8em 0.8em 0.5em;
   padding: 0.5em 0.8em;
   display: table;
 }
@@ -89,17 +118,25 @@ form.db.edit label {
   margin-bottom: 0.3em;
 }
 
+form.db.edit span,
 form.db.edit input {
   width: 70%;
 }
 
-form.db.edit .buttons {
+/*
+form.db.edit
+*/
+.buttons {
   margin: 0.5em auto 0 auto;
   text-align: center;
   clear: both;
 }
+.buttons .button { margin-left: 0.5em; }
 
-form.db.edit .buttons input {
+/*
+*/
+form.db.edit
+.buttons input {
   width: auto;
   float: none;
 }
index 25dda23da58c179fa48e7577df815b355aa59eb6..c3dd045d92c323ab6cfd3e5b5356f2b1c3be95b6 100644 (file)
@@ -278,7 +278,7 @@ EOF;
       'table','div','csv','xml','json','yaml'
     ),array(
       'html'       => 'class="format" name="format"'.$html,
-      'selected'   => $this->p('table'),
+      'selected'   => $this->p('format'),
       'prettyText' => true,
     ));
 
index 4b7cb09e53d0186e91c2549b5c5bf6e3881f05ec..59a3ce43f35125df838babc82c944cac03bc1ec6 100644 (file)
@@ -13,11 +13,14 @@ class field {
   public $name;
   public $type = 'text';
   public $default = null;
-  private $autoincrement = false;
   public $key = false;
   public $table = null;
+  public $extra = null;
+
+  private $autoincrement = false;
 
   function __construct($attr=array()) {
+    if (is_scalar($attr)) $attr = array('name'=>$attr);
     foreach ($attr as $k => $v) { $this->$k = $v; }
   }
 
@@ -31,8 +34,12 @@ class field {
 
   function html_edit($value) {
 
+    $value = htmlspecialchars($value);
     return '<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
-    .'<input name="'.$this->name.'" id="'.$this->name.'" value="'.htmlspecialchars($value).'" />'
+      .($this->extra
+        ? "<span class=\"field.extra\">$value</span>"
+        : '<input name="'.$this->name.'" id="'.$this->name.'" value="'.$value.'" type="text"/>'
+      )
     .PHP_EOL;
 
   }
@@ -64,7 +71,10 @@ class field {
   }
 
   function size() {
-    return preg_match('/\((\d+)\)/',$this->type,$m) ? $m[1] : null;
+    if (! preg_match('/\((\d+)(?:,(\d+)\))?/',$this->type,$m) ) return null;
+    array_shift($m);
+    return count($m) == 1 ? $m[0] : $m;
+// NB 02.08.15     return preg_match('/\((\d+)\)/',$this->type,$m) ? $m[1] : null;
   }
 
   function where($values) {
@@ -76,7 +86,6 @@ class field {
       or $v=='~'
     ) return null;
 
-// NB 03.07.15       $number = preg_match('/int|float|number|currency/',$this->type) ? 1 : 0;
     $number = $this->numeric();
 
     // Equal / Not Equal
@@ -131,5 +140,18 @@ class field {
 // NB 27.07.15     return $sth->bindParam($name, $value, $this->pdo_type($value));
   }
 
+  function out($value,$html_escape=false) {
+
+    static $sqlite = null; if ($sqlite === null) $sqlite = $this->db()->type == 'sqlite';
+
+    # Anoying !
+    if ($sqlite and preg_match('/^float\((?:\d+,)?(\d+)\)/',$this->type,$m)) {
+      $value = sprintf('%.'.$m[1].'f',$value);
+    }
+
+    if ($html_escape and empty($this->extra)) $row[$f] = htmlspecialchars($row[$f]);
+    return $value;
+  }
+
 }
 ?>
index 009cd9edff137a25d49e3a63f0fe0f4ca9d55209..1bfae6869193b960219765f092ad2282db171f4d 100644 (file)
@@ -55,7 +55,7 @@ class table {
 
     $this->name = $name;
 
-    if (@$opt['extras']) $this->add_extras($opt['extras']);
+    if (isset($opt['extras'])) $this->add_extras($opt['extras']);
 
     return $this->fields();
   }
@@ -122,17 +122,14 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       foreach ($rows as $row) {
 
         $field = array(
-          'name'          => null,
+          'name'          => $row['name'],
           'extra'         => null,
-          'type'          => null,
+          'type'          => strtolower($row['type']),
           'default'       => null,
           'key'           => null,
           'autoincrement' => null,
         );
 
-        $field['name'] = $row['name'];
-        $field['type'] = strtolower($row['type']);
-
         if (isset($row['notnull'])) {
           $field['null'] = $row['notnull'] == '0' ? 1 : 0;
 
@@ -389,7 +386,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     $criteria = array();
     foreach ( array_keys($this->fields()) as $k ) {
 
-      $v = @$_REQUEST[$k];
+      $v = empty($_REQUEST[$k]) ? '' : $_REQUEST[$k];
 
       $criteria[] = ''
         . '<label>'.prettyText($k).':</label>'
@@ -522,12 +519,13 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
     foreach ($extras as $k => $v) {
 
-      $this->fields[$k] = array(
+      $v = new Field( ( is_array($v) ? $v : array() ) + array(
+        'name' => $k, 
         'type' => 'text', 
-        'null' => 0,
         'extra' => $v,
-      );
+      ));
 
+      $this->fields[$k] = $v;
       $this->extras[$k] = $v;
 
     }
@@ -538,24 +536,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
     if (!$this->extras) return '';
 
-    $select = array();
-
-    foreach ($this->extras as $k => $v) {
-
-      $select[] = "$v AS ".($this->db->type == 'pgsql' 
-        ? '"'.str_replace('"','\"',$k).'"'
-        : $this->db->quote($k)
-      );
-      /*
-      $select[] = "$v AS ".$this->db->quote($k);
-      */
-
-      /*
-      $k = $this->db->quote($k);
-      if ($this->db->type == 'pgsqpl') $k = str_replace(
-      $select[] = "$v AS $k"
-      */
-
+    $select = array(); foreach ($this->extras as $k => $v) {
+      $select[] = $v->extra." AS ".$v->quote($k,true);
     }
 
     return ','.join(',',$select);
@@ -616,6 +598,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
       foreach ($this->fields() as $f => $field) {
 
+        #echo '<pre>'; var_dump($field); echo '</pre>';
+        $row[$f] = $field->out($row[$f]);
+// NB 02.08.15         if ($escape and empty($this->extra)) $row[$f] = htmlspecialchars($row[$f]);
+
+        /*
         if (!$field->extra) {
           if ($escape) $row[$f] = htmlspecialchars($row[$f]);
         }
@@ -623,20 +610,12 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
         if ($this->db->type == 'sqlite' and preg_match('/^float\((?:\d+,)?(\d+)\)/',$field->type,$m)) {
           $row[$f] = sprintf('%.'.$m[1].'f',$row[$f]);
         }
-
-        if ($count_fields === 0) {
-          #$row[$f] = '<a href="'.$count_fields.'">' . $row[$f] . '</a>';
-        }
+        */
 
         $count_fields++;
 
       }
 
-      if ($opt['is_html']) {
-        array_unshift($row,'<a class="edit button" href="'.$this->url_keys($row,'action=edit').'">'.DB_HTML_EDIT.'</a>');
-        array_push($row,'<a class="delete button" href="'.$this->url_keys($row,'action=delete').'">'.DB_HTML_DELETE.'</a>');
-      }
-
       echo $this->{"rows_rec_$format"}($row);
 
     }
@@ -743,7 +722,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
   function rows_begin_table() {
 
     $html = '';
-    $html .= '<table class="rows '.$this->name.'">'.PHP_EOL;
+    $html .= '<table class="rows db '.$this->name.'">'.PHP_EOL;
 
     $colspan = 0;
     if (DB_HTML_EDIT) $colspan++;
@@ -754,9 +733,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       . '</tr>'#.'</thead>'.PHP_EOL
     ;
 
-    $html .= ''#'<tbody>'.PHP_EOL
-      .'<tr class="'.$this->name.' row">'
-    ;
+    $html .= '<tr class="head">';
 
     if (DB_HTML_EDIT) $html .= '<th class="'.DB_HTML_EDIT.'"></th>';
 
@@ -770,7 +747,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
   }
 
   function rows_rec_table($row) {
-    $html = '<tr>';
+
+    array_unshift($row,'<a class="edit button" href="'.$this->url_keys($row,'action=edit').'">'.DB_HTML_EDIT.'</a>');
+    array_push($row,'<a class="delete button" href="'.$this->url_keys($row,'action=delete').'">'.DB_HTML_DELETE.'</a>');
+
+    $html = '<tr class="row">';
 
     foreach ($row as $k => $v) {
       $html .= '<td class="'.$k.'">'.$v.'</td>';
@@ -805,27 +786,42 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     Html Div
   -----------------------------------------------------------------*/
   function rows_begin_div() {
-    return '<div class="rows '.$this->name.'">'.DB_HTML_NAV_TOP.PHP_EOL;
+    return '<div class="rows db '.$this->name.'">'.DB_HTML_NAV_TOP.PHP_EOL;
   }
 
   function rows_rec_div($row) {
 
     $html = '';
-    $html .= '<ul>';
+
+    $html .= '<ul class="row">';
+
+    $html .= '<li class="buttons">';
+    $html .= '<a class="edit button" href="'.$this->url_keys($row,'action=edit').'">'.DB_HTML_EDIT.'</a>';
+    $html .= '<a class="delete button" href="'.$this->url_keys($row,'action=delete').'">'.DB_HTML_DELETE.'</a>';
+    $html .= '</li>';
 
     foreach ($row as $k => $v) {
       $html .= '<li>'
-        .( $k == '0' ? '' : '<span class="k">'.$k.'</span>: ')
-        .'<span class="v">'.$v.'</span>'
+        .( $k == '0' ? '' : '<label>'.prettyText($k).'</label>')
+        .'<span>'.$v.'</span>'
         .'</li>';
     }
 
     $html .= '</ul>'.PHP_EOL;
+
+// NB 03.08.15     $html .= '<div class="buttons">';
+// NB 03.08.15     $html .= '<a class="edit button" href="'.$this->url_keys($row,'action=edit').'">'.DB_HTML_EDIT.'</a>';
+// NB 03.08.15     $html .= '<a class="delete button" href="'.$this->url_keys($row,'action=delete').'">'.DB_HTML_DELETE.'</a>';
+// NB 03.08.15     $html .= '</div>';
+
+
     return $html;
   }
 
-  function rows_end_div() {
-    return "</div>".PHP_EOL;
+  function rows_end_div($opt=array()) {
+    return '<div class="nav bottom">'.$this->nav($opt['count'],$opt['tot'],$opt['limit']).'</div>'
+      . "</div>".PHP_EOL
+    ;
   }
 
   function sql_name() {
index 2fff54c07426d004fd97f40f4bd928c6d3eda36e..f4397726f1bdc48ba4195bdcaf339424ef1b7ac3 100644 (file)
@@ -17,6 +17,28 @@ echo $first;
 exit;
 */
 
+function _static() {
+  static $v = null;
+  if ($v === null) $v = preg_match('/zaza/','zaza hello') ? true : false;
+  return $v;
+} benchmark('_static');
+
+function _glob() {
+  if (!isset($GLOBALS['ZAZA'])) $GLOBALS['ZAZA'] = preg_match('/zaza/','zaza hello') ? true : false;
+  return $GLOBALS['ZAZA'];
+} benchmark('_glob');
+
+function _defined() {
+  if (!defined('ZAZA')) define('ZAZA',preg_match('/zaza/','zaza hello') ? true : false);
+  return ZAZA;
+} benchmark('_defined');
+
+function direct() {
+  return preg_match('/zaza/','zaza hello');
+} benchmark('direct');
+benchmark();
+exit;
+
 function _f1() {
   $_REQUEST['zaza'] === null;
 } benchmark('_f1');