<?php  

include(dirname(__FILE__).'/header.php');
include(dirname(__FILE__).'/user_session_check.php');
	include (dirname(dirname(__FILE__)).'/objects/class_users.php');
	include (dirname(dirname(__FILE__)).'/objects/class_services.php');
	include (dirname(dirname(__FILE__)).'/objects/class_services_addon.php');
	include (dirname(dirname(__FILE__)).'/objects/class_services_methods.php');
	include (dirname(dirname(__FILE__)).'/objects/class_booking.php');
	
	$con = new cleanto_db();
	$conn = $con->connect();
	$users = new cleanto_users();
	$users->conn = $conn;
	$objservice = new cleanto_services();
	$objservice->conn = $conn;
	$serviceaddon = new cleanto_services_addon();
	$serviceaddon->conn = $conn;
	$servicemethod = new cleanto_services_methods();
	$servicemethod->conn = $conn;
	$booking = new cleanto_booking();
	$booking->conn = $conn;
?>
<div id="cta-export-details" class="panel tab-content">
	<div class="panel panel-default">
		<div class="panel-heading">
			<h1 class="panel-title"><?php echo $label_language_values['export_your_details'];?></h1>
		</div>
		<div class="panel-body">
			<ul class="nav nav-tabs">
				<li class="active"><a data-toggle="tab" href="#booking-info-export"><?php echo $label_language_values['booking_information'];?></a></li>
				<li><a data-toggle="tab" href="#staff-info-export"><?php echo $label_language_values['customer_information'];?></a></li>
				<li><a data-toggle="tab" href="#services-info-export"><?php echo $label_language_values['services_information'];?></a></li>
				
			</ul>
			
			<div class="tab-content">
				<!-- booking infomation export -->
				<div id="booking-info-export" class="tab-pane fade in active">
					<h3><?php echo $label_language_values['booking_information'];?></h3>
					<div id="accordion" class="panel-group">
						
						<form id="" name="" class="" method="post">
							
				
							<hr id="hr" />
							<div class="table-responsive">
								<table id="booking-info-table" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
									<thead>
										<tr>	
											<th>#</th>
											<th><?php echo $label_language_values['service'];?></th>
											<th><?php echo $label_language_values['order_date'];?></th>
											<th><?php echo $label_language_values['app_date'];?></th>
											<th><?php echo $label_language_values['customer'];?></th>
											<th><?php echo $label_language_values['phone'];?></th>
											<th><?php echo "address";?></th>
											<th><?php echo $label_language_values['status'];?></th>
											<th><?php echo $label_language_values['more'];?></th>
										</tr>
									</thead>
									<tbody>
									<?php 
									$display_booking = $booking->get_all_bookingss();
									
									$i = 1;
									while($row2=mysqli_fetch_array($display_booking)){
										$objservice->id=$row2['service_id'];
										$display_ser=$objservice->readone();
										
										$users->id=$row2['client_id'];
										$display_det_client=$users->get_client_info($row2['order_id']);
										
										if($row2['booking_status']=='A'){
											$booking_stats=$label_language_values['active'];
										}elseif($row2['booking_status']=='C'){
											$booking_stats=$label_language_values['confirm'];
										}elseif($row2['booking_status']=='R'){
											$booking_stats=$label_language_values['reject'];
										}elseif($row2['booking_status']=='RS'){
											$booking_stats=$label_language_values["rescheduled"];
										}elseif($row2['booking_status']=='CC'){
											$booking_stats=$label_language_values['cancel_by_client'];
										}elseif($row2['booking_status']=='CS'){
											$booking_stats=$label_language_values['cancelled_by_service_provider'];
										}elseif($row2['booking_status']=='CO'){
											$booking_stats=$label_language_values['completed'];
										}else{
											$row2['booking_status']=='MN';
											$booking_stats=$label_language_values['mark_as_no_show'];
										}
									?>
										<tr>	
											<td><?php echo $i;?></td>
											<!-- <td><?php echo $display_ser[1]; ?></td> -->
											<td><?php
					            	$s_name = [];
					            	$services = $booking->get_booking_service_name($row2['order_id']);
					            	while($service = mysqli_fetch_array($services)){
					            		$s_name[] = $service['sname'];
					            	}
					            	echo implode(', ', $s_name);
					            ?></td>
											<td><?php echo str_replace($english_date_array,$selected_lang_label,date($getdateformat,strtotime($row2['order_date']))); ?></td>
											<td><?php echo str_replace($english_date_array,$selected_lang_label,date($getdateformat,strtotime($row2['booking_date_time']))); ?></td>
											<td>
											<?php 
											$ccnames = explode(" ",$display_det_client[2]);
											$cnamess = array_filter($ccnames);
											$client_name = array_values($cnamess);
											if(sizeof((array)$client_name)>0){
												if($client_name[0]!=""){ 	
													$client_first_name =  $client_name[0];
												}else{
													$client_first_name = "";
													if(!isset($client_name[1]) || $client_name[1]==""){ 	
														$client_first_name =  'N/A'; 
													}
												} 
												
												if(isset($client_name[1]) && $client_name[1]!=""){ 	
													$client_last_name =  $client_name[1]; 
												}else{
													$client_last_name = "";
												} 
											}else{
												$client_first_name = "N/A";
												$client_last_name = "";
											}
											$client_name = $client_first_name.' '.$client_last_name;
											echo $client_name;
											?>
											</td>
											<td><?php $fetch_phone =  strlen($display_det_client[4]); if($fetch_phone >= 6){ echo $display_det_client[4]; }else{ echo 'N/A'; } ?></td>
											<td>
											<?php  
											$array_decode = $display_det_client[5];
											$arr_address_dec=base64_decode($array_decode);
											$tt=unserialize($arr_address_dec);
											echo $tt['address'];
											?>
											</td>
											<td><?php echo $booking_stats;?></td>
											<td class="ct-bookings-td">
												<a class="btn btn-success booking_addons" id="<?php echo $row2['order_id'];?>" href="#booking-addOns" data-toggle="modal"><?php echo $label_language_values['addons_bookings'];?> <span class="badge"></span></a>
												<a class="btn btn-danger booking_methods" id="<?php echo $row2['order_id'];?>" href="#booking-methods" data-toggle="modal"><?php echo $label_language_values['methods_bookings'];?><span class="badge"></span></a> </td>
										</tr>
									<?php 
									$i++;}
									?>
									</tbody>
								</table>
								<div id="booking-addOns" class="modal fade booking-details-modal">
								<div class="modal-dialog modal-lg">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title"><?php echo $label_language_values['addons_bookings'];?></h4>
										</div>
										<div class="modal-body">
										<div class="table-responsive">
											<table id="table-booking-addons" class="display table table-striped table-bordered" cellspacing="0" width="100%">
												<thead>
													<tr>
														<th>#</th>
														<th style="width: 48px !important;"><?php echo $label_language_values['serviceaddons_name'];?></th>
														<th style="width: 73px !important;"><?php echo $label_language_values['service_rate'];?></th>
														<th style="width: 39px !important;"><?php echo $label_language_values['service_quantity'];?></th>
													</tr>
												</thead>
												<tbody id="display_booking_addons">
												</tbody>
											</table>
										</div>
										
										</div>
									</div>
								</div>
							</div>
							<div id="booking-methods" class="modal fade booking-details-modal">
								<div class="modal-dialog modal-lg">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title"><?php echo $label_language_values['methods_booking'];?></h4>
										</div>
										<div class="modal-body">
										<div class="table-responsive">
											<table id="table-booking-method" class="display table table-striped table-bordered" cellspacing="0" width="100%">
													<thead>
														<tr>
															<tr>
															<th>#</th>
															<th style="width: 48px !important;"><?php echo $label_language_values['method_title'];?></th>
															<th style="width: 73px !important;"><?php echo $label_language_values['method_unit_title'];?></th>
															<th style="width: 48px !important;"><?php echo $label_language_values['method_unit_quantity'];?></th>
															<th style="width: 48px !important;"><?php echo $label_language_values['method_unit_quantity_rate'];?></th>
														</tr>
														</tr>
													</thead>
													<tbody id="display_booking_method">
													</tbody>
											</table>
										</div>
										
										</div>
									</div>
								</div>
							</div>
							</div>	
						</form>	
					</div>
				</div>
				<!-- service provicer information export -->
				<div id="staff-info-export" class="tab-pane fade">
					<h3><?php echo $label_language_values['customer_information'];?></h3>
					<div id="accordion" class="panel-group">
						<form id="" name="" class="" method="post">
							<hr id="hr" />
							<div class="table-responsive">
								<table id="staff-info-table" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
									<thead>
										<tr>	
											<th>#</th>
											<th><?php echo $label_language_values['name'];?></th>
											<th><?php echo $label_language_values['email'];?></th>
											<th><?php echo $label_language_values['phone'];?></th>
											<th><?php echo $label_language_values['city'];?></th>
											<th><?php echo $label_language_values['state'];?></th>
											<th><?php echo $label_language_values['notes'];?></th>
										</tr>
									</thead>
									<tbody>
										<?php 
										$cus_display = $users->display_customer();
										$i = 1;
										if(!empty($cus_display)){ 
										while($row=mysqli_fetch_array($cus_display)){
										?>
										<tr>
											<td><?php echo $i;?></td>
											<td>
												<?php 
												$client_first_name = $row['first_name'];
												$client_last_name = $row['last_name'];
												if($client_first_name=="" && $client_last_name==""){
													$client_fname = "N/A";
													$client_lname = "";
												}elseif($client_first_name!="" && $client_last_name!=""){
													$client_fname = $client_first_name;
													$client_lname = $client_last_name;
												}elseif($client_first_name!=""){
													$client_fname = $client_first_name;
													$client_lname = "";
												}elseif($client_last_name!=""){
													$client_fname = "";
													$client_lname = $client_last_name;
												}
												$client_name = $client_fname.' '.$client_lname;
												echo $client_name;
												?>
											</td>
											<td><?php echo $row['user_email'];?></td>
											<td><?php $fetch_phone =  strlen($row['phone']); if($fetch_phone >= 6){ echo $row['phone']; }else{ echo 'N/A'; } ?></td>
											<td><?php if($row['city']==""){ echo "N/A"; }else{ echo $row['city']; } ?></td>
											<td><?php if($row['state']==""){ echo "N/A"; }else{ echo $row['state']; } ?></td>
											<td><?php if($row['notes']==""){ echo "N/A"; }else{ echo $row['notes']; } ?></td>
										</tr>
										<?php 
										$i++;}}
										?>
									</tbody>
								</table>
							</div>	
						</form>	
					</div>
				</div>
				<!-- services  infomation export -->
				<div id="services-info-export" class="tab-pane fade">
					<h3><?php echo $label_language_values['services_information'];?></h3>
					<div id="accordion" class="panel-group">
						<form id="" name="" class="" method="post">
							<hr id="hr" />
							<div class="table-responsive">
								<table id="services-info-table" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
									<thead>
										<tr>	
											<th>#</th>
											<th><?php echo $label_language_values['service_title'];?></th>
											<th><?php echo $label_language_values['description'];?></th>
											<th><?php echo $label_language_values['more'];?></th>
										</tr>
									</thead>
									<tbody>
										<?php 
										$ser_display = $objservice->getalldata();
										$i = 1;
										while($row1=mysqli_fetch_array($ser_display)){
											$serviceaddon->service_id=$row1['id'];
											$count_ser_addons=$serviceaddon->count_addon_serviceid();
											
											$servicemethod->service_id=$row1['id'];
											$count_ser_methods=$servicemethod->count_ser_method();
										?>
										<tr>	
											<td><?php echo $i;?></td>
											<td><?php echo $row1['title'];?></td>
											<td><?php echo $row1['description'];?></td>
											<td class="ct-bookings-td">
												<a class="btn btn-success service_addons" id="<?php echo $row1['id'];?>" href="#service-addOns" data-toggle="modal"><?php echo $label_language_values['addons'];?><span class="badge br-10"><?php echo $count_ser_addons[0];?></span></a>
												<a class="btn btn-danger service_methods ml-10" id="<?php echo $row1['id'];?>" href="#service-methods" data-toggle="modal"><?php echo $label_language_values['methods'];?><span class="badge br-10"><?php echo $count_ser_methods[0];?></span></a> </td>
										</tr>
										<?php 
										$i++;}
										?>	
									</tbody>
								</table>	
							<div id="service-addOns" class="modal fade booking-details-modal">
								<div class="modal-dialog modal-lg">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title"><?php echo $label_language_values['service_addons'];?></h4>
										</div>
										<div class="modal-body">
										<div class="table-responsive">
											<table id="table-service-addons" class="display table table-striped table-bordered" cellspacing="0" width="100%">
													<thead>
														<tr>
															<th style="width: 9px !important;">#</th>
															<th style="width: 48px !important;"><?php echo $label_language_values['serviceaddons_name'];?></th>
															<th style="width: 73px !important;"><?php echo $label_language_values['base_price'];?></th>
															<th style="width: 39px !important;"><?php echo $label_language_values['max_qty'];?></th>
														</tr>
													</thead>
													<tbody id="display_addons">
														
														
													</tbody>
											</table>
										</div>
										
										</div>
									</div>
								</div>
							</div>
							<div id="service-methods" class="modal fade booking-details-modal">
								<div class="modal-dialog modal-lg">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
											<h4 class="modal-title"><?php echo $label_language_values['service_methods'];?></h4>
										</div>
										<div class="modal-body">
										<div class="table-responsive">
											<table id="table-service-method" class="display table table-striped table-bordered" cellspacing="0" width="100%">
													<thead>
														<tr>
															<tr>
															<th style="width: 9px !important;">#</th>
															<th style="width: 48px !important;"><?php echo $label_language_values['method_title'];?></th>
															<th style="width: 73px !important;"><?php echo $label_language_values['status'];?></th>
														</tr>
														</tr>
													</thead>
													<tbody id="display_method">
													</tbody>
											</table>
										</div>
										
										</div>
									</div>
								</div>
							</div>
							</div>	
						</form>	
					</div>
				</div>
			</div>
		</div>
	</div>	
</div>	
 
		
<?php  
	include(dirname(__FILE__).'/footer.php');
?>