2017-02-23 15:21:34 +08:00
|
|
|
<?php
|
2016-08-21 23:06:17 +04:00
|
|
|
|
|
|
|
require_once "tools_sql.php";
|
|
|
|
|
2017-02-16 10:50:05 +08:00
|
|
|
class TableCol
|
|
|
|
{
|
|
|
|
public $text; //显示文本
|
|
|
|
public $icon; //图标
|
|
|
|
public $link; //如果点击列将跳转的页面
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->text=func_get_arg(0);
|
|
|
|
|
|
|
|
if(func_num_args()>1)$this->icon=func_get_arg(1);else $this->icon=null;
|
|
|
|
if(func_num_args()>2)$this->link=func_get_arg(2);else $this->link=null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-21 23:06:17 +04:00
|
|
|
class UITable
|
|
|
|
{
|
2017-02-16 10:50:05 +08:00
|
|
|
protected $title_cols=null;
|
2023-07-10 20:15:28 +08:00
|
|
|
private $thead_style=null;
|
2016-09-01 09:14:30 +04:00
|
|
|
private $table_style="striped";
|
2016-08-21 23:06:17 +04:00
|
|
|
|
2017-02-16 10:50:05 +08:00
|
|
|
public function set_title_col_text($f)
|
|
|
|
{
|
|
|
|
foreach($f as $tt)
|
|
|
|
$this->title_cols[]=new TableCol($tt);
|
|
|
|
}
|
|
|
|
|
2016-11-07 17:30:55 +04:00
|
|
|
public function set_title_col($f)
|
2016-08-21 23:06:17 +04:00
|
|
|
{
|
2017-02-16 11:23:37 +08:00
|
|
|
$this->title_cols=$f;
|
2016-08-21 23:06:17 +04:00
|
|
|
}
|
|
|
|
|
2023-07-10 20:15:28 +08:00
|
|
|
public function set_title_thead_style($s)
|
|
|
|
{
|
|
|
|
$this->thead_style=$s;
|
|
|
|
}
|
|
|
|
|
2016-09-01 09:14:30 +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-09-01 09:14:30 +04:00
|
|
|
if($this->table_style)
|
2016-09-02 14:41:18 +04:00
|
|
|
echo '<table class="table table-responsive table-'.$this->table_style.'">';
|
2016-09-01 09:14:30 +04:00
|
|
|
else
|
2016-09-02 14:41:18 +04:00
|
|
|
echo '<table class="table table-responsive">';
|
2016-08-21 23:06:17 +04:00
|
|
|
|
2017-02-16 10:50:05 +08:00
|
|
|
if($this->title_cols!=null)
|
2016-08-21 23:06:17 +04:00
|
|
|
{
|
2023-07-10 20:15:28 +08:00
|
|
|
if($this->thead_style!=null)
|
|
|
|
echo '<thead class="table-'.$this->thead_style.'">';
|
|
|
|
|
2016-08-31 15:26:29 +04:00
|
|
|
echo '<tr>';
|
2017-02-16 10:50:05 +08:00
|
|
|
foreach($this->title_cols as $field)
|
|
|
|
{
|
|
|
|
echo '<th>';
|
|
|
|
|
|
|
|
if($field->link)
|
|
|
|
echo '<a href="'.$field->link.'">';
|
2017-02-23 15:21:34 +08:00
|
|
|
|
2017-02-16 10:50:05 +08:00
|
|
|
echo $field->text;
|
|
|
|
|
|
|
|
if($field->icon)
|
|
|
|
echo_icon($field->icon);
|
|
|
|
|
|
|
|
if($field->link)
|
|
|
|
echo '</a>';
|
|
|
|
|
|
|
|
echo '</th>';
|
|
|
|
}
|
2016-08-31 15:26:29 +04:00
|
|
|
echo '</tr>';
|
2023-07-10 20:15:28 +08:00
|
|
|
|
|
|
|
if($this->thead_style!=null)
|
|
|
|
echo '</thead>';
|
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
|
|
|
|
2023-07-10 20:15:28 +08:00
|
|
|
public function skip_col (){echo '<td/>';}
|
2016-08-31 15:26:29 +04:00
|
|
|
public function echo_col ($text){echo '<td>'.$text.'</td>';}
|
|
|
|
|
2023-07-07 18:31:30 +08:00
|
|
|
public function echo_multi_col($text_list)
|
|
|
|
{
|
|
|
|
foreach($text_list as $text)
|
|
|
|
echo '<td>'.$text.'</td>';
|
|
|
|
}
|
|
|
|
|
2016-08-31 15:26:29 +04:00
|
|
|
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()
|
|
|
|
{
|
2023-07-10 20:15:28 +08:00
|
|
|
echo '</table>';
|
2016-08-21 23:06:17 +04:00
|
|
|
}
|
|
|
|
};//class UITable
|
|
|
|
|
2016-08-31 15:40:36 +04:00
|
|
|
class UISQLTable extends UITable
|
|
|
|
{
|
2016-11-07 17:26:18 +04:00
|
|
|
private $sql_fields=null;
|
2016-08-31 15:40:36 +04:00
|
|
|
private $sql_result=null;
|
2016-11-07 17:26:18 +04:00
|
|
|
|
2016-08-31 15:40:36 +04:00
|
|
|
private $bool_text=array();
|
|
|
|
private $enum_text=array();
|
|
|
|
|
2016-09-03 21:49:23 +04:00
|
|
|
public function __construct()//$sql,$sql_table_name,$field_list,$where,$start,$count)
|
2016-08-31 15:40:36 +04:00
|
|
|
{
|
2016-09-03 21:49:23 +04:00
|
|
|
$sql=func_get_arg(0);
|
|
|
|
$sql_table_name=func_get_arg(1);
|
2016-09-01 09:14:30 +04:00
|
|
|
|
2016-09-03 21:49:23 +04:00
|
|
|
if(func_num_args()>2)$field_list=func_get_arg(2);else $field_list=null;
|
|
|
|
if(func_num_args()>3)$where =func_get_arg(3);else $where=null;
|
|
|
|
if(func_num_args()>4)$start =func_get_arg(4);else $start=null;
|
|
|
|
if(func_num_args()>5)$count =func_get_arg(5);else $count=null;
|
2016-09-01 09:14:30 +04:00
|
|
|
|
2016-08-31 15:40:36 +04:00
|
|
|
if($field_list==null)
|
|
|
|
{
|
2023-07-10 20:15:28 +08:00
|
|
|
$field_list=sql_get_field_list($sql,$sql_table_name);
|
2016-08-31 15:40:36 +04:00
|
|
|
|
2016-11-07 17:30:55 +04:00
|
|
|
parent::set_title_col($field_list);
|
2016-08-31 15:40:36 +04:00
|
|
|
|
2016-11-07 17:26:18 +04:00
|
|
|
$this->sql_fields=$field_list;
|
|
|
|
|
2023-07-10 20:15:28 +08:00
|
|
|
$this->sql_result=sql_select_table_to_array($sql,$sql_table_name,null,$where,$start,$count);
|
2016-08-31 15:40:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-07 17:30:55 +04:00
|
|
|
parent::set_title_col($field_list);
|
2016-08-31 15:40:36 +04:00
|
|
|
|
2016-11-07 17:26:18 +04:00
|
|
|
$this->sql_fields=$field_list;
|
|
|
|
|
2023-07-10 20:15:28 +08:00
|
|
|
$this->sql_result=sql_select_table_to_array($sql,$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();
|
|
|
|
|
2016-11-07 17:26:18 +04:00
|
|
|
if(array_key_exists($this->sql_fields[$c],$this->bool_text))
|
2016-08-31 15:40:36 +04:00
|
|
|
{
|
2016-11-07 17:26:18 +04:00
|
|
|
echo $this->bool_text[$this->sql_fields[$c]][$row[$c]];
|
2016-08-31 15:40:36 +04:00
|
|
|
}
|
|
|
|
else
|
2016-11-07 17:26:18 +04:00
|
|
|
if(array_key_exists($this->sql_fields[$c],$this->enum_text))
|
2016-08-31 15:40:36 +04:00
|
|
|
{
|
2016-11-07 17:26:18 +04:00
|
|
|
echo $this->enum_text[$this->sql_fields[$c]][$row[$c]];
|
2016-08-31 15:40:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo $row[$c];
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::end_col();
|
|
|
|
}
|
|
|
|
parent::end_row();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::end();
|
|
|
|
}
|
|
|
|
};//class UISQLTable
|
2016-08-21 23:06:17 +04:00
|
|
|
?>
|