<?php
defined('IN_YUNYECMS') or exit('No permission.');
core::load_class('base', false);
core::load_fun('content');
core::load_fun('tree');
class ucontent extends base
{
	public $curmodel;
	function __construct()
	{
		$this->db = core::load_model('content_model');
		parent::__construct();
		if (empty($this->cat)) {
			messagebox("栏目不存在或参数错误", $_SERVER['HTTP_REFERER']);
		} else {
			$modelid = $this->cat['modelid'];
			if (empty($modelid)) {
				messagebox('您选择的栏目有误，请重新选择!', $_SERVER['HTTP_REFERER'], "warn");
			} else {
				$this->curmodel = getmodel($modelid);
			}
		}
		if (empty($this->curmodel)) {
			messagebox('该分类所在的数据模型不存在，请重新选择!', $_SERVER['HTTP_REFERER'], "warn");
		}
	}
	//首页
	public function index()
	{
		$seo['title'] = $this->lang["seotitle"];
		$seo['keywords'] = $this->lang["seokey"];
		$seo['description'] = $this->lang["seodesc"];
		$seostr = Lan('member_center');
		$seo['title'] = "{$seostr}-{$seo['title']}";
		$seo['keywords'] = "{$seostr}-{$seo['keywords']}";
		$cfg = $this->cfg;
		$lang = $this->lang;
		$cfg = $this->cfg;
		$lang = $this->lang;
		$rootcat = $this->rootcat;
		$cat = $this->cat;
		if ($cat) $catid = $cat["id"];
		if ($rootcat) $rootcatid = $cat["id"];
		$breadcumb = array(
			'0' => array('title' => Lan('member_center'), 'url' => url("member/member/index")),
			'1' => array('title' => Lan('member_center'), 'url' => url("member/member/index"))
		);
		islogin();
		$member = $this->member;
		$userid = $this->member['id'];
		include tpl('index', 'ucontent');
	}

	public function lists()
	{
		$seo['title'] = $this->lang["seotitle"];
		$seo['keywords'] = $this->lang["seokey"];
		$seo['description'] = $this->lang["seodesc"];
		$cfg = $this->cfg;
		$lang = $this->lang;
		$rootcat = $this->rootcat;
		$cat = $this->cat;
		$rootcatid = $rootcat["id"];
		islogin();
		$member = $this->member;
		$userid = $this->member['id'];
		if ($cat) {
			$catid = $cat["id"];
			if (!empty($catid)) {
				$parentid = getparentid($catid);
			}
			if ($catid == $rootcatid) {
				$subcatarr = $this->db->find("select id from `#yunyecms_category` where pid='{$rootcatid}' order by ordernum  limit 0,1");
				if ($subcatarr) $scatid = $subcatarr['id'];
			} else {
				if ($parentid == $rootcatid) {
					$scatid = $catid;
				} else {
					$ppid = getparentid($parentid);
					if ($ppid == $rootcatid) $scatid = $parentid;
				}
			}

			$messagetip = "暂时没有{$this->cat["title"]}信息";
			$ispower = $cat["ispower"];
			$seo['title'] = empty($cat["title"]) ? $seo["title"] : $cat["title"] . '-' . $seo['title'];
			$seotitle_pre = empty($cat["title"]) ? '' : $cat["title"] . ',';
			$seo["keywords"] = (empty($cat["keywords"]) ? $seotitle_pre : $cat["keywords"] . ',') . $seo["keywords"];
			$seo["description"] = (empty($cat["description"]) ? $seotitle_pre : strip_tags($cat["description"])) . $seo["description"];
		}
		$tablename = "m_" . $this->curmodel['tablename'];
		$pagesize = empty($rootcat["pages"]) ? 20 : $rootcat["pages"];
		$sqlquery = "select * from `#yunyecms_{$tablename}`  ";
		$where = " where 1=1  and  userid='{$userid}'";
		$sqlcnt = " select count(*) from `#yunyecms_{$tablename}` ";
		$order = " order by `addtime` desc ";
		if (isset($_REQUEST)) {
			if (!empty($_REQUEST["searchkey"])) {
				$searchkey = usafestr(trim($_REQUEST["searchkey"]));
				$where = $where . " and ( `title`  like '%{$searchkey}%'  or  `title_en`  like '%{$searchkey}%' )";
			}
			$catid = trim($_REQUEST['catid']);
			if (!is_numeric($catid)) {
				messagebox("错误的参数", "back", 'warn');
			}
			$catid = usafestr($catid);
			if (!empty($catid)) {
				$subcat = get_cat_child($catid);
				$catidstr = implode(',', $subcat);
				$where = $where . " and catid in($catidstr)";
			}
		}
		$modelfields = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']} and language=1 and issys=0 and issearch=1 and isadd=1 order by ordernum ");
		foreach ($modelfields as $key => $var) {
			$formctrl = $var[formctrl];
			$fdname = $var[fdname];
			if ($formctrl == 'checkbox' || $formctrl == 'radio') {
				$postfdname = usafestr(trim($_REQUEST[$fdname]));
				if (!empty($postfdname)) {
					$where = $where . "and FIND_IN_SET($postfdname,$fdname) ";
				}
			} else {
				$postfdname = usafestr(trim($_REQUEST["searchkey"]));
				if (!empty($postfdname)) {
					$where = $where . " and $fdname ='$postfdname' ";
				}
			}
		}
		$list = array();
		$page = "";
		$pagearr = $this->db->pagelist($sqlcnt, $sqlquery, $where, $order, $pagesize);
		if ($pagearr["count"] != 0) {
			$list = $pagearr["query"];
			if (isset($list)) {
				foreach ($list as $key => $var) {
					if (strlen(RD) > 0 && stripos($list[$key]["pic"], RD) === FALSE) {
						$list[$key]["pic"] = RD . $list[$key]["pic"];
					}
					$list[$key]["url"] = !empty($var['exlink']) ? $var['exlink'] : url('/info/' . $var['catid'] . '/' . $var['id']);
					$list[$key]["yulanurl"] = url('/yulan/' . $var['catid'] . '/' . $var['id']);
					if (!empty($var['content'])) $list[$key]["content"] = uhtmlspecialchars_decode($var["content"]);
					$modelarr = $this->db->find("select modelid  from `#yunyecms_category` where `id`= {$var['catid']}");
					if ($modelarr) {
						$list[$key]["modelid"] = $modelarr["modelid"];
					}
				}
			}
			$page = $pagearr["page"];
		}
		include tpl('lists', 'ucontent');
	}

