<?
$C_126cmsadmin_tname = 'article_config';

include(dirname(__FILE__)."/global.php");




@$job=$submitted_vars['job'];

$fid  = $submitted_vars['id'] ? $submitted_vars['id'] : $submitted_vars['fid'];//网站栏目
$module_id    = $submitted_vars['mid'];//栏目模块
$mid    = $submitted_vars['mid'];//栏目模块


//取$article_page_size
$query="SELECT * FROM `w6_sort` WHERE `id`='".$fid."'";
$result=mysql_query($query);
$maxperpage     =  mysql_result($result,"0","maxperpage");
if( $maxperpage != 0 )$article_page_size = $maxperpage;




	$query="SELECT * FROM `w6_module` WHERE `module_id`='".$module_id."'";
	$result=mysql_query($query);
	$module_config       =  mysql_result($result,"0","module_config");
				  
	$array = unserialize($module_config);


    //$field_db = $array;
	foreach( $array AS $key=>$value ){
		if( $value[listshow] == 1 ){
			$_listdb[intval($value[orderlist])]=$value;
		}
	}
	
	if(is_array($_listdb)) krsort($_listdb);//为防止数组空时出现错误显示

	unset($listdb);

	foreach( (array)$_listdb AS $key=>$rs){//加“(array)”防止显示错误代码
		$listdb[$rs[field_id]]=$rs;
	}
	$field_db=$listdb;
	//$field_db=$listdb+$field_db;

	$f_array=$field_db;
	
	unset($listdb);
	
	//print_r($f_array);
	
	foreach( (array)$f_array AS $key=>$value ){//加“(array)”防止显示错误代码
		if( $value[listshow] == 1 ){
			$title_str .= '<td height="30" align="center" background="images/titlebg.jpg">'.$value[title].'</td>';
			$field_id_array[] = $value[field_id];
		}
	}
	//echo $title_str;
	//print_r($field_id_array);
	

if($job == "del"){
   
   $aid = $_GET['aid'];
   $fid = $_GET['fid'];
   $mid = $_GET['mid'];

   if(!is_numeric($aid) || !is_numeric($fid) || !is_numeric($mid)){
   	exit ( 'ID出错' );
   }
   
   $query="DELETE FROM `w6_module_content_index` WHERE `id`='$aid' ";
   $result=mysql_query($query) or die( mysql_error() );

   $query="DELETE FROM `w6_module_content_$mid` WHERE `aid`='$aid' ";
   $result=mysql_query($query) or die( mysql_error() );
   if ($result)
     {
       $showmsg = "文章删除成功！";
	   $formurl = "article_list.php?id=$fid&mid=$mid";
     }
  else
     {
       $showmsg = "文章删除失败！";
	   $formurl = "article_list.php?id=$fid&mid=$mid";
     }
	 
  include('showmsg.php');
  exit;
  
}


