GameZoo Forums

Live free, frag hard.

You are not logged in.

#1 10/09/2014 17:27:24

seven
Administrator

group membership expiration mod for FluxBB 1.5.*

This thread is here to discuss the GameZoo Group membership expiration mod.

This is a somewhat complicated mod, so the diff file from fluxBB 1.5.6 is included in the release.

Grab the release here: http://fluxbb.org/resources/mods/gamezo … xpiration/

View the plugin in action here: http://postimg.org/gallery/x7fr1n1a/598fd394/

Here is the shipped README.txt.

##
##
##        Mod title:  GameZoo membership expiration mod for FluxBB 1.5.*
##
##      Mod version:  0.1
##  Works on FluxBB:  1.5.*
##     Release date:  2014-09-10
##           Author:  seven (seven@gamezoo.org)
##
##      Description:  This modification allows a group membership to expire
##                    after a certain time. This period can be defined in the
##                    group properties as well as in the individual user
##                    profile.
##                    When the membership expires and the user logs in, he/she
##                    is automatically moved to the PUN_MEMBER group.
##                    PUN_GUEST, PUN_MEMBER and PUN_ADMIN groups are not
##                    affected by this mod for security reasons.
##                    
##                    +------------------------------------------------+
##                    |--------------------WARNING---------------------|
##                    |                                                |
##                    |               A group can have:                |
##                    |                                                |
##                    |         - EITHER auto-promotion                |
##                    |         - OR membership expiration             |
##                    |                                                |
##                    |             It cannot have both.               |
##                    |                                                |
##                    +------------------------------------------------+
##                    
##                    Example of what would happen if the warning is ignored.
##                    
##                    Imagine this auto-promotion chain:
##                     rookies > PUN_MEMBER (10 posts) > snipers (50 posts)
##                       > professionals (100 posts) > Léon (500 posts)
##                        > Mars (1000 posts) > Chuck (1M posts)
##                     
##                    If you set an expire time to the group 'Mars',
##                    all the users in that group will be moved to PUN_MEMBER
##                    after that time expires. But they'll be auto-promoted
##                    again first to 'snipers', then 'professionals', 'Léon'
##                    and finally 'Mars' because of their post count.
##                    Upon entering the 'Mars' group they'll have a new expire
##                    time set.
##
##   Affected files:  admin_groups.php
##                    include/functions.php
##                    install.php
##                    post.php
##                    profile.php
##
##       Affects DB:  Yes
##                    - altered table: users (added column 'group_expire')
##                    - altered table: groups (added columns: 'g_expire_d',
##                      'g_expire_m', 'g_expire_y')
##
##            Notes:  Read the above warning. Be warned.
##                    Possible improvements:
##                    - SQL DATE instead of g_expire_y, g_expire_m, g_expire_d
##                    - Let the admin choose the 'fallback' group instead of
##                      forcing PUN_MEMBER.
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    FluxBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

#
#---------[ 1. RUN SQL STATEMENTS ]--------------------------------------------
#

ALTER TABLE users ADD COLUMN group_expire INT(10) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE groups ADD COLUMN g_expire_d INT(10) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE groups ADD COLUMN g_expire_m INT(10) UNSIGNED NOT NULL DEFAULT 0;
ALTER TABLE groups ADD COLUMN g_expire_y INT(10) UNSIGNED NOT NULL DEFAULT 0;

#
#---------[ 2. OPEN ]-------------------------------------------------------
#

/admin_groups.php


#
#---------[ 3. FIND ]---------------------------------------------------------
#

                                        <span><?php echo $lang_admin_groups['Report flood help'] ?></span>
                                    </td>
                                </tr>

        
