Файл: soc-set/reg.php
Строк: 269
<?php
require_once('core/start.php');
if (isset($_GET['ref'])) {
$id = abs(num($_GET['ref']));
$ank = DB::$dbs->queryFetch("SELECT * FROM ".USERS." WHERE `user_id` = ?",array($id));
if (!empty($ank)) {
$_SESSION['ref'] = $ank['user_id'];
}
}
function GetRef () {
if (!empty($_SESSION['ref'])) {
echo DIV_BLOCK . 'Мой реферал: ' . user_choice(num($_SESSION['ref']), 'link') . CLOSE_DIV;
}
}
switch ($select) {
default:
head('Регистрация. Шаг 1');
GetRef ();
echo DIV_TITLE . '<b>Шаг 1:</b> Укажите фамилию и имя:' . CLOSE_DIV;
if ($_POST) {
$surname = html($_POST['surname']);
$name = html($_POST['name']);
$gender = num($_POST['gender']);
if (empty($surname) || empty($name)) {
$err .= 'Заполните все поля<br />';
}
if (strlen($surname) < 2) {
$err .= 'Слишком короткая фамилия. [Min. 2 символа]<br />';
}
if (strlen($name) < 2) {
$err .= 'Слишком короткое имя. [Min. 2 символа]<br />';
}
$_SESSION['surname'] = $surname;
$_SESSION['name'] = $name;
$_SESSION['gender'] = $gender;
if ($err) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
header("Location: reg/2");
}
}
echo '<form action="'.HOME.'/reg" method="POST">';
echo DIV_AUT . '<b>Фамилия:</b><br /><input type="text" name="surname" value="'.(!empty($_SESSION['surname']) ? html($_SESSION['surname']) : NULL).'" /><br /><br />';
echo '<b>Имя:</b><br /><input type="text" name="name" value="'.(!empty($_SESSION['name']) ? html($_SESSION['name']) : NULL).'" /><br /><br />';
echo '<input type="radio" name="gender" value="0" '.($_SESSION['gender'] == 0 ? 'checked="checked"' : NULL).' /> Женский<br /><input type="radio" name="gender" value="1" '.($_SESSION['gender'] == 1 ? 'checked="checked"' : NULL).' /> Мужской<br /><br />';
echo '<input type="submit" name="submit" value="Продолжить" />' . CLOSE_DIV;
echo '</form>';
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <b>Регистрация</b>' . CLOSE_DIV;
break;
case '2':
if (empty($_SESSION['surname']) || empty($_SESSION['name'])) {
header("Location: reg");
}
GetRef ();
head('Регистрация. Шаг 2');
echo DIV_TITLE . '<b>Шаг 2:</b> Укажите E-Mail и пароль:' . CLOSE_DIV;
if ($_POST) {
$nick = html($_POST['nick']);
$email = html($_POST['email']);
$password = html($_POST['password']);
$password2 = html($_POST['password2']);
if (empty($nick) || empty($password)) {
$err .= 'Заполните все поля<br />';
}
if(!preg_match("/^[A-Za-z0-9]+[-_]*[A-Za-z0-9]+$/", $nick)) {
$err .= 'Укажите ник в верном формате<br />';
}
if (DB::$dbs->querySingle("SELECT COUNT(`user_id`) FROM ".USERS." WHERE `nick` = ?", array($nick)) == TRUE) {
$err .= 'Данный Ник уже зарегистрирован на сайте<br />';
}
if (strlen($password) < 6) {
$err .= 'Слишком короткий пароль. [Min. 6 символов]<br />';
}
if ($password != $password2) {
$err .= 'Пароли не совпадают.<br />';
}
$_SESSION['nick'] = $nick;
$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
if ($err) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
header("Location: ".HOME."/reg/3");
}
}
echo '<form action="'.HOME.'/reg/2" method="POST">';
echo DIV_AUT . '
<b>Ник:</b><br /><input type="text" name="nick" value="'.(!empty($_SESSION['nick']) ? html($_SESSION['nick']) : NULL).'" /><br /><br />
<b>E-Mail:</b> [не обязательно]<br /><input type="text" name="email" value="'.(!empty($_SESSION['email']) ? html($_SESSION['email']) : NULL).'" /><br /><br />';
echo '<b>Пароль:</b><br /><input type="password" name="password" /><br /><br />';
echo '<b>Повторите пароль:</b><br /><input type="password" name="password2" /><br /><br />';
echo '<input type="submit" name="submit" value="Продолжить" />' . CLOSE_DIV;
echo '</form>';
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/reg">1-й шаг</a> / <b>2-й шаг</b>' . CLOSE_DIV;
break;
case '3':
if (empty($_SESSION['nick']) || empty($_SESSION['surname']) || empty($_SESSION['name']) || empty($_SESSION['password'])) {
header("Location: reg");
}
head('Регистрация. Шаг 3');
echo DIV_TITLE . '<b>Шаг 3:</b> Выберите место жительства:' . CLOSE_DIV;
if (isset($_GET['country'])) {
if (DB::$dbs->querySingle("SELECT COUNT(`country_id`) FROM ".COUNTRY." WHERE `country_id` = ?", array(num($_GET['country']))) == TRUE) {
echo $_GET['country'];
$_SESSION['country'] = num($_GET['country']);
header("Location: ".HOME."/reg/4");
} else {
echo DIV_ERROR . 'Страна не найдена в базе данных' . CLOSE_DIV;
}
}
echo DIV_AUT . 'Страна...' . CLOSE_DIV . DIV_AUT;
$all = DB::$dbs->querySingle("SELECT COUNT(`country_id`) FROM ".COUNTRY."");
$n = new Navigator($all,15,'select=3');
$sql = DB::$dbs->query("SELECT * FROM ".COUNTRY." LIMIT {$n->start()}, 15");
while($country = $sql -> fetch()) {
echo ' - <a href="'.HOME.'/reg/3?country='.$country['country_id'].'">'.$country['name'].'</a><br />';
}
echo CLOSE_DIV;
echo $n->navi();
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/reg">1-й шаг</a> / <a href="'.HOME.'/reg">2-й шаг</a> / <b>3-й</b> шаг (Выбор страны)' . CLOSE_DIV;
break;
case '4':
if (empty($_SESSION['nick']) || empty($_SESSION['surname']) || empty($_SESSION['name']) || empty($_SESSION['password']) || empty($_SESSION['country'])) {
header("Location: reg");
}
head('Регистрация. Шаг 3');
echo DIV_TITLE . '<b>Шаг 3:</b> Выберите место жительства:' . CLOSE_DIV;
if (isset($_GET['region'])) {
if (DB::$dbs->querySingle("SELECT COUNT(`region_id`) FROM ".REGION." WHERE `region_id` = ?", array(num($_GET['region']))) == TRUE) {
$_SESSION['region'] = num($_GET['region']);
header("Location: ".HOME."/reg/5");
} else {
echo DIV_ERROR . 'Регион не найден в базе данных' . CLOSE_DIV;
}
}
$country = DB::$dbs->queryFetch("SELECT `name` FROM ".COUNTRY." WHERE `country_id` = ? LIMIT 1",array(num($_SESSION['country'])));
echo DIV_AUT . '<b>'.$country['name'].'</b> / Регион...' . CLOSE_DIV . DIV_AUT;
$all = DB::$dbs->querySingle("SELECT COUNT(`region_id`) FROM ".REGION." WHERE `country_id` = ?", array(num($_SESSION['country'])));
$n = new Navigator($all,15,'select=4');
$sql = DB::$dbs->query("SELECT * FROM ".REGION." WHERE `country_id` = ? LIMIT {$n->start()}, 15", array(num($_SESSION['country'])));
while($region = $sql -> fetch()) {
echo ' - <a href="'.HOME.'/reg/4?region='.$region['region_id'].'">'.$region['name'].'</a><br />';
}
echo CLOSE_DIV;
echo $n->navi();
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/reg">1-й шаг</a> / <a href="'.HOME.'/reg">2-й шаг</a> / <b>3-й</b> шаг (Выбор региона)' . CLOSE_DIV;
break;
case '5':
if (empty($_SESSION['nick']) || empty($_SESSION['surname']) || empty($_SESSION['name']) || empty($_SESSION['password']) || empty($_SESSION['country']) || empty($_SESSION['region'])) {
header("Location: reg");
}
head('Регистрация. Шаг 3');
echo DIV_TITLE . '<b>Шаг 3:</b> Выберите место жительства:' . CLOSE_DIV;
if (isset($_GET['city'])) {
if (DB::$dbs->querySingle("SELECT COUNT(`city_id`) FROM ".CITY." WHERE `city_id` = ?", array(num($_GET['city']))) == TRUE) {
$_SESSION['city'] = num($_GET['city']);
header("Location: ".HOME."/reg/6");
} else {
echo DIV_ERROR . 'Город не найден в базе данных' . CLOSE_DIV;
}
}
$country = DB::$dbs->queryFetch("SELECT `name` FROM ".COUNTRY." WHERE `country_id` = ? LIMIT 1",array(num($_SESSION['country'])));
$region = DB::$dbs->queryFetch("SELECT `name` FROM ".REGION." WHERE `region_id` = ? LIMIT 1",array(num($_SESSION['region'])));
echo DIV_AUT . '<b>'.$country['name'].'</b> / <b>'.$region['name'].'</b> / Город...' . CLOSE_DIV . DIV_AUT;
$all = DB::$dbs->querySingle("SELECT COUNT(`city_id`) FROM ".CITY." WHERE `region_id` = ?", array(num($_SESSION['region'])));
$n = new Navigator($all,15,'select=5');
$sql = DB::$dbs->query("SELECT * FROM ".CITY." WHERE `region_id` = ? LIMIT {$n->start()}, 15", array(num($_SESSION['region'])));
while($city = $sql -> fetch()) {
echo ' - <a href="'.HOME.'/reg/5?city='.$city['city_id'].'">'.$city['name'].'</a><br />';
}
echo CLOSE_DIV;
echo $n->navi();
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/reg">1-й шаг</a> / <a href="'.HOME.'/reg">2-й шаг</a> / <b>3-й</b> шаг (Выбор города)' . CLOSE_DIV;
break;
case '6':
head('Регистрация. Шаг 4');
echo DIV_TITLE . '<b>Шаг 4:</b> Завершение регистрации' . CLOSE_DIV;
if ($_POST['final']) {
$surname = html($_SESSION['surname']);
$name = html($_SESSION['name']);
$nick = html($_SESSION['nick']);
$email = html($_SESSION['email']);
$password = md5($_SESSION['password']);
$gender = num($_SESSION['gender']);
$country = num($_SESSION['country']);
$region = num($_SESSION['region']);
$city = num($_SESSION['city']);
if (empty($nick)) {
header("Location: ".HOME."/index.php");
exit();
}
$ref = (!empty($_SESSION['ref']) ? abs(num($_SESSION['ref'])) : 0);
if (DB::$dbs->query("INSERT INTO ".USERS." (`nick`, `email`, `password`, `surname`, `name`, `gender`, `city`, `recording_date`, `balls`, `ref`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", array($nick, $email, $password, $surname, $name, $gender, $city, time(), 500, $ref))) {
$_SESSION['user_id'] = DB::$dbs->lastInsertId();
unset($_SESSION['surname']);
unset($_SESSION['name']);
unset($_SESSION['nick']);
unset($_SESSION['email']);
unset($_SESSION['password']);
unset($_SESSION['gender']);
unset($_SESSION['country']);
unset($_SESSION['region']);
unset($_SESSION['city']);
unset($_SESSION['ref']);
/* Сообщение при регистрации */
if (!empty($sett['reg_user']) && !empty($sett['reg_msg'])) {
DB::$dbs->query("INSERT INTO ".DIALOG." SET `user_id` = ?, `friend_id` = ? ",array($sett['reg_user'], abs(num($_SESSION['user_id']))));
$last = DB::$dbs->lastInsertId();
DB::$dbs->query("INSERT INTO ".DIALOG_MSG." (`user`,`user_friend`,`msg`,`time`,`status`,`dialog_id`, `delet`) VALUE (?,?,?,?,?,?,?) ",array($sett['reg_user'], abs(num($_SESSION['user_id'])), $sett['reg_msg'], time(), 1, $last, 'no'));
}
/* Подарок при регистрации */
if (!empty($sett['reg_user']) && !empty($sett['reg_present'])) {
$gender = user_choice($sett['reg_user'], 'gender');
$lenta = '<a href="'.HOME.'/id'.$sett['reg_user'].'"><b>' . user_choice($sett['reg_user'], 'nick') . '</b></a> прислал'.(empty($gender) ? 'a' : NULL).' Вам <a href="'.HOME.'/present/list/'.abs(num($_SESSION['user_id'])).'/"><b>подарок</b></a>';
lenta($lenta, abs(num($_SESSION['user_id'])));
DB::$dbs->query("INSERT INTO ".PRESENTS_LIST." SET `present_id` = ?, `user_id` = ?, `friend_id` = ?, `anonim` = ?, `comm` = ?, `time` = ? ", array($sett['reg_present'], $sett['reg_user'], abs(num($_SESSION['user_id'])), 0, 'Добро пожаловать, на наш сайт :-)', time()));
}
header("Location: ".HOME."/page");
} else {
echo DIV_ERROR . 'Возникла ошибка при регистрации' . CLOSE_DIV;
}
}
if ($_POST['restart']) {
unset($_SESSION);
header("Location: ".HOME."/index.php");
}
echo DIV_AUT . '<form action="'.HOME.'/reg/6" method="POST">';
echo '<input type="submit" name="final" value="Завершить регистрацию" />';
echo '<input type="submit" name="restart" value="Начать заново" />';
echo '</form>' . CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/reg">1-й шаг</a> / <a href="'.HOME.'/reg">2-й шаг</a> / <a href="'.HOME.'/reg">3-й</a> / <b>Завершение регистрации</b>' . CLOSE_DIV;
break;
}
require_once('core/stop.php');
?>