<?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');

	$functionName=$_GET['functionName'];
	$cateName=$_POST['cateName'];
	$oldcateName=$_POST['oldcateName'];
	$suffStr=$_POST['suffStr'];
	$hotLines=$_POST['hotLines'];
	$hotWords=$_POST['hotWords'];
	
	$brief=$_POST['brief'];
	$Num=$_POST['Num'];

	
	if ($_GET['ls_msg']=="")
	{
		$ls_msg=$functionName."管理操作";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
		$ls=$_GET['ls'];
		$id=$_GET['id'];
	switch ($ls)
	{
		
	 	case "unenable":
			$unenable_sql="update ls_functioncates set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功！";
			break;
		case "enable":
			$enable_sql="update ls_functioncates 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_functioncates where ID=".$id."";
	   		//echo $del_sql;
	   	$del_query=$opendb->query($del_sql);
	   	$ls_msg="删除操作成功！";
			break;
			
		case "insert":
			$select_sql2="select * from ls_functioncates  where cateName='".trim($cateName)."' and functionName='".$functionName."' ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2_num=mysql_num_rows($select_query2); //总数
			if($select_rows2_num==0)
			{
				$insert_sql="insert into ls_functioncates (cateName,brief,functionName,hotLines,hotWords,Num) values ('".$cateName."','".$brief."','".$functionName."','".$hotLines."','".$hotWords."','".$Num."') ";
				//echo $insert_sql;
				$insert_query=$opendb->query($insert_sql);

				$ls_msg="添加操作成功！";
			}
			else
			{$ls_msg="分类已存在！";}
			break;
			
	case "modi":
			$modiid=$_POST['modiid'];
			$modi_sql="update ls_functioncates set cateName='".$cateName."', suffStr='".$suffStr."', Num='".$Num."',hotLines='".$hotLines."',hotWords='".$hotWords."',brief='".$brief."' where id=".$modiid." ";
					//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);

			//新闻表的分类
			$modi_sql="update ls_news  set cate ='".$cateName."'  where cate='".$oldcateName."' ";
			//	echo $modi_sql_article;
			$modi_query=$opendb->query($modi_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>
	<br />
	<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>
				  <?=$functionName?>
				管理</strong></font></div>
			  </td>
			</tr>
			<tr>
				<td height="258" valign="top" bgcolor="#dee7ff"><br />
				  <?php
					// 获取当前页数
						if( isset($_GET['page']) ){
						   $page = intval( $_GET['page'] );
						}
						else{
						   $page = 1;
						}
						// 每页数量
						$PageSize = $PageNum;
						
						// 获取总数据量
						/********************************************************************************/
						
							$sql = "select * from ls_functioncates where functionName='".$functionName."' order by Num 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=$functionName."管理操作";;
					
					?>
					
				
<table border="0" width="96%" align="center">
						<tr>
							<td><?php echo $ls_msg2; ?></td>
							<td align="right">共 <b><?php echo $row; ?></b> 个分类</td>
						</tr>
					 </table>
					 <table width="96%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
						<tr bgcolor="#B9DAFF">
							<td align="center" height="25" width="30">编号</td>
							<td width="241"  align="center" ><?=$functionName?></td>
							<td width="222"  align="center" >说明</td>
							<td width="69"  align="center" >标签标识</td>
							<td width="69"  align="center" >标题行数</td>
							<td width="55"  align="center" >标题字数</td>
						   <td align="center" width="52">排序</td>
							<td align="center" width="30">修改</td>
							<td align="center" width="30">删除</td>
							<td align="center" width="30">允许</td>
						</tr>
						<?php
						$functioncates_sql="select * from ls_functioncates where functionName='".$functionName."' order by  Num limit ". ($page-1)*$PageSize .",".$PageSize." ";	
						$functioncates_query=$opendb->query($functioncates_sql);
						
						$i=1;
						while($functioncates_rows=mysql_fetch_assoc($functioncates_query))
						{ ?>
						 <tbody id='ZH_<?=$functioncates_rows['ID']?>' >	
						   <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_id" value='<?=$functioncates_rows['ID']?>'>  --> <?=$functioncates_rows['ID']?>
							</td>
							<td style='padding-left:10px;'>
						<?=$functioncates_rows['cateName']?>
							</td>
							<td style='padding-left:10px;'>
						<?=$functioncates_rows['brief']?>
							</td>
							<td style='padding-left:10px;'><?=$functioncates_rows['suffStr']?></td>
							<td style='padding-left:10px;'><?=$functioncates_rows['hotLines']?></td>
							<td style='padding-left:10px;'><?=$functioncates_rows['hotWords']?></td>
							<td style='padding-left:10px;'>
						<?=$functioncates_rows['Num']?>
							</td>
			<td align='center'>
				<a href='javascript:secBoard(<?=$functioncates_rows['ID']?>);' title='编辑'><img src='images/b_edit.png' border='0'></a>
		  </td>
							<td align='center'> 
								<a href='?page=<?=$page?>&id=<?=$functioncates_rows['ID']?>&ls=del&functionName=<?=$functionName?>' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>
						  </td>
							<td align='center'>
						<?				  
						  if($functioncates_rows['enable']==1)
							{ ?>
								<a href='?page=<?=$page?>&id=<?=$functioncates_rows['ID']?>&ls=unenable&functionName=<?=$functionName?>' title='显示'><img src='images/enable.gif' border='0'></a>
							<? }
						  if($functioncates_rows['enable']==0)
						  	{ ?>
								<a href='?page=<?=$page?>&id=<?=$functioncates_rows['ID']?>&ls=enable&functionName=<?=$functionName?>' title='不显示'><img src='images/unenable.gif' border='0'></a>
							<? } ?>
						
							</td>
						</tr>
								</tbody>
		
		<tbody id='Z_<?=$functioncates_rows['ID']?>' style='display:none;'>
		 <form name='fm_menu' action='?ls=modi&page=<?=$page?>&functionName=<?=$functionName?>' method='post'> 

			<tr bgcolor='#CCCCCC'>
			<td align='center'> 
			</td>
				<td style='padding-left:5px;'>
					<input type='text' value='<?=$functioncates_rows['cateName']?>' name='cateName' size='44' class='inp'>
			   		<input type='hidden' value='<?=$functioncates_rows['cateName']?>' name='oldcateName' /></td>
				<td style='padding-left:5px;'>
					<input type='text' value='<?=$functioncates_rows['brief']?>' name='brief' size='44' class='inp'>
	 		  </td>
				<td style='padding-left:5px;'><input type='text' value='<?=$functioncates_rows['suffStr']?>' name='suffStr' size='6' class='inp' /></td>
				<td style='padding-left:5px;'><input type='text' value='<?=$functioncates_rows['hotLines']?>' name='hotLines' size='6' class='inp' /></td>
				<td style='padding-left:5px;'><input type='text' value='<?=$functioncates_rows['hotWords']?>' name='hotWords' size='6' class='inp' /></td>
				<td style='padding-left:5px;'>
					<input type='text' value='<?=$functioncates_rows['Num']?>' name='Num' size='10' class='inp'>
</td>
								<td colspan='3' align='center'>
									<input value='<?=$functioncates_rows['ID']?>' name='modiid' type='hidden'>
									<input type='submit' value='保存'>   
									<input type='button' onclick='javascript:secBoard2(<?=$functioncates_rows['ID']?>)' value='放弃修改'>
						 		</td>
			</tr>

		 </form>
		</tbody>
				<?
                $i++;
                 }?>
                <tr bgcolor="#B9DAFF">
                <td height='25' colspan="10" align='left'>
                 <span style="padding-left:360px">  <?=$page_string?> </span> </td>
                </tr>
            </table>
            <br />
            <form name="addcate" method="post" action="?ls=insert&functionName=<?=$functionName?>"  onSubmit="return checkSubmitForm('Num,cateName','序号,新闻分类');">
				  <table border="0" width="96%" align="center">
					<tr>
					  <td width="28%" >提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
					  <td colspan="5" align="right"  >&nbsp;</td>
					</tr>
					<tr>
					  <td  ><?=$functionName?>: 
					    <label>
						<input name="cateName" type="text" id="cateName" size="40">
					  </label></td>
					  <td width="25%" align="right" ><div align="left">简介:
					    <label>
					      <input name="brief" type="text" id="brief" size="40" />
					    </label>
					  </div></td>
					  <td width="15%" align="right"  ><span style="padding-left:5px;">
					    列表行数:
                            <input type='text' value='12' name='hotLines' size='6' class='inp' />
					  </span></td>
					  <td width="14%" align="right"  ><span style="padding-left:5px;">
					    标题字数:
                            <input type='text' value='36' name='hotWords' size='6' class='inp' />
					  </span></td>
					  <td width="10%" align="right"  >序号:
                        <?
                        	$select_sql2="select * from ls_functioncates    ";
							//echo $select_sql2;
							$select_query2=$opendb->query($select_sql2);
							$select_rows2_num=mysql_num_rows($select_query2); //总数
						?>
                        <input name="Num" id="Num"  type="text" style="width:40px;" value="<?=($select_rows2_num+1)*5?>" size="6" maxlength="6" /></td>
					  <td width="8%" align="right"  ><input type="submit" name="button" id="button" value="添加" /></td>
					</tr>
				  </table>
				  </form>
				  <br />
            </td>
        </tr>
	</table>
 </body>
</html>