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)?
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)?