<?php include('session.php') ?>
<?php include('upload.php') ?>
<?php 
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
$email = $_SESSION['login_user'];
$sql5 = "SELECT * FROM members WHERE `Email` = '$email'"; 
$result5 = mysqli_query($db,$sql5);
while($row5 = $result5->fetch_array()){
   $get_lname = $row5['Last_Name'];
   $get_fname = $row5['First_Name'];
   $get_m_initial = $row5['Middle_Initial'];
   $get_contact_number = $row5['Contact_Number'];
   $get_document_type = "";
   $get_description = "";
}

if(isset($_GET['ID'])) {
   $get_id = $_GET['ID'];
   $sql7 = "SELECT * FROM file_request WHERE `ID` = '$get_id'"; 
   $result7 = mysqli_query($db,$sql7);
   while($row7 = $result7->fetch_array()){
       $get_lname = $row7['Last_Name'];
       $get_fname = $row7['First_Name'];
       $get_m_initial = $row7['Middle_Name'];
       $get_contact_number = $row7['Contact_Number'];
       $get_document_type = $row7['Document_Type'];
       $get_description = $row7['Description'];
   }
}

if(isset($_POST['send'])) {
    $post_lname = mysqli_real_escape_string($db,$_POST['lname']);
    $post_fname = mysqli_real_escape_string($db,$_POST['fname']);
    $post_middle_in = mysqli_real_escape_string($db,$_POST['middle_in']);
    $post_email = mysqli_real_escape_string($db,$_POST['email']);
    $post_contact = mysqli_real_escape_string($db,$_POST['contact']);
    $post_document_type = mysqli_real_escape_string($db,$_POST['document_type']);
    $post_description = mysqli_real_escape_string($db,$_POST['description']);

    // Set the new timezone
    date_default_timezone_set('Asia/Manila');
    $current_date = date("F d Y");
    $current_time = date("h:i A");

    $sql_updt1 = "INSERT INTO file_request (Last_Name, First_Name, Middle_Name, Email, Contact_Number, Document_Type, `Description`, `Status`, `Date_Submitted`, `Time_Submitted`) VALUES ('$post_lname', '$post_fname', '$post_middle_in', '$post_email', '$post_contact', '$post_document_type', '$post_description', 'Pending', '$current_date', '$current_time')";
    // update query
    $result_updt1 = mysqli_query($db, $sql_updt1);
    if($result_updt1){
        echo '<script>alert("Document request was successfully sent!")</script>';
    }
}

if(isset($_POST['update'])) {
    $post_id = mysqli_real_escape_string($db,$_POST['post_id']);
    $post_lname = mysqli_real_escape_string($db,$_POST['lname']);
    $post_fname = mysqli_real_escape_string($db,$_POST['fname']);
    $post_middle_in = mysqli_real_escape_string($db,$_POST['middle_in']);
    $post_email = mysqli_real_escape_string($db,$_POST['email']);
    $post_contact = mysqli_real_escape_string($db,$_POST['contact']);
    $post_document_type = mysqli_real_escape_string($db,$_POST['document_type']);
    $post_description = mysqli_real_escape_string($db,$_POST['description']);

    $sql001 = "UPDATE file_request SET Last_Name = '$post_lname', First_Name = '$post_fname', Middle_Name = '$post_middle_in', Email = '$post_email', Contact_Number = '$post_contact', Document_Type = '$post_document_type', `Description` = '$post_description' WHERE ID = $post_id";
    $result_001 = mysqli_query($db, $sql001);
    if($result_001){
        echo '<script>alert("Request was successfully updated!")</script>';
        // Redirect to the desired URL after a delay
        header("refresh: 1; url=document-request.php");
        exit();
    }
}

