<?php
/**
 * 
 * @file reg.php
 * @copyright (c) 2005 - 2007 eifr.com
 * @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
 * eifr is free software
 */

require_once(dirname(__FILE__) . '/includes/inc_general.php');

$url = $_SERVER["PHP_SELF"];

$errormsg = '';
// ---start---
if (!isset($act)) $act = '';

if ($act == 'save') {
    if (! checkVcode('eifr_checkvcode', kPost('vcode'))) {
        showMsg($lang['vincorrect_vcode'], '-1');
        exit();
    }
    
    $username = kPost('username');
    Log_d(__FILE__, __LINE__, 'reg username: ' . $username);
    $password = md5($password);
    $regtime = time();
    $regip = getIP();
    if (checkUsername($username)) {
        $username = filterUsername($username);
        Common::checkEditDataIsExist(TB_USER, TF_USER_NAME, $username);
        $realname = sTextEncode(kPost('realname'), 255);
        $nickname = sTextEncode(kPost('nickname'), 30);

        $parameter = '';
        $param_arr = array();
        if (kPost('style_id') != '') $param_arr['style_id'] = kPost('style_id');
        if (kPost('only_login') != '') $param_arr['only_login'] = kPost('only_login');
        if ($param_arr) $parameter = serialize($param_arr);

        $rtn_insert = false;
        $sql = "insert into " . TB_USER . " (username,password,email,nickname,realname,tel,fax,mobile,regtime,regip,parameter," . TFR_USER_CLASS_ID . ") values('$username','$password','$email','$nickname','$realname','$tel','$fax','$mobile','$regtime','$regip','$parameter','01')";
        $rs = $db -> Execute($sql);
        if ($rs) {
            $rtn_insert = true;
        } 
        $rs -> Close();

        if ($rtn_insert) {
            $sql = "SELECT * FROM " . TB_USER . " WHERE " . TF_USER_NAME . "='" . $username . "' and " . TF_USER_PASS . "='" . $password . "'";
            $rs = $db -> Execute($sql); 
            // echo $sql;
            if (!$rs -> EOF) {
                Common::setLoginSession($rs -> fields);
                $rs -> Close();
                header("Location:index.php");
            } else {
                $rs -> Close();
            } 
        } else {
            header("Location:error.php");
        } 
    } else {
        $errormsg = $lang['user_username_invalide'];
    } 
} 

$tpl_file = 'reg';
require_once(getTemplatePath($tpl_file));

?>

 