<?php
include("../../session.php");
include("../../connect.php");

$num=$_GET['year'];
$expire=$_GET['expire'];
list($day, $month, $year) = split('[-]', $expire);

date_default_timezone_set ("Singapore");
$todayDate = date("d-m-Y", time());
list($todays, $tomonth, $toyear) = split('[-]', $todayDate); 

if($toyear > $year ){
	// if expired already
	updateYear($todayDate,$num);
	
}else if ($toyear < $year){
	//if haven expired
	updateYear($expire,$num);
	
}else if ($toyear == $year){
	//In this year
	
	if($tomonth > $month){
		//if expired already
		updateYear($todayDate,$num);
		
	}else if ($tomonth < $month){
		//if haven expire
		updateYear($expire,$num);
		
	}else if ($tomonth == $month){
		//In this month
		
		if($todays > $day){
			//if expired already
			updateYear($todayDate,$num);
			
		}else if($todays < $day){
			//if haven expired
			updateYear($expire,$num);
			
		}else if ($todays == $day){
			//today last day
			updateYear($expire,$num);
			
		}//end day compare
	}//end month compare
}//end year compare

function updateYear($renew,$numYear){

	if($numYear=="1"){
		$date = strtotime(date("d-m-Y", strtotime($renew)) . " +365 days");
		$true=date("d-m-Y", $date);
		echo $true;
		die();
	}// update one year
	if($numYear=="2"){
		$date = strtotime(date("d-m-Y", strtotime($renew)) . " +730 days");
		$true=date("d-m-Y", $date);
		echo $true;
		die();
	}// update two year
	if($numYear=="3"){
		$date = strtotime(date("d-m-Y", strtotime($renew)) . " +1095 days");
		$true=date("d-m-Y", $date);
		echo $true;
		die();
	}//update three year

}

?>