#
#---------[ 4. AFTER, ADD ]------------------------------------------------------
#

                                <?php
                                /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
                                if($mode == 'add' || ($group_id != PUN_GUEST && $group_id != PUN_MEMBER && $group_id != PUN_MOD && $group_id != PUN_ADMIN))
                                {
                                    ?>
                                    <tr>
                                        <th scope="row">Group membership period</th>
                                        <td>
                                            <span style="display:inline-block;width:8em;padding-bottom:2px">Years (0-10)</span><input type="text" name="expire_y" size="5" maxlength="4" value="<?php echo $group['g_expire_y'] ?>" tabindex="44" autocomplete="off" /><br />
                                            <span style="display:inline-block;width:8em;padding-bottom:2px">Months (0-12)</span><input type="text" name="expire_m" size="5" maxlength="4" value="<?php echo $group['g_expire_m'] ?>" tabindex="44" autocomplete="off" /><br />
                                            <span style="display:inline-block;width:8em;padding-bottom:2px">Days (0-31)</span><input type="text" name="expire_d" size="5" maxlength="4" value="<?php echo $group['g_expire_d'] ?>" tabindex="44" autocomplete="off" />
                                            <span>Period the user is allowed to stay in the group. Setting all fields to 0 means 'forever'. You can override this for each user.</span>
                                        </td>
                                    </tr>
                                    <?php
                                }
                                /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
                                ?>


#
#---------[ 5. FIND ]---------------------------------------------------------
#

    $search_flood = (isset($_POST['search_flood']) && $_POST['search_flood'] >= 0) ? intval($_POST['search_flood']) : '0';
    $email_flood = (isset($_POST['email_flood']) && $_POST['email_flood'] >= 0) ? intval($_POST['email_flood']) : '0';
    $report_flood = (isset($_POST['report_flood']) && $_POST['report_flood'] >= 0) ? intval($_POST['report_flood']) : '0';


#
#---------[ 6. AFTER, ADD ]---------------------------------------------------
#

    /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
    $no_expire_group = (isset($_POST['group_id']) && ($_POST['group_id'] == PUN_GUEST || $_POST['group_id'] == PUN_MEMBER || $_POST['group_id'] == PUN_MOD || $_POST['group_id'] == PUN_ADMIN)) ? true : false;
    $expire_y = (empty($_POST['expire_y']) || $no_expire_group) ? 0 : intval($_POST['expire_y']);
    $expire_m = (empty($_POST['expire_m']) || $no_expire_group) ? 0 : intval($_POST['expire_m']);
    $expire_d = (empty($_POST['expire_d']) || $no_expire_group) ? 0 : intval($_POST['expire_d']);
    if($expire_y < 0)  $expire_y = 0;
    if($expire_y > 10) $expire_y = 10;
    if($expire_m < 0)  $expire_m = 0;
    if($expire_m > 12) $expire_m = 12;
    if($expire_d < 0)  $expire_d = 0;
    if($expire_d > 31) $expire_d = 31;
    /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */

#
#---------[ 7. FIND ]---------------------------------------------------------
#

        // Now lets copy the forum specific permissions from the group which this group is based on
        $result = $db->query('SELECT forum_id, read_forum, post_replies, post_topics FROM '.$db->prefix.'forum_perms WHERE group_id='.intval($_POST['base_group'])) or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());

#
#---------[ 8. BEFORE, ADD ]---------------------------------------------------------
#

        /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
        $db->query('UPDATE '.$db->prefix.'groups SET g_expire_y='.$expire_y.',g_expire_m='.$expire_m.',g_expire_d='.$expire_d.' WHERE g_id='.$new_group_id) or error('Unable to update group expiration period', __FILE__, __LINE__, $db->error());
        /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */


#
#---------[ 9. FIND ]-----------------------------------------------------
#
        // Promote all users who would be promoted to this group on their next post
        if ($promote_next_group)


#
#---------[ 10. BEFORE, ADD ]--------------------------------------------------------
#

        /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
        $db->query('UPDATE '.$db->prefix.'groups SET g_expire_y='.$expire_y.',g_expire_m='.$expire_m.',g_expire_d='.$expire_d.' WHERE g_id='.intval($_POST['group_id'])) or error('Unable to update group expiration period', __FILE__, __LINE__, $db->error());
        /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */

        
