<?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("function.php");
	require("config.php");	

	//mysql open
	reader_mysql();

	$sid = GetNumber("sid",0);
	
	$jump = GetQuery("jump");
	$action = GetQuery("action");
	$id = GetNumber("id",0);
	
	if ($action){

		$title = GetQuery("title");
		$status = GetQuery("status");
		/**************/
		
		$sort = GetNumber("sort",0);
		
		$attr=addslashes($_POST["attr"]);
		
		$content=($_POST["content"]);
		//$content=stripslashes($_POST["content"]);
		
		//exit($content);
		
		switch($action){
			case "add":
			
				//检查权限
				checker_func("mod-shop-page-add");		

				$sql="insert into ".VI_DBMODPRE."page(title,uid,account,status,content,sid,sort,dateline) values('".$title."',".$_SESSION["Manager"]["id"].",'".$_SESSION["Manager"]["account"]."',".$status.",'".$content."','".$sid."','".$sort."',".time().")";
				
				mysql_query($sql,$mysql);
			
		
				$Project["queries"]++;
				
				$id = mysql_insert_id($mysql);
				
				//错误处理
				if (!$id) {
					trigger_error($sql, E_USER_ERROR);
					exit();
				}
				
				//缓存页面缓存
				//cache_rows($appid,$mysql,VI_DBMODPRE."page","select * from ".VI_DBMODPRE."page where id=".$id);		
				cache_multi($appid,$mysql,VI_DBMODPRE."page","select * from ".VI_DBMODPRE."page where sid=".$sid." order by sort asc,id desc","page.$sid");				
				
				$sql="update ".VI_DBMODPRE."shop set modify=".time()." where id=".$sid;
				mysql_query($sql);
			
				reader_redirect("page.list.php?sid=".$sid,"信息提交成功!");
				
			break;
			
			case "update":
			
				//检查权限
				checker_func("mod-shop-page-mod");		

				$sql="update ".VI_DBMODPRE."page set title='".$title."',status=".$status.",content='".$content."',sort='".$sort."',modify=".time()." where id=".$id." and sid=".$sid;
				mysql_query($sql);
				
				//缓存页面缓存
				//cache_rows($appid,$mysql,VI_DBMODPRE."page","select * from ".VI_DBMODPRE."page where id=".$id);		
				cache_multi($appid,$mysql,VI_DBMODPRE."page","select * from ".VI_DBMODPRE."page where sid=".$sid." order by sort asc,id desc","page.$sid");		
				
				$sql="update ".VI_DBMODPRE."shop set modify=".time()." where id=".$sid;
				mysql_query($sql);
			
				reader_redirect("page.list.php?sid=".$sid,"信息修改成功!");
			
			break;
			
			case "edit";

				$sql="select * from ".VI_DBMODPRE."page where id=".$id;
				$result=mysql_query($sql,$mysql);
				
				if(mysql_num_rows($result)==1){
					$row=mysql_fetch_assoc($result);
					
				}
			
			break;
		}
		
	  }
	  
	  
	//mysql close
	reader_mysql(true);
	  
	  ?>
<!--main-->
	<?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>
	';
	?>
    
    
    
	<?php    
    echo loader_script(array(VI_BASE."editor/kindeditor.js"),"UTF-8",$Project["version"]);    
    ?>

	<?php
	
	//显示权限状态
	switch($action){
		case "":
			echo checker_func("mod-shop-page-add",true);
		break;
		
		case "edit":
			echo checker_func("mod-shop-page-mod",true);
		break;
	}
	
	?>

	<div id="box">
		<form action="?" method="post" name="from1" mode="edit" verify="true">     
        
        	<input type="hidden" name="sid" value="<?php echo $sid;?>" />   
                        
        <table cellpadding="0" cellspacing="0" class="form">
        
            <tr>
                <td width="60"><strong>页面标题：</strong></td>
                <td>
                	<input name="title" type="text" class="text" id="title" value="<?php echo $row["title"];?>" size="35" fix_name="页面标题" fix_null="yes" />
                </td>                
            </tr>
        
            <tr>
                <td><strong>所属商家：</strong></td>
                <td>
                	<?php echo $VICACHE["mod.shop"]["name"];?>
                </td>                
            </tr>
        
            <tr>
                <td><strong>详细内容：</strong></td>
                <td>
                	<textarea name="content" cols="50" rows="10" id="content" style="width:95%;height:350px;"><?php echo $row["content"];?></textarea>
					<script type="text/javascript">
					KE.show({
						id : 'content',
						resizeMode : 2,
						newlineTag : 'p',
						allowFileManager : true,
						filterMode : false,
						loadStyleMode : false
						//cssPath : './css/common.css'
					});
                    </script>  
                </td>                
            </tr>
        
            <tr>
                <td><strong>页面排序：</strong></td>
                <td>
                	<input name="sort" type="text" class="text" id="sort" value="<?php echo $row["sort"];?>" /> 
                     <script type="text/javascript">Mo.Tools("Tip","从小到大依次排序");</script>
                </td>                
            </tr>
        
            <tr>
                <td><strong>页面开放：</strong></td>
                <td>
                        
					<?php
                    
                    $i = 0;
                    foreach($Project["status"] as $key){
                        echo '<label><input type="radio" class="radio" '.($i==1?'checked="checked"':'').' name="status" value="'.$i.'" /> '.$key.'</label>';
						$i++;
                    }
                    
                    ?>
                        
                </td>                
            </tr>
            
            <tr class="nobr">
                <td><strong></strong></td>
                <td>
                    <?php
                        if ($action=="edit"){
                            echo '
                            <input name="action" type="hidden" id="action" value="update" />
                            <input name="id" type="hidden" id="id" value="'.$row["id"].'" />
                            ';
                            echo '<input type="submit" name="Submit" value="修改此页面" class="submit" />';
                        }else{
                            echo '<input name="action" type="hidden" id="action" value="add" />';
                            echo '<input type="submit" name="Submit" value="新增此页面" class="submit" />';
                        }
                    ?>
                </td>				
            </tr>
		</table>
	 </form>
	</div>
    
	<script type='text/javascript'>
    	Mo("input[name=status]").value("<?php echo $row["status"];?>");
    </script>
	
<!--body end-->

<?php html_close();?>