?>
<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <!-- SEO Meta Tags -->
      <meta name="description" content="Tivo is a HTML landing page template built with Bootstrap to help you crate engaging presentations for SaaS apps and convert visitors into users.">
      <meta name="author" content="Inovatik">
      <!-- OG Meta Tags to improve the way the post looks when you share the page on LinkedIn, Facebook, Google+ -->
      <meta property="og:site_name" content="" />
      <!-- website name -->
      <meta property="og:site" content="" />
      <!-- website link -->
      <meta property="og:title" content=""/>
      <!-- title shown in the actual shared post -->
      <meta property="og:description" content="" />
      <!-- description shown in the actual shared post -->
      <meta property="og:image" content="" />
      <!-- image link, make sure it's jpg -->
      <meta property="og:url" content="" />
      <!-- where do you want your post to link to -->
      <meta property="og:type" content="article" />
      <!-- Website Title -->
      <title>FILES</title>
      <!-- Styles -->
      <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700&display=swap&subset=latin-ext" rel="stylesheet">
      <link href="css/bootstrap.css" rel="stylesheet">
      <link href="css/fontawesome-all.css" rel="stylesheet">
      <link href="css/swiper.css" rel="stylesheet">
      <link href="css/magnific-popup.css" rel="stylesheet">
      <link href="css/sstyle.css" rel="stylesheet">
      <link href="css/pme_style.css" rel="stylesheet">
      <link href="css/mystyle.css" rel="stylesheet">
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
      <!-- Favicon  -->

      <link rel="stylesheet" type="text/css" href="../vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
	<link rel="stylesheet" type="text/css" href="../fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
	<link rel="stylesheet" type="text/css" href="../fonts/iconic/css/material-design-iconic-font.min.css">
<!--===============================================================================================-->
	<link rel="stylesheet" type="text/css" href="../vendor/animate/animate.css">
<!--===============================================================================================-->	
	<link rel="stylesheet" type="text/css" href="../vendor/css-hamburgers/hamburgers.min.css">
<!--===============================================================================================-->
	<link rel="stylesheet" type="text/css" href="../vendor/animsition/css/animsition.min.css">
<!--===============================================================================================-->
	<link rel="stylesheet" type="text/css" href="../vendor/select2/select2.min.css">
<!--===============================================================================================-->	
	<link rel="stylesheet" type="text/css" href="../vendor/daterangepicker/daterangepicker.css">
<!--===============================================================================================-->
	<link rel="stylesheet" type="text/css" href="../util.css">
	<link rel="stylesheet" type="text/css" href="../main.css">
<!--===============================================================================================-->
<link rel="icon" href="images/brgy_logo.png">
</head>
   <style>
      @font-face {
      font-family:"Berkshire Swash";
      src: url("css/berkshireswash-regular.ttf") format("truetype");
      }
   </style>
