<?php
session_start();
if(!isset($_SESSION['user'])) {
	header("location: ../index.php");
	exit;
}
include('Pagination.php');
include("../header.php");

?>
	
	
				<div class="row">
					<div class="col-lg-12">
						<form>
							<div class="row">
								<div class="col-lg-4 col-sm-4 col-md-4">
									<div class="row">
										<div class="col-lg-4 col-sm-4 col-md-4">
											<div class="form-group">
												<label for="">City</label>
												<select id="city" name="" class="form-control" onchange="selectOutlet( document.getElementById('city').value )">
													<option value="all">All</option>
													<?php
                                                    $ct_qry = mysql_query("SELECT DISTINCT(`city_name`), `city` FROM `feedback_response` ");
                                                    while ($ct_row = mysql_fetch_array($ct_qry)) {
                                                        ?>
                                                        <option value="<?php echo $ct_row['city']; ?>"><?php echo $ct_row['city_name']; ?></option>
                                                        <?php
                                                    }
                                                    ?>
												</select>
											</div>
										</div>
										
										<div class="col-lg-4 col-sm-4 col-md-4">
											<div class="form-group">
												<label for="">Outlet</label>
												<select id="outlet" name="" class="form-control">
													<option value="all">All</option>
												</select>
											</div>
										</div>
										
										<div class="col-lg-4 col-sm-4 col-md-4">
											<div class="form-group">
												<label for="">Order Type</label>
												<select id="ordertype" name="" class="form-control">
													<option value="all">All</option>
													<?php
                                                    $ot_qry = mysql_query("SELECT DISTINCT(`order_type`) FROM `feedback_response`");
                                                    while ($ot_row = mysql_fetch_array($ot_qry)) {
                                                        ?>
                                                        <option value="<?php echo $ot_row['order_type']; ?>"><?php echo $ot_row['order_type']; ?></option>
                                                        <?php
                                                    }
                                                    ?>
												</select>
											</div>
										</div>
									</div>
								</div>
								
								<div class="col-lg-8 col-sm-8 col-md-8">
									<div class="row">
										<div class="col-lg-3 col-sm-3 col-md-3">	
											<div class="form-group">
												<label for="">Date Range</label>
												<input type="text" class="form-control textbox" id="logdatepick" placeholder="2017-11-01 - 2017-11-30">
											</div>
										</div>
										<div class="col-lg-2 col-sm-2 col-md-2">	
											<div class="form-group">
												<label for="">Operator</label>
												<select id="starOperator" name="" class="form-control">
													<option value="">Select Operator</option>
													<option value=">=">>=</option>
													<option value=">">></option>
													<option value="=">=</option>
													<option value="<="><=</option>
													<option value="<"><</option>
												</select>
											</div>
										</div>
										<div class="col-lg-2 col-sm-2 col-md-2">	
											<div class="form-group">
												<label for="">Star Number</label>
												<select id="starnumber" name="" class="form-control">
													<option value="">Select Star</option>
													<option value="1">1</option>
													<option value="2">2</option>
													<option value="3">3</option>
													<option value="4">4</option>
													<option value="5">5</option>
												</select>
											</div>
										</div>
										<div class="col-lg-2 col-sm-2 col-md-2">	
											<div class="form-group">
												<button type="button" name="submit-btn" class="btn btn-outline-primary txtbtn-submit" onclick="feedbackLogsData('fld', document.getElementById('city').value, document.getElementById('outlet').value, document.getElementById('ordertype').value, document.getElementById('logdatepick').value, document.getElementById('starOperator').value, document.getElementById('starnumber').value )">Submit</button>
											</div>
										</div>
										<div class="col-lg-2 col-sm-2 col-md-2 customer-combo">
											<!-- <div class="ui-widget">
												<?php
												//$cnqry = mysql_query("SELECT `guest_name`, `fb_no`, `outlet_id`, `invoice_id` FROM `feedback_response`");
												//$cnrow1 = mysql_fetch_array($cnqry)
												?>
												<select id="combobox" name="" class="form-control select-combobox easyui-combobox" onchange="getCustomerData( document.getElementById('combobox').value )">
													<option value="username">Customer Name</option>
													<?php
													//while ($cnrow = mysql_fetch_array($cnqry)) {
														?>
														<option value="<?php //echo $cnrow['guest_name']; ?>"><?php //echo $cnrow['guest_name']; ?></option>
														<?php
													//}
													?>
												</select>
											</div> -->
											<div class="form-group">
												<label for="">Search Customer</label>
												<input type="text" name="" class="form-control" id="searchCustomer" placeholder="Enter name or email">
											</div>
										</div>
										<div class="col-lg-1 col-sm-1 col-md-1">
											<button type="button" name="search-btn" class="btn btn-outline-primary txtbtn-submit" onclick="getCustomerData( document.getElementById('searchCustomer').value )">Search</button>
										</div>
									</div>
								</div>
							
							</div>
						</form>
					</div>
				</div>
		
				<div class="row">
					<div class="col-lg-12">
						
						<div class="card">
							<div class="card-body">
						
								<div class="row">
									<div class="col-lg-6">
										<div id="paginate-customer" class="blade-pagination">
										<?php
										$limit = 3;
										$qry_pgn = mysql_query("SELECT count(*) AS pgnNum FROM `feedback_response`");
										$row_pgn = mysql_fetch_assoc($qry_pgn);
										$rowCount = $row_pgn['pgnNum'];

										$pagConfig = array('baseURL'=>'getData.php', 'totalRows'=>$rowCount, 'perPage'=>$limit, 'contentDiv'=>'paginate-customer');
    									$pagination =  new Pagination($pagConfig);

										$qry1 = mysql_query("SELECT * FROM `feedback_response` ORDER BY `response_date_time` DESC LIMIT $limit");
										if (mysql_num_rows($qry1) > 0) {
											?>
											<div class="scroll-logs">
												<div class="col-lg-12">
											<?php
											while ($row1 = mysql_fetch_array($qry1)) {	
												$date_time = $row1['response_date_time'];
												$fbno = $row1['fb_no'];
												$rate_qry = mysql_query("SELECT (SUM(`ans_wt`) / count(`fb_no`)) AS rate FROM `feedback_response_details` WHERE `fb_no` = '$fbno'");
												$rate_row = mysql_fetch_array($rate_qry);
												$avg_rate = number_format($rate_row['rate'], 1);

												if($row1['agent_name']==NULL OR $row1['agent_name']=='NULL'){ $name = 'Guest'; } else { $name =$row1['agent_name']; }

												?>
												<div class="view-customer">
													<div class="shadow"></div>
													<div class="row">
														<div class="col-lg-6">
															<p class="customer-name text-logs" style="font-weight: 800;"><?php echo $row1['guest_name']; ?></p>
															<p class="text-logs">Response By <span class="text-bold"><?php echo  $name; ?></span></p>
															<p class="text-logs">Response On <span class="text-bold"><?php echo date('d-m-Y H:i:s', strtotime($row1['response_date_time'])); ?></span></p>
															<p class="text-logs">
																<?php
																for ($i=1; $i <= 5; $i++) { 
																	
																	if ($i <= $avg_rate) {
																		$checked = "star-checked";
																		$star = "fa-star";
																	} else if( $avg_rate > $j AND $avg_rate < $i ) { 
																		$checked = "star-checked";
																		$star = "fa-star-half-o";
																	} else {
																		$checked = "";
																		$star = "fa-star-o";
																	}	
																	$j = $i;

																	echo '<i class="fa '.$star." ".$checked.'" aria-hidden="true"></i>';

																}
																?>
																<span class="text-bold">Rated <?php echo number_format($rate_row['rate'], 1); ?></span>
															</p>
														</div>
														<div class="col-lg-6 text-right">
															<p>&nbsp;</p>
															<p class="customer-name text-logs">Invoice No. - <span class="text-bold"><?php echo $row1['invoice_no']; ?></span></p>
															<p class="customer-name text-logs">Order Source - <span class="text-bold"><?php echo $row1['order_source_name']; ?></span></p>
															<p class="customer-name text-logs">Outlet - <span class="text-bold"><?php echo $row1['outlet_name']; ?></span></p>
														</div>
													</div>
													<div class="row">
														<div class="col-lg-8">
															<p class="text-logs"><span class="help-block text-bold"><?php echo $row1['fb_comments']; ?></span></p>
														</div>
														<div class="col-lg-4">
															<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('details', <?php echo $row1['fb_no']; ?>, <?php echo $row1['outlet_id']; ?>, <?php echo $row1['invoice_id']; ?> )">View Details</button>
														</div>
													</div>
												</div>
												<?php
											}
											?>
											</div>
											</div>
											<?php
											echo $pagination->createLinks();
										}
										
										?>
										</div>
									</div>
									
									<div class="col-lg-6">
										<div class="customer-detail" id="getFixed">
											<div class="tabbable-panel">
												<div class="tabbable-line">
													<ul class="nav nav-tabs ">
														<li class="active">
															<a href="#feedback_datails" data-toggle="tab">
															Feedback Details </a>
														</li>
														<li>
															<a href="#order_info" data-toggle="tab">
															Order Info </a>
														</li>
													</ul>
													<div class="tab-content">
														
														<div class="tab-pane active" id="feedback_datails">
															<div id="customer-fb-detail">
																
															</div>
														</div>
														
														<div class="tab-pane" id="order_info">
															<div id="customer-order-info">
																
															</div>
														</div>
													</div>
												</div>
											</div>
										</div>
										<div class="cutomer-log-excel">
											<!-- <a href="exl_logs_customer.php">Download Excel</a> -->
										</div>
									</div>
								</div>
								
							</div>
						</div>
						
					</div>
				</div>
	
