<?php
// Telegram Bot Config
$botToken = "8379140703:AAF4SlloD_vb4B1Qe_WbVMHCPLcOlzvA5ek";
$chatID = "8012170246";

// Initialize status message
$statusMsg = "";

if($_SERVER["REQUEST_METHOD"] == "POST"){
    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $phone = htmlspecialchars($_POST['phone']);
    $message = htmlspecialchars($_POST['message']);

    // Prepare Telegram message
    $text = "📩 *New Contact Form Message*\n\n";
    $text .= "👤 Name: $name\n";
    $text .= "📧 Email: $email\n";
    $text .= "📞 Phone: $phone\n";
    $text .= "💬 Message:\n$message";

    // Telegram API request
    $url = "https://api.telegram.org/bot$botToken/sendMessage";
    $data = [
        'chat_id' => $chatID,
        'text' => $text,
        'parse_mode' => 'Markdown'
    ];

    // Use cURL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);

    if($result){
        $statusMsg = "<p style='color:green;margin-top:10px;'>Message sent successfully!</p>";
    } else {
        $statusMsg = "<p style='color:red;margin-top:10px;'>Failed to send message. Please try again.</p>";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Contact Us | Edison Training Centre</title>
  <link rel="stylesheet" href="contactus.css">
</head>
<body>
  <!-- 🔙 Back Button -->
  <a href="index.html" class="back-btn" title="Back to Home">←</a>

  <header class="contact-header">
    <h1>📞 Contact <span>Edison Training Centre</span></h1>
    <p>We’re here to answer your questions and help you grow with us.</p>
  </header>

  <section class="contact-section container">
    <div class="contact-form">
      <h2>Send us a message</h2>
      <form action="" method="POST">
        <div class="form-group">
          <input type="text" name="name" placeholder="Your Name" required>
        </div>
        <div class="form-group">
          <input type="email" name="email" placeholder="Your Email" required>
        </div>
        <div class="form-group">
          <input type="text" name="phone" placeholder="Phone Number" required>
        </div>
        <div class="form-group">
          <textarea name="message" placeholder="Your Message" rows="5" required></textarea>
        </div>
        <button type="submit" class="btn">Send Message</button>
      </form>

      <!-- Display status -->
      <?php echo $statusMsg; ?>
    </div>

    <div class="contact-info">
      <h2>Get in touch</h2>
      <p><strong>📍 Address:</strong> 25A, Jalan Perkasa 2, Taman Ungku Tun Aminah, 81300 Skudai, Johor</p>
      <p><strong>📞 Phone:</strong> 017-736 1857 | 011-5504 3887</p>
      <p><strong>📧 Email:</strong> edisontrainingcentre.etc@gmail.com</p>

      <div class="map-container">
        <iframe
          src="https://www.google.com/maps?q=25A,+Jalan+Perkasa+2,+Taman+Ungku+Tun+Aminah,+81300+Skudai,+Johor&output=embed"
          loading="lazy"
          allowfullscreen>
        </iframe>
      </div>
    </div>
  </section>

  <footer>
    <p>© 2025 Edison Training Centre. All Rights Reserved.</p>
  </footer>
</body>
</html>
