<?php include("cn.php");?>
<?php $title = "CARS Details";
$id = $_REQUEST["id"];
$sql = mysqli_query($connect, "select cars.*, brands.Title as brand_name from cars
inner join brands on brands.Id = cars.Brand
where cars.Id = '$id'");
$data = mysqli_fetch_assoc($sql);
?>
<!DOCTYPE html>
<html lang="en">
<?php include("head-tag.php");?>
<body>

<div class="inner-wrapper">
<?php include("pre-loader.php");?>

<?php include("header.php");?>
<div class="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-xl-3 col-lg-4 col-md-12 theiaStickySidebar">
<aside class="sidebar sidebar-user">
<div class="card ctm-border-radius shadow-sm">
<div class="card-body py-4">
<div class="row">
<div class="col-md-12 mr-auto text-left">
<div class="custom-search input-group">
<div class="custom-breadcrumb">
<ol class="breadcrumb no-bg-color d-inline-block p-0 m-0 mb-2">
<li class="breadcrumb-item d-inline-block"><a href="index.php" class="text-dark">Home</a></li>
<li class="breadcrumb-item d-inline-block active">Car Details</li>
</ol>
<h4 class="text-dark">Car Details</h4>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="user-card card shadow-sm bg-white text-center ctm-border-radius">
<div class="user-info card-body">
<div class="user-avatar mb-4">
<img src="<?php echo $data["Image"];?>" alt="User Avatar" class="img-fluid " width="100%">
</div>
<div class="user-details">
<h4><b><?php echo $data["Title"];?></b></h4>
<p class="card-text"><span class="text-primary"><?php echo $data["brand_name"];?></span></p>
<p class="card-text">Model: <span class="text-primary"><?php echo $data["Model"];?></span></p>
<p class="card-text">Daily Rate: <span class="text-primary"><?php echo $data["Rate"];?> AED</span></p>
</div>
</div>
</div>

</aside>
</div>
<div class="col-xl-9 col-lg-8  col-md-12">
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12 d-flex">
<div class="card flex-fill  ctm-border-radius shadow-sm">
<div class="card-header">
<h4 class="card-title mb-0">Route-wise Rate
<a href="javascript:void(0)" class="btn btn-theme ctm-border-radius text-white btn-sm float-right" data-toggle="modal" data-target="#add-rate"><i class="fa fa-plus" aria-hidden="true"></i> Add Rate</a>
</h4>
</div>
<div class="card-body">
 <div class="table-responsive">
                            <table id="cars" class="table table-striped table-bordered ">
						<thead>
						<tr>
						  <th class="text-center">Sr#</th>
						  <th class="text-center">Pickup</th>
						  <th class="text-center">Destination</th>
						  <th class="text-center">Rate</th>
                          <th class="text-center">Action</th>
						</tr>
						</thead>
						<tbody>
										<?php
										$sql1 = mysqli_query($connect, "select routes.*
										from routes where Car = '$id'");
                                           $i = 1;
										while($data1 = mysqli_fetch_assoc($sql1)){?>
											<tr>
											<td class="text-center"> <?php
                                            echo $i;?> </td>
                                            
                                            <td class="text-center"> <?php
                                            $sql_city = mysqli_query($connect, "select * from emirates where Id = '".$data1['PickUp']."'");
                                            $data_city = mysqli_fetch_assoc($sql_city);
                                            echo $data_city["Title"]?> </td>
                                            <td class="text-center"> <?php
                                            $sql_city = mysqli_query($connect, "select * from emirates where Id = '".$data1['Destination']."'");
                                            $data_city = mysqli_fetch_assoc($sql_city);
                                            echo $data_city["Title"]?> </td>
                                            <td class="text-center"> <?php echo $data1["Rate"]." "?> AED</td>
                                            
                                            <td class="text-center">
                                            <a href="javascript:void(0)" class="btn btn-theme button-1 ctm-border-radius text-white btn-sm float-center" data-toggle="modal" data-target="#edit-rate<?php echo $data1['Id']?>"><i class="fa fa-pencil" aria-hidden="true"></i></a>
                                            <div class="modal fade" id="edit-rate<?php echo $data1['Id']?>">
                                                <div class="modal-dialog modal-dialog-centered">
                                                    <div class="modal-content">
                                                        <div class="modal-body float-left text-left">
                                                            <form method = "post" action="ajax/edit-rate.php" enctype='multipart/form-data'>
                                            				<input type="hidden" name="id" value="<?php echo $data1['Id']?>">
                                            				<input type="hidden" name="car" value="<?php echo $data1['Car']?>">
                                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                                            <h4 class="modal-title mb-3">Edit Rate</h4>
                                                            <div class="row">
                                                                <div class="col-md-12 col-sm-12 col-xs-12">
                       
                        <div class="form-group">
                            <select class="form-control select" name="pickup">
                                <option value="">-- Select Pickup --</option>
                                <?php $sql = mysqli_query($connect, "select emirates.* 
								from emirates");
								while($data_m = mysqli_fetch_assoc($sql)){?>
									<option value="<?php echo $data_m["Id"]?>"
									<?php echo ($data1['PickUp']==$data_m["Id"])?"selected":"";?>
									><?php echo $data_m['Title'];?></option>
								<?php }?>
                            </select>
                        </div>
                        <div class="form-group">
                            <select class="form-control select" name="destination">
                                <option value="">-- Select Destination --</option>
                                <?php $sql = mysqli_query($connect, "select emirates.* 
								from emirates");
								while($data_m = mysqli_fetch_assoc($sql)){?>
										<option value="<?php echo $data_m["Id"]?>"
									<?php echo ($data1['Destination']==$data_m["Id"])?"selected":"";?>
									><?php echo $data_m['Title'];?></option>
								<?php }?>
                            </select>
                        </div>
                        <div class="form-group">
                            <input class="form-control" name="rate" type="text" placeholder="Rate" value="<?php echo $data1['Rate'];?>" />
                        </div>
                    </div>
                                                            </div>
                                                            <button type="button" class="btn btn-danger float-right ml-3 ctm-border-radius" data-dismiss="modal">Cancel</button>
                                                            <button type="submit" class="btn btn-theme  button-1 text-white ctm-border-radius float-right">Save</button>
                                                            </form>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            </td>
                                        </tr>
										<?php $i++;}?>
										
                                    </tbody>
						</table>
                        </div>
        </div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</div>

<div class="sidebar-overlay" id="sidebar_overlay"></div>
<div class="modal fade" id="add-rate">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-body">
                <form method = "post" action="ajax/add-rate.php" enctype='multipart/form-data'>
                    <input type="hidden" name="id" value="<?php echo $id?>">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title mb-3">Add Rates</h4>
                <div class="row">
                    
                    <div class="col-md-12 col-sm-12 col-xs-12">
                       
                        <div class="form-group">
                            <select class="form-control select" name="pickup">
                                <option value="">-- Select Pickup --</option>
                                <?php $sql = mysqli_query($connect, "select emirates.* 
								from emirates");
								while($data_m = mysqli_fetch_assoc($sql)){?>
									<option value="<?php echo $data_m["Id"]?>"><?php echo $data_m['Title'];?></option>
								<?php }?>
                            </select>
                        </div>
                        <div class="form-group">
                            <select class="form-control select" name="destination">
                                <option value="">-- Select Destination --</option>
                                <?php $sql = mysqli_query($connect, "select emirates.* 
								from emirates");
								while($data_m = mysqli_fetch_assoc($sql)){?>
									<option value="<?php echo $data_m["Id"]?>"><?php echo $data_m['Title'];?></option>
								<?php }?>
                            </select>
                        </div>
                        <div class="form-group">
                            <input class="form-control" name="rate" type="text" placeholder="Rate" value="" />
                        </div>
                    </div>
                    
                </div>
                <button type="button" class="btn btn-danger float-right ml-3 ctm-border-radius" data-dismiss="modal">Cancel</button>
                <button type="submit" class="btn btn-theme  button-1 text-white ctm-border-radius float-right">Save</button>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include("scripts.php");?>
</body>

</html>