),
'node' => array(
+ 'row_parse_post'=> function(&$r) {
+ $r['graph'] = '<a target="_blank" href="/graphite/?Hosts='.$r['id'].'"><img src="/images/graphite.png" /></a>';
+ },
'extras'=> array(
+ 'ip' => false,
'ips' => false,
'file' => false, # printed in meta
# n => v
))"),
'fact' => "(SELECT count(*) FROM fact WHERE fact.idnode=node.id)",
'keyevent' => "(SELECT count(*) FROM keyevent WHERE keyevent.idnode=node.id)",
- 'graph' => '\'<a target="_blank" href="/graphite/?Hosts=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
+ #'graph' => '\'<a target="_blank" href="/graphite/?Hosts=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
),
- 'view_backup' => array(
- 'Details' => '\'<a target="_blank" class="view_backup" href="?table=backup&idnode=\' || idnode || \'">Go</a>\'',
- ),
+ ),
- 'view_pingdom_per_month' => array(
- 'Checks' => '\'<a target="_blank" class="pingdom_check_report" href="?table=pingdom_check_policy&idpingdom_policy=\' || idpingdom_policy || \'">\'||(SELECT count(*) FROM pingdom_check_policy pcp WHERE pcp.idpingdom_policy=view_pingdom_per_month.idpingdom_policy)||\'</a>\'',
- ),
- 'pingdom_check' => array(
- 'View' => '\'<a target="_blank" class="pingdom_check_report" href="https://my.pingdom.com/reports/uptime#check=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
+ 'view_backup' => array(
+ 'row_parse_post'=> function(&$r) {
+ $r['Detail'] = '<a target="_blank" class="view_backup" href="?table=backup&idnode='.$r['idnode'].'">View</a>';
+ },
+ ),
+
+ 'view_pingdom_per_month' => array(
+ 'row_parse_post'=> function(&$r) {
+ $r['Checks'] = '<a target="_blank" class="pingdom_check_report" href="?table=pingdom_check_policy&idpingdom_policy='.$r['idpingdom_policy'].'">'.$r['Checks'].'</a>';
+ },
+ 'extras' => array(
+ 'Checks' => '(SELECT count(*) FROM pingdom_check_policy pcp WHERE pcp.idpingdom_policy=view_pingdom_per_month.idpingdom_policy)',
),
),
+
+ 'pingdom_check' => array(
+ 'row_parse_post'=> function(&$r) {
+ $r['View'] = '<a target="_blank" class="pingdom_check_report" href="https://my.pingdom.com/reports/uptime#check='.$r['id'].'"><img src="/images/graphite.png" /></a>';
+ },
+ ),
+
),
);
?>
// apply
$(this).height(h); $(this).width(w);
- $(this).css('overflow','auto');
+ $(this).css({
+ 'overflow':'auto',
+ });
+ if (this.tagName == 'TABLE') $(this).css('display','block');
});
}
#define('NB_EOL','');
#define('NB_PROD',true);
require(dirname(__FILE__).'/nb.php');
-if (nb::php_cli()) argv2request();
+if (!empty($_SERVER['PROD'])) return;
-if (empty($_SERVER['DEV'])) return;
+if (nb::php_cli()) argv2request();
// Should be done in php.ini for performance
date_default_timezone_set('Europe/London');
public function add_extras($extras) {
if ($this->p('extras') === '0') return false;
+ #return false;
$this->fields();
foreach ($extras as $k => $v) {
- if ($v === null or $v === false) {
+ if ($v === false or $v === null) {
if (isset($this->fields[$k])) unset($this->fields[$k]);
+ #if (isset($this->extras[$k])) unset($this->extras[$k]);
+ $this->_rows_fields = true;
continue;
}
Html Output
******************************************************************/
public function rows(&$opt=array(),$opt_by_val=null) {
+
if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
if ($opt_by_val !== null) $opt = $opt_by_val;
$format = $this->p('format');
- if (!$format) bye("No param format");
+ if (!$format) bye("Invalid parameter!");
//
// Select
$select_count = ( $where ? $this->db()->type('select_count') : null );
if (empty($select_count)) $select_count = array('','');
- $sql = "SELECT ".trim("$select_count[0] *"). $this->select_extras();
+ if (!empty($this->_rows_fields)) {
+ foreach ($this->fields() as $f) {
+ if (empty($f->extra)) $select_fields[] = $f->sql_name();
+ }
+ } else {
+ $select_fields = array('*');
+ }
+ $sql = "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras();
$sql .= " FROM ".$this->sql_name();
$sql .= $where;
+ #bye($sql);
if ($this->p('orderby')) $sql .= ' ORDER BY '.$this->p('orderby');
if ($opt['is_html']) out::$type = 'html';
$count = 0;
+ $extras = self::p('extras') === '0' ? 0 : 1;
+ #bye($extras);
while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
$count++;
$call = null;
- if (!empty($this->db()->row_parse)) {
+ if ($extras and !empty($this->db()->row_parse)) {
$call = $this->db()->row_parse; $call($row);
}
- if (!empty($this->row_parse_pre)) {
+ if ($extras and !empty($this->row_parse_pre)) {
$call = $this->row_parse_pre; $call($row);
}
}
}
- if (!empty($this->row_parse_post)) {
+ if ($extras and !empty($this->row_parse_post)) {
$call = $this->row_parse_post; $call($row);
}
$this->out2($e);
return true;
- } elseif ($r=self::class_action_out($this,$action)) {
- return $r;
-# NB 10.04.16 } elseif (preg_match('/^table\.(\w+)/',$action,$m)) {
-# NB 10.04.16 if ($rows = $this->$m[1]() and !empty($rows)) {
-# NB 10.04.16 $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
-# NB 10.04.16 } else {
-# NB 10.04.16 $return = true;
-# NB 10.04.16 }
+ } elseif (self::class_action_out($this,$action)) {
+ return true;
} elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) {
$rows = array();
if (in_array($name,get_class_methods($class))) $rows = $class->$name();
- else $rows = $class->$name;
+ elseif (in_array($name,get_class_vars($class_name))) $rows = $class->$name;
+ else self::bye("Unknow action: `$action`");
+ #else $rows = $class->$name;
if (!$rows) return false;
- return out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : array()));
+ #bye($rows);
+ if (is_scalar($rows)) {
+ #echo "$rows\n";
+ $rows = array($name => $rows);
+ #return true;
+ }
+ #debug($action.' '.$class_name.' '.$name);
+ out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : array()));
+ return true;
+ $class->out2(self::object2array($rows),(is_scalar($rows) ? $name : array()));
+ return true;
return self::object2array($rows);
return $class->out2(self::object2array($rows),(is_scalar($rows) ? $name : array()));
}
# For sprintf
unset($o['head_max_len']);
-# NB 01.04.16 if (!empty($head)) {
-# NB 01.04.16 $o['head_max_len'] = max(self::ar_map('strlen($a)',$head));
-# NB 01.04.16 }
+
if (!empty($data)) {
if (self::is_hash($data[0])) {
$o['head_max_len'] = max(self::ar_map('strlen($a)',array_keys($data[0])));
} elseif (is_array($data[0])) {
+ #debug($data);
$o['head_max_len'] = max(self::ar_map('strlen($a)',$data[0]));
}
#bye($o);