<?php
$t = 'Редактор Заказов';
require_once '../../wcore/core.php';
require_once '../../wcore/head.php';
iank(3);
$id = (isset($_GET['id']) && !empty($_GET['id'])?intval($_GET['id']):0);
$act = (isset($_GET['act']) && !empty($_GET['act'])?antixs($_GET['act']):false);
if ($act == 'edit' && $id != 0 && _mc('orders',"WHERE `oid` = '$id'")!=0 && isset($_POST['ok']) && isset($_POST['status']) && isset($_POST['url']) && isset($_POST['login']) && isset($_POST['pwd']) && isset($_POST['ip']) && isset($_POST['bits'])) {
    $serv = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `orders`.`oid`='$id'"));
    $_j = json_decode(base64_decode($serv['data']),true);
    $status     = intval($_POST['status']);
    $url        = !empty($_POST['url'])?antixs($_POST['url']):$_j['url'];
    $ip         = !empty($_POST['ip'])?antixs($_POST['ip']):$_j['ip'];
    $login      = !empty($_POST['login'])?antixs($_POST['login']):$_j['login'];
    $pwd        = !empty($_POST['pwd'])?antixs($_POST['pwd']):$_j['pwd'];
    $bits       = !empty($_POST['bits'])?antixs($_POST['bits']):$serv['bits'];
    $addday     = !empty($_POST['addday'])?(86400 * intval($_POST['addday'])):0;
    $json = json_encode([
        'url'       =>  $url,
        'login'     =>  $login,
        'pwd'       =>  $pwd,
        'ip'        =>  $ip,
        'packname'  =>  $_j['packname'],
        'tarifs_id' =>  $_j['tarifs_id'],
        'server_id' =>  $_j['server_id'],
        'order_init'=>  $_j['order_init'],
    ]);
    mysqli_query($mysqli,"UPDATE `orders` SET `data`='".(base64_encode($json))."', `status` = '$status', `time` = `time` + '$addday', `bits` = '$bits' WHERE `oid` = '$id'");
    echo msg_err('suc',$lang['admin_moders_ord_m2']);require_once '../../wcore/foot.php';exit();
} elseif ($act == 'edit' && $id != 0 && _mc('orders',"WHERE `oid` = '$id'")!=0){
    $serv = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT * FROM `servers`,`orders` WHERE `servers`.`id`=`orders`.`l_s` AND `orders`.`oid`='$id'"));
    $array = [
        'id'    =>  $serv['oid'],
        'name'  =>  $serv['nametar'],
        'desc'  =>  json_decode(base64_decode($serv['data'])),
        'status'=>  $serv['status'],
        'bits'  =>  $serv['bits'],
        'nserv' =>  $serv['name'],
        'mgr'   =>  $serv['order_init'],
        'time'  =>  ptime($serv['time']).' (Осталось: '.cunter_day_unix($serv['time'],false).')',
    ];
    echo $twig->render('admin_edit_order.tpl', array('lang' =>$lang,'userq'=>'0','act'=>'edit','order'=>$array));
} else {
    echo $twig->render('admin_edit_order.tpl', array('lang' =>$lang,'userq'=>'0','act'=>'home'));
    
}

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