#
#---------[ 11. FIND ]-----------------------------------------------------
#        
<?php
 
$cur_index = 5;
 
foreach ($groups as $cur_group)
    echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row"><a href="admin_groups.php?edit_group='.$cur_group['g_id'].'" tabindex="'.$cur_index++.'">'.$lang_admin_groups['Edit link'].'</a>'.(($cur_group['g_id'] > PUN_MEMBER) ? ' | <a href="admin_groups.php?del_group='.$cur_group['g_id'].'" tabindex="'.$cur_index++.'">'.$lang_admin_groups['Delete link'].'</a>' : '').'</th><td>'.pun_htmlspecialchars($cur_group['g_title']).'</td></tr>'."\n";
?>
                            </table>

#
#---------[ 12. REPLACE ]--------------------------------------------------------
#

<?php
 
$cur_index = 5;

/* ---- MEMBERSHIP EXPIRATION MOD: BEGIN REPLACEMENT ---- 
foreach ($groups as $cur_group)
    echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row"><a href="admin_groups.php?edit_group='.$cur_group['g_id'].'" tabindex="'.$cur_index++.'">'.$lang_admin_groups['Edit link'].'</a>'.(($cur_group['g_id'] > PUN_MEMBER) ? ' | <a href="admin_groups.php?del_group='.$cur_group['g_id'].'" tabindex="'.$cur_index++.'">'.$lang_admin_groups['Delete link'].'</a>' : '').'</th><td>'.pun_htmlspecialchars($cur_group['g_title']).'</td></tr>'."\n";
*/
foreach ($groups as $cur_group)
{
    echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row"><a href="admin_groups.php?edit_group='.$cur_group['g_id'].'" tabindex="'.$cur_index++.'">'.$lang_admin_groups['Edit link'].'</a>'.(($cur_group['g_id'] > PUN_MEMBER) ? ' | <a href="admin_groups.php?del_group='.$cur_group['g_id'].'" tabindex="'.$cur_index++.'">'.$lang_admin_groups['Delete link'].'</a>' : '').'</th><td>'.pun_htmlspecialchars($cur_group['g_title']);
    
    if(!empty($cur_group['g_expire_y']) || !empty($cur_group['g_expire_m']) || !empty($cur_group['g_expire_d']))
    {
        echo "   <em>(membership period:";
        if(!empty($cur_group['g_expire_y']))
        {
            echo " ".$cur_group['g_expire_y']." year";
            if($cur_group['g_expire_y'] > 1) echo "s";
        }
        if(!empty($cur_group['g_expire_m']))
        {
            echo " ".$cur_group['g_expire_m']." month";
            if($cur_group['g_expire_m'] > 1) echo "s";
        }
        if(!empty($cur_group['g_expire_d']))
        {
            echo " ".$cur_group['g_expire_d']." day";
            if($cur_group['g_expire_d'] > 1) echo "s";
        }
        echo ")</em>";
    }
    
    echo '</td></tr>'."\n";
}
/* ---- MEMBERSHIP EXPIRATION MOD: END REPLACEMENT ---- */
 
?>
                            </table>


#
#---------[ 13. OPEN ]--------------------------------------------------------
#

/include/functions.php


#
#---------[ 14. FIND ]-----------------------------------------------------
#        

         // Send a new, updated cookie with a new expiration timestamp
         $expire = ($cookie['expiration_time'] > $now + $pun_config['o_timeout_visit']) ? $now + 1209600 : $now + $pun_config['o_timeout_visit'];


