<?php
/**
 * Author: Li HouYu
 * Copyright 2007 pMVC Reloaded Team
 * 
 * This file is part of pMVC Reloaded.
 * Module: Auth.
 *
 * pMVC Reloaded is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * pMVC Reloaded is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */ 

if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript" language="javascript">
<!--
function on_success(response) {
    var o_result = _eval_json(response);
    if (!o_result) {
        return on_failure(response);
    }
    
    var stat = document.getElementById("loginform_stat");
    if (o_result.result == "ERROR") {
        document.forms["loginform"].reset();
        reload_captcha();
        
        stat.innerHTML = o_result.errmsg;
        return false;
    } else if (o_result.result == "OK") {
        stat.innerHTML = "<?php _e('OK, redirecting...'); ?>";
        window.location.href = o_result.forward;
    } else {
        return on_failure(response);
    }
}

function on_failure(response) {
    document.forms["loginform"].reset();
    reload_captcha();
    
    document.getElementById("loginform_stat").innerHTML = "<?php _e('Request failed!'); ?>";
    return false;
}

function reload_captcha() {
    var captcha = document.getElementById("login_captcha");
    if (captcha) {
        captcha.src = "captcha.php?s=" + random_str(6);
    }
}
//-->
</script>
<?php
$loginform = new Form('index.php', 'loginform', 'check_login_info');
$loginform->p_open('mod_auth', 'dologin', '_ajax');
?>

<div  id="loginMain">
	<ul>
    	<li class="list">
        	<div class="label"><?php _e('Username'); ?></div>
        	<div class="entry"><?php echo Html::input('text', 'login_user', '', '', $loginform, 'RequiredTextbox', __('Please input your username!')); ?></div>
        </li>
    	<li class="list">
        	<div class="label"><?php _e('Password'); ?></div>
        	<div class="entry"><?php echo Html::input('password', 'login_pwd', '', '', $loginform, 'RequiredTextbox',  __('Please input your password!')); ?></div>
        </li>
        <?php if (SITE_LOGIN_VCODE) { ?>
        <li>
        	<div class="label"><?php _e('Security'); ?></div>
            <div class="entry">
            	<img id="login_captcha" src="captcha.php" border="0" class="img_vmiddle"/>
				<?php echo Html::input('text', 'rand_rs', '', 'size="2"', $loginform, 'RequiredTextbox', __('Please give me an answer!')); ?>
            </div>
        </li>
        <?php } ?>
    	<li class="bt">
			<strong><a href="#" class="zhuce"  onclick="show_iframe_win('index.php?<?php echo Html::uriquery('mod_user', 'reg_form'); ?>', '<?php _e('Registe'); ?>', 450, 260);return false;" title="<?php _e('Registe user!'); ?>">
            <?php _e('Registe user!'); ?></a></strong>
			<?php
            echo Html::input('submit', 'bt_login', __('&nbsp;'));
            echo Html::input('hidden', '_f', $forward_url);
            ?>
        </li>
        <!--li>
        	<a href="#" onclick="show_iframe_win('index.php?<?php echo Html::uriquery('mod_user', 'reg_form'); ?>', '<?php _e('Registe'); ?>', 560, 520);return false;" title="<?php _e('Registe user!'); ?>">
            <?php _e('Registe user!'); ?></a>
        </li>
        <li>
        	<a href="#" onclick="show_iframe_win('index.php?<?php echo Html::uriquery('mod_user', 'req_rstpwd_form'); ?>', '<?php _e('Reset password request'); ?>', 560, 520);return false;" title="<?php _e('Reset password'); ?>">
            <?php _e('Forget password?!'); ?></a>
        </li-->
        <div>
            <span id="loginform_stat" class="status" style="display:none;"></span>
        </div>
    </ul>
    <div class="clear"></div>
</div>
<div class="air"></div>
<?php
$loginform->close();
$running_msg = __('Checking user...');
$custom_js = <<<JS
$("#loginform_stat").css({"display":"block"});
$("#loginform_stat").html("$running_msg");
_ajax_submit(thisForm, on_success, on_failure);
return false;

JS;
$loginform->addCustValidationJs($custom_js);
$loginform->writeValidateJs();
?>
