/**
	 * finds and accepts a users invites when registered within CB (front and backend)
	 *
	 * @param  moscomprofilerUser $user
	 */
	public function acceptInvites( $user ) {
		$plugin					=	cbgjClass::getPlugin();

		if ( $plugin->params->get( 'group_invites_accept', 1 ) ) {
			$invites			=	cbgjData::getInvites( null, array( 'email', '=', $user->email ) );

			if ( $invites ) foreach ( $invites as $invite ) {
				$invite->set( 'accepted', cbgjClass::getUTCDate() );
				$invite->set( 'user', (int) $user->id );

				if ( $invite->store() ) {
					$row		=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $invite->get( 'group' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

					if ( ! $row->get( 'id' ) ) {
						$row->set( 'user_id', (int) $user->id );
						$row->set( 'group', (int) $invite->get( 'group' ) );
						$row->set( 'date', cbgjClass::getUTCDate() );
						$row->set( 'status', 1 );

						$row->store();
					}
				}

				$notification	=	cbgjData::getNotifications( array( array( 'grp_usr_notifications' ), 'owner' ), array( array( 'type', '=', 'group' ), array( 'item', '=', (int) $invite->get( 'group' ) ), array( 'user_id', '=', (int) $invite->get( 'user_id' ) ), array( 'params', 'CONTAINS', 'group_inviteaccept=1' ) ), null, null, false );

				if ( $notification->get( 'id' ) ) {
					$subject	=	CBTxt::T( '[group_name] - Invite Accepted!' );
					$message	=	CBTxt::T( '[user] has accepted your invite to join [group] in [category]!' );

					cbgjClass::getNotification( $notification->get( 'user_id' ), $invite->get( 'user' ), $subject, $message, 1, $invite->getCategory(), $invite->getGroup() );
				}
			}
		}
	}
	private function getAuto( $user, $rawPassword, $extras, $trigger ) {
		$cbUser									=	new CBuser();

		$cbUser->load( (int) $user->id );

		if ( ( ! isset( $user->gids ) ) || ( isset( $user->gids ) && ( ! is_array( $user->gids ) ) ) ) {
			$gids								=	array( $user->gid );
		} else {
			$gids								=	$user->gids;
		}

		if ( $user->id ) {
			array_unshift( $gids, -3 );

			if ( isModerator( $user->id ) ) {
				array_unshift( $gids, -5 );
			} else {
				array_unshift( $gids, -4 );
			}
		} else {
			array_unshift( $gids, -2 );
		}

		array_unshift( $gids, -1 );

		$access									=	explode( '|*|', $trigger->get( 'access' ) );

		if ( ! array_intersect( $access, $gids ) ) {
			return;
		}

		$conditionals							=	count( explode( "\n", $trigger->get( 'field' ) ) );

		for ( $i = 0, $n = $conditionals; $i < $n; $i++ ) {
			if ( ! cbgjautoClass::getFieldMatch( $user, $cbUser, $extras, cbgjClass::getHTMLCleanParam( true, "field$i", null, null, $trigger->get( 'field' ) ), cbgjClass::getCleanParam( true, "operator$i", null, null, $trigger->get( 'operator' ) ), cbgjClass::getHTMLCleanParam( true, "value$i", null, null, $trigger->get( 'value' ) ) ) ) {
				return;
			}
		}

		$plugin									=	cbgjClass::getPlugin();
		$exclude								=	$trigger->get( 'exclude' );

		if ( $exclude ) {
			cbArrayToInts( explode( ',', $exclude ) );

			$exclude							=	array_unique( $exclude );

			if ( in_array( $user->id, $exclude ) ) {
				return;
			}
		}

		$params									=	$trigger->getParams();

		if ( ( $params->get( 'auto', null ) == 3 ) && $params->get( 'cat_name', null ) ) {
			$owner								=	(int) $cbUser->replaceUserVars( $params->get( 'cat_owner', $user->id ), true, true, $extras );

			if ( ! $owner ) {
				$owner							=	(int) $user->id;
			}

			$parent								=	(int) $params->get( 'cat_parent', 0 );
			$name								=	trim( strip_tags( $cbUser->replaceUserVars( $params->get( 'cat_name', null ), true, true, $extras ) ) );
			$description						=	$cbUser->replaceUserVars( $params->get( 'cat_description', null ), true, true, $extras );

			if ( $params->get( 'cat_unique', 1 ) ) {
				$where							=	array( array( 'user_id', '=', $owner ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) );
			} else {
				$where							=	array( array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) );
			}

			$row								=	cbgjData::getCategories( null, $where, null, null, false );

			if ( ! $row->get( 'id' ) ) {
				$row->set( 'published', 1 );
				$row->set( 'parent', (int) $parent );
				$row->set( 'user_id', $owner );
				$row->set( 'name', $name );

				if ( $plugin->params->get( 'category_editor', 1 ) >= 2 ) {
					$row->set( 'description', cbgjClass::getFilteredText( $description ) );
				} else {
					$row->set( 'description', trim( strip_tags( $description ) ) );
				}

				$row->set( 'access', (int) $plugin->params->get( 'category_access_default', -2 ) );
				$row->set( 'types', $params->get( 'types', $plugin->params->get( 'category_types_default', '1|*|2|*|3' ) ) );
				$row->set( 'create', (int) $plugin->params->get( 'category_create_default', 1 ) );
				$row->set( 'create_access', (int) $plugin->params->get( 'category_createaccess_default', -1 ) );
				$row->set( 'nested', (int) $plugin->params->get( 'category_nested_default', 1 ) );
				$row->set( 'nested_access', (int) $plugin->params->get( 'category_nestedaccess_default', -1 ) );
				$row->set( 'date', cbgjClass::getUTCDate() );
				$row->set( 'ordering', 99999 );

				$row->store();
			}
		} elseif ( ( $params->get( 'auto', null ) == 2 ) && $params->get( 'category', null ) && $params->get( 'grp_name', null ) ) {
			if ( ( $params->get( 'category', null ) == -1 ) && $params->get( 'cat_name', null ) ) {
				$owner							=	(int) $cbUser->replaceUserVars( $params->get( 'cat_owner', $user->id ), true, true, $extras );

				if ( ! $owner ) {
					$owner						=	(int) $user->id;
				}

				$parent							=	(int) $params->get( 'cat_parent', 0 );
				$name							=	trim( strip_tags( $cbUser->replaceUserVars( $params->get( 'cat_name', null ), true, true, $extras ) ) );
				$description					=	$cbUser->replaceUserVars( $params->get( 'cat_description', null ), true, true, $extras );

				if ( $params->get( 'cat_unique', 1 ) ) {
					$where						=	array( array( 'user_id', '=', $owner ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) );
				} else {
					$where						=	array( array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) );
				}

				$category						=	cbgjData::getCategories( null, $where, null, null, false );

				if ( ! $category->get( 'id' ) ) {
					$category->set( 'published', 1 );
					$category->set( 'parent', (int) $parent );
					$category->set( 'user_id', $owner );
					$category->set( 'name', $name );

					if ( $plugin->params->get( 'category_editor', 1 ) >= 2 ) {
						$category->set( 'description', cbgjClass::getFilteredText( $description ) );
					} else {
						$category->set( 'description', trim( strip_tags( $description ) ) );
					}

					$category->set( 'access', (int) $plugin->params->get( 'category_access_default', -2 ) );
					$category->set( 'types', $params->get( 'types', $plugin->params->get( 'category_types_default', '1|*|2|*|3' ) ) );
					$category->set( 'create', (int) $plugin->params->get( 'category_create_default', 1 ) );
					$category->set( 'create_access', (int) $plugin->params->get( 'category_createaccess_default', -1 ) );
					$category->set( 'nested', (int) $plugin->params->get( 'category_nested_default', 1 ) );
					$category->set( 'nested_access', (int) $plugin->params->get( 'category_nestedaccess_default', -1 ) );
					$category->set( 'date', cbgjClass::getUTCDate() );
					$category->set( 'ordering', 99999 );

					$category->store();
				}
			} else {
				$category						=	cbgjData::getCategories( null, array( 'id', '=', (int) $params->get( 'category', null ) ), null, null, false );
			}

			if ( $category->get( 'id' ) ) {
				$owner							=	(int) $cbUser->replaceUserVars( $params->get( 'grp_owner', $user->id ), true, true, $extras );

				if ( ! $owner ) {
					$owner						=	(int) $user->id;
				}

				$parent							=	(int) $params->get( 'grp_parent', 0 );
				$name							=	trim( strip_tags( $cbUser->replaceUserVars( $params->get( 'grp_name', null ), true, true, $extras ) ) );
				$description					=	$cbUser->replaceUserVars( $params->get( 'grp_description', null ), true, true, $extras );
				$join							=	false;

				if ( $params->get( 'grp_unique', 1 ) ) {
					$where						=	array( array( 'category', '=', (int) $category->get( 'id' ) ), array( 'user_id', '=', $owner ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) );
				} else {
					$where						=	array( array( 'category', '=', (int) $category->get( 'id' ) ), array( 'name', '=', $name ), array( 'parent', '=', (int) $parent ) );

					if ( $params->get( 'grp_autojoin', 1 ) ) {
						$join					=	true;
					}
				}

				$row							=	cbgjData::getGroups( null, $where, null, null, false );

				if ( ! $row->get( 'id' ) ) {
					$row->set( 'published', 1 );
					$row->set( 'category', (int) $category->get( 'id' ) );
					$row->set( 'parent', (int) $parent );
					$row->set( 'user_id', $owner );
					$row->set( 'name', $name );

					if ( $plugin->params->get( 'group_editor', 1 ) >= 2 ) {
						$row->set( 'description', cbgjClass::getFilteredText( $description ) );
					} else {
						$row->set( 'description', trim( strip_tags( $description ) ) );
					}

					$row->set( 'access', (int) $plugin->params->get( 'group_access_default', -2 ) );
					$row->set( 'type', (int) $params->get( 'type', $plugin->params->get( 'group_type_default', 1 ) ) );
					$row->set( 'nested', (int) $plugin->params->get( 'group_nested_default', 1 ) );
					$row->set( 'nested_access', (int) $plugin->params->get( 'group_nestedaccess_default', -1 ) );
					$row->set( 'date', cbgjClass::getUTCDate() );
					$row->set( 'ordering', 1 );

					if ( $row->store() ) {
						$row->storeOwner( $row->get( 'user_id' ) );

						if ( $row->get( 'user_id' ) !=  $user->id ) {
							$usr				=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $row->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

							if ( ! $usr->get( 'id' ) ) {
								$usr->set( 'user_id', (int) $user->id );
								$usr->set( 'group', (int) $row->get( 'id' ) );
								$usr->set( 'date', cbgjClass::getUTCDate() );
								$usr->set( 'status', 1 );
								$usr->store();
							}
						}
					}
				} elseif ( $join ) {
					$usr						=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $row->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

					if ( ! $usr->get( 'id' ) ) {
						$usr->set( 'user_id', (int) $user->id );
						$usr->set( 'group', (int) $row->get( 'id' ) );
						$usr->set( 'date', cbgjClass::getUTCDate() );
						$usr->set( 'status', (int) $params->get( 'status', 1 ) );

						if ( $usr->store() ) {
							if ( $usr->get( 'status' ) == 4 ) {
								$row->storeOwner( $usr->get( 'user_id' ) );
							}
						}
					}
				}
			}
		} elseif ( ( $params->get( 'auto', null ) == 1 ) && $params->get( 'groups', null ) ) {
			$groups								=	$params->get( 'groups', null );

			if ( $groups ) {
				$groups							=	explode( '|*|', $groups );

				cbArrayToInts( $groups );
			}

			if ( $groups ) foreach ( $groups as $groupId ) {
				$group							=	cbgjData::getGroups( null, array( 'id', '=', (int) $groupId ), null, null, false );

				if ( $group->get( 'id' ) ) {
					$row						=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $group->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

					if ( ! $row->get( 'id' ) ) {
						$row->set( 'user_id', (int) $user->id );
						$row->set( 'group', (int) $group->get( 'id' ) );
						$row->set( 'date', cbgjClass::getUTCDate() );
						$row->set( 'status', (int) $params->get( 'status', 1 ) );

						if ( $row->store() ) {
							if ( $row->get( 'status' ) == 4 ) {
								$group->storeOwner( $row->get( 'user_id' ) );
							}
						}
					}
				}
			}
		} elseif ( ( $params->get( 'auto', null ) == 4 ) && $params->get( 'groups', null ) ) {
			$groups								=	$params->get( 'groups', null );

			if ( $groups ) {
				$groups							=	explode( '|*|', $groups );

				cbArrayToInts( $groups );
			}

			if ( $groups ) foreach ( $groups as $groupId ) {
				$group							=	cbgjData::getGroups( null, array( 'id', '=', (int) $groupId ), null, null, false );

				if ( $group->get( 'id' ) ) {
					$row						=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $group->get( 'id' ) ), array( 'user_id', '=', (int) $user->id ) ), null, null, false );

					if ( $row->get( 'id' ) && ( $row->get( 'status' ) != 4 ) ) {
						$row->deleteAll();
					}
				}
			}
		}
	}
			$needs_approval		=	true;
		}
	}

	if ( $plugin->params->get( 'group_approve', 0 ) ) {
		$groups					=	count( cbgjData::getGroups( array( array( 'grp_can_publish', 'cat_approved' ), $user, null, true ), array( 'published', '=', 0 ) ) );

		if ( $groups ) {
			$return				.=				'<div><a href="' . cbgjClass::getPluginURL( array( 'groups', 'approval' ) ) . '">' . CBTxt::P( '[groups] pending approval.', array( '[groups]' => cbgjClass::getOverride( 'group', $groups ) ) ) . '</a></div>';

			$needs_approval		=	true;
		}
	}

	$users						=	count( cbgjData::getUsers( array( array( 'mod_lvl4', 'grp_approved' ), $user, null, true ), array( 'status', '=', 0, 'b.type', '=', 2 ) ) );

	if ( $users ) {
		$return					.=				'<div><a href="' . cbgjClass::getPluginURL( array( 'users', 'approval' ) ) . '">' . CBTxt::P( '[users] pending approval.', array( '[users]' => cbgjClass::getOverride( 'user', $users ) ) ) . '</a></div>';

		$needs_approval			=	true;
	}

	if ( class_exists( 'cbgjEventsData' ) ) {
		$events					=	count( cbgjEventsData::getEvents( array( array( 'mod_lvl4', 'grp_approved' ), $user, null, true ), array( 'published', '=', 0, 'c.params', 'CONTAINS', 'events_approve=1' ) ) );

		if ( $events ) {
			$return				.=				'<div><a href="' . cbgjClass::getPluginURL( array( 'plugin', 'events_approval' ) ) . '">' . CBTxt::P( '[events] pending approval.', array( '[events]' => $events . ' ' . ( $events == 1 ? CBTxt::T( 'Event' ) : CBTxt::T( 'Events' ) ) ) ) . '</a></div>';

			$needs_approval		=	true;
		}
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update )
	 * @param  int              $now                Unix time
	 */
	public function onCPayUserStateChange( &$user, $status, /** @noinspection PhpUnusedParameterInspection */ $planId, /** @noinspection PhpUnusedParameterInspection */ $replacedPlanId, &$integrationParams, /** @noinspection PhpUnusedParameterInspection */ $cause, /** @noinspection PhpUnusedParameterInspection */ $reason, /** @noinspection PhpUnusedParameterInspection */ $now ) {
		global $_CB_framework;

		if ( ! is_object( $user ) ) {
			return;
		}

		$api											=	$_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/user/plug_cbgroupjive/cbgroupjive.class.php';

		if ( ! file_exists( $api ) ) {
			return;
		}

		/** @noinspection PhpIncludeInspection */
		require_once( $api );

		$gj_plugin										=	cbgjClass::getPlugin();
		$cbUser											=	CBuser::getInstance( $user->id );

		if ( ! $cbUser ) {
			$cbUser										=	$cbUser->getInstance( null );
		}

		for ( $i = 1; $i <= 5; $i++ ) {
			if ( $status == 'A' ) {
				if ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 3 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					$parent								=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_cat_parent' . $i, '0', null, $integrationParams );
					$name								=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );

					if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
						$where							=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
					} else {
						$where							=	array( array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
					}

					$row								=	cbgjData::getCategories( null, null, $where, null, null, false );

					if ( ! $row->id ) {
						$category_editor				=	$gj_plugin->params->get( 'category_editor', 1 );
						$types							=	cbgjClass::getCleanParam( true, 'cbgj_auto_cat_types' . $i, '1|*|2|*|3', null, $integrationParams );

						$row->published					=	1;
						$row->parent					=	$parent;
						$row->user_id					=	(int) $user->id;
						$row->name						=	$name;

						if ( ( $category_editor == 2 ) || ( $category_editor == 3 ) ) {
							$row->description			=	$cbUser->replaceUserVars( cbgjClass::getHTMLCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
						} else {
							$row->description			=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
						}

						$row->access					=	(int) $gj_plugin->params->get( 'category_access_default', -2 );
						$row->types						=	( $types ? $types : $gj_plugin->params->get( 'category_types_default', '1|*|2|*|3' ) );
						$row->create					=	(int) $gj_plugin->params->get( 'category_create_default', 1 );
						$row->create_access				=	(int) $gj_plugin->params->get( 'category_createaccess_default', -1 );
						$row->nested					=	(int) $gj_plugin->params->get( 'category_nested_default', 1 );
						$row->nested_access				=	(int) $gj_plugin->params->get( 'category_nestedaccess_default', -1 );
						$row->date						=	date( 'Y-m-d H:i:s' );
						$row->ordering					=	99999;

						$row->store();
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 2 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					if ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) == -1 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_name' . $i, null, null, $integrationParams ) ) {
						$parent							=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_parent' . $i, '0', null, $integrationParams );
						$name							=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_name' . $i, null, null, $integrationParams ) );

						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
						} else {
							$where						=	array( array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
						}

						$category						=	cbgjData::getCategories( null, null, $where, null, null, false );

						if ( ! $category->id ) {
							$category_editor			=	$gj_plugin->params->get( 'category_editor', 1 );
							$types						=	cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_types' . $i, '1|*|2|*|3', null, $integrationParams );

							$category->published		=	1;
							$category->parent			=	$parent;
							$category->user_id			=	(int) $user->id;
							$category->name				=	$name;

							if ( ( $category_editor == 2 ) || ( $category_editor == 3 ) ) {
								$category->description	=	$cbUser->replaceUserVars( cbgjClass::getHTMLCleanParam( true, 'cbgj_auto_grp_cat_desc' . $i, null, null, $integrationParams ) );
							} else {
								$category->description	=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_desc' . $i, null, null, $integrationParams ) );
							}

							$category->access			=	(int) $gj_plugin->params->get( 'category_access_default', -2 );
							$category->types			=	( $types ? $types : $gj_plugin->params->get( 'category_types_default', '1|*|2|*|3' ) );
							$category->create			=	(int) $gj_plugin->params->get( 'category_create_default', 1 );
							$category->create_access	=	(int) $gj_plugin->params->get( 'category_createaccess_default', -1 );
							$category->nested			=	(int) $gj_plugin->params->get( 'category_nested_default', 1 );
							$category->nested_access	=	(int) $gj_plugin->params->get( 'category_nestedaccess_default', -1 );
							$category->date				=	date( 'Y-m-d H:i:s' );
							$category->ordering			=	99999;

							$category->store();
						}
					} else {
						$category						=	cbgjData::getCategories( null, null, array( 'id', '=', cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) ), null, null, false );
					}

					if ( $category->id ) {
						$parent							=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_grp_parent' . $i, '0', null, $integrationParams );
						$name							=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );
						$join							=	false;

						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'category', '=', $category->id ), array( 'user_id', '=', $user->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );
						} else {
							$where						=	array( array( 'category', '=', $category->id ), array( 'name', '=', $name ), array( 'parent', '=', $parent ) );

							if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_autojoin' . $i, 1, null, $integrationParams ) ) {
								$join					=	true;
							}
						}

						$row							=	cbgjData::getGroups( null, null, $where, null, null, false );

						if ( ! $row->id ) {
							$group_editor				=	$gj_plugin->params->get( 'group_editor', 1 );
							$type						=	cbgjClass::getCleanParam( true, 'cbgj_auto_grp_type' . $i, 1, null, $integrationParams );

							$row->published				=	1;
							$row->category				=	(int) $category->id;
							$row->parent				=	$parent;
							$row->user_id				=	(int) $user->id;
							$row->name					=	$name;

							if ( ( $group_editor == 2 ) || ( $group_editor == 3 ) ) {
								$row->description		=	$cbUser->replaceUserVars( cbgjClass::getHTMLCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
							} else {
								$row->description		=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_desc' . $i, null, null, $integrationParams ) );
							}

							$row->access				=	(int) $gj_plugin->params->get( 'group_access_default', -2 );
							$row->type					=	(int) ( $type ? $type : $gj_plugin->params->get( 'group_type_default', 1 ) );
							$row->nested				=	(int) $gj_plugin->params->get( 'group_nested_default', 1 );
							$row->nested_access			=	(int) $gj_plugin->params->get( 'group_nestedaccess_default', -1 );
							$row->date					=	date( 'Y-m-d H:i:s' );
							$row->ordering				=	1;

							if ( $row->store() ) {
								$row->storeOwner( $row->user_id );
							}
						} elseif ( $join ) {
							$usr						=	cbgjData::getUsers( null, null, array( array( 'group', '=', $row->id ), array( 'user_id', '=', $user->id ) ), null, null, false );

							if ( ! $usr->id ) {
								$usr->user_id			=	(int) $user->id;
								$usr->group				=	(int) $row->id;
								$usr->date				=	date( 'Y-m-d H:i:s' );
								$usr->status			=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_grp_usr_status' . $i, 1, null, $integrationParams );

								if ( $usr->store() ) {
									if ( $usr->status == 4 ) {
										$row->storeOwner( $usr->user_id );
									}
								}
							}
						}
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 1 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams ) ) {
					$groups								=	cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams );

					if ( $groups ) {
						$groups							=	explode( '|*|', $groups );

						cbArrayToInts( $groups );
					}

					if ( $groups ) foreach ( $groups as $group_id ) {
						$group							=	cbgjData::getGroups( null, null, array( 'id', '=', $group_id ), null, null, false );

						if ( $group->id ) {
							$row						=	cbgjData::getUsers( null, null, array( array( 'group', '=', $group->id ), array( 'user_id', '=', $user->id ) ), null, null, false );

							if ( ! $row->id ) {
								$row->user_id			=	(int) $user->id;
								$row->group				=	(int) $group->id;
								$row->date				=	date( 'Y-m-d H:i:s' );
								$row->status			=	(int) cbgjClass::getCleanParam( true, 'cbgj_auto_usr_status' . $i, 1, null, $integrationParams );

								if ( $row->store() ) {
									if ( $row->status == 4 ) {
										$group->storeOwner( $row->user_id);
									}
								}
							}
						}
					}
				}
			} elseif ( cbgjClass::getCleanParam( true, 'cbgj_auto_remove' . $i, null, null, $integrationParams ) ) {
				if ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 3 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					$name								=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );

					if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
						$where							=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ) );
					} else {
						$where							=	array( 'name', '=', $name );
					}

					$row								=	cbgjData::getCategories( null, null, $where, null, null, false );

					if ( $row->id ) {
						$row->deleteAll();
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 2 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) && cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) ) {
					$name								=	$cbUser->replaceUserVars( cbgjClass::getCleanParam( true, 'cbgj_auto_name' . $i, null, null, $integrationParams ) );

					if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) == -1 ) {
						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'user_id', '=', $user->id ), array( 'name', '=', $name ) );
						} else {
							$where						=	array( 'name', '=', $name );
						}
					} else {
						$category						=	cbgjData::getCategories( null, null, array( 'id', '=', cbgjClass::getCleanParam( true, 'cbgj_auto_grp_cat' . $i, null, null, $integrationParams ) ), null, null, false );

						if ( cbgjClass::getCleanParam( true, 'cbgj_auto_unique' . $i, 1, null, $integrationParams ) ) {
							$where						=	array( array( 'category', '=', $category->id ), array( 'user_id', '=', $user->id ), array( 'name', '=', $name ) );
						} else {
							$where						=	array( array( 'category', '=', $category->id ), array( 'name', '=', $name ) );
						}
					}

					$row								=	cbgjData::getGroups( null, null, $where, null, null, false );

					if ( $row->id ) {
						$row->deleteAll();
					}
				} elseif ( ( cbgjClass::getCleanParam( true, 'cbgj_auto_type' . $i, null, null, $integrationParams ) == 1 ) && cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams ) ) {
					$groups								=	cbgjClass::getCleanParam( true, 'cbgj_auto_usr_groups' . $i, null, null, $integrationParams );

					if ( $groups ) {
						$groups							=	explode( '|*|', $groups );

						cbArrayToInts( $groups );
					}

					if ( $groups ) foreach ( $groups as $group_id ) {
						$group							=	cbgjData::getGroups( null, null, array( 'id', '=', $group_id ), null, null, false );

						if ( $group->id ) {
							$row						=	cbgjData::getUsers( null, null, array( array( 'group', '=', $group->id ), array( 'user_id', '=', $user->id ) ), null, null, false );

							if ( $row->id ) {
								$row->deleteAll();
							}
						}
					}
				}
			}
		}
	}
	/**
	 * prepare invite group user
	 *
	 * @return cbgjUser
	 */
	public function getUser() {
		static $cache	=	array();

		$id				=	$this->get( 'id' );

		if ( ! isset( $cache[$id] ) ) {
			$cache[$id]	=	cbgjData::getUsers( null, array( array( 'group', '=', (int) $this->get( 'group' ) ), array( 'user_id', '=', (int) $this->get( 'user_id' ) ) ), null, null, false );
		}

		return $cache[$id];
	}
	/**
	 * resaves users fixing various issues
	 *
	 * @param string $mode
	 * @param moscomprofilerUser $user
	 * @param object $plugin
	 */
	private function fixUsers( $mode, $user, $plugin ) {
		$users						=	cbgjData::getUsers();

		if ( ! $users ) {
			cbgjClass::getPluginURL( array( 'tools' ), CBTxt::T( 'No users found to fix.' ), false, true, 'error' );
		}

		switch ( $mode ) {
			case 'notifications':
				foreach ( $users as $usr ) {
					$notification	=	cbgjData::getNotifications( null, array( array( 'type', '=', 'group' ), array( 'item', '=', (int) $usr->get( 'group' ) ), array( 'user_id', '=', (int) $usr->get( 'user_id' ) ) ), null, null, false );

					if ( ( ! $notification->get( 'id' ) ) && ( $usr->get( 'status' ) > 0 ) && cbgjClass::hasAccess( 'grp_usr_notifications', cbgjClass::getAuthorization( $usr->getCategory(), $usr->getGroup(), $usr->getOwner() ) ) ) {
						cbgjClass::saveNotifications( $usr->getCategory()->get( 'id' ), $usr->get( 'group' ), $usr->getOwner(), $plugin );
					}
				}
				break;
		}

		cbgjClass::getPluginURL( array( 'tools' ), CBTxt::T( 'Users fixed successfully!' ), false, true );
	}