]> git.nbdom.net Git - nb.git/commitdiff
css
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 25 Jun 2015 23:25:16 +0000 (00:25 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 25 Jun 2015 23:25:16 +0000 (00:25 +0100)
lib/php/db.php
lib/php/default.php
lib/php/functions.php
lib/php/page.php

index 27058f8c2b55c871b111863524c0eac8372a5187..68773107cf431f9c1c6e24f1955a3178e8c5c6f6 100644 (file)
@@ -16,6 +16,7 @@ if (!function_exists('err')) {
 }
 
 class db {
+
   var $tables = array();
   var $conn;
   var $type;
@@ -173,6 +174,7 @@ EOF;
   }
 
   function initParams($tables=null) {
+
     if (empty($_REQUEST)) $_REQUEST = array();
     if ($tables === null) $tables = $this->tables();
 
@@ -192,9 +194,35 @@ EOF;
 
     @$GLOBALS['PAGE']['js_code'] = 'var sem_ui_tables = ['.join(',',ar_map('str_quote($a)',$tables)).']; var sem_ui_table = '.str_quote(@$_REQUEST['table']).';';
 
+  }
+
+  function html_menu() {
+
+    $r = '';
+
+    $r .= '<ul class="db menu">'.PHP_EOL;
+    $r .= '<li class="tables">Tables';
+    $r .= '<ul>'.PHP_EOL;
+
+    foreach ($this->tables() as $table) {
+      #$count = $table->rowCount();
+      $r .= '<li class="'.$table.'">';
+      #$pretty = prettyText($table);
+      $r .= $table == @$_REQUEST['table'] ? "<span class=\"sel\">$table</span>" : '<a href="?table='.$table.'">'.$table."</a>";
+      $r .= '</li>'.PHP_EOL;
     }
+
+    $r .= '</ul>'.PHP_EOL;
+    $r .= '</li>'.PHP_EOL;
+
+    $r .= '</ul>'.PHP_EOL;
+
+    return $r;
+
   }
 
+}
+
 class table {
 
   var $name;
@@ -298,7 +326,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     return $this->fields;
   }
 
-  function url_edit($values=null) {
+  function url_edit($values=null,$sep='&amp;') {
     if ($values === null) $values = $_REQUEST;
     $url_edit = array();
 
@@ -306,7 +334,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       $url_edit[] = $name . '=' .urlencode($values[$name]);
     }
 
-    return $url_edit ? 'edit/?table='.$_REQUEST['table'].'&'.join('&',$url_edit) : '';
+    return $url_edit ? 'edit/?table='.$_REQUEST['table'].$sep.join($sep,$url_edit) : '';
 
   }
 
@@ -326,7 +354,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
   }
 
-  function edit($values = null) {
+  function html_edit($values = null) {
     if ($values === null) $values = $_REQUEST;
     if (!is_array($values)) $values = array($values);
 
@@ -339,6 +367,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     $st = $this->db->conn->prepare($sql);
     $st->execute();
 
+    echo '<form class="db edit" method="post">'.PHP_EOL;
     $count = 0;
     if ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
       $count ++;
@@ -358,12 +387,13 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     }
 
     echo ''
-      .'<div class="buttons">'
-      .'<input type="submit" />'
+      .'<div class="db buttons">'
+      .'<input type="submit" name="update"/>'
+      .'<input type="text" name="table" value="'.$_REQUEST['table'].'"/>'
       .'<input type="reset" />'
       .($_SERVER['HTTP_REFERER'] ? '<input type="button" onclick="document.location=document.referrer" value="Cancel" />' : '')
-      .'</div>'
-    .PHP_EOL;
+      .'</div>'.PHP_EOL
+    .'</form>'.PHP_EOL;
 
     $this->row = $row;
     return $this;
@@ -715,7 +745,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       }
 
       #debug($this->url_edit($row));
-      if ($format == 'table') array_unshift($row,'<a href="'.$this->url_edit($row).'">EDIT</a>');
+      if ($format == 'table') array_unshift($row,'<a href="'.$this->url_edit($row,'&amp;').'">EDIT</a>');
       echo $this->{"rows_rec_$format"}($row);
 
     }
@@ -871,4 +901,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
   }
 
 }
+
+return;
 ?>
index 0bcb7454a2cb891d4ef523bbbd910d83fd7b043d..c987e882dcae9e2793759a86332bc9ce8353da3f 100644 (file)
@@ -1,73 +1,7 @@
 <?php
-ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
 @define('DEBUG',(int)$_REQUEST['debug']);
-require_once((dirname(__FILE__).'/page.php'));
-
-
-function file_write($file,$data,$mode='w') {
-
-  if (!$ftmp = fopen($file,$mode)) {
-    if (DEBUG) warn("file_write(): Cant open $file in mode $mode");
-    return;
-  }
-
-  if (fwrite($ftmp,$data) === FALSE) {
-    if (DEBUG) warn("file_write(): Cant write $file in mode $mode");
-    return;
-  }
-
-  fclose($ftmp);
-  return 1;
-
-}
-
-function ls_dir($path,$recurse=false,$exp='') {
-
-  $ls = array();
-  $rep = opendir($path);
-  #die(">>>".$exp);
-
-  while($file = readdir($rep)) {
-
-    if ($file == '.' or $file == '..') continue;
-    
-    if (!$exp or preg_match('#\.('.$exp.')$#',$file)) {
-      $ls[] = $file;
-    }
-
-    if ($recurse and is_dir("$path/$file")) {
-#print ">>>$path/$file\n";
-
-      foreach (ls_dir("$path/$file",$recurse,$exp) as $l) {
-#print ">>>$path/$file << $l\n";
-        $ls[] = "$file/$l";
-      }
-
-    }
-
-    #echo "<div>$file</div>\n";
-
-  }
-
-  closedir($rep);
-
-#print ">>>$path: ".print_r($ls,true)."\n";
-  return $ls;
-
-}
-
-function ar_map($return,$array,$as_hash=false) {
-  $map = array_map(create_function('$a',"return($return);"),$array);
-  if ($as_hash) {
-    $new = array();
-    foreach ($map as $k => $v) {
-      foreach ($v as $kk => $vv) {
-        $new[$kk] = $vv;
-      }
-    }
-    $map = $new;
-  }
-  return $map;
-}
+ini_set('include_path', realpath(dirname(__FILE__)).':'.ini_get('include_path'));
 
