How to add a yes/no option for individual users?
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #1
How to add a yes/no option for individual users?
How can I achive the same thing you helped me here but instead of groups, to add it for individual users. Can you help me out again please Yumi? Thank you.

http://mybbhacks.zingaburga.com/showthread.php?tid=318
06-04-2010 10:48 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: How to add a yes/no option for individual users?
Take a look at the admin/modules/user/users.php file (as opposed to admin/modules/user/groups.php) to find the relevant hooks and code executed.
The idea should generally be the same.

My Blog
06-05-2010 09:48 AM
Find all posts by this user Quote this message in a reply
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #3
RE: How to add a yes/no option for individual users?
(06-05-2010 09:48 AM)ZiNgA BuRgA Wrote:  Take a look at the admin/modules/user/users.php file (as opposed to admin/modules/user/groups.php) to find the relevant hooks and code executed.
The idea should generally be the same.

I have tried that but I can''t seem to get it right. Sorry to be a bother, but can you please help me once more with the exact changes? And I promise, I won''t bother you anymore.
06-05-2010 10:08 AM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #4
RE: How to add a yes/no option for individual users?
You can try this code (based on the original code and file name):

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
if(!defined("IN_MYBB"))
{
	die("This file cannot be accessed directly.");
}

$plugins->add_hook("admin_user_users_edit", "custompages_perms_admin_user_users_edit");
$plugins->add_hook("admin_user_users_edit_commit", "custompages_perms_admin_user_users_edit_commit");

function custompages_perms_info()
{
	return array(
		"name"		=> "Custom Pages Permissions",
		"description"	=> "Add permissions for custom pages.",
		"website"	=> "http://community.mybboard.net/user-13556.html",
		"author"	=> "MattRogowski",
		"authorsite"	=> "http://community.mybboard.net/user-13556.html",
		"version"	=> "1.0",
		"compatibility" => "14*,15*,16*"
	);
}

function custompages_perms_activate()
{
	
}

function custompages_perms_deactivate()
{
	
}

function custompages_perms_admin_user_users_edit()
{
	global $plugins;
	
	$plugins->add_hook("admin_formcontainer_end", "custompages_perms_admin_user_users_edit_form");
}

function custompages_perms_admin_user_users_edit_form()
{
	global $mybb, $lang, $form, $form_container, $user;
	
	
	if($mybb->version_code >= 1500) {
		$fc = (array)$form_container;
		$fctitle = $fc["\0DefaultFormContainer\0_title"];
		unset($fc);
	} else $fctitle = $form_container->_title;

	if($fctitle == $lang->account_settings.": {$user['username']}")
	{
		$custom_pages_options = array(
			$form->generate_check_box("canviewpage_contact", 1, "Can view contact page??", array("checked" => $mybb->input['canviewpage_contact']))
		);
		$form_container->output_row("Custom Pages Permissions", "", "<div class=\"user_settings_bit\">".implode("</div><div class=\"user_settings_bit\">", $custom_pages_options)."</div>");
	}
}

function custompages_perms_admin_user_users_edit_commit()
{
	global $mybb, $updated_user;
	
	$updated_user['canviewpage_contact'] = $mybb->input['canviewpage_contact'];
}
?>


06-05-2010 10:17 AM
Find all posts by this user Quote this message in a reply
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #5
RE: How to add a yes/no option for individual users?
Yes, that did it. Thank you very much. I was not entering right a plugin hook.

One more last question, how would I call the user in my script when defining if he would see my custom page which is a bingo page?

For the group was:

PHP Code:
if($mybb->usergroup['canviewpage_contact'] != 1)
{
    error_no_permission();
}



I tried to use:

$mybb->user['uid']['canviewpage_contact'] and $mybb->user['canviewpage_contact'] but it didn''t work. What is the right array to call the user?

06-05-2010 09:15 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: How to add a yes/no option for individual users?
The posted code won't work as is, you need to actually put database modifications to add the permission column for users.
(either that, or you manually add the 'canviewpage_contact' column to your users table)

My Blog
06-05-2010 10:17 PM
Find all posts by this user Quote this message in a reply
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #7
RE: How to add a yes/no option for individual users?
I have added the column by running this query:

PHP Code:
ALTER TABLE `mybb_usergroups` ADD `canviewpage_contact` INT(1) NOT NULL DEFAULT '0'; 


And the option is added at the users but it won''t save when I check the box. Also, I am not sure what array to use for the users when calling the user in my script.

06-05-2010 11:51 PM
Find all posts by this user Quote this message in a reply
RateU Offline
Administrator
*******
Posts: 2,350
Joined: Mar 2010
Post: #8
RE: How to add a yes/no option for individual users?
(06-05-2010 11:51 PM)walkman Wrote:  

PHP Code:
ALTER TABLE `mybb_usergroups` ADD `canviewpage_contact` INT(1) NOT NULL DEFAULT '0'; 


I think you need to add the column in users table.

(06-05-2010 11:51 PM)walkman Wrote:  And the option is added at the users but it won''t save when I check the box.

Maybe something like this:

PHP Code:
1
2
3
4
5
6
function custompages_perms_admin_user_users_edit_commit()
{
	global $mybb, $db, $user;
	
	$db->update_query('users', array('canviewpage_contact' => intval($mybb->input['canviewpage_contact'])), 'uid='.$user['uid']);
}


06-06-2010 07:39 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #9
RE: How to add a yes/no option for individual users?
(06-05-2010 11:51 PM)walkman Wrote:  Also, I am not sure what array to use for the users when calling the user in my script.

PHP Code:
$mybb->user['canviewpage_contact']


My Blog
06-06-2010 09:21 AM
Find all posts by this user Quote this message in a reply
walkman Offline
Junior Member
**
Posts: 36
Joined: May 2010
Post: #10
RE: How to add a yes/no option for individual users?
I feel so stupid. I had forgotten to add the column at the user table. Thank you again Yumi dhe Rateu Smile
06-06-2010 11:23 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: