<?php
header("Content-type:text/html;charset=utf-8");  
session_start(); 
$session_admin = isset($_SESSION['admin']) ? $_SESSION['admin'] : ''; 
if ($session_admin == '') {
	die("Can not access");
}
require_once("../common.php");
checkadminrights($session_admin, 'departments');

function step2() {
	require_once("../common.php");

	$departid = isset($_GET['departid']) ? $_GET['departid'] : '';
	$departname = isset($_GET['departname']) ? urldecode($_GET['departname']) : '';
	$userid = isset($_GET['userid']) ? $_GET['userid'] : '0'; 
	$nickname = isset($_GET['nickname']) ? urldecode($_GET['nickname']) : '';

	//subpageurlparams
	$subpageurlparams = 'departid=' . $departid . '&departname=' . urlencode($departname) . 
		'&userid=' . $userid . '&nickname=' . urlencode($nickname);

	$post_userid = isset($_POST['post_userid']) ? $_POST['post_userid'] : '0'; 
    $post_canfound = isset($_POST['post_canfound']) ? $_POST['post_canfound'] : '0'; 
    $post_nickname = isset($_POST['post_nickname']) ? $_POST['post_nickname'] : ''; 
	$post_signature = isset($_POST['post_signature']) ? $_POST['post_signature'] : ''; 
    $post_actualname = isset($_POST['post_actualname']) ? $_POST['post_actualname'] : ''; 
    $post_sex = isset($_POST['post_sex']) ? $_POST['post_sex'] : '0'; 
    $post_age = isset($_POST['post_age']) ? $_POST['post_age'] : '-1'; 
    $post_birth_year = isset($_POST['post_birth_year']) ? $_POST['post_birth_year'] : '0'; 
    $post_birth_month = isset($_POST['post_birth_month']) ? $_POST['post_birth_month'] : '0'; 
    $post_birth_day = isset($_POST['post_birth_day']) ? $_POST['post_birth_day'] : '0'; 
	$post_country = isset($_POST['post_country']) ? $_POST['post_country'] : '0'; 
    $post_province = isset($_POST['post_province']) ? $_POST['post_province'] : '0'; 
    $post_city = isset($_POST['post_city']) ? $_POST['post_city'] : '0'; 
	$post_area = isset($_POST['post_area']) ? $_POST['post_area'] : '0'; 
    $post_address = isset($_POST['post_address']) ? $_POST['post_address'] : ''; 
    $post_telephone = isset($_POST['post_telephone']) ? $_POST['post_telephone'] : ''; 
	$post_telephone_short = isset($_POST['post_telephone_short']) ? $_POST['post_telephone_short'] : ''; 
    $post_telephone2 = isset($_POST['post_telephone2']) ? $_POST['post_telephone2'] : ''; 
	$post_telephone2_short = isset($_POST['post_telephone2_short']) ? $_POST['post_telephone2_short'] : ''; 
    $post_mobile = isset($_POST['post_mobile']) ? $_POST['post_mobile'] : ''; 
	$post_mobile_short = isset($_POST['post_mobile_short']) ? $_POST['post_mobile_short'] : ''; 
    $post_mobile2 = isset($_POST['post_mobile2']) ? $_POST['post_mobile2'] : ''; 
	$post_mobile2_short = isset($_POST['post_mobile2_short']) ? $_POST['post_mobile2_short'] : ''; 
    $post_fax = isset($_POST['post_fax']) ? $_POST['post_fax'] : ''; 
    $post_qq = isset($_POST['post_qq']) ? $_POST['post_qq'] : ''; 
    $post_weixin = isset($_POST['post_weixin']) ? $_POST['post_weixin'] : ''; 
	$post_weibo = isset($_POST['post_weibo']) ? $_POST['post_weibo'] : ''; 
    $post_email = isset($_POST['post_email']) ? $_POST['post_email'] : ''; 
	$post_roomname = isset($_POST['post_roomname']) ? $_POST['post_roomname'] : '';
	$post_roomnumber = isset($_POST['post_roomnumber']) ? $_POST['post_roomnumber'] : '';
	$post_idnumber = isset($_POST['post_idnumber']) ? $_POST['post_idnumber'] : '';
	$post_carnumber = isset($_POST['post_carnumber']) ? $_POST['post_carnumber'] : '';
    $post_homepage = isset($_POST['post_homepage']) ? $_POST['post_homepage'] : ''; 
    $post_departid = isset($_POST['post_departid']) ? $_POST['post_departid'] : '0'; 
    $post_departname = isset($_POST['post_departname']) ? $_POST['post_departname'] : ''; 
    $post_jobtitle = isset($_POST['post_jobtitle']) ? $_POST['post_jobtitle'] : ''; 
    $post_jobnumber = isset($_POST['post_jobnumber']) ? $_POST['post_jobnumber'] : ''; 
    $post_introduction = isset($_POST['post_introduction']) ? $_POST['post_introduction'] : ''; 

	$methodname = 'Admin.ModifyUser';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<ip>' . getip() . '</ip>' . 
		'<userid>' . $post_userid . '</userid>' . 
		'<canfound>' . $post_canfound . '</canfound>' .
		'<nickname>' . $post_nickname . '</nickname>' .
		'<signature>' . $post_signature . '</signature>' .
		'<actualname>' . $post_actualname . '</actualname>' .
		'<sex>' . $post_sex . '</sex>' .
		'<age>' . $post_age . '</age>' .
		'<birth_year>' . $post_birth_year . '</birth_year>' .
		'<birth_month>' . $post_birth_month . '</birth_month>' .
		'<birth_day>' . $post_birth_day . '</birth_day>' .
		'<country>' . $post_country . '</country>' .
		'<province>' . $post_province . '</province>' .
		'<city>' . $post_city . '</city>' .
		'<area>' . $post_area . '</area>' .
		'<address>' . $post_address . '</address>' .
		'<telephone>' . $post_telephone . '</telephone>' .
		'<telephone_short>' . $post_telephone_short . '</telephone_short>' .
		'<telephone2>' . $post_telephone2 . '</telephone2>' .
		'<telephone2_short>' . $post_telephone2_short . '</telephone2_short>' .
		'<mobile>' . $post_mobile . '</mobile>' .
		'<mobile_short>' . $post_mobile_short . '</mobile_short>' .
		'<mobile2>' . $post_mobile2 . '</mobile2>' .
		'<mobile2_short>' . $post_mobile2_short . '</mobile2_short>' .
		'<fax>' . $post_fax . '</fax>' .
		'<qq>' . $post_qq . '</qq>' .
		'<weixin>' . $post_weixin . '</weixin>' .
		'<weibo>' . $post_weibo . '</weibo>' .
		'<email>' . $post_email . '</email>' .
		'<roomname>' . $post_roomname . '</roomname>' .
		'<roomnumber>' . $post_roomnumber . '</roomnumber>' .
		'<idnumber>' . $post_idnumber . '</idnumber>' .
		'<carnumber>' . $post_carnumber . '</carnumber>' .
		'<homepage>' . $post_homepage . '</homepage>' .
		'<departid>' . $post_departid . '</departid>' .
		'<departname>' . $post_departname . '</departname>' .
		'<jobtitle>' . $post_jobtitle . '</jobtitle>' .
		'<jobnumber>' . $post_jobnumber . '</jobnumber>' .
		'<introduction>' . $post_introduction . '</introduction>' .
		'</request> ';
	$responseinfo = '';
	$responsexml = null;
	$errorcode = ERRORCODE_UNKNOWN;

	$cmd = new COM("OpenCom.Command");
	$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
	$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
	if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 5000)) {
		$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
		$responsexml = simplexml_load_string($responseinfo);
		$errorcode = $responsexml->errorcode;
	}
	$cmd = null;

	switch($errorcode) {
		case ERRORCODE_OK: 
			header("location:   departments_users.php?{$subpageurlparams}");
			break;
		default:
			header("location:   departments_users.php?{$subpageurlparams}");
	}//switch
}//step2