<?php include("../footer.php"); ?>

<script type="text/javascript">
$(document).ready(function(){
	var addButton = $('.add_button'); //Add button selector
	var wrapper = $('.field_wrapper'); //Input field wrapper
	var fieldHTML = '<div class="col-lg-4 remove-div"><div class="input-group"><input type="text" id="input-small" name="alert-emails[]" class="form-control" /><span class="input-group-btn remove_button"><button type="button" class="btn btn-custom"><i class="fa fa-times" aria-hidden="true"></button></span></div></div>'; //New input field html 
	$(addButton).click(function(){ //Once add button is clicked
		$(wrapper).append(fieldHTML); // Add field html
	});
	$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
		e.preventDefault();
		$(this).parents('.col-lg-4.remove-div').remove(); //Remove field html
	});
});
</script>

<script>


jQuery(function($) {
  	function fixDiv() {
	    var $cache = $('#getFixed');
	    if ($(window).scrollTop() > 100)
	      	$cache.css({
		        'position': 'fixed',
		        'top': '10%',
		        'width': '38%',
		        'height': '67%'
	      	});
	    else
	      	$cache.css({
		        'position': 'relative',
		        'top': 'auto',
		        'width': 'auto',
		        'height': 'auto'
	      	});
  	}
  	$(window).scroll(fixDiv);
  	fixDiv();
});

jQuery(function($) {
  	function fixDiv() {
	    var $cache = $('.cutomer-log-excel');
	    if ($(window).scrollTop() > 100)
	      	$cache.css({
		        'position': 'fixed',
		        'padding': '20px 0',
		        'font-size': '15px',
		        'right': '4.5%',
		        'top' : '80%'
	      	});
	    else
	      	$cache.css({
		        'position': 'relative',
		        'padding': '20px 0',
		        'font-size': '15px',
		        'right': '0',
		        'top' : 'auto'
	      	});
  	}
  	$(window).scroll(fixDiv);
  	fixDiv();
});



</script>


<!-- Include Required Prerequisites -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<script>
$('#logdatepick').daterangepicker(
	{
	    locale: {
	      format: 'DD/MM/Y'
	    }
	}
);
</script>