<?php
include('../db.php');

$type = $_POST['type'];
$id = $_POST['id'];

$now = time();


$txt = "select * from `cus` left join `member` on `member`.`id_member` = `cus`.`id_member` where `cus`.`id_cus` = '$id'";
$query = mysqli_query($db,$txt);
$row = mysqli_fetch_assoc($query);
$data['name'] = $row['name_cus'];
$data['card'] = $row['id_scanner'];
$data['v_type'] = $row['name_member'];
$data['v_mony'] = $row['mony_cus'];
$data['date'] =  $row['member_date'];
$data['type'] =$row['type_member'];
$data['date_game'] =$row['date_game'];
if($row['type_member'] == 0)
{
	$data['end'] = $row['count_s'];
}
if($row['type_member'] == 1)
{
	if($data['date_game'] == 0)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 1 days'));
		$data['end_day'] = strtotime($data['end']);
	}
	if($data['date_game'] == 1)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 7 days'));
		$data['end_day'] = strtotime($data['end']);
	}
	if($data['date_game'] == 2)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 30 days'));
		$data['end_day'] = strtotime($data['end']);
	}
	if($data['date_game'] == 3)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 365 days'));
		$data['end_day'] = strtotime($data['end']);
	}
	if($data['date_game'] == 4)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 90 days'));
		$data['end_day'] = strtotime($data['end']);
	}
	if($data['date_game'] == 5)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 180 days'));
		$data['end_day'] = strtotime($data['end']);
	}
	if($data['date_game'] == 6)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 270 days'));
		$data['end_day'] = strtotime($data['end']);
	}
		if($data['date_game'] == 7)
	{
		$data['end'] =  date('Y-m-d', strtotime($row['member_date'].'+ 15 days'));
		$data['end_day'] = strtotime($data['end']);
	}
			$end_day_calc = $data['end_day'] - $now  ;
	$data['day_end'] =  round($end_day_calc / (60 * 60 * 24));
}
if($row['type_member'] == 2)
{
		if($data['date_game'] == 0)
	{
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']. " فى تاريح =" .date('Y-m-d', strtotime($row['member_date'].'+ 1 days'));
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 1 days')));
	}
	if($data['date_game'] == 1)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 7 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;	
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 7 days')));
		}
		
	if($data['date_game'] == 2)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 30 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;	
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 30 days')));}
	if($data['date_game'] == 3)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 365 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;	
		
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 365 days')));
		}
	if($data['date_game'] == 4)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 90 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;	
		
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 90 days')));
		}
	if($data['date_game'] == 5)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 180 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;
$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 180 days')));
		}
	if($data['date_game'] == 6)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 270 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 270 days')));
	}
		if($data['date_game'] == 7)
	{
		$end_date = date('Y-m-d', strtotime($row['member_date'].'+ 15 days'));
		$data['end'] =  "عدد الحصص المتبقة =".$row['count_s']." فى تاريح =" .$end_date;
		$data['end_day'] = strtotime(date('Y-m-d', strtotime($row['member_date'].'+ 15 days')));
	}
		$end_day_calc = $data['end_day'] - $now  ;
	$data['day_end'] =  round($end_day_calc / (60 * 60 * 24));
}
echo json_encode($data);

?>