Location: PHPKode > projects > Trunk.net > ratiowarn.php
<?
    require("include/functions.php");
    dbconn(true);
    
if ($CURUSER){
    //ECHO "RATIOWARN MODULE LOADED<br>"; ###DEBUG PURPOSES
    
    if ($CURUSER["downloaded"] != "0"){
        $userratio = number_format($CURUSER["uploaded"] / $CURUSER["downloaded"], 2);
    }
    $userid = $CURUSER["id"];
    $warningmsg ="You have been warned and your download rights has been removed. Your ratio is too low and has been low for $RATIOWARN_TIME days. You have $RATIOWARN_BAN days to get your ratio above $RATIOWARN_AMMOUNT or you will be banned!";
    
    if ($userratio <= $RATIOWARN_AMMOUNT && $userratio && (get_user_class() == UC_SYSOP) && !$CURUSER["donated"]){
    //ECHO "RATIOWARN MODULE LOADED :: POOR RATIO<br>"; ###DEBUG PURPOSES
        //check if user is in table
        $check = mysql_query("SELECT * FROM ratiowarn WHERE userid='$userid'"); 
    
        if ((mysql_num_rows($check) != "0")){
            //user is in table
            $status = mysql_fetch_assoc($check);
            if($status["warned"] == "yes"){
                //check date of warning
                //ECHO "RATIOWARN MODULE LOADED :: USER WARNED PREVIOUSLY<br>"; ###DEBUG PURPOSES
                        $sql = mysql_query("SELECT warntime,TO_DAYS(NOW()) - TO_DAYS(warntime) as difference FROM ratiowarn WHERE userid='$userid'");
                        $warnedate = mysql_fetch_assoc($sql);
                    if($warnedate["difference"] > $RATIOWARN_BAN){ //if warned for 3 days,
                        //ban
                        //ECHO "RATIOWARN MODULE LOADED :: USER BANNED<br>"; ###DEBUG PURPOSES
                        mysql_query("UPDATE ratiowarn SET banned='yes' WHERE userid='$userid'");
                        mysql_query("UPDATE users SET enabled='no' WHERE id='$userid'");
                        
                        /*
                            begin_frame("You have been banned", center);
                                echo "You have been automatically banned for maintaing a poor ratio.";
                            end_frame();
                        */
                    }
            }
            else{
                //check date of notification
                //ECHO "RATIOWARN MODULE LOADED :: USER NOT PREVIOUSLY WARNED<br>"; ###DEBUG PURPOSES
                
                        $sql = mysql_query("SELECT ratiodate,TO_DAYS(NOW()) - TO_DAYS(ratiodate) as difference FROM ratiowarn WHERE userid='$userid'");
                        $notificationdate = mysql_fetch_assoc($sql);
                    if($notificationdate["difference"] > $RATIOWARN_TIME){//if notification date is > $RATIOWARN_TIME
                    
                        //ECHO "RATIOWARN MODULE LOADED :: USER WARNED<br>"; ###DEBUG PURPOSES
                        
                        mysql_query("UPDATE ratiowarn SET warntime=NOW() WHERE userid='$userid'");    //add to warned list
                        mysql_query("UPDATE ratiowarn SET warned='yes' WHERE userid='$userid'");//warn
                        mysql_query("UPDATE users SET warned='yes' WHERE id='$userid'");
                        mysql_query("UPDATE users SET downloadno='yes' WHERE id='$userid'");
                        mysql_query("INSERT INTO messages (poster, sender, receiver, added, msg) VALUES ('0', '0', $userid, NOW(), " . sqlesc($warningmsg) . ")");   //send pm
                        
                        /*
                            begin_frame("You will be banned", center);
                                echo $warningmsg;
                            end_frame();
                        */
                    }
            }
        }else{
            //insert user into table
            //ECHO "RATIOWARN MODULE LOADED :: USER ADDED TO WATCH LIST<br>"; ###DEBUG PURPOSES
            mysql_query("INSERT INTO ratiowarn (userid, ratiodate) VALUES ($userid, NOW())");    //add to watch list
        }
    }
    
    ##Makre sure user is not in table
    if ($userratio > $RATIOWARN_AMMOUNT && $userratio){
    //ECHO "RATIOWARN MODULE LOADED :: USER HAS OK RATIO<br>"; ###DEBUG PURPOSES
        $check = mysql_query("SELECT * FROM ratiowarn WHERE userid='$userid'");
        
        if(mysql_num_rows($check) != "0"){
        
            //remove user from database
            
            //ECHO "RATIOWARN MODULE LOADED :: USER REMOVED FROM LIST<br>"; ###DEBUG PURPOSES
            mysql_query("DELETE FROM ratiowarn WHERE userid='$userid'");
            mysql_query("UPDATE users SET warned='no' WHERE id='$userid'");
            mysql_query("UPDATE users SET downloadno='no' WHERE id='$userid'");
        }
    }
}//mustbeloggedin
?>
Return current item: Trunk.net