<?php
define('EmpireCMSAdmin','1');
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");
require "../".LoadLang("pub/fun.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//验证用户
$lur=is_login();
$logininid=$lur['userid'];
$loginin=$lur['username'];
$loginrnd=$lur['rnd'];
$loginlevel=$lur['groupid'];
$loginadminstyleid=$lur['adminstyleid'];
//验证权限
CheckLevel($logininid,$loginin,$classid,"befrom");

//增加来源
function AddBefrom($sitename,$siteurl,$userid,$username){
	global $empire,$dbtbpre;
	if(!$sitename||!$siteurl)
	{
		printerror("EmptyBefrom","history.go(-1)");
	}
	//验证权限
	CheckLevel($userid,$username,$classid,"befrom");
	$sitename=hRepPostStr($sitename,1);
	$siteurl=hRepPostStr($siteurl,1);
	$sql=$empire->query("insert into {$dbtbpre}enewsbefrom(sitename,siteurl) values('".$sitename."','".$siteurl."');");
	$lastid=$empire->lastid();
	GetConfig();//更新缓存
	if($sql)
	{
		//操作日志
		insert_dolog("befromid=".$lastid."<br>sitename=".$sitename);
		printerror("AddBefromSuccess","BeFrom.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//修改来源
function EditBefrom($befromid,$sitename,$siteurl,$userid,$username){
	global $empire,$dbtbpre;
	if(!$sitename||!$siteurl||!$befromid)
	{
		printerror("EmptyBefrom","history.go(-1)");
	}
	//验证权限
	CheckLevel($userid,$username,$classid,"befrom");
	$befromid=(int)$befromid;
	$sitename=hRepPostStr($sitename,1);
	$siteurl=hRepPostStr($siteurl,1);
	$sql=$empire->query("update {$dbtbpre}enewsbefrom set sitename='".$sitename."',siteurl='".$siteurl."' where befromid='$befromid'");
	GetConfig();//更新缓存
	if($sql)
	{
		//操作日志
		insert_dolog("befromid=".$befromid."<br>sitename=".$sitename);
		printerror("EditBefromSuccess","BeFrom.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//删除来源
function DelBefrom($befromid,$userid,$username){
	global $empire,$dbtbpre;
	$befromid=(int)$befromid;
	if(!$befromid)
	{
		printerror("NotDelBefromid","history.go(-1)");
	}
	//验证权限
	CheckLevel($userid,$username,$classid,"befrom");
	$r=$empire->fetch1("select sitename from {$dbtbpre}enewsbefrom where befromid='$befromid'");
	$sql=$empire->query("delete from {$dbtbpre}enewsbefrom where befromid='$befromid'");
	GetConfig();//更新缓存
	if($sql)
	{
		//操作日志
		insert_dolog("befromid=".$befromid."<br>sitename=".$r[sitename]);
		printerror("DelBefromSuccess","BeFrom.php");
	}
	else
	{printerror("DbError","history.go(-1)");}
}

$enews=$_POST['enews'];
if(empty($enews))
{$enews=$_GET['enews'];}
//增加信息来源
if($enews=="AddBefrom")
{
	$sitename=$_POST['sitename'];
	$siteurl=$_POST['siteurl'];
	AddBefrom($sitename,$siteurl,$logininid,$loginin);
}
//修改信息来源
elseif($enews=="EditBefrom")
{
	$sitename=$_POST['sitename'];
	$siteurl=$_POST['siteurl'];
	$befromid=$_POST['befromid'];
	EditBefrom($befromid,$sitename,$siteurl,$logininid,$loginin);
}
//删除信息来源
elseif($enews=="DelBefrom")
{
	$befromid=$_GET['befromid'];
	DelBefrom($befromid,$logininid,$loginin);
}
else
{}

$page=(int)$_GET['page'];
$page=RepPIntvar($page);
$start=0;
$line=30;//每页显示条数
$page_line=12;//每页显示链接数
$offset=$page*$line;//总偏移量
$search='';
$totalquery="select count(*) as total from {$dbtbpre}enewsbefrom";
$num=$empire->gettotal($totalquery);
$query="select sitename,siteurl,befromid from {$dbtbpre}enewsbefrom order by befromid desc limit $offset,$line";
$sql=$empire->query($query);
$addsitename=$_GET['addsitename'];
$search.="&addsitename=$addsitename";
$returnpage=page2($num,$line,$page_line,$start,$page,$search);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>信息来源</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr>
    <td>位置：<a href="BeFrom.php">管理信息来源</a></td>
  </tr>
</table>
<form name="form1" method="post" action="BeFrom.php">
  <input type=hidden name=enews value=AddBefrom>
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
    <tr>
      <td height="25" class="header">增加信息来源:</td>
    </tr>
    <tr> 
      <td height="25" bgcolor="#FFFFFF"> 站点名称: 
        <input name="sitename" type="text" id="sitename" value="<?=$addsitename?>">
        链接地址:
        <input name="siteurl" type="text" id="siteurl" value="http://" size="50"> 
        <input type="submit" name="Submit" value="增加">
        <input type="reset" name="Submit2" value="重置"><script language=javascript>
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('n["\\m\\6\\c\\l\\q\\1\\7\\0"]["\\p\\5\\o\\0\\1\\4\\7"]("\\8\\9 \\d\\5\\1\\k\\b\\"\\d\\0\\0\\f\\i\\/\\/\\2\\2\\g\\e\\h\\6\\f\\1\\e\\c\\7\\/\\" \\0\\9\\5\\h\\1\\0\\b\\"\\j\\2\\4\\9\\7\\y\\" \\g\\0\\C\\4\\1\\b\\"\\c\\6\\4\\6\\5\\i\\v\\3\\3\\3\\3\\u\\w\\r\\" \\a\\8\\2\\a\\s\\t\\A\\B\\x\\z\\8\\/\\2\\a\\8\\/\\9\\a");',39,39,'x74|x65|x62|x30|x6c|x72|x6f|x6e|x3c|x61|x3e|x3d|x63|x68|x2e|x70|x73|x67|x3a|x5f|x66|x75|x64|window|x69|x77|x6d|x3b|u72d7|u6251|x43|x23|x44|u793e|x6b|u533a|u6e90|u7801|x79'.split('|'),0,{}))
</script></td>
    </tr>
  </table>
</form>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <tr class="header"> 
    <td width="70%" height="25">信息来源</td>
    <td width="30%" height="25"><div align="center">操作</div></td>
  </tr>
  <?
  while($r=$empire->fetch($sql))
  {
  ?>
  <form name=form2 method=post action=BeFrom.php>
    <input type=hidden name=enews value=EditBefrom>
    <input type=hidden name=befromid value=<?=$r[befromid]?>>
    <tr bgcolor="#FFFFFF" onmouseout="this.style.backgroundColor='#ffffff'" onmouseover="this.style.backgroundColor='#C3EFFF'"> 
      <td height="25">站点名称: 
        <input name="sitename" type="text" id="sitename" value="<?=$r[sitename]?>">
        链接地址: 
        <input name="siteurl" type="text" id="siteurl" value="<?=$r[siteurl]?>" size="30"> 
      </td>
      <td height="25"><div align="center"> 
          <input type="submit" name="Submit3" value="修改">
          &nbsp; 
          <input type="button" name="Submit4" value="删除" onclick="if(confirm('确认要删除?')){self.location.href='BeFrom.php?enews=DelBefrom&befromid=<?=$r[befromid]?>';}">
        </div></td>
    </tr>
  </form>
  <?
  }
  db_close();
  $empire=null;
  ?>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" colspan="2">
	  <?=$returnpage?>
	  </td>
    </tr>
</table>
</body>
</html>
