/*
*/
$CONF = array (
- 'rent' => array (
- 'order' => 1,
- 'pdo' => 'sqlite:/opt/rent/rent.db',
- 'title' => 'Rent',
- 'notice' => 'Micro foncier 4BE',
- 'default_table' => 'rent',
- 'tables' => array (
- 'place' => array (
- 'replace' => array (
- 'id' => 'addr.addr',
- ),
- ),
- 'rent' => array (
- 'order_by' => 'start desc',
- 'replace' => array (
- 'idtenant' => 'tenant.name',
- 'idplace' => 'addr.addr',
- ),
- 'extras' => array (
- 'total' => array (
- 'type' => 'float(8,2)',
- 'extra' => 'ROUND(rent+charge,2)',
- ),
- 'rent_year' => array (
- 'type' => 'float(8,2)',
- 'extra' => 'rent * (1 + ( strftime(\'%m\',end)+12*strftime(\'%Y\',end) ) - ( strftime(\'%m\',start)+12*strftime(\'%Y\',start) ))',
- ),
- ),
- ),
- ),
- 'name' => 'rent',
- ),
- 'ui-mem' => array (
- 'pdo' => 'sqlite:/dev/shm/semantico.db',
- 'title' => 'Semantico UI',
- 'default_table' => 'node',
- 'tables' => array (
- 'node' => array (
- 'order_by' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
- 'replace_' => array (
- 'iddc' => 'dc.id',
- ),
- ),
- ),
- 'replace' => array (
- 'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
- ),
- 'name' => 'ui-mem',
- ),
- 'rt' => array (
- 'pdo' => 'pgsql:host=db.rt.semantico.net;port=5432;dbname=rtdb;user=rtuser;password=',
- 'title' => 'RT',
- 'password' => 'scrubchug',
- 'name' => 'rt',
- ),
- 'ui' => array (
- 'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db',
- 'title' => 'Semantico UI',
- 'default_table' => 'node',
- 'tables' => array (
- 'node' => array (
- 'order_by' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
- 'replace_' => array (
- 'iddc' => 'dc.id',
- ),
- ),
- ),
- 'replace' => array (
- 'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
- ),
- 'name' => 'ui',
- ),
- 'postfix' => array (
- 'title' => 'Postfix on Izideal',
- 'host' => 'media.izideal.vpn',
- 'user' => 'postfix',
- 'password' => 'dx7d50nfs',
- 'type' => 'mysql',
- 'name' => 'postfix',
- ),
- 'izidev' => array (
- 'host' => 'big.cascais.loc',
- 'title' => 'Mysql Izi on Big',
- 'password' => 'mpc60ax73',
- 'default_table' => 'process',
- 'user' => 'nico',
- 'name' => 'izi',
- 'tables' => array (
- 'site' => array (
- 'replace' => array (
- 'idlang' => 'lang.id',
- ),
- ),
- ),
- 'type' => 'mysql',
- ),
- 'wp' => array (
- 'host' => 'admin.izideal.vpn',
- 'user' => 'nico',
- 'password' => 'mpc60ax73',
- 'type' => 'mysql',
- 'name' => 'wp',
- ),
'nb' => array (
'host' => 'admin.izideal.vpn',
'user' => 'nico',
'idtenant' => 'tenant.name',
'idplace' => 'addr.addr',
),
- 'columns' => array (
- 'total' => function(&$r) {$r['rent'] + $r['charge'];}
- ),
+ 'call_rows' => function(&$r) {
+ if (0) $r['rent_year'] = $r['rent'] * (1 +
+ ( date('m',$r['end'])+12*date('Y',strtotime($r['end'])) )
+ -
+ ( date('m',$r['start'])+12*date('Y',strtotime($r['start'])) )
+ );
+ #extra: "rent * (1 + ( strftime('%m',end)+12*strftime('%Y',end) ) - ( strftime('%m',start)+12*strftime('%Y',start) ))"
+ #$r['rent_year'] = $r['rent'] * (1 + ( date('m',strtotime($r['end']))+12
+ $r['Total'] = $r['rent'] + $r['charge'];
+ }
),
),
),
- 'puppetdb' => array (
- 'title' => 'Puppetdb',
- 'host' => 'big',
- 'type' => 'pgsql',
- 'user' => 'puppetdb',
- 'default_table' => 'view_hosts',
- 'tables' => array (
- 'hosts' => array (
- 'extras' => array (
- 'last_compile' => array (
- 'type' => 'text',
- 'extra' => 'to_char(hosts.last_compile, \'YYYY-MM-DD HH:mm:ss\'::text)',
- ),
- 'last_freshcheck' => array (
- 'type' => 'text',
- 'extra' => 'to_char(hosts.last_freshcheck, \'YYYY-MM-DD HH:mm:ss\'::text)',
- ),
- 'updated_at' => array (
- 'type' => 'text',
- 'extra' => 'to_char(hosts.updated_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
- ),
- 'created_at' => array (
- 'type' => 'text',
- 'extra' => 'to_char(hosts.created_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
- ),
- 'test' => array (
- 'type' => 'int',
- 'extra' => 1,
- ),
- ),
- ),
- ),
- 'password' => 'puppetdb6073/!',
- 'name' => 'puppetdb',
- ),
- 'izi' => array (
- 'title' => 'Mysql Izi on Admin',
- 'default_table' => 'process',
- 'host' => 'admin.izideal.vpn',
- 'user' => 'izideal',
- 'name' => 'izi',
- 'tables' => array (
- 'site' => array (
- 'replace' => array (
- 'idlang' => 'lang.id',
- ),
- ),
- ),
- 'password' => 'dx7d50nfs',
- 'type' => 'mysql',
- ),
- 'crypt' => array (
- 'pdo' => 'sqlite:/dev/shm/crypt.db',
- 'name' => 'crypt',
- ),
);
?>
$('<p>'+msg+'</p>').prependTo( "#nb-msg" );
}
+ this.reload_head_js = function() {
+ $("head script").each(function(){
+ var oldScript = this.getAttribute("src");
+ $(this).remove();
+ var newScript;
+ newScript = document.createElement('script');
+ newScript.type = 'text/javascript';
+ newScript.src = oldScript;
+ document.getElementsByTagName("head")[0].appendChild(newScript);
+ });
+ }
+
};
/*
Statics
*/
+NB.reload_head_js = NB.prototype.reload_head_js
NB.get_http = NB.prototype.get_http
NB.dump = NB.prototype.dump
NB.urlParam = NB.prototype.urlParam
$h = array_replace_recursive($h,$yaml);
} elseif (preg_match('/\.php$/i',$file)) {
- #global $VAR1;
- require($file);
- if (!empty($CONF)) $h = $CONF;
+ #global $CONF;
+ require($file); if (!empty($CONF)) $h = array_replace_recursive($h,$CONF);
}
class field {
private $table;
public $name;
- public $type = 'text';
+ #public $type = 'text';
+ public $type;
public $null = true;
public $key = false;
+ #public $value;
public $default;
- public $autoincrement = false;
+ public $autoincrement;
public $extra;
public function __sleep() { return array(
}
public function numeric() {
- return preg_match('/int|float|number|currency/',$this->type) ? true : false;
+ return preg_match('/signed|(snall )?int|float|decimal|numeric|number|currency/i',$this->type) ? true : false;
+ }
+
+ public function html_type() {
+ # See: http://www.w3schools.com/html/html_form_input_types.asp
+ if (strpos($this->name,'password') !== false) return 'password';
+ if ($this->numeric() !== false) return 'number';
+ return 'text';
+ # Html5 only
+ if (strpos($this->name,'email') !== false) return 'email'; # no safari
+ if (strpos($this->name,'color') !== false) return 'color'; # no safari, no ie
+ # NOT READY
+ if (strpos($this->type,'datetime') !== false) return 'datetime';
+ if (strpos($this->type,'time') !== false) return 'time';
+ if (strpos($this->type,'date') !== false) return 'date';
}
public function html_edit($value) {
return '<div class="label '.$this->name.'"><label for="'.$this->name.'">'.htmlspecialchars(prettyText($this->name)).'</label>'
.($this->extra
? '<span class="extra" id="'.$this->name.'">'.$this->out($value).'</span>'
- : '<input name="'.$this->name.'" id="'.$this->name.'" value="'.$value.'" type="text"/>'
+ : '<input'
+ .' name="'.$this->name.'"'
+ .' id="'.$this->name.'"'
+ .' value="'.$value.'"'
+ .($size=$this->size() and is_scalar($size) ? ' size="'.$size.'"' : '')
+ .' type="'.$this->html_type().'"'
+ .'/>'
)
.'</div>'.NB_EOL;
public function size() {
if (! preg_match('/\((\d+)(?:,(\d+)\))?/',$this->type,$m) ) return null;
array_shift($m);
+#debug($m);
return count($m) == 1 ? $m[0] : $m;
// NB 02.08.15 return preg_match('/\((\d+)\)/',$this->type,$m) ? $m[1] : null;
}
# See: http://php.net/manual/en/pdostatement.bindparam.php
if ($name === null) $name = ':'.$this->name;
#debug($this->name . " | $name | $value | $this->type | " . $this->size()."<br/>");
- return $sth->bindParam($name, $value, $this->type2pdo($value), $this->size());
+ if (strpos($this->type,'float') !== false) {
+ $value = strval($value);
+ return $sth->bindParam($name, $value, PDO::PARAM_STR);
+ }
+ return $sth->bindParam($name, $value, $this->type2pdo($this->type), $this->size());
// NB 27.07.15 return $sth->bindParam($name, $value, $this->type2pdo($value));
}
# NB 28.03.16 public $fields_keys;
public $replace = array(); # replace by javascript
public $extras = array();
+ public $call_rows; # Function to call in rows()
public $count;
public $engine;
public $created;
$opt = $name;
#$name = $opt['name'];
$name = isset($opt['name']) ? $opt['name'] : '';
- if (!empty($opt['name'])) $this->name = $opt['name'];
-
- } elseif(!empty($name)) {
- $this->name = $name;
}
+ if(!empty($name)) $opt['name'] = $this->name = $name;
+ #debug($opt);
+
#unset($opt['db']); bye($opt);
// Extras - We dont want to affect $this
#$temp = '_'.substr(md5($this->name),0,6);
$temp = DB_TABLE_QUERY_NAME;
#bye("CREATE TEMPORARY VIEW $temp AS $this->name");
- $this->db()->conn->query("CREATE TEMPORARY VIEW $temp AS $this->name");
+ $this->db()->conn->query("CREATE TEMPORARY TABLE $temp AS $this->name");
$this->name = $temp;
} elseif (preg_match('/\b(\.import|LOAD DATA|COPY|INSERT|REPLACE|DELETE|TRUNCATE|CREATE|DROP|ALERT)\b/',$this->name)) {
public function html_edit($values = null) {
if ($values === null) $values = $this->p();
if (!is_array($values)) $values = array($values);
+ $fields = array_filter($this->fields(),function($v){return empty($v->extra);});
+ #$fields = $this->fields();
+ #debug($fields);
$add = false;
- $where = $this->where($this->fields(),$values);
+ $where = $this->where($fields,$values);
if (empty($where)) {
$where = ' WHERE 1=0';
$add = true;
if ( $add or ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))) {
$count ++;
- foreach ($this->fields() as $name => $field) {
+ foreach ($fields as $name => $field) {
if ($add and !preg_match('/^(null)?$/',$field->default)) $row[$name] = $field->default;
elseif(!isset($row[$name])) $row[$name] = '';
echo $field->html_edit($row[$name]
$st->execute();
# Fields
+ $fields = array();
if (!DB_TABLE_QUERY_NAME) {
- $fields = array();
foreach ($this->db()->fields($st) as $f) { $fields[$f->name] = $f; }
$this->fields = $fields;
}
$count++;
+ if (!empty($this->call_rows)) {
+ $call = $this->call_rows; $call($row);
+ }
+
if ($opt['is_html'] and !$out_conf) {
foreach ($row as $k=>$v) {
if (!isset($this->extras[$k])) $row[$k] = out::format($v);
if ($count === 1) {
if ($opt['is_html']) echo $this->html_rows_top();
+ if ($this->call_rows) {
+ foreach (array_keys($row) as $name) {
+ if (!$this->fields($name)) {
+ $this->fields[$name] = new Field($name);
+ $this->call = true;
+ #$fields[$name] = $this->fields[$name];
+ }
+ }
+ }
+
if ($out_conf) {
out::head($out_conf,$this->fields(),array($row));
foreach ($fields as $name => $f) {
#$html .= '<th class="'.$f.'">'.($this->p('buttons')==='0' ? $f : $this->url_sort($f)).'</th>'.NB_EOL;
- $html .= '<th class="'.$name.($f->key?' key':'').'">'.($this->p('buttons')==='0' ? $this->prettyText($name) : $this->url_sort($name)).'</th>'.NB_EOL;
+ $sort = $this->p('buttons')!=='0' and empty($f->call);
+ $html .= '<th class="'.$name.($f->key?' key':'').'">'.(!$sort ? $this->prettyText($name) : $this->url_sort($name)).'</th>'.NB_EOL;
}
if ($this->p('buttons')!=='0' and DB_HTML_DELETE) $html .= '<th class="delete"></th>'.NB_EOL;
$html .= '</tr>'.NB_EOL.'</thead>'.NB_EOL;
$html = '<tr class="row">'.NB_EOL;
- if ($this->p('buttons')!=='0') $html .= '<td class="action">'.$buttons[0].'</a></td>'.NB_EOL;
+ if ($this->p('buttons')!=='0') $html .= '<td class="action">'.$buttons[0].'</td>'.NB_EOL;
foreach ($row as $k => $v) {
if (isset($this->extras[$k])) $k .= " extra";
$html .= '<td class="'.$k.'">'.$v.'</td>'.NB_EOL;
}
- if ($this->p('buttons')!=='0') $html .= '<td class="action">'.$buttons[1].'</a></td>'.NB_EOL;
+ if ($this->p('buttons')!=='0') $html .= '<td class="action">'.$buttons[1].'</td>'.NB_EOL;
$html .= '</tr>'.NB_EOL;
// Tables - see default.js if you change class
$r .= '<span class="label">';
$r .= '<label for="table">Tables</label>'.html_select_array(array_keys($this->db()->tables()),array(
- 'html' => 'class="tables" id="table" name="table" id="table"',
+ 'html' => 'class="tables" name="table" id="table"',
'selected' => $this->p('table'),
'prettyText' => true,
));