<?php
require("global.php");
@include_once(ROOT_PATH."data{$webdb[web_dir]}/all_area.php");

$thissiteurl=urlencode("$webdb[www_url]/member/myinfo.php");

/*微信短消息提醒做个开关*/
if(!table_field("{$pre}memberdata",'sendmsg')){
	$db->query("ALTER TABLE  `{$pre}memberdata` ADD  `sendmsg` TEXT NOT NULL");
}
is_array($lfjdb[msgA]) || $lfjdb[msgA] = unserialize($lfjdb[sendmsg]);

if($aciton=='uppics1'){
	//修改的信息添加图片
	del_wx_access();	//避免有时会出现access_token is invalid or not latest hint
	$access_token = wx_getAccessToken();
	$wx_api_url="https://api.weixin.qq.com/cgi-bin/media/get?access_token=$access_token&media_id=";
	$path = ROOT_PATH."$webdb[updir]/icon/$lfjuid";
	if(!is_dir($path)){			
		makepath($path);
	}
	if($picstr==''){
		continue;
	}
	$name = $lfjuid.'_'.rands(4).'_'.$timestamp.'.jpg';
	$strcode = file_get_contents($wx_api_url.$picstr);
	write_file("$path/$name",$strcode);

	$db->query("UPDATE {$pre}memberdata SET icon='icon/$lfjuid/$name' WHERE uid='$lfjuid'");
	delete_attachment($lfjuid,tempdir($lfjdb[icon]));
	die("icon/$lfjuid/$name");
	exit;
}

if($aciton=='updateicon'){
	if($icon && eregi("(gif|jpg|png)$",$icon)){
		$db->query("UPDATE {$pre}memberdata SET icon='$icon' WHERE uid='$lfjuid'");
		delete_attachment($lfjuid,tempdir($lfjdb[icon]));
	}
	exit;
}

if($aciton=='choose_area'){
	if($area){
		$listareas.="</select>\r\n";
		$listcitys="<select name='cityid'>\r\n<option value='0'>请选择城市</option>\r\n";
		foreach($city_DB[$area] AS $key=>$value){
			$listcitys.="<option value='$key'>$value</option>\r\n";	
		}
		$listcitys.="</select>\r\n";
	}
	die($listcitys);
}

if($actionedit){
	unset($array);
	$array[uid]=$lfjuid;
	$array[username]=$lfjid;

	if(!in_array($actionedit,array('sendregmsg','email','password','bday','sex','cityid','oicq','address','mobphone','truename'))){
		showerr("不能修改其他参数！");
	}

	if($actionedit=='email'){
		if (!ereg("^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$editvale)){
			showerr("邮箱不符合规则");
		}
		if($lfjdb[email_yz]&&$lfjdb[email]!=$editvale){
			if(!$webdb[EditYzEmail]){
				showerr("你不可以再修改邮箱,因为已经审核过了.");
			}else{
				$array[email_yz]=0;
			}
		}
		$array[email]=$editvale;
	}
	elseif($actionedit=='password'&&$password){
		if($password!=$password1){
			showerr("新密码与重复密码不相同");
		}
		$array[password]=$password;
	}
	elseif($actionedit=='bday'){
		$bday1||$bday1="1980";
		$bday2||$bday2="01";
		$bday3||$bday3="01";
		$array[bday]=$bday1.'-'.$bday2.'-'.$bday3;
		if(!ereg("^([0-9]{4})-([0-9]{2})-([0-9]{2})$",$array[bday])){
			showerr("生日格式不符合规则");
		}
	}
	elseif($actionedit=='cityid'){
		$array[provinceid]=$provinceid;
		$array[cityid]=$cityid;
	}
	elseif($actionedit=='oicq'){
		if(!ereg("^[0-9]{5,11}$",$editvale)){
			showerr("QQ格式不符合规则");
		}
		$array[$actionedit]=$editvale;
	}
	elseif($actionedit=='postalcode'){
		if(!ereg("^[0-9]{6}$",$editvale)){
			showerr("邮政编码格式不符合规则");
		}
		$array[$actionedit]=$editvale;
	
	}elseif($actionedit=='mobphone'){

		if(!ereg("^[0-9]{11,12}$",$editvale)){
			showerr("手机号码格式不符合规则");
		}
		if($lfjdb[mob_yz]&&$lfjdb[mobphone]!=$editvale){
			if(!$webdb[EditYzMob]){
				showerr("你不可以再修改手机号码,因为已经审核过了.");
			}else{
				$array[mob_yz]=0;
			}			
		}
		$array[$actionedit]=$editvale;
	
	}elseif($actionedit=='address'){

		$array[$actionedit] = filtrate($_POST[editvale]);
	}elseif($actionedit=='sendregmsg'){

		$lfjdb[msgA][RegMsg]=intval($editvale);
		$array[sendmsg] = addslashes(serialize($lfjdb[msgA]));


	}else{
		$editvale=filtrate($editvale);
		$array[$actionedit]=$editvale;
	}

	$userDB->edit_user($array);

	echo "<META HTTP-EQUIV=REFRESH CONTENT='0;URL=myinfo.php?updatetime=$timestamp'>";
	exit;
}

require(dirname(__FILE__)."/"."waphead.php");
require(dirname(__FILE__)."/"."template/myinfo.htm");
require(dirname(__FILE__)."/"."wapfoot.php");
?>