	public function infolist_add()
	{
		$seo['title'] = $this->lang["seotitle"];
		$seo['keywords'] = $this->lang["seokey"];
		$seo['description'] = $this->lang["seodesc"];
		$cfg = $this->cfg;
		$lang = $this->lang;
		$rootcat = $this->rootcat;
		$cat = $this->cat;
		$rootcatid = $rootcat["id"];
		islogin();
		$member = $this->member;
		$userid = $this->member['id'];
		$tablename = "m_" . $this->curmodel['tablename'];
		$modelfields = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']} and language=1 and issys=0 and isadd=1 order by ordernum ");
		$morepicfield = $this->db->find("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']} and  issys=1 and fdname='morepic'");
		$membergroup = $this->db->select("select * from `#yunyecms_membergroup` order by ordernum asc");
		if (!empty($_REQUEST["id"])) {
			$parnav = '<li class=\"breadcrumb-item\"><a href=\"' . url_admin('init', "category") . '\" target=\"maincontent\">内容</a></li><li class=\"breadcrumb-item\"><a href=\"' . url_admin('lists', 'content', array("catid" => $this->cat['id'])) . '\" target=\"maincontent\">' . $this->rootcat['title'] . '</a></li><li class=\"breadcrumb-item active\">' . $this->cat['title'] . '</li>';
			$id = trim($_REQUEST["id"]);
			if (!is_numeric($id)) {
				messagebox("参数必须为数字，谢谢!", $_SERVER['HTTP_REFERER']);
			}
			$id = usafestr($id);
			$rsinfo = $this->db->find("select * from `#yunyecms_{$tablename}` where `id`= {$id}");
			if (empty($rsinfo)) {
				messagebox("信息不存在", $_SERVER['HTTP_REFERER']);
			}
			$morepic = $rsinfo["morepic"];
			if (!empty($morepic)) {
				$morepicarr = unserialize($morepic);
				$morepicstr = implode(",", $morepicarr);
			}
			$yyact = "edit";
		} else {
			$yyact = yyact_get("add");
			$parnav = '<li class=\"breadcrumb-item\"><a href=\"' . url_admin('init', "category") . '\" target=\"maincontent\">内容</a></li><li class=\"breadcrumb-item\"><a href=\"' . url_admin('lists', 'content', array("catid" => $this->cat['id'])) . '\" target=\"maincontent\">' . $this->rootcat['title'] . '</a></li><li class=\"breadcrumb-item active\">' . $this->cat['title'] . '</li>';
			$catid = $this->cat['id'];
			$strmaxarray = $this->db->find("select max(ordernum) as maxorder  from `#yunyecms_{$tablename}` where `catid`= {$this->cat['id']}");
			$strmax = $strmaxarray["maxorder"] + 1;
		}
		if (isset($_POST["yyact"])) {
			$_POST = ustripslashes($_POST);
			$modelfields_all = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']}  and issys=0 ");
			if (!empty($_POST['morepic'])) {
				$morepic = $_POST['morepic'];
				$morepicstr = explode(",", $morepic);
				$morepicstr = serialize($morepicstr);
				$data["morepic"] = $morepicstr;
			}
			$data["ispower"] = usafestr(trim($_POST["ispower"]));
			$data["catid"] = usafestr(trim($_POST["catid"]));
			$data["isgood"] = empty($_POST["isgood"]) ? 0 : usafestr(trim($_POST["isgood"]));
			$data["title"] = usafestr(trim($_POST["title"]));
			$data["pic"] = uhtmlspecialchars(trim($_POST["pic"]));
			$data["exlink"] = uhtmlspecialchars(trim($_POST["exlink"]));
			if (uhtmlspecialchars(trim($_POST["picfile"]))) $data["picfile"] = uhtmlspecialchars(trim($_POST["picfile"]));
			$data["summary"] = usafestr(trim($_POST["summary"]));
			$data["seotitle"] = usafestr(trim($_POST["seotitle"]));
			$data["seokeywords"] = usafestr(trim($_POST["seokeywords"]));
			$data["seodesc"] = usafestr(trim($_POST["seodesc"]));
			$data["ordernum"] = usafestr(trim($_POST["ordernum"]));
			$data["status"] = 1;
			$data["lang"] = 1;
			foreach ($modelfields_all as $key => $var) {
				$fdname = $var['fdname'];
				$formctrl = $var['formctrl'];
				$fdtitle = $var['fdtitle'];
				$isunique = $var['isunique'];
				if (isset($_POST[$fdname]) && $_POST[$fdname] != '') {
					$data[$fdname] = uhtmlspecialchars($_POST[$fdname]);
				}
				if ($formctrl == 'checkbox') {
					$postfdname = $_POST[$fdname];
					if (!empty($postfdname)) {
						$postfdname = implode(",", $postfdname);
						$postfdname = str_replace("\n", "", $postfdname);
						$data[$fdname] = $postfdname;
					}
				}
			}
			if (empty($data["title"])) {
				messagebox("标题不能为空，谢谢!", $_SERVER['HTTP_REFERER']);
			}
			if (empty($data["catid"])) {
				messagebox("栏目不能为空，请重新选择!", $_SERVER['HTTP_REFERER']);
			}
			if (!is_numeric($data["catid"])) {
				messagebox("栏目参数错误，请重新选择!", $_SERVER['HTTP_REFERER']);
			}
			$token = trim($_POST["token"]);
			if (empty($token) || $token != $_SESSION['token']) {
				messagebox(Lan('illegal_submit'));
			}
			$catid = $data["catid"];
			if ($_POST["yyact"] == "add") {
				$data["addtime"] = time();
				$data["updatetime"] = $data["addtime"];
				$data["userid"] = $userid;
				$retres = $this->db->insert($data, $tablename, true);
				if ($retres) {
					$datasyn['syn'] = $retres;
					$datasyn['number'] = $retres;
					$retres = $this->db->update($datasyn, "id={$retres}", $tablename);
					$msgcontent['mod'] = ROUTE_M;
					$msgcontent['act'] = ROUTE_A;
					$msgcontent['ctrl'] = ROUTE_C;
					$msgcontent['table'] = $tablename;
					$msgcontent['id'] = serialize($id);
					$msgcontent = serialize($msgcontent);
					$msgtitle = "添加{$this->cat['title']}信息—" . $data["title"];
					$remsg = savemsg($msgtitle, 8, $msgcontent, $retres);
					messagebox("添加{$this->cat['title']}信息成功！", url('member/ucontent/lists', array('catid' => $catid)), "success");
				} else {
					messagebox("添加{$this->cat['title']}信息失败！", url('member/ucontent/lists', array('catid' => $catid)), "error");
				}
			}
			if ($_POST["yyact"] == "edit") {
				$id = $_POST["id"];
				$data["addtime"] = strtotime(trim($_POST["addtime"]));
				$data["updatetime"] = time();
				if (!$this->check_exist($id)) {
					messagebox("该内容不存在！", url('member/ucontent/lists', array('catid' => $catid)), "warn");
				}
				$retres = $this->db->update($data, "id={$id}", $tablename);
				if ($retres) {
					$msgcontent['mod'] = ROUTE_M;
					$msgcontent['act'] = ROUTE_A;
					$msgcontent['ctrl'] = ROUTE_C;
					$msgcontent['table'] = $tablename;
					$msgcontent['id'] = serialize($id);
					$msgcontent = serialize($msgcontent);
					$msgtitle = "更新{$this->cat['title']}信息—" . $data["title"];
					$remsg = savemsg($msgtitle, 8, $msgcontent, $id);
					messagebox("更新{$this->cat['title']}信息成功！", url('member/ucontent/lists', array('catid' => $catid)), "success");
				} else {
					messagebox("更新{$this->cat['title']}信息失败！", url('member/ucontent/lists', array('catid' => $catid)), "error");
				}
			}
		} else {
			$token = ugetcookie("loginrnd");
			$_SESSION['token'] = $token;
		}
		require tpl('infolist_add', 'ucontent');
	}

