<?php
$t = 'Массовое начисление дней';
require_once '../../wcore/core.php';
require_once '../../wcore/head.php';
iank(3);
$k_post = _mc('orders');
$orders = array(
    'vhost' =>  mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `servers`.`type` = '1' ")),
    'ress'  =>  mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `servers`.`type` = '2' ")),
    'vds'   =>  mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `servers`.`type` = '3' ")),
    'dedic' =>  mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `servers`.`type` = '4' ")),
    'domain'=>  mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `servers`.`type` = '5' ")),
);
if(isset($_POST['ok'])){
    $time = isset($_POST['time']) && !empty($_POST['time']) && $_POST['time'] > 0?intval($_POST['time']):0;
    $select = isset($_POST['list'])?'list':'servers';
    $select_data = isset($_POST[$select]) && !empty($_POST[$select])?antixs($_POST[$select]):0;
    if ($select == 'list'){
        mysqli_query($mysqli,"UPDATE `servers`,`orders` SET `orders`.`time`=`orders`.`time`+'$time' WHERE `servers`.`id`=`orders`.`l_s` AND `servers`.`type` = '$select_data'");
    } else {
        mysqli_query($mysqli,"UPDATE `servers` SET `time`=`time`+'$time' WHERE `l_s` = '$select_data'");
    }
    echo msg_err('suc',$lang['adm_adays_orders_m8']);
    require_once '../../wcore/foot.php';
    exit();
}

$_tmp = mysqli_query($mysqli,"SELECT * FROM `servers` ORDER BY `id` ASC") or die("Ошибка запроса: ".mysqli_error($mysqli));
while ($serv = mysqli_fetch_assoc($_tmp)){
    $data[] = $serv;
}

$data = !isset($data)?NULL:$data;
echo $twig->render('admin_add_days_orders.tpl', [
    'lang'  =>  $lang,
    'data'  =>  $data,
    'count' =>  $k_post,
    'mc'    =>  $orders,

]);
require_once '../../wcore/foot.php';
?>