<?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

$tablename = ' settings_fastcompose ';
$start = "select * from ".$tablename." where id='3'";
$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)); 
if( ($startData6['value'] == 'locked'  ) && ( ($hours >= 1)  || $minuts >= 50) ){
    // 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 =3";
		//echo $sqlendtimesave ; 
		 mysqli_query($connect,$sqlendtimesavestr);
		
		$sqlendtimesave = "UPDATE ".$tablename." SET locked_at = '$endtimesave' WHERE id =4";
		//echo $sqlendtimesave ; 
		$resendtimesave = mysqli_query($connect,$sqlendtimesave);
	
    
}