	public function singlepage()
	{
		if (!empty($_REQUEST["catid"])) {
			$tablename = "m_" . $this->curmodel['tablename'];
			$modelfields = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']} and language=1 and issys=0 ");
			$seo['title'] = $this->lang["seotitle"];
			$seo['keywords'] = $this->lang["seokey"];
			$seo['description'] = $this->lang["seodesc"];
			$cfg = $this->cfg;
			$lang = $this->lang;
			$rootcat = $this->rootcat;
			$cat = $this->cat;
			$rootcatid = $rootcat["id"];
			islogin();
			$member = $this->member;
			$userid = $this->member['id'];
			$catid = $_REQUEST['catid'];
			if (!is_numeric($catid)) {
				messagebox("参数必须为数字！");
			}
			$catid = usafestr(trim($catid));
			$parentid = getparentid($catid);
			if ($catid == $rootcatid) {
				$subcatarr = $this->db->find("select id from `#yunyecms_category` where pid='{$rootcatid}' order by ordernum  limit 0,1");
				if ($subcatarr) $scatid = $subcatarr['id'];
			} else {
				if ($parentid == $rootcatid) {
					$scatid = $catid;
				} else {
					$ppid = getparentid($parentid);
					if ($ppid == $rootcatid) $scatid = $parentid;
				}
			}

			$check = $this->db->GetCount("select count(*) from `#yunyecms_{$tablename}`  where catid='{$catid}' and userid='{$userid}'");
			if ($check <= 0) {
				$data['catid'] = $catid;
				$data['userid'] = $userid;
				$data['title'] = $this->cat['title'];
				$data['seotitle'] = $this->cat['title'];
				$data['seokeywords'] = $this->cat['keywords'];
				$data['seodesc'] = $this->cat['description'];
				$retres = $this->db->insert($data, $tablename);
			}
			$rsinfo = $this->db->find("select * from `#yunyecms_{$tablename}` where `catid`= '{$catid}'  and userid='{$userid}' ");
			if (empty($rsinfo)) {
				messagebox("栏目不存在！");
			}
			$yyact = "edit";
		} else {
			messagebox("栏目参数错误，请重新选择!");
		}

		if (isset($_POST["yyact"])) {
			$modelfields_all = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']}  and issys=0 ");
			$_POST = ustripslashes($_POST);
			$data["catid"] = usafestr(trim($_POST["catid"]));
			$data["userid"] = $userid;
			$data["title"] = usafestr(trim($_POST["title"]));
			$data["pic"] = uhtmlspecialchars(trim($_POST["pic"]));
			$data["summary"] = usafestr(trim($_POST["summary"]));
			$data["seotitle"] = usafestr(trim($_POST["seotitle"]));
			$data["seokeywords"] = usafestr(trim($_POST["seokeywords"]));
			$data["seodesc"] = usafestr(trim($_POST["seodesc"]));
			if (isset($_POST["content"])) {
				$data["content"] = uhtmlspecialchars(trim($_POST["content"]));
			}
			foreach ($modelfields_all as $key => $var) {
				$fdname = $var['fdname'];
				if (isset($_POST[$fdname])) {
					$data[$fdname] = uhtmlspecialchars(trim($_POST[$fdname]));
				}
			}
			$token = trim($_POST["token"]);
			if (empty($token) || $token != $_SESSION['token']) {
				messagebox(Lan('illegal_submit'));
			}
			if (empty($data["title"])) {
				messagebox("标题不能为空，谢谢!", $_SERVER['HTTP_REFERER']);
			}
			if (empty($data["catid"])) {
				messagebox("栏目不能为空，请重新选择!", $_SERVER['HTTP_REFERER']);
			}
			if (!is_numeric($data["catid"])) {
				messagebox("栏目参数错误，请重新选择!", $_SERVER['HTTP_REFERER']);
			}
			$catid = $data["catid"];
			if ($_POST["yyact"] == "edit") {
				$catid = $_POST["catid"];
				if (!$this->check_exist_singlepage($catid, $userid)) {
					messagebox("该内容不存在！");
				}
				$retres = $this->db->update($data, array('catid' => $catid, 'userid' => $userid), $tablename);
				if ($retres) {
					$doing = "更新{$this->cat['title']}信息—" . $data["title"];
					$msgcontent['mod'] = ROUTE_M;
					$msgcontent['act'] = ROUTE_A;
					$msgcontent['ctrl'] = ROUTE_C;
					$msgcontent['table'] = $tablename;
					$msgcontent['catid'] = $catid;
					$msgcontent['userid'] = $userid;
					$msgcontent = serialize($msgcontent);
					$msgtitle = "更新{$this->cat['title']}信息—" . $data["title"];
					$remsg = savemsg($msgtitle, 8, $msgcontent, $catid);
					messagebox("更新{$this->cat['title']}信息成功！", url('member/ucontent/singlepage', array('catid' => $catid)), "success");
				} else {
					messagebox("更新{$this->cat['title']}信息失败！", url_admin('member/ucontent/singlepage', array('catid' => $catid)), "error");
				}
			}
		} else {
			$token = ugetcookie("loginrnd");
			$_SESSION['token'] = $token;
		}
		require tpl('singlepage', 'ucontent');
	}

