<?php
require_once 'connection.php';

$enquiry_date = date("l dS M \'y");

$drg = isset($_GET['drg']) ? $_GET['drg'] : '';

if (!empty($_GET['drg'])) {
    include "table.php";
}

$check = "<i class='h2 bi bi-check-circle-fill text-success'></i>";
$cross = "<i class='h2 bi bi-x-circle-fill brown-light'></i>";
$urgent = "<i class='h2 bi bi-exclamation-circle-fill text-warning'></i>";
$not_required = "<i class='h2 bi bi-dash-circle-fill'></i>";

?>
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Dashboard</title>
        <link rel="shortcut icon" href="images/blueprint.ico" type="image/x-icon">
        <link href="css/bootstrap.css" rel="stylesheet">
        <link href="css/blueprint.css" rel="stylesheet">
        <link href="css/print.css" rel="stylesheet" media="print">


        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>

    </head>
    <body>

        <nav class="navbar bg-brown-dark brown-light border-bottom border-body d-print-none" data-bs-theme="dark">
            <div class="container-fluid">
                <a class="navbar-brand brown-light" href="dashboard.php">
                    <img src="images/blueprint-logo-light.png" alt="Logo" width="30" height="24" class="d-inline-block align-text-top">
                    Modulos Design
                </a>
				<div class="ml-auto ms-auto">
  					<a href="create_enquiry.php" class="btn btn-sm bg-brown-three brown-five">
    				<i class="bi bi-plus-circle"></i> Create enquiry
  					</a>
				</div>
            </div>
        </nav>


        <div class="container-fluid">
            <div class="row">
                <div class="col px-0">
                    <table class="table table-sm">
                        <thead class="align-top text-center">
                            <tr>
                                <th scope="col" class="align-middle" style="width: 3%;">Drg</th>
                                <th scope="col" class="align-middle" style="width: 15%;" >Client Name</th>
                                <th scope="col" class="align-middle" style="width: 10%;">Build Type</th>
                            	<th scope="col" class="align-middle" style="width: 5%;">Site Visit</th>
                                <th scope="col" class="align-middle" style="width: 5%;">PID</th>
                                <th scope="col" class="align-middle" style="width: 5%;">Tite Detail</th>

								<th scope="col" class="align-middle" style="width: 5%;">Progress<br><span class="small fw-light">Admin</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">Title<br><span class="small fw-light">Copy</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">Original<br><span class="small fw-light">Plans</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">LOA<br><span class="small fw-light">Signed</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">DA<br><span class="small fw-light">Application</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">BA<br><span class="small fw-light">Application</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">Fire<br><span class="small fw-light">Report</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;">Energy<br><span class="small fw-light">Assesment</span></th>
                                <th scope="col" class="align-middle" style="width: 5%;"></th>
                                
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            	<th scope="col" class="align-middle" ></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $result = mysqli_query($con, " SELECT * FROM `details` JOIN `addresses` ON `details`.`drg` = `addresses`.`drg` ORDER BY `details`.`drg` DESC ");
                            if (!$result) {
                                printf("Error: %s\n", mysqli_error($con));
                                exit();
                            }

                            while ($row = mysqli_fetch_array($result)) {

                            	$drg = (int)$row['drg'];
                                if ( $row['copy_title'] === '1') { $title = "$check"; } else { $title = "$cross"; }
                                if ( $row['original_plans'] === '1') { $original_plans = "$check"; } else { $original_plans = "$cross"; }
                                if ( $row['loa_signed'] === '1') { $loa_signed = "$check"; } else { $loa_signed = "$cross"; }
                                if ( $row['da_application'] === '1') { $da_application = "$check"; } else { $da_application = "$cross"; }
                                if ( $row['ba_application'] === '1') { $ba_application = "$check"; } else { $ba_application = "$cross"; }

                                if ( $row['fire_report'] === '1') { $fire_report = "$check"; } else { $fire_report = "$cross"; }
                                if ( $row['energy_report'] === '1') { $energy_report = "$check"; } else { $energy_report = "$cross"; }
                            	if ( $row['site_visit'] === '1') { $site_visit = "$check"; } else { $site_visit = "$cross"; }

                                echo "<tr class='border-bottom border-dark'>";
                                echo "<th scope='row' class='border-end text-center'><a class='brown-three text-decoration-none' href='client-brief.php?drg=$drg'>" . $drg . "</a></th>";
                                echo "<td><span class='fw-bold'>" . $row['firstname'] . " " . $row['lastname'] . '</span><br><span class="small">' . $row['site_address_street'] . ', ' . $row['site_address_town'] . "</span></td>";
                                echo "<td>" . $row['build_type'] . "</td>";
                            	echo "<td class='text-center'>" . $site_visit . "</td>";
                                echo "<td>" . $row['property_id'] . "</td>";
                                echo "<td class='border-end' >" . $row['title_id'] . "</td>";

                            	echo "<td class='text-center'><a class='brown-three text-decoration-none' href='https://modulosdesign.com.au/contracts/edit_application.php?id=$drg'><i class='h2 bi bi-speedometer'></i></a></td>";
                            	
                                echo "<td class='text-center'>" . $title . "</td>";
                                echo "<td class='text-center'>" . $original_plans . "</td>";
                                echo "<td class='text-center'>" . $loa_signed . "</td>";
                                echo "<td class='text-center'>" . $da_application . "</td>";
                                echo "<td class='text-center border-end'>" . $ba_application . "</td>";
                                echo "<td class='text-center'>" . $fire_report . "</td>";
                                echo "<td class='text-center'>" . $energy_report . "</td>";
                                echo "<td class='text-center'></td>";
                                echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                            	echo "<td class=''></td>";
                                echo "</tr>";
                            }
                            ?>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <script type="text/javascript">

        </script>

        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
<!--
    	<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB-QceOYrDe9otynMmQ9iNF3yEZzbpsanM&libraries=places&callback=initAutocomplete" async defer></script>

        <script src="https://cdn.jsdelivr.net/npm/signature_pad@4.0.0/dist/signature_pad.umd.min.js"></script>
        <script src="js/signature.js" ></script>

        <script async defer src="https://apis.google.com/js/api.js" onload="gapiLoaded()"></script>
        <script async defer src="https://accounts.google.com/gsi/client" onload="gisLoaded()"></script>
-->
    </body>
</html>