if($job == "modifylist"){
	$order = $_POST['order'];
	$fid = $_POST['fid'];
	$mid = $_POST['mid'];
	
	foreach( $order AS $key=>$value)
	{
		$result = mysql_query("UPDATE w6_module_content_$mid SET content_list='$value' WHERE id='$key'");
	}
	$showmsg = "修改成功！";
	$formurl = "article_list.php?id=$fid&mid=$mid";
    include('showmsg.php');
    exit;

}




	if( $job == "search1" ){
	$fid  =  $submitted_vars["parentId"] ? $submitted_vars["parentId"] : $_GET['fid'];
			//取得 mid
		$query="SELECT * FROM `w6_sort` WHERE `id`='".$fid."'";
		$result=mysql_query($query);
		$mid       =  mysql_result($result,"0","mid");
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid'".$S_126cmsadmin_sql_str;
	}
	elseif( $job == "search2" ){
	$keyword = $_POST['keyword'] ? $_POST['keyword'] : $_GET['keyword'];
	$type = $_POST['type'] ? $_POST['type'] : $_GET['type'];
	$mid = $_POST['mid'] ? $_POST['mid'] : $_GET['mid'];
	$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `".$type."` LIKE '%".$keyword."%' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "yz_0" ){//显示未审核文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `yz` != '1' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "yz_1" ){//显示已审核文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `yz` = '1' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "shows_1" ){//显示已显示显示文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `shows` = '1' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "shows_0" ){//显示未显示显示文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `shows` != '1' $S_126cmsadmin_sql_str";
	}
	else{
		$query="SELECT * FROM `w6_module_content_".$module_id."` WHERE `fid` = '$fid' $S_126cmsadmin_sql_str";
	}

  	//echo "<br>".$query."<br><br><br><br>aaaa<br><br><br><br>";
  	$result=mysql_query($query) or die("Could not connect: " . mysql_error());
	//为了防止有时不是GET方式接收module_id时读取mid
	$module_id = stripslashes(mysql_result($result,"0","module_id"));
	//
  	$num=mysql_num_rows($result);
	
	$url = '?job='.$job.'&fid='.$fid.'&mid='.$module_id.'&type='.$type.'&keyword='.$keyword;
  	$page = isset($_GET['page']) ? $_GET['page'] : 1;  //当前页
	$showpage = getpage($url,$article_page_size,$num,$page);
    $query=$query." ORDER BY `content_list` DESC  LIMIT ".(($page-1)*$article_page_size)." , $article_page_size ";


  	$result=mysql_query($query);
  	$i = 0;
	while($row=mysql_fetch_array($result))
  	{
		$listdb[$i]['id'] = stripslashes($row['id']);
		$listdb[$i]['aid'] = stripslashes($row['aid']);
		$listdb[$i]['fid'] = stripslashes($row['fid']);
		$listdb[$i]['mid'] = stripslashes($row['module_id']);
		$listdb[$i]['fname'] = stripslashes($row['fname']);
		$listdb[$i]['yz'] = stripslashes($row['yz']);
		$listdb[$i]['shows'] = stripslashes($row['shows']);
		$listdb[$i]['title'] = stripslashes($row['title']);
		$listdb[$i]['count'] = stripslashes($row['count']);
		$listdb[$i]['content_list'] = stripslashes($row['content_list']);
		$listdb[$i]['posttime'] = date("Y-m-d H:i",$row['posttime']);
	
		foreach( (array)$field_id_array AS $key=>$value ){//加“(array)”防止显示错误代码
			@$title_nr .= '<td align="center" class="td">'.$row[$value].'</td>';
		}
		$listdb[$i]['title2'] = $title_nr;
		unset($title_nr);
		
		$i++;
	
	}
	


$tplFile_0 = './tpl/mother/list.htm';
$tplFile_1 = "./tpl/wn_tpl/list_$mid.htm";
if ( !file_exists( $tplFile_1 ) ) {
	$tplFile = $tplFile_0;
}else{
	$tplFile = $tplFile_1;
}
	
//生成静态页
ob_start();
//require($tpl_head);
require( $tplFile );
//require($tpl_foot);
$html = ob_get_contents();
ob_end_clean();

echo $html;

exit;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>后台管理</title>
<link href="css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	text-decoration: none;
	color: #000000;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: underline;
	color: #FF0000;
}
a:active {
	text-decoration: none;
	color: #000000;
}
-->
</style>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
  return confirm(msg);
}
//-->
</script>

</head>

<body>
<div align="center" class="font12">
  <table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#A4B6D7">
    <tr>
      <td width="100%" height="22" align="center" background="images/titlebg.jpg">&nbsp;</td>
    </tr>
  </table>
  <br />
  <table width="100%" height="25" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td align="left" bgcolor="#FFFFFF">[<a 
      href="article_add.php" class="a_bt">文章管理</a>] 
      [<a 
      href="post_info/post.php?id=<?=$fid?>&mid=<?=$mid?>" class="a_bt">发表文章</a>] </td>
    </tr>
  </table>
  <br />
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
    <tr>
      <td height="22" align="left" class="head">相关选项</td>
    </tr>
    <tr>
      <td height="30" align="center"><input onclick="window.location.href='?mid=<?=$module_id?>&fid=<?=$fid?>'" type="button" value="所有" name="Submit" />
	  <!--
        <input onclick="window.location.href='index.php?lfj=artic&amp;job=listartic&amp;type=my&amp;only=1&amp;mid=0'" type="button" value="我发表的" name="Submit" />
		//-->
        <input onclick="window.location.href='?job=yz_0&mid=<?=$module_id?>&fid=<?=$fid?>'" type="button" value="未审" name="Submit5" />
        <input onclick="window.location.href='?job=yz_1&mid=<?=$module_id?>&fid=<?=$fid?>'" type="button" value="已审" name="Submit6" />
        <input onclick="window.location.href='?job=shows_0&mid=<?=$module_id?>&fid=<?=$fid?>'" type="button" value="未显示" name="Submit6" />
        <input onclick="window.location.href='?job=shows_1&mid=<?=$module_id?>&fid=<?=$fid?>'" type="button" value="显示" name="Submit5" />
		<!--
        <input onclick="window.location.href='index.php?lfj=artic&amp;job=listartic&amp;fid=&amp;type=levels&amp;only=1&amp;mid=0'" type="button" value="精华" name="Submit52" />
        <input onclick="window.location.href='index.php?lfj=artic&amp;job=listartic&amp;fid=&amp;type=unlevels&amp;only=1&amp;mid=0'" type="button" value="非精华" name="Submit522" />
        <input onclick="window.location.href='index.php?lfj=artic&amp;job=listartic&amp;fid=&amp;type=picurl&amp;only=1&amp;mid=0'" type="button" value="图片主题" name="Submit5222" />
        <input onclick="window.location.href='index.php?lfj=artic&amp;job=listartic&amp;type=rubbish&amp;only=1&amp;mid=0'" type="button" value="回收站" name="Submit5222" />
		//-->
        <SELECT name="parentId" onchange="window.location=('?job=search1&parentId='+this.options[this.selectedIndex].value+'')">
          <option value="" selected="selected">现有分类</option>
		  <?
		  formListSort("w6_sort",$fid,1);
		  ?>
        </select></td>
    </tr>
  </table>
  <br />
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
    <tr>
      <td height="22" align="left" class="head">文章管理</td>
    </tr>
    <tr>
      <td height="24" align="left">
	  <br />
      <UL>
      <LI>注意:<FONT color=#ff0000>排序的规则是,数值大的排在前面</FONT> </LI>
      </UL>
