Write-Host "Reading index.html and style.css..."
$html = [IO.File]::ReadAllText("index.html")
$css = [IO.File]::ReadAllText("style.css")
Write-Host "Converting images to base64..."
$workersBytes = [IO.File]::ReadAllBytes("images/japanese_workers.png")
$workersBase64 = [Convert]::ToBase64String($workersBytes)
$workersDataUri = "data:image/png;base64," + $workersBase64
$managerBytes = [IO.File]::ReadAllBytes("images/compliance_manager.png")
$managerBase64 = [Convert]::ToBase64String($managerBytes)
$managerDataUri = "data:image/png;base64," + $managerBase64
Write-Host "Injecting PHP Form logic..."
$phpMailLogic = @"
<?php
`$success = null;
if (`$_SERVER["REQUEST_METHOD"] == "POST") {
`$company = isset(`$_POST["companyName"]) ? strip_tags(trim(`$_POST["companyName"])) : "";
`$department = isset(`$_POST["department"]) ? strip_tags(trim(`$_POST["department"])) : "";
`$name = isset(`$_POST["picName"]) ? strip_tags(trim(`$_POST["picName"])) : "";
`$phone = isset(`$_POST["phone"]) ? strip_tags(trim(`$_POST["phone"])) : "";
`$email = isset(`$_POST["email"]) ? filter_var(trim(`$_POST["email"]), FILTER_SANITIZE_EMAIL) : "";
`$needs = isset(`$_POST["needsType"]) ? strip_tags(trim(`$_POST["needsType"])) : "";
`$message = isset(`$_POST["message"]) ? strip_tags(trim(`$_POST["message"])) : "";
`$to = "rachencare@gmail.com";
`$subject = "=?UTF-8?B?44CQ5bel5L2c54mp55+z57a/5LqL5YmN6Kq/5p+76ICF44OK44OT44CR44GK5ZWP44GE5ZCI44KP44Gb?=";
`$email_content = base64_decode("5bel5L2c54mp55+z57a/5LqL5YmN6Kq/5p+76ICF44OK44OTIOOBi+OCieaWsOOBl+OBhOOBiuWVj+OBhOWQiOOCj+OBm+OBjOOBguOCiuOBvuOBl+OBn+OAggoK");
`$email_content .= base64_decode("6LK056S+5ZCNOiA=") . `$company . "\n";
`$email_content .= base64_decode("6YOo572y44O75b256IG3OiA=") . `$department . "\n";
`$email_content .= base64_decode("44GU5ouF5b2T6ICF5qeY5ZCNOiA=") . `$name . "\n";
`$email_content .= base64_decode("6Zu76Kmx55Wq5Y+3OiA=") . `$phone . "\n";
`$email_content .= base64_decode("44Oh44O844Or44Ki44OJ44Os44K5OiA=") . `$email . "\n";
`$email_content .= base64_decode("44GU5biM5pyb5YaF5a65OiA=") . `$needs . "\n\n";
`$email_content .= base64_decode("44GU6KaB5pyb44O744GU6LOq5ZWPOgo=") . `$message . "\n";
`$email_headers = "From: =?UTF-8?B?" . base64_encode(`$name) . "?= <`$email>\r\n";
`$email_headers .= "Reply-To: `$email\r\n";
`$email_headers .= "MIME-Version: 1.0\r\n";
`$email_headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
if (mail(`$to, `$subject, `$email_content, `$email_headers)) {
`$success = true;
} else {
`$success = false;
}
}
?>
"@
$formHtml = @"
<form class="lead-form" method="POST" action="">
<?php if (isset(`$success) && `$success): ?>
<div style="background-color: #d4edda; color: #155724; padding: 15px; border-radius: 8px; margin-bottom: 20px; border: 1px solid #c3e6cb; font-weight: bold; text-align: center;">
<?php echo base64_decode('44GK5ZWP44GE5ZCI44KP44Gb44GC44KK44GM44Go44GG44GU44GW44GE44G+44GZ77yB5Luj6KGo44Gu5bCP5bed56uc5bmz44KI44KK5oqY44KK6L+U44GX44GU6YCj57Wh44GE44Gf44GX44G+44GZ44CC'); ?>
</div>
<?php elseif (isset(`$success) && !`$success): ?>
<div style="background-color: #f8d7da; color: #721c24; padding: 15px; border-radius: 8px; margin-bottom: 20px; border: 1px solid #f5c6cb; font-weight: bold; text-align: center;">
<?php echo base64_decode('6YCB5L+h44Gr5aSx5pWX44GX44G+44GX44Gf44CC44GK5omL5pWw44Gn44GZ44GM44CB44GK6Zu76Kmx77yIMDgwLTY5MjYtOTA0M++8ieOBq+OBpuOBiuWVj+OBhOWQiOOCj+OBm+OBj+OBoOOBleOBhOOAgg=='); ?>
</div>
<?php endif; ?>
"@
# Inject name attributes and form PHP
$html = $html -replace '<form class="lead-form"[^>]*>', $formHtml
$html = $html.Replace('id="companyName"', 'id="companyName" name="companyName"')
$html = $html.Replace('id="department"', 'id="department" name="department"')
$html = $html.Replace('id="picName"', 'id="picName" name="picName"')
$html = $html.Replace('id="phone"', 'id="phone" name="phone"')
$html = $html.Replace('id="email"', 'id="email" name="email"')
$html = $html.Replace('id="needsType"', 'id="needsType" name="needsType"')
$html = $html.Replace('id="message"', 'id="message" name="message"')
Write-Host "Merging styles..."
$html = $html.Replace('<link rel="stylesheet" href="style.css">', "<style>`n" + $css + "`n</style>")
$html = $html.Replace('src="images/japanese_workers.png"', "src=" + '"' + $workersDataUri + '"')
$html = $html.Replace('src="images/compliance_manager.png"', "src=" + '"' + $managerDataUri + '"')
# Prepend PHP mail logic
$finalPhpContent = $phpMailLogic + "`n" + $html
# Save inline index.php to workspace
[IO.File]::WriteAllText("index.php", $finalPhpContent, [System.Text.Encoding]::UTF8)
Write-Host "Single index.php generated in workspace."
# Also save directly to Desktop for easy access
[IO.File]::WriteAllText("c:\Users\abc51\OneDrive\Desktop\index.php", $finalPhpContent, [System.Text.Encoding]::UTF8)
Write-Host "Single index.php generated on Desktop."
# Generate WordPress Template Page (page-lp.php) on Desktop
$wpTemplateHeader = "<?php`n/*`nTemplate Name: 工作物石綿事前調査者ナビ LP`n*/`n?>`n"
$wpTemplateContent = $wpTemplateHeader + $finalPhpContent
[IO.File]::WriteAllText("c:\Users\abc51\OneDrive\Desktop\page-lp.php", $wpTemplateContent, [System.Text.Encoding]::UTF8)
Write-Host "WordPress page-lp.php generated on Desktop."
# Also update the WordPress theme directory if exists
$wpThemeIndex = "c:\Users\abc51\OneDrive\Desktop\asbestos-lp-theme\index.php"
if (Test-Path $wpThemeIndex) {
[IO.File]::WriteAllText($wpThemeIndex, $finalPhpContent, [System.Text.Encoding]::UTF8)
Write-Host "WordPress Theme index.php updated."
}