options:
- "PDO::MYSQL_ATTR_INIT_COMMAND: SET NAMES utf8'"
+ui-mem:
+ pdo: 'sqlite:/dev/shm/semantico.db'
+ _conf2h_copy: ui
+
ui:
pdo: 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db'
title: 'Semantico UI'
}
- this.resize = function() {
+ this.wh = function(s) {
+ var item = $(s);
+ if (!item) return [0,0]
+
+ var width = item.width();
+ var height = item.height();
+
+ /*
+ */
+ width -= $(item).css('paddingLeft').replace(/px/,'');
+ width -= $(item).css('paddingRight').replace(/px/,'');
+ height -= $(item).css('paddingTop').replace(/px/,'');
+ height -= $(item).css('paddingBottom').replace(/px/,'');
+
+ width -= $(item).css('marginLeft').replace(/px/,'');
+ width -= $(item).css('marginRight').replace(/px/,'');
+ height -= $(item).css('marginTop').replace(/px/,'');
+ height -= $(item).css('marginBottom').replace(/px/,'');
+ //console.log(width+'/'+height);
+ return [parseInt(width),parseInt(height)];
+ }
- // table to div
- if ($('#_responsive').css('content') != 'none') {
- that.table2div('table.rows');
- return true;
- } else {
- $('table.rows').addClass('t2d');
- $('.t2d-th').each(function(){
- $(this).remove();
- });
+ this.maxhw = function(s) {
+ var height = $('body').height();
+ var width = $(window).width();
+
+ /*
+ var prev = $(s).prev();
+ for (var i=0;i<50 && prev;i++) {
+ prev = $(prev).prev();
+ if (prev) {
+ try {
+ height -= that.wh(prev)[1];
+ } catch (e) {
+ prev = undefined;
+ break;
+ }
+ }
}
+ */
+//console.log('total: '+width+'/'+height);
+
+ //if (prev) height -= that.wh(prev)[1];
+ //if (prev) height -= $(prev).height();
+ $(s).each(function(){
+ w = width;// - that.wh(this)[0];
+ h = height;// - that.wh(this)[1];
+ //if ($(this).height() > h) $(this).height(h);
+ //if ($(this).width() > w) $(this).width(w);
+//$(this).css('border','solid 1px red');
+ $(this).height(h); $(this).width(w);
+ /*
+ if (1 || $(this).height() > h || $(this).width() > w) $(this).css({
+ //'display': 'block',
+ 'overflow': 'scroll',
+ 'border': 'solid 2px blue',
+ });
+ */
+//console.log(w+'/'+h);
+ });
+ }
- // Max width for blocks
- var block = $("table, div");
+ this.maxhw_resize = function(s) {
+ var block = $(s);
if (!block) return false;
- var width = $(window).width();
+ var width = $('body').width();
var set_width = width - 20;
block.each(function(){
var first_width = $(this).attr('nb-resize');
var cur_width = $(this).width();
+//$(this).css({ 'border': 'solid 1px yellow', });
if (cur_width > width) {
if (!first_width) {
$(this).attr('nb-resize',cur_width);
}
+ this.resize = function() {
+
+ // table to div
+ if ($('#_responsive').css('content') != 'none') {
+ that.table2div('table.rows');
+ return true;
+ } else {
+ $('table.rows').addClass('t2d');
+ $('.t2d-th').each(function(){ $(this).remove(); });
+ }
+
+ // Max width for blocks
+ that.maxhw_resize('table, div');
+ }
+
this.table2div = function(find) {
var th = []
exit;
*/
-function __f1(&$ar) { $v=$ar; return; foreach ($ar as $v) { 1; } }
+#function __f1(&$ar) { $v=$ar; return; foreach ($ar as $v) { 1; } }
+function __f1(&$ar) { return; foreach ($ar as $v) { 1; } }
function __f2($ar) { return; foreach ($ar as $v) { 1; } }
$array = array_fill(0,100000,"a");
#if (function_exists('__f1')) { function _f1() { __f1($array); } nb::benchmark('_f1'); }
#if (function_exists('__f2')) { function _f2() { __f2($array); } nb::benchmark('_f2'); }
-function _f1() { file_exists('/tm'); } nb::benchmark('_f1');
-function _f2() { echo ''; } nb::benchmark('_f2');
+function _f1() { ini_set('display_errors', 'On'); } nb::benchmark('_f1');
+function _f2() { ; } nb::benchmark('_f2');
nb::benchmark(); exit;
*/
date_default_timezone_set('Europe/London');
-ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT | E_NOTICE);
# NB 05.03.16 ini_set('include_path', realpath(dirname(__FILE__).'/../lib').':'.realpath(dirname(__FILE__)).':'.ini_get('include_path'));
#define('NB_EOL','');
#define('NB_PROD',true);
-require_once('nb.php');
+include('nb.php');
if (nb::php_cli()) argv2request();
+
+ini_set('display_errors', 'On');
+if (nb::php_cli() or nb::p('txt_errors')) ini_set('html_errors', false);
?>
require_once(dirname(__FILE__).'/out.php');
require_once(dirname(__FILE__).'/db/table.php');
require_once('out.php');
-if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS',''
- #.'<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"/>'
-// NB 04.08.15 .'<a class="button form_clear" href="#" onclick="nb.form_clear(this.parentElement)?0:0">X</a>'
- .'<span class="buttons">'
- .'<input type="submit" class="button submit" value="GO"/>'
- .'<input type="button" class="button table_add" value="Add" onclick="window.location = \'?action=edit&table=\'+$(\'#table\').val()"/>'
- .'</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>');
-#if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','<input type="submit" class="button" value="Add" onclick="this.setAttribute(\'name\',\'edit\')?0:0"/>');
$DB_TYPES = array(
'tables' => array(
return $mime;
}
- function html_menu($table=null) {
-
- $r = '<form class="db menu" method="get" action="?">'.NB_EOL;
-
- // Criterias
- if (!empty($table)) {
- $r .= '<div class="criterias">';
- foreach ( array_keys($table->fields()) as $k ) {
-
- $v = $this->p($k);
-
- $r .= ''
- .'<span class="label '.$k.'">'
- . '<label>'.prettyText($k)
- .'</label>'
- . '<input type="text" id="'.$k.'" name="'.$k.'" value="'.$v.'" />'
- .'</span>'
- ;
-
- }
- $r .= '</div>';
- #$r .= '<span class=""></span>';
- }
-
- //
- // Hiddens
- //
- foreach (array(
- 'db',
- 'debug',
- ) as $v) {
- $r .= '<input type="hidden" name="'.$v.'" value="'.$this->p($v).'"/>';
- }
-
- //
- // Options
- //
- $r .= '<div class="options">';
-
- // Tables
- $r .= '<span class="label">';
- $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,
- ));
- $r .= '</span>';
-
- // Format
- $r .= '<span class="label">';
-
- #$criteria[] = html_select_array(ar_map('array($a == "html" ? "" : $a,strtoupper($a))',$this->formats));
-# NB 01.03.16 $r .= '<label for="format">Format</label>'.html_select_array(array(
-# NB 01.03.16 'table','div','csv','xml','json','yaml'
- $r .= '<label for="format">Format</label>'.html_select_array($this->formats,array(
- 'html' => 'class="format" name="format" id="format"',
- 'selected' => $this->p('format'),
- 'prettyText' => true,
- ));
- $r .= '</span>';
-
- // Limit
- if (!empty($this->limits)) {
- $r .= '<span class="label">';
- $r .= '<label for="limit">Limit</label>'.html_select_array($this->limits,array(
- 'html' => 'class="limit" name="limit" id="limit"',
- 'selected' => $this->p('limit'),
- 'prettyText' => true,
- ));
- $r .= '</span>';
- }
-
- // Dbs
- if (!empty($this->dbs) and count($this->dbs)>1) {
- $r .= '<span class="label">';
- $r .= '<label for="db">Db</label>'.html_select_array($this->dbs,array(
- 'html' => 'class="dbs" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
- 'selected' => $this->name,
- 'prettyText' => true,
- ));
- $r .= '</span>';
- }
-
- // Buttons
- $r .= DB_HTML_FORM_BUTTONS;
-
- $r .= '</div>';
-
- ///
- // Bye
- ///
- $r .= '</form>'.NB_EOL;
- return $r;
- }
-
function sql_name($value) {
if ($this->type == 'mysql') return '`'.$value.'`';
return '"'.$value.'"';
* @param [FILES] $files Files to load
* @return ARRAY the new/existing value of $this->db
*/
- static function config2h ($files=array(),&$first=false) {
+ static function conf2h ($files=array(),&$first=false) {
if (empty($files)) return array();
if (!empty($files)) {
$h = array();
foreach ($files as $file) {
- if (is_readable($file) and ($yaml = @yaml_parse_file($file))) {
- #foreach ($yaml as $k=>$v) { $yaml[$k]['_config2h'] = $file; }
+ if (is_readable($file) and ($yaml = yaml_parse_file($file))) {
+ #foreach ($yaml as $k=>$v) { $yaml[$k]['_conf2h'] = $file; }
#debug($file);
$h = array_replace_recursive($h,$yaml);
}
#debug($file);
#if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml)
;
- unset($yaml);
#}
}
- #debug($h);
+ unset($yaml);
+
+ # Emulate hash pointer
+ foreach ($h as $db=>$o) {
+ foreach ($o as $k => $v) {
+ if ($k != '_conf2h_copy') continue;
+
+ foreach ($h[$v] as $kk => $vv) {
+ if (!isset($o[$kk])) $h[$db][$kk] = $vv;
+ }
+ unset($h[$db][$k]);
+ #bye($h[$db]);
+
+ }
+ }
+
}
if (!$h) return false;
#self::bye($h['puppetdb']);
$Db = new self();
#bye($_SERVER["PHP_SELF"]); bye($_SERVER);
- if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml';
- if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml';
+# NB 19.03.16 if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml';
+# NB 19.03.16 if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml';
# Load databases
- if (! ($dbs = $Db->config2h($conf)) ) return false;
-
- # Param - Extract dbname from table
- if (preg_match('/^(\w+)\.(.*?)$/',$Db->p('table'),$m)) {
- $Db->pset('db',$m[1]);
- $Db->pset('table',$m[2]);
- }
+ if (! ($dbs = $Db->conf2h($conf)) ) return false;
#die (nb::p('db'));
# Param - Default base on order hight num value
$Db->pset('db',$Db->ar_first($dbs,true));
}
- # Param - correction / aliases
- if (($format=$Db->p('format'))) {
- }
-
# Connection
#bye($Db->p('db'));
if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
if (empty($Db)) return false;
if (!$Db->p('table') and isset($Db->default_table)) $Db->pset('table',$Db->default_table);
if (!$Db->p('table') and ($v = $Db->tables())) $Db->pset('table',$Db->ar_first($v));
- if (!$Db->p('table')) return;
# NB 10.01.16 $Table = new table($Db->p('table'),array('db' => $Db));
- $Table = $Db->table($Db->p('table'));
+ if ($Db->p('table')) $Table = $Db->table($Db->p('table'));
return true;
require_once(dirname(__FILE__).'/../config.php');
require_once(dirname(__FILE__).'/../db.php');
-Db::init(array( '/etc/dbs.yaml' ));
+# Param - Extract dbname from table
+if (preg_match('/^(\w+)\.(.*?)$/',Db::p('table'),$m)) {
+ Db::pset('db',$m[1]);
+ Db::pset('table',$m[2]);
+}
+Db::init(array( nb::$root_dir.'/etc/dbs.yaml','/etc/dbs.yaml' ));
if( defined('DB_JUST_INIT')) return true;
return $Db->action($Table);
foreach (array_merge( $this->params, array_keys($fields) ) as $f) {
- if (@strcmp($this->p($f),'')==0) continue;
+ if (strcmp($this->p($f,''),'')==0) continue;
$params[$f] = $this->p($f);
}
$st->execute();
if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format)
- ? ( $this->p('header')!=="0" and $this->p('inc')!=="1")
+ ? (
+ $this->p('header')!=="0"
+ #and $this->p('download')!=="1"
+ )
: false
;
} elseif ($action == 'table.count') { return $this->out2($this->count(),'count');
} elseif ($action == 'table.rows' or $action == 'rows') {
- #if ($this->p('page')==='0') $this->pset('inc',1);
$this->db->print_header($this->p('format'));
$this->rows(); return true;
return true;
} elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) {
- #} elseif ($action == 'table' and $this->p('format') and $this->p('table')) {
- #} elseif ($is_html) {
$this->rows(array( 'format' => $this->p('format')));
return true;
) as $v) {
$r .= '<input type="hidden" name="'.$v.'" value="'.$this->p($v).'"/>';
}
- $r .= '<input type="hidden" name="inc" value="0"/>'; // Embed for no html format
+ $r .= '<input type="hidden" name="download" value="0"/>'; // Embed for no html format
//
// Options
$msg = $preff_msg.$msg;
}
- nb::msg( !nb::php_cli()
+ #nb::msg( !nb::php_cli()
+ nb::msg( preg_match('/ml/i',nb::get_header('Content-type'))
? '<pre'
.' class="err'. ( ($preff and $preff!='err') ? " $preff" : '' ).'"'
.'>'.$msg.'</pre>'.NB_EOL
);
public static $content_types = array(
- 'json' => 'application/json',
+ 'json' => 'text/json',
'doc' => 'application/msword',
'xls' => 'application/vnd.ms-excel',
'xml' => 'application/xml',
return prettyText($text);
}
+ public static function mime2ext($mime) {
+
+ static $aliases = null; if ($aliases === null) $aliases = array_combine(array_values(self::$content_types_aliases),array_keys(self::$content_types_aliases));
+ #static $v = array_combine(array_values(self::$content_types_aliases),array_keys(self::$content_types_aliases));
+ foreach (self::$content_types as $e => $c) {
+ if ($mime == $c) return $e;
+ }
+
+ // Aliases
+ if (isset($aliases[$ext])) return self::ext2mime($aliases[$ext]);
+
+ }
+
/*
- * Function: prettyText
+ * Function: ext2mime
* Does what it says
*/
+ #public static function ext2content_type($ext) { return self::ext2mime($ext); }
public static function ext2mime($ext) {
foreach (self::$content_types as $e => $c) {
return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
}
+ public static function no_accent($str){
+ return strtr($str,array(
+'À' => 'A',
+'Á' => 'A',
+'Â' => 'A',
+'Ã' => 'A',
+'Ä' => 'A',
+'Å' => 'A',
+'à' => 'a',
+'á' => 'a',
+'â' => 'a',
+'ã' => 'a',
+'ä' => 'a',
+'å' => 'a',
+'Ā' => 'A',
+'ā' => 'a',
+'Ă' => 'A',
+'ă' => 'a',
+'Ą' => 'A',
+'ą' => 'a',
+'Ç' => 'C',
+'ç' => 'c',
+'Ć' => 'C',
+'ć' => 'c',
+'Ĉ' => 'C',
+'ĉ' => 'c',
+'Ċ' => 'C',
+'ċ' => 'c',
+'Č' => 'C',
+'č' => 'c',
+'Ð' => 'D',
+'ð' => 'd',
+'Ď' => 'D',
+'ď' => 'd',
+'Đ' => 'D',
+'đ' => 'd',
+'È' => 'E',
+'É' => 'E',
+'Ê' => 'E',
+'Ë' => 'E',
+'è' => 'e',
+'é' => 'e',
+'ê' => 'e',
+'ë' => 'e',
+'Ē' => 'E',
+'ē' => 'e',
+'Ĕ' => 'E',
+'ĕ' => 'e',
+'Ė' => 'E',
+'ė' => 'e',
+'Ę' => 'E',
+'ę' => 'e',
+'Ě' => 'E',
+'ě' => 'e',
+'Ĝ' => 'G',
+'ĝ' => 'g',
+'Ğ' => 'G',
+'ğ' => 'g',
+'Ġ' => 'G',
+'ġ' => 'g',
+'Ģ' => 'G',
+'ģ' => 'g',
+'Ĥ' => 'H',
+'ĥ' => 'h',
+'Ħ' => 'H',
+'ħ' => 'h',
+'Ì' => 'I',
+'Í' => 'I',
+'Î' => 'I',
+'Ï' => 'I',
+'ì' => 'i',
+'í' => 'i',
+'î' => 'i',
+'ï' => 'i',
+'Ĩ' => 'I',
+'ĩ' => 'i',
+'Ī' => 'I',
+'ī' => 'i',
+'Ĭ' => 'I',
+'ĭ' => 'i',
+'Į' => 'I',
+'į' => 'i',
+'İ' => 'I',
+'ı' => 'i',
+'Ĵ' => 'J',
+'ĵ' => 'j',
+'Ķ' => 'K',
+'ķ' => 'k',
+'ĸ' => 'k',
+'Ĺ' => 'L',
+'ĺ' => 'l',
+'Ļ' => 'L',
+'ļ' => 'l',
+'Ľ' => 'L',
+'ľ' => 'l',
+'Ŀ' => 'L',
+'ŀ' => 'l',
+'Ł' => 'L',
+'ł' => 'l',
+'Ñ' => 'N',
+'ñ' => 'n',
+'Ń' => 'N',
+'ń' => 'n',
+'Ņ' => 'N',
+'ņ' => 'n',
+'Ň' => 'N',
+'ň' => 'n',
+'ʼn' => 'n',
+'Ŋ' => 'N',
+'ŋ' => 'n',
+'Ò' => 'O',
+'Ó' => 'O',
+'Ô' => 'O',
+'Õ' => 'O',
+'Ö' => 'O',
+'Ø' => 'O',
+'ò' => 'o',
+'ó' => 'o',
+'ô' => 'o',
+'õ' => 'o',
+'ö' => 'o',
+'ø' => 'o',
+'Ō' => 'O',
+'ō' => 'o',
+'Ŏ' => 'O',
+'ŏ' => 'o',
+'Ő' => 'O',
+'ő' => 'o',
+'Ŕ' => 'R',
+'ŕ' => 'r',
+'Ŗ' => 'R',
+'ŗ' => 'r',
+'Ř' => 'R',
+'ř' => 'r',
+'Ś' => 'S',
+'ś' => 's',
+'Ŝ' => 'S',
+'ŝ' => 's',
+'Ş' => 'S',
+'ş' => 's',
+'Š' => 'S',
+'š' => 's',
+'ſ' => 's',
+'Ţ' => 'T',
+'ţ' => 't',
+'Ť' => 'T',
+'ť' => 't',
+'Ŧ' => 'T',
+'ŧ' => 't',
+'Ù' => 'U',
+'Ú' => 'U',
+'Û' => 'U',
+'Ü' => 'U',
+'ù' => 'u',
+'ú' => 'u',
+'û' => 'u',
+'ü' => 'u',
+'Ũ' => 'U',
+'ũ' => 'u',
+'Ū' => 'U',
+'ū' => 'u',
+'Ŭ' => 'U',
+'ŭ' => 'u',
+'Ů' => 'U',
+'ů' => 'u',
+'Ű' => 'U',
+'ű' => 'u',
+'Ų' => 'U',
+'ų' => 'u',
+'Ŵ' => 'W',
+'ŵ' => 'w',
+'Ý' => 'Y',
+'ý' => 'y',
+'ÿ' => 'y',
+'Ŷ' => 'Y',
+'ŷ' => 'y',
+'Ÿ' => 'Y',
+'Ź' => 'Z',
+'ź' => 'z',
+'Ż' => 'Z',
+'ż' => 'z',
+'Ž' => 'Z',
+'ž' => 'z'
+ ));
+ }
} # < Class
#die(self::ext2mime('csv'));
?>
return (is_array($v) ? $v : array($v));
}
- function filename2title() {
+ public static function title2filename($title,$content_type='') {
+ $ext = $content_type ? self::mime2ext($content_type) : '';
+ $title = self::no_accent($title);
+ $title = preg_replace('/\W+/','_',$title);
+ if ($ext) $title .= '.'.$ext;
+ return $title;
+ }
+
+ public function filename2title() {
$str = '';
#$this->title = $GLOBALS['argv'][0]
if (isset($_SERVER['REQUEST_URI'])) $str = preg_replace('/\?.*$/','',preg_replace(',^.*?([^/]+)(\/?.*)?$,','\1',$_SERVER['REQUEST_URI']));
$c = strtoupper ( $this->charset );
# NB 19.08.15 $this->header('Content-type: ',$this->content_type . ($c ? "; charset=$c" : ""));
header('Content-type: '.$this->content_type . ($c ? "; charset=$c" : ""));
+ if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
+ . $this->title2filename($this->title,$this->content_type)
+ );
return true;
}