Вход Регистрация
Файл: api.php
Строк: 1809
<?

$mtime 
microtime(); $mtime explode(" ",$mtime); $mtime $mtime[1] + $mtime[0]; $tstart $mtime

$full_home_path dirname(__FILE__);
require_once(
$full_home_path.'/_rootload.php');

if (
$language) {
    
$_lang LoadLanguageToVariable($language);
} else {
    
EnableLanguages(1);
}

if (
mconnect(1)) {
    if (
$login) {
        
$login strtolower($login);

        if (
$login != "test") {
            
$queryParametersForLog = @serialize($queryParametersForLog);
            
$APILogId AddAPILog($login,$command,'',$queryParametersForLog);
        } else {
            
$APILogId "";
        }


        if (
$login == "test" and $pass == "test") { 
            
$isTest 1

            
$user->id 9999;
            
$user->api 1;
            
$user->money 999999;
            
$user->currency "";
        } else { 
            
$isTest 0

            
$user GetUserByLogin($login);
        }

        if (
$user->id) {
            if (
$user->api) {
                if (
$pass and $apikey) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "9";
                    
#$res[errorMsg] = "Запрещено использовать пароль и ключ API в одном запросе";
                    
$res[errorMsg] = $_lang[ErrorAPIcode9];
                }
                else if (
$pass or $apikey) {

                    
$isAPI 1;

                    
$curr LoadCurrencyToVariable($user->currency);

                    
$chkProfile GetSetting("checkprofiletype",1); if ($chkProfile != "max") { $chkProfile "min"; }
                    
$company_name=GetSetting('company_name',1);
                    
$company_url=GetSetting('company_url',1);
                    
$billing_url=GetSetting('billing_url',1);
                    
$support_url=GetSetting('support_url',1);
                    
$manager_email=GetSetting('manager_email',1);

                    if (
$isTest or crypt($pass,$user->password) == $user->password or ($apikey == $user->apikey and $user->apikey) and !$user->banned) {




#############################################################################
#
# Создание профайла

#############################################################################

if ($command == "createProfile") {
    if (
checkProfile($chkProfile)) {
        if (
$ripn and !preg_match("/-RIPN$/ui",$ripn)) { $ripn $ripn."-RIPN"; }
        if (
$uanic and !preg_match("/-UANIC$/ui",$uanic)) { $uanic $uanic."-UANIC"; }
        if (
$ripe and !preg_match("/-RIPE$/ui",$ripe)) { $ripe $ripe."-RIPE"; }
        if (
$eunic and !preg_match("/-EUNIC$/ui",$eunic)) { $eunic $eunic."-EUNIC"; }
        if (
$dpnic and !preg_match("/-DPNIC$/ui",$dpnic)) { $dpnic $dpnic."-DPNIC"; }
        if (
$epnic and !preg_match("/-EPNIC$/ui",$dpnic)) { $epnic $epnic."-EPNIC"; }

        
$name = @mb_strtoupper(@mb_substr($name,0,1)).@mb_substr($name,1);
        
$otchestvo = @mb_strtoupper(@mb_substr($otchestvo,0,1)).@mb_substr($otchestvo,1);
        
$surname = @mb_strtoupper(@mb_substr($surname,0,1)).@mb_substr($surname,1);

        if (
$isTest or @mysql_query("INSERT INTO users_profile (uid,icq,name,otchestvo,firma,firmaeng,phone,mobile,fax,country,oblast,city,post,street,address_org,komu,pasport_seriya,pasport_by,ripn,ripe,uanic,eunic,dpnic,epnic,surname,pasport_date,birthday,inn,kpp,okonh,okpo,bank,bank_schet,bank_bik,edrpou,email,org,socstrahnumber,idnum,ogrn,ogrn_by,ogrn_date,skype) VALUES('$user->id','$icq','$name','$otchestvo','$firma','$firmaeng','$phone','$mobile','$fax','$country','$oblast','$city','$post','$street','$address_org','$komu','$seriya','$by','$ripn','$ripe','$uanic','$eunic','$dpnic','$epnic','$surname','".fromMyDate($date)."','".fromMyDate($birthday)."','$inn','$kpp','$okonh','$okpo','$bank','$bank_schet','$bank_bik','$edrpou','$email','$org','$socstrahnumber','$idnum','$ogrn','$ogrn_by','".fromMyDate($ogrn_date)."','$skype')")) {
            
$profile_id = @mysql_insert_id();
            if (
$isTest) { $profile_id mt_rand(10,500); }

            
$res[status] = "SUCCESS";
            
$res[profileid] = $profile_id;
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "2";
            
#$res[errorMsg] = "Ошибка сохранения данных профайла в БД: ".mysql_error();
            
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();
        }
    } else {
        
$res[status] = "ERROR";
        
$res[errorCode] = "11";
        
#$res[errorMsg] = "Ошибки в полях профайла: $GLOBALerrorFields";
        
$res[errorMsg] = $_lang[ErrorAPIcode11].": $GLOBALerrorFields";
    }
}


#############################################################################
#
# Изменение профайла

#############################################################################

else if ($command == "updateProfile") {
    if (
$profileid) {
        
$profile GetUserProfileByUserId($user->id,$profileid);
        if (
$isTest) { $profile->id $profileid; }
    } else {
        
$profile GetUserProfileByUserId($user->id);
        if (
$isTest) { $profile->id mt_rand(10,500); }
    }

    if (
$isTest or $profile->id) {
        
$fieldsCnt 0;

        
$org $profile->org;
        if (!isset(
$surname)) { $surname $profile->surname; } else { $fieldsCnt++; }
        if (!isset(
$name)) { $name $profile->name; } else { $fieldsCnt++; }
        if (!isset(
$otchestvo)) { $otchestvo $profile->otchestvo; } else { $fieldsCnt++; }
        if (!isset(
$firma)) { $firma $profile->firma; } else { $fieldsCnt++; }
        if (!isset(
$firmaeng)) { $firmaeng $profile->firmaeng; } else { $fieldsCnt++; }
        if (!isset(
$seriya)) { $seriya $profile->pasport_seriya; } else { $fieldsCnt++; }
        if (!isset(
$by)) { $by $profile->pasport_by; } else { $fieldsCnt++; }
        if (!isset(
$date)) { $date mydate($profile->pasport_date); } else { $fieldsCnt++; }
        if (!isset(
$birthday)) { $birthday mydate($profile->birthday); } else { $fieldsCnt++; }
        if (!isset(
$inn)) { $inn $profile->inn; } else { $fieldsCnt++; }
        if (!isset(
$kpp)) { $kpp $profile->kpp; } else { $fieldsCnt++; }
        if (!isset(
$country)) { $country $profile->country; } else { $fieldsCnt++; }
        if (!isset(
$oblast)) { $oblast $profile->oblast; } else { $fieldsCnt++; }
        if (!isset(
$post)) { $post $profile->post; } else { $fieldsCnt++; }
        if (!isset(
$city)) { $city $profile->city; } else { $fieldsCnt++; }
        if (!isset(
$street)) { $street $profile->street; } else { $fieldsCnt++; }
        if (!isset(
$address_org)) { $address_org $profile->address_org; } else { $fieldsCnt++; }
        if (!isset(
$komu)) { $komu $profile->komu; } else { $fieldsCnt++; }
        if (!isset(
$phone)) { $phone $profile->phone; } else { $fieldsCnt++; }
        if (!isset(
$mobile)) { $mobile $profile->mobile; } else { $fieldsCnt++; }
        if (!isset(
$fax)) { $fax $profile->fax; } else { $fieldsCnt++; }
        if (!isset(
$email)) { $email $profile->email; } else { $fieldsCnt++; }
        if (!isset(
$icq)) { $icq $profile->icq; } else { $fieldsCnt++; }
        if (!isset(
$skype)) { $icq $profile->skype; } else { $fieldsCnt++; }
        if (!isset(
$ripn) or isset($ripn) and !$ripn) { $ripn $profile->ripn; } else { $fieldsCnt++; }
        if (!isset(
$ripe) or isset($ripe) and !$ripe) { $ripe $profile->ripe; } else { $fieldsCnt++; }
        if (!isset(
$uanic) or isset($uanic) and !$uanic) { $uanic $profile->uanic; } else { $fieldsCnt++; }
        if (!isset(
$eunic) or isset($eunic) and !$eunic) { $eunic $profile->eunic; } else { $fieldsCnt++; }
        if (!isset(
$dpnic) or isset($dpnic) and !$dpnic) { $dpnic $profile->dpnic; } else { $fieldsCnt++; }
        if (!isset(
$epnic) or isset($epnic) and !$epnic) { $epnic $profile->epnic; } else { $fieldsCnt++; }
        if (!isset(
$okonh)) { $okonh $profile->okonh; } else { $fieldsCnt++; }
        if (!isset(
$okpo)) { $okpo $profile->okpo; } else { $fieldsCnt++; }
        if (!isset(
$bank)) { $bank $profile->bank; } else { $fieldsCnt++; }
        if (!isset(
$bank_schet)) { $bank_schet $profile->bank_schet; } else { $fieldsCnt++; }
        if (!isset(
$bank_bik)) { $bank_bik $profile->bank_bik; } else { $fieldsCnt++; }
        if (!isset(
$edrpou)) { $edrpou $profile->edrpou; } else { $fieldsCnt++; }
        if (!isset(
$socstrahnumber)) { $socstrahnumber $profile->socstrahnumber; } else { $fieldsCnt++; }
        if (!isset(
$idnum)) { $idnum $profile->idnum; } else { $fieldsCnt++; }
        if (!isset(
$ogrn)) { $ogrn $profile->ogrn; } else { $fieldsCnt++; }
        if (!isset(
$ogrn_by)) { $ogrn_by $profile->ogrn_by; } else { $fieldsCnt++; }
        if (!isset(
$ogrn_date)) { $ogrn_date mydate($profile->ogrn_date); } else { $fieldsCnt++; }

        if (
$fieldsCnt 0) {
            if (
$ripn and !preg_match("/-RIPN$/ui",$ripn)) { $ripn $ripn."-RIPN"; }
            if (
$uanic and !preg_match("/-UANIC$/ui",$uanic)) { $uanic $uanic."-UANIC"; }
            if (
$ripe and !preg_match("/-RIPE$/ui",$ripe)) { $ripe $ripe."-RIPE"; }
            if (
$eunic and !preg_match("/-EUNIC$/ui",$eunic)) { $eunic $eunic."-EUNIC"; }
            if (
$dpnic and !preg_match("/-DPNIC$/ui",$dpnic)) { $dpnic $dpnic."-DPNIC"; }
            if (
$epnic and !preg_match("/-EPNIC$/ui",$epnic)) { $epnic $epnic."-EPNIC"; }

            
$name = @mb_strtoupper(@mb_substr($name,0,1)).@mb_substr($name,1);
            
$otchestvo = @mb_strtoupper(@mb_substr($otchestvo,0,1)).@mb_substr($otchestvo,1);
            
$surname = @mb_strtoupper(@mb_substr($surname,0,1)).@mb_substr($surname,1);

            if (
$isTest or checkProfile($chkProfile)) {
                if (
$isTest or @mysql_query("UPDATE users_profile SET icq = '$icq', name = '$name', otchestvo = '$otchestvo', firma = '$firma', firmaeng = '$firmaeng', phone = '$phone', mobile = '$mobile', fax = '$fax', country = '$country', oblast = '$oblast', city = '$city', post = '$post', street = '$street', address_org = '$address_org', komu = '$komu', pasport_seriya = '$seriya', pasport_by = '$by', ripn = '$ripn', ripe = '$ripe', uanic = '$uanic', eunic = '$eunic', dpnic = '$dpnic', epnic = '$epnic', surname = '$surname',pasport_date = '".fromMyDate($date)."',birthday = '".fromMyDate($birthday)."',inn = '$inn',kpp = '$kpp', okonh = '$okonh', okpo = '$okpo', bank = '$bank',bank_schet = '$bank_schet',bank_bik = '$bank_bik',edrpou='$edrpou',email='$email',org='$org',socstrahnumber='$socstrahnumber', idnum='$idnum', ogrn='$ogrn', ogrn_by='$ogrn_by', ogrn_date='".fromMyDate($ogrn_date)."',skype='$skype' WHERE uid = '$user->id' and id='$profile->id'")) {
                    
$res[status] = "SUCCESS";
                    
$res[profileid] = $profile->id;
                }
                else {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "2";
                    
#$res[errorMsg] = "Ошибка сохранения данных профайла в БД: ".mysql_error();
                    
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();
                }
            } else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "11";
                
#$res[errorMsg] = "Ошибки в полях профайла: $GLOBALerrorFields";
                
$res[errorMsg] = $_lang[ErrorAPIcode11].": $GLOBALerrorFields";
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "12";
            
#$res[errorMsg] = "Не указано ни одно из полей профайла для изменения";
            
$res[errorMsg] = $_lang[ErrorAPIcode12];
        }
    }
    else {
        
$res[status] = "ERROR";
        
$res[errorCode] = "10";
        
#$res[errorMsg] = "Профайл не найден";
        
$res[errorMsg] = $_lang[ErrorAPIcode10];
    }
}


#############################################################################
#
# Получение данных профайла

#############################################################################

else if ($command == "getProfile") {
    if (
$profileid) {
        
$profile GetUserProfileByUserId($user->id,$profileid);
    } else {
        
$profile GetUserProfileByUserId($user->id);
    }

    if (
$isTest or $profile->id) {
        if (
$profile->org) { $fields[org] = $profile->org; }
        if (
$profile->surname) { $fields[surname] = $profile->surname; }
        if (
$profile->name) { $fields[name] = $profile->name; }
        if (
$profile->otchestvo) { $fields[otchestvo] = $profile->otchestvo; }
        if (
$profile->firma) { $fields[firma] = $profile->firma; }
        if (
$profile->firmaeng) { $fields[firmaeng] = $profile->firmaeng; }
        if (
$profile->pasport_seriya) { $fields[seriya] = $profile->pasport_seriya; }
        if (
$profile->pasport_by) { $fields[pasport_by] = $profile->pasport_by; }
        if (
$profile->pasport_date) { $fields[date] = mydate($profile->pasport_date); }
        if (
$profile->birthday) { $fields[birthday] = mydate($profile->birthday); }
        if (
$profile->inn) { $fields[inn] = $profile->inn; }
        if (
$profile->kpp) { $fields[kpp] = $profile->kpp; }
        if (
$profile->country) { $fields[country] = $profile->country; }
        if (
$profile->oblast) { $fields[oblast] = $profile->oblast; }
        if (
$profile->post) { $fields[post] = $profile->post; }
        if (
$profile->city) { $fields[city] = $profile->city; }
        if (
$profile->street) { $fields[street] = $profile->street; }
        if (
$profile->address_org) { $fields[address_org] = $profile->address_org; }
        if (
$profile->komu) { $fields[komu] = $profile->komu; }
        if (
$profile->phone) { $fields[phone] = $profile->phone; }
        if (
$profile->mobile) { $fields[mobile] = $profile->mobile; }
        if (
$profile->fax) { $fields[fax] = $profile->fax; }
        if (
$profile->email) { $fields[email] = $profile->email; }
        if (
$profile->icq) { $fields[icq] = $profile->icq; }
        if (
$profile->skype) { $fields[skype] = $profile->skype; }
        if (
$profile->ripn) { $fields[ripn] = $profile->ripn; }
        if (
$profile->ripe) { $fields[ripe] = $profile->ripe; }
        if (
$profile->uanic) { $fields[uanic] = $profile->uanic; }
        if (
$profile->eunic) { $fields[eunic] = $profile->eunic; }
        if (
$profile->dpnic) { $fields[dpnic] = $profile->dpnic; }
        if (
$profile->epnic) { $fields[epnic] = $profile->epnic; }
        if (
$profile->okonh) { $fields[okonh] = $profile->okonh; }
        if (
$profile->okpo) { $fields[okpo] = $profile->okpo; }
        if (
$profile->bank) { $fields[bank] = $profile->bank; }
        if (
$profile->bank_schet) { $fields[bank_schet] = $profile->bank_schet; }
        if (
$profile->bank_bik) { $fields[bank_bik] = $profile->bank_bik; }
        if (
$profile->edrpou) { $fields[edrpou] = $profile->edrpou; }
        if (
$profile->socstrahnumber) { $fields[socstrahnumber] = $profile->socstrahnumber; }
        if (
$profile->idnum) { $fields[idnum] = $profile->idnum; }
        if (
$profile->ogrn) { $fields[ogrn] = $profile->ogrn; }
        if (
$profile->ogrn_by) { $fields[ogrn_by] = $profile->ogrn_by; }
        if (
$profile->ogrn_date) { $fields[ogrn_date] = mydate($profile->ogrn_date); }

        
$res[status] = "SUCCESS";
        
$res[profileid] = $profile->id;
        
$res[fields] = $fields;
    }
    else {
        
$res[status] = "ERROR";
        
$res[errorCode] = "10";
        
#$res[errorMsg] = "Профайл не найден";
        
$res[errorMsg] = $_lang[ErrorAPIcode10];
    }
}


#############################################################################
#
# Регистрация домена

#############################################################################

else if ($command == "registerDomain") {
    
$fulldomain=mb_strtolower($domain); 

    
preg_match("/^([^.]+).(.+)$/ui",$fulldomain,$arr);
    
$domain=$arr[1]; $zone=$arr[2];

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    }
    else if (!
$zone) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "14";
        
#$res[errorMsg] = "Не указана доменная зона";
        
$res[errorMsg] = $_lang[ErrorAPIcode14];
    }
    else {
        if (
preg_match("/.{0,1}[ru|su|рф]$/ui",$zone)) { $isR=1; }
        else { 
$isD=1; if ($zone == "pp.ua") { $isPPUA=1; } }

        
$zones=@mysql_query("select * from zones where zone='$zone' and active='1' order by isDefault desc");
        if (
$registratorid) {
            if (@
mysql_num_rows($zones) > 1) {
                
$zones=@mysql_query("select * from zones where zone='$zone' and autoreg='$registratorid' and active='1' order by isDefault desc");
            } else {
                
$zones "";
            }
        }
        
$zone=@mysql_fetch_object($zones);
        
$registrator=@mysql_query("select * from registrators where id='$zone->autoreg'");
        
$registrator=@mysql_fetch_object($registrator);

        if (!
$zone->id) {
            
$res[status] = "ERROR";
            
$res[errorCode] = "15";
            
#$res[errorMsg] = "Доменная зона указана неверно, либо она не активна";
            
$res[errorMsg] = $_lang[ErrorAPIcode15];
        }
        else {
            
$dom=new domain($fulldomain);
            
$k=@mysql_query("select * from orders_domains where domain='$fulldomain' and todate>NOW()");
            
$domainFreeLimit GetSetting("domainFreeLimit",1);

            if (
mb_strlen($domain) < $zone->minWidth or mb_strlen($domain) > $zone->maxWidth) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "16";
                
#$res[errorMsg] = "Длина доменного имени должна быть от $zone->minWidth до $zone->maxWidth символов";
                
$res[errorMsg] = $_lang[ErrorAPIcode16];
            }
            else if (
$zone->idn == "no" and !preg_match("/^[a-z0-9]{1}[a-z0-9-]*[a-z0-9]{1}$/u",$domain)) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "17";
                
#$res[errorMsg] = "Доменное имя может содержать только a-z, 0-9 и символ дефиса, при чем не должно начинаться с дефиса или заканчиваться на него";
                
$res[errorMsg] = $_lang[ErrorAPIcode17];
            }
            else if (
$zone->idn == "yes" and !preg_match("/^[a-zа-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ0-9]{1}[a-zа-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ0-9-]*[a-zа-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ0-9]{1}$/u",$domain)) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "17";
                
#$res[errorMsg] = "Доменное имя может содержать только a-z, 0-9, а-я и символ дефиса, при чем не должно начинаться с дефиса или заканчиваться на него";
                
$res[errorMsg] = $_lang[ErrorAPIcode17];
            }
            else if (
$zone->idn == "only" and !preg_match("/^[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ0-9]{1}[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ0-9-]*[а-яёЁїЇіІєЄӘәҒғҚқҢңӨөҮүҰұҺһ0-9]{1}$/u",$domain)) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "17";
                
#$res[errorMsg] = "Доменное имя может содержать только а-я, 0-9 и символ дефиса, при чем не должно начинаться с дефиса или заканчиваться на него";
                
$res[errorMsg] = $_lang[ErrorAPIcode17];
            }
            else if (!
$dom->is_available()) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "18";
                
#$res[errorMsg] = "Доменное имя занято";
                
$res[errorMsg] = $_lang[ErrorAPIcode18];
            }
            else if (!
$isTest and @mysql_num_rows($k) > 0) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "19";
                
#$res[errorMsg] = "Доменное имя уже заказано другим пользователем биллинговой системы";
                
$res[errorMsg] = $_lang[ErrorAPIcode19];
            }
            else if (!
$isTest and $zone->free and $domainFreeLimit and GetDomainsFreeCountTodayByUserId($user->id) >= $domainFreeLimit) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "20";
                
#$res[errorMsg] = "Превышен лимит на количество регистрируемых бесплатных доменных имен в день ($domainFreeLimit)";
                
$res[errorMsg] = $_lang[ErrorAPIcode20]." ($domainFreeLimit).";
            }
            else if (
$period <= 0) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "21";
                
#$res[errorMsg] = "Не указан срок регистрации доменного имени";
                
$res[errorMsg] = $_lang[ErrorAPIcode21];
            } 
            else if (
$period != ($zone->minsrok/12)) {
                
$res[status] = "ERROR";
                
$res[errorCode] = "22";
                
#$res[errorMsg] = "Допустимый срок регистрации доменного имени, г. - ".($zone->minsrok/12);
                
$res[errorMsg] = $_lang[ErrorAPIcode22]." - ".($zone->minsrok/12);
            } 
            else {
                
$ns1=trim(mb_strtolower($ns1)); $ns1 preg_replace("/.$/ui","",$ns1);
                
$ns2=trim(mb_strtolower($ns2)); $ns2 preg_replace("/.$/ui","",$ns2);
                
$ns3=trim(mb_strtolower($ns3)); $ns3 preg_replace("/.$/ui","",$ns3);
                
$ns4=trim(mb_strtolower($ns4)); $ns4 preg_replace("/.$/ui","",$ns4);

                
$ns1ip=trim($ns1ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns1ip)) { $ns1ip ""; }
                
$ns2ip=trim($ns2ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns2ip)) { $ns2ip ""; }
                
$ns3ip=trim($ns3ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns3ip)) { $ns3ip ""; } if (!$ns3) { $ns3ip ""; }
                
$ns4ip=trim($ns4ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns4ip)) { $ns4ip ""; } if (!$ns4) { $ns4ip ""; }

                if (
$defaultns and !$zone->enableDefaultNS) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "23";
                    
#$res[errorMsg] = "Возможность использования DNS-серверов по умолчанию отключена для доменной зоны";
                    
$res[errorMsg] = $_lang[ErrorAPIcode23];
                }
                else if (!
$defaultns and (!$ns1 or !preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns1) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns1))) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "24";
                    
#$res[errorMsg] = "Не указан или указан неверно первичный DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode24];
                }
                else if (!
$defaultns and (!$ns2 or !preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns2) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns2) or $ns1 == $ns2)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "25";
                    
#$res[errorMsg] = "Не указан или указан неверно вторичный DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode25];
                }
                else if (!
$defaultns and $ns3 and (!preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns3) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns3) or $ns3 == $ns1 or $ns3 == $ns2)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "26";
                    
#$res[errorMsg] = "Указан неверно третий DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode26];
                }
                else if (!
$defaultns and $ns4 and (!preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns4) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns4) or $ns4 == $ns1 or $ns4 == $ns2 or $ns4 == $ns3)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "27";
                    
#$res[errorMsg] = "Указан неверно четвертый DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode27];
                }
                else if (!
$defaultns and $registrator->type == "gfx" and (preg_match("/.$fulldomain$/u",$ns1) or preg_match("/.$fulldomain$/u",$ns2) or preg_match("/.$fulldomain$/u",$ns3) or preg_match("/.$fulldomain$/u",$ns4))) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "28";
                    
#$res[errorMsg] = "API не поддерживает работу с собственными DNS-серверами для данной доменной зоны";
                    
$res[errorMsg] = $_lang[ErrorAPIcode28];
                }
                else if (!
$defaultns and preg_match("/.$fulldomain$/u",$ns1) and !$ns1ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "45";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS1";
                    
$res[errorMsg] = $_lang[ErrorAPIcode45];
                }
                else if (!
$defaultns and $ns1ip and !preg_match("/.$fulldomain$/u",$ns1)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "46";
                    
#$res[errorMsg] = "Указан IP-адрес для NS1, который не является собственным DNS-сервером домена";
                    
$res[errorMsg] = $_lang[ErrorAPIcode46];
                }
                else if (!
$defaultns and preg_match("/.$fulldomain$/u",$ns2) and !$ns2ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "47";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS2";
                    
$res[errorMsg] = $_lang[ErrorAPIcode47];
                }
                else if (!
$defaultns and $ns2ip and !preg_match("/.$fulldomain$/u",$ns2)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "48";
                    
#$res[errorMsg] = "Указан IP-адрес для NS2, который не является собственным DNS-сервером домена";
                    
$res[errorMsg] = $_lang[ErrorAPIcode48];
                }
                else if (!
$defaultns and $ns3 and preg_match("/.$fulldomain$/u",$ns3) and !$ns3ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "49";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS3";
                    
$res[errorMsg] = $_lang[ErrorAPIcode49];
                }
                else if (!
$defaultns and $ns3ip and !preg_match("/.$fulldomain$/u",$ns3)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "50";
                    
#$res[errorMsg] = "Указан IP-адрес для NS3, который не является собственным DNS-сервером домена";
                    
$res[errorMsg] = $_lang[ErrorAPIcode50];
                }
                else if (!
$defaultns and $ns4 and preg_match("/.$fulldomain$/u",$ns4) and !$ns4ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "51";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS4";
                    
$res[errorMsg] = $_lang[ErrorAPIcode51];
                }
                else if (!
$defaultns and $ns4ip and !preg_match("/.$fulldomain$/u",$ns4)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "52";
                    
#$res[errorMsg] = "Указан IP-адрес для NS4, который не является собственным DNS-сервером домена";
                    
$res[errorMsg] = $_lang[ErrorAPIcode52];
                }
                else if (!
$defaultns and $zone->enableCheckNS and !checkDNS($fulldomain$zone->id$ns1$ns2$ns3$ns4)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "29";
                    
#$res[errorMsg] = "Ошибка проверки DNS-серверов: $GLOBALerror";
                    
$res[errorMsg] = $_lang[ErrorAPIcode29].": $GLOBALerror";
                }
                else {
                    if (!
$profileid) { 
                        
$profile GetUserProfileByUserId($user->id);
                        if (
$isTest) { $profile->id mt_rand(10,500); }
                    } else {
                        
$profile GetUserProfileByUserId($user->id,$profileid);
                        if (
$isTest) { $profile->id $profileid; }
                    }

                    if (
$isR) { $chkProfile "max"; } else { $chkProfile "min"; }
                    if (
$isPPUA) { $rF[] = "mobile"; }

                    if (!
$profile->id) {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "10";
                        
#$res[errorMsg] = "Профайл не найден";
                        
$res[errorMsg] = $_lang[ErrorAPIcode10];
                    }
                    else if (!
$isTest and !checkProfile($chkProfile$user->id$profile->id$rF)) {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "11";
                        
#$res[errorMsg] = "Ошибки в полях профайла: $GLOBALerrorFields";
                        
$res[errorMsg] = $_lang[ErrorAPIcode11].": $GLOBALerrorFields";
                    }
                    else {
                        
$domainCost GetDomainCostForUserByZoneId($user->id,$zone->id,0);
                        
$domainCost $domainCost*($zone->minsrok/12);

                        if (
$defaultns) {
                            
$ns1 $zone->defaultNS1;
                            
$ns2 $zone->defaultNS2;
                            
$ns3 $zone->defaultNS3;
                            
$ns4 $zone->defaultNS4;
                        }

                        if (
$isTest or @mysql_query("insert into orders_domains (uid,zone_id,domain,orderdate,ns1,ns2,ns3,ns4,ns1ip,ns2ip,ns3ip,ns4ip,profileId,defaultNSFlag) values ('$user->id','$zone->id','$fulldomain',NOW(),'$ns1','$ns2','$ns3','$ns4','$ns1ip','$ns2ip','$ns3ip','$ns4ip','$profile->id','$defaultns')")) {
                            
$domain_id=@mysql_insert_id();
                            if (
$isTest) { $domain_id mt_rand(10,500); }

                            if (!
$isTest and $zone->free) {
                                
$domFreeCnt GetDomainsFreeCountTodayByUserId($user->id);
                                if (
$domFreeCnt 0) {
                                    @
mysql_query("update users set freeDomainCount=freeDomainCount+1 where id='$user->id'");
                                } else {
                                    @
mysql_query("update users set freeDomainCount=1,freeDomainDay=NOW() where id='$user->id'");
                                }
                            }

                            
$history "Домен: <B>$fulldomain</B>, ".($zone->minsrok/12)." г.";

                            if (
$isTest or @mysql_query("insert into bills (uid,domain_id,domain_srok,money_domain,created,history) values('$user->id','$domain_id','$zone->minsrok','$domainCost',NOW(),'$history')")) {
                                
$bill_id=mysql_insert_id();

                                if (
$user->money >= $domainCost) {
                                    if (
$isTest or @mysql_query("UPDATE users set money=money-$domainCost WHERE id='$user->id'")) {
                                        if (
$isTest or @mysql_query("update bills set payed=NOW(),payeddt=NOW(),status='1' where id='$bill_id'")) {
                                            if (
$isTest or @mysql_query("update orders_domains set startdate=NOW(), todate=DATE_ADD(NOW(),INTERVAL ".$zone->minsrok." MONTH) where id='$domain_id'")) {
                                                
$balanceRounded round(($user->money-$domainCost)*$curr["CURK"],2);
                                                
$costRounded round($domainCost*$curr["CURK"],2);

                                                if (!
$isTest) { MakePartnersProcentsByBillId($bill_id); }

                                                if (
$isTest or regDomain($domain_id$period)) {
                                                    
$res[status] = "SUCCESS";
                                                    
$res[domain] = "$fulldomain";
                                                    
$res[period] = "$period";
                                                    
$res[profileid] = "$profile->id";
                                                    
$res[defaultns] = "$defaultns";
                                                    if (
$ns1) { $res[ns1] = "$ns1"; }
                                                    if (
$ns2) { $res[ns3] = "$ns2"; }
                                                    if (
$ns3) { $res[ns4] = "$ns3"; }
                                                    if (
$ns4) { $res[ns5] = "$ns4"; }
                                                    if (
$ns1ip) { $res[ns1ip] = "$ns1ip"; }
                                                    if (
$ns2ip) { $res[ns3ip] = "$ns2ip"; }
                                                    if (
$ns3ip) { $res[ns4ip] = "$ns3ip"; }
                                                    if (
$ns4ip) { $res[ns5ip] = "$ns4ip"; }
                                                    
$res[balance] = "$balanceRounded";
                                                    
$res[cost] = "$costRounded";
                                                    
$res[currency] = $curr["CURC"];
                                                }
                                                else {
                                                    
$res[status] = "SUCCESS";
                                                    
$res[errorCode] = "30";
                                                    
#$res[errorMsg] = "Заявка принята, но по техническим причинам будет обработана в ручном режиме";
                                                    
$res[errorMsg] = $_lang[ErrorAPIcode30];
                                                    
$res[domain] = "$fulldomain";
                                                    
$res[period] = "$period";
                                                    
$res[profileid] = "$profile->id";
                                                    
$res[defaultns] = "$defaultns";
                                                    if (
$ns1) { $res[ns1] = "$ns1"; }
                                                    if (
$ns2) { $res[ns3] = "$ns2"; }
                                                    if (
$ns3) { $res[ns4] = "$ns3"; }
                                                    if (
$ns4) { $res[ns5] = "$ns4"; }
                                                    if (
$ns1ip) { $res[ns1ip] = "$ns1ip"; }
                                                    if (
$ns2ip) { $res[ns3ip] = "$ns2ip"; }
                                                    if (
$ns3ip) { $res[ns4ip] = "$ns3ip"; }
                                                    if (
$ns4ip) { $res[ns5ip] = "$ns4ip"; }
                                                    
$res[balance] = "$balanceRounded";
                                                    
$res[cost] = "$costRounded";
                                                    
$res[currency] = $curr["CURC"];

                                                }
                                            }
                                            else {
                                                
$res[status] = "ERROR";
                                                
$res[errorCode] = "2";
                                                
#$res[errorMsg] = "Ошибка сохранения данных статуса заказа в БД: ".mysql_error();
                                                
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                                @
mysql_query("UPDATE users set money=money+$domainCost WHERE id='$user->id'");
                                                @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                                @
mysql_query("DELETE FROM orders_domains WHERE id='$domain_id'");
                                            }
                                        }
                                        else {
                                            
$res[status] = "ERROR";
                                            
$res[errorCode] = "2";
                                            
#$res[errorMsg] = "Ошибка сохранения данных статуса счета в БД: ".mysql_error();
                                            
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                            @
mysql_query("UPDATE users set money=money+$domainCost WHERE id='$user->id'");
                                            @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                            @
mysql_query("DELETE FROM orders_domains WHERE id='$domain_id'");
                                        }
                                    } 
                                    else {
                                        
$res[status] = "ERROR";
                                        
$res[errorCode] = "2";
                                        
#$res[errorMsg] = "Ошибка сохранения данных баланса пользователя в БД: ".mysql_error();
                                        
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                        @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                        @
mysql_query("DELETE FROM orders_domains WHERE id='$domain_id'");
                                    }
                                }
                                else {
                                    
$res[status] = "ERROR";
                                    
$res[errorCode] = "31";
                                    
#$res[errorMsg] = "Недостаточно среств на внутреннем балансе";
                                    
$res[errorMsg] = $_lang[ErrorAPIcode31];

                                    @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                    @
mysql_query("DELETE FROM orders_domains WHERE id='$domain_id'");
                                }

                                if (!
$isTest and $res[status] == "SUCCESS") {
                                    
$sid=sprintf("%04d"$bill_id);

                                    
addUserLog($user->id,'orderdomain',"$fulldomain, ".(($zone->minsrok/12))." г.");
                                         
addUserLog($user->id"pay""Bill № $sid via API");

                                    
$tpl=GetTpl('email_touser_domain_order'$user->lang);
                                    
$subject $tpl[subject]; $template $tpl[template];
                
                                    if (
$subject and $template) {
                                        
$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('{domain}',$fulldomain,$template);
                                        
$template str_replace('{login}',$user->login,$template);
                                        
$template str_replace('{password}','******',$template);
                                        
$template str_replace('{schet}',$sid,$template);
                                        
$template str_replace('{domaincost}',$costRounded." ".$curr["CURS"],$template);
                                        
$template str_replace('{cost}',$costRounded." ".$curr["CURS"],$template);
                                        
$template str_replace('{srok}',($zone->minsrok/12),$template);
                                        
$template str_replace('{paymethod}','',$template);
                                        
$template str_replace('{comment}',$comment,$template);
                                        if (
$ns1 or $ns2) { $ns "NS1: $ns1nNS2$ns2nNS3$ns3nNS4$ns4nn"; }
                                        
$template str_replace('{ns}',$ns,$template);
                                        
$template str_replace('{userid}',$user->id,$template);
                    
                                        
WriteMailLog($subject,$template,$user->id);
                                        
sendmail($user->email,$company_name,$manager_email,$subject,$template,'','',$tpl[type]);
                                        
sendmail($user->email2,$company_name,$manager_email,$subject,$template,'','',$tpl[type]);

                                        
$subject "Duplicate: ".$subject;

                                        
$admEmails=GetAdminEmailsWhereTrueParam("sendneworder");
                                        if (
count($admEmails) > 0) {
                                            
WriteMailLog($subject,$template);
                                        }
                                        while (list(
$i,$em) = @each($admEmails)) {
                                            
sendmail($em,'',$manager_email,$subject,$template,'','',$tpl[type]);
                                        }
                                    }
                                }

                            } 
                            else {
                                
$res[status] = "ERROR";
                                
$res[errorCode] = "2";
                                
#$res[errorMsg] = "Ошибка сохранения данных счета в БД: ".mysql_error();
                                
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                @
mysql_query("DELETE FROM orders_domains WHERE id='$domain_id'");
                            }


                        }
                        else {
                            
$res[status] = "ERROR";
                            
$res[errorCode] = "2";
                            
#$res[errorMsg] = "Ошибка сохранения данных заказа в БД: ".mysql_error();
                            
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();
                        }
                    }
                }
            }
        }

    }
}


#############################################################################
#
# Продление домена

#############################################################################

else if ($command == "renewDomain") {
    
$fulldomain=mb_strtolower($domain); 

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    } else {
        
$domain GetDomainByDomain($fulldomain);

        if (
$isTest or ($domain->id and $domain->uid == $user->id)) {
            
$zone GetZoneById($domain->zone_id);
            
            if (
$isTest or $zone->id) {
                if (
$period <= 0) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "34";
                    
#$res[errorMsg] = "Не указан срок продления доменного имени";
                    
$res[errorMsg] = $_lang[ErrorAPIcode34];
                } 
                else if (!
$isTest and $period != ($zone->minsrok_renew/12)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "35";
                    
#$res[errorMsg] = "Допустимый срок продления доменного имени, г. - ".($zone->minsrok_renew/12);
                    
$res[errorMsg] = $_lang[ErrorAPIcode35]." - ".($zone->minsrok_renew/12);
                }
                else {
                            
$b=mysql_query("select * from bills where archived=0 and domain_id = '$domain->id' and uid='$user->id'");
                            
$bills=mysql_num_rows($b);
                            
$bp=mysql_query("select * from bills where archived=0 and domain_id = '$domain->id' and uid='$user->id' and !(status='0')") or die("File: ".__FILE__."<BR>Line: ".__LINE__."<BR>MySQL Error: ".mysql_error());
                            
$billspayed=mysql_num_rows($bp);
                            
$billsNonPayed $bills-$billspayed;

                    if (!
$isTest and $billsNonPayed != 0) {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "36";
                        
#$res[errorMsg] = "Операция не возможна, т.к. для заказа есть неоплаченные счета";
                        
$res[errorMsg] = $_lang[ErrorAPIcode36];
                    }
                    else if (!
$isTest and $domain->todate == "0000-00-00") {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "37";
                        
#$res[errorMsg] = "Операция не возможна, т.к. заказ не обработан";
                        
$res[errorMsg] = $_lang[ErrorAPIcode37];
                    }
                    else if (!
$isTest and $zone->daysRenew and $zone->daysRenew $domain->leftdays) {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "38";
                        
#$res[errorMsg] = "Продление доменного имени не возможно ранее чем за $zone->daysRenew дней до окончания срока регистрации.";
                        
$res[errorMsg] = $_lang[ErrorAPIcode38]." (X = $zone->daysRenew)";
                    }
                    else {
                        
$domainCost GetDomainCostRenewForUserByZoneId($user->id,$zone->id,0);
                        
$domainCost $domainCost*($zone->minsrok_renew/12);
                        
$domainDiscount $domain->discount;
                        
$domainCost $domainCost - ($domainCost/100)*$domainDiscount;

                        
$history "Домен: <B>$domain->domain</B>, ".($zone->minsrok_renew/12)." г.";

                        if (
$isTest or @mysql_query("insert into bills (uid,domain_id,domain_srok,money_domain,created,renew,history) values('$user->id','$domain->id','$zone->minsrok_renew','$domainCost',NOW(),'1','$history')")) {
                            
$bill_id=mysql_insert_id();

                            if (
$user->money >= $domainCost) {
                                if (
$isTest or @mysql_query("UPDATE users set money=money-$domainCost WHERE id='$user->id'")) {
                                    if (
$isTest or @mysql_query("update bills set payed=NOW(),payeddt=NOW(),status='1' where id='$bill_id'")) {
                                        if (
$isTest or @mysql_query("update orders_domains set todate=DATE_ADD(todate,INTERVAL ".$zone->minsrok_renew." MONTH) where id='$domain->id'")) {
                                            
$balanceRounded round(($user->money-$domainCost)*$curr["CURK"],2);
                                            
$costRounded round($domainCost*$curr["CURK"],2);

                                            if (!
$isTest) { MakePartnersProcentsByBillId($bill_id); }

                                            if (
$isTest or renewDomain($domain->id$period)) {
                                                
$res[status] = "SUCCESS";
                                                
$res[domain] = "$fulldomain";
                                                
$res[period] = "$period";
                                                
$res[balance] = "$balanceRounded";
                                                
$res[cost] = "$costRounded";
                                                
$res[currency] = $curr["CURC"];

                                            }
                                            else {
                                                
$res[status] = "SUCCESS";
                                                
$res[errorCode] = "30";
                                                
#$res[errorMsg] = "Заявка принята, но по техническим причинам будет обработана в ручном режиме";
                                                
$res[errorMsg] = $_lang[ErrorAPIcode30];
                                                
$res[domain] = "$fulldomain";
                                                
$res[period] = "$period";
                                                
$res[balance] = "$balanceRounded";
                                                
$res[cost] = "$costRounded";
                                                
$res[currency] = $curr["CURC"];

                                            }
                                        }
                                        else {
                                            
$res[status] = "ERROR";
                                            
$res[errorCode] = "2";
                                            
#$res[errorMsg] = "Ошибка сохранения данных статуса заказа в БД: ".mysql_error();
                                            
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                            @
mysql_query("UPDATE users set money=money+$domainCost WHERE id='$user->id'");
                                            @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                        }
                                    }
                                    else {
                                        
$res[status] = "ERROR";
                                        
$res[errorCode] = "2";
                                        
#$res[errorMsg] = "Ошибка сохранения данных статуса счета в БД: ".mysql_error();
                                        
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                        @
mysql_query("UPDATE users set money=money+$domainCost WHERE id='$user->id'");
                                        @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                    }
                                } 
                                else {
                                    
$res[status] = "ERROR";
                                    
$res[errorCode] = "2";
                                    
#$res[errorMsg] = "Ошибка сохранения данных баланса пользователя в БД: ".mysql_error();
                                    
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();

                                    @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                                }
                            }
                            else {
                                
$res[status] = "ERROR";
                                
$res[errorCode] = "31";
                                
#$res[errorMsg] = "Недостаточно среств на внутреннем балансе";
                                
$res[errorMsg] = $_lang[ErrorAPIcode31];

                                @
mysql_query("DELETE FROM bills WHERE id='$bill_id'");
                            }

                            if (!
$isTest and $res[status] == "SUCCESS") {
                                
$sid=sprintf("%04d"$bill_id);

                                     
addUserLog($user->id"renewdomain""$domain->domain, ".($zone->minsrok_renew/12)." г.");
                                     
addUserLog($user->id"pay""Bill № $sid via API");

                                
$tpl=GetTpl('email_touser_domain_renew'$user->lang);
                                
$subject $tpl[subject]; $template $tpl[template];

                                if (
$subject and $template) {
                                    
$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('{domain}',$domain->domain,$template);
                                         
$template str_replace('{srok}',($zone->minsrok_renew/12),$template);
                                         
$template str_replace('{login}',$user->login,$template);
                                         
$template str_replace('{password}',"******",$template);
                                         
$template str_replace('{schet}',$sid,$template);
                                         
$template str_replace('{domaincost}',$costRounded." ".$curr["CURS"],$template);
                                         
$template str_replace('{cost}',$costRounded." ".$curr["CURS"],$template);
                                         
$template str_replace('{userid}',$user->id,$template);
                     
                                    
WriteMailLog($subject,$template,$user->id);
                                    
sendmail($user->email,$company_name,$manager_email,$subject,$template,'','',$tpl[type]);
                                    
sendmail($user->email2,$company_name,$manager_email,$subject,$template,'','',$tpl[type]);
                        
                                    
$admEmails=GetAdminEmailsWhereTrueParam("sendneworder");
                                    if (
count($admEmails) > 0) {
                                        
WriteMailLog("Duplicate: ".$subject,$template);
                                    }
                                    while (list(
$i,$em) = @each($admEmails)) {
                                        
sendmail($em,'',$manager_email,"Duplicate: ".$subject,$template,'','',$tpl[type]);
                                    }
                                }
                            }
                        } else {
                            
$res[status] = "ERROR";
                            
$res[errorCode] = "2";
                            
#$res[errorMsg] = "Ошибка сохранения данных счета в БД: ".mysql_error();
                            
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();
                        }
                    }
                }

            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "33";
                
#$res[errorMsg] = "Доменная зона для заказа не найдена";
                
$res[errorMsg] = $_lang[ErrorAPIcode33];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "32";
            
#$res[errorMsg] = "Заказ на доменное имя не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode32];
        }
    }
}


#############################################################################
#
# Изменение контактов для домена

#############################################################################

else if ($command == "updateDomainContacts") {
    
$fulldomain=mb_strtolower($domain); 

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    } else {
        
$domain GetDomainByDomain($fulldomain);

        if (
$isTest or ($domain->id and $domain->uid == $user->id)) {
            
$zone GetZoneById($domain->zone_id);
            
            if (
$isTest or $zone->id) {
                if (
preg_match("/.{0,1}[ru|su|рф]$/ui",$zone->zone)) { $isR=1; }
                else { 
$isD=1; if ($zone->zone == "pp.ua") { $isPPUA=1; } }

                if (
$profileid) {
                    
$profile GetUserProfileByUserId($user->id,$profileid);
                } else {
                    
$profile GetUserProfileByUserId($user->id);
                }

                if (
$isR) { $chkProfile "max"; } else { $chkProfile "min"; }
                if (
$isPPUA) { $rF[] = "mobile"; }

                
$registrator GetRegistratorTypeById($domain->autoregby);
                
$currentProfile GetUserProfileByUserId($user->id$domain->profileId);

                if (!
$isTest and !$profile->id) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "10";
                    
#$res[errorMsg] = "Профайл не найден";
                    
$res[errorMsg] = $_lang[ErrorAPIcode10];
                }
                else if (!
$isTest and !checkProfile($chkProfile$user->id$profile->id$rF)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "11";
                    
#$res[errorMsg] = "Ошибки в полях профайла: $GLOBALerrorFields";
                    
$res[errorMsg] = $_lang[ErrorAPIcode11].": $GLOBALerrorFields";
                }
                else if (!
$isTest and ($registrator == "webnames" or $registrator == "regru") and $profile->id != $currentProfile->id and $profile->org != $currentProfile->org) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "39";
                    
#$res[errorMsg] = "Тип профайла не должен отличаться от типа профайла на который изначально регистрировался домен";
                    
$res[errorMsg] = $_lang[ErrorAPIcode39];
                }
                else if (!
$isTest and ($domain->todate == "0000-00-00" or $domain->status != "1")) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "37";
                    
#$res[errorMsg] = "Операция не возможна, т.к. заказ не обработан";
                    
$res[errorMsg] = $_lang[ErrorAPIcode37];
                }
                else if (!
$isTest and $domain->leftdays 0) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "40";
                    
#$res[errorMsg] = "Операция не возможна, т.к. заказ просрочен";
                    
$res[errorMsg] = $_lang[ErrorAPIcode40];
                }
                else if (!
$isTest and $registrator != "r01" and $registrator != "internetx" and $registrator != "ukrnames" and $registrator != "ppua" and $registrator != "websitews" and $registrator != "dotfm" and $registrator != "niclv" and $registrator != "epag" and $registrator != "todaynic" and $registrator != "rrpproxy" and $registrator != "webnames" and $registrator != "regru" and $registrator != "cnic" and $registrator != "gfx" and $registrator != "internetbs" and $registrator != "hostmasterepp" and $registrator != "nicdpua" and $registrator != "pskz") {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "41";
                    
#$res[errorMsg] = "Операция не поддерживается для данной доменной зоны";
                    
$res[errorMsg] = $_lang[ErrorAPIcode41];
                }
                else if (!
$isTest and $domain->localContact and ($registrator == "r01" or $registrator == "internetx" or $registrator == "epag" or $registrator == "rrpproxy" or $registrator == "webnames" or $registrator == "regru" or $registrator == "rootpanel")) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "41";
                    
#$res[errorMsg] = "Операция не поддерживается для данной доменной зоны, т.к. для домена установлен локальный контакт.";
                    
$res[errorMsg] = $_lang[ErrorAPIcode41];
                }
                else {
                    if (
$isTest or updateDomainContact($domain->id$profile->id)) {
                        
$res[status] = "SUCCESS";
                        
$res[domain] = "$fulldomain";
                    }
                    else {
                        
$res[status] = "SUCCESS";
                        
$res[errorCode] = "30";
                        
#$res[errorMsg] = "Заявка принята, но по техническим причинам будет обработана в ручном режиме";
                        
$res[errorMsg] = $_lang[ErrorAPIcode30];
                        
$res[domain] = "$fulldomain";
                    }
                }
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "33";
                
#$res[errorMsg] = "Доменная зона для заказа не найдена";
                
$res[errorMsg] = $_lang[ErrorAPIcode33];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "32";
            
#$res[errorMsg] = "Заказ на доменное имя не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode32];
        }
    }
}


#############################################################################
#
# Получение DNS-серверов для домена

#############################################################################

else if ($command == "getDNS") {
    
$fulldomain=mb_strtolower($domain); 

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    } else {
        
$domain GetDomainByDomain($fulldomain);
        
$zone GetZoneById($domain->zone_id);

        if (
$isTest or ($domain->id and $domain->uid == $user->id)) {
            if (
$isTest or $zone->id) {
                if (
$domain->ns1 or $domain->ns2 or $domain->ns3 or $domain->ns4) {
                    
$ns1 $domain->ns1;
                    
$ns1ip $domain->ns1ip;
                    
$ns2 $domain->ns2;
                    
$ns2ip $domain->ns2ip;
                    
$ns3 $domain->ns3;
                    
$ns3ip $domain->ns3ip;
                    
$ns4 $domain->ns4;
                    
$ns4ip $domain->ns4ip;
                } 
                else {
                    
$d = new domain($fulldomain);
                    
$result $d->info();
    
                    if (!
$d->last_error) {
                        
$result1 mb_split("n"$result);
                        while (list(
$index,$res) = each($result1)) {
                            if (
preg_match("/nserver/ui",$res)) {
                                
preg_match("/nserver:s*(.*)/iu",$res,$arr);
                                
$resultarray[]=$arr[1];
                            } else if (
preg_match("/Name Server/ui",$res)) {
                                
preg_match("/Name Server:s*(.*)/iu",$res,$arr);
                                
$resultarray[]=$arr[1];
                            }
                        }
                        
$ns1 $resultarray[0];
                        
$ns2 $resultarray[1];
                        
$ns3 $resultarray[2];
                        
$ns4 $resultarray[3];
                    }
                }

                if (!
$d->last_error) {
                    if (
$ns1 or $ns2 or $ns3 or $ns4) {
                            
$res[status] = "SUCCESS";
                            
$res[domain] = "$fulldomain";
                            if (
$ns1) { $res[ns1] = "$ns1"; }
                            if (
$ns2) { $res[ns2] = "$ns2"; }
                            if (
$ns3) { $res[ns3] = "$ns3"; }
                            if (
$ns4) { $res[ns4] = "$ns4"; }
                            if (
$ns1ip) { $res[ns1ip] = "$ns1ip"; }
                            if (
$ns2ip) { $res[ns2ip] = "$ns2ip"; }
                            if (
$ns3ip) { $res[ns3ip] = "$ns3ip"; }
                            if (
$ns4ip) { $res[ns4ip] = "$ns4ip"; }
                    }
                    else {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "53";
                        
#$res[errorMsg] = "Ошибка получения DNS-серверов";
                        
$res[errorMsg] = $_lang[ErrorAPIcode53];
                    }
                }
                else {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "53";
                    
#$res[errorMsg] = "Ошибка получения DNS-серверов ($d->last_error)";
                    
$res[errorMsg] = $_lang[ErrorAPIcode53]." ($d->last_error)";
                }
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "33";
                
#$res[errorMsg] = "Доменная зона для заказа не найдена";
                
$res[errorMsg] = $_lang[ErrorAPIcode33];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "32";
            
#$res[errorMsg] = "Заказ на доменное имя не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode32];
        }
    }
}


#############################################################################
#
# Изменение DNS-серверов для домена

#############################################################################

else if ($command == "updateDNS") {
    
$fulldomain=mb_strtolower($domain); 

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    } else {
        
$domain GetDomainByDomain($fulldomain);

        if (
$isTest or ($domain->id and $domain->uid == $user->id)) {
            
$zone GetZoneById($domain->zone_id);
            
$registrator=@mysql_query("select * from registrators where id='$zone->autoreg'");
            
$registrator=@mysql_fetch_object($registrator);
            
            if (
$isTest or $zone->id) {
                
$ns1=trim(mb_strtolower($ns1)); $ns1 preg_replace("/.$/ui","",$ns1);
                
$ns2=trim(mb_strtolower($ns2)); $ns2 preg_replace("/.$/ui","",$ns2);
                
$ns3=trim(mb_strtolower($ns3)); $ns3 preg_replace("/.$/ui","",$ns3);
                
$ns4=trim(mb_strtolower($ns4)); $ns4 preg_replace("/.$/ui","",$ns4);

                
$ns1ip=trim($ns1ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns1ip)) { $ns1ip ""; }
                
$ns2ip=trim($ns2ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns2ip)) { $ns2ip ""; }
                
$ns3ip=trim($ns3ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns3ip)) { $ns3ip ""; } if (!$ns3) { $ns3ip ""; }
                
$ns4ip=trim($ns4ip); if (!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns4ip)) { $ns4ip ""; } if (!$ns4) { $ns4ip ""; }

                if (
$domain->ns1) { $oldns1 $domain->ns1$oldns1ip $domain->ns1ip; }
                if (
$domain->ns2) { $oldns2 $domain->ns2$oldns2ip $domain->ns2ip; }
                if (
$domain->ns3) { $oldns3 $domain->ns3$oldns3ip $domain->ns3ip; }
                if (
$domain->ns4) { $oldns4 $domain->ns4$oldns4ip $domain->ns4ip; }

                if (
$defaultns and !$zone->enableDefaultNS) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "23";
                    
#$res[errorMsg] = "Возможность использования DNS-серверов по умолчанию отключена для доменной зоны";
                    
$res[errorMsg] = $_lang[ErrorAPIcode23];
                }
                else if (!
$defaultns and (!$ns1 or !preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns1) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns1))) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "24";
                    
#$res[errorMsg] = "Не указан или указан неверно первичный DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode24];
                }
                else if (!
$defaultns and (!$ns2 or !preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns2) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns2) or $ns1 == $ns2)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "25";
                    
#$res[errorMsg] = "Не указан или указан неверно вторичный DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode25];
                }
                else if (!
$defaultns and $ns3 and (!preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns3) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns3) or $ns3 == $ns1 or $ns3 == $ns2)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "26";
                    
#$res[errorMsg] = "Указан неверно третий DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode26];
                }
                else if (!
$defaultns and $ns4 and (!preg_match("/^[a-z0-9]{1}[a-z0-9-]*.[a-z0-9-.]*[a-z0-9]{1}$/u",$ns4) or preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/u",$ns4) or $ns4 == $ns1 or $ns4 == $ns2 or $ns4 == $ns3)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "27";
                    
#$res[errorMsg] = "Указан неверно четвертый DNS-сервер";
                    
$res[errorMsg] = $_lang[ErrorAPIcode27];
                }
                else if (!
$defaultns and $registrator->type == "gfx" and (preg_match("/.$fulldomain$/u",$ns1) or preg_match("/.$fulldomain$/u",$ns2) or preg_match("/.$fulldomain$/u",$ns3) or preg_match("/.$fulldomain$/u",$ns4))) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "28";
                    
#$res[errorMsg] = "API не поддерживает работу с собственными DNS-серверами для данной доменной зоны";
                    
$res[errorMsg] = $_lang[ErrorAPIcode28];
                }
                else if (!
$defaultns and preg_match("/.$fulldomain$/u",$ns1) and !$ns1ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "45";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS1.";
                    
$res[errorMsg] = $_lang[ErrorAPIcode45];
                }
                else if (!
$defaultns and $ns1ip and !preg_match("/.$fulldomain$/u",$ns1)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "46";
                    
#$res[errorMsg] = "Указан IP-адрес для NS1, который не является собственным DNS-сервером домена";
                    
$res[errorMsg] = $_lang[ErrorAPIcode46];
                }
                else if (!
$defaultns and preg_match("/.$fulldomain$/u",$ns2) and !$ns2ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "47";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS2.";
                    
$res[errorMsg] = $_lang[ErrorAPIcode47];
                }
                else if (!
$defaultns and $ns2ip and !preg_match("/.$fulldomain$/u",$ns2)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "48";
                    
#$res[errorMsg] = "Указан IP-адрес для NS2, который не является собственным DNS-сервером домена.";
                    
$res[errorMsg] = $_lang[ErrorAPIcode48];
                }
                else if (!
$defaultns and $ns3 and preg_match("/.$fulldomain$/u",$ns3) and !$ns3ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "49";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS3";
                    
$res[errorMsg] = $_lang[ErrorAPIcode49];
                }
                else if (!
$defaultns and $ns3ip and !preg_match("/.$fulldomain$/u",$ns3)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "50";
                    
#$res[errorMsg] = "Указан IP-адрес для NS3, который не является собственным DNS-сервером домена.";
                    
$res[errorMsg] = $_lang[ErrorAPIcode50];
                }
                else if (!
$defaultns and $ns4 and preg_match("/.$fulldomain$/u",$ns4) and !$ns4ip) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "51";
                    
#$res[errorMsg] = "Не указан IP-адрес для собственного NS4";
                    
$res[errorMsg] = $_lang[ErrorAPIcode51];
                }
                else if (!
$defaultns and $ns4ip and !preg_match("/.$fulldomain$/u",$ns4)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "52";
                    
#$res[errorMsg] = "Указан IP-адрес для NS4, который не является собственным DNS-сервером домена";
                    
$res[errorMsg] = $_lang[ErrorAPIcode52];
                }
                else if (!
$defaultns and $zone->enableCheckNS and !checkDNS($fulldomain$zone->id$ns1$ns2$ns3$ns4)) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "29";
                    
#$res[errorMsg] = "Ошибка проверки DNS-серверов: $GLOBALerror";
                    
$res[errorMsg] = $_lang[ErrorAPIcode29].": $GLOBALerror";
                }
                else if (!
$isTest and ($domain->todate == "0000-00-00" or $domain->status != "1")) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "37";
                    
#$res[errorMsg] = "Операция не возможна, т.к. заказ не обработан";
                    
$res[errorMsg] = $_lang[ErrorAPIcode37];
                }
                else if (!
$isTest and $domain->leftdays 0) {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "40";
                    
#$res[errorMsg] = "Операция не возможна, т.к. заказ просрочен";
                    
$res[errorMsg] = $_lang[ErrorAPIcode40];
                }
                else {
                    if (
$defaultns) {
                        
$ns1 $zone->defaultNS1;
                        
$ns2 $zone->defaultNS2;
                        
$ns3 $zone->defaultNS3;
                        
$ns4 $zone->defaultNS4;
                    }

                    if (
$isTest or @mysql_query("UPDATE orders_domains set ns1='$ns1',ns2='$ns2',ns3='$ns3',ns4='$ns4',ns1ip='$ns1ip',ns2ip='$ns2ip',ns3ip='$ns3ip',ns4ip='$ns4ip' WHERE id='$domain->id'")) {
                        if (
$isTest or updateNS($domain->id,$ns1,$ns2,$ns3,$ns4,$ns1ip,$ns2ip,$ns3ip,$ns4ip,$oldns1,$oldns2,$oldns3,$oldns4,$oldns1ip,$oldns2ip,$oldns3ip,$oldns4ip,$defaultns)) {
                            
$res[status] = "SUCCESS";
                            
$res[domain] = "$fulldomain";
                            if (
$ns1) { $res[ns1] = "$ns1"; }
                            if (
$ns2) { $res[ns2] = "$ns2"; }
                            if (
$ns3) { $res[ns3] = "$ns3"; }
                            if (
$ns4) { $res[ns4] = "$ns4"; }
                            if (
$ns1ip) { $res[ns1ip] = "$ns1ip"; }
                            if (
$ns2ip) { $res[ns2ip] = "$ns2ip"; }
                            if (
$ns3ip) { $res[ns3ip] = "$ns3ip"; }
                            if (
$ns4ip) { $res[ns4ip] = "$ns4ip"; }
                        }
                        else {
                            
$res[status] = "SUCCESS";
                            
$res[errorCode] = "30";
                            
#$res[errorMsg] = "Заявка принята, но по техническим причинам будет обработана в ручном режиме";
                            
$res[errorMsg] = $_lang[ErrorAPIcode30];
                            
$res[domain] = "$fulldomain";
                            if (
$ns1) { $res[ns1] = "$ns1"; }
                            if (
$ns2) { $res[ns2] = "$ns2"; }
                            if (
$ns3) { $res[ns3] = "$ns3"; }
                            if (
$ns4) { $res[ns4] = "$ns4"; }
                            if (
$ns1ip) { $res[ns1ip] = "$ns1ip"; }
                            if (
$ns2ip) { $res[ns2ip] = "$ns2ip"; }
                            if (
$ns3ip) { $res[ns3ip] = "$ns3ip"; }
                            if (
$ns4ip) { $res[ns4ip] = "$ns4ip"; }

                            
$nsss "DefaulNSFlag: $defaultnsnNS1$ns1 $ns1ipnNS2$ns2 $ns2ip";
                            if (
$ns3) {$nsss $nsss."nNS3: $ns3 $ns3ip";}
                            if (
$ns4) {$nsss $nsss."nNS4: $ns4 $ns4ip";}
                            
$subject_msg "Изменение DNS-серверов для $domain->domain (API)";
                            
$message "Пользователь $login заказал смену DNS-серверов для домена $domain->domain (ID # $domain->id) на:nn$nsssnnВам необходимо изменить DNS-сервера у регистратора и указать их в редактировании заказа на домен в биллинге.nn--nRootPanel";
                            
$manager_email GetSetting("manager_email");
                            
$admEmails=GetAdminEmailsWhereTrueParam("senddns");
                            if (
count($admEmails) > 0) {
                                
WriteMailLog($subject_msg,$message);
                            }
                            while (list(
$i,$em) = @each($admEmails)) {
                                
sendmail($em,'',$manager_email,$subject_msg,$message);
                            }
                        }
                    } else {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "2";
                        
#$res[errorMsg] = "Ошибка сохранения данных заказа в БД: ".mysql_error();
                        
$res[errorMsg] = $_lang[ErrorAPIcode2].": ".mysql_error();
                    }
                }
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "33";
                
#$res[errorMsg] = "Доменная зона для заказа не найдена";
                
$res[errorMsg] = $_lang[ErrorAPIcode33];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "32";
            
#$res[errorMsg] = "Заказ на доменное имя не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode32];
        }
    }
}


#############################################################################
#
# Получение списка доступных областей для страны

#############################################################################

else if ($command == "getAvailOblast") {
    
$country=strtoupper($country); 

    if (!
$country) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "42";
        
#$res[errorMsg] = "Не указан ISO-код страны";
        
$res[errorMsg] = $_lang[ErrorAPIcode42];
    } else {
        if (
count($_lang[Oblast][$country]) > 0) {
            
$res[status] = "SUCCESS";
            
$res[country] = "$country";

            while (list(
$k,$v) = @each($_lang[Oblast][$country])) {
                
$i++;
                
$res[oblast][$i] = $v;
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "43";
            
#$res[errorMsg] = "Список областей для страны не задан";
            
$res[errorMsg] = $_lang[ErrorAPIcode43];
        }
    }
}


#############################################################################
#
# Получение списка доступных регистраторов для доменной зоны

#############################################################################

else if ($command == "getAvailRegistrators") {
    
$zone mb_strtolower($zone);

    if (!
$zone) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "14";
        
#$res[errorMsg] = "Не указана доменная зона";
        
$res[errorMsg] = $_lang[ErrorAPIcode14];
    }
    else {
        
$zones=@mysql_query("select * from zones where zone='$zone' and active='1' order by isDefault desc");
        if (@
mysql_num_rows($zones) > 0) {
            if (@
mysql_num_rows($zones) > 1) {
                
$res[status] = "SUCCESS";
                
$res[zone] = "$zone";

                while (
$zone = @mysql_fetch_object($zones)) {
                    
$i++;

                    
$registrator GetRegistratorById($zone->autoreg);
                    if (
$registrator->id) {
                        
$domainCost GetDomainCostForUserByZoneId($user->id,$zone->id,0);
                        
$domainCost $domainCost*($zone->minsrok/12);
                        
$domainCost round($domainCost*$curr["CURK"],2);

                        
$domainCostRenew GetDomainCostRenewForUserByZoneId($user->id,$zone->id,0);
                        
$domainCostRenew $domainCostRenew*($zone->minsrok_renew/12);
                        
$domainCostRenew round($domainCostRenew*$curr["CURK"],2);

                        
$res[registrators][$i][registratorid] = $registrator->id;
                        
$res[registrators][$i][registratorname] = $registrator->name;
                        
$res[registrators][$i][registratorisdefault] = $zone->isDefault;
                        
$res[registrators][$i][zoneregcost] = "$domainCost";
                        
$res[registrators][$i][zonerenewcost] = "$domainCostRenew";
                        
$res[registrators][$i][zoneregperiod] = $zone->minsrok/12;
                        
$res[registrators][$i][zonerenewperiod] = $zone->minsrok_renew/12;
                        
$res[registrators][$i][currency] = $curr["CURC"];
                    }
                }
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "44";
                
#$res[errorMsg] = "Для доменной зоны отсутствует возможность выбора регистратора";
                
$res[errorMsg] = $_lang[ErrorAPIcode44];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "15";
            
#$res[errorMsg] = "Доменная зона указана неверно, либо она не активна";
            
$res[errorMsg] = $_lang[ErrorAPIcode15];
        }
    }
}


#############################################################################
#
# Получение статуса регистрации домена

#############################################################################

else if ($command == "getStatus") {
    
$fulldomain=mb_strtolower($domain); 

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    } else {
        
$domain GetDomainByDomain($fulldomain);
        
$zone GetZoneById($domain->zone_id);

        if (
$isTest or ($domain->id and $domain->uid == $user->id)) {
            if (
$isTest or $zone->id) {
                if (
$domain->status == "0") { $status "unregistered"; }
                else if (
$domain->status == "1") { 
                    if (
$domain->leftdays >= 0) {
                        
$status "registered"
                    } else {
                        
$status "expired"
                    }
                    
$todate mydate($domain->todate);
                }
                else if (
$domain->status == "2") { $status "suspended"$todate mydate($domain->todate); }
                else if (
$domain->status == "3") { $status "inprocess"; }
                else { 
$status "unknown"; }

                
$res[status] = "SUCCESS";
                
$res[domain] = "$fulldomain";
                
$res[domainStatus] = "$status";
                if (
$todate) { $res[todate] = "$todate"; }
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "33";
                
#$res[errorMsg] = "Доменная зона для заказа не найдена";
                
$res[errorMsg] = $_lang[ErrorAPIcode33];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "32";
            
#$res[errorMsg] = "Заказ на доменное имя не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode32];
        }
    }
}


#############################################################################
#
# Получение данных профайла для домена

#############################################################################

else if ($command == "getStatus") {
    
$fulldomain=mb_strtolower($domain); 

    if (!
$domain) {
        
$res[status] = "ERROR";
        
$res[errorCode] = "13";
        
#$res[errorMsg] = "Не указано доменное имя";
        
$res[errorMsg] = $_lang[ErrorAPIcode13];
    } else {
        
$domain GetDomainByDomain($fulldomain);
        
$zone GetZoneById($domain->zone_id);

        if (
$isTest or ($domain->id and $domain->uid == $user->id)) {
            if (
$isTest or $zone->id) {
                if (
$domain->status == "0") { $status "unregistered"; }
                else if (
$domain->status == "1") { 
                    if (
$domain->leftdays >= 0) {
                        
$status "registered"
                    } else {
                        
$status "expired"
                    }
                }
                else if (
$domain->status == "2") { $status "suspended"; }
                else if (
$domain->status == "3") { $status "inprocess"; }
                else { 
$status "unknown"; }

                
$res[status] = "SUCCESS";
                
$res[domain] = "$fulldomain";
                
$res[domainStatus] = "$status";
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "33";
                
#$res[errorMsg] = "Доменная зона для заказа не найдена";
                
$res[errorMsg] = $_lang[ErrorAPIcode33];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "32";
            
#$res[errorMsg] = "Заказ на доменное имя не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode32];
        }
    }
}


#############################################################################
#
# Команда не задана

#############################################################################

else {
    
$res[status] = "ERROR";
    
$res[errorCode] = "8";
    
#$res[errorMsg] = "Неизвестная команда";
    
$res[errorMsg] = $_lang[ErrorAPIcode8];
}




#############################################################################




                    
}
                    else {
                        
$res[status] = "ERROR";
                        
$res[errorCode] = "7";
                        
#$res[errorMsg] = "Указан неправильный пароль или ключ API";
                        
$res[errorMsg] = $_lang[ErrorAPIcode7];
                    }
                }
                else {
                    
$res[status] = "ERROR";
                    
$res[errorCode] = "6";
                    
#$res[errorMsg] = "Не указан пароль или ключ API";
                    
$res[errorMsg] = $_lang[ErrorAPIcode6];
                }
            }
            else {
                
$res[status] = "ERROR";
                
$res[errorCode] = "5";
                
#$res[errorMsg] = "Доступ к API отключен";
                
$res[errorMsg] = $_lang[ErrorAPIcode5];
            }
        }
        else {
            
$res[status] = "ERROR";
            
$res[errorCode] = "4";
            
#$res[errorMsg] = "Пользователь не найден";
            
$res[errorMsg] = $_lang[ErrorAPIcode4];
        }
    }
    else {
        
$res[status] = "ERROR";
        
$res[errorCode] = "3";
        
#$res[errorMsg] = "Не указан логин пользователя";
        
$res[errorMsg] = $_lang[ErrorAPIcode3];
    }

else {
    
$res[status] = "ERROR";
    
$res[errorCode] = "1";
    
#$res[errorMsg] = "Ошибка подключения к БД: $GLOBALerror";
    
$res[errorMsg] = $_lang[ErrorAPIcode1].": $GLOBALerror";
}

$status $res[status];
$res serialize($res);

$mtime microtime(); $mtime explode(" ",$mtime); $mtime $mtime[1] + $mtime[0]; $tend $mtime;
$totaltime = ($tend $tstart);
$querySeconds sprintf("%f"$totaltime); 

if (
$APILogId) {
    
AddAPILog($login,$command,$status,$res,$APILogId,$querySeconds);
}

header("Content-Type: text/html; charset=utf-8");
print 
$res;

mclose();
?>
Онлайн: 1
Реклама