query('SELECT username FROM '.$db->prefix.'users WHERE username=\''.addslashes($username).'\' OR username=\''.addslashes(preg_replace("/[^\w]/", '', $username)).'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result))
{
$busy = $db->result($result, 0);
message($lang_register['Username dupe 1'].' '.htmlspecialchars($busy).'. '.$lang_register['Username dupe 2']);
}
// Validate e-mail
require 'include/email.php';
if (!is_valid_email($email1))
message($lang_common['Invalid e-mail']);
else if ($options['regs_validate'] == '1' && $email1 != $email2)
message($lang_register['E-mail not match']);
// Check it it's a banned e-mail address
if (is_banned_email($email1))
{
if ($permissions['allow_banned_email'] == '0')
message($lang_prof_reg['Banned e-mail']);
$banned_email = true; // Used later when we send an alert e-mail
}
// Check if someone else already has registered with that e-mail address
$result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE email=\''.$email1.'\'') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
$num_dupes = $db->num_rows($result);
if ($num_dupes > 0 && $permissions['allow_dupe_email'] == '0')
message($lang_prof_reg['Dupe e-mail']);
$hide_email = (isset($_POST['hide_email']) != '1') ? '0' : '1';
$save_pass = (isset($_POST['save_pass']) != '1') ? '0' : '1';
// Insert the new user into the database. We have to do this now to get the last inserted id in order to
// send out an add an alert e-mail with a link to the users profile (phew!)
$now = time();
$intial_status = ($options['regs_validate'] == '0') ? 0 : -1;
// Add the user
$db->query('INSERT INTO '.$db->prefix.'users (username, password, email, hide_email, save_pass, timezone, style, status, registered) VALUES(\''.addslashes($username).'\', \''.md5($password1).'\', \''.$email1.'\', '.$hide_email.', '.$save_pass.', '.$_POST['timezone'].' ,\''.$options['default_style'].'\' ,'.$intial_status.', '.$now.')') or error('Unable to create user', __FILE__, __LINE__, $db->error());
$new_uid = $db->insert_id();
// If we previously found out that the e-mail was banned
if (isset($banned_email) && $options['mailing_list'] != '')
{
$mail_subject = 'Alert - Banned e-mail detected';
$mail_message = 'User "'.$username.'" registered with banned e-mail address: '.$email1."\r\n\r\n".'User profile: '.$options['base_url'].'/profile.php?id='.$new_uid;
$mail_extra = 'From: '.$options['board_title'].' Mailer <'.$options['webmaster_email'].'>';
require 'include/email.php';
pun_mail($options['mailing_list'], $mail_subject, $mail_message, $mail_extra);
}
// If we previously found out that the e-mail was a dupe
if ($num_dupes && $options['mailing_list'] != '')
{
while ($cur_dupe = $db->fetch_assoc($result))
$dupe_list[] = $cur_dupe['username'];
$mail_subject = 'Alert - Duplicate e-mail detected';
$mail_message = 'User "'.$username.'" registered with an e-mail address that also belongs to: '.implode(', ', $dupe_list)."\r\n\r\n".'User profile: '.$options['base_url'].'/profile.php?id='.$new_uid;
$mail_extra = 'From: '.$options['board_title'].' Mailer <'.$options['webmaster_email'].'>';
require_once 'include/email.php';
pun_mail($options['mailing_list'], $mail_subject, $mail_message, $mail_extra);
}
// Must the user validate the registration or do we log him/her in right now?
if ($options['regs_validate'] == '1')
{
$mail_subject = $lang_register['Reg e-mail 1'];
$mail_message = $lang_register['Reg e-mail 2'].' '.$options['base_url'].'/'."\r\n\r\n".$lang_register['Reg e-mail 3'].': '.$username."\r\n".$lang_register['Reg e-mail 4'].': '.$password1."\r\n\r\n".$lang_register['Reg e-mail 5'].' '.$options['base_url'].'/login.php '.$lang_register['Reg e-mail 6']."\r\n\r\n".'/Forum Mailer'."\r\n".'('.$lang_register['Reg e-mail 7'].')';
$mail_extra = 'From: '.$options['board_title'].' Mailer <'.$options['webmaster_email'].'>';
pun_mail($email1, $mail_subject, $mail_message, $mail_extra);
message($lang_register['Reg e-mail 8'].' '.$email1.'. '.$lang_register['Reg e-mail 9'].' '.$options['admin_email'].'.', true);
}
else
{
$expire = ($save_pass != '0') ? $now + 31536000 : 0;
setcookie('punbb_cookie', serialize(array($username, md5($password1), $now, $now, $now)), $expire, $cookie_path, $cookie_domain, $cookie_secure);
}
redirect('index.php', $lang_register['Reg complete']);
}
else
{
$page_title = htmlspecialchars($options['board_title']).' / '.$lang_register['Register'];
$validate_form = true;
$form_name = 'register';
$focus_element = 'req_username';
require 'header.php';
?>