<?php
include('../headertop.php');
include('../db.php');
//include('../datepicker.php');

$disp = '';
$pagetitle = 'View/Search Projects';

date_default_timezone_set('Asia/Kolkata');

$disp .= '<div class="row"><div class="col-md-8"><h3>Select Type of Projects</h3><br><form method="post" action="'.$_SERVER['PHP_SELF'].'">
<select name="type"><option value="all">All Projects</option>
<option value="ct">Construction Projects</option>
<option value="mt">Maintenance Projects</option></select>
<button type="submit" class="btn-primary">Submit</button>
</form>
</div></div>';

if(!isset($_REQUEST['type']) or $_REQUEST['type']=='all')
{
$q = "select * from project order by start_date desc";
$pt = 'All';
}
elseif($_REQUEST['type']=='mt')
{
$q =  "select * from project  where type='mt' order by start_date desc";
$pt = 'Maintenance';
}
elseif($_REQUEST['type']=='ct')
{
$q =  "select * from project where type='ct' order by start_date desc";
$pt = 'Construction';
}


$res = mysqli_query($dbcon,$q) or die(mysqli_error($dbcon));
if(mysqli_num_rows($res)<1)
{
$disp .= 'No projects found';
include('../template.php');
exit;
}

$disp .= '

<div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            '.$pt.' Projects List: <br>
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
											<th>Project Name</th>
                                            <th>Photo</th>
											<th>Address</th>
											<th>Start Date</th>
                                            <th>Details </th>
                                            <th>Floors/Flats</th>
                                            <th>Operation</th>
                                        </tr>
                                    </thead>
                                    <tbody>';

while($row = mysqli_fetch_array($res))
{
if($row['type'] == 'mt')
{
$typedisp = 'Maintenance';
$disp .= '<tr class="odd gradeX" style="background-color:pink">';
}
elseif($row['type'] =='ct')
{
$typedisp = 'Construction';
$disp .= '<tr class="odd gradeX">';
}

$datedisp = date("d-m-Y", strtotime($row['start_date']));

$disp .= '<td>'.$row['project_name'].'<br>(<b>'.$typedisp.' Project</b>)</td><td><a href="'.$row['photo'].'" target=_blank><img src="'.$row['photo'].'" style="height:80px;width:80px"></a></td><td>'.$row['project_address'].'</td>
<td>'.$datedisp.'</td><td>'.$row['project_details'].'</td><td><b>Floors:</b> '.$row['no_floors'].'<br><b>Flats:</b> '.$row['no_flats'].'</td><td><a href="editproject.php?id='.$row['id'].'"><img src="../assets/img/edit.png"></a> &nbsp; <a onclick="return confirm(\'Want to delete project & its expenses/estimates data? \')" href="deleteproject.php?id='.$row['id'].'&type='.$row['type'].'"><img src="../assets/img/delete.png"></a>&nbsp;&nbsp;</td>
</tr>';
}

$disp .='            </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>';
			

			
include('../header.php');
include('../template.php');

?>

<script>
            $(document).ready(function () {
                $('#dataTables-example').dataTable();
            });
    </script>
    
     