# 
#-----[ SQL ]------------------------------------------ 
# 
CREATE TABLE phpbb_invitations (
	invitation_id MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT ,
	invitation_code VARCHAR( 8 ) NOT NULL ,
	invitation_description TEXT NOT NULL,
	invitation_uses MEDIUMINT( 8 ) NOT NULL DEFAULT '1',
	invitation_sender MEDIUMINT( 8 ) NOT NULL DEFAULT '0',
	invitation_group MEDIUMINT( 8 ) NOT NULL DEFAULT '0',
	invitation_group_auto_activate TINYINT( 1 ) NOT NULL DEFAULT '0',
	invitation_email TEXT NOT NULL,
	PRIMARY KEY ( invitation_id ) 
);

CREATE TABLE phpbb_invitation_users (
	invitation_id MEDIUMINT( 8 ) NOT NULL,
	user_id MEDIUMINT( 8 ) NOT NULL,	
	PRIMARY KEY ( user_id ) 
);	

INSERT INTO phpbb_config ( config_name , config_value ) 
	VALUES ('invitation_only', '2');
	
INSERT INTO phpbb_config ( config_name , config_value ) 
	VALUES ('invite_u2u', '2');
	
INSERT INTO phpbb_config ( config_name , config_value ) 
	VALUES ('additional_rules', '');
 
INSERT INTO phpbb_config ( config_name , config_value ) 
	VALUES ('send_invit_accept_pm', '1');
	
INSERT INTO phpbb_config ( config_name , config_value ) 
	VALUES ('send_invit_confirm_mail', '1');
 
INSERT INTO phpbb_config ( config_name , config_value ) 
	VALUES ('send_invit_confirm_pm', '1');
	
ALTER TABLE phpbb_users ADD user_invites MEDIUMINT( 8 ) NOT NULL DEFAULT '0';

ALTER TABLE phpbb_groups ADD group_invites MEDIUMINT( 8 ) NOT NULL DEFAULT '0';
	
#
#-----[ OPEN ]------------------------------------------
#
includes/constants.php 
#
#-----[ FIND ]------------------------------------------
#
define('PAGE_TOPIC_OFFSET', 5000);
#
#-----[ AFTER, ADD ]------------------------------------------
#

define('PAGE_INVITE', -1340);
define('INVITATION_TABLE', $table_prefix.'invitations');
define('INVITATION_USER_TABLE', $table_prefix.'invitation_users');
define('POST_INVITES_URL', 'i');

#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_register.php
#
#
#-----[ FIND ]------------------------------------------
#
function show_coppa()
#
#-----[ ]------------------------------------------
#

function show_coppa($invite_code, $email)

#-----[ FIND ]------------------------------------------
#
"U_AGREE_OVER13" => append_sid("profile.$phpEx?mode=register&amp;agreed=true"),
#
#-----[ ]------------------------------------------
#
"U_AGREE_OVER13" => append_sid("profile.$phpEx?mode=register&amp;agreed=true".$invite_code . $email),
#
#-----[ FIND ]------------------------------------------
#
		"U_AGREE_UNDER13" => append_sid("profile.$phpEx?mode=register&amp;agreed=true&amp;coppa=true"))
#
#-----[ ]------------------------------------------
#

