<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Member Template</title>
    <link rel="stylesheet" href="guestprofile.css">
</head>
<body class="body">
<!-- membertemplate server connection -->

<?php

require 'database.php';

// echo "Haha.. Connected successfully";
//check if numeric to avoid sql injection
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$sql = "SELECT *
FROM person_per
WHERE PersonID = " . $_GET['id'];



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

if ($results === false) {
  // code...
  echo mysqli_error($conn);
} else {
  // code...
  $viewGuests= mysqli_fetch_assoc($results);



}
} else {
  $viewGuests = null;
}
 ?>


       <?php if ($viewGuests === null):?>
         <p>Member no found</p>
       <?php else: ?>
       <!-- <ul>


           <article class="">
             <h2><?= $article['title']; ?></h2>
             <p><?= $article['content']; ?></p>

           </article>


       </ul> -->
     
     



<!-- END of Membertemplate server connection -->




    <div class="guestprofile">
    <div class="qaContainer" style="width:600px;">
        <div class="guestinfo">
        <h2>First Name: <?= $viewGuests['FirstName']; ?></h2>
        <h2>Last Name: <?= $viewGuests['LastName']; ?></h2>
        <h2>Phone Number: <?= $viewGuests['per_CellPhone']; ?></h2></div>
        
        <?php endif; ?>
               
               
            </div>
        <div class="leftContainer" style="float:left;">
            
           <div> <a href="javascript:" onClick="showDiv('1');"><button style="width:100%">send email</button></a></div> <br>
            <div><a href="javascript:" onClick="showDiv('2');"><button style="width:100%">volunteer</button></a></div><br />
            <div><a href="javascript:" onClick="showDiv('7');"><button style="width:100%">Send text message</button></a></div><br />
            <div><a href="javascript:" onClick="showDiv('3');"><button style="width:100%">Add record or view records</button></a></div><br />
            <div><a href="javascript:" onClick="showDiv('4');"><button style="width:100%">Thithes</button></a></div><br />
            <div><a href="javascript:" onClick="showDiv('5');"><button style="width:100%">View Applications</button></a></div><br />
            <div><a href="javascript:" onClick="showDiv('6');"><button style="width:100%">Groups</button></a></div><br />
        </div>
        <div class="right">
        <div class="rightContainer" style="float:right;">
           <div id="div1" style="display:none;">
            <!--Send mail -->
            <div>
    <form action="mailprocessing.php" method="post">
        email :<input type="text" name="email" value="<?= $viewGuests['per_Email']; ?>" readonly><br/>
         subject: <input type="text" name="subject" id=""><br />
         message <textarea style="width: 150px; height:150px" name="message" id=""></textarea>
        <input type="submit">
    </form>
</div>
            <!--End of Send mail --></div> 






            <!--start of volunteer -->
            
            <div id="div2" style="display:none;">Link to become a volunteer comming soon</div>
            
             <!--End of volunteer -->
             
             
             
              <!--start of sending text -->
            
            <div id="div7" style="display:none;">Send text
            
    
<body>
    <div id="formtitle"><h2>Send Message to registered church member or guests</h2></div>
   
    
    <div class="form" id="mainform"><form action="finalconditiontest.php" method="post">
        
      <div > This Phone Number: <input name="number" type="number" value="<?= $viewGuests['per_CellPhone']?>" id="number" readonly"/></div>
      <p>Or</p>
      <div>Select group:
            <input type="checkbox" name="group" value="everyone"> Everyone
            <input type="checkbox" name="group" value="Committee"> Committee
            <input type="checkbox" name="group" value="individual"> individual
        </div>

      <div><label for="">Type Message here</label> </div> 
      <div>  <textarea name="message" id="message" rows="5" cols="40"></textarea></div>
       <div> <input type="submit"></div>

    </form></div
