let g:File['c'] = '//'
elseif (g:File['type'] == 'php')
- let g:File['c'] = '//'
+ let g:File['c'] = '#'
elseif (g:File['type'] == 'sql')
let g:File['c'] = '--'
margin: 0.3em 0.3em 0.3em 0;
}
+ /*
form label {
display: inline-block;
- width: 8em;
+ width: 7em;
text-align: right;
}
+ */
-/*
-*/
/*
List
*/
margin-bottom: 0.5em;
padding: 0.2em;
display: inline-block;
- width: 22em;
+ width: 21em;
+ width: 16em;
}
div.rows .nav {
form.db.edit label {
width: 20%;
margin-bottom: 0.3em;
+ display: inline-block;
+ text-align: right;
}
form.db.edit span,
--- /dev/null
+/*!
+ * NB JavaScript Library v0.0.0
+ *
+ * Date: 28.03.15
+ * See: http://www.w3schools.com/jquery/jquery_ref_selectors.asp
+ */
+function NB() {
+
+ this.form_submit_clean = function(f) {
+ var i = 0;
+ var msg = '';
+ var url = '';
+ msg += f.action + '\n';
+
+ for(i=0;i<f.length;i++) {
+ var p = f[i];
+ if (!p.name) continue;
+ if (p.value=='') continue;
+ if (p.value=='undefined') continue;
+ msg += p.name + '=' + p.value + '\n';
+ // NB 02.09.13 url += (url ? '&' : '?') + escape(p.name) + '=' + escape(p.value);
+ url += (url ? '&' : '?') + encodeURI(p.name) + '=' + encodeURI(p.value);
+ }
+
+ url = f.action + url;
+
+ //document.location = url;
+
+ /*
+ if (izi_opt['test_version']) {
+ html_msg(''
+ + '<a href="#" onclick="window.location=\''+(url)+'\'; return false;">'
+ + (url)
+ + '</a>'
+ );
+ return false;
+ }
+ */
+
+ //if (url == window.location) return false;
+ window.location = url;
+ return false;
+ }
+
+ this.form_clear = function(form) {
+ var e;
+ for(i=0;i<form.length;i++) {
+ e = form.elements[i];
+ if (e.style.display == 'none') continue;
+ if (e.type != 'text') continue;
+ e.value = ''
+ }
+ };
+
+ this.debug = function(test) {
+ console.log(test);
+ };
+
+ this.get_http = function(url) {
+
+ var xhr_content='';
+ // try when from other domain, ex google cache
+ try {
+ var xhr;
+ if(document.all && !window.opera) { //Internet Explorer
+ xhr = new ActiveXObject("Microsoft.XMLHTTP") ;
+ //xhr = new ActiveXObject("Msxml2.XMLHTTP") ;
+ } else { //Mozilla
+ xhr = new XMLHttpRequest();
+ }
+ xhr.onreadystatechange = function() {};
+ xhr.open("GET", url, false);
+ xhr.send(null);
+ if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText;
+ }
+
+ catch (e) { console.log (e) }
+ return xhr_content;
+
+ };
+
+ this.str2a = function(elems,compact=true,class_exp_file='dir|path') {
+ $(elems).each(function(){
+
+ html = $(this).html();
+ if (html == '') return;
+
+ // Search /home
+ url = html
+ if (html.match(/^~/)) {
+ ua = navigator.userAgent
+ if (ua.match(/Macintosh/)) { url = url.replace(/^~/,'/Users/') }
+ else { url = url.replace(/^~/,'/home/') }
+ //console.log(url);
+ }
+
+ if (class_exp_file) {
+ var re = new RegExp(class_exp_file);
+ if (this.className.match(re) && !url.match(/^\w+:/)) url = 'file://'+encodeURI(url);
+ }
+
+ if (compact) html = html.replace(/^((?:\w+:\/+)?[^\/]+\/)(.*?)(\/?[^\/]+)$/,'$1..$3');
+
+ $(this).html('<a href="'+url+'" class="small" target="_blank">'+html+'</a>');
+
+ });
+
+ };
+
+};
+
+//NB.prototype.your_method = function() { }
+++ /dev/null
-/*!
- * NB JavaScript Library v0.0.0
- *
- * Date: 28.03.15
- */
-function NB() {
-
- this.form_submit_clean = function(f) {
- var i = 0;
- var msg = '';
- var url = '';
- msg += f.action + '\n';
-
- for(i=0;i<f.length;i++) {
- var p = f[i];
- if (!p.name) continue;
- if (p.value=='') continue;
- if (p.value=='undefined') continue;
- msg += p.name + '=' + p.value + '\n';
- // NB 02.09.13 url += (url ? '&' : '?') + escape(p.name) + '=' + escape(p.value);
- url += (url ? '&' : '?') + encodeURI(p.name) + '=' + encodeURI(p.value);
- }
-
- url = f.action + url;
-
- //document.location = url;
-
- /*
- if (izi_opt['test_version']) {
- html_msg(''
- + '<a href="#" onclick="window.location=\''+(url)+'\'; return false;">'
- + (url)
- + '</a>'
- );
- return false;
- }
- */
-
- //if (url == window.location) return false;
- window.location = url;
- return false;
- }
-
- this.form_clear = function(form) {
- var e;
- for(i=0;i<form.length;i++) {
- e = form.elements[i];
- if (e.style.display == 'none') continue;
- if (e.type != 'text') continue;
- e.value = ''
- }
- };
-
- this.debug = function(test) {
- console.log(test);
- };
-
- this.get_http = function(url) {
-
- var xhr_content='';
- // try when from other domain, ex google cache
- try {
- var xhr;
- if(document.all && !window.opera) { //Internet Explorer
- xhr = new ActiveXObject("Microsoft.XMLHTTP") ;
- //xhr = new ActiveXObject("Msxml2.XMLHTTP") ;
- } else { //Mozilla
- xhr = new XMLHttpRequest();
- }
- xhr.onreadystatechange = function() {};
- xhr.open("GET", url, false);
- xhr.send(null);
- if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText;
- }
-
- catch (e) { console.log (e) }
- return xhr_content;
-
- };
-
-};
-
-//NB.prototype.your_method = function() { }
require_once(dirname(__FILE__).'/db/table.php');
require_once(dirname(__FILE__).'/db/field.php');
if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS',''
- .'<input type="button" class="button" value="Add" onclick="window.location = \'?action=edit&table=\'+this.parentElement.elements[\'table\'].value"/>'
#.'<input type="button" class="button" value="Add" onclick="this.setAttribute(\'type\',\'submit\');this.setAttribute(\'name\',\'edit\')?1:1"/>'
#.'<input type="button" class="button" value="Add" onclick="this.setAttribute(\'name\',\'edit\');this.parentElement.submit()?0:0"/>'
#.'<input type="button" class="button" onclick="return nb.form_clear(this.parentElement)" value="X"/>'
- .'<a class="button" href="#" onclick="nb.form_clear(this.parentElement)?0:0">X</a>'
- .'<input type="submit" class="button" value="GO"/>'
+// NB 04.08.15 .'<a class="button form_clear" href="#" onclick="nb.form_clear(this.parentElement)?0:0">X</a>'
+ .'<span style="display:inline-block;">'
+ .'<input type="submit" class="button submit" value="GO"/>'
+ .'<input type="button" class="button table_add" value="Add" onclick="window.location = \'?action=edit&table=\'+this.parentElement.elements[\'table\'].value"/>'
+ .'</span>'
);
#if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT','<input type="submit" class="button" value="GO"/>');
#if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','<a class="button" href="?" onclick="nb.form_clear(this.parentElement) ? 0: 0">Add</a>');
function html_menu($table=null) {
- $html = ' onchange="this.parentElement.submit()"';
- $r = '<form class="db menu" method="get" action="" onsubmit="return nb.form_submit_clean(this)">'.PHP_EOL;
+ $r = '<form class="db menu" method="get" action="">'.PHP_EOL;
// Tables
- $r .= '<label>Tables</label>'.html_select_array($this->tables(),array(
- 'html' => 'class="tables" name="table"'.preg_replace('/"/','"nb.form_clear(this.parentElement);',$html,1),
+ $r .= '<label for="table">Tables</label>'.html_select_array($this->tables(),array(
+ 'html' => 'class="tables" name="table" id="table"',
'selected' => $this->p('table'),
'prettyText' => true,
));
// Format
- $r .= '<label>Format</label>'.html_select_array(array(
+ $r .= '<label for="format">Format</label>'.html_select_array(array(
'table','div','csv','xml','json','yaml'
),array(
- 'html' => 'class="format" name="format"'.$html,
+ 'html' => 'class="format" name="format" id="format"',
'selected' => $this->p('format'),
'prettyText' => true,
));
// Limit
- $r .= '<label>Limit</label>'.html_select_array(array(
+ $r .= '<label for="limit">Limit</label>'.html_select_array(array(
'10','20','50','100','500','1000'
),array(
- 'html' => 'class="limit" name="limit"'.$html,
+ 'html' => 'class="limit" name="limit" id="limit"',
'selected' => $this->p('table'),
'prettyText' => true,
));
$v = $this->p($k);
$r .= ''
- #.'<span class="i">'
+ .'<span class="label '.$k.'">'
. '<label>'.prettyText($k)
.'</label>'
. '<input type="text" id="'.$k.'" name="'.$k.'" value="'.$v.'" />'
- #.'</span>'
+ .'</span>'
;
}
#$r .= '<span class=""></span>';
}
+ $r .= ''
+ .'<input type="hidden" name="db" value="'.$this->p('db').'"/>'
+ .'<input type="hidden" name="debug" value="'.$this->p('debug').'"/>'
+ ;
+
// Bye
$r .= '</form>'.PHP_EOL;
return $r;
function html_edit($value) {
- $value = htmlspecialchars($value);
- return '<label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
+ return '<span class="label '.$this->name.'"><label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
.($this->extra
- ? "<span class=\"field.extra\">$value</span>"
+ ? '<span class="extra" id="'.$this->name.'">'.$this->out($value).'</span>'
: '<input name="'.$this->name.'" id="'.$this->name.'" value="'.$value.'" type="text"/>'
)
- .PHP_EOL;
+ .'</span>'.PHP_EOL;
}
function out($value,$html_escape=false) {
+ #if ($value === null) return '';
static $sqlite = null; if ($sqlite === null) $sqlite = $this->db()->type == 'sqlite';
- # Anoying !
+ # Anoying, sqlite does not format properly !
if ($sqlite and preg_match('/^float\((?:\d+,)?(\d+)\)/',$this->type,$m)) {
$value = sprintf('%.'.$m[1].'f',$value);
}
public $name;
public $db;
public $sql;
- public $fields = array();
- public $fields_keys = array();
+ public $fields = null;
+ public $fields_keys = null;
public $extras = array();
public $params = array(
'table',
*/
function fields($name=null) {
- if (!$this->fields) {
+ if ($this->fields === null) {
if ($this->db->type == 'sqlite') {
$sql = "PRAGMA table_info('$this->name')";
foreach ($rows as $row) {
+ $row = array_change_key_case($row,CASE_LOWER);
+
+ // Mysql field name
+ if (isset($row['field'])) {
+ $row['name'] = $row['field'];
+ unset($row['field']);
+ }
+
+#bye($row);
$field = array(
'name' => $row['name'],
'extra' => null,
# Autoincrement
# mysql autoincrement
- if (isset($row['Extra']) and $row['Extra'] == 'auto_increment') {
+ if (isset($row['extra']) and $row['extra'] == 'auto_increment') {
$field['autoincrement'] = true;
# sqlite autoincrement
$field['default'] = $row[$f];
}
- foreach (array('pk','Key') as $f) {
+ foreach (array('pk','key') as $f) {
if (!isset($row[$f])) continue;
$field['key'] = preg_match('/^1|yes|t/i',$row[$f]) ? 1 : 0;
}
- $this->fields[$row['name']] = new field($field);
+ $this->fields[$field['name']] = new field($field);
}
+ if (empty($this->fields)) bye($this->name." does not exists!");
}
+#bye($this->fields);
if ($name !== null ) {
if (!isset($this->fields[$name])) return null;
return $this->fields[$name];
;
}
+ if (($v = $this->db->p('db'))) $url[] = 'db='.$this->db->p('db');
return $url ? '?table='.$this->db->p('table').$sep.join($sep,$url) : '';
}
.'<div class="db buttons">'
.'<input type="submit"/>'
.'<input type="hidden" name="table" value="'.$this->db->p('table').'"/>'
- .'<input type="hidden" name="action" value="'.($add ? 'insert' : 'update').'"/>'
+ .'<input type="hidden" name="db" value="'.$this->db->p('db').'"/>'
+ .'<input type="hidden" name="debug" value="'.$this->db->p('debug').'"/>'
.'<input type="reset" />'
.( empty($_SERVER['HTTP_REFERER']) ? '' : '<input type="button" onclick="document.location=document.referrer" value="Cancel" />')
.'</div>'.PHP_EOL
}
function form_criterias($opt=array()) {
- // Legacy from sem - NB 25.07.15
+ // Legacy from sem - NB 25.07.15 !!!!!!!!!!!!!!!!!!!
echo '<form class="criteria" method="get" action="">'.PHP_EOL;
echo '<div class="small help">Use: '.join(' | ',$this->db->help_criterias).'</div>'.PHP_EOL;
$v = empty($_REQUEST[$k]) ? '' : $_REQUEST[$k];
$criteria[] = ''
- . '<label>'.prettyText($k).':</label>'
+ .'<span class="label '.$k.'">'
+ . '<label for="'.$k.'">'.prettyText($k).':</label>'
. '<input type="text" id="'.$k.'" name="'.$k.'" value="'.$v.'" />'
+ .'</span>'
;
}
if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format) ? true : false;
$escape = preg_match('/^(table|row|xml)$/',$format) ? true : false;
- if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($opt);
+ if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($this->fields());
$count = 0;
while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
$count_fields = 0;
foreach ($this->fields() as $f => $field) {
+ #foreach ($row as $f => $value) {
+ #$field = $this->fields($f);
#echo '<pre>'; var_dump($field); echo '</pre>';
+#bye(array($field,$row));
$row[$f] = $field->out($row[$f]);
// NB 02.08.15 if ($escape and empty($this->extra)) $row[$f] = htmlspecialchars($row[$f]);
/*-----------------------------------------------------------------
Csv
-----------------------------------------------------------------*/
- function rows_begin_csv() {
- return join("\t",array_keys($this->fields()))."\n";
+ function rows_begin_csv($fields) {
+ return join("\t",array_keys($fields))."\n";
}
function rows_rec_csv($row) {
foreach ($row as $k => $v) {
$html .= '<li>'
.( $k == '0' ? '' : '<label>'.prettyText($k).'</label>')
- .'<span>'.$v.'</span>'
+ .'<span class="'.$k.'">'.$v.'</span>'
.'</li>';
}
class Page {
public $call = array();
- public $output = '';
+# NB 04.08.15 wtf ??? public $output;
public $charset = 'utf-8';
public $content_type = 'text/html';
public $js = array();
public $js_code = '';
- public $body_class;
- public $body_id;
+ public $body_class = '';
+ public $body_id = '';
+
+ public $h1 = '';
/*
Create
}
// Defaults
- if ( ! isset($opt['title']) )
- #$this->title = $GLOBALS['argv'][0]
- $this->title = $this->filename2title();
- #bye($this->title);
- #$this->title = preg_replace('@^.*?([^/\.]+)[^/]*@','\1',$_SERVER['SCRIPT_NAME']);
- #die( $this->title);
- ;
+ if ( empty($this->title) ) $this->title = $this->filename2title();
//// Default
#print_r($this);
function filename2title() {
$str = '';
+ #$this->title = $GLOBALS['argv'][0]
if (isset($_SERVER['REQUEST_URI'])) $str = preg_replace('/\?.*$/','',preg_replace(',^.*?([^/]+)(\/?.*)?$,','\1',$_SERVER['REQUEST_URI']));
if ($str == '' or $str == '/') $str = preg_replace('@^.*?([^/\.]+)(/index)?(\..*?)$@','\1',$_SERVER['SCRIPT_NAME']);
$str = preg_replace('@[\'_-]+$@',' ',$str);
return htmlspecialchars($v,$replace_flags,$charset);
}
- function tag($content='',$tag,$attrs='') {
+# NB 04.08.15 function tag($content='',$tag,$attrs='') {
+ function tag($tag,$content='',$attrs='') {
if (!is_array($content)) $content = array($content);
$tags = array();
.(empty($this->body_class) ? '' : ' class="'.$this->body_class.'"')
.(empty($this->body_id) ? '' : ' id="'.$this->body_id.'"')
.'>' . PHP_EOL;
- if ($this->title) echo $this->tag($this->title,'h1').PHP_EOL;
+
+ if ($this->h1) echo $this->tag('h1',$this->h1).PHP_EOL;
+ elseif ($this->title) echo $this->tag('h1',$this->title).PHP_EOL;
}
}
$head .= '<head>'.PHP_EOL;
#$head .= '</head>'.PHP_EOL; return $head;
- if ($this->title) $head .= $this->tag($this->title,'title') . PHP_EOL;
+ if ($this->title) $head .= $this->tag('title',$this->title) . PHP_EOL;
if ($this->charset) $head .= '<meta http-equiv="Content-Type" content="text/html; charset='.$this->charset.'" />'.PHP_EOL;
if (preg_match('/tml$/',$this->content_type)) {
die("Db->is(): unknow argument '$is'. Accepted values are xhtml, html, xml");
}
+ function path() {
+ return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
+ }
+
} return;
?>