<?php
$t = 'Выбор услуги';
require_once '../../wcore/core.php';
require_once '../../wcore/head.php';
$serv = (isset($_GET['server']) && !empty($_GET['server'])?intval($_GET['server']):0);
$id = (isset($_GET['type']) && !empty($_GET['type'])?intval($_GET['type']):0);
if ($serv !=0 && $id > 0 && $id <= 5){
    $list = 'tarifs';
    
    # Выводим тарифы
    $_tmp = mysqli_query($mysqli,"SELECT * FROM `tarifs` WHERE `sid` = '$serv' ORDER BY `tid` ASC") or die("Ошибка запроса: ".mysqli_error($mysqli));
    while ($serv = mysqli_fetch_assoc($_tmp)){
        $array[] = array(
            'id'            =>  $serv['tid'],
            'name'          =>  $serv['namepack'],
            'desc'          =>  json_decode(base64_decode($serv['deskpack'])),
            'bits'          =>  $serv['bits'],
            'bits_eternal'  =>  $serv['bits_eternal'],
            'eternal_service'=> $serv['eternal_service'],
            'manual_moderation'=> $serv['manual_moderation'],
            'block_a_monthly_payment'=>$serv['block_a_monthly_payment']
        );
    }
    if (!isset($array)){$array = FALSE;}
} elseif ($serv ==0 && $id > 0 && $id <= 5){
    # Выводим сервера
    $list = 'servers';
    $_tmp = mysqli_query($mysqli,"SELECT * FROM `servers` WHERE `type` = '$id' ORDER BY `id` ASC") or die("Ошибка запроса: ".mysqli_error($mysqli));
    while ($serv = mysqli_fetch_assoc($_tmp)){
        $array[] = array(
            'id'    =>  $serv['id'],
            'name'  =>  $serv['name'],
            'count' =>  mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `tarifs` WHERE `sid` = '".$serv['id']."'")),
            'msg'   =>  base64_decode(json_decode($serv['notify'])),
        );
    }
    if (!isset($array)){$array = FALSE;}
    #echo base64_encode(json_encode(array('type'=>'none','msg'=>'')));
} else {
    # Уходим на главную
    go('/');
}
echo $twig->render('page_modules_order_index.tpl', array(
    'lang'  =>  $lang,
    'iserv' =>  $serv,
    'id'    =>  $id,
    'list'  =>  $list,
    'data'  =>  $array,
    )
    );
require_once '../../wcore/foot.php';
?>