$step = isset($_GET['step']) ? $_GET['step'] : '1'; 

if ($step == '2') {
	step2();
	exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<link type="text/css" rel="stylesheet" href="../css/base.css" />
<style type="text/css">
.td1 { padding:5px 0 0 0;width:80px;height:20px;vertical-align:top; }
.td2 { width:300px;vertical-align:top; }
</style>
<script type="text/javascript">
String.prototype.trim=function() {
     return this.replace(/(^\s*)(\s*$)/g, '');
}
function chkform() {
	var form = document.getElementById('form');
	if (form.departments.selectedIndex >= 0) {
		var selvalue = form.departments.options[form.departments.selectedIndex].value;
		var seltext = form.departments.options[form.departments.selectedIndex].text;
		if (selvalue > 0) {
			form.post_departid.value = selvalue;
			form.post_departname.value = seltext;
		}
	}
    return   true; 
}//chkform
</script>
</head>
<body style="background-color:#f2f2f2;">

<?php
require_once("../common.php");

$departid = isset($_GET['departid']) ? $_GET['departid'] : '';
$departname = isset($_GET['departname']) ? urldecode($_GET['departname']) : '';
$userid = isset($_GET['userid']) ? $_GET['userid'] : '0'; 
$nickname = isset($_GET['nickname']) ? urldecode($_GET['nickname']) : '';

//subpageurlparams
$subpageurlparams = 'departid=' . $departid . '&departname=' . urlencode($departname) . 
	'&userid=' . $userid . '&nickname=' . urlencode($nickname);

//GetUserInfo
$methodname = 'Admin.GetUserInfo';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
    '<ip>' . getip() . '</ip>' . 
	'<userid>' . $userid . '</userid>' . 
	'</request> ';
$responseinfo = '';
$responsexml = null;
$errorcode = ERRORCODE_UNKNOWN;

$cmd = new COM("OpenCom.Command");
$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 5000)) {
	$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
	$responsexml = simplexml_load_string($responseinfo);
	$errorcode = $responsexml->errorcode;
}
$cmd = null;