</body>
</html>
            </div>
            
             <!--End of sending text -->
            
             
            
            
            <div id="div3" style="display:none;">
                <!-- add new records and view records -->
                <div><a href="viewrecords.php"><p>View all records for <?= $viewGuests['FirstName']; ?></p></a></div>
                <div>Add new record below</div><br />
             <form action="addmembernewrecords.php" method="post">
              <input type="date" name="date" id="date">
              <input type="hidden" id="GuestID" name="PersonID" value="<?= $viewGuests['PersonID']; ?>" readonly> <br />
              <textarea name="writerecord" id="writerecord" placeholder="start typing record" style="height:300px"></textarea>
              <center><input type="submit"></center>
             </form>    
            </div>
            <div id="div4" style="display:none;">
                <!-- add new thithes and view thithes info -->

                <?php
  if ($_SERVER["REQUEST_METHOD"] == "POST") {

    require 'db.php';

    $current_date = date("Y-m-d");
    // code...
    $sql = "INSERT INTO thites (member, ThithesAmount, ThithesDate)
              VALUES ('" . mysqli_escape_string($con, $_POST['member']) . "', '"
                          . mysqli_escape_string($con, $_POST['amount']) . "','"
                          . mysqli_escape_string($con, $_POST['Date']) . "')";

    $results = mysqli_query($con, $sql);

    if ($results === false) {
      echo mysqli_error($con);
    } else {

      $id = mysqli_insert_id($con);
       echo "thithes enter successfully with $id";
    }


  }

   ?>

           <form method="post">
            
            <label for="">Enter thites for:</label>
            <input type="text" name="member" id="" value="<?= $viewGuests['FirstName'];?> <?= $viewGuests['LastName'];?>" readonly style="width: 50%"><br />
           <br>
            date: <input type="date" name="Date" id="tithes"><br/>
            <div>Amount: <input name="amount" type="number" min="1" step="any" style="width:40%">$</div><br/>
            <center><input type="submit"></center>
            </form>
            <div class="viewthithes">
              <p>view amount of thithes for:<br/> <?= $viewGuests['FirstName'];?></p> <br/>
                <form action="thithestotalperperson.php" method="post">
                  <input id="member" name="memberName" type="hidden" value="<?= $viewGuests['FirstName'];?> <?= $viewGuests['LastName'];?>">
                  <input type="submit">
                </form>
            </div>

            <div>
              <form action="thithesoverview.php" method="post">
              <input id="member" name="memberName" type="hidden" value="<?= $viewGuests['FirstName'];?> <?= $viewGuests['LastName'];?>">
                  <input type="submit" value="print thithes statement"></form>
            </div>
          
          </div>
            <div id="div5" style="display:none;">Applications</div>
            <div id="div6" style="display:none;"> 
              
    <!-- Approve Membership -->
              <?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

  require 'database.php';
  // code...
  $sql = "INSERT INTO person_per (FirstName, LastName, per_Address1, per_City, per_Zip, per_Email, per_CellPhone, per_State)
            VALUES ('" . mysqli_escape_string($conn, $_POST['FirstName']) . "', '"
                        . mysqli_escape_string($conn, $_POST['LastName']) . "','"
                        . mysqli_escape_string($conn, $_POST['per_City']) . "','"
                        . mysqli_escape_string($conn, $_POST['per_Zip']) . "','"
                        . mysqli_escape_string($conn, $_POST['per_Email']) . "','"
                        . mysqli_escape_string($conn, $_POST['per_State']) . "','"
                        . mysqli_escape_string($conn, $_POST['per_CellPhone']) . "','"
                        . mysqli_escape_string($conn, $_POST['per_Address1']) . "')";

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

  if ($results === false) {
    echo mysqli_error($conn);
  } else {

    $id = mysqli_insert_id($conn);
    echo "Member has been approved with this $id";
  }


}

 ?>


            <h2> Approve Membership</h2>
            <h3> Verify and correct info</h3>
              <h3>before approve it</h3>
            
              <form action="approvemembership.php" method="post">
                First Name: <input type="text" name="FirstName" id="FirstName" value="<?= $viewGuests['FirstName']; ?> " readonly><br />
                Last Name: <input type="text" name="LastName" id="LastName" value="<?= $viewGuests['LastName']; ?>" readonly> <br />
                Phone Number: <input type="text" name="per_CellPhone" id="per_CellPhone" value="<?= $viewGuests['per_CellPhone']; ?>" readonly><br />
                Email: <input type="text" name="per_Email" id="per_Email" value="<?= $viewGuests['per_Email']; ?>" readonly><br>
                Address : <input type="text" name="per_Address1" id="per_Address1"><br>
                City: <input type="text" name="per_City" id="per_City"><br>
                State: <input type="text" name="per_State" id="per_State"><br>
                ZipCode: <input type="text" name="per_Zip" id="per_Zip"><br>
                Country: <input type="text" name="per_Country" id="per_Country"><br>

                <center><input type="submit" name="" id=""></center>

              </form>
              
            
          </div>
        </div>
    </div>
</div>

        <script>
            function showDiv(id) {  
    for (var i=1;i<=6;i++)
    {
        document.getElementById('div'+i).style.display = 'none';
    }
    document.getElementById('div'+id).style.display = 'block';
}
        </script>
</body>
</html>