]> git.nbdom.net Git - nb.git/commitdiff
css,nav
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 9 Jul 2015 15:35:32 +0000 (16:35 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 9 Jul 2015 15:35:32 +0000 (16:35 +0100)
lib/css/db.css
lib/php/db.php
lib/php/db/table.php

index 85f359f8af65f23d1cdcefd5d73e50e8e4bd0142..814be6d8c19a0d2456fa8278a4e3ee6b49285562 100644 (file)
@@ -1,7 +1,11 @@
+/*
+  All
+.rows { margin: 0 auto; }
+*/
+
 /*
   Edit
 */
-.rows { margin: 0 auto; }
 form.Zdb.edit
 ,form.db.edit label
 ,form.db.edit input
index e28405cfb7fca54dde994fa2e752bd60cace7ba7..1f3542301bd1ba7ef2c8a2e15229e3c570c7a4eb 100644 (file)
@@ -197,7 +197,6 @@ EOF;
     $r .= '</select>'.PHP_EOL;
 
     $r .= '</div>'.PHP_EOL;
-    $r .= '<div id="msg"></div>'.PHP_EOL;
 
     return $r;
 
index a7527fa8e09cb2dd8dad15027a73c1814d2663ef..aa19e14fa689c94645f1bba8f9ee760fe828f6f0 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once(dirname(__FILE__).'/../functions.php');
 if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
+if (!defined('DB_HTML_NAV_TOP')) define('DB_HTML_NAV_TOP','<div align="center" class="nav" id="nav_top"></div>'.PHP_EOL);
 class table {
 
   public $name;
@@ -249,6 +250,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
   function nav($count,$tot,$limit) {
 
+    $html = '';
     if ($count<$tot) {
       list($x,$y) = strpos($limit,',')!==false
         ? preg_split('/\s*,\s*/',$limit)
@@ -266,24 +268,26 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       $next = 999999;
     }
 
-    echo '<div align="center" class="nav" id="nav_bottom">';
+    $html .= '<div align="center" class="nav" id="nav_bottom">';
 
-    if ($prev>=0) echo '<span class="prev"><a href="'.$this->url_params('limit',preg_replace('/^0,/','',"$prev,$y")).'">&lt;&lt;</a></span>&nbsp;';
+    if ($prev>=0) $html .= '<span class="prev"><a href="'.$this->url_params('limit',preg_replace('/^0,/','',"$prev,$y")).'">&lt;&lt;</a></span>&nbsp;';
 
-    echo '<span class="count">'.($tot ? ($x+1) : 0).' - '.($x+$y).' / '.$tot.' results</span>';
+    $html .= '<span class="count">'.($tot ? ($x+1) : 0).' - '.($x+$y).' / '.$tot.' results</span>';
 
-    if ($next<$tot) echo '&nbsp;<span class="prev"><a href="'.$this->url_params('limit',"$next,$y").'">&gt;&gt;</a></span>';
+    if ($next<$tot) $html .= '&nbsp;<span class="prev"><a href="'.$this->url_params('limit',"$next,$y").'">&gt;&gt;</a></span>';
 
-    echo '</div>'.PHP_EOL;
+    $html .= '</div>'.PHP_EOL;
     static $js = null;
     if ($js === null) {
-      echo '<script type="text/javascript"><!-- '.PHP_EOL
+      $html .= '<script type="text/javascript"><!-- '.PHP_EOL
         ."var rb = document.getElementById('nav_bottom'); var rt = document.getElementById('nav_top'); if (rb && rt) rt.innerHTML = rb.innerHTML;\n"
       . ' --></script>'.PHP_EOL
       ;
       $js = '1';
     }
 
+    return $html;
+
   }
 
   function form_criterias($opt=array()) {
@@ -501,7 +505,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     $format = (!empty($opt['format']) ? $opt['format'] : 'table');
 
     if (!@$opt['is_html']) $opt['is_html'] = preg_match('/^(table)$/',$format) ? true : false;
-    if ($opt['is_html']) echo '<div align="center" class="nav" id="nav_top"></div>'.PHP_EOL;
 
     $escape = preg_match('/^(table|row|xml)$/',$format) ? true : false;
     if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($opt);
@@ -526,25 +529,18 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
         }
 
         $count_fields++;
-      /* only if in latin1
-        if ($this->db->p('format') == 'csv') {
-          $row[$f] = utf8_encode($row[$f]);
-        } elseif ($spec['extra']) {
-          $row[$f] = htmlentities($row[$f]);
-
-        }
-      */
 
       }
 
-      #debug($this->url_edit($row));
-      if ($format == 'table') array_unshift($row,'<a class="edit button" href="'.$this->url_edit($row,'&amp;').'">'.DB_HTML_EDIT.'</a>');
+      if ($opt['is_html']) array_unshift($row,'<a class="edit button" href="'.$this->url_edit($row,'&amp;').'">'.DB_HTML_EDIT.'</a>');
       echo $this->{"rows_rec_$format"}($row);
 
     }
 
