<?php
$template_vars['header'] = array(
'TITLE' => $lang['REGISTRATION'],
'CSS' => $css
);
$template_vars['body'] = array();
$template->set_vars('header', $template_vars['header']);
$show_form = true;
if( !$sql->query("DELETE FROM `" . CATALOGUE_REGS . "` WHERE `time` < UNIX_TIMESTAMP();") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( !$sql->query("SELECT COUNT(*) FROM `" . CATALOGUE_REGS . "` WHERE `ip` = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "');") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$captcha = $sql->result($sql->result, 0) > 5;
if( empty($_POST) == false )
{
$site = isset( $_POST['site'] ) ? (string) $_POST['site'] : '';
$password = isset( $_POST['password'] ) ? (string) $_POST['password'] : '';
$email = isset( $_POST['email'] ) ? (string) $_POST['email'] : '';
$title = isset( $_POST['title'] ) ? (string) $_POST['title'] : '';
$description = isset( $_POST['description'] ) ? (string) $_POST['description'] : '';
$tr = isset( $_POST['tr'] ) ? (boolean) $_POST['tr'] : false;
$section_id = isset( $_POST['section_id'] ) ? (int) $_POST['section_id'] : '';
$code = isset( $_POST['code'] ) ? (int) $_POST['code'] : '';
if( $captcha )
{
$_SESSION['captcha_key'] = isset( $_SESSION['captcha_key'] ) ? $_SESSION['captcha_key'] : NULL;
$_SESSION['captcha_failures'] = isset( $_SESSION['captcha_failures'] ) ? $_SESSION['captcha_failures'] : 0;
}
if( get_magic_quotes_gpc() )
{
$site = stripslashes( $site );
$password = stripslashes( $password );
$email = stripslashes( $email );
$title = stripslashes( $title );
$description = stripslashes( $description );
}
if( $tr )
{
$title = tr( $title );
$description = tr( $description );
}
$site = cleanup(trim($site));
$email = cleanup(trim($email));
$title = cleanup(trim($title));
$description = cleanup(trim($description));
if( !$sql->query("SELECT * FROM `" . CATALOGUE_SECTIONS . "` WHERE `id` = " . $section_id . ";") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$invalid_section_id = $sql->num_rows() < 1;
if( !$sql->query("DELETE FROM `" . CATALOGUE_BANNED . "` WHERE `time` < UNIX_TIMESTAMP();") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( !$sql->query("SELECT * FROM `" . CATALOGUE_BANNED . "` WHERE `ip` = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "') AND `ua` = '" . mysql_escape_string($ua) . "';") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $captcha && ($_SESSION['captcha_key'] === NULL || ($_SESSION['captcha_key'] != $code)) )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_CAPTCHA']));
if( ++$_SESSION['captcha_failures'] == 5 )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_CAPTCHA_TOO_MANY_FAILURES']));
$_SESSION['captcha_key'] = NULL;
$_SESSION['captcha_failures'] = 0;
}
}
else if( $sql->num_rows() > 0 )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_BANNED']));
}
else if( $invalid_section_id )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_INVALID_SECTION_ID']));
}
else if( !preg_match('#^http://([a-z\d-]+\.)*[a-z\d-]+(:\d+)?(.*)$#i', $site, $match) )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_INVALID_SITE']));
}
else if( $password === '' )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_EMPTY_PASSWORD']));
}
else if( $description === '' )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => $lang['ERR_EMPTY_DESCRIPTION']));
}
else
{
$site = parse_url( $site );
$site = strtolower( $site['host'] );
$path = empty( $match[3] ) ? '/' : $match[3];
if( !($qresult = $sql->query("SELECT * FROM `" . CATALOGUE_SITES . "` WHERE `site` = '" . $sql->escape_string($site) . "';")) )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $sql->num_rows() > 0 && $_SESSION['crc32'] !== crc32( $site ) )
{
$site = $sql->fetch_assoc($sql->result);
if( $site['checked'] )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => sprintf($lang['ERR_SITE_AE'], output($site['site']), $site['id'])));
}
else
{
$template->load_template('templates/' . VERSION . '/message.tpl', 'body');
$template->set_vars('body', array('MESSAGE' => sprintf($lang['ERR_MODERATING'], output($site['site']), "http://" . $_SERVER['HTTP_HOST'] . gen_uri('in', $site['id'], '', false, false))));
$link = array(
array('HREF' => gen_uri('index'), 'NAME' => $lang['BACK'])
);
for($i = 0; $i < count($link); $i++)
{
$template->set_block_vars('body', 'link', $link[$i]);
}
}
}
else
{
if( !$sql->query("SELECT * FROM `" . CATALOGUE_BANNED_SITES . "` WHERE `site` = '" . $sql->escape_string($site, array(0x25, 0x5F)) . "';") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $sql->num_rows() > 0 )
{
$template->set_block_vars('body', 'error', array('MESSAGE' => sprintf($lang['ERR_SITE_BANNED'], output($site))));
}
else
{
if( $_SESSION['crc32'] !== crc32( $site ) )
{
if( $title == '' ) $title = $site;
$phone_number = isset( $_SERVER['X_NOKIA_MSISDN'] ) ? $_SERVER['X_NOKIA_MSISDN'] : (isset( $_SERVER['X_NETWORK_INFO'] ) ? $_SERVER['X_NETWORK_INFO'] : '' );
$phone_number = cleanup($phone_number);
if( !$sql->query("INSERT INTO `" . CATALOGUE_SITES . "` SET `site` = '" . $sql->escape_string($site) . "', `path` = '" . $sql->escape_string($path) . "', `password` = '" . md5($password) . "', `email` = '" . $sql->escape_string($email) . "', `checked` = 1, `section_id` = " . $section_id . ", `reg_dt` = UNIX_TIMESTAMP(), `reg_ip` = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "'), `reg_ua` = '" . mysql_escape_string($ua) . "', `reg_phone_number` = '" . $sql->escape_string($phone_number) . "', `reg_email` = '" . $sql->escape_string($email) . "', `title` = '" . $sql->escape_string($title) . "', `description` = '" . $sql->escape_string($description) . "', `update_dt` = UNIX_TIMESTAMP();") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( !$sql->query("SELECT LAST_INSERT_ID() FROM `" . CATALOGUE_SITES . "`;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$id = $sql->result($sql->result, 0);
if( !$sql->query("INSERT INTO `" . CATALOGUE_REGS . "` SET `ip` = INET_ATON('" . $_SERVER['REMOTE_ADDR'] . "'), `time` = UNIX_TIMESTAMP() + 600;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
$_SESSION['account'] = $id;
$_SESSION['crc32'] = crc32( $site );
$_SESSION['captcha_key'] = NULL;
}
else
{
$id = $_SESSION['account'];
}
$template->load_template('templates/' . VERSION . '/message.tpl', 'body');
$template->set_vars('body', array('MESSAGE' => sprintf($lang['REG_SUCCESS'], "http://" . $_SERVER['HTTP_HOST'] . gen_uri('in', $id, '', '', false, false))));
$link = array(
array('HREF' => gen_uri('index'), 'NAME' => $lang['BACK'])
);
for($i = 0; $i < count($link); $i++)
{
$template->set_block_vars('body', 'link', $link[$i]);
}
$show_form = false;
}
}
}
}
if( $show_form )
{
if( !$sql->query("SELECT * FROM `" . CATALOGUE_SECTIONS . "` WHERE `reg_access` = 1 ORDER BY `name` ASC;") )
{
put_error(DBMS_ERROR, htmlspecialchars($sql->error['message']), __LINE__, __FILE__);
}
if( $sql->num_rows() < 1 )
{
put_error(ERROR, $lang['ERR_SECTION_LIST_IS_EMPTY']);
}
for( $i = 0; $section = $sql->fetch_assoc(); $i++ )
{
$template->set_block_vars('body', 'section', array(
'ID' => $section['id'],
'NAME' => output($section['name']),
'SELECTED' => $i ? "" : " selected='selected'"
));
}
$template_vars['body'] = array(
'SITE' => $lang['SITE'],
'SITE_VALUE' => 'http://',
'PASSWORD' => $lang['PASSWORD'],
'TITLE' => $lang['TITLE'],
'DESCRIPTION' => $lang['DESCRIPTION'],
'SECTION' => $lang['SECTION'],
'SECTION_VALUE' => $sql->result($sql->result, 0, 'id'),
'TR' => $lang['TR'],
'SUBMIT' => $lang['REG_SUBMIT'],
'Y' => $lang['Y'],
'N' => $lang['N'],
'PATH' => gen_uri($m, '', $nocache),
'BACK_HREF' => gen_uri('index'),
'BACK' => $lang['BACK'],
'NOCACHE' => $nocache
);
if( $captcha )
{
$pic_types = array('gif', 'jpg', 'png');
$pic_type = isset( $_GET['type'] ) ? (string) $_GET['type'] : '';
$pic_type = in_array($pic_type, $pic_types) ? $pic_type : 'gif';
$pic_type_links = array();
for($i = 0; $i < count($pic_types); $i++)
{
if( $pic_type != $pic_types[$i] )
{
$pic_type_links[] = "<a href='" . gen_uri($m, '', 'type=' . $pic_types[$i]) . "'>" . strtoupper($pic_types[$i]) . "</a>";
}
}
$pic_type_links = implode(', ', $pic_type_links);
$template_vars['body'] = array_merge($template_vars['body'], array(
'CODE' => $lang['CODE'],
'CAPTCHA_SRC' => append_sid(PATH . '/captcha/?type=' . $pic_type),
'PIC_IS_NOT_LOAD' => $lang['PIC_IS_NOT_LOAD'],
'PIC_TYPE_LINKS' => $pic_type_links
));
$template->set_block_vars('body', 'captcha', array());
}
}
$template->set_vars('header', $template_vars['header']);
$template->set_vars('body', $template_vars['body']);
$template->set_vars('footer', array('SWITCH_VERSION' => switch_version($m, '', $nocache)));
?>