<?php
/*
 * @Author: 云业科技
 * @Date: 2023-01-05 00:12:05
 * @LastEditTime: 2023-01-05 18:34:49
 * @LastEditors: 云业科技
 * @Description: 
 * @FilePath: \v221.yunyecms.yunyehui.cn\core\lib\base.class.php
 * 
 */
defined('IN_YUNYECMS') or exit('No direct script access allowed');
session_save_path(YUNYECMS_SESSION);
session_start();
class base
{
	public $lang;
	public $cat;
	public $rootcat;
	public $cfg;
	public $member;
	public $db;
	public $ismobie;
	public $iswechat;
	public $notice;
	function __construct()
	{
		header("Content-type: text/html; charset=utf-8");
		global $lang;
		global $cfg;
		$this->db = core::load_model('common_model');
		$this->cfg = getcfg();
		if (!empty($_GET['lang']) && (is_numeric($_GET['lang']) || ctype_alnum($_GET['lang']))) {
			$this->lang = getcurlang(usafestr(trim($_GET['lang'])));
		} else {
			$this->lang = getdefaultlang();
		}
		if (is_mobile()) $this->ismobile = true;
		if (is_wechat_browser()) $this->iswechat = true;
		$this->lang = dolang($this->lang, $this->cfg);
		$this->lang['logo'] = dopic($this->lang['logo']);
		$this->lang['icon'] = dopic($this->lang['icon']);
		$this->lang['qrcode'] = dopic($this->lang['qrcode']);
		$this->lang['footlogo'] = dopic($this->lang['footlogo']);
		$this->lang['logo_mem'] = dopic($this->lang['logo_mem']);
		$this->lang['logo_mem_mini'] = dopic($this->lang['logo_mem_mini']);
		$this->lang['copyright'] = doimgs($this->lang['copyright']);
		$lang = $this->lang;
		$cfg = $this->cfg;
		define('LAN', empty($this->lang['landir']) ? "cn" : $this->lang['landir']);
		define('LAN_DEFAULT', $this->lang['isdefault']);
		define('CTD', empty($this->lang['theme']) ? "default" : $this->lang['theme']);
		check_parameter($_GET);
		if (!empty($cfg['mobilecfg']["displaymode"])) {
			if ($this->ismobile) {
				define('TPL', THEME . CTD . "/" . LAN . "_mobile/");
			} else {
				define('TPL', THEME . CTD . "/" . LAN . "/");
			}
		} else {
			define('TPL', THEME . CTD . "/" . LAN . "/");
		}
		if (!empty($_REQUEST['catid'])) {
			$catid = trim($_REQUEST['catid']);
			if (!is_numeric($catid)) {
				messagebox("错误的参数", "back", 'warn');
			}
			$catid = usafestr($catid);
			$catid = getreal_catid($catid, $this->lang['id'], 'category', $this->db);
			$this->cat = getbyid($catid);
			$this->rootcat = getbyid(getppid($catid));
			if (strlen(RD) > 0 && stripos($this->rootcat["pic"], RD) === FALSE) {
				$this->rootcat["pic"] = !empty($this->rootcat["pic"]) ? RD . $this->rootcat["pic"] : '';
				RD . $this->rootcat["pic"];
			};
		}
		if ($this->cfg['isclose'] == 1) {
			include tpl("closesite");
			exit;
		}
		$this->member = checklogin();
		if ($this->member) {
			if ($this->member["id"]) {
				$this->member['cartnum'] = getcount("select count(*) from `#yunyecms_cart` where userid='{$this->member["id"]}'");
				$this->member['ordernum'] = getcount("select count(*) from `#yunyecms_orders` where userid='{$this->member["id"]}'");
				$this->member['noticenum'] = getcount("select count(*) from `#yunyecms_notice` where status=1 and touserid={$this->member["id"]}");
				$this->notice = $this->db->select("select * from #yunyecms_notice where status=1 and  touserid={$this->member["id"]}  order by addtime desc limit 0,10");
			}
		}
	}
}
