CMPHP/ui_table.php

170 lines
4.2 KiB
PHP
Raw Normal View History

2016-08-21 23:06:17 +04:00
<?php
require_once "tools_sql.php";
class UITable
{
2016-08-31 15:26:29 +04:00
private $heading=null;
private $heading_style="default";
private $body=null;
2016-08-31 15:40:36 +04:00
protected $fields=null;
private $table_style="striped";
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
public function set_heading($h)
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
$this->heading=$h;
2016-08-21 23:06:17 +04:00
}
2016-08-31 15:26:29 +04:00
public function set_heading_style($hs)
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
$this->heading_style=$hs;
2016-08-21 23:06:17 +04:00
}
2016-08-31 15:26:29 +04:00
public function set_body_text($bt)
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
$this->body=$bt;
2016-08-21 23:06:17 +04:00
}
2016-08-31 15:26:29 +04:00
public function set_fields($f)
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
$this->fields=$f;
2016-08-21 23:06:17 +04:00
}
public function set_table_style($ts)
{
$this->table_style=$ts;
}
2016-08-31 15:26:29 +04:00
public function start()
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
echo '<div class="panel panel-'.$this->heading_style.'">';
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
if($this->heading!=null)
echo '<div class="panel-heading">'.$this->heading.'</div>';
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
if($this->body!=null)
echo '<div class="panel-body"><p>'.$this->body.'</p></div>';
2016-08-21 23:06:17 +04:00
if($this->table_style)
2016-09-02 14:41:18 +04:00
echo '<table class="table table-responsive table-'.$this->table_style.'">';
else
2016-09-02 14:41:18 +04:00
echo '<table class="table table-responsive">';
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
if($this->fields!=null)
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
echo '<tr>';
foreach($this->fields as $field)
echo '<th>'.$field.'</th>';
echo '</tr>';
2016-08-21 23:06:17 +04:00
}
}
2016-08-31 15:26:29 +04:00
public function start_row (){echo '<tr>';}
public function end_row (){echo '</tr>';}
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
public function start_col (){echo '<td>';}
public function end_col (){echo '</td>';}
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
public function echo_col ($text){echo '<td>'.$text.'</td>';}
public function echo_row ($text_list)
2016-08-21 23:06:17 +04:00
{
2016-08-31 15:26:29 +04:00
start_row();
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
foreach($text_list as $text)
echo_col($text);
2016-08-21 23:06:17 +04:00
2016-08-31 15:26:29 +04:00
end_row();
2016-08-21 23:06:17 +04:00
}
public function end()
{
2016-08-31 15:26:29 +04:00
echo '</table>
</div>';
2016-08-21 23:06:17 +04:00
}
};//class UITable
2016-08-31 15:40:36 +04:00
class UISQLTable extends UITable
{
private $sql_result=null;
private $bool_text=array();
private $enum_text=array();
public function __construct()//$sql_table_name,$field_list,$where,$start,$count)
2016-08-31 15:40:36 +04:00
{
$sql_table_name=func_get_arg(0);
if(func_num_args()>1)$field_list=func_get_arg(1);else $field_list=null;
if(func_num_args()>2)$where =func_get_arg(2);else $where=null;
if(func_num_args()>3)$start =func_get_arg(3);else $start=null;
if(func_num_args()>4)$count =func_get_arg(4);else $count=null;
2016-08-31 15:40:36 +04:00
if($field_list==null)
{
$field_list=get_field_list($sql_table_name);
parent::set_fields($field_list);
$this->sql_result=select_table($sql_table_name,null,$where,$start,$count);
2016-08-31 15:40:36 +04:00
}
else
{
parent::set_fields($field_list);
$this->sql_result=select_table($sql_table_name,$field_list,$where,$start,$count);
2016-08-31 15:40:36 +04:00
}
}
public function SetBoolText($field,$true_text,$false_text)
{
$this->bool_text[$field]=array($false_text,$true_text);
}
public function SetEnumText($field,$text_array)
{
$this->enum_text[$field]=$text_array;
}
public function get_sql_result()
{
return $this->sql_result;
}
public function out_html()
{
parent::start();
for($r=0;$r<count($this->sql_result);$r++)
{
$row=$this->sql_result[$r];
parent::start_row();
for($c=0;$c<count($row);$c++)
{
parent::start_col();
if(array_key_exists($this->fields[$c],$this->bool_text))
{
echo $this->bool_text[$this->fields[$c]][$row[$c]];
}
else
if(array_key_exists($this->fields[$c],$this->enum_text))
{
echo $this->enum_text[$this->fields[$c]][$row[$c]];
}
else
{
echo $row[$c];
}
parent::end_col();
}
parent::end_row();
}
parent::end();
}
};//class UISQLTable
2016-08-21 23:06:17 +04:00
?>