<?include('header.php');?>
<div class="menucenter">
<?
include("wm_chek.php");
$res=mysql_query("select valuta from tb_site where id='1'");
$v=mysql_result($res,0,0);


if(isset($_SESSION["username"]) && isset($_SESSION["password"])){echo "<div class=error>Вы уже зарегистрированы...</div>";include('footer.php');exit();}
require('config/conf_reg.php');
require('config.php');
require('karera/setup_ball.php');
if (isset($_POST["username"]))
{
if( strtolower($_POST['code'])!= strtolower($_SESSION['logcaptcha']) OR !isset($_SESSION["logcaptcha"])){echo "<div class=error>Неверно введен код с картинки... </div>";require 'footer.php';exit(); }

  $username = login(strtolower($_POST["username"]));
  $realPassword = $_POST["password"];
  $password = strtolower($_POST["password"]);
  $password = myHashData($password);
  $cpassword = strtolower($_POST["password"]);
  $cpassword = myHashData($cpassword);
  $country = $_POST["country"];
  $referer=$_POST["referer"];

  if($username==NULL|$password==NULL|$cpassword==NULL)
  {
   echo "<div class=error>Заполнены не все поля!!!</div>";
  }else{
   $username = text($username);
   if($referer!="") $referer = text($referer);
   if($country!="") {$country = text($country);}
     if($_POST["system"]=="liqpay"){
   	 function liq($mensaje)
     {
      if (preg_match("/[0-9]/", $mensaje))
      {
        return $mensaje;
      }else{
        echo "<div class=error>Введенные данные содержат запрещенные символы. Проверьте правильность ввода счета LiqPay</div>";include('footer.php');exit();
      }
     }

     $sys_stat = 1;$schet = liq($_POST["schet"]);$pemail = $schet;$wmid ="";
     if(!is_numeric($pemail) or strlen($pemail)< 8 or strlen($pemail)> 15 or $pemail==NULL){echo "</div>Неверно введен номер счета LiqPay</div>";include('footer.php');exit();}
   }else{
   	 echo "<div class=error>Заполнены не все поля!!!</div>";include('footer.php');exit();
   }

   if($password!=$cpassword)
   {
    echo "<div class=error>Неверно указан пароль</div>";
   }else{
    $laip = getRealIP();



    if ($ip_exist>0)
    {
     echo "<div class=error>Ошибка! С Вашего IP адреса уже была регистрация. Повторная регистрация невозможна </div>";
    }else{
     $checkuser = mysql_query("SELECT username FROM tb_users WHERE username='$username'");
     $username_exist = mysql_num_rows($checkuser);

     $checkpemail = mysql_query("SELECT id FROM tb_users WHERE pemail='$pemail'");
     $pemail_wm = mysql_num_rows($checkpemail);

     if ($username_exist>0)
     {
      echo "<div class=error>Такой логин есть в системе.</div>";
     }else{
      if ($pemail_wm>0)
      {
       echo "<div class=error>Указанные данные уже используются</div>";
      }else{
       $buying='0';
       if($referer!='')
       {
        $checkref = mysql_query("SELECT * FROM tb_users WHERE username='$referer'");
        $referer_exist = mysql_num_rows($checkref);

        if ($referer_exist<1)
        {
         $referer='';
        }else{
         $myrowz = mysql_fetch_assoc($checkref);


//Конкурс рефералов
         $refer_kon=mysql_query("SELECT id
                  FROM still_konkurs_ref
                  WHERE idref=(SELECT id FROM tb_users WHERE username=(SELECT referer FROM tb_users WHERE username='".$myrowz["username"]."')) and vid='3'
                  and time_start < '".time()."' and time_start+(time_end*86400) > '".time()."' LIMIT 1");
                  if(mysql_num_rows($refer_kon) > 0){
                    $rk = mysql_fetch_assoc($refer_kon);

                    $top_kon=mysql_query("SELECT id
                    FROM still_top_kon WHERE idk='".$rk["id"]."' and  idu=(SELECT id FROM tb_users WHERE username='".$myrowz["username"]."') LIMIT 1");
                    if(mysql_num_rows($top_kon) > 0){
                      $tk = mysql_fetch_assoc($top_kon);

                      mysql_query("UPDATE still_top_kon SET danie=danie+'1' WHERE id='".$tk["id"]."'");

                    }else{

                      mysql_query("insert into still_top_kon (idu,danie,idk) values ((SELECT id FROM tb_users WHERE username='".$myrowz["username"]."'),'1','".$rk["id"]."')");

                    }

                  }

         $res=mysql_query("select count(*) as kolvo from tb_users where referer='$referer' and buying='0'");
         $res=mysql_fetch_assoc($res);
         $refcount=$res["kolvo"];
         if($refcount<999999999999)
         {
          $numero=$myrowz["referals"];
$umoney=$myrowz["money_cr"];
$totlumoney=$umoney+$mon_zaref;
$timenowe=time();
$sqlex= "UPDATE tb_users SET referals='$numero'+1, money_cr='$totlumoney', `ball` = `ball` + '".$ball["ref"]."' WHERE username='$referer'";
mysql_query("INSERT INTO tb_infoball (user, date, ball, referer, mesage) VALUES('$referer', '$timenowe', '+ ".$ball["ref"]."', '---', 'Регистрация реферала системе')") or die(mysql_error());
          $resultex = mysql_query($sqlex);

          $res11=mysql_query("select * from tb_comp where param='0'");
          if(mysql_num_rows($res11)>0)
          {
                              while($row11=mysql_fetch_assoc($res11))
                              {
                              $idk=$row11[ "id"];
                              $lidertype=$row11["lidername"];
                              $t=time();
                              $sd=strtotime($row11["startdate"]);
                              $ed=strtotime($row11["enddate"]);
                              if($t>$sd && $t<$ed)
                              {
                              if($lidertype=='1')
                              {
                              $res111=mysql_query("select wmid from tb_users where username='$referer'");
                              if(mysql_num_rows($res111)>0){$res1=mysql_fetch_assoc($res111); $lidername=$res111["wmid"];}else{$lidername='';}
                              }else{
                              $lidername=$referer;
                              }
                              if($lidername!='')
                              {
                              $res111=mysql_query("select * from tb_compdata where idk='$idk' and user='$lidername'");
                              if(mysql_num_rows($res111)>0)
                              {
                              $res111=mysql_fetch_assoc($res111);
                              $resvalue=$res111["resvalue"]+1;
                              mysql_query("update tb_compdata set resvalue='$resvalue' where id='".$res111["id"]."'");
                              }else{
                              mysql_query("insert into tb_compdata (idk,user,resvalue) values ('$idk','$lidername','1')");
                              }
                              }
                              }
                              }
          }
         }else{
          $referer='';
         }
        }
// andreika {
  $sqlz = "SELECT * FROM tb_users WHERE username='$referer'";
  $resultz = mysql_query($sqlz);
  $myrowz2 = mysql_fetch_assoc($resultz);
  $referer2=$myrowz2["referer"];
  // } andreika
  }
  // andreika {
  else // if($referer=='')
  // } andreika
  {
       }

       $joindate=date("d.m.Y");

$allper = 0;
if($referer != ""){

  $check = mysql_query("SELECT `refbek`,`text` FROM `still_auto_refbek` WHERE `id_us` = '".$myrowz["id"]."' LIMIT 1");
  if(mysql_num_rows($check) > 0){

    $ref_b=mysql_fetch_assoc($check);

    $allper = $ref_b["refbek"];

    if($ref_b["text"] != ""){

      mysql_query("INSERT INTO `tb_mail` (sender, recipient, subject, message, status , data)
      VALUES('".$myrowz["username"]."', '$username', 'Сообщение от Реферера', '".$ref_b["text"]."', '0', '".time()."')");

    }

  }

}

$timenow=time();
mysql_query("INSERT INTO tb_users (username, password, ip, pemail, referer, referer2, country, money, joindate, wmid, buying, ref_per_all,system,ball,ball_date) VALUES('$username','$password','$laip','$pemail','$referer','$referer2','$country','$mon_new','$joindate','$wmid','$buying', '$allper', '$sys_stat', '".$ball["rega"]."','".time()."')");
mysql_query("INSERT INTO tb_infoball (user, date, ball, referer, mesage) VALUES('$username', '$timenow', '+ ".$ball["rega"]."', '---', 'Регистрация в системе')") or die(mysql_error());
require('config.php');
mysql_query("UPDATE tb_users SET timereg='$timenow' WHERE username='$username'") or die(mysql_error());
       echo "<div class='good'><small>Поздравляем теперь вы <font color='red'><b>$username</b> зарегистрированы, ваш пароль: <font color='red'><b>$realPassword</b></font>.<br />Спасибо что выбрали Almazz-Bux.Info! Желаем отличного заработка!</div>";
  session_start();
  $lastlogdate=date("Y.m.d");
  $lastip = getRealIP();

  mysql_query("UPDATE tb_users SET lastlogdate='$lastlogdate', lastvxod='$timenow', lastiplog='$lastip' WHERE username='$username'");
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
$lastnameus = strtolower($lastnameus);
$username = strtolower($username);
 if(($lastnameus != $username) and ($lastnameus != ""))  {
    mysql_query("UPDATE tb_users set blockpay='1', lastuser='$lastnameus' where username='$username'");
    mysql_query("UPDATE tb_users set blockpay='1', lastuser='$username' where username='$lastnameus'");
  }
?>
    <script type="text/javascript">
    location.replace("members.php");
    </script>
    <noscript>
    <meta http-equiv="refresh" content="0; url=members.php">
    </noscript>
    <?
}
     }
    }
   }
  }
}else{

?>
<fieldset class=alert>Нажимая "Зарегистрироваться", Вы автоматически соглашаетесь с правилами!</fieldset>
<table class='reyt' align='center' width='100%' border='0' cellpadding='0' cellspacing='0' style='margin-bottom: 0;'>
<form action="register_liq.php" method="POST">
<input type=hidden name=ask_editcode value=0 />
<thead><tr>
<th align="left" width=34%>Параметр</th>
<th align="left">Значение параметра</th>
</tr></thead>
<tr>
<td width=34%><b>Ваше Имя (Англ. буквами)</b></td>
<td><input type='text' size='15' maxlength='15' name='username' autocomplete="off" value="" tabindex="1" /></td>

</tr>
<tr>
<td width=34%><b>Ваш пароль</b></td>
<td><input type="password" size="25" maxlength="15" name="password" autocomplete="off" class="field" value="" tabindex="1" /></td>

</tr>
<tr>
<td width=34%><b>Повторите пароль</b></td>
<td><input type="password" size="25" maxlength="15" name="cpassword" autocomplete="off" class="field" value="" tabindex="1" /></td>
</tr>
<tr>
<td width=34%><b>Платежная система</b></td>
<td>
 <input name="system" value="liqpay" onClick="javascript:lpau('liqpay2')" checked="checked" type="radio">LiqPay</td>
</tr>
<tr>
<td width=34%><b>LiqPay счет:</b></td>
<td><input readonly="readonly" size="25" maxlength="1" value="+" style="color:#357D2B;font-size:14px;width: 10px;" tabindex="1" type="text"><input type="text" size="23" maxlength="13" name="schet" class="field" value=""></td>
</tr>
<tr>
<td width=34%><b>Где проживаете?:</b></td>
<td>
<select name="country" style="width: 194px;" id="select">
        <option value="ru">Россия</option>
        <option value="ua">Украина</option>
        <option value="by">Беларусь</option>
        <option value="kz">Казахстан</option>
        <option value="ot">Другая страна</option>
        </select>
</td>

</tr>
<tr>
<td width=34%><b>Ваш реферер:</b></td>
<td style='padding:5px;'>
        <? if(isset($_SESSION["arl"])) { ?>
        <font color='#C15F24'><b>( <? echo text($_SESSION["arl"]); ?> )</b></font>
	<input type="text" size="25" maxlength="25" name="referer" value="<? echo text($_SESSION["arl"]); ?>" readonly autocomplete="off" style="display:none;" tabindex="15"/>
	<? } else { ?>
	<font color='#C15F24'><b>( Никто, сам пришёл )</b></font>
        <input type="text" size="25" maxlength="25" name="referer" value="<? echo text($_GET["r"]); ?>" autocomplete="off" style="display:none;" tabindex="15" />
	<? } ?></td>

</tr>

<tr>
<td width=34%><b>Введите код</b></td>
<td>
<input class=val type='text' size='3' maxlength='4' name='code' autocomplete="off" onChange="getZakaz(this.form)" value="">
<img src="logincap.php" align="absabsabsmiddle">
</td>
</tr>

<tr>
<td width=34%><b>Зарегистрироваться!</b></td>
<td>
<input  class="okey" type="submit" value="Зарегистрироваться" class="submit" tabindex="4" />
</td>
</tr>
</tbody>
</table>
</form>
<?
}
include('footer.php'); ?>