prepare("select * from vpnuser where vuser='".$username."'");
$data->execute();
$row = $data->fetch(PDO::FETCH_ASSOC);
if (empty($row)){
echo json_encode([
"status" => 401,
"message" => "Account doesn't exist",
]);
return;
} else{
$group = "BY";
$hyid = "2";
$speed = "1024";
if($plan == "discount") {
$hyid = "2";
$speed = "1024";
} else if($plan == "basic") {
$hyid = "3";
$speed = "1024";
} else if($plan == "premium") {
$hyid = "4";
$speed = "2048";
} else {
$hyid = "5";
$speed = "4096";
}
$months = "+1 month";
if($time == "1month") {
$months = "+1 month";
} else if($time == "3month") {
$months = "+3 months";
} else if($time == "6month") {
$months = "+6 months";
} else {
$months = "+1 year";
}
if($row['groups'] == 'LL') {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
if (date("Y-m-d H:i:s", strtotime($row['lastdate'])) <= date("Y-m-d H:i:s" )) {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
if($hyid == 2 | $hyid == 3) {
if($row['hyid'] == 2 | $hyid == 3) {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months, strtotime($row['lastdate'])))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
$now = time(); // or your date as well
$expire = strtotime($row['lastdate']);
$datediff = $expire - $now;
$days = round($datediff / (60 * 60 * 24));
$money = 0;
if($row['hyid'] == 4)
$money = ($days / 30) * 32;
else if($row['hyid'] == 5)
$money = ($days / 30) * 64;
$plusDays = round($money / (64 / 30));
$plusStr = "+1 day";
if($plusDays > 1) {
$plusStr = "+".$plusDays." days";
}
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($plusStr, strtotime($new['lastdate'])))
."' where vuser='".$username."'");
$data->execute();
}
} else if($hyid == 4) {
if($row['hyid'] == 4) {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months, strtotime($row['lastdate'])))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
$now = time(); // or your date as well
$expire = strtotime($row['lastdate']);
$datediff = $expire - $now;
$days = round($datediff / (60 * 60 * 24));
$money = 0.0;
if($row['hyid'] == 2 | $row['hyid'] == 3) {
$money = ($days / 30) * 16;
} else if($row['hyid'] == 4) {
$money = ($days / 30) * 32;
}
$plusDays = round($money / (32 / 30));
$plusStr = "+1 day";
if($plusDays > 1) {
$plusStr = "+".$plusDays." days";
}
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($plusStr, strtotime($new['lastdate'])))
."' where vuser='".$username."'");
$data->execute();
}
} else if($hyid == 5) {
if($row['hyid'] == 5) {
$data = $db->prepare("update vpnuser set lastdate = '" . date("Y-m-d H:i:s", strtotime($months, strtotime($row['lastdate'])))
. "', hyid = '" . $hyid
. "', groups = '" . $group
. "', updk = '" . $speed
. "', downdk = '" . $speed
. "', flow = 0 where vuser='" . $username . "'");
$data->execute();
} else {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
$now = time(); // or your date as well
$expire = strtotime($row['lastdate']);
$datediff = $expire - $now;
$days = round($datediff / (60 * 60 * 24));
$money = 0.0;
if($row['hyid'] == 4)
$money = ($days / 30) * 32;
else if($row['hyid'] == 5)
$money = ($days / 30) * 64;
else if($row['hyid'] == 2 | $row['hyid'] == 3)
$money = ($days / 30) * 16;
$plusDays = round($money / (64 / 30));
$plusStr = "+1 day";
if($plusDays > 1) {
$plusStr = "+".$plusDays." days";
}
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($plusStr, strtotime($new['lastdate'])))
."' where vuser='".$username."'");
$data->execute();
}
}
}
}
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
echo json_encode([
"status" => 200,
"data" => $new
]);
}
} else {
echo json_encode([
"status" => 401,
"message" => "Email, password are required!",
]);
return;
}
?>