<?php 
date_default_timezone_set("Asia/Dhaka");
$page_name="user_register";  

include ('../common/library.php');
include ('../common/helper.php');
include ('../template/header.php'); 
include ('../template/sidebar.php');



if(isset($_POST['save'])){
  $device_details = $_POST['device_details'];
  $contact_no = $_POST['contact_no'];
  $cust_name =  $_POST['cust_name'];
  $address = $_POST['address'];
  $issues_for = $_POST['issues_for'];
  $entry_by = $_SESSION['user_id'];
  $date=date("Y-m-d");


   $insert ="insert into user_register_phone (device_details,contact_no,`cust_name`,`address`,`issues_for`,`entry_by`,`date` ) 
   Values('".$device_details."','".$contact_no."','".$cust_name."','".$address."','".$issues_for."','".$entry_by."', '".$date."')";
  $ins = $conn->query($insert);


}





if(isset($_POST['update'])){

    $update_id = $_POST['update_id'];
	$device_details = $_POST['device_details'];
  $contact_no = $_POST['contact_no'];
  $cust_name =  $_POST['cust_name'];
  $address = $_POST['address'];
  $issues_for = $_POST['issues_for'];
  $entry_by = $_SESSION['user_id'];

  

  

  if($update_id>0){

  $update = "update user_register_phone set device_details='".$device_details."', contact_no='".$contact_no."', cust_name='".$cust_name."',issues_for='".$issues_for."',address='".$address."'  where id='".$update_id."'";


$conn->query($update);

}


}



