*****************************************************************************/
require_once(dirname(__FILE__).'/nb.php');
+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',''
foreach ($db as $k=>$v) $this->$k = $v;
}
+ #$this->formats += array_keys(out::$types);
+ foreach(out::$types as $t=>$v) if (!in_array($t,$this->formats)) $this->formats[] = $t;
+
# Pdo
return $this->connect();
# NB 09.03.16 $head = array($head);
# NB 09.03.16 }
- out::rows($this->p('format','csv'),$rows,$head);
+ out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
return true;
}
require_once(dirname(__FILE__).'/../db/field.php');
require_once(dirname(__FILE__).'/../out.php');
-if (false and empty($_SERVER['DOCUMENT_ROOT'])) {
- $_REQUEST['db'] = 'rent'; $name = 'tenant';
- $_REQUEST['db'] = 'rt'; $name = 'classes';
- $_REQUEST['db'] = 'mysql'; $name = 'addr';
- $_REQUEST['db'] = 'izi'; $name = 'zone';
- require_once('/opt/rent/www/config/db.php');
- print_r($Db->tables());
- $Table = $Db->table($name);
- print_r($Table->fields());
- #print_r($Table->sql());
-}
-
define('TABLE_INDENT',NB_EOL ? "\t" : "");
define('TABLE_CSV_SEP',nb::p('sep') ? nb::p('sep') : "\t");
if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
public $extras = array();
# hidden, sort, ... fields
- public $params = array( 'table', 'limit', 'debug', 'action',);
+ public $params = array( 'table', 'limit', 'debug', 'action');
public $order_by = null;
$st = $this->db->conn->prepare($sql);
$st->execute();
- $format = ( $this->p('format') ? $this->p('format') : 'table' );
+# NB 17.03.16 $format = ( $this->p('format') ? $this->p('format') : 'table' );
+ $format = $this->pdef('format','table');
if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format)
? ( $this->p('header')!=="0" and $this->p('inc')!=="1")
# Use the module out when format unknow
$out_conf = null;
- if ($this->p('out') or !preg_match('/^text|csv|yaml|json|table|div$/',$format)) {
+ if ($this->p('out') or !preg_match('/^('.join('|',
+ array( 'table','div','csv','xml','json','yaml' )
+ ).')$/',$format))
+ {
+
if (!($out_conf = out::$types[$format])) $this->bye("Unknow format `$format`");
+ $this->params += array_values(out::$types);
+
if (empty($out_conf['enclose'])) $out_conf['enclose'] = array('','');
debug('Using out module!');
+
}
$count = 0;
}
/*
- * Set a default value for param, if not sent
+ * Set a default's param value, if not set
+ * Return the value set or existing
*/
public static function pdef($name,$value) {
if (preg_match('/^\s*$/',self::p($name))) return self::pset($name,$value);
- return false;
+ return self::p($name);
}
/*
'head' => 'out_csv_head',
'function' => 'out_csv',
),
+ 'divs' => array(
+ 'enclose' => array("<div class=\"rows\">".NB_EOL,"</div>".NB_EOL),
+ 'tag_enclose' => 'div class="row"',
+ #'tag_head' => 'span',
+ #'tag_head_enclose' => 'span class="row"',
+ 'tag' => 'div',
+ 'function' => 'out_tag',
+ 'head' => 'out_tag_head',
+ ),
'center' => array(
'enclose' => array("<center>".NB_EOL,"</center>".NB_EOL),
'tag_enclose' => 'div',
'head' => 'out_tag_head',
),
'table' => array(
- 'enclose' => array("<table>".NB_EOL,"</table>".NB_EOL),
- 'tag_enclose' => 'tr',
+ 'enclose' => array("<table class=\"rows\">".NB_EOL,"</table>".NB_EOL),
+ 'tag_enclose' => 'tr class="row"',
'tag_head' => 'th',
'tag' => 'td',
'function' => 'out_tag',
if (!empty($type) and !empty($data)) return $this->rows($type,$data,$head);
}
- public static function begin($o,$head,$data) {
+ public static function begin($o,$head,$data=array()) {
if (!empty($o['enclose'])) echo $o['enclose'][0];
if (!isset($o['head'])) return;
#function out_tag_head(&$row,$o) { return ''; }
function out_tag_head(&$data,$o) {
#return var_dump($row,true); return '';
- if (empty($o['tag']) and isset($o['tag_head'])) $o['tag'] = $o['tag_head'];
+ if (isset($o['tag_head'])) $o['tag'] = $o['tag_head'];
$row = out::ar_first($data);
if (!out::is_hash($row)) $row = $data;
if (!is_array($row)) return 0;
+
+ # For object
if (out::is_hash($row)) $row = array_combine(array_keys($row),array_keys($row));
+
+ # Avoid: <th class="0">name</th>
+ if (!out::is_hash($row)) $row = array_combine(array_values($row),array_values($row));
+ #bye($row);
out_tag($row,$o);
}
-function out_tag(&$row,$o) {
+function out_tag(&$row,&$o) {
#var_dump($row); return '';
if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').'<'.$o['tag_enclose'].'>'.NB_EOL;
}
echo ''
.(NB_EOL ? ' ' : '')
- #.(isset($o['tag_enclose']) ? '<'.$o['tag_enclose'].'>' : '')
."<$k$class>$v</$k>"
- #.(isset($o['tag_enclose']) ? '</'.$o['tag_enclose'].'>' : '')
.NB_EOL
;
}
- if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').'</'.$o['tag_enclose'].'>'.NB_EOL;
+ if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').'</'.explode(' ',$o['tag_enclose'])[0].'>'.NB_EOL;
}
function out_xml(&$row,$o) {
/****************************************************************************/
#die("A NB_EOL B \n");
-if (empty($argv) or $argv[1] != 'test') return true;
+if (empty($argv) or count($argv) < 2 or $argv[1] != 'test') return true;
$data = array(
'a' => 1,
'b' => 2,