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

	$dispname="栏目系统";
	$nowNum=$_GET['nowNum'];
	$subjectpicFile=$_POST['subjectpicFile'];
	$brief=$_POST['brief'];
	$mydate=$_POST['mydate'];
									/* 添加POST变量标志，勿动 */
	
//上面勿删空格和换行

	$oldsubjectpicFile=$_POST['oldsubjectpicFile'];
	$oldbrief=$_POST['oldbrief'];
	if($_GET['brief']!="")
	{$brief=$_GET['brief'];}
	$postcode=$_POST['postcode'];
	
	if ($_GET['ls_msg']=="")
	{
		$ls_msg=$subjectpicFile."系统管理操作";
	}	
	else
	{
		$ls_msg=$_GET['ls_msg'];	
	}
		$ls=$_GET['ls'];
		$id=$_GET['id'];
	switch ($ls)
	{
			case "up":
			$down=$nowNum-1;
			$down_sql="update ls_subjectpic set Num=".$nowNum." where Num=".$down." ";
			$down_sql2="update ls_subjectpic set Num=Num-1 where id=".$id." ";
			//echo $down_sql;
			$down_query=$opendb->query($down_sql);
			$down_query=$opendb->query($down_sql2);
			$ls_msg="上移操作成功！";
			echo "<script>window.open(\"masterplate_tpl.php\",   \"right\")   </script>";//重新打开；不可刷新，否则会重复禁止操
			break;
	//下移
		case "down":
			$up=$nowNum+1;
			$up_sql="update ls_subjectpic set Num=".$nowNum." where Num=".$up."  ";
			$up_sql2="update ls_subjectpic set Num=Num+1 where id=".$id." ";
			
			//echo $up_sql;
			$up_query=$opendb->query($up_sql);
			$up_query=$opendb->query($up_sql2);

			$ls_msg="下移操作成功！";
			echo "<script>window.open(\"masterplate_tpl.php\",   \"right\")   </script>";//重新打开；不可刷新，否则会重复禁止操
			break;
		
	 	case "unenable":
			$unenable_sql="update ls_subjectpic set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="不显示操作成功,，系统下的文章都将不显示！";
			break;
		case "enable":
			$enable_sql="update ls_subjectpic set enable=1 where id=".$id." ";
			//echo $enable_sql;
			$enable_query=$opendb->query($enable_sql);
			$ls_msg="显示操作成功！";
			break;
		case "del":
		
			$lssql2="select * from ls_subjectpic where ID='".$id."' ";
			$ls_query2=$opendb->query($lssql2);
			$ls_rows2=mysql_fetch_assoc($ls_query2);
            $num_sql2="update ls_subjectpic set Num=Num-1 where Num>".$ls_rows2['Num']." ";//all order number-1
			$down_query=$opendb->query($num_sql2);

			$del_sql="delete from ls_subjectpic where ID=".$id."";
	   		//echo $del_sql;
	   		$del_query=$opendb->query($del_sql);
	  	 	$ls_msg="删除操作成功！";
			writelog($_SERVER['PHP_SELF'],"delete column(function) ","ID: ".$id);
			break;
			
	
			
	case "modi":
			$modiid=$_POST['modiid'];
			$modi_sql="update ls_subjectpic set subjectpicFile='".$subjectpicFile."',brief='".$brief."',mydate='".$mydate."'  where id=".$modiid." ";/* 添加modi_sql标志，勿动 */
					//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);
			//全部系统

			writelog($_SERVER['PHP_SELF'],"modify column(function) "."brief: ".$brief." subjectpicFile: ".$subjectpicFile,"ID: ".$modiid);

			$ls_msg="修改操作成功！";
			break;
	}
