<?php

/*
*	Copyright VeryIDE,2007-2010
*	http://www.veryide.com/
*
*	$Id:veryide.profile.php ,v1 10:39 2008-10-16 Lay $
*/

require '../../include/loader.php';
html_start("用户编辑 - VeryIDE");
?>

<!--body start-->
	<?php
	
	//module
	require 'naver.php';
	
	//菜单处理
	$action = getgpc('action');
	$jump = getgpc('jump');
	
	//下一步
	$next=true;
	
	if(!$jump) $jump="admin.list.php";
	
	$people = getgpc("people");
	
	$id = getnum('id',0);	
	
	if($action){
		$account=trim(getgpc('name'));
		$password = getgpc('password');
		$confirm = getgpc('confirm');
		
		$gid = getnum('gid',0);
		$state = getnum("state",1);
		$sex = getnum('sex',0);
		$email = getgpc('email');
		$phone = getgpc('phone');
		$blog = getgpc('blog');
		$qq = getgpc('qq');
		$birthday = getgpc('birthday');
	}	
	
	//连接数据库
	System :: connect();
	
	//动作处理
	switch ($action){
		
		case "add":
		
			//检查权限
			$func = "mod-member-add";
			System :: check_func( $func, false );				
				
			//查询数据
			$sql="SELECT * FROM `mod:member` WHERE account='".$account."'";
			$row = System :: $db -> getOne( $sql );

			if( $row ){
				
				$_G['project']['message']="已经存在同名用户!";
				
			}else{
			
				//插入数据
				$sql="INSERT INTO `mod:member`(account,password,state,gid,dateline,blog,email,ip,avatar,qq,phone,sex,birthday,config) values('".$account."','".md5($password)."','".$state."','".$gid."',".time().",'".$blog."','".$email."','".GetIP()."','".$_SESSION['Manager']["avatar"]."','".$qq."','".$phone."',".$sex.",'".$birthday."','{}')";
				
				System :: $db -> execute( $sql );
				
				$id = System :: $db -> getInsertId();
				
				///////////////////////////
				
				//复制快捷方式
				$quick = unserialize( $_CACHE['system']['group'][$gid]['quick'] );
				
				if( $quick && is_array( $quick ) ){
				
					foreach( $quick as $q ){	
						//插入数据
						$sql = "INSERT INTO `sys:quick`(aid,appid,dateline) values(".$id.",'".$q."',".time().")";	
	
						System :: $db -> execute( $sql );	
					}
					
				}
				
				//复制小工具
				$widget = unserialize( $_CACHE['system']['group'][$gid]['widget'] );

				if( $widget && is_array( $widget ) ){
					foreach( $widget as $appid => $a ){

						foreach( $a as $w ){
	
							//插入数据
							$sql = "INSERT INTO `sys:widget`(aid,appid,widget,x,y,z,fx,fy,dateline) values(".$id.",'".$appid."','".$w."','','',0,0,0,".time().")";	
	
							System :: $db -> execute( $sql );
	
						}
	
					}
				}
				
				//////////////////////////////////////
					
				//写入日志
				System :: insert_event($func,time(),time(),"创建用户：".$account."，用户：".$_CACHE['system']['group'][$gid]["name"]);				
				
				//缓存系统用户
				Cached :: table( 'system', 'mod:member', array( 'jsonde' => array('config') ) );
				
				System :: redirect("admin.list.php","成功添加新用户!");
				
			}
		
		break;
		
		case "update":
		
			//检查权限
			$func = "mod-member-mod";
			System :: check_func( $func, false );
				
			//更新数据
			//$sql="UPDATE `mod:member` SET `state`='".$state."',blog='".$blog."',email='".$email."',qq='".$qq."',phone='".$phone."',sex='".$sex."',birthday='".$birthday."',`modify`='".time()."' WHERE id=".$id;			
			
			//System :: $db -> execute( $sql );
			
			$set = '';
		
			foreach($_POST as $key=>$val){
				if( !in_array($key,array("id","account","ip","dateline","stat_login","stat_level")) && array_key_exists( $key ,$_G['module']['member']["fieds"] )  ){									
					$set .= $key."='".$val."',";
				}
			}
			
			$sql="UPDATE `mod:member` SET ".$set."`modify`=".time()." WHERE id=".$id;
			
			System :: $db -> execute($sql);
				
			System :: redirect(($jump?$jump:"?id=".$id."&action=edit"),"成功修改用户信息!");
		
		break;
		
		case "edit":
		
			$sql="SELECT * FROM `mod:member` WHERE id=".$id;
			$row = System :: $db -> getOne( $sql );
		
		break;
		
	}
	
	//关闭数据库
	System :: connect();

	?>

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

	<?php   
    echo loader_script(array(VI_BASE."js/mo.calendar.js"),"utf-8",$_G['product']['version']);    
    ?>
    
	<div id="box">
		<form action="?" method="post" mode="edit" verify="true">
                
        <table cellpadding="0" cellspacing="0" class="form">
            
            <tr><td colspan="2" class="section"><strong>基本信息</strong></td></tr>
                
            <tr>
                <td width="60"><strong>用户名称：</strong></td>
                <td><input name="account" type="text" class="text" value="<?php echo $row['account'];?>" size="35" <?php echo ($action?'disabled="true"':'');?> /></td>
            </tr>
                
	    <tr>
		<td><strong>真实姓名：</strong></td>
		<td><input name="name" type="text" class="text" value="<?php echo $row["name"];?>" size="35" fix_name="用户姓名" fix_null="no" /></td>
	    </tr>
	    
	    <tr>
		<td><strong>我的性别：</strong></td>
		<td>
		<label><input type="radio" class="radio" name="sex" value="-1" fix_name="用户性别" fix_null="no" /> 未知</label>
		<label><input type="radio" class="radio" name="sex" value="1" fix_name="用户性别" fix_null="no" /> 男士</label>
		<label><input type="radio" class="radio" name="sex" value="0" fix_name="用户性别" fix_null="no" /> 女士</label>
		</td>
	    </tr>
	    
	    <tr>
		<td><strong>手机号码：</strong></td>
		<td><input name="phone" type="text" class="text" value="<?php echo $row["phone"];?>" size="35" fix_name="手机号码" fix_mobile="no" /></td>
	    </tr>	    
	    
	    <tr>
		<td><strong>身份证号：</strong></td>
		<td><input name="idcard" type="text" class="text" value="<?php echo $row["idcard"];?>" size="35" fix_name="身份证号" fix_idcard="no" /></td>
	    </tr>
        
        	<tr>
            	<td><strong>帐号状态：</strong></td>
                <td>		
                    <label>
                    <input type="radio" class="radio" name="state" value="0">
                    禁用</label>
                    <label>
                    <input type="radio" class="radio" name="state" value="1" checked> 
                    正常
                    </label>
                </td>
            </tr>
            
            <tr><td colspan="2" class="section"><strong>详细信息</strong></td></tr>
	    
	    <tr>
		<td></td>
		<td>
			<table cellpadding="0" cellspacing="1" border="0" class="gird">
		    <thead>
			<td>
			 出生日期
			</td>
			<td>
			血型信息
			</td>
		    </thead>
		    <tr>
			<td>
			<input name="birthday" id="birthday" type="text" class="text" value="<?php echo $row["birthday"];?>" size="35" readonly="true" onclick="return showCalendar(this.id,'y-mm-dd');" title="年-月-日">
			</td>
			<td>
			<label><input type="radio" class="radio" name="blood" value='' /> 未知</label>
			<label><input type="radio" class="radio" name="blood" value="A" />A</label>
			<label><input type="radio" class="radio" name="blood" value="B" />B</label>
			<label><input type="radio" class="radio" name="blood" value="C" />C</label>
			<label><input type="radio" class="radio" name="blood" value="O" />O</label>
			</td>
		    </tr>
		    <thead>
			<td>
			QQ/MSN
			</td>
			<td>
			 电子邮箱
			</td>
		    </thead>
		    <tr>
			<td>
			<input name="qq" type="text" class="text" value="<?php echo $row["qq"];?>" size="35">
			</td>
			<td>
			<input name="email" type="text" class="text" value="<?php echo $row["email"];?>" size="35">
			</td>
		    </tr>		    
		    <thead>
			<td>
			个人主页
			</td>
			<td>
			 联系地址
			</td>
		    </thead>
		    <tr>
			<td>
			<input name="blog" type="text" class="text" value="<?php echo $row["blog"];?>" size="35">
			</td>
			<td>
			<input name="address" type="text" class="text" value="<?php echo $row["address"];?>" size="35">
			</td>
		    </tr> 
		    <thead>
			<td>
			毕业院校
			</td>
			<td>
			 婚姻状况
			</td>
		    </thead>
		    <tr>
			<td>
			<input name="school" type="text" class="text" value="<?php echo $row["school"];?>" size="35">
			</td>
			<td>
				<label><input name="marriage" type="radio" class="radio" value='' /> 未知</label>
				<?php
				foreach( $_G['project']['marriage'] as $key => $val ){
					echo '<label><input name="marriage" type="radio" class="radio" value="'.$key.'" /> '.$val.'</label>';	
				}
				?>
			</td>
		    </tr>		    
		    <thead>
			<td>
			职业职位
			</td>
			<td>
			 所在公司
			</td>
		    </thead>
		    <tr>
			<td>
			<input name="career" type="text" class="text" value="<?php echo $row["career"];?>" size="35">
			</td>
			<td>
			<input name="company" type="text" class="text" value="<?php echo $row["company"];?>" size="35">
			</td>
		    </tr>
		 </table>
		</td>
	    </tr>
            
            <tr><td colspan="2" class="section"><strong>统计信息</strong></td></tr>
	    
	    <tr>
		<td></td>
		<td>
			<table cellpadding="0" cellspacing="1" border="0" class="gird">
		    <thead>
			<td>
			 登录次数
			</td>
			<td>
			活动次数
			</td>
		    </thead>
		    <tr>
			<td>
			<?php echo $row["stat_login"];?>
			</td>
			<td>
			<?php echo $row["stat_level"];?>
			</td>
		    </tr>
		    <thead>
			<td>
			活动积分
			</td>
			<td>
			 注册 IP
			</td>
		    </thead>
		    <tr>
			<td>
			<?php echo $row["stat_credit"];?>
			</td>
			<td>
			<?php echo $row["ip"];?>
			</td>
		    </tr>		    
		    <thead>
			<td>
			创建时间
			</td>
			<td>
			 更新时间
			</td>
		    </thead>
		    <tr>
			<td>
			<?php echo date("Y/m/d H:i:s",$row['dateline']);?>
			</td>
			<td>
			<?php echo date("Y/m/d H:i:s",$row["modify"]);?>
			</td>
		    </tr>
		 </table>
		</td>
	    </tr>
            
            <tr><td colspan="2" class="section pointer" onclick=" Mo('#box-extend').toggle( 0, function( ele, vis ){ if( vis ){ Mo('#sel-extend').attr({ 'class' : 'open' }); }else{ Mo('#sel-extend').attr({ 'class' : 'close' }); } } ); "><a id="sel-extend" class="close"></a><strong>扩展信息</strong></td></tr>
	    
	    <tbody id="box-extend" style="display:none;">
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_book"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_music"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_movie"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_sport"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_person"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_brand"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_color"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_yearn"];?></textarea></td>
            </tr>
        
        	<tr>
            	<td><strong>喜欢的书：</strong></td>
                <td><textarea name="tag_book" rows="3" cols="80"><?php echo $row["tag_other"];?></textarea></td>
            </tr>
	    
	    </tbody>
        
        	<tr class="nobr">
            	<td><strong></strong></td>
                <td>
                <?php
				
				if($action=="edit" || $action=="update" ){
					echo '
					<input type="submit" name="Submit" value="修改用户" class="submit '.($disabled?'disabled="true"':'').'" />
					<input type="hidden" name="action" id="action" value="update" />
					<input type="hidden" name="id" id="id" value="'.$id.'" />
					';
				}else{
					echo '
					<input type="submit" name="Submit" value="添加用户" class="submit" '.($disabled?'disabled="true"':'').' />
					<input type="hidden" name="action" id="action" value="add" />
					';
				}
				echo '<input type="hidden" name="jump" id="jump" value="'.$_GET["jump"].'" />';
				
				?>
                </td>
            </tr>
        
        </table>
        
		<script type="text/javascript">
			Mo("input[name=sex]").value("<?php echo $row["sex"];?>");
			Mo("input[name=blood]").value("<?php echo $row["blood"];?>");
			Mo("input[name=state]").value("<?php echo isset($row['state']) ? $row['state'] : 1;?>");
			Mo("input[name=marriage]").value("<?php echo $row["marriage"];?>");
		</script>

		</form>
	</div>
<!--body end-->

<?php html_close();?>