<?php
	require_once('_approot.php');	

	$selectfunctionName=str_replace("'","''",$_GET['selectfunctionName']);
	$selectcate=str_replace("'","''",$_GET['selectcate']);
	$fromInMenu=str_replace("'","''",$_GET['fromInMenu']);
	$perpage=$_POST['perpage']!=""?$_POST['perpage']:$_SESSION['perpage'];
	$_SESSION['perpage']=$perpage;
		
	if ($_GET['ls_msg']=="")
	{
		$ls_msg="文章管理操作";
	}	
	else
	{
		$ls_msg=urldecode($_GET['ls_msg']);	
	}
	 
	$searchproductName=($_POST['searchproductName']==""?str_replace("'","''",$_GET['searchproductName']):str_replace("'","''",$_POST['searchproductName']));
	if($searchproductName!="") $ls_msg="包含 $searchproductName 的文章 ";
	if($_POST['gopage']!=""){$gopage =(ctype_digit($_POST['gopage'])?$_POST['gopage']:1);}
	if($gopage!="") $ls_msg="第 $gopage 页的文章 ";

	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$sort=$_GET['sort'];
	switch ($sort)
	{
	 	case "enable":
			$sortstr=" order by enable ASC";
			break;
		
	 	case "date":
			$sortstr=" order by articleDate ASC";
			break;
		
	 	case "promote":
			$sortstr=" order by clickNum DESC";
			break;
		
	 	case "home":
			$sortstr=" order by flag DESC";
			break;
		
		default:
			$sortstr=" order by functionName,cateName,Num desc,articleDate desc";
	
	}
	
	switch ($ls)
	{
		
	 	case "unenable":
			$unenable_sql="update ls_article set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_article set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
		case "del":
			$del_sql="delete from ls_article where ID=".$id."";
	   		//echo $del_sql;
	   		$del_query=$opendb->query($del_sql);
			writelog($_SERVER['PHP_SELF'],"delete article: ".$articleTitle,"ID: ".$id);

	   	$ls_msg="删除操作成功！";
			break;
	}
