PDA

View Full Version : Temporary New Thread Forum Permissions


imported_silkroad
06-29-2009, 03:39 PM
Hi. I am working on some code that permits a user without access rights to post a new thread in a forum for a limited time period based by decrementing a field in the user table. I have created a new table that consists of a transactionid, a userid, a forumid and a unix timestamp.

When the user attempts a new thread the code looks to see if the forum has a newthread_access_cost set in the forum. If it does, it pops up a vbphased error message that gives the user the option to use their virtual currency to post a newthread.

It also checks to see if the time against the allowed posting time and resets the users accessmasks back to zero.

I have most of the code working, except I am a bit confused about setting and resetting access masks for a user. Is this correct?



Granting accesss:

$db->query_write("REPLACE INTO " . TABLE_PREFIX . "access (userid, forumid, accessmask) VALUES (" . $vbulletin->userinfo['userid'] . ", " . $foruminfo['forumid'] . ", 1)");

$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$userdm->set_existing($vbulletin->userinfo);
$userdm->set_bitfield('options', 'hasaccessmask', true);
$userdm->save();
unset($userdm);

Revoking access:

$db->query_write("REPLACE INTO " . TABLE_PREFIX . "access (userid, forumid, accessmask) VALUES (" . $vbulletin->userinfo['userid'] . ", " . $foruminfo['forumid'] . ", 0)");

$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$userdm->set_existing($vbulletin->userinfo);
$userdm->set_bitfield('options', 'hasaccessmask', true);
$userdm->save();
unset($userdm);


In other words, all I need to do is toggle the accessmask for the access set (userid, forumid, accessmask)?

Andreas
06-29-2009, 04:06 PM
If you only need the access once to create the thread I probably wouldn't even bother to set access masks - just set the bit you need?

imported_silkroad
06-29-2009, 04:25 PM
If you only need the access once to create the thread I probably wouldn't even bother to set access masks - just set the bit you need?

Hi Andreas,

The way I have configured is that the forum table has two fields, one field is newthread_access_cost and the other is newthread_access_period. Generally, access is for about an hour, or 360 in unixtime. So, the user can post anytime for an hour as long as NOW - timestamp_of_first_access < newthread_access_period.

That is why I thought it would be good to set/unset the access mask.

Cheers.