	//加载首页
	public function customform()
	{
		if (!getroot('info', 'view')) {
			messagebox(Lan('no_permission_infoview'), 'back', "warn");
		} else {
			$catpower = fetch_cat_power();

			if (!empty($catpower)) {
				$catpwerid = get_power_catid($catpower);
			}
		}
		$tablename = "m_" . $this->curmodel['tablename'];
		$parnav = '<li class=\"breadcrumb-item\"><a href=\"' . url_admin('init', "category") . '\" target=\"maincontent\">内容</a></li><li class=\"breadcrumb-item\"><a href=\"' . url_admin('lists', 'content', array("catid" => $this->cat['id'])) . '\" target=\"maincontent\">' . $this->rootcat['title'] . '</a></li><li class=\"breadcrumb-item active\">' . $this->cat['title'] . '</li>';
		if (!getroot('users', 'logs')) {
			messagebox(Lan('no_permission'), 'back', "warn");
		}
		$modelfields = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']}  and isdisplay=1 ");
		$pagesize = 20;
		$sqlquery = "select * from `#yunyecms_{$tablename}`  ";
		$where = " where 1=1  ";
		$sqlcnt = " select count(*) from `#yunyecms_{$tablename}` ";
		$order = " order by `addtime` desc ";
		if (isset($_REQUEST)) {
			if (!empty($_REQUEST["searchkey"])) {
				$searchkey = usafestr(trim($_REQUEST["searchkey"]));
				$where = $where . " and ( `title`  like '%{$searchkey}%' or  `title_en`  like '%{$searchkey}%' )";
			}
		}
		if (!empty($_REQUEST['catid'])) {
			$catid = trim($_REQUEST['catid']);
			if (!is_numeric($catid)) {
				messagebox("错误的参数", "back", 'warn');
			}
			$catid = usafestr($catid);
			$subcat = get_cat_child($catid);
			$catidstr = implode(',', $subcat);
			$newcat = array_intersect($subcat, $catpwerid);
			$messagetip = "暂时没有{$this->cat["title"]}信息";
			if (!empty($catpwerid)) {
				if (empty($newcat)) {
					messagebox("您没有管理{$this->cat["title"]}信息的权限", 'back', "warn");
				} else {
					$catidstr = implode(',', $newcat);
					$where = $where . " and catid in($catidstr)";
				}
			} else {
				$where = $where . " and catid in($catidstr)";
			}
		}

		$pagearr = $this->db->pagelist($sqlcnt, $sqlquery, $where, $order, $pagesize);
		if ($pagearr["count"] != 0) {
			$list = $pagearr["query"];
			foreach ($list as $key => $var) {
				$modelarr = $this->db->find("select modelid  from `#yunyecms_category` where `id`= {$var['catid']}");
				if ($modelarr) {
					$list[$key]["modelid"] = $modelarr["modelid"];
					if (!empty($var["userid"])) {
						$list[$key]["user"] = $this->db->getbyid($var["userid"], "member");
					}
				}
			}
			$pages = $pagearr["page"];
		}
		require tpl_adm('customform');
	}


