File indexing completed on 2024-12-22 05:33:23

0001 <?php
0002 
0003 /*
0004  *   TRT GFX 3.0.1 (beta build) BackToSlash
0005  * 
0006  *   support: happy.snizzo@gmail.com
0007  *   website: http://trt-gfx.googlecode.com
0008  *   credits: Claudio Desideri
0009  *   
0010  *   This software is released under the MIT License.
0011  *   http://opensource.org/licenses/mit-license.php
0012  */ 
0013 
0014 class EUser{
0015   
0016   public static $debug = true;
0017   
0018   private static $logged = false;
0019   private static $group = "anonymous";
0020   private static $pass;
0021   private static $nick;
0022   private static $mail;
0023   private static $id;
0024   
0025   public static function load(){
0026     
0027     EUser::$debug = true;
0028     EUser::$logged = false;
0029     EUser::$group = "anonymous";
0030     
0031     if(isset($_SESSION['nick'])){
0032       EUser::$logged = true;
0033       EUser::$nick = $_SESSION['nick'];
0034       EUser::$id = $_SESSION['id'];
0035       EUser::$group = $_SESSION['group'];
0036       EUser::$mail = $_SESSION['mail'];
0037       EUser::$pass = $_SESSION['pass'];
0038     } else {
0039       if(isset($_COOKIE['nick']) and isset($_COOKIE['pass'])){
0040         $r = EDatabase::q("SELECT * FROM ocs_person WHERE login='".$_COOKIE['nick']."' AND password='".$_COOKIE['pass']."' LIMIT 1");
0041         
0042         while($row = mysql_fetch_array($r)){
0043           EUser::$nick = $_SESSION['nick'] = $row['login'];
0044           EUser::$id = $_SESSION['id'] = $row['id'];
0045           EUser::$group = $_SESSION['group'] = $row['tgroup'];
0046           EUser::$mail = $_SESSION['mail'] = $row['email'];
0047           EUser::$pass = $_SESSION['pass'] = $row['password'];
0048           if(!empty($row['login'])){
0049             EUser::$logged = true;
0050           } else {
0051             EUser::$logged = false;
0052           }
0053         }
0054       
0055       } else {
0056         EUser::$logged = false;
0057       }
0058     }
0059     
0060   }
0061   
0062   
0063   public static function status(){
0064     return EUser::$status;
0065   }
0066   
0067   public static function password(){
0068     return EUser::$pass;
0069   }
0070   
0071   public static function mail(){
0072     return EUser::$mail;
0073   }
0074   
0075   public static function id(){
0076     return EUser::$id;
0077   }
0078   
0079   public static function nick(){
0080     return EUser::$nick;
0081   }
0082   
0083   public static function logged(){
0084     return EUser::$logged;
0085   }
0086   
0087   public static function login($nick, $pass){
0088     $r = EDatabase::q("SELECT * FROM ocs_person WHERE login='$nick' AND password='$pass' LIMIT 1");
0089     while($row = mysql_fetch_array($r)){
0090       
0091       if(!empty($row['login'])){
0092         EUser::$logged = true;
0093       } else {
0094         EUser::$logged = false;
0095       }
0096             
0097       setcookie("nick",$nick, time()+2419200);
0098       setcookie("pass",$pass, time()+2419200);
0099       EUser::$nick = $_SESSION['nick'] = $row['login'];
0100       EUser::$id = $_SESSION['id'] = $row['id'];
0101       EUser::$group = $_SESSION['group'] = $row['tgroup'];
0102       EUser::$logged = true;
0103       EUser::$mail = $_SESSION['mail'] = $row['email'];
0104       EUser::$pass = $_SESSION['pass'] = $row['password'];
0105     }
0106     return EUser::logged();
0107   }
0108   
0109   public static function logout(){
0110     session_destroy();
0111     setcookie("nick","", time()-2419200);
0112     setcookie("pass","", time()-2419200);
0113     EUser::$logged = false;
0114   }
0115   
0116   public static function gdeny($g){
0117     $groups = explode("|", EUser::$group);
0118     foreach($groups as $thGroup){
0119       if($thGroup==$g){
0120         ELog::error("You're not allowed to be here.");
0121         die($error);
0122       }
0123     }
0124     if(EUser::$logged==false){
0125       $error = "Loggati e riprova!";
0126       die($error);
0127     }
0128   }
0129   
0130   public static function refresh(){
0131     $r = EDatabase::q("SELECT * FROM ocs_person WHERE login='".EUser::$nick."' AND password='".EUser::$pass."' LIMIT 1");
0132     while($row = mysql_fetch_array($r)){
0133       EUser::$nick = $_SESSION['nick'] = $row['login'];
0134       EUser::$id = $_SESSION['id'] = $row['id'];
0135       EUser::$group = $_SESSION['group'] = $row['tgroup'];
0136       EUser::$logged = true;
0137       EUser::$mail = $_SESSION['mail'] = $row['email'];
0138     }
0139     return EUser::$logged();
0140   }
0141   
0142   public static function gallow($g){
0143     $allowedgroups = explode("|", $g);
0144     $groups = explode("|", EUser::$group);
0145     foreach($groups as $thGroup){
0146       foreach($allowedgroups as $alGroup){
0147         if($thGroup==$alGroup){
0148           return true;
0149         }
0150       }
0151     }
0152     ELog::error("You're not allowed to be here.");
0153     return false;
0154   }
0155   
0156   public static function belongs_to_group($g){
0157     $groups = explode("|", EUser::$group);
0158     foreach($groups as $thGroup){
0159       if($thGroup==$g){
0160         return true;
0161       }
0162     }
0163     //else return false :)
0164     return false;
0165   }
0166   
0167   public static function group(){
0168     return EUser::$group;
0169   }
0170   
0171   public static function register($nick, $pass, $group){
0172     EDatabase::q("INSERT INTO ocs_person (login, password, tgroup) VALUES ('$nick', '$pass', '$group')");
0173   }
0174   
0175 }
0176 
0177 ?>