<?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,"changedata");

//批量更新動態頁緩存
function ChangePageCache($add,$userid,$username){
	global $empire,$public_r,$class_r,$fun_r,$dbtbpre;
	//驗證權限
	//CheckLevel($userid,$username,$classid,"changedata");
	if(empty($public_r['ctimeopen']))
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	$dopage=(int)$add['dopage'];
	if(!$dopage)
	{
		printerror("ErrorUrl","history.go(-1)");
	}
	$chall=(int)$add['chall'];
	$tid=(int)$add['tid'];
	$classid=$add['classid'];
	$ttid=$add['ttid'];
	$from=$add['from'];
	$time=time();
	if($dopage==2)//欄目
	{
		if($chall)
		{
			$cids=eArrayReturnInids($classid);
			if($cids)
			{
				$empire->query("update {$dbtbpre}enewsclass set fclast='$time' where classid in (".$cids.")");
			}
		}
		else
		{
			$empire->query("update {$dbtbpre}enewsclass set fclast='$time'");
		}
	}
	elseif($dopage==3)//內容
	{
		if(!$tid)
		{
			printerror("ErrorUrl","history.go(-1)");
		}
		$tbr=$empire->fetch1("select tid,tbname from {$dbtbpre}enewstable where tid='$tid'".do_dblimit_one());
		if(!$tbr['tbname'])
		{
			printerror("ErrorUrl","history.go(-1)");
		}
		$empire->query("update {$dbtbpre}ecms_".$tbr['tbname']." set lastdotime='$time'");
	}
	elseif($dopage==4)//標題分類
	{
		if($chall)
		{
			$ttids=eArrayReturnInids($ttid);
			if($ttids)
			{
				$empire->query("update {$dbtbpre}enewsinfotype set fclast='$time' where typeid in (".$ttids.")");
			}
		}
		else
		{
			$empire->query("update {$dbtbpre}enewsinfotype set fclast='$time'");
		}
	}
	elseif($dopage==5)//TAGS
	{
		$empire->query("update {$dbtbpre}enewstags set fclast='$time'");
	}
	elseif($dopage==6)//父子信息
	{
		$empire->query("update {$dbtbpre}enewsfz_info set fclast='$time'");
	}
	else//首頁
	{
		$empire->query("update {$dbtbpre}enewspublic_fc set fclastindex='$time'".do_dblimit_upone());
	}
	insert_dolog("");//操作日誌
	printerror("ChangePageCacheSuccess",$from);
}

$enews=$_POST['enews'];
if(empty($enews))
{$enews=$_GET['enews'];}
if($enews)
{
	hCheckEcmsRHash();
	@set_time_limit(0);
	include('../../../e/data/dbcache/class.php');
}
if($enews=="ChangePageCache")//批量更新緩存
{
	ChangePageCache($_POST,$logininid,$loginin);
}

$dopage=(int)$_GET['dopage'];

//欄目
$fcfile="../../../c/ecachepub/eclassfc/ListEnews.php";
$class="<script src=../../../c/ecachepub/eclassfc/cmsclass.js></script>";
if(!file_exists($fcfile))
{$class=ShowClass_AddClass("",0,0,"|-",0,0);}
//刷新表
$retable="";
$selecttable="";
$i=0;
$tsql=$empire->query("select tid,tbname,tname from {$dbtbpre}enewstable where intb=0 order by tid");
while($tr=$empire->fetch($tsql))
{
	$i++;
	if($i%4==0)
	{
		$br="<br>";
	}
	else
	{
		$br="";
	}
	$retable.="<input type=checkbox name=tbname[] value='".$tr['tbname']."' checked>".$tr['tname']."&nbsp;&nbsp;".$br;
	$selecttable.="<option value='".$tr['tid']."'>".$tr['tname']."</option>";
}
//標題分類
$tts='';
$infotypesql=$empire->query("select typeid,tname from {$dbtbpre}enewsinfotype order by typeid");
while($infotyper=$empire->fetch($infotypesql))
{
	$tts.="<option value='".$infotyper['typeid']."'".$selected.">".$infotyper['tname']."</option>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>更新動態頁面緩存</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../ecmseditor/js/jstime/WdatePicker.js"></script>
<script>
function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall')
       e.checked = form.chkall.checked;
    }
  }