	public function customform_view()
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$modelfields = $this->db->select("select * from `#yunyecms_modelfields`  where modelid={$this->curmodel['modelid']}  and isadd=1 ");
		if (!empty($_REQUEST["id"])) {
			$parnav = '<li class=\"breadcrumb-item\"><a href=\"' . url_admin('init', "category") . '\" target=\"maincontent\">内容</a></li><li class=\"breadcrumb-item\"><a href=\"' . url_admin('lists', 'content') . '\" target=\"maincontent\">' . $this->rootcat['title'] . '</a></li><li class=\"breadcrumb-item active\">' . $this->cat['title'] . '</li>';
			$id = trim($_REQUEST["id"]);
			if (!is_numeric($id)) {
				messagebox("参数必须为数字，谢谢!", $_SERVER['HTTP_REFERER']);
			}
			$id = usafestr($id);
			$rsinfo = $this->db->find("select * from `#yunyecms_{$tablename}` where `id`= {$id}");
			if (empty($rsinfo)) {
				messagebox("栏目不存在", $_SERVER['HTTP_REFERER']);
			} else {
				$strsql = "update `#yunyecms_{$tablename}` set isview=1 where id=" . $id . "";
				$this->db->query($strsql);
			}
			$catid = $this->cat['id'];
		}
		require tpl_adm('customform_view');
	}


	public function finaldelete()
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$catid = $this->cat["id"];
		$id = $_REQUEST["id"];
		if (!is_array($id)) {
			$id = compact('id');
		}
		$idarray = $id;
		foreach ($idarray as $key => $var) {
			if (!is_numeric($var)) {
				messagebox("错误的参数！", 'back', "warn");
			}
			$var = usafestr($var);
			$curmodelnr = $this->db->find("select id,pic,content from `#yunyecms_{$tablename}` where `id`= {$var}");
			if ($curmodelnr) {
				$thumb = $curmodelnr["pic"];
				$ct_content = $curmodelnr["content"];
				$ct_content_img = getcontentimg($ct_content);
				if (!empty($thumb)) {
					file_delete($thumb);
				}
				foreach ($ct_content_img as $key3 => $var3) {
					file_delete($var3);
				}
			}
		}
		if (isset($idarray)) {
			$idarray = implode(",", $idarray);
			$retres = $this->db->delete("id in ({$idarray})", $tablename);
			if ($retres !== false) {
				$msgcontent['mod'] = ROUTE_M;
				$msgcontent['act'] = ROUTE_A;
				$msgcontent['ctrl'] = ROUTE_C;
				$msgcontent['table'] = $tablename;
				$msgcontent['id'] = serialize($id);
				$msgcontent = serialize($msgcontent);
				$msgtitle = "删除{$this->cat['title']}信息：{$idarray} ";
				$remsg = savemsg($msgtitle, 8, $msgcontent, $insertid);
				messagebox(Lan('admin_delete_success'), $_SERVER['HTTP_REFERER'], "success");
			} else {
				messagebox(Lan('admin_delete_error'), $_SERVER['HTTP_REFERER'], "warn");
			}
		} else {
			messagebox(Lan('admin_delete_error'), $_SERVER['HTTP_REFERER'], "warn");
		}
	}






	public function customformdelete()
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$catid = $this->cat["id"];
		if (!getroot('info', 'del')) {
			messagebox(Lan('no_permission_infodel'), 'back', "warn");
		} else {
			if (!get_cat_power($catid, "del")) {
				messagebox("您没有删除{$this->cat["title"]}信息的权限", 'back', "warn");
			}
		}

		$id = $_REQUEST["id"];
		if (!is_array($id)) {
			$id = compact('id');
		}
		$idarray = $id;
		if (isset($idarray)) {
			$idarray = implode(",", $idarray);
			$retres = $this->db->delete("id in ({$idarray})", $tablename);
			if ($retres !== false) {
				$msgcontent['mod'] = ROUTE_M;
				$msgcontent['act'] = ROUTE_A;
				$msgcontent['ctrl'] = ROUTE_C;
				$msgcontent['table'] = $tablename;
				$msgcontent['id'] = serialize($id);
				$msgcontent = serialize($msgcontent);
				$msgtitle = "删除{$this->cat['title']}信息：{$idarray} ";
				$remsg = savemsg($msgtitle, 8, $msgcontent, $insertid);
				messagebox(Lan('admin_delete_success'), $_SERVER['HTTP_REFERER'], "success");
			} else {
				messagebox(Lan('admin_delete_error'), $_SERVER['HTTP_REFERER'], "warn");
			}
		} else {
			messagebox(Lan('admin_delete_error'), $_SERVER['HTTP_REFERER'], "warn");
		}
	}





	public function check()
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$this->infocheck($tablename, $this->db);
	}

	public function nocheck()
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$this->infonocheck($tablename, $this->db);
	}



	private function infocheck($tablename, $db)
	{
		$id = $_REQUEST["id"];
		if (!is_array($id)) {
			$id = compact('id');
		}
		if (empty($tablename)) {
			messagebox("非法操作!", $_SERVER['HTTP_REFERER'], "warn");
		}
		$idarray = $id;
		if (isset($idarray)) {
			foreach ($idarray as $key => $var) {
				if (!is_numeric($var)) {
					messagebox("错误的参数！", 'back', "warn");
				}
				$idarray[$key] = usafestr($var);
			}
			$idarray = implode(",", $idarray);
			$retres = $db->query("update `#yunyecms_{$tablename}` set  status=1 where id in({$idarray}) ");
			if (false !== $retres) {
				messagebox("信息审核成功!", $_SERVER['HTTP_REFERER'], "success");
			} else {
				messagebox("信息审核失败!", $_SERVER['HTTP_REFERER'], "warn");
			}
		}
	}



	private function infonocheck($tablename, $db)
	{
		$id = $_REQUEST["id"];
		if (!is_array($id)) {
			$id = compact('id');
		}
		if (empty($tablename)) {
			messagebox("非法操作!", $_SERVER['HTTP_REFERER'], "warn");
		}
		$idarray = $id;
		if (isset($idarray)) {
			foreach ($idarray as $key => $var) {
				if (!is_numeric($var)) {
					messagebox("错误的参数！", 'back', "warn");
				}
				$idarray[$key] = usafestr($var);
			}
			$idarray = implode(",", $idarray);
			$retres = $db->query("update `#yunyecms_{$tablename}` set  status=0 where id in({$idarray}) ");
			if (false !== $retres) {
				messagebox("信息取消审核成功!", $_SERVER['HTTP_REFERER'], "success");
			} else {
				messagebox("信息取消审核失败!", $_SERVER['HTTP_REFERER'], "warn");
			}
		}
	}

	private function check_exist($id)
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$id = trim($id);
		if (empty($id)) {
			return false;
		} else {
			if (!is_numeric($id)) {
				return false;
			}
			if ($this->db->find("select count(*) as cnt from `#yunyecms_{$tablename}` where `id`= {$id}")) {
				return true;
			}
		}
	}
	private function check_exist_singlepage($catid, $userid)
	{
		$tablename = "m_" . $this->curmodel['tablename'];
		$catid = trim($catid);
		if (empty($catid)) {
			return false;
		} else {
			if (!is_numeric($catid)) {
				return false;
			}
			if ($this->db->find("select count(*) as cnt from `#yunyecms_{$tablename}` where `catid`= '{$catid}'  and userid='{$userid}' ")) {
				return true;
			}
		}
	}
}
