<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="profilecss.css">
  <script src="absenceprofile.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
  $("#btnmessage").click(function(){
    $.post("textprocessing.php",
    {
      phonenumber: $("#phonenumber").val(),
      message: $("#message").val()
    },
    function(status){
      $("#display").html(status);
    });
  });

});

</script>


<script>
$(document).ready(function(){
  $("#btnemail").click(function(){
    $.post("emailprocessing.php",
    {
      email: $("#email").val(),
      emailmessage: $("#emailmessage").val()
    },
    function(status){
      $("#emaildisplay").html(status);
    });
  });

});

</script>





</head>





<body>
  <h1>Individual absentee profile</h1>
  <hr>
  <?php

  require "database.php";

  $id = $_GET["id"];

  //echo $id;
  
  $parts = explode(", ", $id);
  if (count($parts) > 1) {
    $lastname = array_pop($parts);
    $firstname = implode(" ", $parts);
  } else {
    $firstname = $name;
    $lastname = " ";
  }

  // echo "Lastname: $lastname <br>";
// echo "Firstname: $firstname";
  
  $sql = "SELECT PersonID, FirstName, LastName, per_CellPhone, per_Email
 from person_per 
 WHERE FirstName = '$firstname' And LastName = '$lastname' ";





  $data = mysqli_query($conn, $sql);



  $result1 = mysqli_fetch_all($data, MYSQLI_ASSOC);




  ?>
  <button onclick="history.back()">Go Back</button>
  <hr>
  <div class="tableabsent">

    <?php if (empty($data)): ?>
      <p>No </p>
    <?php else: ?>
      <ul>
        <?php foreach ($result1 as $result): ?>

          <table class="tableabsent">
            <tr>
              <th>First Name</th>
              <th> Last Name</th>
              <th> Phone Number</th>
              <th> Phone Number</th>
            </tr>

            <tr>
              <td><?= $result['FirstName'] ?></td>
              <td><?= $result['LastName'] ?></td>
              <td><?= $result['per_CellPhone'] ?></td>
              <td><?= $result['per_Email'] ?></td>

            </tr>
          </table>
        <?php endforeach; ?>
      </ul>
    <?php endif; ?>
  </div>

  <!-- button menu -->

  <div class="grid-container">
    <div class=" borderabsence=">
      <div class="absentmenu">
        <div class="absentMenu"><button onclick="showDiv('div1')">Send a message</button></div>
        <div class="absentMenu"><button onclick="showDiv('div2')">Send email 2</button></div>
        <div class="absentMenu"><button onclick="showDiv('div3')">View Attendance History </button></div>
        <div class="absentMenu"><button onclick="showDiv('div4')">Show Div 4</button></div>
        <div class="absentMenu"><button onclick="showDiv('div5')">Show Div 5</button></div>


      </div>


    </div>
    <!-- menu -->
<!-- send message-->

    <div id="div1" style="display: block;">

      <div>
        
          <div id="display">..</div>
          <div><label for="">Phone Number</label></div>
          <input type="text" name="phonenumber" id="phonenumber" value="<?= $result['per_CellPhone'] ?>" readonly>
          <div><label for="">Enter message</label></div>
          <textarea name="message" id="message" cols="30" rows="10"></textarea>
          <div><button  id="btnmessage">Send</button></div>
        
      </div>

    </div>
<!-- send email -->
    <div id="div2" style="display: none;">
      
            <div id="emaildisplay">..</div>
            <div><label for="">Email address:</label></div>
            <div><input type="email" id="email" name="email" value="<?= $result['per_Email'] ?>"></div>
            <div><textarea name="emailmessage" id="emailmessage" cols="30" rows="10"></textarea></div>
            <div><button id="btnemail">Send</button></div>
          


    </div>


    <!--  -->
    <div id="div3" style="display: none;">
      <h2>View Attendance History </h2>
      <div><input type="hidden" name="" id="individualabsenceinput" value="<?= $result['FirstName'] ?>" onkeyup="showHint(this.value)"></div>
      <button onclick="individualabsence()">Click to view latest attendance</button>
      <p id="individualabsence">..</p>
    </div>

    <!--  -->
    <div id="div4" style="display: none;">
      <h2>Content of Div 4</h2>
      <p>This is the second div, initially hidden.</p>
    </div>

    <!-- -->

    <div id="div5" style="display: none;">
      <h2>Content of Div 5</h2>
      <p>This is the second div, initially hidden.</p>
    </div>

  </div>
  <!-- test -->



</body>

</html>