<?php
/**
* 用户信息类
* @author moufer<moufer@163.com>
* @copyright (C)2001-2007 Moufersoft
* @varsion $Id: user.class.php 3 2008-1-31 23:21 $
*/

!defined('IN_MUDDER') && exit('Access Denied');

class User_class {
    var $uid;
    var $email;
    var $username;
    var $groupid;
    var $newmsgs;
    var $face;
    var $isLogin;
    var $hash;
	var $coin;
	var $point;

    function User_class($uid = 0) {
        global $_passport;
        if($_passport['enable']) {
            $this->passport_login();
        } else {
            $this->login();
        }
    }

    function login() {
        global $db, $dbpre, $timestamp, $_DCOOKIE;
        $user_uid = $_DCOOKIE['uid'];
        $user_username = $_DCOOKIE['username'];
        $user_hash = $_DCOOKIE['hash'];
        if($user_uid && $user_username && $user_hash) {
            $row = $db->get_one("SELECT uid,password,username,email,face,groupid,point,coin,newmsg FROM {$dbpre}members WHERE username='$user_username'");
            $site_uid = $row['uid'];
            $site_email = $user_email;
            $site_username = $row['username'];
            $site_pw = $row['password'];
            $db_hash = formhash($site_uid,$site_username,$site_pw);
            //如果已经登录，则取得数据库中的uid进行比较
            if (strcmp($db_hash, $user_hash) == 0){
                $user_username = $site_username;
                $this->uid = $user_uid;
                $this->email = $row['email'];
                $this->username = $row['username'];
                $this->groupid = $row['groupid']; //用户类型
                $this->newmsgs = $row['newmsg']; //新短信(未读)
                $this->face = get_face($row['face']); //头像
				$this->point = $row['point'];
				$this->coin = $row['coin'];
                $this->hash = $db_hash;
                $this->isLogin = true;
            }else{
                del_cookie(array("uid", "username", "hash", "logintime", "remembertime"));
                unset($user_uid,$user_username,$user_hash);
                $this->uid = '0';
                $this->groupid = 1; //游客
                $this->isLogin = false;
            }
        } else {
          $this->uid = '0'; //游客
          $this->groupid = 1; //游客
          $this->isLogin = false;
        }
    }

    function passport_login() {
        global $db, $dbpre, $timestamp, $_DCOOKIE;
        $user_uid = $_DCOOKIE['uid'];
        $user_username = $_DCOOKIE['username'];
        $user_hash = $_DCOOKIE['hash'];
        if($user_uid && $user_username && $user_hash) {
            $row = $db->get_one("SELECT uid,password,username,email,face,groupid,point,coin,newmsg FROM {$dbpre}members WHERE username='$user_username'");
            $site_uid = $row['uid'];
            $site_email = $row['email'];
            $site_username = $row['username'];
            $db_hash = formhash($site_uid,$site_username,'');
            //如果已经登录，则取得数据库中的uid进行比较
            if (strcmp($db_hash, $user_hash) == 0) {
                $user_username = $site_username;
                $this->uid = $user_uid;
                $this->email = $row['email'];
                $this->username = $row['username'];
                $this->groupid = $row['groupid']; //用户类型
                $this->newmsgs = $row['newmsg']; //新短信(未读)
                $this->face = get_face($row['face']); //头像
				$this->point = $row['point'];
				$this->coin = $row['coin'];
                $this->hash = $db_hash;
                $this->isLogin = true;
            } else {
                del_cookie(array("uid", "username", "hash"));
                unset($user_uid,$user_username,$user_hash);
                $this->uid = '0';
                $this->groupid = 1; //游客
                $this->isLogin = false;
            }
        } else {
          $this->uid = '0'; //游客
          $this->groupid = 1; //游客
          $this->isLogin = false;
        }
    }

}

class Member_Base_class {

    var $uid        = 0;        //UID
    var $username   = '';
    var $face       = '';
    var $point      = 0;
    var $coin       = 0;
    var $reviews    = 0;
    var $flowers    = 0;
    var $rank       = '';        //积分等级

    function __construct() {
    }

    function Member_Base_class() {
        $this->__construct();
    }

    function Set_Row($row) {

        $this->uid = $row['uid'] ? $row['uid'] : 0;
        $this->username = $row['username'] ? $row['username'] : '会员已删除';
        $this->face = get_face($row['face'] ? $row['face'] : 'noface.gif');
        $this->point = intval($row['point']);
        $this->coin = intval($row['coin']);
        $this->reviews = intval($row['reviews']);
        $this->flowers = intval($row['flowers']);
        $this->rank = get_userrank(intval($row['point']));

    }

    function ToArray() {
        $array = array(
            'uid' => $this->uid,
            'username' => $this->username,
            'face' => $this->face,
            'point' => $this->point,
            'coin' => $this->coin,
            'reviews' => $this->reviews,
            'rank' => $this->rank,
        );

        return $array;
    }

}
?>