?>
<!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=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
	</head>

 <body>
	<table width="99%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#3c8dbc">
			<tr>
				<td height="31" background=""><div align="center"><font color="#ffffff"><strong>菜单、栏目内容管理</strong></font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top" bgcolor="#f0f0ee"> <br>
					<form name="del" method="Post" action="delall.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>" onSubmit="return ConfirmDel();">
					<table border="0" width="99%" align="center">
						<tr>
							<td width="63%" >提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td width="9%" align="right" ><div align="left"><span style="padding-left:20px;">

								<?php 								if($searchproductName!="") $searhprostr=" and (articleTitle like '%".$searchproductName."%' or articleBrief like '%".$searchproductName."%' or articleText like '%".$searchproductName."%' or articleDate like '%".$searchproductName."%'  ) "; 
								
								$addstr=substr(str_replace(",","' or cateName='",$defaultmenu),1)."' ";
								//echo $addstr;
                             $article_sql= "SELECT distinct functionName FROM ls_functioncates where enable=1 order by Num ASC";
							  //"SELECT * FROM ls_functioncates  where (cateName='' or cateName is NULL ".$addstr.") and ( subCateName='' or subCateName is NULL )  order by Num ASC "; // 
							  $article_query=$opendb->query($article_sql);
							  

			?>

						  </span></div></td>
							<td width="28%" align="right" ><img src="images/shao.gif">&nbsp;<a href="addarticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&fromInMenu=<?=$fromInMenu?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort?>"><u>添加</u></a></td>
						</tr>
                        <?php if($fromInMenu==""){ ?>

						<tr>
						  <td colspan="3" >大类： 
                            <?php                           while($news_rows2=mysqli_fetch_assoc($article_query))
		  					{  
								$thisfunc1=$news_rows2['functionName'];
								$thiscate=$news_rows2['cateName'];
								$showfunc=$thisfunc1;
								if($thisfunc1=="博客分类")$showfunc=getlangmemu("Blog");
								if($thisfunc1=="常见问题")$showfunc=getlangmemu("Faq");
								if($thisfunc1=="新闻分类")$showfunc=getlangmemu("News");
 
								$thisfunc=$news_rows2['functionName'];
								$showfunc=$thisfunc;
								$showhref=$menulinks[$thiscate];
								$catehref=$showhref==""?"?selectfunctionName=".urlencode($thisfunc):$showhref;
								if($thisfunc=="博客分类"){$catehref="blog.php";$showfunc=getlangmemu("Blog");}
								if($thisfunc=="常见问题"){$catehref="faq.php";$showfunc=getlangmemu("Faq");}
								if($thisfunc=="新闻分类"){$catehref="news.php";$showfunc=getlangmemu("News");}
								
								if($news_rows2['brief'] == "home"){
									if($selectfunctionName==$thisfunc)
									{echo "<a href='".$catehref."'><font  color='#549800' ><span style=\"color:#930\" >".urlencode($showfunc)."</span></font></a> | ";}
									else
									{echo "<a href='".$catehref."'><font  color='#549800' >".urlencode($showfunc)."</font></a> | ";}
								}else{
									if($selectfunctionName==$showfunc)
									{echo "<a href='".$catehref."'><span style=\"color:#930\" >".$showfunc."</span></a> | ";}
									else
									{echo "<a href='".$catehref."'>".$showfunc."</a> | ";}
								}
								
							}
						  ?>
<a href='?selectcate='> 全部 </a></td>
					  </tr>
					  <?php }
					  
					  	$mid_sql="SELECT * FROM ls_functioncates where functionName='".$selectfunctionName."'  and enable=1 order by Num";
						$mid_query=$opendb->query($mid_sql);
						$mid_rows_num=mysqli_num_rows($mid_query);
						if($mid_rows_num > 1){
					  ?>
						<tr>
						  <td colspan="3" >
                          <?php if($selectfunctionName!="") {?>
                          
                          中类： 
                          <?php 						  $article_sql="SELECT distinct(cateName) FROM ls_functioncates   where functionName='".$selectfunctionName."' and enable=1  order by Num";//count the error by searchtype
						   
					      $article_query=$opendb->query($article_sql);
                          while($news_rows2=mysqli_fetch_assoc($article_query))
		  					{
								if($selectcate==$news_rows2['cateName'])
								{echo "<a href='?selectcate=".urlencode($news_rows2['cateName'])."&selectfunctionName=".urlencode($selectfunctionName)."&fromInMenu=".$fromInMenu."&searchproductName=".urlencode($searchproductName)."'><span style=\"color:#F90\" >".$news_rows2['cateName']."</span></a> | ";}
								else
								{echo "<a href='?selectcate=".urlencode($news_rows2['cateName'])."&selectfunctionName=".urlencode($selectfunctionName)."&fromInMenu=".$fromInMenu."&searchproductName=".urlencode($searchproductName)."'><span style=\"color:#930\" >".$news_rows2['cateName']."</span></a> | ";}
								
							}
						  ?>
                          <a href='?selectfunctionName=<?=$selectfunctionName?>&fromInMenu=<?=$fromInMenu?>'> 全部 </a>
                          
                          <?php } ?>
                          </td>
					  </tr>
					  <?php }?>
					</table>
					<?php
					// 获取当前页数
					   if( isset($_GET['page']) ){
					      $page = intval( $_GET['page'] );
					   }
					   else{
					      $page = 1;
					   }
					   if($gopage!="")$page = $gopage;
					   // 每页数量
					   $PageSize = $perpage==0?12:$perpage;
					   
					   // 获取总数据量
					   /********************************************************************************/
					   if($selectcate<>''&&$selectfunctionName<>''&&$selectfunctionName<>'全部'){	$sql="select * from ls_article where cateName='".urldecode($selectcate)."' and functionName='".urldecode($selectfunctionName)."' and functionName!='新闻分类' and functionName!='singlePages' ". $searhprostr.$sortstr;
					   	$sqlct="select count(*) as ctrows from ls_article where cateName='".urldecode($selectcate)."' and functionName='".urldecode($selectfunctionName)."' and functionName!='新闻分类' and functionName!='singlePages' ". $searhprostr;
					   }
					   else
					   {
					   	if($selectfunctionName<>''&&$selectfunctionName<>'全部'){	$sql="select * from ls_article where functionName='".urldecode($selectfunctionName)."' and functionName!='新闻分类' and functionName!='singlePages'  ". $searhprostr.$sortstr;
							$sqlct="select count(*) as ctrows from ls_article where functionName='".urldecode($selectfunctionName)."' and functionName!='新闻分类' and functionName!='singlePages'  ". $searhprostr;
						}
					   	else
					   	{	$sql="select * from ls_article where functionName!='新闻分类' and functionName!='singlePages'  ". $searhprostr.$sortstr;	
							$sqlct="select count(*) as ctrows from ls_article where functionName!='新闻分类' and functionName!='singlePages'  ". $searhprostr;
						}
					   }

					   	$result=$opendb->query($sqlct);
					  
					   /********************************************************************************/
					   // 获取总数据量
					   
					   $row = mysqli_fetch_assoc($result);
					   $amount = $row['ctrows'];
					   
					   // 记算总共有多少页
					   if( $amount ){
					      if( $amount < $PageSize ){ $page_count = 1; }			   //如果总数据量小于$PageSize，那么只有一页
					      if( $amount % $PageSize ){								  //取总数据量除以每页数的余数
					   	   $page_count = (int)($amount / $PageSize) + 1;		   //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
					      }else{
					   	   $page_count = $amount / $PageSize;					  //如果没有余数，则页数等于总数据量除以每页数的结果
					      }
					   }
					   else{
					      $page_count = 0;
					   }
					   
					   // 翻页链接
					   $page_string = '';
					   	
					   if( $page == 1 ){
					      $page_string .= '首页 | 上一页 |';
					   }
					   else{
					      $page_string .= '<a href=?selectcate='.$selectcate.'&selectfunctionName='.$selectfunctionName.'&page=1&searchproductName='.$searchproductName.'&sort='.$sort.'><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?selectcate='.$selectcate.'&selectfunctionName='.$selectfunctionName.'&page='.($page-1).'&searchproductName='.$searchproductName.'&sort='.$sort.'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
					   }
					   if( ($page == $page_count) || ($page_count == 0) ){
					      $page_string .= ' 下一页 | 尾页';
					   }
					   else{
					      $page_string .= ' <a href=?selectcate='.$selectcate.'&selectfunctionName='.$selectfunctionName.'&page='.($page+1).'&searchproductName='.$searchproductName.'&sort='.$sort.'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?selectcate='.$selectcate.'&selectfunctionName='.$selectfunctionName.'&page='.$page_count.'&searchproductName='.$searchproductName.'&sort='.$sort.'><u><font color=\"#0000FF\">尾页</font></u></a>';
					   }
					   	 $page_string .= " &nbsp;&nbsp;页次：<font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b>页";
					   	 //$page_string .= " &nbsp;&nbsp;<b>".$PageSize."</b>个每页";
					   	 
					   $ls_msg2="文章管理 >> ".($selectfunctionName==''?'全部':$selectfunctionName." >> ")." ".$selectcate." 文章";
					
					?>
					
				
		  <table border="0" width="99%" align="center">
						<tr>
							<td width="40%"><?php echo $ls_msg2; ?></td>
							<td width="51%" align="right"><?=strtolower($selectfunctionName)=="about us"?"<a href='ls_about.php'>编辑默认About Us</a>":""?></td>
							<td width="9%" align="right">共 <b><?php echo $amount; ?></b> 个</td>
		          </tr>
					 </table>
					 <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
				  <tr bgcolor="#E4E4E4">
							<td align="center" height="22" width="2%">选</td>
							<td align="center" width="3%">ID</td>
						  <td align="center" width="14%">主菜单</td>
						  <td align="center" width="14%">子菜单</td>
                          <td align="center" width="20%">标题</td>
                          <td align="center" width="20%">title / 跳转链接</td>
                          <td align="center" width="3%"><a href='managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=urlencode($selectfunctionName)?>&id=<?=$article_rows['ID']?>&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort==""?"home":""?>' title='首页文章'>首页</a></td>
						  <td align="center" width="3%"><a href='managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=urlencode($selectfunctionName)?>&id=<?=$article_rows['ID']?>&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort==""?"promote":""?>' title='列出推荐'>推荐</a></td>
						  <td align="center" width="6%"><a href='managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=urlencode($selectfunctionName)?>&id=<?=$article_rows['ID']?>&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort==""?"date":""?>' title='日期倒序'>日期</a></td>
						  <td align="center" width="3%">排序</td>
						  <td align="center" colspan="2" width="3%">操作</td>
							<td align="center" width="3%"><a href='managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=urlencode($selectfunctionName)?>&id=<?=$article_rows['ID']?>&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort==""?"enable":""?>' title='列出无效'>有效</a></td>
					   </tr>
						<?php
						$page= $page<1?1:$page;
					   $article_sql=$sql." limit ". ($page-1)*$PageSize .",".$PageSize." ";	
					   $article_query=$opendb->query($article_sql);
						
					   $i=1;
					   while($article_rows=mysqli_fetch_assoc($article_query))
						{ ?>
					   		  <tr bgcolor='#f4f4f4'		  
					   	  onMouseOver=		  
					   		   	this.style.backgroundColor='#FDFDFD' 		  
					   		  onMouseOut=		  
					   		   	this.style.backgroundColor='#f4f4f4' 		  
					   		  >		  
					   		  	<td align='center' height='34'>		  
					   		  		<input name='select_id<?=$i?>' type='checkbox' onclick="unselectall()" id="select_id" value='<?=$article_rows['ID']?>'>		  
					   		  	</td>
					   		  	<td style='padding-left:10px;'><?php
                                switch($article_rows['grade']){
									case 4:
										echo "";
										break;
									case 0:
										echo "普通会员";
										break;
									case 1:
										echo "理事";
										break;
									case 2:
										echo "理事长";
										break;
								}
								
								?>-
  <?=$article_rows['ID']?></td>		  
					   		  	<td style='padding-left:10px;'>		  
					   		  	<?=$article_rows['functionName']?>
					   		  	</td>		  
					   		  	<td style='padding-left:10px;'>		  
					   		  	<?=$article_rows['cateName']?>
					   		  	</td>
                                <td style='padding-left:10px;'><?=$article_rows['articleTitle']?></td>
                                <td style='padding-left:10px;' title="<?=" \r\n描述： ".$article_rows['description']."\r\n "?>" ><span style="color:#757575;font-size:10px;">
                                <?=mb_substr($article_rows['title'],0,60)?>
                                <br />
                                 <?=mb_substr($article_rows['headerurl'],0,60)!=""? "=>".mb_substr($article_rows['headerurl'],0,60):""?>
                                </span></td>
                                <td align="center" style='padding-left:10px;' title="<?=" \r\n描述： ".$article_rows['description']."\r\n "?>" ><span style="color:#757575">
                                  <?=$article_rows['flag']==0?"":"Y"?>
                                </span></td>		  
					   		  	<td style='padding-left:10px;'>		  
					   		  	<?=$article_rows['clickNum']?>
					   		  	</td>		  
					   		  	<td style='padding-left:10px;'>		  
					   		  	<?=substr($article_rows['articleDate'],2)?>
					   		  	</td>		  
					   		  	<td style='padding-left:10px;'>		  
					   		  	<?=$article_rows['Num']?>
					   		  	</td>		  
					   		  	<td  width='3%' align='center'> 		  
					   		  		<a href='modiarticle.php?selectcate=<?=$selectcate==""?$article_rows['cateName']:$selectcate?>&selectfunctionName=<?=urlencode($selectfunctionName==""?$article_rows['functionName']:$selectfunctionName)?>&id=<?=$article_rows['ID']?>&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort?>' title='编辑'><img src='images/b_edit.png' border='0'></a>		  
					   		    </td>		  
					   		  	<td width='16'  align='center'> 		  
					   		  		<a href='?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&id=<?=$article_rows['ID']?>&ls=del&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort?>' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>		  
					   		    </td>		  
					   		  	<td align='center'>		  
											  
					   <?php  if($article_rows['enable']==1)
					   	{ ?>
					   	 <a href='?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&id=<?=$article_rows['ID']?>&ls=unenable&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort?>' title='显示'><img src='images/enable.gif' border='0'></a>		  
					   	<?php }
					     if($article_rows['enable']==0)
					     	{ ?>
					   		 <a href='?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&id=<?=$article_rows['ID']?>&ls=enable&fromInMenu=<?=$fromInMenu?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>&sort=<?=$sort?>' title='不显示'><img src='images/unenable.gif' border='0'></a>		  
					   <?php } ?>
					   							
					   		  	</td>		  
					   		  	 </tr>		  
					   		  	
							<?php  $i++;
							 }?>
							 <tr bgcolor="#E4E4E4">		  
					   		<td height='40' colspan='13' align='center'>		  
					   		<?=$page_string?> &nbsp; &nbsp;  					   		  <span style="padding-left:6px;"> 每页
                            <select name="perpage" id="perpage" onchange="document.del.action='<?=$_SERVER['PHP_SELF'];?>';document.del.submit();">
                              <option value="12" <?=$perpage==12||$perpage==""?"selected":""?>>12</option>
                              <option value="20" <?=$perpage==20?"selected":""?>>20</option>
                              <option value="50" <?=$perpage==50?"selected":""?>>50</option>
                              <option value="100" <?=$perpage==100?"selected":""?>>100</option>
                              <option value="200" <?=$perpage==200?"selected":""?>>200</option>
                              <option value="500" <?=$perpage==500?"selected":""?>>500</option>
                              <option value="1000" <?=$perpage==1000?"selected":""?> >1000</option>
                            </select>
                            &nbsp;  &nbsp; &nbsp;&nbsp;</span>共 <b><?php echo $amount; ?></b> 个</td>
					   		</tr>		  
						
					
					</table>
					 <table width="99%" border="0" align="center" cellpadding="3" cellspacing="1">
					<tr >
							<td height="28" colspan="8" style="padding-left:6px;">
							  <p>
							  <input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox"> 
							全部
							<input name="submit1" type='submit' value='删除'>
							<input name="Action" type="hidden" id="Action" value="articleDel">
							    Num为99999，表示头条；首页Y表示首页显示；序号相同，可能没有下一页<br />
              </p></td>
					   </tr>
					</table>
				  </form>
                  <form name="searcharticle" method="Post" action="?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>" >
				  <div align="right" style=" width:98%"><span style="padding-left:6px;">
			      <input type="text" name="searchproductName" size="16" maxlength="50"  value="<?=$searchproductName?>" />
			      <input type='submit'    value="查询" style="height:24px;"    />
			      </span> <span style="padding-left:26px;">
			      <input name="gopage" id="gopage" type="text" size="3" />
			      页
<input type='submit'    value="GO"  style="height:24px;"   />
			      </span>
			      </div>
				</form><br/>
				</td> 
	  </tr>
	</table>

 </body>
</html>