Groups on Registration and Custom Profile Fields

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in the Customisations Database.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTICE: This forum is only for the announcement of new releases and/or updates of MODs. Any MOD support should be obtained through the Customisations Database in the support area designated for each MOD.

A direct link to support for each MOD is in the first post of the respective topic.
Locked
User avatar
nims
Registered User
Posts: 310
Joined: Sun Aug 13, 2006 12:29 pm
Contact:

Re: Groups on Registration and Custom Profile Fields

Post by nims »

Ok done manually.

Now I need to understand few more things (sorry to be a pain)
I want to divide the members of my forum in two categories viz. Buyers and Sellers. Buyers will have different set of permissions like - allowed to start new topic in sellers forum and buyers will only have permission to reply the threads in sellers forum but they can start a new topic in buyers forum etc.
How can I provide an option during registration to choose the particular group. The thing to note here is that I don't want a person to be member of both the groups. They should not be able to change their group.

Can you help please.
Outsource content writing - Freelance Content Writers
*** Everything related to kids - Kids ***
SEO- search engine optimisation melbourne
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

Create a custom profile group and display at registration

Buy-Sell:
    • ?
      Buyers
      Sellers
Also, create two groups at ACP groups pages and make them closed groups, so users cannot change groups

Users are added to closed groups as pending; to automatically add them, ignore pending at
ACP -> Groups based on custom profile fields option -> Add usesr to hidden or closed groups without pending


----------
If you prefer manually approving pending groups members, you may prefer Groups on registration option
I abandoned all of my mods.
User avatar
nims
Registered User
Posts: 310
Joined: Sun Aug 13, 2006 12:29 pm
Contact:

Re: Groups on Registration and Custom Profile Fields

Post by nims »

Ok done but there is one problem.
I have custom profile field with 5 options and corressponding to that I have 4 closed groups. I want two options in custom profile field to go in one particular group. How can that be done.
Outsource content writing - Freelance Content Writers
*** Everything related to kids - Kids ***
SEO- search engine optimisation melbourne
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

Sorry, you can't do that, mod is designed to assign one custom profile fields to only one group.
I abandoned all of my mods.
myles.oneill
Registered User
Posts: 33
Joined: Sun Jan 03, 2010 11:49 am

Re: Groups on Registration and Custom Profile Fields

Post by myles.oneill »

Hi, firstly thanks for the great mod - its perfect for what I need on my forum.

I was wondering if you'd help me with an extension of the mod. Basically I have modified my posting.php file to allow users to change one of their custom profile fields. This custom profile field is connected to a group using your mod - however when I change the field using the posting function it doesn't change the group.

Is there any code I can add to posting.php which will allow me to re-sync that user (or the whole board if need be)?

I tried adding the lines:

Code: Select all

//Begin: Group on Registration and Custom Profile Fields 
include($phpbb_root_path . 'includes/functions_group_on_regs.' . $phpEx);
//End: Group on Registration and Custom Profile Fields 
and then after changing the custom profile field:

Code: Select all

group_add_delete_user_cpf($victim_id);
Where $victim_id is the user_id of the player needing to be changed.

However this did not work.

Any help would be awesome.
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

The edits in includes/functions_profile_fields.php should be similar to do what you need.
How/where do you allow your users to change one of their custom profile fields at posting.php?
If you share your code changes, I may take a look.
I abandoned all of my mods.
myles.oneill
Registered User
Posts: 33
Joined: Sun Jan 03, 2010 11:49 am

Re: Groups on Registration and Custom Profile Fields

Post by myles.oneill »

Hi, I'm happy to share what I've done.
For a bit of context my mod is part of changes to my whole board to let it function for the tag-game Humans vs Zombies, so the gist of it is that someone posts to "report a kill" and in doing so it causes the player tagged to switch teams (ie. groups).

I'm using it in conjunction with this mod: http://www.phpbb.com/community/viewtopi ... 0&t=869265
(so that I can have normal forum posting too).

