############################################################## 
## MOD Title: Post Cap 
## MOD Author: UT[EO]Clans < webmaster@uteoclans.com > (Anti) www.uteoclans.com www.statho.com www.statho.com/anti/
## MOD Description: This mod will allow you to put a daily post cap on specific users via ACP, User - Management
## MOD Version: 1.0.3 
## 
## Installation Level: (Moderate) 
## Installation Time: ~15 Minutes 
## Files To Edit: 
##            includes/functions_post.php
##            admin/admin_users.php
##            language/lang_english/lang_admin.php
##            language/lang_english/lang_main.php
##            templates/subSilver/admin/user_edit_body.tpl
## Included Files: N/A 
############################################################## 
## For Security Purposes, Please Check: http://www.phpbb.com/mods/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered 
## in our MOD-Database, located at: http://www.phpbb.com/mods/ 
############################################################## 
## Author Notes: This mod was inspired by |UCT|Pimp'n_Fly. Thanx to Salty & Treat for the idea & name
##         Thanx to VIVI, Indy, Sapp, & all the others that either helped test this mod during it's
##         short development period, or pointed out errors during development. For The most up to date
##         copy of "Post Cap" mod, please check the downloads database at www.uteoclans.com/. 
##        
##         This will most likely be the last release of this mod, in this version. I have received 
##         requests for versions of this mod that work based on groups, and another that is based on
##         time the user has been registered. These releases will be Post_Cap_Mod-1.2.* and Post_Cap_Mod-2.0.*
## 
############################################################## 
## MOD History:
##   2005-04-27 - version 1.0.3 final
##    - Fixed small error and some typos. sorry for these, I was tired when I tested it.
##
##   2005-04-15 - Version 1.0.2
##    - Reworked period processing/generation to work by hours, not days
##
##   2005-02-22 - Version 1.0.1 
##      - Fixed error with new period generation.
##    - Re-organized logic on post count processing and period generation
##    - Re-strucutured original mysql table modificiations -- more efficient. 
## 
############################################################## 
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD 
############################################################## 


### USE THIS SQL IF YOU HAVE NEVER INSTALLED THIS MOD ###
#
#-----[ SQL ]------------------------------------------
#
ALTER TABLE `phpbb_users` 
ADD `daily_post_count` TINYINT( 3 ) DEFAULT '0' NOT NULL ,
ADD `daily_post_limit` TINYINT( 3 ) NOT NULL ,
ADD `daily_post_period` INT( 11 ) NOT NULL ;

### USE THIS SQL IF YOU ARE UPDATING FROM THE FIRST VERSION ONLY! ###
#
#-----[ SQL ]------------------------------------------
#
ALTER TABLE `phpbb_users` CHANGE `daily_post_period` `daily_post_period` INT( 11 ) DEFAULT '0' NOT NULL 


# 
#-----[ OPEN ]------------------------------------------ 
#
includes/functions_post.php

# 
#-----[ FIND ]------------------------------------------ 
#
                    message_die(GENERAL_MESSAGE, $lang['Flood_Error']);
                }
            }
        }

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
        ############### POST CAP MOD BY ANTI -- www.uteoclans.com ###############
        function generate_limit_period($period_id) {
        global $db;
                $sql = "UPDATE " . USERS_TABLE . " 
                SET daily_post_period = '".time()."', daily_post_count = '0' 
                WHERE user_id = '".$period_id."' 
                LIMIT 1";
                if(!($result = $db->sql_query($sql)))
                {
                    message_die(GENERAL_ERROR, 'Could not update daily flood post period', 'Daily Flood Update');
                }
            return 0;
        }        

        if($userdata['daily_post_period'] != 0 && ((time() - $userdata['daily_post_period']) > 86400 )) { // stale period
            $userdata['daily_post_limit'] = generate_limit_period($userdata['user_id']);
        }
        if($userdata['daily_post_period'] == 0 && $userdata['daily_post_limit'] > 0) { // new limit
            $userdata['daily_post_limit'] = generate_limit_period($userdata['user_id']);
        }
        if(($userdata['daily_post_limit'] - $userdata['daily_post_count']) <= 0 && $userdata['daily_post_limit'] != 0) // if they have reached the limit
        {
            message_die(GENERAL_MESSAGE, $lang['daily_flood_limit'], 'Daily Flood Limit');
        } else { // if they havent reached the limit
        $sql = "UPDATE " . USERS_TABLE . " 
        SET daily_post_count = daily_post_count+1 
        WHERE user_id = '".$userdata[user_id]."' 
        LIMIT 1";
            if(!($result = $db->sql_query($sql)))
            {
                message_die(GENERAL_ERROR, 'Could not update daily flood post count', '', __LINE__, __FILE__, $sql);
            }
        }
        ############### END POST CAP MOD ###############