switch($errorcode) {
	case ERRORCODE_OK: 
		break;
	default:
		header("location:   departments_users.php?{$subpageurlparams}");
}//switch

//GetDepartments
$departmentshtml = '';

$methodname = 'Admin.GetDepartments';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
    '<ip>' . getip() . '</ip>' . 
	'<parentdepartid>' . '-1' . '</parentdepartid>' . 
	'</request> ';
$responseinfo = '';
$responsexml2 = null;
$errorcode = ERRORCODE_UNKNOWN;

$cmd = new COM("OpenCom.Command");
$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 5000)) {
	$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
	$responsexml2 = simplexml_load_string($responseinfo);
	$errorcode = $responsexml2->errorcode;
}
$cmd = null;

function LoadDepartments($childs, $selected_departid) {
	$result = '';
	foreach($childs as $child) {				
		if ($child->getName() == 'department') { 
			$attrs = $child->attributes();	
			$offset = '';
			for ($i=0;$i<$attrs->indent;$i++) $offset .= '&nbsp;&nbsp;';	
			if ($attrs->departid == $selected_departid) { 
				$result .= '<option value="' . $attrs->departid . '" selected>' . $offset . $attrs->departname . '</option>'; 
			} else {
				$result .= '<option value="' . $attrs->departid . '">' . $offset . $attrs->departname . '</option>'; 
			}//if
			$result .= LoadDepartments($child->children(), $selected_departid); 
		}//if
	}//foreach
	return $result;
}//function LoadDepartments

switch($errorcode) {
	case ERRORCODE_OK: 
		$departmentshtml = '<option value="0">请选择</option>';
		$departmentshtml .= LoadDepartments($responsexml2->departments->children(), strval($responsexml->departid));
		break;
	default:
		$departmentshtml = '<option value="0">请选择</option>';
}//switch

echo<<<EOT
	<div style="clear:both;margin:0 auto;padding:0;">
		<div style="float:left;margin:0;padding:20px 0 0 20px;text-align:left;font-size:13px;color:#330000;">
			<form action="departments_modifyuser.php?step=2&{$subpageurlparams}" method="post" id="form" onSubmit="return chkform();">
			<input type="hidden" name="post_signature" value="{$responsexml->signature}"/>
			<input type="hidden" name="post_country" value="{$responsexml->country}"/>
			<input type="hidden" name="post_area" value="{$responsexml->area}"/>
			<input type="hidden" name="post_departid" value="0"/>
			<input type="hidden" name="post_departname" value=""/>
			<table style="border:0;">
			<tr>
				<td class="td1">用户ID:</td>
				<td class="td2"><input style="width:260px;background-color:#e1e1e1;" type="text" name="post_userid" value="{$userid}" readonly /></td>
			</tr>
			<tr>
				<td class="td1">用户名:</td>
				<td class="td2"><input style="width:260px;background-color:#e1e1e1;" type="text" name="username" value="{$responsexml->username}" readonly /></td>
			</tr>
			<tr>
				<td class="td1"></td>
				<td class="td2" style="height:40px;"><input type="checkbox" class="checkbox" name="post_canfound" value="1" 