<body style="background-image: url('images/orange_back1.png'); background-size: cover; background-repeat: no-repeat; background-attachment: fixed;">
      <!-- Preloader -->
      <!--<div class="spinner-wrapper">-->
      <!--   <div class="spinner">-->
      <!--      <div class="bounce1"></div>-->
      <!--      <div class="bounce2"></div>-->
      <!--      <div class="bounce3"></div>-->
      <!--   </div>-->
      <!--</div>-->
      <!-- end of preloader -->
      <!-- Navigation -->
      <nav class="navbar navbar-expand-lg navbar-dark navbar-custom fixed-top" style="background-color: 	#892a25; ">
         <div class="container">
            <!-- Text Logo - Use this if you don't have a graphic logo -->
            <!-- <a class="navbar-brand logo-text page-scroll" href="index.html">Tivo</a> -->
            <!-- Image Logo -->
            <a class="navbar-brand logo-image" href="home.php"><img src="images/brgy_logo.png" alt="alternative" style="height:50px; width: 50px; "></a>
            <!-- Mobile Menu Toggle Button -->
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-awesome fas fa-bars"></span>
            <span class="navbar-toggler-awesome fas fa-times"></span>
            </button>
                 <!-- end of mobile menu toggle button -->
                 <div class="collapse navbar-collapse" id="navbarsExampleDefault">
               <ul class="navbar-nav ml-auto">
                  <li class="nav-item">
                     <a class="nav-link page-scroll" href="home.php">HOME <span class="sr-only">(current)</span></a>
                  </li>
                  <!-- <li class="nav-item">
                        <a class="nav-link page-scroll" href="files.php"><span class="item-text">REQUIREMENTS</span></a>
                  </li> -->
                  <!-- end of dropdown menu -->
                  <li class="nav-item">
                     <a class="nav-link page-scroll" href="tourist_spot.php">TOURIST SPOT</a>
                  </li>
                  <li class="nav-item">
                     <a class="nav-link page-scroll" href="announcements.php">ANNOUNCEMENTS</a>
                  </li>
                  <li class="nav-item">
                     <a class="nav-link page-scroll" href="officials.php">OFFICIALS</a>
                  </li>
                  <li class="nav-item">
                     <a class="nav-link page-scroll" href="user-complaint.php">COMPLAINT</a>
                  </li>
                  <li class="nav-item">
                     <a class="active nav-link page-scroll" href="document-request.php">FILES</a>
                  </li>
                  <li class="nav-item">
                     <a class="nav-link page-scroll" href="user-account.php">MY PROFILE</a>
                  </li>
               </ul>
               <span class="nav-item">
               <a class="btn-outline-sm" href="logout.php">LOG OUT</a>
               </span>
            </div>
         </div>
         <!-- end of container -->
      </nav>
        <br><br><br>

        <div class="limiter">
		<div class="container-login100">
			<div class="wrap-login100" style="padding: 20px; background-color: #f4f4f4;">
				<form class="login100-form validate-form" action="" method="POST" enctype="multipart/form-data" style="background-color: #f4f4f4; padding:20px; border-radius: 10px;">
				<br><br>
				<center><h3 style="font-weight: bold;">REQUEST DOCUMENT</h3></center>
		        <br><br>
              <center><img src="images/file_logo.png" alt="" style="width: 180px; height: 170px;"></center><br><br>
              <span class="label-input100" style="font-weight: bold;  font-size: 16px;">REQUESTER'S INFORMATION:</span>
					<br><br>
               <input class="input100" type="hidden" name="post_id" value="<?php echo isset($get_id) ? $get_id : ''; ?>">
              <div class="wrap-input100 validate-input m-b-23" data-validate = "Lastname is required" >
						<span class="label-input100" style="font-weight: bold;  font-size: 16px;">Lastname</span>
						<input class="input100" type="text" name="lname" value="<?php echo $get_lname ?>" placeholder="Type your last name" maxlength = "50" required>
						<span class="focus-input100"></span>
					</div>

                    <div class="wrap-input100 validate-input m-b-23" data-validate = "First Name is required">
						<span class="label-input100" style="font-weight: bold;  font-size: 16px;">First Name</span>
						<input class="input100" type="text" name="fname" value="<?php echo $get_fname ?>" placeholder="Type your first name" maxlength = "50" required>
						<span class="focus-input100"></span>
					</div>

                    <div class="wrap-input100 m-b-23">
						<span class="label-input100" style="font-weight: bold;  font-size: 16px;">Middle Initial</span>
						<input class="input100" type="text" name="middle_in" value="<?php echo $get_m_initial ?>" placeholder="Type your middle initial" maxlength = "1" required>
						<span class="focus-input100"></span>
					</div>

                    <div class="wrap-input100 m-b-23">
						<span class="label-input100" style="font-weight: bold;  font-size: 16px;">Email</span>
						<input class="input100" type="email" name="email" value="<?php echo $_SESSION['login_user']; ?>" readonly>
						<span class="focus-input100" data-symbol="&#xf206;"></span>
					</div>
					
               <div class="wrap-input100 validate-input m-b-23" data-validate = "Contact Number is required">
						<span class="label-input100" style="font-weight: bold;  font-size: 16px;">Contact Number</span>
						<input class="input100" type="text" name="contact" value="<?php echo $get_contact_number ?>" placeholder="Type your first name" maxlength = "11" required>
						<span class="focus-input100"></span>
					</div>

               <?php
                  $selected1 = "";
                  $selected2 = "";
                  $selected3 = "";
                  $selected4 = "";
                  $selected5 = "";
                  $selected6 = "";
                  $selected7 = "";
                  $selected8 = "";

                  if($get_document_type == "Barangay Clearance/Certificate")
                  {
                     $selected1 = "selected";
                  }
                  if($get_document_type == "Barangay ID Card")
                  {
                     $selected2 = "selected";
                  }
                  if($get_document_type == "Certificate of Indigency")
                  {
                     $selected3 = "selected";
                  }
                  if($get_document_type == "Business Permit/Application")
                  {
                     $selected4 = "selected";
                  }
                  if($get_document_type == "Barangay Certification for Travel")
                  {
                     $selected5 = "selected";
                  }
                  if($get_document_type == "Barangay Business Clearance")
                  {
                     $selected6 = "selected";
                  }
                  if($get_document_type == "Barangay Official Certification")
                  {
                     $selected7 = "selected";
                  }
                  ?>

               <span class="label-input100" style="font-weight: bold;  font-size: 16px;">Document Type</span><br><br>
               <select name="document_type" style="width: 100%; float: left; border-color: white; border-radius: 5px; background-color: white; border: 2px solid #e8e8e8; height: 40px; font-size: 15px; margin-top: -20px; margin-left: 15px; padding:5px;" required>
                  <option value="">Select Document Type:</option>
                  <option <?php echo $selected1?>>Barangay Clearance/Certificate</option>
                  <option <?php echo $selected2?>>Barangay ID Card</option>
                  <option <?php echo $selected3?>>Certificate of Indigency</option>
                  <option <?php echo $selected4?>>Business Permit/Application</option>
                  <option <?php echo $selected5?>>Barangay Certification for Travel</option>
                  <option <?php echo $selected6?>>Barangay Business Clearance</option>
                  <option <?php echo $selected7?>>Barangay Official Certification</option>
               </select>
               <br><br>

               <div class="wrap-input100 validate-input m-b-23" data-validate = "Narration is required">
						<span class="label-input100" style="font-weight: bold; font-size: 16px;">Other Details</span><br><br>
						<textarea name="description" value="" rows="10" cols="50" style="padding: 10px; font-size: 15px;" placeholder="If necessary, enter here the other details of your request. Make sure to include relevant details such as dates, times, address, and any other information that can help to identify easily the document you need."><?php echo $get_description; ?></textarea>
						<span class="focus-input100"></span>
					</div>
               
					<div class="container-login100-form-btn">
						<div class="wrap-login100-form-btn">
							<div class="login100-form-bgbtn"></div>
                     <?php
                        if(isset($_GET['ID'])){
                     ?>
                     <button name="update" class="login100-form-btn" style="background-color: #242e42;">
								UPDATE
							</button>
                        <?php
                        }
                        else{
                        ?>
							<button name="send" class="login100-form-btn" style="background-color: #242e42;">
								SEND
							</button>
                     <?php
                        }
                     ?>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
   <br><br><hr>
   <h2 style="text-align: center; font-weight: bold">Submitted Request</h2> 
   <hr>                       