# 
#-----[ OPEN ]------------------------------------------ 
#
admin/admin_users.php



# 
#-----[ FIND ]------------------------------------------ 
#
        $user_status = ( !empty($HTTP_POST_VARS['user_status']) ) ? intval( $HTTP_POST_VARS['user_status'] ) : 0;
        $user_allowpm = ( !empty($HTTP_POST_VARS['user_allowpm']) ) ? intval( $HTTP_POST_VARS['user_allowpm'] ) : 0;
        $user_rank = ( !empty($HTTP_POST_VARS['user_rank']) ) ? intval( $HTTP_POST_VARS['user_rank'] ) : 0;
        $user_allowavatar = ( !empty($HTTP_POST_VARS['user_allowavatar']) ) ? intval( $HTTP_POST_VARS['user_allowavatar'] ) : 0;

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
        $daily_post_limit = ( !empty($HTTP_POST_VARS['daily_post_limit']) ) ? trim(strip_tags( $HTTP_POST_VARS['daily_post_limit'] ) ) : 0;

# 
#-----[ FIND ]------------------------------------------ 
#
        //
        // Update entry in DB
        //
        if( !$error )
        {
            $sql = "UPDATE " . USERS_TABLE . "
                SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) . "', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", $aim) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_sig_bbcode_uid = '$signature_bbcode_uid', user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowavatar = $user_allowavatar, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_allow_pm = $user_allowpm, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_active = $user_status, user_rank = $user_rank" . $avatar_sql . "


# 
#-----[ IN-LINE FIND ]------------------------------------------ 
#
user_rank = $user_rank" . $avatar_sql . "

# 
#-----[ IN-LINE AFTER, ADD ]------------------------------------------ 
#
        , daily_post_limit = $daily_post_limit


# 
#-----[ FIND ]------------------------------------------ 
#
        $user_status = $this_userdata['user_active'];
        $user_allowavatar = $this_userdata['user_allowavatar'];
        $user_allowpm = $this_userdata['user_allow_pm'];

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
        $daily_post_limit = $this_userdata['daily_post_limit'];

# 
#-----[ FIND ]------------------------------------------ 
#
            $s_hidden_fields .= '<input type="hidden" name="user_status" value="' . $user_status . '" />';
            $s_hidden_fields .= '<input type="hidden" name="user_allowpm" value="' . $user_allowpm . '" />';
            $s_hidden_fields .= '<input type="hidden" name="user_allowavatar" value="' . $user_allowavatar . '" />';
            $s_hidden_fields .= '<input type="hidden" name="user_rank" value="' . $user_rank . '" />';

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
            $s_hidden_fields .= '<input type="hidden" name="daily_post_limit" value="' . $daily_post_limit . '" />';

# 
#-----[ FIND ]------------------------------------------ 
#
            'USER_ACTIVE_NO' => (!$user_status) ? 'checked="checked"' : '', 
            'RANK_SELECT_BOX' => $rank_select_box,

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#
    #### DAILY POST LIMIT MOD -- Anti ####
            'DAILY_POST_LIMIT' => $daily_post_limit,
            'L_DAILY_LIMIT' => $lang['daily_limit'],

# 
#-----[ OPEN ]------------------------------------------ 
# 
langauge/lang_english/lang_admin.php


# 
#-----[ FIND ]------------------------------------------ 
#

//
// That's all Folks!
// -------------------------------------------------

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
//
// DAILY POST LIMIT MOD -- Anti
$lang['daily_limit'] = "Daily Post Limit";

# 
#-----[ OPEN ]------------------------------------------ 
# 
language/lang_enlish/lang_main.php


# 
#-----[ FIND ]------------------------------------------ 
#
//
// That's all, Folks!
// -------------------------------------------------

# 
#-----[ BEFORE, ADD ]------------------------------------------ 
#
$lang['daily_flood_limit'] = "You have already posted your daily alloted posts. Please try back at a later time<br />";

# 
#-----[ OPEN ]------------------------------------------ 
# 
templates/subSilver/admin/user_edit_body.tpl

# 
#-----[ FIND ]------------------------------------------ 
#
    <tr>
      <th class="thSides" colspan="2">{L_SPECIAL}</th>
    </tr>

# 
#-----[ AFTER, ADD ]------------------------------------------ 
#

    <tr>
      <td class="row1"><span class="gen">{L_DAILY_LIMIT}</span><br /><span class="gensmall"># of posts a user can make in a 24 hour period. 0 = no limit</span></td>
      <td class="row2"><input class="post" type="text" name="daily_post_limit" value="{DAILY_POST_LIMIT}" size="3" /></td>
    </tr>


# 
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 
# 
# EoM