$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) {
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[$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;
}
}
}
}
}
if(isset($_POST['CreateLic'])){
$string = filter_var($_POST['CreateLic'], FILTER_SANITIZE_STRING);
$delimiter = ",";
$splitString = explode($delimiter, $string);
$ClientName = $splitString[0];
$ClientEmail = $splitString[1];
$LicenseNo = $splitString[2];
$ExpiryDate = $splitString[3];
$filePrefix = '#';
$folder = "OrNrs/";
$files = scandir($folder);
$numbers = array();
foreach ($files as $file) {
if (preg_match('/' . preg_quote($filePrefix) . '(\d+)/', $file, $matches)) {
$numbers[] = intval($matches[1]);
}
}
if (!empty($numbers)) {
$nextNumber = max($numbers) + 1;
} else {
$nextNumber = 1;
}
$remainingData = implode($delimiter, array_slice($splitString, 4));
$fileContent = $ClientName . $ClientEmail . $LicenseNo . $ExpiryDate. str_replace($delimiter, '', $remainingData);
$newFileName = $filePrefix . $nextNumber;
$filePath = $folder . $newFileName;
file_put_contents($filePath, $fileContent);
}
if(isset($_POST['SearchFiles'])){
$string = filter_var($_POST['SearchFiles'], FILTER_SANITIZE_STRING);
if (($string) == "DewaldRequest") {
$folder = "OrNrs/";
$files = scandir($folder);
$AllFiles = "";
foreach ($files as $file) {
if (($file) == "." or ($file) == "..") {
} else {
$Linesofcontent = $folder. $file;
$contents = file($Linesofcontent);
$AllFiles .= $file ."\n";
foreach ($contents as $row) {
$AllFiles .= $row;
}
$AllFiles .= "\n\n";
}
}
echo "".json_encode($AllFiles). "";
}
}
if(isset($_POST['DeleteFileFromControlPanel'])){
$string = filter_var($_POST['DeleteFileFromControlPanel'], FILTER_SANITIZE_STRING);
$delimiter = ",";
$splitString = explode($delimiter, $string);
$PassWord = $splitString[0];
$folder = "OrNrs/";
$FileToDelete = $splitString[1];
$files = scandir($folder);
if (($PassWord) == "DewaldRequest") {
foreach ($files as $file) {
if (($file) == $FileToDelete) {
unlink($folder . $FileToDelete);
}
}
echo "".json_encode($FileToDelete). "";
}
}
if(isset($_POST['EmailBH'])){
$string = filter_var($_POST['EmailBH'], FILTER_SANITIZE_STRING);
$delimiter = ",";
$splitString = explode($delimiter, $string);
$ClientName = $splitString[0];
$Email = $splitString[1]; //Email
$PCID = $splitString[2]; //PCID
$ExpiryDate = $splitString[3];
$currentDate = date("Y-m-d");
$filePath = 'PCIDs';
$lineToAdd = $PCID. "," .$Email. "," .$currentDate;
// Read the contents of the file
$fileContents = file_get_contents($filePath);
if (strpos($fileContents, $PCID) !== false) {
if ($currentDate > $ExpiryDate) {
$message1 = $ClientName. "'s 7-day trial has expired! Send them the price list.";
$subject = "Fenestration License Request";
$toEmail = "dewald@blackhoundenterprises.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: Blackhound Server \r\n";
$message = "" . "To Whom it may concern:" . "
"
.$message1. "
" .
"
" . "PC Details:" . "
" .
"Name.: " .$ClientName. "
" .
"Email: " .$Email. "
" .
"PCID: " .$PCID;
mail($toEmail,$subject,$message,$headers);
$MessageToProgram = "Your 7-day trial has expired! An email will be sent with our rates";
echo "".json_encode($MessageToProgram). "";
exit;
} else {
$message1 = $ClientName. " requested another license. Send them the price list.";
$subject = "Fenestration License Request";
$toEmail = "dewald@blackhoundenterprises.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: Blackhound Server \r\n";
$message = "" . "To Whom it may concern:" . "
"
.$message1. "
" .
"
" . "PC Details:" . "
" .
"Name.: " .$ClientName. "
" .
"Email: " .$Email. "
" .
"PCID: " .$PCID;
mail($toEmail,$subject,$message,$headers);
$MessageToProgram = "A new license has been requested." . " An email will be sent with our rates";
echo "".json_encode($MessageToProgram). "";
exit;
}
}
file_put_contents($filePath, $lineToAdd . PHP_EOL, FILE_APPEND);
$message1 = $ClientName. "'s 7-day trial has started.";
$subject = "Fenestration License Request";
$toEmail = "dewald@blackhoundenterprises.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: Blackhound Server \r\n";
$message = "" . "To Whom it may concern:" . "
"
.$message1. "
" .
"
" . "PC Details:" . "
" .
"Name.: " .$ClientName. "
" .
"Email: " .$Email. "
" .
"PCID: " .$PCID;
mail($toEmail,$subject,$message,$headers);
$ClientName = $splitString[0];
$Email = $splitString[1];
$LicenseNo = "1";
$ExpiryDate = date("Y-m-d", strtotime("-1 year +6 days", strtotime($currentDate)));
$filePrefix = '#';
$folder = "OrNrs/";
$files = scandir($folder);
$numbers = array();
foreach ($files as $file) {
if (preg_match('/' . preg_quote($filePrefix) . '(\d+)/', $file, $matches)) {
$numbers[] = intval($matches[1]);
}
}
if (!empty($numbers)) {
$nextNumber = max($numbers) + 1;
} else {
$nextNumber = 1;
}
// Get a list of all files in the folder
$files = scandir($folder);
// Loop through each file
foreach ($files as $file) {
// Exclude current directory (.) and parent directory (..)
if ($file === '.' || $file === '..') {
continue;
}
// Read the file contents
$filePath = $folder . '/' . $file;
$contents = file_get_contents($filePath);
// Check if the file contains the keyword
if (strpos($contents, $Email) !== false) {
exit;
}
}
$length = 13;
$randomBytes = random_bytes($length);
$base64String = base64_encode($randomBytes);
foreach ($files as $file) {
// Exclude current directory (.) and parent directory (..)
if ($file === '.' || $file === '..') {
continue;
}
// Read the file contents
$filePath = $folder . '/' . $file;
$contents = file_get_contents($filePath);
// Check if the file contains the keyword
if (strpos($contents, $base64String) !== false) {
exit;
}
}
$fileContent = $ClientName. "\n" .$Email. "\n"."1"."\n" .$ExpiryDate ."\n" . $base64String;
$newFileName = $filePrefix . $nextNumber;
$filePath = $folder . $newFileName;
file_put_contents($filePath, $fileContent);
$MessageToProgram = "Your 7-day trial has started." . " The expiry date is ". $ExpiryDate . " " . $newFileName;
echo "".json_encode($MessageToProgram). "";
}
?>