<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	2011/6/5 Lay
*/

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

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

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

	$list = getgpc('list');
	$state = getnum("state",1);
	$order = getgpc("order");
	
	$action = getgpc('action');

	//连接数据库
	System :: connect();

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

				System :: $db -> execute("DELETE FROM `mod:page` WHERE id in(".$list.")");
				
				$_G['project']['message']="页面删除成功！";
			
			break;
			
			//状态
			case "update":
			
				//检查权限
				System :: check_func("mod-shop-page-mod", false );		
			
				$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 `mod:page` SET title='".$title."',sort='".$sort."' WHERE id=".$id;
						System :: $db -> execute( $sql );
					}
				}
				
				//缓存页面缓存
				//Cached :: rows( $appid,"SELECT * FROM `mod:page` WHERE id in(".$list.")");		
				Cached :: multi( $appid,"SELECT * FROM `mod:page` WHERE sid=".$sid." ORDER BY sort asc,id desc","page.$sid");		
				
				$_G['project']['message']="页面更新成功！";
				
			break;
			
			case "state":
			
				//检查权限
				System :: check_func("mod-shop-page-mod", false );		
				
				$sql="UPDATE `mod:page` SET state=".$state." WHERE id in(".$list.")";
				System :: $db -> execute( $sql );
				
				$_G['project']['message']="页面修改成功！";
				
			break;
			
		}
				
		$_G['project']['jump'] = "";
		
	}
	
?>
	<?php
	
	//加载缓存
	Cached :: loader($appid,"shop.".$sid);
	
	echo '
    <div id="nav">
        <strong>'.$_CACHE["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 `mod: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 = System :: $db -> getAll( $sql );
        
        $all = array();
		
        foreach( $result as $row ){
            $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.state($("s-<?php echo $row['id'];?>"),"r-<?php echo $row['id'];?>","?action=state&sid=<?php echo $sid;?>&list=<?php echo $row['id'];?>&state=",["禁用","正常"],<?php echo $row['state'];?>,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
  
			//关闭数据库
        System :: connect();
            ?>
				
        <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();?>