<?php

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

require '../../include/loader.php';
html_start("表单数据 - VeryIDE");
?>

<!--body start-->

	<?php

	$appid = Module :: get_appid();

	//module
	require 'config.php';

	//表单id
	$fid = getnum('fid',0);
	
	//记录id
	$id = getnum('id',0);
	
	//加载缓存
	if( !Cached :: loader($appid,"form.".$fid) ){
		exit('Cache Error!');
	}

	?>
    
    <div class="item">
        <strong><?php echo $_CACHE[$appid]['form']["name"];?></strong> 修改用户数据 	
    </div>
    
	<?php
	$q = getgpc('q');
	$s = getgpc("s");
	
	$list = getgpc('list');
	$state = getnum("state",1);
	$order = getgpc("order");
	$action = getgpc('action');
	
	//连接数据库
	System :: connect();

	if ($action){
	
		switch($action){
			
			case "update":
			
				//检查权限
				System :: check_func( 'mod-form-mod', false );
	
				//用户信息
				$sql="SELECT * FROM `mod:value` WHERE id=".$id;
				
				$row = System :: $db -> getOne( $sql );

                if( $row ){
					
					//删除空白字符
					$row['config'] = preg_replace("/([\r\n\t\f])/"," ",$row['config']);
					
					//配置
					$data = fix_json( $row['config'] );	
					
					//写入新值
					foreach( $_POST as $k => $v ){
						if( !in_array( $k, array('id','action') ) ){
							$data[$k] = $v;
						}
					}
				
					//记录用户提交数据	
					$data = format_json( fix_json($data) );
					
					$sql="UPDATE `mod:value` SET config='".$data."' WHERE id = ".$id;
					System :: $db -> execute($sql);
					
				}
				
				echo '<div id="state">用户数据修改成功!</div>';

			break;
			
		}
	}
	
		
	//用户信息
    $sql="SELECT * FROM `mod:value` WHERE id=".$id;
	
    $row = System :: $db -> getOne( $sql );

	if( $row ){
		
		//删除空白字符
		$row['config'] = preg_replace("/([\r\n\t\f])/"," ",$row['config']);
		
		//配置
        $config = fix_json( $row['config'] );	
		
    }
	
    ?>
    
    <div id="box">
    
    <form action="" name="formPost" id="formPost"  method="post">
    
    <table width="100%" border="0" cellpadding="1" cellspacing="1" id="table" class="table">
                    
        <?php
        
        //用户数据
		$i = 0;
        foreach ($_CACHE[$appid]['group'] as $gid => $group){
			
			if ( in_array($group["type"],array("text","textarea","file")) ){
				
				if( $group["type"] == "" ){
					$val = '<textarea name="G-'.$gid.'">'.$config["G-".$gid].'</textarea>';	
				}else{
					$val = '<input name="G-'.$gid.'" value="'.$config["G-".$gid].'" size="60" />';	
				}
			
           		echo '<tr class="'.($i%2?'title':'line').'"> <td align="right">'.$group["name"].'</td> <td>'.$val.'</td></tr>';
				
				$i++;
			}
			
        }
        ?>
    </table>
    
    	<div id="saving">	
        <input type="hidden" name="id" value="<?php echo $id;?>" />
        <input name="action" id="action" type="hidden" value="update" />
        <input type="submit" class="submit" value="保存更改" />
        </div>
    
    </form>
    
    </div>
    
    <?php
  
	//关闭数据库
	System :: connect();
    
    ?>
    
<!--body end-->

<?php html_close();?>