<?php
	require_once('_approot.php');	
	
	$selectcate=$_GET['selectcate'];
		
	if ($_GET['ls_msg']=="")
	{
		$ls_msg="单页管理";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
	$ls=$_GET['ls'];
	$id=$_GET['id'];
		
	$searchproductName=($_POST['searchproductName']==""?$_GET['searchproductName']:$_POST['searchproductName']);
	if($searchproductName!="") $ls_msg="包含 $searchproductName 的单页 ";
	if($_POST['gopage']!=""){$gopage =(ctype_digit($_POST['gopage'])?$_POST['gopage']:1);}
	if($gopage!="") $ls_msg="第 $gopage 页的单页 ";
		
	switch ($ls)
	{
		
	 	case "unenable":
			$unenable_sql="update ls_singlepages set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_singlepages set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
		case "del":
			$in_sql="SELECT * from ls_singlepages where ID=".$id.""; //count the error by searchtype
			$in_query=$opendb->query($in_sql);
			$in_rows=mysqli_fetch_assoc($in_query);
			$tpl="../Templates1/".$in_rows['static_tpl'];
			if(file_exists($tpl)&& trim($in_rows['static_tpl'])!="single_page.html" ) 
				if(!unlink($tpl)) $ls_msg.=" 模板".$tpl."删除错误，";  
				else $ls_msg.=" 模板".$tpl."已删除，"; //删除模板
			else $ls_msg.=" 模板".$tpl."未删除，"; //删除模板
	   		//echo $del_sql;
			$del_sql="delete from ls_singlepages where ID=".$id."";
	   		$del_query=$opendb->query($del_sql);
	   		$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">
         <link rel="stylesheet" href="css/style2.css" />
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
	</head>

 <body>
	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
			<tr>
                <td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">单页管理</font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top"><br>
					<form name="del" method="Post" action="delall.php?page=<?=$page?>&searchproductName=<?=$searchproductName?>" onSubmit="return ConfirmDel();">
					<table border="0" width="100%" align="center">
						<tr>
							<td width="63%" style="border-bottom:1px solid #FFF;">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td width="9%" align="right" style="border-bottom:1px solid #FFF;"><div align="left"><span style="padding-left:20px;">
							</span></div></td>
							<td width="28%" align="right" style="border-bottom:1px solid #FFF;"><img src="images/shao.gif">&nbsp;<a href="addsinglepage.php?page=<?=$page?>&searchproductName=<?=$searchproductName?>">添加</a>&nbsp; &nbsp; &nbsp; <?php if(!(strpos($_SERVER['HTTP_REFERER'],"managearticle")===false)){ ?> <a href="managearticle.php">返回</a><?php } ?></td>
						</tr>
					</table>
					<br>
					
					<?php
					// 获取当前页数
													if( isset($_GET['page']) ){
													   $page = intval( $_GET['page'] );
													}
													else{
													   $page = 1;
													}
													// 每页数量
													$PageSize = $PageNum;
													
													// 获取总数据量
													/********************************************************************************/
				if($searchproductName!="") $searhprostr=" where (pageTitle like '%".$searchproductName."%' or pageText like '%".$searchproductName."%' or pageBrief like '%".$searchproductName."%' or pageDate like '%".$searchproductName."%'  ) "; 
				
				if($selectcate<>''&&$selectcate<>'全部'){	$sql="select * from ls_singlepages ". $searhprostr."  order by Num,pageDate desc";}
				else
				{	$sql="select * from ls_singlepages ". $searhprostr." order by Num desc,pageDate desc";	}

					$result=$opendb->query($sql);
													
													/********************************************************************************/
													// 获取总数据量
													
													$row = mysqli_num_rows($result);
													$amount = $row;
													
													// 记算总共有多少页
													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.'&page=1><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?selectcate='.$selectcate.'&page='.($page-1).'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
													}
													if( ($page == $page_count) || ($page_count == 0) ){
													   $page_string .= ' 下一页 | 尾页';
													}
													else{
													   $page_string .= ' <a href=?selectcate='.$selectcate.'&page='.($page+1).'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?selectcate='.$selectcate.'&page='.$page_count.'><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="单页管理 >> 所有单页";
					
					?>
					
				
				<table border="0" width="100%" align="center">
						<tr height="37">
							<td><?php echo $ls_msg2; ?></td>
							<td align="right">共 <b><?php echo $row; ?></b>条</td>
				  </tr>
					 </table>
					 <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
						<tr bgcolor="#f0f0ee" height="37">
							<td align="center"  width="38"></td>
							<td align="center"  width="38">编号</td>
							<td align="center" width="265">标题</td>
							<td align="center" width="260">链接</td>
							<td align="center" width="80">日期</td>
							<td align="center" width="140">主题图</td>
							<td align="center" width="76">模板</td>
						  <td align="center" colspan="2"  >操作</td>
							
			<td align="center" width="40">允许</td>
						</tr>
						<?php						$single_sql=$sql." limit ". ($page-1)*$PageSize .",".$PageSize." ";	
													$single_query=$opendb->query($single_sql);
													$i=1;
													while($single_rows=mysqli_fetch_assoc($single_query))
										 			 { ?>
													<tr height='37' bgcolor='#f9f9f9'
						onMouseOver=
							 	this.style.backgroundColor='#e5e5e5' 
							onMouseOut=
							 	this.style.backgroundColor='#f9f9f9' 
							>
														<td align='center'>
														<input name='select_id<?=$i?>' type='checkbox' onclick="unselectall()" id="select_id" value='<?=$single_rows['ID']?>'>
														</td>
														<td align='center'>
													<?=$single_rows['ID']?>
														</td>
												  	<td style='padding-left:10px;'>
												  <?=$single_rows['pageTitle']?>
												  	</td>
												  	<td style='padding-left:10px;'>
												  <?=$single_rows['singlepage_name']?>
												  	</td>
												  	<td style='padding-left:10px;'>
												  <?=$single_rows['pageDate']?>
												  	</td>
												  	<td style='padding-left:10px;'>
												  <?=$single_rows['banner']?>
												  	</td>
												  	<td style='padding-left:10px;'>
												  <?=$single_rows['static_tpl']?>
												  	</td>
												  	<td align='center'> 
														<a href='modisinglepage.php?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$single_rows['ID']?>&searchproductName=<?=$searchproductName?>' title='编辑'><img src='images/b_edit.png' border='0'></a>
													  </td>
														<td align='center'> 
															<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$single_rows['ID']?>&ls=del&searchproductName=<?=$searchproductName?>' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>
													  </td>
														<td align='center'>
											  
													<?php  if($single_rows['enable']==1)
														{ ?>
															<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$single_rows['ID']?>&ls=unenable' title='显示'&page=<?=$page?>&searchproductName=<?=$searchproductName?>><img src='images/enable.gif' border='0'></a>
													<?php 	}
													 if($single_rows['enable']==0)
													  	{ ?>
															<a href='?selectcate=<?=$selectcate?>&page=<?=$page?>&id=<?=$single_rows['ID']?>&ls=enable&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='不显示'><img src='images/unenable.gif' border='0'></a>
													<?php }?>
																				
														</td>
												  </tr>
												  
												<?php  $i++;
												 }?>
					</table>
					<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
					<tr >
					  <td width="15%" height="30" style="padding-left:6px;">
							<input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
							 所有
						     <button name="submit" type='submit' value='删除'>删除</button>
							<input name="Action" type="hidden" id="Action" value="singleDel">
							
							
					  </td>
					  <td width="44%" style="padding-left:6px;">注：自动建立模板，主题图如空，则为 images 下 链接名_banner.jpg</td>
					  <td width="34%" style="padding-left:6px;"><?=$page_string?></td>
							<td width="7%" height="30" align="center" style="padding-left:6px;"><span style="border-bottom:1px solid #FFF;"><img src="images/shao.gif" alt="" />&nbsp;<a href="addsinglepage.php?page=<?=$page?>&searchproductName=<?=$searchproductName?>"><u>添加</u></a></span></td>
					  </tr>
					</table>
				  </form>
				
					<form name="searcharticle" method="Post" action="?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>" >
			  <table align="center"  cellpadding="4px;" style="width:100%;background-color:#f0f0ee"><tr>
						<td width="99%" height="41" align="right"><span style="padding-left:6px;">
			      <input type="text" name="searchproductName" size="16" maxlength="50"  value="" />
			      <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></td>
						<td width="1%" align="right">&nbsp;</td>
						</tr>
			      </table>
				</form>  
				</td>
			</tr>
	</table>
 </body>
</html>