<?php
class iqqol_member {
    function Login($i_name, $i_pass) {
        list($uid, $username, $password, $email) = uc_user_login($i_name, $i_pass);
        setcookie('login_auth', '', -86400);
        if ($uid > 0) {
            //用户登陆成功，设置 Cookie，加密直接用 uc_authcode 函数，用户使用自己的函数
            setcookie('login_auth', uc_authcode($uid . "\t" . $i_name, 'ENCODE'));
            //生成同步登录的代码
            $ucsynlogin = uc_user_synlogin($uid);
            echo '登录成功' . $ucsynlogin . '<br><a href="' . $_SERVER['PHP_SELF'] . '">继续</a>';
            //exit;
            return true; //成功登陆
            
        } elseif ($uid == - 1) {
            return "-1"; //用户不存在,或者被删除
            
        } elseif ($uid == - 2) {
            return "-2"; //密码错
            
        } else {
            return false; //未定义
            
        }
    }
    function registra($i_name, $i_pass, $i_serivceqq, $i_email) {
        $uid = uc_user_register($i_name, $i_pass, $i_serivceqq, $i_email);
        if ($uid <= 0) {
            if ($uid == - 1) {
                return '-1'; //用户名不合法
                
            } elseif ($uid == - 2) {
                return '-2'; //包含要允许注册的词语
                
            } elseif ($uid == - 3) {
                return '-3'; //用户名已经存在
                
            } elseif ($uid == - 4) {
                return '-4'; //Email 格式有误
                
            } elseif ($uid == - 5) {
                return '-5'; //Email 不允许注册
                
            } elseif ($uid == - 6) {
                return '-6'; //该 Email 已经被注册
                
            } else {
                return false; //未定义
                
            }
        } else {
            $username = $i_name;
        }
        if ($username) {
            $db->query("INSERT INTO {$tablepre}members (uid,username,serviceqq,admin) VALUES ('$uid','$i_name','$i_serviceqq','0')");
            //注册成功，设置 Cookie，加密直接用 uc_authcode 函数，用户使用自己的函数
            setcookie('login_auth', uc_authcode($uid . "\t" . $username, 'ENCODE'));
            return true;
        }
    }
    function sp_auth($password) {
        $password = md5(md5($password) . iZzx_IQQOL);
        return $password;
    }
}
class iqqol_parameter {
    function currentfilename() {
        $dir_file = $_SERVER['SCRIPT_NAME'];
        $filename = basename($dir_file);
        return $filename;
    }
    function get_dir_glob($path, $type, $dir = false) {
        if ($type == 'path') {
            $tree = array();
            foreach (glob(IQQOL_FILE_ROOT . '/' . $path . '/*') as $single) {
                if ($dir ? is_dir($single) : is_file($single)) {
                    $tree[] = $single;
                }
            }
            return $tree;
        } elseif ($type == 'name') {
            $tree = array();
            foreach (scandir(IQQOL_FILE_ROOT . '/' . $path) as $single) {
                if ($dir ? is_dir(IQQOL_FILE_ROOT . '/' . $path . '/' . $single) : is_file(IQQOL_FILE_ROOT . '/' . $path . '/' . $single)) {
                    if ($single != '.' and $single != '..') {
                        $tree[] = $single;
                    }
                }
            }
            return $tree;
        }
    }
    function delDir($dir) {
        if (is_dir($dir)) {
            $objects = scandir($dir);
            foreach ($objects as $object) {
                if ($object != "." && $object != "..") {
                    if (filetype($dir . "/" . $object) == "dir") {
                        self::delDir($dir . "/" . $object);
                    } else {
                        unlink($dir . "/" . $object);
                    }
                }
            }
            reset($objects);
            rmdir($dir);
        }
        return true;
    }
}
class QQ {
    private static $downLine = 600;
    private static $upLine = 1303;
    private static $no = 1072;
    public $QQNum;
    private $url;
    public $imgId;
    public $state;
    function __construct($QQNUM, $ImgId = '4') {
        $this->QQNum = $QQNUM;
        $this->imgId = $ImgId;
        $this->url = "http://wpa.qq.com/pa?p=1:" . $QQNUM . ":$ImgId";
    }
    function getstatus() {
        $conReturn = file_get_contents($this->url);
        $fileSize = strlen($conReturn);
        if ($fileSize == self::$downLine) {
            $this->state = "0";
        } elseif ($fileSize == self::$upLine) {
            $this->state = "1";
        } else {
            $this->state = "no";
        }
        return $this->state;
    }
    function showImg() {
        if ($this->state == "Y") {
            echo '<img src="' . $this->url . '">';
            return 0;
        } elseif ($this->state == "N") {
            echo '<img src="' . $this->url . '">';
            return 1;
        } else {
            echo '<img src="' . $this->url . '">';
            return;
        }
    }
}
class iemail{
    function send($sendto,$header,$data)
    {
      $data=str_replace("#br#","%0D%0A",$data);
      $pack = 'authkey='.APIKEY.'&authpwd='.APIPASS.'&infohead='.$header.'&infotext='.$data.'&sendto='.$sendto;
      $return =$this->request_by_curl($pack);
      global $con;
      if($return=='Authracation has expired'){
        mysql_select_db(IQQOL_DBNAME,$con);
        mysql_query("UPDATE ".IQQOL_SQLTABLE."config SET status='verify' WHERE id = '1'");
      }
      return $return;
    }
    function request_by_curl($fields)
    {
  $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://open.izzx.cc/tools/email.php");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        //curl_setopt($ch, CURLOPT_PROXY, PROXYIP);      代理选项，打开后将采用后台QQ代理IP发送请求到其他服务器
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, "iQQol Client");
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
}
function nowtime() {
    date_default_timezone_set('PRC');
    $tomorrow = mktime(0, 0, 0, date("m") , date("d") + 30, date("Y"));
    $time = date("Y-m-d", $tomorrow);
    $now = date("Y-m-d");
    $deltime = date('G:i:s');
    $time5 = $time . ' ' . $deltime;
    return $time5;
}
function get_client_ip() 
{ 
    if ($_SERVER['REMOTE_ADDR']) { 
        $cip = $_SERVER['REMOTE_ADDR']; 
    } elseif (getenv("REMOTE_ADDR")) { 
        $cip = getenv("REMOTE_ADDR"); 
    } elseif (getenv("HTTP_CLIENT_IP")) { 
        $cip = getenv("HTTP_CLIENT_IP"); 
    } else { 
        $cip = "unknown"; 
    } 
    return $cip; 
}
function setlog($log){
    $nowday = date("Y-m-j");
    $nowss = date("H:i:s");
    $fp=fopen('data/log/'.$nowday.'.log','a+');
    fwrite($fp,'['.$nowday.'-'.$nowss.']'.$log."\r\n");
    fclose($fp);
}