<?php

require_once(dirname(dirname(__FILE__)) . '/app.php');
need_login();

if($_POST){
    $u = array();
    if($_POST['password']!=$login_user['password']){
        $u['password'] = strval($_POST['password']);
    }
    $u['email'] = strval($_POST['email']);
    $u['mobile'] = strval($_POST['mobile']);
    $u['realname'] = strval($_POST['realname']);
    $u['gender'] = strval($_POST['gender']);
    $u['qq'] = strval($_POST['qq']);
    $u['zipcode'] = strval($_POST['zipcode']);
    $u['address'] = strval($_POST['address']);

    if (!Utility::ValidEmail($u['email'], true)) {
        Session::Set('error', 'Email地址为无效地址');
        redirect(WEB_ROOT . '/account/index.php');
    }
    if ($_POST['password2'] == $_POST['password'] && $_POST['password']) {
        if ( OUser::Modify($login_user['id'], $u) ) {
            Session::Set('success', '修改账户设置成功');
            redirect( WEB_ROOT . '/account/index.php ');
        } else {
            Session::Set('error', '修改账户设置失败');
            redirect( WEB_ROOT . '/account/index.php ');
        }
    }else{
        Session::Set('error', '密码输入错误！');
        redirect(WEB_ROOT . '/account/index.php');
    }
}

$login_user = Table::Fetch('user', $login_user_id);


include template('account_index');
?>
