|?| make this page exclusive for this group?

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
Locked
User avatar
fahad4x4
Registered User
Posts: 15
Joined: Wed May 30, 2007 1:10 am

|?| make this page exclusive for this group?

Post by fahad4x4 »

Hi


By the help of this page (http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/) I made a new custom page and I added it to my phpbb forum.

Now, I want a group of my users can see this page only that what I meant is a group of my phpBB3 forum users can see it only.

Is there kind of code that I can add to this page can make this page exclusive for this group?

Thanks for ur help
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: |?| make this page exclusive for this group?

Post by Erik Frèrejean »

Well just check whether the user is part of the group.

Code: Select all

$allowed_groups = array('1'); // Fill this array with the groups who are allowed to see the page

// Don't modify
$sql = 'SELECT group_id
        FROM ' . USER_GROUP_TABLE . '
            WHERE user_id = ' . (int) $user->data['user_id'] . '
                AND ' . $db->sql_in_set('group_id', $allowed_groups) . '
                AND user_pending = 0';
$result = $db->sql_query($sql);
$group    = $db->sql_fetchfield('group_id', $result);

if (!$group)
{
    trigger_error('No access');
}
// End Don't modify 
Note: just wrote this very quickly, so maybe there is an fault in this code :wink:
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
User avatar
fahad4x4
Registered User
Posts: 15
Joined: Wed May 30, 2007 1:10 am

Re: |?| make this page exclusive for this group?

Post by fahad4x4 »

code very beautiful

Great result
Thank you
HASHIMS
Registered User
Posts: 5
Joined: Tue Mar 11, 2008 8:42 am

Re: |?| make this page exclusive for this group?

Post by HASHIMS »

Hi...
Is this code work with you friends?

Because I faced this error when I tried to view the page.

Code: Select all

Fatal error: Call to a member function sql_in_set() on a non-object in /home/salm55ss/public_html/phpbb3/JF_Mag.php on line 8
note:
line 8 is :

Code: Select all

  AND ' . $db->sql_in_set('group_id', $allowed_groups) . '
I need your assistance :?
User avatar
Erik Frèrejean
Former Team Member
Posts: 9899
Joined: Tue Oct 09, 2007 9:09 am
Location: The Netherlands, 3.0.x Support Forum
Name: Erik Frèrejean
Contact:

Re: |?| make this page exclusive for this group?

Post by Erik Frèrejean »

Did you start the phpBB session? (Knowledge Base - Add a New Custom Page to phpBB).
You must do this because this code relays on the phpBB3.x DBAL.
Support Toolkit | Support Request Template | Knowledge Base | phpBB 3.0.x documentation
I don't give support via PM or IM! (all unsolicited pms will be trashed!)
User avatar
fahad4x4
Registered User
Posts: 15
Joined: Wed May 30, 2007 1:10 am

Re: |?| make this page exclusive for this group?

Post by fahad4x4 »

hi

Is it still working on the latest version

because I tested I appeared this Error

Code: Select all

Fatal error: Call to a member function sql_in_set() on a non-object in /home/xxxxxxx/public_html/BB2/page.php on line 20
line 20

Code: Select all

AND ' . $db->sql_in_set('group_id', $allowed_groups) . '
User avatar
4_seven
I've Been Banned!
Posts: 5155
Joined: Wed Apr 30, 2008 1:41 am

Re: |?| make this page exclusive for this group?

Post by 4_seven »

try

Code: Select all

$allowed_groups = array(5,7,9)

Code: Select all

$allowed_groups = array(1)
instead of

Code: Select all

$allowed_groups = array('5','7','9')

Code: Select all

$allowed_groups = array('1')
or try this instead

http://www.phpbb.com/community/viewtopi ... 5#p7753375
Current Mods | Mod Base | php(BB) programming | No help via PM
Locked

Return to “[3.0.x] MOD Requests”