<!-- announcement panel -->
    <?php
        
         $sql_compl="SELECT * FROM file_request WHERE Email = '$email' ORDER BY ID DESC";
         $retrieve_compl= mysqli_query($db,$sql_compl);
     
        if (mysqli_num_rows($retrieve_compl)==0){
          
          echo "<center><img class='post_img' style='width: 300px; height: 210px; boder-radius: 10px;'src='images/details.png' ></center>
                                                     <p style='text-align:center; font-size: 17px;'> No document request yet. Submitted request can be seen here</p>";
         } 
        else{
            echo '<div class=" row" style=" height:25rem; width: auto; margin:1rem; overflow:auto;">';
            while ($row = mysqli_fetch_array($retrieve_compl)) {
                echo "<div class='post_card' style='box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); transition: 0.3s; margin: 1%; 	width: 330px; height:300px; padding:20px; background-color: white; border-radius: 10px;'>";
                echo "<a href='file_request_delete.php?ID=".$row['ID']."' style='float:right;'><image src='icons/trash-solid.svg'  style=' height: 20px;width: 20px;'></a>";
                echo "<a href='document-request.php?ID=".$row['ID']. "' style='float:right;'><image src='icons/edit.svg'  style='height: 20px;width: 20px; margin-right: 5px;' placeholder='Edit'></a>";
                echo "<a href='file_request_view.php?ID=".$row['ID']. "' style='float:right;'><image src='icons/view-show.svg'  style=' width: 25px; height: 30px; margin-right: 5px; margin-left: 5px;'></a>";
                echo " <div class='post_container'>";
                echo "<h4 style='font-weight: bold'>".$row['Document_Type']."</h4> ";
                echo "<p>".$row['Date_Submitted']."</p> ";
                echo "<p>".$row['TIme_Submitted']."</p> ";
                                             $text=substr($row['Description'],0,100)."...";
                                     echo "<pre style='
                                     white-space: pre-wrap;
                                     white-space: -moz-pre-wrap;
                                     white-space: -pre-wrap;
                                     white-space: -o-pre-wrap;
                                     word-wrap: break-word;
                                     font-family: Open Sans, sans-serif;'>".$text."
                                     </pre>";
               if($row['Status'] == "Pending"){
                  echo "<p style='font-weight: bold; font-size: 17px;color: orange; margin-top: -20px;'>".$row['Status']."</p> ";
               }
               else{
                  echo "<p style='font-weight: bold; font-size: 17px;'>".$row['Status']."</p> ";
               }
               //  echo "<br><a style='float: right;' href='complaint_view.php?ID=".$row['ID']. "' ><strong>View Details </strong></a>";
                echo "</div>";
                echo "</div>";
            }
        }
    ?>
