$line) {
if (strpos($line, $currentPCID) !== false) {
//string PCID exists
$License = $lines[$key];
$count = 0;
foreach ($lines as $key => $line) {
$count +=1;
}
$Inuse = 0;
foreach ($lines as $key => $line) {
if (strpos($line, "PCID") !== false) {
$Inuse +=1;
}
}
$remainder = $count - $Inuse;
echo "".json_encode($ExpiryDate . " - " . $License. " - " . $remainder). "";
exit;
}
}
foreach ($lines as $key => $line) {
if (strpos($line, "PCID") !== false) {
// string doesn't exist
//$License = $lines[$key];
//echo "".json_encode($ExpiryDate . " - " . $Licenses). "";
//echo "".json_encode($License). "";
if (strpos($line, $currentPCID) !== false) {
$License = $lines[$key];
$count = 0;
foreach ($lines as $key => $line) {
$count +=1;
}
$Inuse = 0;
foreach ($lines as $key => $line) {
if (strpos($line, "PCID") !== false) {
$Inuse +=1;
}
}
$remainder = $count - $Inuse;
echo "".json_encode($ExpiryDate . " - " . $License . " - " . $remainder). "";
exit;
} else {
echo "".json_encode("Maximum Licenses Reached"). "";
}
} else {
if (strpos($line, "PCID") === false) {
if (strpos($line, $currentPCID) === false) {
// string PCID exists
$lines[$key] = $lines[$key] ." PCID " . $currentPCID;
$License = $lines[$key];
file_put_contents($folder, implode(PHP_EOL, $lines));
$lines1 = file($folder, FILE_IGNORE_NEW_LINES);
$new_lines = array($ClientName, $ClientEmail, $LicenseQauntity, $originalDate);
array_splice($lines1, 0, 0, $new_lines);
file_put_contents($folder, implode("\n", $lines1));
$count = 0;
foreach ($lines as $key => $line) {
$count +=1;
}
$Inuse = 0;
foreach ($lines as $key => $line) {
if (strpos($line, "PCID") !== false) {
$Inuse +=1;
}
}
$remainder = $count - $Inuse;
echo "".json_encode($ExpiryDate . " - " . $License. " - " . $remainder). "";
//echo "".json_encode($ExpiryDate . " - " . $License). "";
exit;
}
}
}
}
} else {
echo "".json_encode("Invalid Email address"). "";
}
} else {
echo "".json_encode("Invalid Order No"). "";
}
}
if(isset($_POST['DeleteEntry'])){
$string = filter_var($_POST['DeleteEntry'], FILTER_SANITIZE_STRING);
$delimiter = ",";
$splitString = explode($delimiter, $string);
$productCode = $splitString[0];
$currentPCID = $splitString[1];
$Email = $splitString[2];
$folder = "OrNrs/" . $productCode;
if(file_exists($folder)){
$EmailData = file($folder, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINE);
$EmailIFexist = $EmailData[1]; //row 2
$Rowsinfile = file($folder, FILE_IGNORE_NEW_LINES);
$ClientName = $Rowsinfile[0];
$ClientEmail = $Rowsinfile[1];
$LicenseQauntity = $Rowsinfile[2];
$originalDate = $Rowsinfile[3]; //row 4
if (($Email) == $EmailIFexist) {
$timestamp = strtotime($originalDate1);
$date = date("Y-m-d", $timestamp);
$ExpiryDate = date("Y-m-d", strtotime("+1 year", $timestamp));
// file exists in the folder.
$lines = file($folder, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$lines = array_slice($lines, 4);
foreach ($lines as $key => $line) {
if (strpos($line, $currentPCID) !== false) {
//$lines[$key]= str_replace(" PCID " . $currentPCID, "", $lines);
$lines[$key] = str_replace(" PCID " . $currentPCID, "", $lines[$key]);
file_put_contents($folder, implode(PHP_EOL, $lines));
$lines1 = file($folder, FILE_IGNORE_NEW_LINES);
$new_lines = array($ClientName, $ClientEmail, $LicenseQauntity, $originalDate);
array_splice($lines1, 0, 0, $new_lines);
file_put_contents($folder, implode("\n", $lines1));
$count = 0;
foreach ($lines as $key => $line) {
$count +=1;
}
$Inuse = 0;
foreach ($lines as $key => $line) {
if (strpos($line, "PCID") !== false) {
$Inuse +=1;
}
}
$remainder = $count - $Inuse;
echo "".json_encode("PC license Removed" . "-" . $remainder). "";
exit;
}
}
}
}
}
?>