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

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

if(!isset($_REQUEST['project']) or $_REQUEST['project']=='all')
{
$q = "select * from client order by name";
$p = 'All';
}
else
{
$q =  "select * from client where project='".$_REQUEST['project']."' order by name";
$q2 = "select project_name from project where id='".$_REQUEST['project']."'";
$res2 = mysqli_query($dbcon,$q2) or die(mysqli_error($dbcon));
if(mysqli_num_rows($res2)<1)
{
echo 'No projects found with this id';
exit;
}
$row2 = mysqli_fetch_array($res2);
$project = $row2['project_name'];
$p = $row2['project_name'];
}


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

$disp .= '

<div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            '.UCFirst($p).' - Clients 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> Name</th>
                                            <th>Phone</th>
											<th>Address</th>
											<th>Project</th>
											<th>Purchase Details</th>
                                            <th>Flats Purchased </th>
                                            <th>Total Cost</th>
                                            <th>Bank Details</th>
											<th>Operation</th>
                                        </tr>
                                    </thead>
                                    <tbody>';

while($row = mysqli_fetch_array($res))
{
if($p=='All')
{
$q2 = "select project_name from project where id='".$row['project']."'";
$res2 = mysqli_query($dbcon,$q2) or die(mysqli_error($dbcon));
$row2 = mysqli_fetch_array($res2);
$project = $row2['project_name'];
}

$disp .= '<tr class="odd gradeX" >';
$disp .= '<td>'.$row['name'].'</td><td>'.$row['phone'].'</td><td>'.$row['address'].'</td>
<td>'.$project.'</td><td>'.$row['purchase_details'].'</td><td>'.$row['flat_no'].'</td><td>'.$row['total_cost'].'</td><td>'.$row['bank_details'].'</td><td><a href="editclient.php?id='.$row['id'].'"><img src="../assets/img/edit.png"></a> &nbsp; <a onclick="return confirm(\'Are you sure you want to delete this client info? \')" href="deleteclient.php?id='.$row['id'].'"><img src="../assets/img/delete.png"></a>&nbsp;&nbsp;</td>
</tr>';
}

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

echo $disp;
			
//include('../header.php');
//include('../template.php');

?>

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