</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr> 
    <td width="39%" height="32">位置：<a href="ChangePageCache.php<?=$ecms_hashur['whehref']?>">批量更新動態頁面緩存</a></td>
    <td width="61%"><div align="right" class="emenubutton">
      <input type="button" name="Submit52" value="數據更新中心" onClick="self.location.href='ChangeData.php<?=$ecms_hashur['whehref']?>';">
	  &nbsp;&nbsp;
      <input type="button" name="Submit522" value="更新信息頁地址" onClick="self.location.href='ReInfoUrl.php<?=$ecms_hashur['whehref']?>';">
	  &nbsp;&nbsp;
      <input type="button" name="Submit52" value="數據整理" onClick="self.location.href='DoUpdgxData.php<?=$ecms_hashur['whehref']?>';">
    </div></td>
  </tr>
</table>
<form action="ChangePageCache.php" method="post" name="form1" target="_blank" onSubmit="return confirm('確認要更新?');">
  <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder" id="ChangePageCache">
  <?=$ecms_hashur['form']?>
  <?php echo heformhash_get('ChangePageCache'); ?>
    <input name="from" type="hidden" id="from" value="ChangePageCache.php<?=$ecms_hashur['whehref']?>">
    <tr class="header"> 
      <td height="25"> <div align="center">批量更新動態頁面緩存</div></td>
    </tr>
    <tr> 
      <td height="25" bgcolor="#FFFFFF"> <div align="center"> 
          <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
            <tr>
              <td width="23%" height="25">更新緩存的頁面：</td>
              <td width="77%" height="25"><select name="dopage" id="dopage" onChange="self.location.href='ChangePageCache.php?<?=$ecms_hashur['ehref']?>&dopage='+this.options[this.selectedIndex].value;">
                <option value="1"<?=$dopage==1?' selected':''?>>首頁</option>
                <option value="2"<?=$dopage==2?' selected':''?>>欄目頁</option>
                <option value="3"<?=$dopage==3?' selected':''?>>內容頁</option>
                <option value="4"<?=$dopage==4?' selected':''?>>標題分類頁</option>
                <option value="5"<?=$dopage==5?' selected':''?>>TAGS頁</option>
				<option value="6"<?=$dopage==6?' selected':''?>>父子信息頁</option>
              </select>              </td>
            </tr>
			<?php
			if($dopage==2||$dopage==4)
			{
			?>
            <tr>
              <td height="25">選擇更新緩存範圍：</td>
              <td height="25"><input name="chall" type="radio" value="0" checked>更新所有緩存
                <input type="radio" name="chall" value="1">按下面選定更新緩存</td>
            </tr>
			<?php
			}
			?>
			<?php
			if($dopage==3)
			{
			?>
            <tr> 
              <td height="25">數據表：</td>
              <td height="25"> <select name="tid" id="tid">
                  <option value=''>------ 選擇數據表 ------</option>
                  <?=$selecttable?>
                </select></td>
            </tr>
			<?php
			}
			if($dopage==2)
			{
			?>
            <tr> 
              <td height="25" valign="top">欄目：<br>
			  <br>
			  <br>
			  <br>
			  <br>
			  <font color="#999999">(多個用CTRL/SHIFT)</font></td>
              <td height="25"><select name="classid[]" size="18" multiple id="classid[]" style="width:180">
                  <?=$class?>
                </select></td>
            </tr>
			<?php
			}
			if($dopage==4)
			{
			?>
            <tr>
              <td height="25" valign="top">標題分類：<br>
                <br>
                <br>
                <br>
				<br>
				<br>
                <font color="#999999">(多個用CTRL/SHIFT)</font></td>
              <td height="25"><select name="ttid[]" size="18" multiple id="ttid[]" style="width:180">
			  <?=$tts?>
              </select>              </td>
            </tr>
			<?php
			}
			?>
            <tr> 
              <td height="25">&nbsp;</td>
              <td height="25">
			  <?php
			  if(empty($public_r['ctimeopen']))
			  {
			  ?>
					動態頁面緩存未啟用，無需使用此更新！
			  <?php
			  }
			  else
			  {
			  ?>
			  <input type="submit" name="Submit62" value="開始更新緩存"> 
			  &nbsp;
                <input type="reset" name="Submit72" value="重置"> 
                <input name="enews" type="hidden" value="ChangePageCache">
			  <?php
			  }
			  ?>
              </td>
            </tr>
          </table>
        </div></td>
    </tr>
  </table>
</form>
<br>
</body>
</html>
<?php
db_close();
$empire=null;
?>
