<?php include('../config/setup.php');?>
<?php 

if($_SERVER['REQUEST_METHOD'] == 'POST'){
    
    $action = $_POST['action'];

// contact_master
    // contact_master update query starts
    if($action == 'c_edit'){
        $c_location = $_POST['c_location'];
        $c_address = $_POST['c_address'];
        $c_mobile = $_POST['c_mobile'];
        $c_telephone = $_POST['c_telephone'];
        $c_email_id = $_POST['c_email_id'];
        $c_map = $_POST['c_map'];
        $c_status = $_POST['c_status'];
        
        $sql = "UPDATE contact_master SET c_location = '$c_location' ,c_address = '$c_address' , c_mobile = '$c_mobile' , c_telephone = '$c_telephone' , c_email_id = '$c_email_id' , c_map = '$c_map' , c_status = '$c_status' " ;
        if($config->query($sql) === TRUE){
            $_SESSION['status'] = "Updated successfully" ;
            $_SESSION['alert'] = "success" ;
        }else{
            $_SESSION['status'] = "Update Failed" ;
            $_SESSION['alert'] = "success" ;
        }
    }
    // contact_master update query ends

}


?>
<?php include "head.php" ?>
	<div class="wrapper">
		<div class="main-header">
			<!-- Logo Header -->
			<?php include('logo.php');?>
			<!-- End Logo Header -->

			<!-- Navbar Header -->
			<?php include('topbar.php');?>
			 <!-- End Navbar -->
		</div>
		<!-- Sidebar -->
		<?php include('sidebar.php');?>
		
		
		<div class="main-panel">
			<div class="content">
				<div class="page-inner">
					<div class="page-header">
						<h4 class="page-title">App Contact & Address Master </h4>
						 
					</div>
					<div class="row">
						<div class="col-md-12">
							<div class="card">
								
								<div class="card-body">
								 
									<div class="table-responsive">
										<table id="basic-datatables" class="display table table-striped table-hover" >
											<thead>
												<tr>
													<th>S.No</th>
													<th>Location</th>
													<th>Address</th>
													<th>Mobile No</th>
													<th>Telphone No</th>
													<th>Mail Id</th>
													<th>Status</th>
													<th>Action</th>
												</tr>
											</thead>
											 
											<tbody>
											    <?php 
												    $sno = 1;
													$sql = "SELECT * FROM contact_master ";
													$res = $config->query($sql);
													$row = $res->fetch_assoc();
													$status = $row['c_status'];
												?>
												<tr>
													<td><?= $sno; ?></td>
													<td><?= $row['c_location'] ?></td>
													<td><?= $row['c_address'] ?></td>
													<td><?= $row['c_mobile'] ?></td>
													<td><?= $row['c_telephone'] ?></td>
													<td><?= $row['c_email_id'] ?></td>
													<td>
													    <?php if($status == 1){ ?>
													    <button class="btn btn-success">Active</button>
													    <?php }else{ ?>
													        <button class="btn btn-danger">In-Active</button>
													    <?php } ?>
                                                    </td>
													<td>
													    <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#contact"> <i class="fas fa-pencil-alt"></i>  </a>
                                                    </td><!-- Modal -->
                                                    <div class="modal fade" id="contact" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                        <div class="modal-dialog" role="document">
                                                            <div class="modal-content">
                                                                <div class="modal-header">
                                                                    <h5 class="modal-title" id="exampleModalLabel">Contact Edit</h5>
                                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                        <span aria-hidden="true">&times;</span>
                                                                    </button>
                                                                </div>
                                                                <div class="modal-body">
                                                            	    <form method="post">
                                                                        <div class="form-group">
                                                            			    <label for="c_location">Location</label>
                                                            			    <input type="text" class="form-control" id="c_location" name="c_location"  value="<?= $row['c_location'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="c_address">Address</label>
                                                            			    <input type="text" class="form-control" id="c_address" name="c_address"  value="<?= $row['c_address'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="c_mobile">Mobile</label>
                                                            			    <input type="text" class="form-control" id="c_mobile" name="c_mobile"  value="<?= $row['c_mobile'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="c_telephone">Telephone</label>
                                                            			    <input type="text" class="form-control" id="c_telephone" name="c_telephone"  value="<?= $row['c_telephone'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="c_email_id">Email Id</label>
                                                            			    <input type="email" class="form-control" id="c_email_id" name="c_email_id"  value="<?= $row['c_email_id'] ?>">
                                                            			</div>
                                                                        <div class="form-group">
                                                            			    <label for="c_map">Map</label>
                                                            			    <textarea type="text" class="form-control" id="c_map" name="c_map" rows="3"><?= $row['c_map'] ?></textarea>
                                                            			</div>
                                                                        <div class="form-group">
                        												    <label for="c_status">Status</label>
                        												    <select class="form-control" id="c_status" name="c_status">
                        												    <?php if($status == 1){ ?>
                            													<option value="1" >Active</option>
                            													<option value="0">In-Active</option>
                        													<?php }else{?>
                            													<option value="0" >In-Active</option>
                            													<option value="1" >Active</option>
                        													<?php } ?>
                            												</select>
                            											</div>	
                                                                        <div class="form-group">
                                        									<input type="hidden" name="action" value="c_edit">
                                        									<button class="btn btn-warning" type="submit" name="submit">Submit</button>
                                         								</div>
                                                        		    </form>	
                                                                </div>
                                                                <div class="modal-footer">
                                                                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </tr>
											</tbody>
										</table>
									</div>
								</div>
							</div>
						</div>
	                </div>
				</div>
			</div>
		<?php include('footer.php');?>	
		 
		</div>
		<!-- End Custom template -->
	</div>
	<script>
	<?php if(isset($_SESSION['status']) && !empty($_SESSION['status'])){ ?>
	    swal({
          title: "<?= $_SESSION['status'] ?>",
          text: "",
          icon: "<?= $_SESSION['alert'] ?>",
        });
    <?php unset($_SESSION['status']); } ?>
	</script>
	<!--   Core JS Files   -->
	<script src="../assets/js/core/jquery.3.2.1.min.js"></script>
	<script src="../assets/js/core/popper.min.js"></script>
	<script src="../assets/js/core/bootstrap.min.js"></script>
	<!-- jQuery UI -->
	<script src="../assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
	<script src="../assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>
	
	<!-- jQuery Scrollbar -->
	<script src="../assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
	<!-- Datatables -->
	<script src="../assets/js/plugin/datatables/datatables.min.js"></script>
	<!-- Atlantis JS -->
	<script src="../assets/js/atlantis.min.js"></script>
	<!-- Atlantis DEMO methods, don't include it in your project! -->
	<script src="../assets/js/setting-demo2.js"></script>
	<script >
		$(document).ready(function() {
			$('#basic-datatables').DataTable({
			});

		 
 
			 
		});
	</script>
</body>
</html>