?>


		<div class="main-panel">

			<div class="content">

                     <div class="row">

						<div class="col-md-12">

							<div class="card">

								<div class="card-header">

									<div class="d-flex align-items-center">

										<h4 class="card-title"><?=$mgs;?></h4>

										<button class="btn btn-dark btn-round ml-auto" data-toggle="modal" data-target="#addRowModal">

											<i class="fa fa-plus"></i>

											Add New

										</button>

									</div>

								</div>

								<div class="card-body">

									<!-- Modal -->

									<form action="<?=$_POST['PHP_SELF']?>" method="post" enctype="multipart/form-data">

									<div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">

										<div class="modal-dialog" role="document">

											<div class="modal-content">

												<div class="modal-header no-bd">

													<h5 class="modal-title">
														<span class="fw-mediumbold">User</span> 
														<span class="fw-light">Information</span>
													</h5>

													<button type="button" class="close" data-dismiss="modal" aria-label="Close">
														<span aria-hidden="true">&times;</span>
													</button>

												</div>

												<div class="modal-body">

															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Device Details <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="device_details"  id="device_details"  class="form-control" placeholder="Device Details" required>
																</div>
															</div>


															<div class="row">

															<div class="col-sm-6">
																<div class="form-group form-group-default">
																	<label>Contact No <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="contact_no"  id="contact_no"  class="form-control" placeholder="Contact Info">
																</div>
															</div>

															<div class="col-sm-6">
																<div class="form-group form-group-default">
																	<label>User Name <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="cust_name"  id="cust_name"  class="form-control" placeholder="User Name">
																</div>
															</div>

														</div>

															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Address<span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="address"  id="address"  class="form-control" placeholder="Address">
																</div>
															</div>


															<div class="col-sm-12">
																<div class="form-group form-group-default">
																	<label>Date<span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="date" name="date"  id="date"  class="form-control" value="<?php if($data['date'] !='') echo $data['date']; else echo date('Y-m-d');?>">
																</div>
															</div>

												</div>

												<div class="modal-footer no-bd">

													<!--<button type="button" id="addRowButton" class="btn btn-primary">Add</button>-->

													<input type="submit" name="save"  value="Add" class="btn btn-primary" />

													<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>

												</div>

											</div>

										</div>

									</div>

								  </form>



									<div class="table-responsive">

										<table id="add-row" class="display table table-striped table-hover basic-datatables" >

											<thead>

												<tr>
													<th>ID</th>
													<th>Device Details</th>
													<th>Contact Info</th>
													<th>User Name</th>
													<th>Address</th>
													<th>Contact Date</th>
													<th style="width: 10%">Action</th>
												</tr>

											</thead>

											<tfoot>

											      <tr>

													<th></th>

													<th></th>

													<th></th>

													<th></th>

													<th></th>

													<th></th>

													<th></th>

												</tr>

											</tfoot>

											<tbody>

											<?php

											  $select =$conn->query("select * from user_register_phone where 1 ");

											 while($c_data = $select->fetch_assoc()){ ?>



												<tr>
												    <td><?=$c_data['id']?></td>
													<td><?=$c_data['device_details']?></td>
													<td><?=$c_data['contact_no']?></td>
													<td><?=$c_data['cust_name']?></td>
													<td><?=$c_data['address']?></td>
													<td><?=$c_data['date']?></td>
													

													<td>

														<div class="form-button-action">

															<button type="button"  data-toggle="modal" data-target="#editRowModal<?=$c_data['id']?>" title="" class="btn btn-link btn-primary btn-lg" data-original-title="Edit Task">

																<i class="fa fa-edit"></i>

															</button>

															

												

								 <form action="<?=$_POST['PHP_SELF']?>" method="post" enctype="multipart/form-data">			<!--- edit modal -->

									<div class="modal fade" id="editRowModal<?=$c_data['id']?>" tabindex="-1" role="dialog" aria-hidden="true">

										<div class="modal-dialog" role="document">

											<div class="modal-content">

												<div class="modal-header no-bd">

													<h5 class="modal-title">

														<span class="fw-mediumbold">

														User </span> 

														<span class="fw-light">

															Information

														</span>

													</h5>

													<button type="button" class="close" data-dismiss="modal" aria-label="Close">

														<span aria-hidden="true">&times;</span>

													</button>

												</div>

												<div class="modal-body">



														<div class="row">
														
														
														<div class="col-sm-6">

																<div class="form-group form-group-default" style="display:none">

																	<label> ID <span style="color:#FF0000; font-size:15px;">*</span></label>

																	<input type="hidden" name="update_id"  id="update_id"  class="form-control" value="<?=$c_data['id']?>" readonly="readonly" required>

																</div>

															</div>


															<div class="col-sm-12">

																<div class="form-group form-group-default">

																	<label> Device Details <span style="color:#FF0000; font-size:15px;">*</span></label>

																	<input type="text" name="device_details"  id="device_details"  class="form-control" value="<?=$c_data['device_details']?>" required>

																</div>

															</div>

															
															<div class="col-md-6">
																<div class="form-group form-group-default">
																	<label>Contact No</label>
																	<input name="contact_no" id="contact_no" class="form-control" value="<?=$c_data['contact_no'];?>" />
																</div>
															</div>

															<div class="col-md-6">
																<div class="form-group form-group-default">
																	<label>User Name (Customer)</label>
																	<input name="cust_name" id="cust_name" class="form-control" value="<?=$c_data['cust_name'];?>" />
																</div>
															</div>

															<div class="col-sm-6">
																<div class="form-group form-group-default">
																	<label> Address <span style="color:#FF0000; font-size:15px;">*</span></label>
																	<input type="text" name="address"  id="address"  class="form-control" value="<?=$c_data['address']?>">
																</div>
															</div>

															
														

															<div class="col-md-12">
																<div class="form-group form-group-default">
																	<!-- generate barcode -->
																	
																</div>
															</div>

														</div>

													

												</div>

												<div class="modal-footer no-bd">

													<!--<button type="button" id="addRowButton" class="btn btn-primary">Add</button>-->

													<input type="submit" name="update"  value="Update" class="btn btn-primary" />

													<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>

												</div>

											</div>

										</div>

									</div>

								</form>
															<!--edit modal end-->

															<button type="button" data-toggle="tooltip" title="" class="btn btn-link btn-danger" data-original-title="Remove">

																<i class="fa fa-times"></i>

															</button>

														</div>

													</td>

												</tr>

												<?php } ?>
							
											</tbody>

										</table>

									</div>

								</div>

							</div>

						</div>

					</div>
			</div>
<?php include('../template/footer.php');?>