<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

// 会员修改
class UcModifyAction extends UserCenterAction {
	public function index()
	{
		$user_info = D("User")->where("id=".intval($_SESSION['user_id']))->find();
		$this->assign("user_info",$user_info);
		$this->display("Page:user_center_frame");
	}
	
	//修改
	public function doModify()
	{
		if(sunnyiC("TOKEN_ON")&&!M()->autoCheckToken($_POST))
		{
			$this->error(L("TOKEN_ERROR"));
		}
		$data['id'] = intval($_SESSION['user_id']);
     	$data['nickname'] = trim($_POST['nickname']);
    	$check_pwd = trim($_POST['user_pwd']);
    	$data['sex'] = trim($_POST['sex']);
    	$data['email'] = trim($_POST['email']);
		$data['fix_phone'] = trim($_POST['fix_phone']);
		$data['fax_phone'] = trim($_POST['fax_phone']);
		$data['mobile_phone'] = trim($_POST['mobile_phone']);
		$data['zip'] = trim($_POST['zip']);
		$data['address'] = trim($_POST['address']);
		$data['qq'] =  trim($_POST['qq']);
		$data['msn'] = trim($_POST['msn']);
		$data['alim'] = trim($_POST['alim']);
		$data['pwd_question'] = trim($_POST['pwd_question']);
		$data['pwd_answer'] = trim($_POST['pwd_answer']);
		
		$origin_pwd = D("User")->where("id=".$data['id']." and status=1")->getField("user_pwd");
		if(md5($check_pwd)!=$origin_pwd)
		{
			$this->error(L("PWD_ERROR"));
		}
		//开始相关验证
		if($data['email']=='')
		{
			$this->error(L("EMAIL_EMPTY"));
		}
		if(!preg_match("/\w+@\w+\.\w{2,3}\b/",$data['email']))
	   		{
	   			$this->error(L("EMAIL_FORMAT_ERROR"));
	   		}
     	$data['update_time']	=	gmtTime();
    	
    	$rs = D("User")->save($data);
    	if($rs>0)
    	{
    		$this->success(L("MODIFY_SUCCESS"));    		
    	}
    	else
    		$this->error(L("MODIFY_FAILED")); 
	}
}
?>