+require_once((dirname(__FILE__).'/functions.php'));
+require_once((dirname(__FILE__).'/page.php'));
 ?>
index 2abe2103a17bef697aa995b2627d16375341bec6..cbd8bacbece4a87bba7aac26b5b38503b0f4bcd5 100644 (file)
@@ -1,8 +1,80 @@
 <?php
 @define('DEBUG',(int)$_REQUEST['debug']);
-require_once((dirname(__FILE__).'//default.php'));
+require_once((dirname(__FILE__).'/default.php'));
 require_once(dirname(__FILE__).'/parsedown/Parsedown.php');
 
+function file_write($file,$data,$mode='w') {
+
+  if (!$ftmp = fopen($file,$mode)) {
+    if (DEBUG) warn("file_write(): Cant open $file in mode $mode");
+    return;
+  }
+
+  if (fwrite($ftmp,$data) === FALSE) {
+    if (DEBUG) warn("file_write(): Cant write $file in mode $mode");
+    return;
+  }
+
+  fclose($ftmp);
+  return 1;
+
+}
+
+function ls_dir($path,$recurse=false,$exp='') {
+
+  $ls = array();
+  $rep = opendir($path);
+  #die(">>>".$exp);
+
+  while($file = readdir($rep)) {
+
+    if ($file == '.' or $file == '..') continue;
+    
+    if (!$exp or preg_match('#\.('.$exp.')$#',$file)) {
+      $ls[] = $file;
+    }
+
+    if ($recurse and is_dir("$path/$file")) {
+#print ">>>$path/$file\n";
+
+      foreach (ls_dir("$path/$file",$recurse,$exp) as $l) {
+#print ">>>$path/$file << $l\n";
+        $ls[] = "$file/$l";
+      }
+
+    }
+
+    #echo "<div>$file</div>\n";
+
+  }
+
+  closedir($rep);
+
+#print ">>>$path: ".print_r($ls,true)."\n";
+  return $ls;
+
+}
+
+function ar_map($return,$array,$as_hash=false) {
+  $map = array_map(create_function('$a',"return($return);"),$array);
+
+  if ($as_hash) {
+
+    $new = array();
+
+    foreach ($map as $k => $v) {
+      foreach ($v as $kk => $vv) {
+        $new[$kk] = $vv;
+      }
+    }
+
+    $map = $new;
+
+  }
+
+  return $map;
+}
+
 function txt2md($txt) {
   static $MD = null;
   if ($MD === null) $MD = new Parsedown();
@@ -39,8 +111,11 @@ function debug($msg,$level=0) {
 }
 
 function prettyText($text) {
-  $text = str_replace('_',' ',$text);
-  return ucwords(preg_replace('/\W+/',' ',$text));
+  return ucwords(
+    preg_replace('/\W+/',' ',
+      str_replace('_',' ',$text)
+    )
+  );
 }
 
 function rtf2txt($rtf) {
index a7f35878d52f75032d40aeeeea4589dc9411469d..669cbcc82900937265380d1b37ce918f2e209a50 100644 (file)
@@ -84,10 +84,6 @@ class Page {
     return mb_strtoupper(mb_substr($str,0,1)).mb_strtolower(mb_substr($str,1,mb_strlen($str)));
   }
 
-  function ar_map($return,$array) {
-    return array_map(create_function('$a',"return($return);"),$array);
-  }
-
   function js_quote($str) {
     return "'".str_replace("'","\'",$str)."'";
   }
@@ -96,15 +92,15 @@ class Page {
     $html = array(
       sprintf('%c[1;',27) => sprintf('<bold>%c[0;',27),
 
-        'black'   => 30,
-          'red'     => 31,
-            'green'   => 32,
-              'yellow'    => 33,
-                'blue'    => 34,
-                  'magenta' => 35,
-                    'cyan'    => 36,
-                      'white'   => 37,
-                        'default' => 39,
+      'black'   => 30,
+      'red'     => 31,
+      'green'   => 32,
+      'yellow'  => 33,
+      'blue'    => 34,
+      'magenta' => 35,
+      'cyan'    => 36,
+      'white'   => 37,
+      'default' => 39,
       sprintf('%c[0;30m',27) => '<span style="color:black">',
       sprintf('%c[0;31m',27) => '<span style="color:red">',
       sprintf('%c[0;32m',27) => '<span style="color:green">',
@@ -282,8 +278,8 @@ class Page {
     if ($is == 'xhtml') return preg_match('/xhtml$/',$this->content_type);
     if ($is == 'html') return preg_match('/html$/',$this->content_type);
     if ($is == 'xml') return preg_match('/xml$/',$this->content_type);
-    die("Db->is(): unknow value '$is'");
+    die("Db->is(): unknow argument '$is'. Accepted values are xhtml, html, xml");
   }
-}
-return;
+
+return;
 ?>