EOT;
	if ($responsexml->canfound == '1') echo(" checked ");		
echo<<<EOT
	/>允许与外部帐号沟通</td>
			</tr>
			<tr>
				<td class="td1">昵称:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_nickname" value="{$responsexml->nickname}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">真实姓名:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_actualname" value="{$responsexml->actualname}"/>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;"></span></td>
			</tr>
			<tr>
				<td class="td1">性别:</td>
				<td class="td2">
					<select name="post_sex" style="width:266px;">
					<option value="0"
EOT;
	if ($responsexml->sex == '0') echo(" selected ");	
echo<<<EOT
					>请选择</option>
					<option value="1"
EOT;
	if ($responsexml->sex == '1') echo(" selected ");	
echo<<<EOT
					>男</option>
					<option value="2"
EOT;
	if ($responsexml->sex == '2') echo(" selected ");	
echo<<<EOT
					>女</option>
					</select>
				</td>
			</tr>
			<tr>
				<td class="td1">年龄:</td>
				<td class="td2">
					<select name="post_age" style="width:266px;">
					<option value="-1">请选择</option>
EOT;
for($i=0;$i<120;$i++) {
	if ($responsexml->age == $i)
	    echo '<option value="' . $i . '" selected>' . $i . '&nbsp;岁</option>';
	else
	    echo '<option value="' . $i . '">' . $i . '&nbsp;岁</option>';
}
echo<<<EOT
					</select>
				</td>
			</tr>
			<tr>
				<td class="td1">所属部门:</td>
				<td class="td2">
					<select id="departments" style="width:266px;">
					{$departmentshtml}
					</select>
				</td>
			</tr>
			<tr>
				<td class="td1">职位名称:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_jobtitle" value="{$responsexml->jobtitle}"/>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;"></span></td>
			</tr>
			<tr>
				<td class="td1">工作编号:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_jobnumber" value="{$responsexml->jobnumber}"/>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;"></span></td>
			</tr>
			<tr>
				<td class="td1">联系地址:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_address" value="{$responsexml->address}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">电话:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_telephone" value="{$responsexml->telephone}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">电话(短号):</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_telephone_short" value="{$responsexml->telephone_short}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">电话2:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_telephone2" value="{$responsexml->telephone2}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">电话2(短号):</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_telephone2_short" value="{$responsexml->telephone2_short}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">手机:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_mobile" value="{$responsexml->mobile}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">手机(短号):</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_mobile_short" value="{$responsexml->mobile_short}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">手机2:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_mobile2" value="{$responsexml->mobile2}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">手机2(短号):</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_mobile2_short" value="{$responsexml->mobile2_short}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">传真:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_fax" value="{$responsexml->fax}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">QQ:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_qq" value="{$responsexml->qq}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">微信:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_weixin" value="{$responsexml->weixin}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">微博:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_weibo" value="{$responsexml->weibo}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">Email:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_email" value="{$responsexml->email}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">科室名称:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_roomname" value="{$responsexml->roomname}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">办公室号:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_roomnumber" value="{$responsexml->roomnumber}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">身份证号:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_idnumber" value="{$responsexml->idnumber}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">车牌号:</td>
				<td class="td2"><input style="width:260px;" type="text" name="post_carnumber" value="{$responsexml->carnumber}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1">个人主页:</td>
				<td class="td2" style="height:40px;"><input style="width:260px;" type="text" name="post_homepage" value="{$responsexml->homepage}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;"></span></td>
			</tr>
			<tr>
				<td class="td1"></td>
				<td class="td2" style="height:60px"><input class="cssbtn" type="submit" value="修改">&nbsp;<input class="cssbtn" type="button" value="取消" onclick="window.location='departments_users.php?{$subpageurlparams}'"></td>
			</tr>
			</table>
			</form>
		</div>
	</div>
EOT;
?>

</body>
</html>
