Grads

# PowerShell script to create a student information form webpage

# Create HTML content for the form
$htmlContent = @"
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Information Form</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .form-container {
            background-color: #f9f9f9;
            border-radius: 8px;
            padding: 25px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"], input[type="email"], select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 16px;
        }
        input[type="file"] {
            margin-top: 5px;
        }
        button {
            background-color: #4285f4;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #3367d6;
        }
        .required:after {
            content: " *";
            color: red;
        }
        .success-message {
            display: none;
            background-color: #d4edda;
            color: #155724;
            padding: 15px;
            border-radius: 4px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <div class="form-container">
        <h1>Student Information Form</h1>
        <p>Please complete all required fields marked with an asterisk (*)</p>
        
        <form id="studentForm" enctype="multipart/form-data">
            <div class="form-group">
                <label for="firstName" class="required">First Name</label>
                <input type="text" id="firstName" name="firstName" required>
            </div>
            
            <div class="form-group">
                <label for="lastName" class="required">Last Name</label>
                <input type="text" id="lastName" name="lastName" required>
            </div>
            
            <div class="form-group">
                <label for="currentSchool" class="required">School Graduating From</label>
                <input type="text" id="currentSchool" name="currentSchool" required>
            </div>
            
            <div class="form-group">
                <label for="futureSchool" class="required">Future School to Attend</label>
                <input type="text" id="futureSchool" name="futureSchool" required>
            </div>
            
            <div class="form-group">
                <label for="major" class="required">Major</label>
                <input type="text" id="major" name="major" required>
            </div>
            
            <div class="form-group">
                <label for="studentImage">Upload Image</label>
                <input type="file" id="studentImage" name="studentImage" accept="image/*">
                <p style="font-size: 14px; color: #666;">Accepted formats: JPG, PNG, GIF (Max size: 5MB)</p>
            </div>
            
            <div class="form-group">
                <label for="email" class="required">Your Email</label>
                <input type="email" id="email" name="email" required>
            </div>
            
            <button type="submit">Submit Information</button>
        </form>
        
        <div id="successMessage" class="success-message">
            Thank you for submitting your information! The details have been sent.
        </div>
    </div>

    <script>
        document.getElementById('studentForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            // Create FormData object to handle file uploads
            const formData = new FormData(this);
            
            // Add recipient email (hidden from user)
            formData.append('recipient', '[email protected]');
            
            // Here you would normally send the data to a server
            // For demo purposes, we'll just show the success message
            document.getElementById('successMessage').style.display = 'block';
            document.getElementById('studentForm').reset();
            
            // In a real implementation, you would use fetch or XMLHttpRequest to send the data
            // Example with fetch:
            /*
            fetch('submit.php', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if(data.success) {
                    document.getElementById('successMessage').style.display = 'block';
                    document.getElementById('studentForm').reset();
                }
            })
            .catch(error => console.error('Error:', error));
            */
        });
    </script>
</body>
</html>
"@

# Output file path
$outputPath = "$env:USERPROFILE\Desktop\student_information_form.html"

# Write the HTML content to a file
$htmlContent | Out-File -FilePath $outputPath -Encoding UTF8

# Create a simple PHP handler script for the form
$phpHandler = @"
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Recipient email address
    $recipient = "[email protected]";
    
    // Get form data
    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];
    $currentSchool = $_POST['currentSchool'];
    $futureSchool = $_POST['futureSchool'];
    $major = $_POST['major'];
    $senderEmail = $_POST['email'];
    
    // Set email subject
    $subject = "New Student Information: $firstName $lastName";
    
    // Initialize message
    $message = "
Student Information:
-------------------
First Name: $firstName
Last Name: $lastName
Current School: $currentSchool
Future School: $futureSchool
Major: $major
Sender's Email: $senderEmail
";

    // Handle file upload
    if(isset($_FILES['studentImage']) && $_FILES['studentImage']['error'] == 0) {
        $tempName = $_FILES['studentImage']['tmp_name'];
        $fileName = $_FILES['studentImage']['name'];
        
        // This is where you would handle the file
        // For an email with attachment, you would need to use a library like PHPMailer
        $message .= "\nAn image file was uploaded: $fileName";
    }
    
    // Email headers
    $headers = "From: $senderEmail" . "\r\n";
    
    // Send email
    if(mail($recipient, $subject, $message, $headers)) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'message' => 'Failed to send email']);
    }
} else {
    // Not a POST request
    echo json_encode(['success' => false, 'message' => 'Invalid request method']);
}
?>
"@

$phpPath = "$env:USERPROFILE\Desktop\submit.php"
$phpHandler | Out-File -FilePath $phpPath -Encoding UTF8

# Display the paths to the created files
Write-Host "Form HTML file created at: $outputPath"
Write-Host "PHP handler created at: $phpPath"
Write-Host ""
Write-Host "Note: To fully implement the email functionality, you'll need to set up a PHP server or modify the JavaScript to use a different backend solution."

# Open the HTML file in the default browser
Start-Process $outputPath