#
#---------[ 15. BEFORE, ADD ]--------------------------------------------------------
#

        /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
        if($pun_user['group_id'] != PUN_GUEST && $pun_user['group_id'] != PUN_MEMBER && $pun_user['group_id'] != PUN_MOD && $pun_user['group_id'] != PUN_ADMIN)
        {
            // We have to check if the user can stay in the group.
            // If the group has expired, we need to put the user back to the
            // default user group. The default user group is PUN_MEMBER.
            // After that, we need to fetch the user+group info again.
            
            if (!empty($pun_user['group_expire'])) // exists and is not zero
            {
                if ($pun_user['group_expire'] < time()) // expired?
                {
                    $uid = $pun_user['id'];
                    $pun_user = array();
                    
                    $db->query('UPDATE '.$db->prefix.'users SET group_id='.PUN_MEMBER.',group_expire=0 WHERE id='.$uid) or error('Unable to update user visit data', __FILE__, __LINE__, $db->error());
                    
                    $result = $db->query('SELECT u.*, g.*, o.logged, o.idle FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.user_id=u.id WHERE u.id='.$uid) or error('Unable to fetch user information', __FILE__, __LINE__, $db->error());
                    $pun_user = $db->fetch_assoc($result);
                    $uid = null;
                }
            }
        }
        /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */


#
#---------[ 16. OPEN ]-----------------------------------------------------
#

/install.php


#
#---------[ 17. FIND ]--------------------------------------------------------
#

                 'datatype'        => 'SMALLINT(6)',
                 'allow_null'    => false,
                 'default'        => '60'
            )
         'PRIMARY KEY'    => array('g_id')


#
#---------[ 18. REPLACE ]-----------------------------------------------------
#

                 'datatype'        => 'SMALLINT(6)',
                 'allow_null'    => false,
                 'default'        => '60'
            ),
            /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
            'g_expire_y'        => array(
                'datatype'        => 'INT UNSIGNED',
                'allow_null'    => false,
                'default'        => '0'
            ),
            'g_expire_m'        => array(
                'datatype'        => 'INT UNSIGNED',
                'allow_null'    => false,
                'default'        => '0'
            ),
            'g_expire_d'        => array(
                'datatype'        => 'INT UNSIGNED',
                'allow_null'    => false,
                'default'        => '0'
            ),
            /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
         ),
         'PRIMARY KEY'    => array('g_id')
        

#
#---------[ 19. FIND ]--------------------------------------------------------
#

                 'datatype'        => 'VARCHAR(8)',
                 'allow_null'    => true
             ),
         ),
         'PRIMARY KEY'    => array('id'),

#
#---------[ 20. REPLACE ]--------------------------------------------------------
#

                 'datatype'        => 'VARCHAR(8)',
                 'allow_null'    => true
             ),
            /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
            'group_expire'        => array(
                'datatype'        => 'INT(10) UNSIGNED',
                'allow_null'    => false,
                'default'        => '0'
            ),
            /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
         ),
         'PRIMARY KEY'    => array('id'),


#
#---------[ 21. OPEN ]-----------------------------------------------------
#

/post.php

        
#
#---------[ 22. FIND ]--------------------------------------------------------
#

             {
                 $new_group_id = $pun_user['g_promote_next_group'];
                 $db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$pun_user['id']) or error('Unable to promote user to new group', __FILE__, __LINE__, $db->error());
             }
 
             // Topic tracking stuff...

        
#
#---------[ 23. REPLACE ]-----------------------------------------------------
#

             {
                 $new_group_id = $pun_user['g_promote_next_group'];
                 $db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$pun_user['id']) or error('Unable to promote user to new group', __FILE__, __LINE__, $db->error());
                
                /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
                if($new_group_id != PUN_GUEST && $new_group_id != PUN_MEMBER && $new_group_id != PUN_MOD && $new_group_id != PUN_ADMIN)
                {
                    // Read and apply the group expiration date.
                    $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE id='.$new_group_id) or error('Unable to retrieve group expiration date', __FILE__, __LINE__, $db->error());
                    $new_group = $db->fetch_assoc($result);
                    if(!empty($new_group['g_expire_y']) || !empty($new_group['g_expire_m']) || !empty($new_group['g_expire_d']))
                    {
                        $now = getdate();
                        $group_expire = mktime(0,0,0, $now['mon']+$new_group['g_expire_m'], $now['mday']+$new_group['g_expire_d'], $now['year']+$new_group['g_expire_y']);
                        $db->query('UPDATE '.$db->prefix.'users SET group_expire='.$group_expire.' WHERE id='.$id) or error('Unable to change user group membership expiration date', __FILE__, __LINE__, $db->error());
                    }
                }
                /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
             }
 
             // Topic tracking stuff...

        