?>
<html>
<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>首选服务 - ls-webmotor</title>
	</head>

 <body>
         <?php
					// 获取当前页数
				if( isset($_GET['page']) ){
				   $page = intval( $_GET['page'] );
				}
				else{
				   $page = 1;
				}
				// 每页数量
				$PageSize = $Pagemessage;
				
				// 获取总数据量
				/********************************************************************************/
				
					$sql = "SELECT * FROM `ls_subjectpic` 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="";
					
					?>
	<table width="98%" 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">
                <span style="height:20;margin-left:10px;margin-top:10px;" >提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></span>
                <table border="0" width="99%" align="center">
          <tr>
							<td></td>
							<td align="right">共 <b><?php echo $row; ?></b> 个系统</td>
				  </tr>
				  </table>
        		<table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
        		  <tr bgcolor="#B9DAFF">
        		    <td  width="20" align="center">选择</td>
        		    <td height="25"  width="18" align="center">序号</td>
        		    <td  align="center">主题图图片文件</td>
        		    <td  align="center">简要说明</td>
        		    <td  align="center">添加时间</td>
        		    
        		    
        		    
        		    
        		    
        		    
        		    
        		    
                     <!-- 添加表头标志，勿动 -->
        		    <td  colspan='3'  align="center" >修改</td>
        		    <td width="27" align="center" >删除</td>
        		    <td align="center" width="34">允许</td>
      		    </tr>
        		  <?php
				$functioncates_sql="SELECT * FROM `ls_subjectpic` order by  Num limit ". ($page-1)*$PageSize .",".$PageSize." ";	
				$functioncates_query=$opendb->query($functioncates_sql);
						
				$i=1;
				while($message_rows=mysql_fetch_assoc($functioncates_query))
				 {?>
        		  <tbody id='ZH_<?=$message_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='<?=$message_rows['ID']?>'></td>
        		      <td align='center'><?=$i?></td>
        		      <td style='padding-left:10px;'><?=$message_rows['subjectpicFile']?></td>
        		      <td style='padding-left:10px;'><?=$message_rows['brief']?></td>
        		      <td style='padding-left:10px;'><?=$message_rows['mydate']?></td>
        		     
        		     
        		     
        		     
        		     
        		     
        		     
         		     
                      <!-- 显示字段标志，勿动 -->

                      <td align='center'>
					  <? if($i!=1)// not start up
						{
						?>	<a href='?id=<?=$message_rows['ID']?>&nowNum=<?=$message_rows['Num']?>&ls=up' title='向上移动'><img src='images/up.gif' border='0'></a>
						<? } ?>
					  </td><td align='center'> 
						<? if($i!=$amount)// not end down
						{ ?>
							<a href='?id=<?=$message_rows['ID']?>&nowNum=<?=$message_rows['Num']?>&ls=down' title='向下移动'><img src='images/down.gif' border='0'></a>
						<? }  ?>
						</td>

        		      <td align='center'><a href='javascript:secBoard(<?=$message_rows['ID']?>);' title='编辑'><img src='images/b_edit.png' border='0'></a></td>
        		      <td align='center'><a href='?id=<?=$message_rows['ID']?>&ls=del&name=<?=$subjectpicFile?>&brief=<?=$brief?>' onClick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a></td>
        		      <td align='center'>
				<?						  
				  if($message_rows['enable']==1)
					{
						echo	"<a href='?id=".$message_rows['ID']."&ls=unenable&name=".$subjectpicFile."''&brief=".$brief."' title='显示'><img src='images/enable.gif' border='0'></a>";
					 }
				  if($message_rows['enable']==0)
				  	{
					echo  "	<a href='?id=".$message_rows['ID']."&ls=enable&name=".$subjectpicFile."''&brief=".$brief."' title='不显示'><img src='images/unenable.gif' border='0'></a>";
					}?></td>
      		      </tr>
      		    </tbody>
        		  <tbody id='Z_<?=$message_rows['ID']?>' style='display:none;'>
      		    <form name='fm_menu' action='?ls=modi&page=<?=$page?>&subjectpicFile=<?=$subjectpicFile?>' method='post'>
      		      <tr bgcolor='#CCCCCC'>
      		        <td align='center'>&nbsp;</td>
      		        <td align='center'>&nbsp;</td>
      		        <td style='padding-left:5px;'><input type='text' value='<?=$message_rows['subjectpicFile']?>' name='subjectpicFile' size='16' class='inp'>
   		            <input type='hidden' value='<?=$message_rows['subjectpicFile']?>' name='oldsubjectpicFile' ></td>
      		        <td style='padding-left:5px;'>
   		            <input type='text' value='<?=$message_rows['brief']?>' name='brief' size='16' class='inp'>      		        </td>
      		        <td style='padding-left:5px;'><input type='text' value='<?=$message_rows['mydate']?>' name='mydate' size='16' class='inp'></td>
      		             		             		             		             		             		             		             		                           <!-- 修改字段标志，勿动 -->


      		        <td colspan='7' align='center'><input value='<?=$message_rows['ID']?>' name='modiid' type='hidden'>
      		          <input type='submit' value='确定'>
      		          &nbsp;
      		          <input type='button' onClick='javascript:secBoard2(<?=$message_rows['ID']?>)' value='放弃'></td>
   		          </tr>
    		      </form>
        		  <?		 $i++;		}?>
                    <tr>
                      <td>                      
                    </tbody> 
        		  <tr  bgcolor="#B9DAFF">
        		    <td colspan='18' align='right' height='25'><?=($page_count==0||$page_count==1?"":$page_string)?></td>
      		    </tr>
               
      		  </table>
        		<span style="padding-left:10px;">
        		<?=$message_rows['subjectpicFile1']?>
       		  </span></td>
			</tr>
	</table>
</body>
</html>