<?php
if(!defined('IN_TM')) exit('Access Denied');
class login{
	var $db;
	var $table;
	var $pages;
    var $TM;

    function __construct(){
    	global $db;
        $this->db = &$db;
        $this->table = DB_PRE.'admin';
    }

    function login(){
        $this->__construct();
    }
      /*
     * 后台登陆
     * -1 用户不存在
     * 0  密码错误
     * > 0 登陆成功返回用户uid
     */
    function admin_login($username, $password){
        $r = $this->get($username);
        if(!$r){
            $this->msg = '用户名不存在';
            return FALSE;
        }
        $md5_password = md5($password);
        if($r['password'] != $md5_password){
            $this->msg = '密码不正确';
                return FALSE;
            }
        return True;
    }
    function msg(){
		return $this->msg;
    }
	function get($username, $fields = '*'){
		return $this->db->get_one("SELECT $fields FROM $this->table WHERE username='$username'");
	}
   /**
	 * 添加新闻
	 *
	 * @param ARRAY $info
	 * @param ARRAY $moreinfo
	 * @return INT用户ID
	 */
	function logout(){
		if($_SESSION["admin"]!="NewsTeng")showmessage('请登陆', '/admin.php?file=login');
        session_destroy();
		return true;
	}
}
?>