View Full Version : Automatically change usergroup after certain amount of time
zsmom
12-18-2003, 01:08 AM
I would like there to be a way for members' usergroups to automatically change to a different one after a certain amount of time since their last post.
This seems like it would be fairly simple to do, but I have no idea.
Or is there a way to do this already?
Logician
12-18-2003, 09:14 AM
do you want to change at the moment they revisited the board or even if they dont revisit? If latter, it will require a cron script.
Zachery
12-18-2003, 10:55 AM
could be done with vb3 very simply as its a built in feature
zsmom
12-18-2003, 11:26 AM
I'd prefer it to change even if they don't revisit. But either way would be fine with me. It beats having to do it manually, that's for sure.
Logician
12-18-2003, 05:56 PM
let us know:
a) Usergroups the hack will apply
b) New Usergroup hack will put users in
c) Time hack will check
zsmom
12-18-2003, 08:05 PM
Ok...usergroups 9 and 11 would change to usergroup 2 at 30 days since last post. And I guess it would check this once per day, midnight I guess, though that part doesn't matter much.
Thanks!!!
Logician
12-18-2003, 09:03 PM
Create a "anynameyouwant.php" file in your forum directory and put this code inside that file:
<?php
set_time_limit(900);
require('./global.php');
$userArray=$DB_site->query("SELECT * FROM user WHERE (usergroupid=9 OR usergroupid=11) AND posts>0");
while ($user=$DB_site->fetch_array($userArray))
{
$days = mktime (date("H"), date("i"), date("s"), date("m"), date("d")-30, date("Y"));
$lastpost=$DB_site->query_first("SELECT dateline FROM post WHERE visible=1 AND userid='$user[userid]' ORDER BY dateline DESC LIMIT 1");
if ($lastpost[dateline]>0 AND $lastpost[dateline]>$days)
{
$DB_site->query("UPDATE user SET usergroupid=2 WHERE userid='$user[userid]'");
}
}
?>
Now configure your CRON job to run this file once everyday at any time you like.
Please test this script in a test board first! I dont expect a problem but I don't like giving away scripts like this as they make changes in DB so a bug can create serious problems. I didnt test the script myself.
zsmom
12-20-2003, 01:20 AM
Thank you so much! I'll give it a whirl...
g-force2k2
12-20-2003, 05:03 AM
Question Logician, what exactly does set_time_limit( ) function do? I appreciate any assistance.
Regards,
g-force2k2
zsmom
12-20-2003, 07:11 AM
Ok, I tried it and it changes everyone in usergroups 9 & 11, regardless of the time since their last post, to usergroup 2. Any ideas?
Logician
12-20-2003, 07:20 AM
Ok, I tried it and it changes everyone in usergroups 9 & 11, regardless of the time since their last post, to usergroup 2. Any ideas?
himm the line:
if ($lastpost[dateline]>0 AND $lastpost[dateline]>$days)
should be
if ($lastpost[dateline]>0 AND $lastpost[dateline]<$days)
It was not changing everyone but it was changing who posted in the last 30 days. Since you asked for the opposite, new line should do the trick ;)
what exactly does set_time_limit( ) function do? I appreciate any assistance.
buddy, by default PHP scripts are granted 30 seconds running time. (unless it is set otherwise in php configuration). If they exceed 30 seconds, they time out. However some scripts may need more running time so you can set how many seconds a script can run before it times out with set_time_limit() command.
I thought this script might take some time if user database is large so I put this command in the begining just in case to prevent time out error. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.