<?php
if(!defined('empirecms'))
{
	exit();
}

//显示提示页面
function ShowViewInfoMsg($r,$msg){
	global $public_r,$check_path,$level_r;
	//查看权限
	if(empty($r['userfen']))
	{
		$ViewLevel="需要 [".$level_r[$r[groupid]][groupname]."] 级别以上才能查看。";
	}
	else
	{
		$ViewLevel="需要 [".$level_r[$r[groupid]][groupname]."] 级别以上与扣除 ".$r['userfen']." 点积分才能查看。";
	}
	$url="<a href='../../../'>首页</a>&nbsp;>&nbsp;<a href='../cp'>控制面板</a>&nbsp;>&nbsp;查看信息";
	include($check_path."e/data/template/cp_1.php");
	?>
	<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <tr class="header"> 
    <td height="25">提示信息</td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="25"><?=$msg?></td>
  </tr>
</table>
<br>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <tr class="header"> 
    <td height="25" colspan="2">标题：
      <?=$r[title]?>
    </td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="25">查看权限：</td>
    <td height="25">
      <?=$ViewLevel?>
    </td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td width="17%" height="25">发布时间：</td>
    <td width="83%" height="25"> 
      <?=$r[newstime]?>
    </td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td height="25">信息简介：</td>
    <td height="25"> 
      <?=ReturnTheIntroField($r)?>
    </td>
  </tr>
	</table>
	<?php
	include($check_path."e/data/template/cp_2.php");
	exit();
}

//返回简介字段名
function ReturnTheIntroField($r){
	global $public_r,$check_tbname;
	$f=0;
	$sublen=100;//截取100个字
	if(strstr($public_r['savetxtf'],",".$check_tbname.".newstext,"))
	{
		$r['newstext']='';
		$f=1;
	}
	if($r['smalltext'])//简介
	{
		$value=$r['smalltext'];
	}
	elseif($r['newstext'])//新闻内容
	{
		$value=sub(strip_tags($r['newstext']),0,$sublen,false);
	}
	elseif($r['softsay'])//软件简介
	{
		$value=$r['softsay'];
	}
	elseif($r['flashsay'])//flash简介
	{
		$value=$r['flashsay'];
	}
	return $value;
}

//是否登陆
function ViewCheckLogin($infor){
	global $empire,$public_r,$user_tablename,$user_userid,$user_username,$user_userfen,$user_group,$user_groupid,$user_rnd,$user_zgroup,$user_userdate,$user_checked,$eloginurl,$toreturnurl,$gotourl;
	$userid=(int)getcvar('mluserid');
	$rnd=getcvar('mlrnd');
	if(!$userid)
	{
		if(!getcvar('returnurl'))
		{
			esetcookie("returnurl",$toreturnurl,0);
		}
		$msg="您还未登陆，<a href='$gotourl'><u>点击这里</u></a>进行登陆操作；注册请<a href='".$public_r['newsurl']."e/member/register'><u>点击这里</u></a>。";
		ShowViewInfoMsg($infor,$msg);
	}
	$cr=$empire->fetch1("select ".$user_checked.",".$user_userid.",".$user_username.",".$user_group.",".$user_userfen.",".$user_userdate.",".$user_zgroup." from ".$user_tablename." where ".$user_userid."='$userid' and ".$user_rnd."='$rnd' limit 1");
	if(!$cr[$user_userid])
	{
		EmptyEcmsCookie();
		if(!getcvar('returnurl'))
		{
			esetcookie("returnurl",$toreturnurl,0);
		}
		$msg="同一帐号只能一人在线，<a href='$gotourl'><u>点击这里</u></a>重新登陆；注册请<a href='".$public_r['newsurl']."e/member/register'><u>点击这里</u></a>。";
		ShowViewInfoMsg($infor,$msg);
	}
	if($cr[$user_checked]==0)
	{
		EmptyEcmsCookie();
		if(!getcvar('returnurl'))
		{
			esetcookie("returnurl",$toreturnurl,0);
		}
		$msg="您的帐号还未审核通过，<a href='$gotourl'><u>点击这里</u></a>重新登陆；注册请<a href='".$public_r['newsurl']."e/member/register'><u>点击这里</u></a>。";
		ShowViewInfoMsg($infor,$msg);
	}
	//默认会员组
	if(empty($cr[$user_group]))
	{
		$usql=$empire->query("update ".$user_tablename." set ".$user_group."='$user_groupid' where ".$user_userid."='".$cr[$user_userid]."'");
		$cr[$user_group]=$user_groupid;
	}
	//是否过期
	if($cr[$user_userdate])
	{
		if($cr[$user_userdate]-time()<=0)
		{
			OutTimeZGroup($cr[$user_userid],$cr[$user_zgroup]);
			$cr[$user_userdate]=0;
			if($cr[$user_zgroup])
			{
				$cr[$user_group]=$cr[$user_zgroup];
				$cr[$user_zgroup]=0;
			}
		}
	}
	$re[userid]=$cr[$user_userid];
	$re[username]=doUtfAndGbk($cr[$user_username],1);
	$re[userfen]=$cr[$user_userfen];
	$re[groupid]=$cr[$user_group];
	$re[userdate]=$cr[$user_userdate];
	$re[zgroupid]=$cr[$user_zgroup];
	return $re;
}

