<?php
define('EmpireCMSAdmin','1');
require("../../../e/class/connect.php");
require("../../../e/class/functions.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
//驗證用戶
$lur=is_login();
$logininid=(int)$lur['userid'];
$loginin=$lur['username'];
$loginrnd=$lur['rnd'];
$loginlevel=(int)$lur['groupid'];
$loginadminstyleid=(int)$lur['adminstyleid'];
//ehash
$ecms_hashur=hReturnEcmsHashStrAll();
//驗證權限
CheckLevel($logininid,$loginin,$classid,"public");

//設置DIGG參數
function eSetDigg($add,$userid,$username){
	global $empire,$dbtbpre;
	CheckLevel($userid,$username,$classid,"public");//驗證權限
	$add['digglevel']=(int)$add['digglevel'];
	$diggcmids=eReturnSetGroups($add['cmid']);
	$diggcmids=hRepPostStr($diggcmids,1);
	
	$sql=$empire->query("update {$dbtbpre}enewspublicadd set digglevel='".$add['digglevel']."',diggcmids='$diggcmids'".do_dblimit_upone());
	if($sql)
	{
		GetConfig();
		//操作日誌
		insert_dolog("");
		printerror("SetDiggSuccess","SetDigg.php".hReturnEcmsHashStrHref2(1));
	}
	else
	{printerror("DbError","history.go(-1)");}
}

//清空DIGG記錄
function eClearDiggRecord($add,$userid,$username){
	global $empire,$dbtbpre,$ecms_config,$public_r;
	//DIGG記錄表
	do_dbTableClearTbData($dbtbpre.'enewsdiggips');//pgsql
	//操作日誌
	insert_dolog("");
	printerror("ClearDiggRecordSuccess",EcmsGetReturnUrl());
}


$enews=$_POST['enews'];
if(empty($enews))
{$enews=$_GET['enews'];}
if($enews)
{
	hCheckEcmsRHash();
}
if($enews=="SetDigg")//設置參數
{
	eSetDigg($_POST,$logininid,$loginin);
}
elseif($enews=="ClearDiggRecord")//清空記錄
{
	@set_time_limit(1000);
	eClearDiggRecord($_GET,$logininid,$loginin);
}
else
{}

$r=$empire->fetch1("select * from {$dbtbpre}enewspublicadd".do_dblimit_one());

//系統模型
$mids='';
$i=0;
$modsql=$empire->query("select mid,mname from {$dbtbpre}enewsmod order by myorder,mid");
while($modr=$empire->fetch($modsql))
{
	$i++;
	if($i%4==0)
	{
		$br="<br>";
	}
	else
	{
		$br="";
	}
	$select='';
	if(strstr($r['diggcmids'],','.$modr['mid'].','))
	{
		$select=' checked';
	}
	$mids.="<input type=checkbox name=cmid[] value='".$modr['mid']."'".$select.">".$modr['mname']."&nbsp;&nbsp;".$br;
}

//formhash
$efh=heformhash_get('SetDigg');
$efh1=heformhash_get('ClearDiggRecord',1);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DIGG頂參數設置</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../ecmseditor/js/jstime/WdatePicker.js"></script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr>
    <td height="32"><p>位置：<a href="SetDigg.php<?=$ecms_hashur['whehref']?>">DIGG頂參數設置</a></p>
    </td>
  </tr>
</table>
<form name="setpublic" method="post" action="SetDigg.php" onsubmit="return confirm('確認設置?');">
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
  <?=$ecms_hashur['form']?>
  <?php echo $efh; ?>
    <tr class="header"> 
      <td height="25" colspan="2">DIGG頂參數設置 
        <input name="enews" type="hidden" value="SetDigg"></td>
    </tr>
	<tr bgcolor="#FFFFFF">
      <td width="18%" height="25">重複頂限制</td>
      <td width="82%"><select name="digglevel" id="digglevel">
        <option value="0"<?=$r['digglevel']==0?' selected':''?>>不限制 (可一直重複頂)</option>
        <option value="1"<?=$r['digglevel']==1?' selected':''?>>COOKIE驗證 (同一瀏覽器COOKIE進行只能頂一次)</option>
        <option value="2"<?=$r['digglevel']==2?' selected':''?>>IP驗證 (同一IP只能頂一次)</option>
        <option value="3"<?=$r['digglevel']==3?' selected':''?>>會員驗證 (每個會員只能頂一次)</option>
      </select>
        &nbsp;(<strong><a href="SetDigg.php?enews=ClearDiggRecord<?=$ecms_hashur['href'].$efh1?>" onclick="return confirm('確認要清空驗證記錄？');"><u>點擊這裡</u></a></strong>清空驗證記錄，可以讓重新頂)</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td height="25">關閉頂的系統模型</td>
      <td><?=$mids?></td>
    </tr>
    <tr bgcolor="#FFFFFF"> 
      <td height="25">&nbsp;</td>
      <td height="25"><input type="submit" name="Submit" value="提交"> <input type="reset" name="Submit2" value="重置"></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td height="25" colspan="2"><font color="#666666">說明：<br>
      要讓系統模型支持頂功能，需要往模型表增加字段名為「diggtop」、類型為INT的字段；<br>
      要讓系統模型支持踩功能，需要往模型表增加字段名為「diggdown」、類型為INT的字段。</font>      </td>
    </tr>
  </table>
</form>
<br>
</body>
</html>
<?php
db_close();
$empire=null;
?>