# 
#-----[ COPY ]---------------------------------
#
/root/admin/admin_invites.php            to  /admin/admin_invites.php
/root/templates/admin/admin_invites.tpl  to  /templates/admin/admin_invites.tpl
/root/templates/default/invite.tpl       to  /templates/default/invite.tpl
/root/invite.php                         to  /invite.php


# 
#-----[ SQL QUERY ]---------------------------------
# 
CREATE TABLE `invite_rules` (
	`rule_id` INT(4) unsigned NOT NULL auto_increment,
	`user_rating` INT(4) unsigned NOT NULL default 0,
	`user_age` INT(4) unsigned NOT NULL default 0,
	`invites_count` INT(4) unsigned NOT NULL default 0,
	PRIMARY KEY (`rule_id`)
);
CREATE TABLE `invites` (
	`invite_id` INT(8) unsigned NOT NULL auto_increment,
	`user_id` MEDIUMINT(8) NOT NULL default 0,
	`new_user_id` MEDIUMINT(8) NOT NULL default 0,
	`invite_code` VARCHAR(16) NOT NULL default '',
	`active` ENUM('1','0') default '1',
	`generation_date` INT(10) NOT NULL default '0',
	`activation_date` INT(10) NOT NULL default '0',
	PRIMARY KEY (`invite_id`)
);

# 
#-----[  ]---------------------------------
# 
templates/default/page_header.tpl

#
#-----[  ]--------------------------------
#
<a href="{U_SEARCH_SELF_BY_LAST}">{L_SEARCH_SELF}</a>

#
#-----[ ,  ]---------------------
#
<a href="invite.php"> </a>

# 
#-----[  ]---------------------------------
# 
templates/default/usercp_register.tpl

#
#-----[  ]--------------------------------
#
<span id="check_pass"></span></td>
</tr>

#
#-----[ ,  ]----------------------
#
<!-- IF EDIT_PROFILE -->
<!-- ELSE -->
<tr>
	<td> :<!-- IF $bb_cfg['new_user_reg_only_by_invite'] --> *<br /><small>!<br />       .<br />     ,    .</small><!-- ELSE --><br /><small>      .</small><!-- ENDIF --></td>
	<td><input type="text" name="invite_code" size="35" value="{INVITE_CODE}" /></td>
</tr>
<!-- ENDIF -->


# 
#-----[  ]---------------------------------
# 
config.php

#
#-----[  ]--------------------------------
#
$bb_cfg['new_user_reg_disabled']   = false;        // Disable new user registrations

#
#-----[ ,  ]----------------------
#
$bb_cfg['new_user_reg_only_by_invite']   = true;    // Disable new user registrations 


# 
#-----[  ]---------------------------------
# 
includes/ucp/usercp_register.php

#
#-----[  ]--------------------------------
#
$username = ( !empty($HTTP_POST_VARS['username']) ) ? phpbb_clean_username($HTTP_POST_VARS['username']) : '';

#
#-----[ ,  ]----------------------
#
$invite_code = (!empty($HTTP_POST_VARS['invite_code'])) ? phpbb_clean_username($HTTP_POST_VARS['invite_code']) : '';

#
#-----[  ]--------------------------------
#
	else if ( $mode == 'register' )
	{
		if ( empty($username) || empty($new_password) || empty($password_confirm) || empty($email) )
		{
			$error = TRUE;
			$error_msg .= ( ($error_msg) ? '<br />' : '' ) . $lang['Fields_empty'];
		}

#
#-----[ ,  ]----------------------
#
		if ($bb_cfg['new_user_reg_only_by_invite']) {
			if (empty($invite_code) || $invite_code == '') {
				$error = TRUE;
				$error_msg .= ( ($error_msg) ? '<br />' : '' ) . '    ';
			} else {
				$sql = "SELECT `invite_id` FROM `invites` WHERE `invite_code` = '".$invite_code."' AND `active`='1'";
				if (!($result = $db->sql_query($sql))) message_die(GENERAL_ERROR, '    ', '', __LINE__, __FILE__, $sql);
				$num_row = $db->sql_numrows($result);
				$db->sql_freeresult($result);
				if ($num_row == 0) {
					$error = TRUE;
					$error_msg .= ( ($error_msg) ? '<br />' : '' ) . '        ';
				}
			}
		}

#
#-----[  ]--------------------------------
#
			$user_id = $db->sql_nextid();

#
#-----[ ,  ]----------------------
#
			if ($invite_code != '') {
				$sql = "UPDATE `invites` SET `active`='0', `new_user_id`=".$user_id.", `activation_date`=".time()." WHERE `invite_code`='".$invite_code."'";
				if (!($rrresult = $db->sql_query($sql))) message_die(GENERAL_ERROR, '   ', '', __LINE__, __FILE__, $sql);
				$db->sql_freeresult($rrresult);
			}