MyBB Community Forums

Full Version: Make Plugin Add To "Additional Groups" Instead of Overwriting "Primary Group"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good evening people,

I am using the mySubscription plugin and it works wonderfully with one single exception. Since the plugin support forum has not had any support responses since Q3 2012 I am not hopeful my request there will bear fruit; therefore I am seeking help here as well.

Basically what this plugin does is take money via paypal and assign the member to a myBB group. It does this wonderfully, but it overrides the Primary Usergroup which is not what I want at all.

I have attached the php file in question, but the area I believe I need to change is isolated in the code section below. As you can see there is an if statement commented out that checks if the group is allowed to purchase the sub in question; since this was malfunctioning and not allowing all groups to buy I commented it out which fixed that problem, but lead to the exposure of the primary group overwrite problem. If I can get this fixed the plugin should work nicely for me.

if($txn_type == 'WEB_ACCEPT') // This is the txn type we want (for now). Any other type should be considered unhandled.
		{
			$item_number = $db->escape_string($ipn_data['item_number']);
			$query = $db->simple_select('mysubs', '*', "`item_number`='{$item_number}'");
			if($db->num_rows($query) > 0)
			{
				$item = $db->fetch_array($query);
				$price = unserialize($item['price']);
				$custom = unserialize(base64_decode($ipn_data['custom']));
				$uid = intval($custom['uid']);
				$user = get_user($uid);
				if($user)
				{
					$gid = intval($user['usergroup']);
					if($price[$custom['po']]['c'] == $ipn_data['mc_gross'])
					{
						$accepted_gid = true;
						/* if($sub['accepted_gids'] != 'all')
						{
							$gids = explode(',', $user['additionalgroups']);
							$gids[] = $user['usergroup'];
							$matched = array_intersect($gids, explode(',', $sub['accepted_gids']));
							if(empty($matched)) $accepted_gid = false;
						} */
						if($accepted_gid)
						{
							$base_time = TIME_NOW;
							if($gid == intval($item['new_group']))
							{
								$notif_result = $db->simple_select('mysubs_notifs', '*', "`uid` = {$user['uid']} AND `active` = 1", array('limit' => 1));
								if($notif_result && $db->num_rows($notif_result) > 0)
								{
									$notif = $db->fetch_array($notif_result);
									$base_time = intval($notif['expiration']);
									$gid = $notif['old_gid'];
								}
							}
							$update_data = array(
								'usergroup' => intval($item['new_group'])
							);
							$result = $db->update_query('users', $update_data, "`uid`=$uid");
							if($result)
							{
								$db->update_query('mysubs_notifs', array('active' => 0), "`uid` = {$user['uid']}");
								if(intval($price[$custom['po']]['l']) < 1) $expiration_time = 0;
								else
								{
									$lt = 1;
									switch($price[$custom['po']]['lt'])
									{
										case 'm':
											$lt = 30;
										break;
										
										case 'y':
											$lt = 365;
										break;
										
										case 'd':
										default:
										break;
									}
									$expiration_time = intval($base_time + (60 * 60 * 24 * $lt * intval($price[$custom['po']]['l'])));
								}
								$insert_data = array(
									'uid' => intval($custom['uid']),
									'item_number' => $db->escape_string($ipn_data['item_number']),
									'expiration' => $expiration_time,
									'email' => $db->escape_string($ipn_data['payer_email']),
									'time' => time(),
									'success' => 1,
									'active' => 1,
									'old_gid' => $gid,
									'new_gid' => intval($item['new_group']),
									'txn_type' => $db->escape_string($ipn_data['txn_type']),
									'ipn_data' => $db->escape_string($ipn_serialized)
								);
								$db->insert_query('mysubs_notifs', $insert_data);
							}
							else
							{
								// For some reason the user's group was not updated properly.
								handle_unknown($ipn_data, $txn_type, $ipn_serialized, 'ERROR_UPDATING_USERGROUP');
							}
						}
						else
						{
							// User not allowed to purchase this item.
							handle_unknown($ipn_data, $txn_type, $ipn_serialized, 'USERGROUP_FORBIDDEN');
						}
					}
					else
					{
						// Incorrect price, log this.
						handle_unknown($ipn_data, $txn_type, $ipn_serialized, 'INCORRECT_GROSS');
					}
				}
				else
				{
					// User doesn't exist.
					handle_unknown($ipn_data, $txn_type, $ipn_serialized, 'UNKNOWN_USER');
				}
			}
			else
			{
				// Item doesn't exist in our records.
				handle_unknown($ipn_data, $txn_type, $ipn_serialized, 'ITEM_NOT_FOUND');
			}
		}
		else
		{
			// This isn't currently a supported transaction type.
			handle_unknown($ipn_data, $txn_type, $ipn_serialized, 'TXN_NOT_SUPPORTED');
		}
	}

Any help would be appreciated, I did check the documentation but I am so far out of my depth it's not funny.



Afterthought: Would altering this change how I need to remove from group at the end of a subscription tenure? Or does the same code for removing primary extend to additional groups?
I unapproved the attachment - which plugin is this? Is it the one from Pirata? if so he provides support for subscribers on his site.
No it's by EthanD

http://mods.mybb.com/view/mysubscriptions

My apologies if the php file violated some rule