vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Temporary New Thread Forum Permissions (https://vborg.vbsupport.ru/showthread.php?t=217426)

imported_silkroad 06-29-2009 03:39 PM

Temporary New Thread Forum Permissions
 
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?

Quote:


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

Quote:

Originally Posted by Andreas (Post 1839665)
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.


All times are GMT. The time now is 01:23 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01143 seconds
  • Memory Usage 1,718KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete