<?php
$t = 'Импорт тарифов';
require_once '../../wcore/core.php';
require_once '../../wcore/head.php';
require_once '../../wcore/order_tld24.php';
iank(3);
$id = (isset($_GET['id']) && !empty($_GET['id'])?intval($_GET['id']):9);
#tld24_oblast
    $_upd = json_decode(order_tld24('AvailOblast',$id));
    $u1 = 0;
    mysqli_query($mysqli,"TRUNCATE tld24_oblast");
    foreach($_upd->oblast as $var) {
       mysqli_query($mysqli,"INSERT INTO `tld24_oblast` SET `name` = '$var'");
       $u1 ++;
    }
      
      
    $_upd = json_decode(order_tld24('AvailZones',$id));
    $u2 = 0;
    foreach($_upd->zones as $var) {
        
        $domain = array(
            'id'=>$var->id,
            'zone'=>$var->zone,
            'regcost'=>$var->regcost,
            'renewcost'=>$var->renewcost,
            'currency'=>$var->currency,
        );
        $sign = md5($var->id.$var->zone.$var->currency);
        
        if (mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `tarifs` WHERE `preset` = '$sign'")) == 0){
            mysqli_query($mysqli,"INSERT INTO `tarifs`(`sid`, `namepack`, `deskpack`, `preset`, `bits`) VALUES ($id,'Домен $var->zone','".base64_encode(json_encode($domain))."','$sign','$var->regcost,')");
            echo 'Добавлена зона '.$var->zone.' (Sign: '.$sign.')<br>';
        } else {
            echo 'Зона уже добавлена '.$var->zone.' (Sign: '.$sign.')<br>';
        }
       $u2 ++;
    }  
    echo '<div>Импортировано областей: '.$u1.'</div>';
    echo '<div>Импортировано доменов: '.$u2.'</div>';
require_once '../../wcore/foot.php';