#
#---------[ 24. OPEN ]--------------------------------------------------------
#

/profile.php


#
#---------[ 25. FIND ]--------------------------------------------------------
#

     $old_group_id = $db->result($result);
 
     $db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());

    // Regenerate the users info cache
     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
    
    
#
#---------[ 26. REPLACE ]-----------------------------------------------------
#

     $old_group_id = $db->result($result);
 
     $db->query('UPDATE '.$db->prefix.'users SET group_id='.$new_group_id.' WHERE id='.$id) or error('Unable to change user group', __FILE__, __LINE__, $db->error());
    
    /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
    if($new_group_id != PUN_GUEST && $new_group_id != PUN_MEMBER && $new_group_id != PUN_ADMIN)
    {
        // Read and apply the group expiration date.
        $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE g_id='.$new_group_id) or error('Unable to retrieve group expiration date', __FILE__, __LINE__, $db->error());
        $new_group = $db->fetch_assoc($result);
        if(!empty($new_group['g_expire_y']) || !empty($new_group['g_expire_m']) || !empty($new_group['g_expire_d']))
        {
            $now = getdate();
            $group_expire = mktime(0,0,0, $now['mon']+$new_group['g_expire_m'], $now['mday']+$new_group['g_expire_d'], $now['year']+$new_group['g_expire_y']);
            $db->query('UPDATE '.$db->prefix.'users SET group_expire='.$group_expire.' WHERE id='.$id) or error('Unable to change user group membership expiration date', __FILE__, __LINE__, $db->error());
        }
    }
    /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
 
     // Regenerate the users info cache
     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))


