<?
include LOCALE.LOCALESET."register.php";
include INCLUDES."countries.php";

if($settings['enable_registration']==1){
echo "<br><br><br><br><br><br><br><br><br><br><br><br>";
echo "<form name='inputform' method='post' action='".AMX_SELF."?id=add' onsubmit='return ValidateForm(this)'>\n";
echo "<table align='center' cellpadding='0' cellspacing='1' width='400' class='tbl-border'>\n<tr>\n";
echo "<td class='tbl2'><strong>";


if (!isset($_POST['step']) || $_POST['step'] == "" || $_POST['step'] == "1") {
echo "</strong></td>\n</tr>\n<tr>\n<td class='tbl1'style='text-align:center'>\n";
	echo $settings['register_MG1'];
	echo "<table align='center' cellpadding='0' cellspacing='0' width='100%'>\n<tr>\n";
	echo "<td class='tbl1'>".$locale['reg003']."<span style='color:#ff0000'>*</span></td>\n";
	echo "<td class='tbl1' style='text-align:right'>";
	?><input type="text" name="server_ip" value="IP" class='textbox' onFocus="if(this.value=='IP')this.value='';" style='width:200px'></td> <td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg02']?>', this, event, '150px')">[?]</a></td></tr><?
	echo "<tr>\n<td class='tbl1'>".$locale['reg004']."<span style='color:#ff0000' >*</span></td>\n";
	echo "<td class='tbl1' style='text-align:right'>";
	?><input type="text" name="server_port" value="Порт" class='textbox' onFocus="if(this.value=='<?=$locale['reg011']?>')this.value='';" style='width:200px'></td> <td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg012']?>', this, event, '150px')">[?]</a></td></tr><?
	echo "<tr>\n<td class='tbl1'>".$locale['reg005']."<span style='color:#ff0000' >*</span></td>\n";
	echo "<td class='tbl1' style='text-align:right'>";
	echo "<select name='protokol' style='width:206px'>";
	echo "<option value='0'>".$locale['reg006']."</option>";
	echo "<option value='47'>47</option>";
	echo "<option value='48'>48</option>";
	echo "<option value='47/48'>47/48</option>";
	echo "</select></td>";
	?><td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg013']?>', this, event, '150px')">[?]</a></td></tr><?
	echo "<tr><td>".$locale['reg007']."<span style='color:#ff0000' >*</span></td>\n";
	echo "<td style='text-align:right'>".csm_makeSelbox()."</td>";?><td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg014']?>', this, event, '150px')">[?]</a></td></tr><?php
	echo "<tr><td>".$locale['reg008']."<span style='color:#ff0000' >*</span></td>\n";
	echo "<td style='text-align:right'><input type='text' value='' name='email' class='textbox' style='width:200px'></td>";?><td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg015']?>', this, event, '150px')">[?]</a></td></tr><?php
	echo "<tr><td>".$locale['reg009']."</td>\n";
	echo "<td style='text-align:right'><input type='text' value='' name='icq' class='textbox' style='width:200px'></td>";?><td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg016']?>', this, event, '150px')">[?]</a></td></tr><?php
	echo "<tr><td>".$locale['reg010']."</td>\n";
	echo "<td style='text-align:right'>http://<input type='text' value='' name='www' class='textbox' style='width:180px'></td>";?><td><a href="#" class="hintanchor" onMouseover="showhint('<?=$locale['reg017']?>', this, event, '150px')">[?]</a></td></tr><?php
	echo "</table>\n";
	echo "</td>\n</tr>\n<tr>\n<td style='text-align:center'>\n";
	echo "<input type='hidden' name='step' value='2'>\n";
	echo "<input type='submit' name='next' value='Далее' class='button'>\n";

}
if (isset($_POST['step']) && $_POST['step'] == "2") {
	$error = "";
	$server_ip = stripinput($_POST['server_ip']);
	$server_port = stripinput($_POST['server_port']);
    $protokol = stripinput($_POST['protokol']);
    $server_location =stripinput($_POST['server_location']);
    $email=stripinput($_POST['email']);
    $icq=stripinput($_POST['icq']);
	$www=stripinput($_POST['www']);
	$result="SELECT * FROM ".DB_SERVERS." WHERE server_ip = '".$server_ip.":".$server_port."'";
	$dbresult=mysql_query($result);
	$n=mysql_num_rows($dbresult);
	if($n) {$error .=$locale['reg021']."<br><br>\n";}

	if($protokol==0)$error .=$locale['reg022']."<br><br>\n";

	if (!preg_match("/^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$/i", $server_ip)) {
		$error .= $locale['reg024']."<br><br>\n";
	}

 	if (!preg_match("/^[0-9]{5,5}$/i", $server_port)) {
		$error .= $locale['reg025']."<br><br>\n";
	}

	if($server_location=='')  $error .= "Вы не выбрали месторасположение сервера.<br><br>\n";
    	if (!preg_match("/^[-0-9A-Z_\.]{1,50}@([-0-9A-Z_\.]+\.){1,50}([0-9A-Z]){2,4}$/i", $email)) {
		$error .= $locale['reg026']."<br />\n";
	}
	if($icq !=""){
	if(!preg_match("/^[0-9]{5,30}$/i", $icq))$error .= $locale['reg027']."<br><br>\n";}
	if ($error == "") {
   $date_resp = date("Y-m-d");
   $result = dbquery("INSERT INTO ".DB_SERVERS."(server_name, server_ip, server_map, server_players,server_maxplayers, server_status, server_location, server_vip, server_protokol, server_regdata, server_email, server_icq,server_new, server_site ) VALUES ('','".$server_ip.":".$server_port."','','','','', '".$server_location."', '0','".$protokol."', '".$date_resp."','".$email."','".$icq."','1','".$www."')");

   echo "</strong></td>\n</tr>\n<tr>\n<td class='tbl1'style='text-align:center'>\n";
   echo $settings['register_MG2'];

	} else {
		echo "</strong></td>\n</tr>\n<tr>\n<td class='tbl1'style='text-align:center'>\n";
		echo "<br>\n ".$locale['reg028']."<br><br>\n".$error;
		echo "</td>\n</tr>\n<tr>\n<td class='tbl2' style='text-align:center'>\n";
		echo "<input type='hidden' name='step' value='1'>\n";
		echo "<input type='submit' name='back' value='Назад' class='button'>\n";
	}

}

echo "</td>\n</tr>\n";
echo "</table>\n</form>\n";
}
else {
echo "<center><br><br><br><br><br><br><br><br><br><br><b><font size='3'>".$locale['reg029']."</font></b></center><br><br><br><br><br><br><br><br><br><br><br><br>";
}

