<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>NGE EMS | Tasks</title>

  <?php
  include 'header.php';
  include 'navbar.php';
  ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Tasks</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Tasks</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
    
      <!-- Default box -->
      <div class="card">
        <div class="card-header">
          <h3 class="card-title">Tasks</h3>
        </div>
        <div class="card-body p-0">
          <table class="table table-striped projects">
              <thead>
                  <tr>
                      <th style="width: 1%">
                        #
                      </th>
                      <th style="width: 20%">
                        Task Name  
                      </th>
                      <th style="width: 30%">
                        Description
                      </th>
                      <th>
                        Unit
                      </th>
                      <th style="width: 8%" class="text-center">
                        Price
                      </th>
                      <th style="width: 20%">
                      </th>
                  </tr>
              </thead>
              <tbody>
                <?php
                    $query1 = $db->query("SELECT * FROM tasks ORDER BY id DESC");
                    if($query1->num_rows > 0){
                      while($row = $query1->fetch_assoc()){
                        $task_id = $row["id"];
                        $task_name = $row["task_name"];
                        $task_desc = $row["task_desc"];
                        $task_unit_id = $row["unit_id"];
                        $task_price = $row["price"];?>
                  <tr>
                      <td>
                        <?php echo $task_id; ?>
                      </td>
                      <td>
                        <?php echo $task_name; ?>
                      </td>
                      <td>
                        <?php echo $task_desc; ?>
                      </td>
                      <td>
                        <?php 
                        $unit_name = '';
                        $query2 = $db->query("SELECT unit_name FROM units WHERE id ='".$task_unit_id."'");
                        if($query2->num_rows > 0){
                            while($row = $query2->fetch_assoc()){
                            $unit_name = $row["unit_name"];
                            echo $unit_name;}};
                        ?>
                      </td>
                      <td class="project-state">
                        <?php echo $task_price; ?>
                      </td>
                      <td class="project-actions text-right">
                        <form name="taskEdit" action="task-edit.php" method="post">
                          <input name="task_id" value='<?php echo $task_id; ?>' hidden>
                          <input type="submit" class="btn btn-success btn-sm" id="submit" name="submit" value="Edit">
                        </form>
                      </td>
                  </tr>
                <?php } }; //$db->close();
                ?>
              </tbody>
          </table>

        </div>
        <!-- /.card-body -->
      </div>
      <!-- /.card -->
    
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

    <!-- Footer -->
    <?php
        include 'footer.php'; //Pages footer
    ?>