#
#---------[ 27. FIND ]--------------------------------------------------------
#

 else if (isset($_POST['update_forums']))
 {
     if ($pun_user['g_id'] > PUN_ADMIN)

#
#---------[ 28. BEFORE, ADD ]--------------------------------------------------------
#

/* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
else if (isset($_POST['update_group_membership_expiration']))
{
    if ($pun_user['g_id'] > PUN_ADMIN)
        message($lang_common['No permission'], false, '403 Forbidden');
    
    confirm_referrer('profile.php');
    
    $g_expire_y = intval($_POST['g_expire_y']);
    $g_expire_m = intval($_POST['g_expire_m']);
    $g_expire_d = intval($_POST['g_expire_d']);
    
    // if all of these fields are set to 0, then membership never expires
    if($g_expire_y == 0 && $g_expire_m == 0 && $g_expire_d == 0)
    {
        $db->query('UPDATE '.$db->prefix.'users SET group_expire=0 WHERE id='.$id) or error('Unable to change user membership expiration date', __FILE__, __LINE__, $db->error());
    }
    else
    {
        // check the fields before submitting to the database
        if(!checkdate($g_expire_m, $g_expire_d, $g_expire_y))
            message('The entered date ('.$g_expire_d.'/'.$g_expire_m.'/'.$g_expire_y.') is not valid.');
            
        $timestamp = mktime(0,0,0, $g_expire_m, $g_expire_d, $g_expire_y);
        if($timestamp < time())
            message('The entered date ('.$g_expire_d.'/'.$g_expire_m.'/'.$g_expire_y.') is in the past.');
        
        $db->query('UPDATE '.$db->prefix.'users SET group_expire='.$timestamp.' WHERE id='.$id) or error('Unable to change user membership expiration date', __FILE__, __LINE__, $db->error());
    }
    
    redirect('profile.php?section=admin&id='.$id, 'The expiration date of the group membership has been updated');
}
/* ---- MEMBERSHIP EXPIRATION MOD: END ---- */

#
#---------[ 29. FIND ]--------------------------------------------------------
#

     $next_group_id = $db->result($result);
     $db->query('UPDATE '.$db->prefix.'users SET group_id='.$next_group_id.' WHERE id='.$id) or error('Unable to promote user', __FILE__, __LINE__, $db->error());
 
     redirect('viewtopic.php?pid='.$pid.'#p'.$pid, $lang_profile['User promote redirect']);
    

#
#---------[ 30. REPLACE ]-----------------------------------------------------
#

     $next_group_id = $db->result($result);
     $db->query('UPDATE '.$db->prefix.'users SET group_id='.$next_group_id.' WHERE id='.$id) or error('Unable to promote user', __FILE__, __LINE__, $db->error());
    
    /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
    if($next_group_id != PUN_GUEST && $next_group_id != PUN_MEMBER && $next_group_id != PUN_ADMIN)
    {
        // Read and apply the group expiration date.
        $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE id='.$next_group_id) or error('Unable to retrieve group expiration date', __FILE__, __LINE__, $db->error());
        $next_group = $db->fetch_assoc($result);
        if(!empty($next_group['g_expire_y']) || !empty($next_group['g_expire_m']) || !empty($next_group['g_expire_d']))
        {
            $now = getdate();
            $group_expire = mktime(0,0,0, $now['mon']+$next_group['g_expire_m'], $now['mday']+$next_group['g_expire_d'], $now['year']+$next_group['g_expire_y']);
            $db->query('UPDATE '.$db->prefix.'users SET group_expire='.$group_expire.' WHERE id='.$id) or error('Unable to change user group membership expiration date', __FILE__, __LINE__, $db->error());
        }
    }
    /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
 
     redirect('viewtopic.php?pid='.$pid.'#p'.$pid, $lang_profile['User promote redirect']);


#
#---------[ 31. FIND ]--------------------------------------------------------
#

    redirect('profile.php?section='.$section.'&id='.$id, $lang_profile['Profile redirect']);
}
 
 
$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
    message($lang_common['Bad request'], false, '404 Not Found');
    
    
#
#---------[ 32. REPLACE ]-----------------------------------------------------
#

    redirect('profile.php?section='.$section.'&id='.$id, $lang_profile['Profile redirect']);
}
 
/* ---- MEMBERSHIP EXPIRATION MOD: REPLACEMENT BEGIN ---- */
// I don't even understand why SELECT * is not used. Let's replace this wonton soup and select everything instead of adding another field.
 
/* replaced code
$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, u.last_visit, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
*/

