<?php
	define('YUKEY', true);

	require(dirname(__FILE__) . '/includes/init.php');

    $action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
    $username = isset($_REQUEST['tbUserName']) ? trim($_REQUEST['tbUserName']) : '';
    $password = isset($_REQUEST['tbPassword']) ? trim($_REQUEST['tbPassword']) : '';
    //$back_act = isset($_REQUEST['back_act']) ? trim($_REQUEST['back_act']) : '';
	$id = isset($_REQUEST['tbID']) ? trim($_REQUEST['tbID']) : '';

//用户中心欢迎页
if ($action == 'default')
{
  /*  include_once(ROOT_PATH .'includes/lib_clips.php');
    if ($rank = get_rank_info())
    {
        $smarty->assign('rank_name', sprintf($_LANG['your_level'], $rank['rank_name']));
        if (!empty($rank['next_rank_name']))
        {
            $smarty->assign('next_rank_name', sprintf($_LANG['next_level'], $rank['next_rank'] ,$rank['next_rank_name']));
        }
    }
*/
	$smarty->assign('act', 'act_login');
	$smarty->assign('id', $id);//这里如果不声明这两个变量，有些架构会报错，显示undefine错误,是smarty报错
	$smarty->assign('user_notice', '');
    $smarty->display('user_passport.dwt');
}
elseif ($action == 'act_login')
{   
    if (check_user($username,$password))
    {
        update_user_info();
		ecs_header("Location:".APPURI."sicms/projects.php");
		//ecs_header("Location:".APPURI."sicms/test.php");

    }
    else
    {
		$msg = "<font color='green'>Username or Password error !</font>";
		$smarty->assign('user_notice', $msg);
		$smarty->assign('act', 'act_login');
		$smarty->assign('id', $id);
        $smarty->display('user_passport.dwt');
    }
}
elseif ($action == 'review_abooking' || $action == 'review_areport')
{
    //$tbPN = isset($_REQUEST['tbPN']) ? trim($_REQUEST['tbPN']) : '';
/*
    $captcha = intval($_CFG['captcha']);
    if (($captcha & CAPTCHA_LOGIN) && (!($captcha & CAPTCHA_LOGIN_FAIL) || (($captcha & CAPTCHA_LOGIN_FAIL) && $_SESSION['login_fail'] > 2)) && gd_version() > 0)
    {
        if (empty($_POST['captcha']))
        {
            show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
        }

        /* 检查验证码 
        include_once('sicms/includes/cls_captcha.php');

        $validator = new captcha();
        $validator->session_word = 'captcha_login';
        if (!$validator->check_word($_POST['captcha']))
        {
            show_message($_LANG['invalid_captcha'], $_LANG['relogin_lnk'], 'user.php', 'error');
        }
    }
*/
    //if ($user->login($username, $password,isset($_POST['remember'])))
	if(!empty($username) && !empty($password))
	{ 
		if (check_user($username,$password))
		{
			update_user_info();
			//recalculate_price();
			if ($action == 'review_abooking'){
				ecs_header("Location:".APPURI."sicms/project_page.php?client=".$client."&id=".$id."&act=show");
			}
			elseif ($action == 'review_areport'){
				ecs_header("Location:".APPURI."sicms/report_page.php?client=".$client."&id=".$id."&active=2");
			}
			else{
				exit;
			}
			//$ucdata = isset($user->ucdata)? $user->ucdata : '';
			//show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
		}
		else
		{
			//$_SESSION['login_fail'] ++ ;
			$msg = "<font color='red'>Username or Password error !</font>";
			$smarty->assign('user_notice', $msg);
			$smarty->assign('act', $action);
			$smarty->assign('id', $id);
			$smarty->assign('client', $client);
			$smarty->display('user_passport.dwt');
			//show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], 'user.php', 'error');
		}
	}
	else
	{
	$msg = "<font color='red'>Please input your Username and Password!</font>";
	$smarty->assign('user_notice', $msg);
	$smarty->assign('act', $action);
	$smarty->assign('id', $id);
	$smarty->assign('client', $client);
	$smarty->display('user_passport.dwt');
	}
}

?>