<?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();
	
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$modiid=$_POST['modiid'];
	$menuName=$_POST['menuName'];
	$menuLink=$_POST['menuLink'];
	$nowmenunum=$_GET['menuNum'];

	$ls_msg="主菜单管理操作";
	
	
	
	
	switch ($ls)
	{
		case "up":
			$down=$nowmenunum-1;
			$down_sql="update ls_menu set menuNum=".$nowmenunum." where menuNum=".$down." ";
			$down_sql2="update ls_menu set menuNum=menuNum-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);
			$ls_msg="上移操作成功！";
			break;
		case "down":
			$up=$nowmenunum+1;
			$up_sql="update ls_menu set menuNum=".$nowmenunum." where menuNum=".$up."  ";
			$up_sql2="update ls_menu set menuNum=menuNum+1 where id=".$id." ";
			
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);

			$ls_msg="下移操作成功！";
			break;
		case "insert":
			$Num_sql2="select * from ls_menu ";
			$Num_query2=$opendb->query($Num_sql2);
			$Num_rows2=mysql_num_rows($Num_query2); //总数
		
			$insert_sql="insert into ls_menu(menuName,menuLink,menuNum,enable) values ('".$menuName."','".$menuLink."',".($Num_rows2+1).",1)";
			//echo $insert_sql;
			$insert_query=$opendb->query($insert_sql);
			$ls_msg="添加操作成功！";
			break;
		case "modi":
			$modi_sql="update ls_menu set menuName='".$menuName."' where id=".$modiid." ";
			//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);
			$ls_msg="修改操作成功！";
			break;
		case "del":
			$menu_sql2="select * from ls_menu where id=".$id." ";
			$menu_query2=$opendb->query($menu_sql2);
			$menu_rows2=mysql_fetch_assoc($menu_query2);
			$num_sql2="update ls_menu set menuNum=menuNum-1 where menuNum>".$menu_rows2['menuNum']." ";//all order number-1
			$down_query=$opendb->query($num_sql2);
		
			$del_sql="delete from ls_menu where id=".$id." ";
			//echo $del_sql;
			$del_query=$opendb->query($del_sql);
			$ls_msg="删除操作成功！";
			break;
		case "unenable":
			$unenable_sql="update ls_menu set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_menu set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
	}
	
	$menu_sql="select * from ls_menu order by menuNum asc";
	$menu_query=$opendb->query($menu_sql);
	$menu_num=mysql_num_rows($menu_query);	
	
