<?php
function removePTAG($string){
 return str_replace("</p>","",str_replace("<p>", "", $string));
}


function drawTime(){
	global $DB;
	date_default_timezone_set('Asia/Kolkata');

$date = time();

$lotMin = date("i", $date);
$lotHour = date("h", $date);
$lotSec = date("s", $date);
$ampm = date("A", $date);



if ($lotMin >= 0 && $lotMin < 15) {
    $lotMin = 15;
} else if ($lotMin >= 15 && $lotMin < 30) {
    $lotMin = 30;
} else if ($lotMin >= 30 && $lotMin < 45) {
    $lotMin = 45;
} else if ($lotMin >= 45 && $lotMin < 60) {
    $lotMin = 0;
    $lotHour++;
}

$lotHour = $lotHour % 12;
if ($lotHour == 0) {
    $lotHour = 12;
}

if ($lotHour < 10) {
    $lotHour = "0" . $lotHour;
}
if ($lotMin < 10) {
    $lotMin = "0" . $lotMin;
}
// if ($lotSec < 10) {
//     $lotSec = "0" . $lotSec;
// }

$time_lot =  "$lotHour:$lotMin";
//return '<body style="background-color: rgb(255,224,192);"><b>'.$time_lot.'</b></body>';
  return $time_lot;
}
function getTimeFront(){
		global $DB;
	date_default_timezone_set('Asia/Kolkata');
	header('Access-Control-Allow-Origin: *');

$date = time();

$lotMin = date("i", $date);
$lotHour = date("h", $date);
$lotSec = date("s", $date);
$ampm = date("A", $date);



if ($lotMin >= 0 && $lotMin < 15) {
    $lotMin = 15;
} else if ($lotMin >= 15 && $lotMin < 30) {
    $lotMin = 30;
} else if ($lotMin >= 30 && $lotMin < 45) {
    $lotMin = 45;
} else if ($lotMin >= 45 && $lotMin < 60) {
    $lotMin = 0;
    $lotHour++;
}

$lotHour = $lotHour % 12;
if ($lotHour == 0) {
    $lotHour = 12;
}

if ($lotHour < 10) {
    $lotHour = "0" . $lotHour;
}
if ($lotMin < 10) {
    $lotMin = "0" . $lotMin;
}
// if ($lotSec < 10) {
//     $lotSec = "0" . $lotSec;
// }

$time_lot = date("Y-m-d", $date) . " $lotHour:$lotMin:$lotSec";
$time_now = date("Y-m-d h:i:s", $date);

// $h = date("h", $date);
$m = $lotMin;
// $s = date("s", $date);

if ($m > 60) {
    $m = $m % 60;
    $h++;
    if ($m < 10) {
        "0" . $m;
    }
}

if ($time_lot == $time_now) {
    echo "Expired";
}
$drawTime = $lotHour.':'.$lotMin;

$sec_remaining =  (60 - date("s", time()));
if ($sec_remaining < 10) {
    $sec_remaining = "0" . $sec_remaining;
}

$min_remaining =  ((strtotime($time_lot) - strtotime($time_now)) / 60) - 1;
if ($min_remaining < 10) {
    $min_remaining = "0" . $min_remaining;
}
$time_remaining = $min_remaining . ":" . $sec_remaining;

//echo "Draw Time: " . $time_lot;
//echo "<br>Curr.. Time: " . $time_now;
//echo  $time_remaining.'-'.date('h:i',strtotime($drawTime)); 
echo  $time_remaining;

}
function getTodayDate(){
	date_default_timezone_set('Asia/Kolkata');
	return '<body style="background-color: rgb(255,224,192);"><b>'.date('d-m-Y').'</b></body>';
}
function getCurrentTime(){
	date_default_timezone_set('Asia/Kolkata');
	header('Access-Control-Allow-Origin: *');
	
	return date('h:i:s');
}



















if($_REQUEST["xAction"]) {
	@session_start();
	switch($_REQUEST["xAction"]) {
		
		
		case 'cont':
			include("../connectdb.inc.php");
			echo addCont();
		break;
		case 'eventReg':
			include("../connectdb.inc.php");
			echo eventRegister();
		break;
		
		case 'chkUser':
			include("../connectdb.inc.php");
			echo chkUser();
		break;
		case 'chkRef':
			include("../connectdb.inc.php");
			echo chkRef();
		break;
		case 'chkSide':
			include("../connectdb.inc.php");
			echo chkSide();
		break;
		case 'saveReg':
			include("../connectdb.inc.php");
			echo saveReg();
		break;
		case 'login':
			include("../connectdb.inc.php");
			echo frntUserLogin();
		break;
		case 'chkActMail':
			include("../connectdb.inc.php");
			echo chkActMail();
		break;
		case 'sendPass':
			include("../connectdb.inc.php");
			echo sendPassword($_REQUEST['email']);
		break;
		case 'chkDirect':
			include("../connectdb.inc.php");
			echo checkDirect();
		break;
		case 'chkChild':
			include("../connectdb.inc.php");
			echo display_children('SS124391','1');
		break;
		
		case 'forPass':
			include("../connectdb.inc.php");
			echo sendForgotPassword();
		break;
		case 'chkMob':
			include("../connectdb.inc.php");
			echo chkMob();
		break;
		
		case 'chkPan':
			include("../connectdb.inc.php");
			echo chkPan();
		break;
		case 'chkAdhar':
			include("../connectdb.inc.php");
			echo chkAdhar();
		break;
		case 'getDrawTime':
			echo drawTime();
		break;
		case 'GT':
				getTimeFront();
				break;
		case 'GTD':
				echo getTodayDate();
				break;
		case 'GCT':
				echo getCurrentTime();
				break;
		
		
	}
}

?>