<?php

/**
 * ============================================================================
 * 版权所有 福建荣升信息技术有限公司，保留所有权利。
 * 网站地址: http://www.fjrsweb.cn；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 */

if (!defined('ADMIN')) {
	exit('Access Denied');
}
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post' or $_GET['get'] == 1) {
	//列表中更新单个字段
	if ($_POST['field']) {
		$udata['table'] = MOD;
		$udata['field'] = $_POST['field'];
		$udata['value'] = $_POST['value'];
		$duoduo->changefield($data);
	}
	$title = 'title';
	$page = !($_POST['page']) ? '1' : intval($_POST['page']);
	$pagesize = $_REQUEST['limit'];
	$frmnum = ($page - 1) * $pagesize;
	$q = $_POST['q'];
	$cid = (int)$_POST['cid'];
	if (isset($_POST['sort'])) {
		$by = 'sort asc,';
		$page_arr['sort'] = $_POST['sort'];
	} else {
		if ($table_sort != '') {
			$by = $table_sort . ',';
		} else {
			$by = '';
		}
	}
	$where = '';

	if (method_exists(MOD, "listwhere")) {
		$where = app(MOD)->listwhere($where, $frmnum, $pagesize);
	}
	//搜索条件
	if ($_POST['title']) {
		$where .= " and title like '%" . $_POST['title'] . "%'";
	}
	if ($_POST['cid']) {
		$where .= " and cid like '%" . $_POST['cid'] . "%'";
	}
	if ($_POST['status']) {
		$where .= " and status like '%" . $_POST['status'] . "%'";
	}
	if ($_POST['tj']) {
		$where .= " and tj like '%" . $_POST['tj'] . "%'";
	}
	$d = $duoduo->get_table_struct(MOD);
	$total = $duoduo->count(MOD, "`" . $title . "` like '%$q%' " . $where);
	$row = $duoduo->select_all(MOD, '*', '`' . $title . '` like "%' . $q . '%" ' . $where . ' order by ' . $by . ' sort asc ,id desc limit ' . $frmnum . ',' . $pagesize);



	if (MOD == "article") {
		foreach ($row as $key => $value) {
			$row[$key]['cidname'] = $duoduo->get_field("type", $value['cid']);
		}
	}
	if (MOD == "slides") {
		$slides = slides();
		foreach ($row as $key => $value) {
			$row[$key]['cidname'] = $slides[$value['cid']];
		}
	}

	if (db()->TableField(MOD, "addtime")) {

		foreach ($row as $key => $value) {
			if (MOD == "zw")
				$row[$key]['addtime'] = date("Y-m-d", $value['addtime']);
			else
				$row[$key]['addtime'] = date("Y-m-d H:i:s", $value['addtime']);
		}
	}
	if (method_exists(MOD, "list")) {
		$row = app(MOD)->list($row);
	}
	json(0, "", $row, $total);
}
