<?php
set_time_limit(0);
ini_set('memory_limit', '-1');
include("config.php");
//include("functions.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
///For Cron
//die ; 
$tablename = ' settings_api_bultsms  ';
$start = "select * from ".$tablename." where id='6'";
$start_que_start = mysqli_query($connect,$start);
$startData = mysqli_fetch_array($start_que_start);
$datetime1 = $startData['locked_at'] ;

$start6 = "select * from ".$tablename." where id='6'";
$start_que_start6 = mysqli_query($connect,$start6);
$startData6 = mysqli_fetch_array($start_que_start6);
$currentdatetime = date("Y-m-d H:i:s");
$diff = abs(strtotime($currentdatetime) - strtotime($datetime1));
$years   = floor($diff / (365*60*60*24)); 
$months  = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); 
$days    = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$hours   = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60)); 
$minuts  = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60); 
$seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minuts*60)); 



//echo $hours .' -- ' . $minuts .' -- '.$startData6['value'] ;  die  ; 
if( (($startData6['value'] == 'Locked' ) || ($startData6['value'] == 'locked' ) ) && ( ($hours >= 1)  || $minuts >= 50) ){
    // die ("in ");
    // UPDATE seting table
    	$upd1 = "UPDATE ".$tablename." SET value = 'Unlocked' WHERE id =6";
		 mysqli_query($connect,$upd1);
		$endtimesave = date("Y-m-d H:i:s");
		$sqlendtimesavestr = "UPDATE ".$tablename." SET locked_at = '$endtimesave' WHERE id =6";
		echo $sqlendtimesavestr ; 
		 mysqli_query($connect,$sqlendtimesavestr);
		// die ("end ");
	
}else{
    
     die ("end ");
}