"U_AGREE_UNDER13" => append_sid("profile.$phpEx?mode=register&amp;agreed=true&amp;coppa=true" .$invite_code . $email))
#
#-----[ FIND ]------------------------------------------
#
if ( $mode == 'register' && !isset($HTTP_POST_VARS['agreed']) && !isset($HTTP_GET_VARS['agreed']) )
{
	include($phpbb_root_path . 'includes/page_header.'.$phpEx);
#
#-----[ AFTER, ADD ]------------------------------------------
#

	if (!empty($HTTP_GET_VARS['invite'])||!empty($HTTP_POST_VARS['invite']))
	{
		$invite_code = htmlspecialchars((!empty($HTTP_GET_VARS['invite'])) ? $HTTP_GET_VARS['invite'] : $HTTP_POST_VARS['invite']);
		
		$invite_post = "&amp;invite=" .  urlencode($invite_code);
		
	}
	$email = ( !empty($HTTP_GET_VARS['email']) ) ? "&email=" .  urlencode($HTTP_GET_VARS['email']) :  '';
	$email = trim(htmlspecialchars($email));
	if ($board_config['invitation_only'] == 2 && empty($invite_code))
	{
		include($phpbb_root_path . 'includes/functions_invite.'.$phpEx);	    
		show_invitation_only();
	
	}
	else
	{
	 
#
#-----[ FIND ]------------------------------------------
#
show_coppa();
#
#-----[ ]------------------------------------------
#
show_coppa($invite_post, $email);

#
#-----[ FIND ]------------------------------------------
#
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
#
#-----[ BEFORE, ADD ]------------------------------------------
#

}

#
#-----[ FIND ]------------------------------------------
#
			$db->sql_freeresult($result);
		}
	}

#
#-----[ AFTER, ADD ]------------------------------------------
#
	$invite_data = false; 
	if ($board_config['invitation_only'] !=0 && $mode === 'register')
	{
		include($phpbb_root_path . "includes/functions_invite.$phpEx");
		$invitation_code = $_POST['invitation_code'];
		$invitation_code = trim(htmlspecialchars($invitation_code));
		if (empty($invitation_code) && $board_config['invitation_only'] == 2)
		{
			$error = TRUE;
			$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Invitation_code_invalid'];
		}
		if (!empty($invitation_code))
		{
			$invite_data = get_valid_invitation($invitation_code);
			if (!$invite_data)
			{
				$error = TRUE;
				$error_msg .= ( ( isset($error_msg) ) ? '<br />' : '' ) . $lang['Invitation_code_invalid'];
				$invite_data = false; 
			}
		} 
	}

#
#-----[ FIND ]------------------------------------------
#
			$email_template = 'user_welcome';
			}

			include($phpbb_root_path . 'includes/emailer.'.$phpEx);			 
#
#-----[ AFTER, ADD ]------------------------------------------
#

			if ($board_config['invitation_only'] && !empty($invite_data) )
			{  
				use_invite($invite_data, $user_id, $username);
			}


#
#-----[ FIND ]------------------------------------------
#
		$template->assign_block_vars('switch_confirm', array());
	}
#
#-----[ AFTER, ADD ]------------------------------------------
#

	if (!empty($board_config['invitation_only']) && $mode == 'register')
	{
		$template->assign_block_vars('switch_invitation_only', array());
		$invitation_code = ( isset($HTTP_GET_VARS['invite']) ) ? trim($HTTP_GET_VARS['invite']) : ((isset($invitation_code)) ? $invitation_code : ''  ) ;
		$invitation_code = htmlspecialchars($invitation_code); 
		$email = ( isset($HTTP_GET_VARS['email']) ) ? trim($HTTP_GET_VARS['email']) : ((isset($email)) ? $email : ''  ) ;
		$email = htmlspecialchars($email); 
		$template->assign_vars(array(
			'INVITATION' => $invitation_code, 
			'L_INVITATION' => $lang['Invitation'],
			'L_INVITATION_EXPLAIN' => ($board_config['invitation_only']==1)? $lang['Invitation_optional'] : $lang['Invitation_mandantory'],
			'INVITATION_REQUIRED' => ($board_config['invitation_only']==2)? '*' : ''
		)); 
	}  
#
#-----[ OPEN ]------------------------------------------
#
includes/page_header.php
#
#-----[ FIND ]------------------------------------------
#
$l_timezone = (count($l_timezone) > 1 && $l_timezone[count($l_timezone)-1] != 0) ? $lang[sprintf('%.1f', $board_config['board_timezone'])] : $lang[number_format($board_config['board_timezone'])];
#
#-----[ AFTER, ADD ]------------------------------------------
#

