Bad Boy Blog, an unofficial Diddy and Bad Boy fan blog

Bookmark and Share

group_request.txt not filled in

Are you looking for a specific phpBB hack? Please post your request here. This is also where hack authors can develop new hacks (please read the guidelines first) and discuss development in general.

group_request.txt not filled in

Postby CarolC » February 18th 2013, 12:43 am

This is in reference to my earlier topic

request-to-join-group-while-registering-vt79869.html

but I didn't know if my question would be seen if I posted there because of the anti-double post mod (or whatever makes today's post show up in yesterday's post).

I thought I could get functions_group_on_regs.php to fill in the missing information on group_request.txt. but so far I have not. The email is sending, but this part of

Code: Select all
The user "{REQUEST_USERNAME}" has requested to join the group "{GROUP_NAME}" you moderate on "{SITENAME}."


is being sent as

Code: Select all
The user "Anonymous" has requested to join the group "" you moderate on
"mysite.net".


It has to be this code in functions_group_on_regs.php

Code: Select all
$messenger->assign_vars(array(
				'USERNAME'			=> htmlspecialchars_decode($row['username']),
				'GROUP_NAME'		=> htmlspecialchars_decode($group_row['group_name']),
				'REQUEST_USERNAME'	=> $user->data['username'],


but I can't see where the disconnect is. The email is sent properly filled in when the user requests to join through the ucp, it is sent blank when they request to join on the registration screen.

Can anyone tell me what I am missing?

Thanks. :oops:
CarolC
Well Known User
 
Posts: 194
Joined: March 11th 2007, 9:40 pm

Re: group_request.txt not filled in

Postby Thoul » February 18th 2013, 11:08 pm

Okay, it looks like the username is not being passed to the function at all, so we need a query to fetch that and fill it in. In functions_group_on_regs.php, find this code, which was added during the other topic:
Code: Select all
		$group_row = $row;
		global $phpbb_root_path, $phpEx;
		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
		$messenger = new messenger();

After that, add this:
Code: Select all
		$sql = 'SELECT username FROM ' . USERS_TABLE . '
				WHERE user_id = ' . (int) $user_id;
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);
		$request_username = $row['username'];


Then, in the code you posted from this file above, change this line:
Code: Select all
'REQUEST_USERNAME'	=> $user->data['username'],

to:
Code: Select all
'REQUEST_USERNAME'	=> htmlspecialchars_decode($request_username),


And that should get the username into the e-mail correctly.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Re: group_request.txt not filled in

Postby CarolC » February 19th 2013, 2:42 am

Thanks for your reply.

I'm sorry, I'm posting the whole file here. Maybe it's me. Unbelievably, still getting the email with Anonymous for the username and empty quotes for the group name.
1) started with an unedited file and redid the edits
2) verified again it does send filled-in email if I request to join from the ucp
3) verified I refreshed the templates and purged the cache after uploading and before testing
4) verified the uploaded file is the freshly edited file


