dzadsod/web/table_ajax.class.php

142 lines
3.4 KiB
PHP

<?php
defined('IN_MET') or exit ('No permission');
load::own_class('appweb');
load::own_class('../traits/tdata');
load::own_class('../traits/tlist');
load::own_class('../traits/tfield');
//表格
class table_ajax extends appweb
{
# 过滤方法名
private $ado = ['doindex'];
//非备份,正常字段即可
private $bsign = false;
//列表
private $list = [];
//当前执行表名
private $sqlk;
//form数组
private $form = [];
//info_on 快速URL
private $own_name_info;
private $own_name_table;
public function __construct()
{
global $_M, $_YW;
parent::__construct();
// 过滤
if (!in_array(M_ACTION, $this->ado, true)) {
//报错
exit(0);
}
$this->form = $_M['form'];
if ($this->form['tname']) {
$this->tname = $this->form['tname'];
$this->sqlk = $_YW['k'][ $this->tname ];
}
//地址要换算成前台的,目前是后台的
// $this->own_name_info = $_M['url']['own_name'].'c=info_on&a=do';
// $this->own_name_table = $_M['url']['own_name'].'c=table_on&a=do';
}
//表格数据
public function doindex()
{
global $_M;
//加载表格数据获取类
$table = load::own_class('tabledata', 'new');
$field = self::td_field();
$sqlk = self::td_sqlk();
$where = self::td_where();
$order = self::td_order();
/*查询表*/
if ($where) {
$conds .= " WHERE {$where} ";
}
if ($order) {
$conds .= " ORDER BY {$order} ";
}
//整理查询条件
$query = "SELECT {$field} FROM {$sqlk} {$conds} ";
//获取数据
$data = $table->getdata($sqlk, $field, $where, $order, $query, $this->multi_table);
//数据整理
$array = self::sqlarr($data);
//返回数据
$table->rdata($array);
}
use tdata;
/*
* 【列出】
* 返回数据数组
*/
private function sqlarr($data = [])
{
global $_M;
// if(in_array($this->tname,$this->k_name)){
foreach ($data as $val) {
self::output($val);
$array[] = $this->list;
}
return $array;
// }else{
// return false;
// }
}
/*
* 【新行】
* 新增行分发
*/
public function do_table_add_list()
{
global $_M;
$val = ['id' => 'new-' . $this->form['new_id'], 'p_type' => $this->form['p_type']];
if (in_array($this->tname, $this->k_name)) {
self::output($val, 'checked=""');
}
self::addlist($val);
}
/*
* 【新行】
* 生成文件新增行
*/
private function addlist($val)
{
global $_M;
$metinfo = '';
foreach ($this->list as $v) {
$metinfo .= '<td class=" text-xs-center">' . $v . '</td>';
}
echo "<tr>{$metinfo}</tr>";
}
use tfield;
use tlist;
//公用的输出
protected function output($val, $checked = '')
{
global $_M, $_YW;
$array = self::{$this->tname}($val, $checked);
$this->list = array();
foreach ($array as $value) {
$this->list[] = $value;
}
}
}
?>