if ( $userdata['session_logged_in']  && ($board_config['invite_u2u']))
{
	if ($board_config['invite_u2u'] == 2 || ($board_config['invite_u2u'] == 1 && $userdata['user_invites']))
	{
		if (!$userdata['user_invites'])
		{
			$invites_text = $lang['No_invites'];	   
		} 
		elseif ($userdata['user_invites'] == 1)
		{
			$invites_text = $lang['One_invite_left'];	   
		}
		else
		{
			$invites_text = $userdata['user_invites'];	  
		} 
		 
		$template->assign_block_vars('switch_show_invites', array());
		$template->assign_vars(array(
			'L_INVITE_FRIEND' => $lang['Invite_a_friend'],
			'INVITES_LEFT' => $invites_text,
			'U_INVITE' => append_sid("invite.$phpEx",true)
		));
	}
}

#
#-----[ OPEN ]------------------------------------------
#
templates/index_body.tpl 
#
#-----[ FIND ]------------------------------------------
#
- <a href="{U_VIEWONLINE}">{TOTAL_USERS_ONLINE}</a><br/>
#
#-----[ AFTER, ADD ]------------------------------------------
#

						<!-- BEGIN switch_show_invites -->
- <a href="{U_INVITE}">{L_INVITE_FRIEND} ({INVITES_LEFT})</a><br/>
<!-- END switch_show_invites -->
#
#-----[ OPEN ]------------------------------------------
#
templates/profile_add_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<!-- END switch_confirm --> 
#
#-----[ AFTER, ADD ]------------------------------------------
#

	<!-- BEGIN switch_invitation_only -->
	<tr>
<td class="row1">{L_INVITATION}: {INVITATION_REQUIRED}<br />{L_INVITATION_EXPLAIN}<br/>
<input type="text" class="post" style="width: 200px" name="invitation_code" size="8" maxlength="8" value="{INVITATION}" /></td>
	</tr>
	<!-- END switch_invitation_only -->
#
#-----[ OPEN ]------------------------------------------
#
admin/admin_users.php
# 
#-----[ FIND ]------------------------------------------
#
			$sql = "SELECT g.group_id 
#
#-----[ BEFORE, ADD ]------------------------------------------
#
			include($phpbb_root_path . 'includes/functions_invite.'.$phpEx);	    
			delete_user_invites($user_id);
#			
#-----[ FIND ]------------------------------------------
#
		$user_allowavatar = ( !empty($HTTP_POST_VARS['user_allowavatar']) ) ? intval( $HTTP_POST_VARS['user_allowavatar'] ) : 0;
#
#-----[ AFTER, ADD ]------------------------------------------
#

		$user_invites = ( !empty($HTTP_POST_VARS['user_invites']) ) ? intval( $HTTP_POST_VARS['user_invites'] ) : 0;
#
#-----[ FIND ]------------------------------------------
#
				SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) .  
#
#-----[ IN-LINE FIND ]------------------------------------------
#
$avatar_sql . "
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
, user_invites = $user_invites
#
#-----[ FIND ]------------------------------------------
#
			'L_SELECT_RANK' => $lang['Rank_title'],
#
#-----[ AFTER, ADD ]------------------------------------------
#

			'L_INVITES' => $lang['Invites'],
			'INVITES' => $this_userdata['user_invites'],
#
#-----[ OPEN ]------------------------------------------
#
templates/admin/user_edit_body.tpl
#
#-----[ FIND ]------------------------------------------
#
	<select name="user_rank">{RANK_SELECT_BOX}</select></td>
	</tr>
#
#-----[ AFTER, ADD ]------------------------------------------
#

	<tr> 
	  <td class="row1">{L_INVITES}<br/>
		<input class="post" type="text" name="user_invites" size="5" maxlength="5" value="{INVITES}" />
	  </td>
	</tr>

#
#-----[ OPEN ]------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
	include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx);
#
#-----[ AFTER, ADD ]------------------------------------------
#

		include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_invites.' . $phpEx);
#
#-----[ FIND ]------------------------------------------
#
		include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx);
#
#-----[ AFTER, ADD ]------------------------------------------
#
			include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_invites_admin.' . $phpEx);
