<?php
	session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	if ($_GET['ls_msg']=="")
	{
		$ls_msg="主题图片管理操作";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
		$ls=$_GET['ls'];
		$id=$_GET['id'];
	switch ($ls)
	{
		case "up":
			$up_sql="update ls_motif set Num=Num+1 where id=".$id." ";
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$ls_msg="下移操作成功！";
			break;
		case "down":
			$down_sql="update ls_motif set Num=Num-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$ls_msg="上移操作成功！";
			break;
	 	case "unenable":
			$unenable_sql="update ls_motif set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_motif set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
	  case "del":
	  	$select_sql="select * from ls_motif where ID=".$id."";
	  	$select_query=$opendb->query($select_sql);
	  	$select_myrows=mysql_fetch_assoc($select_query);
	  	//获取文件目录
	  	$Bigpicsrc="../".$MotifFolders."/".$BigFoldersProducts."/".$select_myrows['motifPic'];
			$Smallpicsrc="../".$MotifFolders."/".$SmallFoldersProducts."/".$select_myrows['motifPic'];
			//删除文件
			unlink($Bigpicsrc);
	  	$del_sql="delete from ls_motif where ID=".$id."";
	   		//echo $del_sql;
	   	$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">
		<script language="JavaScript" src="js/ls.js"></script>
		<title>无标题文档</title>
	</head>

 <body>
	<table width="99%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>主题图片管理</strong></font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top" bgcolor="#dee7ff"><br>
					<form name="del" method="Post" action="delall.php" onSubmit="return ConfirmDel();">
					<table border="0" width="98%" align="center">
						<tr>
							<td style="border-bottom:1px solid #FFF;">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right" style="border-bottom:1px solid #FFF;"><img src="images/shao.gif">&nbsp;<a href="addmotif.php"><u>添加主题图片</u></a></td>
						</tr>
					</table><br>
					
					<?php
					// 获取当前页数
													if( isset($_GET['page']) ){
													   $page = intval( $_GET['page'] );
													}
													else{
													   $page = 1;
													}
													// 每页数量
													$PageSize = $PageNum;
													
													// 获取总数据量
													/********************************************************************************/
													
														$sql = "select * from ls_motif order by ID desc";
														$result=$opendb->query($sql);
													
													/********************************************************************************/
													// 获取总数据量
													
													$row = mysql_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=?page=1><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?page='.($page-1).'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
													}
													if( ($page == $page_count) || ($page_count == 0) ){
													   $page_string .= ' 下一页 | 尾页';
													}
													else{
													   $page_string .= ' <a href=?page='.($page+1).'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?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="98%" align="center">
						<tr>
							<td><?php echo $ls_msg2; ?></td>
							<td align="right">共 <b><?php echo $row; ?></b> 个主题图</td>
						</tr>
					 </table>
					 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
					   <tr bgcolor="#B9DAFF">
					     <td align="center" width="2%">选中</td>
					     <td align="center" width="41%">首页主题图片</td>
					     <td align="center" width="12%">主题简介</td>
					     <td align="center" colspan="2" width="6%">排序</td>
					     <td align="center" colspan="2" width="6%">操作</td>
					     <td align="center" width="3%">显示</td>
				       </tr>
					   <?php
							$news_sql="select * from ls_motif order by Num desc limit ". ($page-1)*$PageSize .",".$PageSize." ";	
							$news_query=$opendb->query($news_sql);

							$i=1;
							while($news_rows=mysql_fetch_assoc($news_query))
							 {
						?>
					   <tr bgcolor='#f4f4f4'onmouseover="this.style.backgroundColor='#CCFFCC'" onmouseout="this.style.backgroundColor='#f4f4f4'" >
					     <td align='center'><input name='select_id<?=$i?>' type='checkbox' onclick="unselectall()" id="select_id2" value='<?=$news_rows['ID']?>' /></td>
					     <td style='padding-left:10px;'><img src="..\<?=$MotifFolders?>\<?=$BigFoldersProducts?>\<?=$news_rows['motifPic']?>" alt="" width="700" border="1" /></td>
					     <td style='padding-left:10px;'><?=$news_rows['motifText']?></td>
					     <td align='center'><? if($i!=1){?>
					       <a href='?page=<?=$page?>&id=<?=$news_rows['ID']?>&amp;nowNum=<?=$news_rows['Num']?>&amp;ls=up' title='向上移动'><img src='images/up.gif' alt="" border='0' /></a>
					       <? } ?></td>
					     <td align='center'><? if($i!=$amount){?>
					       <a href='?page=<?=$page?>&id=<?=$news_rows['ID']?>&amp;nowNum=<?=$news_rows['Num']?>&amp;ls=down' title='向下移动'><img src='images/down.gif' alt="" border='0' /></a>
					       <? } ?></td>
					     <td align='center'><a href='modimotif.php?page=<?=$page?>&id=<?=$news_rows['ID']?>' title='编辑'><img src='images/b_edit.png' alt="" border='0' /></a></td>
					     <td align='center'><a href='?page=<?=$page?>&id=<?=$news_rows['ID']?>&amp;ls=del' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' alt="" border='0' /></a></td>
					     <td align='center'><?
								if($news_rows['enable']==1){
							?>
					       <a href='?page=<?=$page?>&id=<?=$news_rows['ID']?>&amp;ls=unenable' title='显示'><img src='images/enable.gif' alt="" border='0' /></a>
					       <?
								}
								if($news_rows['enable']==0)
								{
							?>
					       <a href='?page=<?=$page?>&id=<?=$news_rows['ID']?>&amp;ls=enable' title='不显示'><img src='images/unenable.gif' alt="" border='0' /></a></td>
					     <? }
								$i++;
							 }
							?>
				       </tr>
					   <tr bgcolor="#B9DAFF">
					     <td colspan='8' align='center' height='25'><?=$page_string?></td>
				       </tr>
				      </table>
					 <br />
					 <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
					   <tr >
					     <td style="padding-left:6px;" colspan="8"><input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value="checkbox" />
					       选中本页显示的所有主题图
					       <input name="submit" type='submit' value='删除选定的产品' />
					       <input name="Action" type="hidden" id="Action" value="motifDel" /></td>
				       </tr>
				      </table>
					 <br />
					 <!--<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
				  <tr bgcolor="#B9DAFF">
							<td align="center" width="3%">&nbsp;</td>
							<td align="center" width="80%"><strong>默认主题图片（首页动画背景和其他页面主题图）</strong></td>
							<td width="7%" align="center">大小</td>
							<td align="center" width="10%">操作</td>
						</tr>
						<tr bgcolor='#f4f4f4'onMouseOver=this.style.backgroundColor='#CCFFCC' onMouseOut=this.style.backgroundColor='#f4f4f4' >
							<td align='center'></td>
							<td style='padding-left:10px;'><img src="<?=$defaultMotifFolders?>" width="700" border="1"></td>
                            <?  $picsize=getimagewh($defaultMotifFolders);
   								?>
							<td align='center'><p>宽：<?=$picsize[0]?><br />
							</p>
						    <p>高：<?=$picsize[1]?><br />
						    </p></td>
							<td align='center'><a href='modimotif.php?lso=default' title='编辑'><img src='images/b_edit.png' border='0'></a></td>
						</tr>
					</table> -->
					<br>
				  </form>
				
					
				</td>
			</tr>
	</table>
 </body>
</html>