Code: Select all
<?php
/**
*
* @package phpBB3
* @author mtrs
* @version $Id: functions_group_on_reg.php 1.0.1 2009-11-21 16:53:36Z mtrs $
* @copyrigh(c) 2009 mtrs
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit();
}

function group_on_registration()
{
	//We obtain the list of groups, which are not special, for registration screen
	global $db, $user, $config, $template;
	$user->setup('mods/group_on_regs');

	$sql = 'SELECT group_id, group_name
		FROM ' . GROUPS_TABLE . '
		WHERE group_type <> ' . GROUP_SPECIAL . '
			AND display_on_registration = 1';
	$result = $db->sql_query($sql);

	$group_id = 0;
	$s_group_multi_options = '';
	$s_group_options = '<option value=""  selected="selected">--</option>';
		
	while ($row = $db->sql_fetchrow($result))
	{
		$group_id = $row['group_id'];
		$group_name = $row['group_name'];
		$s_group_options .= "<option value=\"$group_id\">$group_name</option>";
		$s_group_multi_options .= "<input id=\"$group_name\" type=\"checkbox\" name=\"reg_group_id[]\" value=\"$group_id\" /><label for=\"$group_name\">$group_name</label><br />";
	}
	$db->sql_freeresult($result);
	
	if (isset($group_id))
	{
		$template->assign_vars(array(
			'S_GROUP_OPTIONS'				=> $s_group_options,
			'S_GROUP_MULTIPLE_OPTIONS'		=> $s_group_multi_options,
			'S_GROUPS_ON_REGISTRATION'		=> ($config['groups_on_reg_enable'] && $group_id) ? true : false,
			'S_GROUPS_ON_REG_MULTIPLE'		=> ($config['groups_on_reg_multiple']) ? true : false,
			'GROUPS_REGISTRATION_EXP'		=> ($config['groups_on_reg_multiple']) ? $user->lang['GROUPS_MULTIPLE_ON_REGISTRATION'] : $user->lang['GROUPS_ONE_ON_REGISTRATION'],
			'S_GROUPS_REQUIRED'				=> ($config['groups_require']) ? true : false,
		));
	}
		
}

function reg_group_select($reg_group_id)
{
	global $db, $template, $config;

	//We save the selected group option, to return in case there is any error
	$s_group_options = (empty($reg_group_id)) ? '<option value=""  selected="selected">--</option>' : '<option value=""  >--</option>';
	
	$sql = 'SELECT group_id, group_name
		FROM ' . GROUPS_TABLE . '
		WHERE group_type <> ' . GROUP_SPECIAL . '
			AND display_on_registration = 1';
	$result = $db->sql_query($sql);

	$group_id = 0;
	$selected = 'selected="selected"';
	$s_group_multi_options = '';
		
	while ($row = $db->sql_fetchrow($result))
	{
		$group_id = $row['group_id'];
		$group_name = $row['group_name'];

		$s_group_options .= ($group_id == $reg_group_id) ? "<option value=\"$group_id\" $selected>$group_name</option>" : "<option value=\"$group_id\">$group_name</option>";
		if ($config['groups_on_reg_multiple'])
		{
			$checked = (in_array($group_id, $reg_group_id)) ? "checked = \"checked\"" : '';
			$s_group_multi_options .= "<input id=\"$group_name\" type=\"checkbox\"$checked name=\"reg_group_id[]\" value=\"$group_id\" /><label for=\"$group_name\">$group_name</label><br />";	
		}
	}
	$db->sql_freeresult($result);
		
	$template->assign_vars(array(
		'S_GROUP_OPTIONS'				=> $s_group_options,
		'S_GROUP_MULTIPLE_OPTIONS'		=> $s_group_multi_options,
		'S_GROUPS_ON_REGISTRATION'		=> ($config['groups_on_reg_enable'] && $group_id) ? true : false,
	));
	
	return ($config['groups_on_reg_multiple']) ? $s_group_multi_options : $s_group_options;
}

function group_add_registration($user_id, $reg_group_id)
{
	//At the end, we add user to a group and update default group settings
	global $db, $user, $config;
	$user->add_lang('mods/group_on_regs');
	
	//Begin: Select Group on Registration	
	if (isset($reg_group_id))
	{
		$sql = 'SELECT group_id, group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $reg_group_id . '
				AND group_type = ' . GROUP_FREE;
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);
		
		$pending = 1;
		if ($row)
		{
			$pending = 0;
		}
	
		//We add user to a new group selected on registration
		$sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array(
			'user_id'		=> (int) $user_id,
			'group_id'		=> (int) $reg_group_id,
			'user_pending'	=> $pending)
		);
		$db->sql_query($sql);
				$group_row = $row;
		global $phpbb_root_path, $phpEx;
		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
		$messenger = new messenger();
				$sql = 'SELECT username FROM ' . USERS_TABLE . '
				WHERE user_id = ' . (int) $user_id;
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);
		$request_username = $row['username'];

		$sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang
			FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . " u
			WHERE ug.user_id = u.user_id
				AND ug.group_leader = 1
				AND ug.group_id = $reg_group_id";
		$result = $db->sql_query($sql);

		while ($row = $db->sql_fetchrow($result))
		{
			$messenger->template('group_request', $row['user_lang']);

			$messenger->to($row['user_email'], $row['username']);
			$messenger->im($row['user_jabber'], $row['username']);

			$messenger->assign_vars(array(
				'USERNAME'			=> htmlspecialchars_decode($row['username']),
				'GROUP_NAME'		=> htmlspecialchars_decode($group_row['group_name']),
				'REQUEST_USERNAME'	=> htmlspecialchars_decode($request_username),

				'U_PENDING'		=> generate_board_url() . "/ucp.$phpEx?i=groups&mode=manage&action=list&g=$group_id",
				'U_GROUP'		=> generate_board_url() . "/memberlist.$phpEx?mode=group&g=$group_id")
			);

			$messenger->send($row['user_notify_type']);
		}
		$db->sql_freeresult($result);

		$messenger->save_queue();

		//Set group if enabled
		if ($config['groups_default'] && !$config['groups_on_reg_multiple'] && !$pending)
		{
			group_set_user_default($reg_group_id, array($user_id), false);
			
			// set the newest user colour to default group colour
			$sql = 'SELECT user_colour
				FROM ' . USERS_TABLE . '
				WHERE user_id = ' . (int) $user_id . '
					AND user_type = ' . USER_NORMAL;
			$result = $db->sql_query_limit($sql, 1);
			$row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);
			
			if ($row['user_colour'])
			{
				set_config('newest_user_colour', $row['user_colour'], true);
			}
		}
	}
}

//Add or delete users to/from groups based on custom profile fields - on registration only add user to gruop if correct option is selected
function group_add_delete_user_cpf($user_id)
{
	global $db, $user, $config, $phpbb_root_path, $phpEx;

	if (!function_exists('group_user_add'))
	{
		include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
	}
	$user_id_ary = array($user_id);
	$group_default = false;
	
	$sql_where = ($config['groups_to_cpf_no_pending']) ? 'WHERE group_type IN (' . GROUP_FREE . ', ' . GROUP_CLOSED . ', ' . GROUP_HIDDEN . ')' : 'WHERE group_type = ' . GROUP_FREE;

	$sql = 'SELECT group_id
		FROM ' . GROUPS_TABLE . '
		' . $sql_where;
	$result = $db->sql_query($sql);

	$groups_free = array();
	while ($row = $db->sql_fetchrow($result))
	{
		$groups_free[] = $row['group_id'];
	}
	$db->sql_freeresult($result);
	
	$user->get_profile_fields($user_id);
	$user_fields = $user->profile_fields;
	
	//Obtain custom profile fields based group names
	$sql = 'SELECT l.lang_value, l.group_id, l.group_name, l.option_id, f.field_name
		FROM ' . PROFILE_FIELDS_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
		WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
			AND l.group_id <> 0
			AND l.field_type = ' . FIELD_DROPDOWN . '
			AND l.field_id = f.field_id
		GROUP BY l.group_id';
	$result = $db->sql_query($sql);

	while ($row = $db->sql_fetchrow($result))
	{
		if (isset($user_fields['pf_' . $row['field_name']]))
		{
			if ($user_fields['pf_' . $row['field_name']] == ($row['option_id'] + 1))
			{
				$pending = (in_array($row['group_id'], $groups_free)) ? 0 : 1;
				group_user_add($row['group_id'], $user_id_ary, false, $row['group_name'], $group_default, 0, $pending, false);
			}
			else if (request_var('mode', '') != 'register')
			{
				group_user_del($row['group_id'], $user_id_ary, false, $row['group_name']);
			}
		}
	}
	$db->sql_freeresult($result);	
	
	return;
}

function validate_reg_group_id($num, $optional = false, $min = 0, $max = 1E99)
{
	global $user, $config;
	$user->setup('mods/group_on_regs');
	
	if (empty($num) && $optional)
	{
		return false;
	}
	if ($config['groups_on_reg_multiple'] && empty($num))
	{
		return $user->lang['SHOULD_SELECT_GROUPS'];
	}		
	else if ($num < $min && !$config['groups_on_reg_multiple'])
	{
		return $user->lang['SHOULD_SELECT_GROUP'];
	}

	return false;
}
?>
CarolC
Well Known User
 
Posts: 194
Joined: March 11th 2007, 9:40 pm

Re: group_request.txt not filled in

Postby Thoul » February 19th 2013, 9:38 am

Hm. The code looks correct to me. I'll have to test it myself and do some debugging on it. I'll see if I can do that sometime tonight.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Re: group_request.txt not filled in

Postby CarolC » February 19th 2013, 12:06 pm

Thank you so much. :)
CarolC
Well Known User
 
Posts: 194
Joined: March 11th 2007, 9:40 pm

Re: group_request.txt not filled in

Postby Thoul » February 21st 2013, 12:15 am

Okay, testing revealed that apparently the registering user's name can't be pulled from the database at this point. To work around it, we'll have to pass the username in from a calling file. In includes/ucp/ucp_register.php (or your special registration file you mentioned a few posts back, if you're using that instead), you'll need to find this block of code:
Code: Select all
						foreach ($data['reg_group_id'] as $add_group_id)
						{
							//Add user to the selected groups
							group_add_registration($user_id, $add_group_id);
						}
					}
					else
					{
						group_add_registration($user_id, $data['reg_group_id']);

Change it to this:
Code: Select all
						foreach ($data['reg_group_id'] as $add_group_id)
						{
							//Add user to the selected groups
							group_add_registration($user_id, $data['username'], $add_group_id);
						}
					}
					else
					{
						group_add_registration($user_id, $data['username'], $data['reg_group_id']);


Then in functions_group_on_reg.php, replace the group_add_registration function with this code below. The rest of that file is fine, so you only need to replace this one function. The group name and username should both appear correctly in the e-mail as well at this point; at least they did in my test.
Code: Select all
function group_add_registration($user_id, $request_username, $reg_group_id)
{
	//At the end, we add user to a group and update default group settings
	global $db, $user, $config;
	$user->add_lang('mods/group_on_regs');

	//Begin: Select Group on Registration
	if (isset($reg_group_id))
	{
		$sql = 'SELECT group_id, group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $reg_group_id . '
				AND group_type = ' . GROUP_FREE;
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		$pending = 1;
		if ($row)
		{
			$pending = 0;
		}

		//We add user to a new group selected on registration
		$sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array(
			'user_id'		=> (int) $user_id,
			'group_id'		=> (int) $reg_group_id,
			'user_pending'	=> $pending)
		);
		$db->sql_query($sql);

		$group_row = $row;
		global $phpbb_root_path, $phpEx;
		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
		$messenger = new messenger();

		$sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang
			FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . " u
			WHERE ug.user_id = u.user_id
				AND ug.group_leader = 1
				AND ug.group_id = $reg_group_id";
		$result = $db->sql_query($sql);

		while ($row = $db->sql_fetchrow($result))
		{
			$messenger->template('group_request', $row['user_lang']);

			$messenger->to($row['user_email'], $row['username']);
			$messenger->im($row['user_jabber'], $row['username']);

			$messenger->assign_vars(array(
				'USERNAME'			=> htmlspecialchars_decode($row['username']),
				'GROUP_NAME'		=> htmlspecialchars_decode($group_row['group_name']),
				'REQUEST_USERNAME'	=> htmlspecialchars_decode($request_username),

				'U_PENDING'		=> generate_board_url() . "/ucp.$phpEx?i=groups&mode=manage&action=list&g=$reg_group_id",
				'U_GROUP'		=> generate_board_url() . "/memberlist.$phpEx?mode=group&g=$reg_group_id")
			);

			$messenger->send($row['user_notify_type']);
		}
		$db->sql_freeresult($result);

		$messenger->save_queue();

		//Set group if enabled
		if ($config['groups_default'] && !$config['groups_on_reg_multiple'] && !$pending)
		{
			group_set_user_default($reg_group_id, array($user_id), false);

			// set the newest user colour to default group colour
			$sql = 'SELECT user_colour
				FROM ' . USERS_TABLE . '
				WHERE user_id = ' . (int) $user_id . '
					AND user_type = ' . USER_NORMAL;
			$result = $db->sql_query_limit($sql, 1);
			$row = $db->sql_fetchrow($result);
			$db->sql_freeresult($result);

			if ($row['user_colour'])
			{
				set_config('newest_user_colour', $row['user_colour'], true);
			}
		}
	}
}
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Re: group_request.txt not filled in

Postby CarolC » February 21st 2013, 9:54 pm

Yes, the username is filling in now.

First I want to tell you BIG thank you for all the help here. I am sure this has gone beyond what anyone would expect for a support question. As far as I can tell, you have pretty much written half a mod on the fly. I don't know if it took 20 minutes or 5 hours, I suspect the latter is closer. I am sure you had to install the mod, write the code, test it with email, probably test it again, and again, and testing email notifications is time consuming. You have been so generous with your time and talent, and this never would have gotten done otherwise, because it is way beyond anything I could have done.

I am still having an issue with the group name not being filled in. Since it worked on your board, it is probably either something I have done wrong installing it, or there were differences in my files to begin with.

I tried taking a break and coming back to it fresh and remodding the files again but got the same result.

I decided:

1) the moderators do not need the group name as we are only dealing with one usergroup
2) I could hide it by removing the group name from the notification, though that doesn't fix anything
3) I do want to get it working because I always have a bit of uneasiness when something is a little off...but it is not an emergency

I would like to send you a feedback later when this is in use to explain exactly how it is being used. I hope you will think it was worth it. :)
CarolC
Well Known User
 
Posts: 194
Joined: March 11th 2007, 9:40 pm

Re: group_request.txt not filled in

Postby Thoul » February 24th 2013, 10:24 am

Well, it didn't take quite that long and I cheated a little bit with the e-mail by printing the message before it was sent. ;) It is nice to be appreciated though, so thank you. :) I would be happy to hear how this is being used, if you want to share that, but that's up to you of course. I never pry on details of that nature.

When it comes to the group name, the only other thing I can think of that would prevent that from appearing is the configuration of the group type. Do you have the group configured as a Request group? You can check this by managing the group in the Administration Control Panel. If not, change this bit of code from my last post:
Code: Select all
		$sql = 'SELECT group_id, group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $reg_group_id . '
				AND group_type = ' . GROUP_FREE;

to look like this:
Code: Select all
		$sql = 'SELECT group_id, group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $reg_group_id;

You may also need to remove this to continue requiring a moderator's approval of group members:
Code: Select all
		if ($row)
		{
			$pending = 0;
		}
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Re: group_request.txt not filled in

Postby CarolC » February 24th 2013, 8:37 pm

Thoul wrote:Well, it didn't take quite that long and I cheated a little bit with the e-mail by printing the message before it was sent. ;) It is nice to be appreciated though, so thank you. :) I would be happy to hear how this is being used, if you want to share that, but that's up to you of course. I never pry on details of that nature.

I'm glad it didn't take as long as it might have. I will let you know about the setup, as soon as I can. :)

When it comes to the group name, the only other thing I can think of that would prevent that from appearing is the configuration of the group type. Do you have the group configured as a Request group? You can check this by managing the group in the Administration Control Panel. If not, change this bit of code from my last post:
Code: Select all
		$sql = 'SELECT group_id, group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $reg_group_id . '
				AND group_type = ' . GROUP_FREE;

to look like this:
Code: Select all
		$sql = 'SELECT group_id, group_name
			FROM ' . GROUPS_TABLE . '
			WHERE group_id = ' . $reg_group_id;


Yes, I'm afraid the dot is on Request in the acp.

I don't know if it makes a difference but I used Group_on_Registration_and_Custom_Profile_Fields_v1.0.2. They still have v1.0.1 in the main download link on the site, version 1.0.2 is in a post further down in the support topic. I don't know if that would make any difference, in the post it sounds like there was little change. I started to compare the files of the two versions in WinMerge, but didn't do them all. The main file, functions_group_on_regs.php, was identical in both versions. If you used version 1.0.1, I would be glad to try that. I don't care which version it is as long as it works. And again, we can use it without the group filled in, I would just prefer not to have any loose ends. Thanks!


You may also need to remove this to continue requiring a moderator's approval of group members:
Code: Select all
		if ($row)
		{
			$pending = 0;
		}
Last edited by CarolC on February 24th 2013, 10:06 pm, edited 1 time in total.
CarolC
Well Known User
 
Posts: 194
Joined: March 11th 2007, 9:40 pm

Re: group_request.txt not filled in

Postby Thoul » February 24th 2013, 8:47 pm

I did use version 1.0.1, but after looking at 1.0.2 I don't think that would make any difference. It appears none of the code was changed in 1.0.2. That version only mentions updating the install instructions for compatibility with more recent phpBB releases.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Next

Return to phpBB 3 Hack Requests and Development

Who is online

Users browsing this forum: No registered users and 0 guests