// replacement code
$result = $db->query('SELECT u.*, g.* FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
/* ---- MEMBERSHIP EXPIRATION MOD: REPLACEMENT END ---- */

if (!$db->num_rows($result))
    message($lang_common['Bad request'], false, '404 Not Found');


#
#---------[ 33. FIND ]--------------------------------------------------------
#

                            <input type="hidden" name="form_sent" value="1" />
                            <?php echo $username_field ?>
<?php if ($pun_user['id'] == $id || $pun_user['g_id'] == PUN_ADMIN || ($user['g_moderator'] == '0' && $pun_user['g_mod_change_passwords'] == '1')): ?>                            <p class="actions"><span><a href="profile.php?action=change_pass&id=<?php echo $id ?>"><?php echo $lang_profile['Change pass'] ?></a></span></p>
<?php endif; ?>                        </div>

                     </fieldset>
                 </div>
                 <div class="inform">
                
                
#
#---------[ 34. REPLACE ]-----------------------------------------------------
#

                            <input type="hidden" name="form_sent" value="1" />
                            <?php echo $username_field ?>
<?php if ($pun_user['id'] == $id || $pun_user['g_id'] == PUN_ADMIN || ($user['g_moderator'] == '0' && $pun_user['g_mod_change_passwords'] == '1')): ?>                            <p class="actions"><span><a href="profile.php?action=change_pass&id=<?php echo $id ?>"><?php echo $lang_profile['Change pass'] ?></a></span></p>
<?php endif; ?>
                        <?php
                        /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
                        if ($pun_user['id'] == $id || $pun_user['g_id'] == PUN_ADMIN)
                        {
                            // compute data and display the form
                            echo '<p>Group: '.$user['g_title'];
                            
                            if(!empty($user['group_expire']))
                                echo ' <em>expires: '. date("d/m/Y H:i:s T (\U\T\C O)", $user['group_expire']).'</em>';
                            echo '</p>'."\n";
                        }
                        /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */
                        ?>
                        </div>
                     </fieldset>
                 </div>
                 <div class="inform">

#
#---------[ 35. FIND ]--------------------------------------------------------
#

                            <input type="submit" name="update_group_membership" value="<?php echo $lang_profile['Save'] ?>" />
                        </div>
                    </fieldset>
                </div>

                
#
#---------[ 36. AFTER, ADD ]---------------------------------------------------------
#

<?php /* ---- MEMBERSHIP EXPIRATION MOD: BEGIN ---- */
                // Display the membership period form on user groups different from PUN_ADMIN, PUN_GUEST, PUN_MEMBER
                // because these groups *cannot* have an ending.
                // Zapping admin(s) would be rather bad.
                // Zapping members is useless, since this group is the one where people will be put after expiration.
                // Zapping guests would make them members instead and cause havoc.
                if (isset($user['group_id']) && isset($user['group_expire'])) // Check that the mod is present
                {
                    if($user['group_id'] != PUN_ADMIN && $user['group_id'] != PUN_MEMBER && $user['group_id'] != PUN_GUEST)
                    {
                        // compute data and display the form whe
                        if(empty($user['group_expire']))
                        {
                            $expiration_date = 'never';
                            $g_expire_y = '0';
                            $g_expire_m = '0';
                            $g_expire_d = '0';
                        }
                        else
                        {
                            $expiration_date = date("d/m/Y H:i:s T (\U\T\C O)", $user['group_expire']);
                            $g_expire_y = date("Y", $user['group_expire']);
                            $g_expire_m = date("n", $user['group_expire']);
                            $g_expire_d = date("j", $user['group_expire']);
                        }
                        ?>
                        <div class="inform">
                            <fieldset>
                                <legend>Current group membership expiration date: <strong><?php echo $expiration_date; ?></strong></legend>
                                <div class="infldset">
                                    <span><em>All times are relative to this server's timezone: <strong><?php echo date_default_timezone_get() ?></strong></em></span>
                                    <div>Set all fields to 0 to disable expiration.</div>
                                    <span style="display:inline-block;width:8em;padding-bottom:2px">Day (1-31)</span><input type="text" name="g_expire_d" maxlength="4" value="<?php echo $g_expire_d ?>" autocomplete="off" /><br />
                                    <span style="display:inline-block;width:8em;padding-bottom:2px">Month (1-12)</span><input type="text" name="g_expire_m" maxlength="4" value="<?php echo $g_expire_m ?>" autocomplete="off" /><br />
                                    <span style="display:inline-block;width:8em;padding-bottom:2px">Year (≥<?php echo date("Y");?>)</span><input type="text" name="g_expire_y" maxlength="4"  value="<?php echo $g_expire_y ?>" autocomplete="off" /><br />
                                    <div><input type="submit" name="update_group_membership_expiration" value="Set new date"/></div>
                                </div>
                            </fieldset>
                        </div>
                        <?php
                    }
                }
                /* ---- MEMBERSHIP EXPIRATION MOD: END ---- */ ?>

#
#---------[ 37. SAVE/UPLOAD ]--------------------------------------------------------
#

Punirne cento per educarne uno.

Offline

Board footer

Powered by FluxBB