public $created;
public static $is_admin = true;
+ public $fields = [];
+ public $indexes;
+
+ public $itemplate_id;
+
# hidden, sort, ... fields
public static $params = [ 'db', 'table', 'limit', 'debug', 'action'
, 'page', 'paged' # wordpress
];
- public $fields = [];
- public $indexes;
-
function __construct($name,$opt=[]) {
if (!is_scalar($name)) {
if ($opt['is_html'] and !$opt['use_out']) {
foreach ($row as $k=>$v) {
- if (!isset($this->extras[$k])) $row[$k] = out::format($v);
+ if (!isset($this->extras[$k])) $row[$k] = $this->db()->out->format($v);
}
}
{
$opt['use_out'] = true;
- if (!($out_conf = out::types($format))) $this->bye("Unknow format `$format`");
+ if (!($out_conf = $this->db()->out->types($format))) $this->bye("Unknow format `$format`");
$out_conf = array_merge($opt,$out_conf);
# Function name should be format
- out::type($format); self::$params += array_values(out::types());
+ $this->db()->out->type($format); self::$params += array_values($this->db()->out->types());
if (empty($out_conf['enclose'])) $out_conf['enclose'] = ['',''];
debug('Using out module!',3);
if (!$this->p('inc')) echo $this->form_hidden();
}
- if ($opt['is_html']) out::type('html');
+ if ($opt['is_html']) $this->db()->out->type('html');
#
# Rows
}
if ($out_conf) {
- out::head($out_conf,array_keys($fields),[$row]);
+ $this->db()->out->head($out_conf,array_keys($fields),[$row]);
} else {
echo $this->{"rows_begin_$format"}($fields,$opt);
}
if ($out_conf) {
- out::row($out_conf,$row);
+ $this->db()->out->row($out_conf,$row);
} else {
echo $this->{"rows_rec_$format"}($row,$opt);
}
if ($out_conf) {
- out::end($out_conf);
+ $this->db()->out->end($out_conf);
} else {
echo $this->{"rows_end_$format"}();
Template
-----------------------------------------------------------------*/
public function rows_begin_template($fields,&$o) {
- $id = self::templateid();
+ $id = $this->template_id();
$id = preg_replace('/[^\w\._-]/','',$id);
return $info['rowCount'];
}
- public function out($v,$head=[]) { return $this->db()->out($v,$head); }
+ public function out($v,$head=[],$conf=[]) { return $this->db()->out($v,$head,$conf); }
private function url_referer($default='') {
if (self::p('referer')) {
}
}
- public function action($action=null) {
- #if (empty($action)) return;
- #if ($action === null) $action = $this->p('action');
- #debug($action);
+ public function fields_rows() {
+ $rows = array_values($this->object2array($this->fields()));
- if ($action == 'table.fields') {
- $rows = array_values($this->object2array($this->fields()));
+ list($sql,$where,$limit,$select_count) = $this->rows_sql();
+ foreach ([
+ 'maxlen' => 'MAX(LENGTH(<NAME>))',
+ 'max' => 'MAX(<NAME>)',
+ ] as $name => $select) {
+ if ($this->p($name)) {
+ $sql = '';
- list($sql,$where,$limit,$select_count) = $this->rows_sql();
- foreach ([
- 'maxlen' => 'MAX(LENGTH(<NAME>))',
- 'max' => 'MAX(<NAME>)',
- ] as $name => $select) {
- if ($this->p($name)) {
- $sql = '';
-
- foreach ($this->fields() as $f) {
- $sql .= ($sql == '' ? 'SELECT ' : ', ');
- $sql .= str_replace('<NAME>',$f->sql_name(),$select);
- }
+ foreach ($this->fields() as $f) {
+ $sql .= ($sql == '' ? 'SELECT ' : ', ');
+ $sql .= str_replace('<NAME>',$f->sql_name(),$select);
+ }
- $sql .= ' FROM ' . $this->sql_name() . $where . ($limit ? " LIMIT ".$limit : '');
- $len = $this->db()->query($sql)->fetch(PDO::FETCH_NUM);
+ $sql .= ' FROM ' . $this->sql_name() . $where . ($limit ? " LIMIT ".$limit : '');
+ $len = $this->db()->query($sql)->fetch(PDO::FETCH_NUM);
- $i = 0;
- foreach ($rows as $k => $v) { $rows[$k][$name] = $len[$i]; $i++; }
+ $i = 0;
+ foreach ($rows as $k => $v) { $rows[$k][$name] = $len[$i]; $i++; }
- }
}
+ }
+
+ #return $this->out(array_values($this->object2array($this->fields())));
+ return $rows;
+ }
- #return $this->out(array_values($this->object2array($this->fields())));
+ public function action($action=null) {
+ #if (empty($action)) return;
+ #if ($action === null) $action = $this->p('action');
+ #debug($action);
+
+ if ($action == 'table.fields') {
+ $rows = $this->fields_rows();
return $this->out($rows);
} elseif ($action == 'table.rows') {
return $this->status;
}
- private static function templateid($id=null) {
+ private function template_id($id=null) {
if (empty($id)
and !( $id=self::p('table.template.id') )
and !( $id=self::p('idtemplate') )
+ and !( $id = $this->template_id )
) self::bye('Wrong parameter!');
return $id;
}
public function template($id=null) {
- $id = self::templateid($id);
+ $id = $this->template_id($id);
$id = preg_replace('/[^\w\._-]/','',$id);
parent::__construct($opt);
// Defaults
- if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title();
- if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
+# NB 06.12.16 if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title();
+# NB 06.12.16 if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
+ if ( empty($this->title) ) $this->title = !empty($nav) ? join($this->sep,$nav) : $this->filename2title();
// Call / Print
if (!empty($this->call)) $this->call($this->call);
* Function: tag
* Return html code for a tag
*/
- public static function h1($content='',$attrs='') { return self::tag('h1',$content,$attrs); }
- public static function div($content='',$attrs='') { return self::tag('div',$content,$attrs); }
- public static function pp($content='',$attrs='') { return self::tag('p',$content,$attrs); }
+# NB 06.12.16 public static function h1($content='',$attrs='') { return self::tag('h1',$content,$attrs); }
+# NB 06.12.16 public static function div($content='',$attrs='') { return self::tag('div',$content,$attrs); }
+# NB 06.12.16 public static function pp($content='',$attrs='') { return self::tag('p',$content,$attrs); }
public static function tag($tag,$content='',$attrs='') {
static $is_html = null;
if ($is_html === null) $is_html = preg_match('/ml$/',self::content_type()) ? true : false;