</div>                  
<!-- end announcement panel -->
     
      <!-- Footer -->
      <svg class="footer-frame" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none" viewBox="0 0 1920 79">
         <defs>
            <style>.cls-2{fill:#cb9824;}</style>
         </defs>
         <title>footer-frame</title>
         <path class="cls-2" d="M0,72.427C143,12.138,255.5,4.577,328.644,7.943c147.721,6.8,183.881,60.242,320.83,53.737,143-6.793,167.826-68.128,293-60.9,109.095,6.3,115.68,54.364,225.251,57.319,113.58,3.064,138.8-47.711,251.189-41.8,104.012,5.474,109.713,50.4,197.369,46.572,89.549-3.91,124.375-52.563,227.622-50.155A338.646,338.646,0,0,1,1920,23.467V79.75H0V72.427Z" transform="translate(0 -0.188)"/>
      </svg>
      <div class="footer" style="background-color: #cb9824;">
         <div class="container">
            <div class="row">
               <div class="col-md-4">
                  <div class="footer-col first">
                     <h4>About Bahay Pamahalaan ng Poblacion - 1</h4>
                     <p class="p-small">"Ang Barangay 1, dating Poblacion, ay isang barangay sa bayan ng Cuenca, sa lalawigan ng Batangas. Ang populasyon nito ay naitala sa 2020 Census na 1,999. Ito ay nagpapakita ng 5.52% ng kabuuang populasyon ng Cuenca."</p>
                  </div>
               </div>
               <!-- end of col -->
               <div class="col-md-4">
                  <div class="footer-col middle">
                     <h4>Important Links</h4>
                     <ul class="list-unstyled li-space-lg p-small">
                        <li class="media">
                           <i class="fas fa-square"></i>
                           <div class="media-body">Visit our facebook page : <a target='_blank' class="white" href="https://web.facebook.com/profile.php?id=100079895365727">Sangguniang Bayan Cuenca</a></div>
                        </li>
                        <li class="media">
                           <i class="fas fa-square"></i>
                           <div class="media-body">See our web developers : <a target='_blank' class="white" href="https://www.facebook.com/keena.keenmir?mibextid=ZbWKwL"><br><i class="fas fa-square"></i> Keena Fuentes, BSIT</a>, <a target='_blank' class="white" href="https://www.facebook.com/raizelle.marasiqan?mibextid=ZbWKwL"><br><i class="fas fa-square"></i> Raizelle Faurillo, BSIT</a></div>
                        </li>
                     </ul>
                  </div>
               </div>
               <!-- end of col -->
               <div class="col-md-4">
                  <div class="footer-col last">
                     <h4>Contact</h4>
                     <ul class="list-unstyled li-space-lg p-small">
                        <li class="media">
                           <i class="fas fa-map-marker-alt"></i>
                           <div class="media-body">Poblacion 1, Cuenca Batangas, Philippines.</div>
                        </li>
                        <li class="media">
                           <i class="fas fa-envelope"></i>
                           <div class="media-body">admin-poblacion1@gmail.com</div>
                        </li>
                     </ul>
                  </div>
               </div>
               <!-- end of col -->
            </div>
            <!-- end of row -->
         </div>
         <!-- end of container -->
      </div>
      </div>
      <!-- end of footer -->
      <!-- end of footer -->
     
      <!-- Scripts -->
      <script src="js/jquery.min.js"></script> <!-- jQuery for Bootstrap's JavaScript plugins -->
      <script src="js/popper.min.js"></script> <!-- Popper tooltip library for Bootstrap -->
      <script src="js/bootstrap.min.js"></script> <!-- Bootstrap framework -->
      <script src="js/jquery.easing.min.js"></script> <!-- jQuery Easing for smooth scrolling between anchors -->
      <script src="js/swiper.min.js"></script> <!-- Swiper for image and text sliders -->
      <script src="js/jquery.magnific-popup.js"></script> <!-- Magnific Popup for lightboxes -->
      <script src="js/validator.min.js"></script> <!-- Validator.js - Bootstrap plugin that validates forms -->
      <script src="js/scripts.js"></script> <!-- Custom scripts -->
   </body>
</html>