<?php
class shop{
	
	var $db;
	var $webUrl;
	var $tpl;
	
	function shop()
	{
		global $db,$tpl;
		$this -> db     = & $db;
		$this -> tpl    = & $tpl;
		$this -> view_user_times();
	}
	
	function get_custom_cat_list($type="")
	{
		global $config;
		$sql="select * from ".CUSTOM_CAT." where company_id='$_GET[uid]' $str order by nums asc";
		$this->db->query($sql);
		$re=$this->db->getRows();
		return $re;
	}
	
	function user_detail($uid)
	{	
		global $config,$action;
		$_GET["uid"]=$uid;
		
		if(is_numeric($uid))
			$sql="select * from ".COMPANY." where company_id='$uid'";
		else
			$sql="select * from ".COMPANY." where domain='$uid'";
		$this ->db ->query($sql);
		$com=$this ->db->fetchRow();
		if($com)
		{	
			//----------------------主联系人----------------------
			$re=$this->get_main_user($com['admin']);
			if(is_array($re))
				$com=array_merge($com,$re);
			//----------------------COMPANYCAT------------------
			if (!empty($com["catid"]))
			{
				$strcat=explode(",",$com["catid"]);
				$st=implode("','",$strcat);
				$sqlo="select cat  from ".COMPANYCAT." where catid in ('".$st."')";
				$this ->db ->query($sqlo);
				$catn=$this ->db->getRows();
				$com["catname"]='';
				foreach($catn as $vc)
				{
					$com["catname"].=$vc['cat'].'&nbsp;|&nbsp;';
				}
			}
			//----------------------所在国家-------------
			if($config['language']=='cn')
				$sqlo="select cname as countryname from ".COUNTRY." where id='".$com['country']."'";
			else
				$sqlo="select ename as countryname from ".COUNTRY." where id='".$com['country']."'";
			$this ->db ->query($sqlo);
            $com["country"]=$this->db->fetchField('countryname');
			//-----------------------会员组信息----------------------
			$ifpay=empty($com['ifpay'])?1:$com['ifpay'];
			include($config['webroot']."/config/usergroup.php");
			if(!empty($group[$ifpay]['logo']))
			{
				$com['medal']="<img src=".$group[$ifpay]['logo']." />";
				$com['group_name']=$group[$ifpay]['name'];
			}
			$com['rank']=$group[$ifpay]['name'];
			include($config['webroot']."/config/module_company_config.php");
			$com['jsbook']=$module_company_config['jsbook_'.$ifpay];
			unset($group);
			//----------------------------------------------------
			$this ->tpl->assign("com",$com);
			return $com;
		}
	}
	
	function get_main_user($uid)
	{
		$sql="select userid,statu,name,position,qq,msn,email,mobile,province,city,skype,logo as plogo,regtime,company_id
				from ".ALLUSER." WHERE is_admin=1 and userid='$uid'";
		$this->db->query($sql);
		$re=$this->db->fetchRow();
		return $re;
	}
	
	function get_user_detail($uid,$type=1)
	{
		$sql="select intro,logo as img from ".CDETAIL." where company_id='$uid' and type=$type";
		$this->db->query($sql);
		return $this->db->fetchRow();
	}
	
	
	function view_user_times()
	{
		$sql="update ".COMPANY." SET view_times=view_times+1 WHERE company_id='$_GET[uid]'";
		$this ->db ->query($sql);
	}
	
	function get_business_validate()
	{
		$sql="select statu from ".CERTIFICATION." where company_id='$_GET[uid]'";
		$this->db->query($sql);
		$re=$this->db->fetchRow();
		return isset($re['statu']) ? $re['statu'] : 0;
	}

}
?>
