<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id: ,v1 10:39 2008-7-27 Leilei $
*/

require("../../include/header.php");
html_start("页面列表 - VeryIDE");
?>

<!--body start-->
<?php

	//form
	require("config.php");
	require("function.php");	
	
	$sid = GetNumber("sid",0);

	$list = GetQuery("list");
	$status = GetNumber("status",1);
	$order = GetQuery("order");
	
	$action = GetQuery("action");

	//mysql open
	reader_mysql();

	
	if ($action){
	
		switch($action){
			//删除
			case "delete":
			
				//检查权限
				checker_func("mod-shop-page-del");		

				mysql_query("delete from ".VI_DBMODPRE."page where id in(".$list.")");
				
				$Project["message"]="页面删除成功！";
			
			break;
			
			//状态
			case "update":
			
				//检查权限
				checker_func("mod-shop-page-mod");		
			
				$link_list=$_POST["all"];
				$link_array=explode(",",$link_list);
				for($i=0;$i<count($link_array);$i++){
				
					$id=intval($link_array[$i],0);
					$title=$_POST["p_".$id."_title"];
					
					if($id>0 && $title){
					
						$sort=$_POST["p_".$id."_sort"];
				
						$sql="update ".VI_DBMODPRE."page set title='".$title."',sort='".$sort."' where id=".$id;
						mysql_query($sql,$mysql);
					}
				}
				
				//缓存页面缓存
				//cache_rows($appid,$mysql,VI_DBMODPRE."page","select * from ".VI_DBMODPRE."page where id in(".$list.")");		
				cache_multi($appid,$mysql,VI_DBMODPRE."page","select * from ".VI_DBMODPRE."page where sid=".$sid." order by sort asc,id desc","page.$sid");		
				
				$Project["message"]="页面更新成功！";
				
			break;
			
			case "status":
			
				//检查权限
				checker_func("mod-shop-page-mod");		
				
				$sql="update ".VI_DBMODPRE."page set status=".$status." where id in(".$list.")";
				mysql_query($sql);
				
				$Project["message"]="页面修改成功！";
				
			break;
			
		}
				
		$Project["jump"] = "";
		
	}
	
?>
	<?php
	
	//加载缓存
	loader_cache($appid,"shop.".$sid);
	
	echo '
    <div id="nav">
        <strong>'.$VICACHE["mod.shop"]["name"].'</strong> 	
    </div>
    
    <ul id="naver">
        <li><a href="page.edit.php?sid='.$sid.'">新增页面</a></li>
        <li><a href="page.list.php?sid='.$sid.'">管理页面</a></li>
    </ul>
	';
	?>
    
    
    
	<script type="text/javascript">
    Mo.reader(
        function(){
            
            /*筛选表格*/
            Mo.Table($T("table")[0],
                [
                    'dblclick',function(o,event){
                        var pid = o.getAttribute("pid");
                        location.href='page.edit.php?action=edit&sid=<?php echo $sid;?>&id='+pid+'&jump='+encodeURIComponent(location.href);
                    }
                ]
            );
            
        }
    );
    </script> 
    
    <div id="box">
    
    <form action="?" method="post" verify="true">
    	<input name="sid" type="hidden" value="<?php echo $sid;?>" />
    
    <?php		
    //echo $mysql;
    
    $sql="SELECT * FROM ".VI_DBMODPRE."page where sid = ".$sid;
    if ($q){
        $sql.=" and  ".$s." like '%".$q."%'";
    }
    
    //排序
    $sql.=" order BY sort asc,id desc";
    
    ?>
        <table width="100%" border="0" cellpadding="1" cellspacing="1" id="table" class="table">
          <tr class="title">
            <td>ID</td>
            <td>排序 <script type="text/javascript">Mo.Tools("Tip","从小到大依次排序");</script></td>
            <td>页面标题</td>
            <td>所属用户</td>
            <td>状态</td>
            <td width="50">操作</td>
          </tr>
        <?php
        
        $result=mysql_query($sql,$mysql);
        
        $all = array();
		
        while($row=mysql_fetch_assoc($result)){
            $id=$row["id"];
            
            array_push($all,$row["id"]);
            ?>
              <tr class="line" pid="<?php echo $row["id"];?>">
                    <td>
                        <?php echo $row["id"];?>
                    </td>
                <td>
                    <input name="p_<?php echo $row["id"];?>_sort" type="text" class="text" size="5" value="<?php echo $row["sort"];?>" fix_name="页面排序" fix_number="yes" />
                </td>
                
                <td>
                    <input name="p_<?php echo $row["id"];?>_title" type="text" class="text" value="<?php echo $row["title"];?>" fix_name="页面标题" fix_null="yes" />
                </td>
               <td><a><?php echo $row["account"];?></a></td>
				<td id="s-<?php echo $row["id"];?>" class="next">
					<script type="text/javascript">
						Mo.Status($("s-<?php echo $row["id"];?>"),"r-<?php echo $row["id"];?>","?action=status&sid=<?php echo $sid;?>&list=<?php echo $row["id"];?>&status=",["禁用","正常"],<?php echo $row["status"];?>,0,25);
					</script>            
				</td>
                <td>
            
                <?php
                echo "
                <script type='text/javascript'>
                    Mo.Tools('RsEdit','page.edit.php?action=edit&sid=".$sid."&id=".$row["id"]."','');
                    Mo.Tools('RsDelete','page.list.php?action=delete&sid=".$sid."&list=".$row["id"]."','');
                </script>
                ";
                
                ?>
                </td>
              </tr>
            <?php
            
                $i++;
            }
            ?>
            </table>
            <?php
  
			//mysql close
			reader_mysql(true);
            ?>
				
        <div id="saving">
            <input type="hidden" name="all" value="<?php echo implode(",",$all);?>" />
            <input name="action" id="action" type="hidden" value="update" />
            <input type="submit" class="submit" value="保存更改" />
        </div>
    
	</form>
    
    </div>
				
<!--body end-->

<?php html_close();?>