Here is the core change to posting.php (starting from roughly line 600, right after:

Code: Select all

if ($submit || $preview || $refresh)
{
	$post_data['topic_cur_post_id']	= request_var('topic_cur_post_id', 0);
	$post_data['post_subject']		= utf8_normalize_nfc(request_var('subject', '', true));
	$message_parser->message		= utf8_normalize_nfc(request_var('message', '', true));
The part of most importance to this question are the three comments which say "// Change Victim's group" , these are where I need the code to make your mod re-sync the user. The user field is changed under: "// Change Profile Field Data of Victim".

Code: Select all

	if ($post_data['enable_sts'] == TRUE && ($mode == 'post'))
	{
		$user->add_lang('mods/ticket');
		
		// PART 1 : Get Variables
		
			// Variables that may need to modified in later games:
				// You may need to change the place the code calls for things like fullname, gamestatus etc. if you change the fields. (which you shouldn't!)
				
				// Change the following value to whatever the id of the forum used for kills in the game will be.
				$kill_forum = 23;
			
			// Data from report kill form
			$killcode = utf8_normalize_nfc(request_var('killcode', '', true ));
				if ($killcode == NULL) { $error[] = "Error: You have not entered a \"Victim's Code\"!"; } else {
			$daykilled = utf8_normalize_nfc(request_var('daykilled', '', true ));
			$hourkilled = utf8_normalize_nfc(request_var('hourkilled', '', true ));
			
			// Data from user posting (killer)
			$user->get_profile_fields($user->data['user_id']);
				$killer_name = ($user->profile_fields['pf_fullname']);
			
			// Data from killcode nominated user (victim)
			$sql = 'SELECT pf_fullname, pf_gamestatus, pf_overallsurvival, user_id
                FROM ' . PROFILE_FIELDS_DATA_TABLE . "
                WHERE pf_secretcode = '" . $db->sql_escape($killcode) . "'";
       		$result = $db->sql_query($sql);
			$row = $db->sql_fetchrow($result);
				$victim_id = $row['user_id'];
				$victim_name = $row['pf_fullname'];
				$victim_status = $row['pf_gamestatus'];
				$victim_overallsurvival = $row['pf_overallsurvival'];
		
			// Get Number of Kill
			$sql = 'SELECT forum_topics
					FROM ' . FORUMS_TABLE . "
					WHERE forum_id = $db->sql_escape($kill_forum)"; // Modify this to include variable for kill forum
			$result = $db->sql_query($sql);
			$row = $db->sql_fetchrow($result);
				$kill_number = ($row['forum_topics']) + 1;
		
		// PART 2 : Create Second Order Variables [Note: Kill variables under Zombie poster, for higher preformance]
		
			// Kill Hour
			$kill_hour = 'Error: No time specified.';
				if ($hourkilled < '13') {
					$kill_hour = $hourkilled . ' AM';
				}
				else {
					$kill_hour = ($hourkilled - 12) . ' PM';
				}

			// Kill Day
			$kill_day = 'Error: No day specified.';
				if ($daykilled == '1') {
					$kill_day = 'Monday (Day 1)';
				}
				else if ($daykilled == '2') {
					$kill_day = 'Tuesday (Day 2)';
				}
				else if ($daykilled == '3') {
					$kill_day = 'Wednesday (Day 3)';
				}
				else if ($daykilled == '4') {
					$kill_day = 'Thursday (Day 4)';
				}
				else if ($daykilled == '5') {
					$kill_day = 'Friday (Day 5)';
				}	
				else {
					$kill_day = 'Saturday (Day 6)';
				}
	
			// Survival Time
			$survival_time = ((24*$daykilled) + $hourkilled - 24);
			$overall_survival_time = $victim_overallsurvival + $survival_time;
			
        // Stuff I don't understand ^.^     
		$message		= utf8_normalize_nfc(request_var('message', '', true));
		$anti_support_message = utf8_normalize_nfc(request_var('message', '', true));
		$messagetemp = '';
		
		// PART 3: Four Different Computations Depending on Who is Reporting the Kill
		
		
		
		//-------------------- Human (Report a death mode) --------------------//
		if (($user->profile_fields['pf_gamestatus']) == 2)
			{
				// Check to see if user entered the correct secret code. (ie. Their own).
				if (($user->profile_fields['pf_secretcode']) != $killcode) {
					$error[] = "Error: You are a human, thus you are assumed to be posting your own death, however the \"Victim's Code\" you entered was not your own, please try again and make sure your code is correctly entered. If it still doesn't work, ask a mod for help.";
				}
				// Check to make sure the killer is also the victim, this should always be true
				else if ($killer_name != $victim_name) {
					$error[] = "Error: Something went horribly wrong! Please tell the mods you got a database error while reporing your kill";
				}
				else {
				
				// Change Profile Field Data of Victim
					$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . "
						SET pf_gamestatus 		= 3,
							pf_survivaltime 	= $db->sql_escape($survival_time),
							pf_overallsurvival 	= $db->sql_escape($overall_survival_time),
							pf_killedby			= $db->sql_escape('Unknown'),
							pf_kills			= 0
						WHERE pf_secretcode = $db->sql_escape($killcode)";
					$db->sql_query($sql);
					
				// Change Victim's group

				
				// Post the Kill message
					// Subject
					$post_data['post_subject']		= utf8_normalize_nfc("Kill #" . $kill_number . " - " . $victim_name . " was killed.");
					
					// Message
					$messagetemp .= "[size=120][b]" . $victim_name. "[/b] died at [b]" . $kill_hour . " [/b] on [b]" . $kill_day .  "[/b][/size].\n";
					$messagetemp .= $victim_name . " had survived " . $survival_time .  " hours. \n \n";
					$messagetemp .= "This player has reported their own death because their killer did not report it within 3 hours of the kill. \n \n";
					$messagetemp .= "[b]Kill Description:[/b] (Written by the Human) \n \n";
					$messagetemp .= "[hr][/hr]" . $message;
					$message_parser->message = $messagetemp;
				}
		}
			
		//-------------------- Zombie (Report a kill mode) --------------------//	
		else if (($user->profile_fields['pf_gamestatus']) == 3)
			{
				// Check to see if the killcode matches any players and if not give an error
				if ($victim_name == NULL)
					{
						$error[] = "Error: The \"Victim's Code\" you have entered does not match any player in the game, please try again and make sure your code is correctly entered. If it still doesn't work, ask a mod for help.";
					}
				// Check to see if the victim is a human and if not give an error
				else if ($victim_status != 2) 
					{
						$error[] = "Error: The \"Victim's Code\" you have entered matches a player, but that player is not a human! It is possible the player has reported themselves because you took too long (more than 3 hours after the kill was made). Try to register kills more quickly in the future - it sucks having to wait for your killer to report you. If you think there is some error involved here try entering the code again or contacting a moderator.";
					}
				else {
					
				// Compute Kills
				$kills = ($user->profile_fields['pf_kills']);
					if ($kills == NULL) { $kills = 0; }
				$overall_kills = ($user->profile_fields['pf_overallkills']);
					if ($overallkills == NULL) { $overallkills = 0; }
					
				$new_kills = $kills + 1;
				$new_overall_kills = $overall_kills + 1;
				
				// Change Profile Field Data of Victim
				$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . "
					SET pf_gamestatus 		= 3,
						pf_survivaltime 	= $db->sql_escape($survival_time),
						pf_overallsurvival 	= $db->sql_escape($overall_survival_time),
						pf_killedby			= $db->sql_escape($killer_name),
						pf_kills			= 0
					WHERE pf_secretcode = $db->sql_escape($killcode)";
				$db->sql_query($sql);
				
				// Change Victim's group

				
				// Change Profile Field Data of Zombie
				$user_id = $user->data['user_id'];
				$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . "
					SET pf_kills 			= $db->sql_escape($new_kills),
						pf_overallkills		= $db->sql_escape($new_overall_kills)
					WHERE user_id = $db->sql_escape($user_id)";
				$db->sql_query($sql);
				
				// Post the Kill message
					// Subject
					$post_data['post_subject']		= utf8_normalize_nfc("Kill #" . $kill_number . " - " . $killer_name . " killed " . $victim_name);

					// Message
					$messagetemp .= "[size=120][b]" . $killer_name . "[/b]  killed [b]" . $victim_name . "[/b] at [b]" . $kill_hour . " [/b] on [b]" . $kill_day .  "[/b][/size]. \n";
					$messagetemp .= $victim_name . " had survived " . $survival_time .  " hours. \n";
					$messagetemp .= $killer_name . " has now killed " . $new_kills .  " humans. \n \n";
					$messagetemp .= "[b]Kill Description:[/b] (Written by the Zombie) \n \n";
					$messagetemp .= "[hr][/hr]" . $message;
					$message_parser->message = $messagetemp;
				}
		}
		
		//-------------------- Moderator (Report a death on behalf of someone) --------------------//
		else if (($user->profile_fields['pf_gamestatus']) == 4)		
			{
				// Check to see if the killcode matches any players and if not give an error
				if ($human_name == NULL)
					{
						$error[] = "Error: The \"Victim's Code\" you have entered does not match any player in the game, please try again and make sure your code is correctly entered. If it still doesn't work, ask a mod for help.";
					}
				// Check to see if the victim is a human and if not give an error
				else if ($human_status != 2) 
					{
						$error[] = "Error: The \"Victim's Code\" you have entered matches a player, but that player is not a human! It is possible the player has reported themselves because you took too long (more than 3 hours after the kill was made). Try to register kills more quickly in the future - it sucks having to wait for your killer to report you. If you think there is some error involved here try entering the code again or contacting a moderator.";
					}
				else {
				
				// Change Profile Field Data of Victim
					$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . "
						SET pf_gamestatus 		= 3,
							pf_survivaltime 	= $db->sql_escape($survival_time),
							pf_overallsurvival 	= $db->sql_escape($overall_survival_time),
							pf_killedby			= $db->sql_escape('Unknown'),
							pf_kills			= 0
						WHERE pf_secretcode = $db->sql_escape($killcode)";
					$db->sql_query($sql);
					
				// Change Victim's group


				// Post the Kill message
					// Subject
					$post_data['post_subject']		= utf8_normalize_nfc("Kill #" . $kill_number . " - " . $victim_name . " was killed.");

					// Message
					$messagetemp .= "[size=120][b]" . $victim_name . "[/b] died at [b]" . $kill_hour . " [/b] on [b]" . $kill_day .  "[/b][/size]. \n \n";
					$messagetemp .= $victim_name . " had survived " . $survival_time .  " hours. \n \n";
					$messagetemp .= "A moderator has reported this player's death because their killer did not report it within 3 hours of the kill. \n \n";
					$messagetemp .= "[b]Kill Description:[/b] (Written by the Moderator) \n";
					$messagetemp .= "[hr][/hr]" . $message;
					$message_parser->message = $messagetemp;
				}
		}

		//-------------------- Non-player, This should never get called due to permissions --------------------//	
		else
			{
				$error[] = "Error: You are not playing in this game! If you think you should be playing and there is a problem, contact the moderators.";
			}
		}
	}
	
Also I should mention I am using phpbb 3.0.5 and the compatible version of your mod (1.0.0 RC5). Thanks for any help you can give - it'd be much appreciated.
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

In your code above

Find (three times, line 109, 159 and 210)

Code: Select all

                      WHERE pf_secretcode = $db->sql_escape($killcode)";
                   $db->sql_query($sql);
Add after

Code: Select all

					//Begin: Group on Registration and Custom Profile Fields
					if ($config['groups_to_cpf_enable'])
					{	
						if (!function_exists('group_add_delete_user_cpf'))
						{
							include($phpbb_root_path . 'includes/functions_group_on_regs.' . $phpEx);
						}
						group_add_delete_user_cpf($user_id);
					}								
					//End: Group on Registration and Custom Profile Fields
If any cpf data changes, this code is used to update custom profile fields based groups for the the $user_id. Test this way and add thsi code to any independent cases. You may need to to add extra code to obtain actual user_id value. It is needed for my function.
I abandoned all of my mods.
myles.oneill
Registered User
Posts: 33
Joined: Sun Jan 03, 2010 11:49 am

Re: Groups on Registration and Custom Profile Fields

Post by myles.oneill »

Hmmm, I'm still having problems but I can't work out why.

I put in all the code as you mentioned, then tested it and it didn't work.

I then looked into testing the if statements in your addition, the second one is never called but I don't think thats a problem. The first is called (ie. groups to cpf are enabled) so the line must be being called.

I also checked the user_id and confirmed that the right one was being sent to it, which it was.

Do you have any other suggestions? Maybe if I was to take the code out of the function itself and include it in the file?
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

The function is in included function file, make sure it is called. Test by chaning a relevant cpf value and see if the function is called. You can manually enter user_id value instead, for test purposes. Replace $user_id with 1111 for instance.
I abandoned all of my mods.
myles.oneill
Registered User
Posts: 33
Joined: Sun Jan 03, 2010 11:49 am

Re: Groups on Registration and Custom Profile Fields

Post by myles.oneill »

Hey, I did some more investigating and found out that it was in fact working - but it was doing the wrong thing!

What I found out is that the script managed to consistently change the user who was tagged (ie. the one who is meant to be changed) into the user group from the person posting the tag. This is what lead to the difference in usergroups seen.

So for example when a "human" tags another "human" the human they tag is set to a "Zombie" (correct) but their group remains at "Human" - matching the person who tagged them.

Do you have any idea why this error might be occurring?
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

Code: Select all

            // Change Profile Field Data of Zombie
            $user_id = $user->data['user_id'];
That is because of this code, function uses the user_id of actual poster.
You would need to enter correct user_id to function.
Such as,

Code: Select all

$user_id = request_var('user_id', 0);
add this to posting.php
also add the relevant in html file to take the input.
Or you can obtain correct user_id in your codes, if that was already provided.
I abandoned all of my mods.
User avatar
nims
Registered User
Posts: 310
Joined: Sun Aug 13, 2006 12:29 pm
Contact:

Re: Groups on Registration and Custom Profile Fields

Post by nims »

In ref to my earlier request above ... I have a dropdown custom profile field with 5 options that I want to map to 4 groups. Is that possible?

One more thing - I noticed a message - "Please note that, editing a custom profile field can reset group options."
So does that mean once I setup the "Groups based on custom profile fields" and then add one custom profile field that has nothing to do with the settings of groups etc. will the settings of this MOD still reset ?
Outsource content writing - Freelance Content Writers
*** Everything related to kids - Kids ***
SEO- search engine optimisation melbourne
mtrs
Registered User
Posts: 2049
Joined: Sat Sep 22, 2007 2:39 pm

Re: Groups on Registration and Custom Profile Fields

Post by mtrs »

nims wrote:In ref to my earlier request above ... I have a dropdown custom profile field with 5 options that I want to map to 4 groups. Is that possible?
http://www.phpbb.com/community/viewtopi ... #p11695095
mtrs wrote:Sorry, you can't do that, mod is designed to assign one custom profile fields to only one group.
nims wrote:One more thing - I noticed a message - "Please note that, editing a custom profile field can reset group options."
So does that mean once I setup the "Groups based on custom profile fields" and then add one custom profile field that has nothing to do with the settings of groups etc. will the settings of this MOD still reset ?
Yes. It is due ot how custom profile fields data table works. CPF based groups settings are kept in cpf tables.
I abandoned all of my mods.
tiyakap
Registered User
Posts: 300
Joined: Fri May 29, 2009 4:01 pm

Re: Groups on Registration and Custom Profile Fields

Post by tiyakap »

I made two groups boys and girls on the basis of CPF male and female.
the groups are hidden. I have two forums one for girls and other for boys. I want boys to have access in boys section only not in girls vice versa. So how do i set the permissions so that users divide in two groups i.e. boys and girls on registration and have permissions accordingly?
Locked

Return to “[3.0.x] MOD Database Releases”