Файл: billing/reg.php
Строк: 669
<?php
require_once( "./_rootconfig.php" );
session_start( );
mconnect( );
validateuser( );
if ( $do == "whois" )
{
head( );
$d = new domain( $_GET['d'] );
print "<B>Информация о домене:</b><BR><BR>";
echo $d->html_info( );
foot( );
mclose( );
exit( );
}
if ( $do == "order" )
{
if ( $domain_reg == "" )
{
$error = "Не указано будет домен переноситься или нужно его зарегистрировать.";
$do = "";
}
else if ( ( !$domain || !$zone ) && !$otherdomain )
{
$error = "Не указано доменное имя.";
$do = "";
}
else if ( !$tarif_id )
{
$error = "Не выбран тарифный план.";
$do = "";
}
else if ( !$months[$tarif_id] )
{
$error = "Не выбран срок заказа.";
$do = "";
}
else
{
if ( !$paymethod )
{
$error = "Не указан способ оплаты.";
$do = "";
}
else
{
if ( $domain && $zone )
{
$fulldomain = $domain.".".$zone;
}
else
{
$fulldomain = $otherdomain;
}
$dom = new domain( $fulldomain );
if ( $domain_reg && !$dom->is_available( ) )
{
$error = "Доменное имя <B>{$fulldomain}</b> уже зарегистрировано.</font><BR>Вы можете <a href=?d={$fulldomain}&do=whois target=_blank>просмотреть whois-информацию</a> о домене";
$do = "";
if ( !( $r = @mysql_query( @"select * from orders where domain='{$fulldomain}' and domain_reg='0' and todate>NOW()" ) ) )
{
exit( mysql_error( ) );
}
if ( !( $k = @mysql_query( @"select * from orders_domains where domain='{$fulldomain}' and todate>NOW()" ) ) )
{
exit( mysql_error( ) );
}
}
else if ( 0 < mysql_num_rows( $r ) )
{
$error = "Тарифный план для указанного доменного имени уже заказан другим пользователем.";
$do = "";
}
else
{
if ( $domain_reg && 0 < mysql_num_rows( $k ) )
{
$error = "Указанное доменное имя уже заказано другим пользователем.";
$do = "";
}
else
{
if ( !$_SESSION['userId'] && $elogin && $epassword )
{
$auth = userlogon( $elogin, $epassword );
if ( $auth == "-1" )
{
$error = "Введено несуществующее имя пользователя.";
$do = "";
}
else
{
if ( !$auth )
{
$error = "Указан неверный пароль.";
$do = "";
}
}
}
else if ( !$_SESSION['userId'] )
{
$login = strtolower( $login );
if ( !$login )
{
$error = "Не указан логин.";
$do = "";
}
else if ( eregi( "^[0-9]", $login ) )
{
$error = "Логин должен начинаться с a-z";
$do = "";
}
else if ( eregi( "[^a-z,0-9]", $login ) )
{
$error = "Логин должен состоять из сиволов a-z,0-9";
$do = "";
}
else if ( strlen( $login ) < 3 || 10 < strlen( $login ) )
{
$error = "Длина логина должна быть от 3 до 10 символов.";
$do = "";
}
else if ( !$password )
{
$error = "Не указан пароль.";
$do = "";
}
else if ( !$repassword )
{
$error = "Не подтверждён пароль.";
$do = "";
}
else if ( strlen( $password ) < 6 )
{
$error = "Длина пароля не должна быть менее 6 символов.";
$do = "";
}
else if ( $password != $repassword )
{
$error = "Неправильно подтверждён пароль.";
$do = "";
}
else if ( !valid_email( $email ) )
{
$error = "Указан неправильный e-mail адрес.";
$do = "";
if ( !( $r = @mysql_query( @"select * from users where login='{$login}'" ) ) )
{
exit( mysql_error( ) );
}
}
else if ( 0 < mysql_num_rows( $r ) )
{
print "<font color=red>Пользователь с таким логином уже зарегистрирован.";
$do = "";
}
else
{
if ( !mysql_query( "insert into users (login,password,email,datareg) values('{$login}','".crypt( $password )."','{$email}',NOW())" ) )
{
exit( mysql_error( ) );
}
userlogon( "{$login}", "{$password}" );
if ( !mysql_query( "insert into users_profile (uid) values('".$_SESSION['userId']."')" ) )
{
exit( mysql_error( ) );
}
}
}
if ( $_SESSION['userId'] )
{
$hostmonths = $months[$tarif_id];
$addonsCost = 0;
$selectedAddons = $addons[$tarif_id];
$addonsToSave = "";
$addonsToSaveText = "";
while ( @list( $k, $v ) = each( @$selectedAddons ) )
{
if ( $v )
{
$selectedAddon = getaddonbyid( $v );
if ( $addonsToSaveText )
{
$addonsToSaveText = $addonsToSaveText.", ".$selectedAddon->textid;
}
else
{
$addonsToSaveText = $selectedAddon->textid;
}
$addonsToSave = $addonsToSave.":x:{$selectedAddon->id}";
$addonsCost += $selectedAddon->cost_start;
$addonsCost += $selectedAddon->cost_monthly * $hostmonths;
}
}
if ( !$addonsToSaveText )
{
$addonsToSaveText = "нет";
}
if ( !@mysql_query( @"insert into orders (uid,tarif,domain,domain_reg,addons,orderdate,paymethod,comment) values('".@$_SESSION['userId'].@"','{$tarif_id}','{$fulldomain}','{$domain_reg}','{$addonsToSave}',NOW(),'{$paymethod}','".@addslashes( @$comment )."')" ) )
{
exit( mysql_error( ) );
}
$host_id = mysql_insert_id( );
if ( $domain_reg )
{
if ( !( $zid = @mysql_query( @"select * from zones where zone='{$zone}'" ) ) )
{
exit( mysql_error( ) );
}
$zid = mysql_fetch_object( $zid );
$zid = $zid->id;
if ( !@mysql_query( @"insert into orders_domains (uid,zone_id,host_id,domain,orderdate) values ('".@$_SESSION['userId'].@"','{$zid}','{$host_id}','{$fulldomain}',NOW())" ) )
{
exit( mysql_error( ) );
}
$domain_id = mysql_insert_id( );
}
if ( !( $t = @mysql_query( @"select cost,cost_setup,name from tarifs where id={$tarif_id}" ) ) )
{
exit( mysql_error( ) );
}
$t = mysql_fetch_object( $t );
$hostcost = $t->cost;
$host_setup = $t->cost_setup;
if ( !( $tsroki = @mysql_query( @"select discount from tarifs_sroki where tarif_id={$tarif_id} and months='{$hostmonths}'" ) ) )
{
exit( mysql_error( ) );
}
$tsroki = mysql_fetch_object( $tsroki );
$srokDiscount = $tsroki->discount;
$host = $hostcost * $hostmonths + $host_setup;
$host = $host - $host / 100 * $srokDiscount;
$dom = 0;
if ( $domain_reg )
{
if ( !( $tzones = @mysql_query( @"select cost_if_host,minsrok from zones where zone='{$zone}'" ) ) )
{
exit( mysql_error( ) );
}
$tzones = mysql_fetch_object( $tzones );
$domaincost = $tzones->cost_if_host;
$domainminsrok = $tzones->minsrok;
if ( !( $tfreedomains = @mysql_query( @"select * from tarifs_freedomains where tarif_id='{$tarif_id}' and zone='{$zone}' and hostmonths='{$hostmonths}'" ) ) )
{
exit( mysql_error( ) );
}
if ( 0 < mysql_num_rows( $tfreedomains ) )
{
$domainfree = 1;
}
else
{
$domainfree = 0;
}
$dom = $domaincost * ( $domainminsrok / 12 );
if ( $domainfree )
{
$dom = 0;
}
}
if ( !@mysql_query( @"insert into bills (uid,host_id,domain_id,host_srok,domain_srok,money_host,money_domain,money_addons,created) values('".@$_SESSION['userId'].@"','{$host_id}','{$domain_id}','{$hostmonths}','{$domainminsrok}','{$host}','{$dom}','{$addonsCost}',NOW())" ) )
{
exit( mysql_error( ) );
}
$bill_id = mysql_insert_id( );
$sid = sprintf( "%04d", $bill_id );
$template = gettpl( "email_touser_".$vid."_order" );
$company_name = getsetting( "company_name" );
$company_url = getsetting( "company_url" );
$billing_url = getsetting( "billing_url" );
$support_url = getsetting( "support_url" );
$manager_email = getsetting( "manager_email" );
if ( $elogin && $epassword )
{
$tl = strtolower( $elogin );
$tp = $epassword;
}
else if ( $login && $password )
{
$tl = strtolower( $login );
$tp = $password;
}
else
{
$tl = $_SESSION['userLogin'];
$tp = "******";
}
$template = str_replace( "{company_name}", $company_name, $template );
$template = str_replace( "{company_url}", $company_url, $template );
$template = str_replace( "{billing_url}", $billing_url, $template );
$template = str_replace( "{support_url}", $support_url, $template );
$template = str_replace( "{tarif}", $t->name, $template );
$template = str_replace( "{srok}", $hostmonths, $template );
$template = str_replace( "{domain}", $fulldomain, $template );
$template = str_replace( "{addons}", $addonsToSaveText, $template );
$template = str_replace( "{newreg}", $_newreg[$domain_reg], $template );
$template = str_replace( "{login}", $tl, $template );
$template = str_replace( "{password}", $tp, $template );
$template = str_replace( "{schet}", $sid, $template );
$template = str_replace( "{hostcost}", $host, $template );
$template = str_replace( "{domaincost}", $dom, $template );
$template = str_replace( "{addonscost}", $addonsCost, $template );
$template = str_replace( "{cost}", $host + $dom + $addonsCost, $template );
$template = str_replace( "{paymethod}", $paymethod, $template );
if ( $comment )
{
$comment = "Комментарий:n".$comment;
}
$template = str_replace( "{comment}", $comment, $template );
$template = str_replace( "{userid}", $_SESSION['userId'], $template );
adduserlog( $_SESSION['userId'], "order", "{$t->name}, {$hostmonths} мес., {$fulldomain} [".$_newreg[$domain_reg]."]" );
sendmail( $_SESSION['userEmail'], $manager_email, "Оформление заказа [{$vid}]", $template );
sendmail( $manager_email, $_SESSION['userEmail'], "Duplicate: Оформление заказа [{$vid}]", $template );
if ( $domain_reg )
{
header( "Location: billing.php?do=profile&fromreg=1&bill_id={$bill_id}" );
}
else
{
header( "Location: billing.php?do=pay&fromreg=1&id={$bill_id}" );
}
mclose( );
exit( );
}
}
}
}
}
}
if ( !$do )
{
head( );
print "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td><font size=5><b><font size=3>Оформление заказа</font></b></font><hr size=1></td></tr></table>";
if ( $error )
{
print "<font color=red>Ошибка: {$error}</font><BR><BR>";
}
if ( $domain_reg == "0" )
{
$check1 = "checked";
$disabled = "";
}
else
{
$check2 = "checked";
$disabled = "disabled";
}
if ( !$vid )
{
$vid = "hosting";
}
if ( $tarif )
{
if ( !( $r = @mysql_query( @"select * from tarifs where name='{$tarif}'" ) ) )
{
exit( mysql_error( ) );
}
if ( 0 < mysql_num_rows( $r ) )
{
$r = mysql_fetch_object( $r );
$tarif_id = $r->id;
}
}
echo "rnt";
echo "<s";
echo "cript language=javascript type='text/javascript'>rnrntfunction showdiv(divid) {rntt";
if ( $tarif_id )
{
print "parent.flast='{$tarif_id}';";
}
echo "rnttif (parent.last) {hidediv(parent.last);} else { if (parent.flast) {hidediv(parent.flast);}}rnrnttparent.last=divid;rnttif (document.getElementById) { // DOM3 = IE5, NS6rntttdocument.getElementById('d'+divid).style.display = 'block';rntttdocument.getElementById('a'+divid).style.display = 'block';rntt}rnttelse {rntttif (document.layers) { // Netscape 4rnttttdivid = 'd'+divid; document.divid.disp";
echo "lay = 'block';rnttttdivid = 'a'+divid; document.divid.display = 'block';rnttt}rntttelse { // IE 4rnttttdivid = 'd'+divid; document.all.divid.style.display = 'block';rnttttdivid = 'a'+divid; document.all.divid.style.display = 'block';rnttt}rntt}rnt}rnrntfunction hidediv(divid) {rnttif (document.getElementById) { // DOM3 = IE5, NS6rntttdocument.getElementById('d'+divid).style.display = 'none';rntttd";
echo "ocument.getElementById('a'+divid).style.display = 'none';rntt}rnttelse {rntttif (document.layers) { // Netscape 4rnttttdivid = 'd'+divid; document.divid.display = 'none';rnttttdivid = 'a'+divid; document.divid.display = 'none';rnttt}rntttelse { // IE 4rnttttdivid = 'd'+divid; document.all.divid.style.display = 'none';rnttttdivid = 'a'+divid; document.all.divid.style.display = 'none';rnttt}rntt}rnt";
echo "}rnrntfunction showblankdiv(divid) {rnttif (document.getElementById) { // DOM3 = IE5, NS6rntttdocument.getElementById(divid).style.display = 'block';rntt}rnttelse {rntttif (document.layers) { // Netscape 4rnttttdocument.divid.display = 'block';rnttt}rntttelse { // IE 4rnttttdocument.all.divid.style.display = 'block';rnttt}rntt}rnt}rntrntfunction hideblankdiv(divid) {rnttif (document.getElementById";
echo ") { // DOM3 = IE5, NS6rntttdocument.getElementById(divid).style.display = 'none';rntt}rnttelse {rntttif (document.layers) { // Netscape 4rnttttdocument.divid.display = 'none';rnttt}rntttelse { // IE 4rnttttdocument.all.divid.style.display = 'none';rnttt}rntt}rnt}rnt</script>rnrnt<form method=post name=order>rnt<input type=hidden name=do value=order>rnt<input type=hidden name=vid value=";
echo $vid;
echo ">rn";
if ( !isset( $_SESSION['userId'] ) )
{
echo "t<B>Выбор типа клиента:</B><BR>rnt<table border=0><tr><td>rnt<input type=radio name=usertype value=exists ";
if ( $usertype != "new" )
{
print "checked";
}
echo " onclick="hideblankdiv('tablereg'); showblankdiv('tablelogin')">Зарегистрированный клиент<BR>rnt<input type=radio name=usertype value=new ";
if ( $usertype == "new" )
{
print "checked";
}
echo " onclick="hideblankdiv('tablelogin'); showblankdiv('tablereg')">Новый клиент<BR><BR>rnt</td></tr></table>rnrnt";
if ( $usertype != "new" )
{
$style = "style='display: block;'";
}
else
{
$style = "style='display: none;'";
}
echo "trnt<div id=tablelogin ";
echo $style;
echo ">rnt<B>Введите Ваши логин и пароль:</b><br>rnt<table border=0>rnt<tr><td colspan=2></td></tr>rnt<tr><td>* Логин в системе:</td><td><input type="text" name="elogin" value="";
echo $elogin;
echo "" maxlength=10 size=20></td></tr>rnt<tr><td>* Пароль:<BR><BR></td><td><input type="password" name="epassword" size=20><BR><BR></td></tr>rnt</table>rnt</div>rntrnt";
if ( $usertype == "new" )
{
$style = "style='display: block;'";
}
else
{
$style = "style='display: none;'";
}
echo "rnt<div id=tablereg ";
echo $style;
echo ">rnt<table border=0>rnt<tr><td colspan=3><B>Заполните нижеследующую форму:</b><br><br></td></tr>rnt<tr><td align=right>* Логин в системе:</td><td><input type="text" name="login" value="";
echo $login;
echo "" maxlength=10 size=20> от 3 до 10 символов a-z,0-9</td><td></td></tr>rnt<tr><td align=right>* Пароль:</td><td><input type="password" name="password" size=20> не менее 6 символов</td><Td></td></tr>rnt<tr><td valign=middle align=right>* Повтор пароля:</td><td colspan="2"><input type="password" name="repassword" size=20></td></tr>rnt<tr><td valign=middle align=right>* Ваш e-mail:<BR><BR></td><td colspan="2"><input type="text"";
echo " name="email" value="";
echo $email;
echo ""><BR><BR></td></tr>rnt</table>rnt</div>rn";
}
echo "t<table border=0>rnt<tr><td colspan=3><B>Выбор тарифного плана и оформление заказа:</b><br><br></td></tr>rnt<tr><td align=right valign=top> * Хостинг:</td><td colspan="2"><input type=radio onclick="javascript: this.form.otherdomain.disabled=0;" name=domain_reg value=0 ";
echo $check1;
echo ">с переносом домена<BR><input type=radio onclick="javascript: this.form.otherdomain.disabled=1;" name=domain_reg value=1 ";
echo $check2;
echo ">с регистрацией нового</td></tr>rnt<tr><td align=right>* Домен:</td><td><input type="text" name="domain" value="";
echo $domain;
echo ""> ";
echo "<s";
echo "elect name="zone"><option>rnt";
if ( !( $r = @mysql_query( "select * from zones where active=1 order by zone" ) ) )
{
exit( mysql_error( ) );
}
while ( $rr = mysql_fetch_object( $r ) )
{
if ( $rr->zone == $zone )
{
$addon = "selected";
}
else
{
$addon = "";
}
print "<option value={$rr->zone} {$addon}>.{$rr->zone}";
}
echo "t</select></td></tr>rnt<tr><td align=right></td><td>домен в другой зоне:<BR><input type="text" name="otherdomain" ";
echo $disabled;
echo " value="";
echo $otherdomain;
echo "" size=30> например, example.ex</td><td></td></tr>rnt<tr><td align=right valign=top>* Тарифный план:</td><td colspan="2">rnt";
if ( !( $r = @mysql_query( @"select * from tarifs where active=1 and vid='{$vid}' order by id" ) ) )
{
exit( mysql_error( ) );
}
while ( $rr = mysql_fetch_object( $r ) )
{
if ( $rr->id == $tarif_id || $tarif == $rr->name )
{
$addon = "checked";
$tarif_id = $rr->id;
}
else
{
$addon = "";
}
if ( $rr->cost_setup )
{
$addon_cost = " + {$rr->cost_setup} $ разово за установку";
}
else
{
$addon_cost = "";
}
print "<input type=radio name=tarif_id value={$rr->id} {$addon} onclick='showdiv(this.value);'>{$rr->name} ({$rr->cost} $/мес".$addon_cost.")<BR>";
}
echo "t</select></td></tr>rnt<tr><td align=right>* На срок:</td><td colspan="2">rnt";
$r = @mysql_query( "select * from tarifs_sroki order by tarif_id,months" );
while ( $rr = mysql_fetch_object( $r ) )
{
if ( $rr->tarif_id == $tarif_id )
{
$style = "style='display: block;'";
}
else
{
$style = "style='display: none;'";
}
if ( !$last_tarif_id )
{
print "<div id=d{$rr->tarif_id} {$style}><select name=months[{$rr->tarif_id}]><option>";
}
else if ( $last_tarif_id != $rr->tarif_id )
{
print "</select></div><div id=d{$rr->tarif_id} {$style}><select name=months[{$rr->tarif_id}]><option>";
}
if ( $months[$rr->tarif_id] == $rr->months )
{
$addon = "selected";
}
else
{
$addon = "";
}
print "<option value={$rr->months} {$addon}>{$rr->months} мес (скидка {$rr->discount}%)";
$last_tarif_id = $rr->tarif_id;
}
print "</div>";
echo "t</td></tr>rnt<tr><td align=right valign=top>Доп. услуги:</td><td colspan="2">rnt";
$r = @mysql_query( @"select * from tarifs where active=1 and vid='{$vid}' order by cost" );
while ( $rr = mysql_fetch_object( $r ) )
{
$addonsForTarif = split( ":x:", $rr->addons );
if ( $rr->id == $tarif_id )
{
$style = "style='display: block;'";
}
else
{
$style = "style='display: none;'";
}
print "<div id=a{$rr->id} {$style}>";
$v = each( @$addonsForTarif )[1];
$k = each( @$addonsForTarif )[0];
while ( @each( @$addonsForTarif ) )
{
if ( $v )
{
$oneAddon = getaddonbyid( $v );
if ( $oneAddon->active )
{
$addonMoney = "";
if ( $oneAddon->cost_start )
{
$addonMoney = "{$oneAddon->cost_start}$ разово";
if ( $oneAddon->cost_monthly )
{
$addonMoney = $addonMoney." + ";
}
}
if ( $oneAddon->cost_monthly )
{
$addonMoney = $addonMoney."{$oneAddon->cost_monthly} $/мес";
}
if ( !$addonMoney )
{
$addonMoney = "бесплатно";
}
print "<input type=checkbox name=addons[{$rr->id}][] value={$oneAddon->id}>{$oneAddon->name} ({$addonMoney})<BR>";
}
}
}
print "</div>";
}
print "</div>";
echo "t</td></tr>rnt<tr><td align=right><BR>* Способ оплаты:</td><Td><BR>";
echo "<s";
echo "elect name=paymethod><option>rnt";
if ( getsetting( "wmz" ) || getsetting( "wmr" ) || getsetting( "wme" ) )
{
print "<option>WebMoney</option>";
}
echo "t";
if ( getsetting( "yandex" ) )
{
print "<option>Яндекс.Деньги</option>";
}
echo "t";
if ( getsetting( "egold" ) )
{
print "<option>E-Gold</option>";
}
echo "t";
if ( getsetting( "rupayschet" ) )
{
print "<option>RuPay</option>";
}
echo "t</select></td></tr>rnt<tr><td valign=top align=right>Комментарий:</td><Td><textarea name=comment cols=25 rows=3></textarea></td></tr>rnt<tr><td> </td><td colspan="2"><BR><input type="submit" name="Submit" value="Заказать"></td></tr>rnt</table>rnt</form>rnrnt<br>Поля, отмеченные знаком *, обязательны для заполнения.rn<br><br>Перед заказом хостинга ознакомтесь с <b>Правилами</b>rnrnt";
foot( );
}
mclose( );
?>