//查看权限函数
function CheckShowNewsLevel($infor){
	global $check_path,$level_r,$empire,$user_userfen,$user_userid,$user_tablename,$user_userdate,$gotourl,$toreturnurl,$public_r,$dbtbpre;
	$groupid=$infor['groupid'];
	$fh=$infor['fh'];
	$userfen=$infor['userfen'];
	$newsid=$infor['id'];
	$classid=$infor['classid'];
	//是否登陆
	$user_r=ViewCheckLogin($infor);
	//等于
	if($fh)
	{
		if($groupid<>$user_r[groupid])
		{
			if(!getcvar('returnurl'))
			{
				esetcookie("returnurl",$toreturnurl,0);
			}
			$msg="您所在的会员组，没有查看此信息的权限! <a href='$gotourl'><u>点击这里</u></a>重新登陆；注册请<a href='".$public_r['newsurl']."e/member/register'><u>点击这里</u></a>。";
			ShowViewInfoMsg($infor,$msg);
		}
	}
	//大于等于
	else
	{
		if($level_r[$groupid][level]>$level_r[$user_r[groupid]][level])
		{
			if(!getcvar('returnurl'))
			{
				esetcookie("returnurl",$toreturnurl,0);
			}
			$msg="您的会员级别不足(您的当前级别：".$level_r[$user_r[groupid]][groupname].")，没有查看此信息的权限! <a href='$gotourl'><u>点击这里</u></a>重新登陆；注册请<a href='".$public_r['newsurl']."e/member/register'><u>点击这里</u></a>。";
			ShowViewInfoMsg($infor,$msg);
		}
	}
	//扣点
	if(!empty($userfen))
	{
		//是否有历史记录
		$bakr=$empire->fetch1("select id,truetime from {$dbtbpre}enewsdownrecord where id='$newsid' and classid='$classid' and userid='$user_r[userid]' and online=2 order by truetime desc limit 1");
		if($bakr['id']&&(time()-$bakr['truetime']<=$public_r['redoview']*3600))
		{}
		else
		{
			if($user_r[userdate]-time()>0)//包月
			{}
			else
			{
				if($user_r[userfen]<$userfen)
				{
					if(!getcvar('returnurl'))
					{
						esetcookie("returnurl",$toreturnurl,0);
					}
					$msg="您的积分不足(您当前拥有的积分 ".$user_r[userfen]." 点)，没有查看此信息的权限! <a href='$gotourl'><u>点击这里</u></a>重新登陆；注册请<a href='".$public_r['newsurl']."e/member/register'><u>点击这里</u></a>。";
					ShowViewInfoMsg($infor,$msg);
				}
				//扣点
				$usql=$empire->query("update ".$user_tablename." set ".$user_userfen."=".$user_userfen."-".$userfen." where ".$user_userid."='$user_r[userid]'");
			}
			//备份下载记录
			$utfusername=$user_r['username'];
			BakDown($classid,$newsid,0,$user_r['userid'],$utfusername,$infor[title],$userfen,2);
		}
	}
}
//扣点
include($check_path."e/class/connect.php");
if(!defined('InEmpireCMS'))
{
	exit();
}
include($check_path."e/class/config.php");
include($check_path."e/class/db_sql.php");
include($check_path."e/class/user.php");
include($check_path."e/class/MemberLevel.php");
$link=db_connect();
$empire=new mysqlquery();
$check_tbname=RepPostVar($check_tbname);
$check_infoid=(int)$check_infoid;
$check_classid=(int)$check_classid;
$checkinfor=$empire->fetch1("select * from {$dbtbpre}ecms_".$check_tbname." where id='$check_infoid' and classid='$check_classid' limit 1");
if(!$checkinfor['id'])
{
	echo"<script>alert('此信息不存在');history.go(-1);</script>";
	exit();
}
if($checkinfor['groupid'])
{
	$toreturnurl=$_SERVER['PHP_SELF'];	//返回页面地址
	$gotourl=$eloginurl?$eloginurl:$public_r['newsurl']."e/member/login";	//登陆地址
	CheckShowNewsLevel($checkinfor);
}
db_close();
$empire=null;
?>