<?
require_once("module/module.user.php");
$users = new CModuleUser();
$users->Init($UserInfo["UID"]);
$user=$users->modules[0];
?>
<br>
<table border=0 align=center width=700 cellspacing="1" cellpadding="0" bgcolor=#cccccc>
	<tr>
		<td>
			<table border=0 align=center width=100% bgcolor=#ffffff>
				<tr height=40>
					<td colspan=2 class=big><?php echo $UserInfo["RNAME"]?></td>
				</tr>
				<tr>
					<td align=center width=260 valign=top>
						<img id="user_photo" src="<?php echo $user->photo?>" border=1 width=200 height=150>
						<br>
						<span id="photo_title" style="display:block">
							<a href="javascript:change_photo()">更新相片</a>
						</span>
						<span id="photo_input" style="display:none">
							<form action="control/doaction.php" target="frame_photo" name="photo_form" enctype="multipart/form-data" method=post>
									<input type="hidden" name="action" value="cfg_user">
									<input type="hidden" name="job" value="photo">
									<input type="file" name="attach_photo" id="attach_photo" class="box" size="40" width=40>
									<br>
									<input type=button value="确定" class="box" onclick="submit_photo();"> 
									<input type=button value="取消" class="box" onclick="cancel_photo()">
									<iframe id="frame_photo" name="frame_photo" width=0 height=0>
									</iframe>
								</form>
						</span>
					</td>
					<td valign=top style="padding-left:40; line-height:200%">
						用户帐号:  <?php echo $user->user_name?><br>
						
						<span id="span_passwd">
							登陆密码:  
							<a href="javascript:change_passwd()">修改密码</a>
							<br>
						</span>
						<div id="span_passwd_input" style="display:none; background-color:#efefef;" >
							新 密 码:<input type=password id="new_passwd" class="box" size=10><br>
							确认密码:<input type=password id="cf_passwd" class="box" size=10><br>
							<input type=button value="确认" class=box onclick="submit_passwd()">
							&nbsp;&nbsp;
							<input type=button value="取消" class=box onclick="cancel_passwd()">
							
						</div>
						<span id="span_info">
							真实姓名:  <?php echo $user->real_name?><br>
							邮件地址:  <?php echo $user->email?><br>					
							I P 地址:  <?php echo $user->ip?><br>
							联系电话:  <?php echo $user->phone?><br>
							所属部门:  <?php echo $user->dept_name?><br>
						</span>
						<div id="div_info" style="display:none; background-color:#efefef;">
							真实姓名:  <input type=text class="box" id="real_name" size=16 value="<?php echo $user->real_name?> "> <br>
							邮件地址:  <input type=text class="box" id="email" size=16 value="<?php echo $user->email?> "> <br>					
							I P 地址:	 <input type=text class="box" id="ip" size=16 value="  <?php echo $user->ip?> "> <br>
							联系电话:  <input type=text class="box" id="phone" size=16 value="<?php echo $user->phone?> "> <br>
							所属部门:
							<?php
							require_once("module/module.dept.php");
							$depts = new CModuleDept();
							$depts->Init();
							?>
								<select id="dept_id" class="box">
									<?php for($i=0; $i<$depts->GetSize();$i++){?>
									<option value="<?php echo $depts->modules[$i]->dept_id?>"  <?php if($user->dept_id==$depts->modules[$i]->dept_id){echo "selected";}?>><?php echo $depts->modules[$i]->dept_name;?></option>
									<?php }?>
								</select> 
						</div>
						系统角色:  <?php echo $user->role_name?><br> 
					</td>
				</tr>
				<tr>
					<td align=center colspan=2><hr size=1 width=600></td>
				</tr>
				<tr height=60>
					<td colspan=2 style="padding-left:40;">
						<span id="bt_change">
						<input id="bt_info_mod" type=button value=" 修改信息 " class="box" onclick="change_info()">
						</span>
						<span id="bt_submit" style="display:none">
						<input type=button value=" 提交 " class="box" onclick="submit_info()">	
						<input type=button value=" 取消 " class="box" onclick="cancel_info()">
						</span>	
					</td>
				</tr>
			</table>
</td>
</tr>
</table>
<script>
		function change_photo()
		{
			$('#photo_title').hide();
			$('#photo_input').show();	
		}
		function cancel_photo()
		{
			$('#photo_title').show();
			$('#photo_input').hide();	
		}
		
		function submit_photo()
		{
			attach_photo = $('#attach_photo').val();
			if(IsNull(attach_photo))
			{
				alert("请选择文件");
				return;	
			}
			
			cancel_photo();
			var pos = attach_photo.lastIndexOf(".");
			if(pos >= 0)
			{		
				var attr = attach_photo.slice(pos+1).toLowerCase();				
				if(attr == 'gif' || attr == 'jpg' || attr == 'png')
				{
					document.photo_form.submit();
					return;
				}
			}
			
			alert("上传相片非法");
		}
		
		function change_passwd()
		{
			$('#span_passwd').hide();	
			$('#span_passwd_input').show();
		}
		
		function cancel_passwd()
		{
			$('#span_passwd').show();	
			$('#span_passwd_input').hide();
		}
		
		function submit_passwd()
		{
			passwd = $('#new_passwd').val();
			if(IsNull(passwd))
			{
				alert('密码不能为空');
				return;	
			}
			
			if(passwd !=  $('#cf_passwd').val())
			{
				alert('两次填写的密码必须一致');
				return;	
			}
			
			$.ajax({
				type: "POST",
		  	url: "control/doaction.php",
				dataType: "text",
				data: { 
					action:"cfg_user",
					job:"mod_passwd",
					passwd:passwd
			},
			timeout: 1000,
			complete: function(){},
			success: function(data)
			{
				alert("密码修改成功");
				$('#new_passwd').val('');
				$('#cf_passwd').val('');
				cancel_passwd();
			}
			});	
		}
		
		function change_info()
		{
			$('#bt_change').hide();
			$('#span_info').hide();	
			$('#div_info').show();
			$('#bt_submit').show();
		}
		
		function cancel_info()
		{
			$('#bt_change').show();
			$('#span_info').show();	
			$('#div_info').hide();
			$('#bt_submit').hide();	
		}
		
		function submit_info()
		{
			$.ajax({
				type: "POST",
		  	url: "control/doaction.php",
				dataType: "text",
				data: { 
					action:"cfg_user",
					job:"mod_info",
					real_name:$('#real_name').val(),
					email:$('#email').val(),
					ip:$('#ip').val(),
					phone:$('#phone').val(),
					dept_id:$('#dept_id').val()
			},
			timeout: 1000,
			complete: function(){},
			success: function(data)
			{
				alert("信息修改成功");
				$('#new_passwd').val('');
				$('#cf_passwd').val('');
				cancel_info();
				window.location.reload(true);
			}
			});		
		
		}
		
</script>