?>
<!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="96%" 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>
					<table border="0" width="96%" align="center">
						<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
						</tr>
					</table>
					
					<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
					 <tr bgcolor="#B9DAFF"> 
						<td align="center" width="62" height="28">序号</td>
						<td align="center" width="189" height="28">菜单名</td>
						<td align="center" width="190">菜单链接</td>
						<td width="267" align="center">主题图</td>
						<td align="center" colspan="2">排序</td>
						<td align="center" colspan="2">操作</td>
						<td align="center" width="53">有效</td>
					  </tr>
					 <?php 
					 $i=1;
					  while ($menu_rows=mysql_fetch_assoc($menu_query))
					  {
						echo "<tbody id='ZH_".$menu_rows['ID']."' >";	
						echo "<tr bgcolor='#f4f4f4'";
						echo "onMouseOver=";
						echo " 	this.style.backgroundColor='#CCFFCC' ";
						echo "onMouseOut=";
						echo " 	this.style.backgroundColor='#f4f4f4' ";
						echo ">";	
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$menu_rows['menuNum'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:20px;' height='25' >";
					  	echo 		$menu_rows['menuName'];
						echo "	</td>";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'>";
					  	echo 		$menu_rows['menuLink'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'>";
						$picName="motif_".strtolower(str_replace(" ","",$menu_rows['argument'])); //获得文件名
						$folderPic="../".$MotifFolders."/".$picName;
					  	echo 		(file_exists($folderPic)? "<img src=\"".$folderPic."\" width=\"180\" height=\"70\"  border='0' />":"")
									."<a href='modimotif.php?lso=pagemotif&folderPic=".urlencode($folderPic)."&menuName=".urlencode($menu_rows['menuName'])."' title='主题图、页面说明管理'>
									<img src=\"images/b_add.gif\" width=\"16\" height=\"16\" alt='主题图管理' border='0'/ ></a>";
						echo "	</td>";
						echo "	<td align='center'> ";
						if($i!=1)// not start up
						{						
							echo "	<a href='?id=".$menu_rows['ID']."&menuNum=".$menu_rows['menuNum']."&ls=up' title='向上移动'><img src='images/up.gif' border='0'></a>";
						}
						echo "  </td>";
						echo "	<td align='center'> ";
						if($i!=$menu_num)// not end down
						{
							echo "	 <a href='?id=".$menu_rows['ID']."&menuNum=".$menu_rows['menuNum']."&ls=down' title='向下移动'><img src='images/down.gif' border='0'></a>";
						}
						echo "  </td>";
						echo "	<td align='center'> ";
						echo "	<a href='javascript:secBoard(".$menu_rows['ID'].")' title='编辑'><img src='images/b_edit.png' border='0'></a>";
						echo "  </td>";
						echo "	<td align='center'> ";
						if($menu_rows['menuAdmin']==1)
						{
							echo "	<img src='images/b_undrop.png' border='0'>";
						}
						if($menu_rows['menuAdmin']==0)
						{
							echo "		<a href='?id=".$menu_rows['ID']."&ls=del' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>";
						}
						echo "  </td>";
						echo "	<td align='center'>";
						  
						  if($menu_rows['enable']==1)
							{
								echo "<a href='?id=".$menu_rows['ID']."&ls=unenable' title='显示'><img src='images/enable.gif' border='0'></a>";
							}
						  if($menu_rows['enable']==0)
						  	{
								echo "<a href='?id=".$menu_rows['ID']."&ls=enable' title='不显示'><img src='images/unenable.gif' border='0'></a>";
							}
						  if($menu_rows['enable']==2)
						  	{
								echo "<img src='images/disable.gif' border='0' alt='选项禁用'>";
							}
													
						echo "	</td>";
						echo "</tr>";
						echo "</tbody>";
						
						echo "<tbody id='Z_".$menu_rows['ID']."' style='display:none;'>";
						echo " <form name='fm_menu' action='?ls=modi' method='post'> ";
						echo "	<tr bgcolor='#CCCCCC'>";
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$menu_rows['menuNum'];
						echo "	</td>";
						echo "		<td style='padding-left:20px;'>";
						echo "			<input type='text' value='".$menu_rows['menuName']."' name='menuName' class='inp'> ";
						echo " 		</td>";
						echo "		<td style='padding-left:20px;'>";
						echo 			$menu_rows['menuLink'];
						echo " 		</td>";
						echo "		<td style='padding-left:20px;'>";
						echo 			$menu_rows['subjectPic'];
						echo " 		</td>";
						echo "		<td colspan='5' align='center'>";
						echo "			<input value='".$menu_rows['ID']."' name='modiid' type='hidden'>";
						echo "			<input type='submit' value='确定修改'> &nbsp; ";
						echo "			<input type='button' onclick='javascript:secBoard2(".$menu_rows['ID'].")' value='放弃修改'>";
						echo " 		</td>";
						echo "	</tr>";
						echo " </form>";
						echo "</tbody>";
						$i++;
					  }
					 ?> 
					</table>
					
					
					<form name="fmaddmenu" action="?ls=insert" method="post">
					 <table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
						 <tr bgcolor="#B9DAFF"> 
							<td height="28" style='padding-left:20px;'>菜单名:<input type="text" name="menuName"></td>
							<td style='padding-left:20px;'>菜单链接：<input type="text" name="menuLink"></td>
							<td align="center"><input type="submit" value="添加菜单"></td>
							
					   </tr>
					  </table>
				  </form>
					
					
				</td>
			</tr>
		</table>
	</body>
</html>