</td>
    </tr>
    <tr>
      <td align="center">
	  <FORM name="formlist" action="" method="post">
  <table width="99%" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td width="2%" align="center" background="images/titlebg.jpg">I D</td>
          <td width="3%" align="center" background="images/titlebg.jpg">排序</td>
          <td width="30%" align="center" background="images/titlebg.jpg">标题</td>
          <!--<td width="6%" align="center" background="images/titlebg.jpg">效果</td>//-->
          <?=$title_str?>
          <td width="8%" align="center" background="images/titlebg.jpg">所在栏目</td>
          <!--<td width="10%" align="center" background="images/titlebg.jpg">发布者</td>//-->
          <td width="4%" align="center" background="images/titlebg.jpg">浏览</td>
          <td width="10%" align="center" background="images/titlebg.jpg">发表日期</td>
          <td width="3%" align="center" background="images/titlebg.jpg">审核</td>
          <td width="3%" align="center" background="images/titlebg.jpg">显示</td>
          <td width="10%" colspan="3" align="center" background="images/titlebg.jpg">操作</td>
          </tr>
		<?
		
	if( $job == "search1" ){
	$fid  =  $submitted_vars["parentId"] ? $submitted_vars["parentId"] : $_GET['fid'];
			//取得 mid
		$query="SELECT * FROM `w6_sort` WHERE `id`='".$fid."'";
		$result=mysql_query($query);
		$mid       =  mysql_result($result,"0","mid");
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid'".$S_126cmsadmin_sql_str;
	}
	elseif( $job == "search2" ){
	$keyword = $_POST['keyword'] ? $_POST['keyword'] : $_GET['keyword'];
	$type = $_POST['type'] ? $_POST['type'] : $_GET['type'];
	$mid = $_POST['mid'] ? $_POST['mid'] : $_GET['mid'];
	$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `".$type."` LIKE '%".$keyword."%' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "yz_0" ){//显示未审核文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `yz` != '1' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "yz_1" ){//显示已审核文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `yz` = '1' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "shows_1" ){//显示已显示显示文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `shows` = '1' $S_126cmsadmin_sql_str";
	}
	elseif( $job == "shows_0" ){//显示未显示显示文章
		$fid = $_GET['fid'];
		$mid = $_GET['mid'];
		$query="SELECT * FROM `w6_module_content_".$mid."` WHERE `fid` = '$fid' AND `shows` != '1' $S_126cmsadmin_sql_str";
	}
	else{
		$query="SELECT * FROM `w6_module_content_".$module_id."` WHERE `fid` = '$fid' $S_126cmsadmin_sql_str";
	}

  	//echo "<br>".$query."<br><br><br><br>aaaa<br><br><br><br>";
  	$result=mysql_query($query) or die("Could not connect: " . mysql_error());
	//为了防止有时不是GET方式接收module_id时读取mid
	$module_id = stripslashes(mysql_result($result,"0","module_id"));
	//
  	$num=mysql_num_rows($result);
	
	$url = '?job='.$job.'&fid='.$fid.'&mid='.$module_id.'&type='.$type.'&keyword='.$keyword;
  	$page = isset($_GET['page']) ? $_GET['page'] : 1;  //当前页
	$showpage = getpage($url,$article_page_size,$num,$page);
    $query=$query." ORDER BY `content_list` DESC  LIMIT ".(($page-1)*$article_page_size)." , $article_page_size ";
    
	//echo "<br>".$query."<br><br><br><br>2aaaa<br><br><br><br>";

  	$result=mysql_query($query);
  	while($row=mysql_fetch_array($result))
  	{
  	$id      =  stripslashes($row["id"]);
  	$aid      =  stripslashes($row["aid"]);
  	$fid      =  stripslashes($row["fid"]);
  	$mid      =  stripslashes($row["module_id"]);
  	$fname    =  stripslashes($row["fname"]);
  	$yz       =  stripslashes($row["yz"]);
  	$shows    =  stripslashes($row["shows"]);
  	$title    =  stripslashes($row["title"]);
  	$count    =  stripslashes($row["count"]);
  	$content_list    =  stripslashes($row["content_list"]);
	$posttime =  date("Y-m-d H:i",$row['posttime']);
	
	foreach( (array)$field_id_array AS $key=>$value ){//加“(array)”防止显示错误代码
			@$title_nr .= '<td align="center" class="td">'.$row[$value].'</td>';
	}
	$title2 = $title_nr;
	unset($title_nr);
	//$title    = '<td align="left" class="td">'. stripslashes( $row[$field_id_array[$i]] ) .'</td>';

?>
        <tr class=trA onMouseOver="this.className='trB'" 
        onmouseout="this.className='trA'">
          <td align="center" class="td"><?=$id?></td>
          <td align="center" class="td"><input maxlength="4" size="3" value="<?=$row['content_list']?>" name="order[<?=$row['id']?>]" /></td>
          <td align="left" class="td">&nbsp;<a href="../../show.php?aid=<?=$aid?>"  target="_blank">
            <?=$title?>
          </a></td>
          <!--<td align="center" class="td"><a href="article_show.php?aid=<?=$aid?>&amp;fid=<?=$fid?>&amp;mid=<?=$mid?>" target="_blank">查看</a></td>//-->
          <?=$title2?>
          <td align="center" class="td"><a href="?job=search1&amp;parentId=<?=$fid?>"><?=$fname?></a></td>
          <!--<td align="center" class="td">&nbsp;</td>//-->
          <td align="center" class="td"><?=$count?></td>
          <td align="center" class="td"><?=$posttime?></td>
          <td align="center" class="td"><? if($yz==1) echo '已审'; else echo '未审';?></td>
          <td align="center" class="td"><? if($shows==1) echo '已显示'; else echo '未显示';?></td>
          <td width="3%" align="center" class="td"><a href="<? echo "$webdb[www_url]/show.php?job=makeHtml&aid=$aid&updatapage=1";?>" title="生成静态网页" target="_blank">A</a></td>
          <td width="6%" align="center" class="td"><a href="article_modify.php?aid=<?=$aid?>&fid=<?=$fid?>&mid=<?=$mid?>">修改</a></td>
          <td width="6%" align="center" class="td"><a href="?job=del&amp;aid=<?=$aid?>&fid=<?=$fid?>&mid=<?=$mid?>" onClick="return MM_popupMsg('确定要删除吗！删除后无法恢复！')">删除</a></td>
        </tr>
		<?
		}
		?>
        <tr>
          <td height="30" colspan="9" align="center"><input type="submit" value="修改排序" name="Submit22" />
            <input name="job" type="hidden" id="job" value="modifylist" />
            <input name="fid" type="hidden" id="fid" value="<?=$fid?>" />
            <input name="mid" type="hidden" id="mid" value="<?=$mid?>" />			</td>
        </tr>
      </table>
	  </form></td>
    </tr>
  </table>
  <div style="clear:both"></div>
  <div id="page"><?=$showpage?></div>
  <div style="clear:both"></div>
  <table width="100%" border="0" cellpadding="0" cellspacing="0" class="table">
    <tr>
      <td height="22" align="left" class="head">内容搜索</td>
    </tr>
    <tr>
	<form id="form1" name="form1" method="post" action="">
      <td height="30" align="center">
	  关键字
        <input name="keyword" />
        <select name="type">
          <option value="title" selected="selected">文章标题</option>
          <option value="aid">文章内容</option>
          <option value="aid">文章ID</option>
        </select>
        <input type="submit" value="提交" name="Submit7" />
        <input name="job" type="hidden" id="job" value="search2" />
		<input name="mid" type="hidden" id="mid" value="<?=$mid?>" />
      </td>
	  </form>
    </tr>
  </table>
</div>
</body>
</html>