+    $opt['count'] = $count;
+    $opt['tot'] = $tot;
+    $opt['limit'] = $limit;
     echo $this->{"rows_end_$format"}($opt);
-    if ($opt['is_html']) echo $this->nav($count,$tot,$limit);
 
     $st->closeCursor();
 
@@ -556,28 +552,29 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
   -----------------------------------------------------------------*/
   function rows_begin_json() {
     $this->_row_json = null;
-    echo '['.PHP_EOL;
+    return '['.PHP_EOL;
   }
 
   function rows_rec_json($row) {
+    $json = '';
     if ($this->_row_json === null) {
       $this->_row_json = true;
     } else {
-      echo ',';
+      $json .= ',';
     }
-    echo json_encode($row).PHP_EOL;
+    return $json . json_encode($row).PHP_EOL;
   }
 
   function rows_end_json() {
     unset($this->_row_json);
-    echo ']'.PHP_EOL;
+    return ']'.PHP_EOL;
   }
 
   /*-----------------------------------------------------------------
     Yaml
   -----------------------------------------------------------------*/
   function rows_begin_yaml() {
-    echo "---\n";
+    return "---\n";
   }
 
   function rows_rec_yaml($row) {
@@ -585,52 +582,55 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     $yaml = preg_replace('/^---\n/','',$yaml);
     $yaml = preg_replace('/\n\.\.\.$/','',$yaml);
     $yaml = preg_replace('/^/m','  ',$yaml);
-    echo '- '.trim($yaml)."\n";
+    return '- '.trim($yaml)."\n";
   }
 
   function rows_end_yaml() {
-    echo '';
+    return '';
   }
 
   /*-----------------------------------------------------------------
     Xml
   -----------------------------------------------------------------*/
   function rows_begin_xml() {
-    echo ''
+    return ''
       .'<?xml version=“1.0” encoding=“utf-8”?>'.PHP_EOL
       .'<db name="'.$this->db->name.'" table="'.$this->name.'" type="'.$this->db->type.'">'.PHP_EOL
     ;
   }
 
   function rows_rec_xml($row) {
-    echo "\t<".$this->name.">".PHP_EOL;
+    $xml = '';
+    $xml .= "\t<rows>".PHP_EOL;
     foreach (array_keys($this->fields()) as $f) {
-      if ($row[$f] !== '') echo ''
+      if ($row[$f] !== '') $xml .= ''
         . "\t\t<".$f.'>'
         .'<![CDATA['.$row[$f].']]>'
         . '</'.$f.'>'
       .PHP_EOL;
     }
-    echo "\t</".$this->name.">".PHP_EOL;
+    $xml .= "\t</rows>".PHP_EOL;
+    return $xml;
   }
 
   function rows_end_xml() {
-    #echo '</'.$this->name.'>'.PHP_EOL;
-    echo '</db>'.PHP_EOL;
+    return '</db>'.PHP_EOL;
   }
 
   /*-----------------------------------------------------------------
     Csv
   -----------------------------------------------------------------*/
   function rows_begin_csv() {
-    echo join("\t",array_keys($this->fields()))."\n";
+    return join("\t",array_keys($this->fields()))."\n";
   }
 
   function rows_rec_csv($row) {
-    echo join("\t",array_values($row))."\n";
+    return join("\t",array_values($row))."\n";
   }
 
   function rows_end_csv() {
+    return $this->nav($opt['count'],$opt['tot'],$opt['limit']);
+    return '';
   }
 
   /*-----------------------------------------------------------------
@@ -639,51 +639,73 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 // NB 14.04.14   function rows_begin_table($opt=array()) {
   function rows_begin_table() {
 
-    echo '<table class="'.$this->name.' rows border">'.PHP_EOL;
+    $html = '';
+    $html .= '<table class="'.$this->name.' rows border">'.PHP_EOL;
+
+    if (DB_HTML_NAV_TOP) $html .= '<thead><tr>'
+      . '<td colspan="'.(count($this->fields())+1).'">' . DB_HTML_NAV_TOP . '</td>'
+      . '</tr></thead>'.PHP_EOL
+    ;
 
-    echo '<tr class="'.$this->name.' row bold">';
-    echo '<th class="'.DB_HTML_EDIT.'"></th>';
+    $html .= '<tr class="'.$this->name.' row bold">';
+    $html .= '<th class="'.DB_HTML_EDIT.'"></th>';
     foreach (array_keys($this->fields()) as $f) {
-      echo '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
+      $html .= '<th class="'.$f.'">'.$this->url_sort($f).'</th>';
     }
 
-    echo '</tr>'.PHP_EOL;
+    $html .= '</tr>'.PHP_EOL.'<tbody>'.PHP_EOL;
+
+    return $html;
   }
 
   function rows_rec_table($row) {
-    echo '<tr>';
+    $html = '<tr>';
 
     foreach ($row as $k => $v) {
-      echo '<td class="'.$k.'">'.$v.'</td>';
+      $html .= '<td class="'.$k.'">'.$v.'</td>';
     }
 
-    echo '</tr>'.PHP_EOL;
+    $html .= '</tr>'.PHP_EOL;
+
+    return $html;
   }
 
-  function rows_end_table() {
-    echo '</table>'.PHP_EOL;
+  function rows_end_table($opt=array()) {
+    $html = PHP_EOL.'</tbody>'.PHP_EOL;
+
+    if (!empty($opt['count'])) $html .= '<tfoot><tr>'
+      . '<td colspan="'.(count($this->fields())+1).'">'
+        . $this->nav($opt['count'],$opt['tot'],$opt['limit'])
+      . '</td>'
+     . '</tr></tfoot>'.PHP_EOL
+    ;
+
+    $html .= '</table>'.PHP_EOL;
+    return $html;
   }
 
   /*-----------------------------------------------------------------
     Html Div
   -----------------------------------------------------------------*/
   function rows_begin_div() {
-    echo '<div class="'.$this->name.' rows">'.PHP_EOL;
+    return '<div class="'.$this->name.' rows">'.DB_HTML_NAV_TOP.PHP_EOL;
   }
 
   function rows_rec_div($row) {
 
-    echo '<ul class="border rad bgcolor">';
+    $html = '';
+    $html .= '<ul class="border rad bgcolor">';
 
     foreach ($row as $k => $v) {
-      echo '<li>'
+      $html .= '<li>'
         .'<span class="k">'.$k.'</span>'
         .': '
         .'<span class="v">'.$v.'</span>'
         .'</li>';
     }
 
-    echo '</ul>'.PHP_EOL;
+    $html .= '</ul>'.PHP_EOL;
+    return $html;
   }
 
   function rows_end_div() {