<?php

session_start();

if(!isset($_SESSION['user'])) {

	header("location: ../index.php");

	exit;

}



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

    //Include pagination class file

    include('Pagination.php');

    

    //Include database configuration file

    include "../dbconnect.php";

    

    $start = !empty($_POST['page'])?$_POST['page']:0;

    $limit = 3;

    

    //get number of rows

    

	

	$qry_pgn = mysql_query("SELECT count(*) AS pgnNum FROM `feedback_response`");

	$row_pgn = mysql_fetch_assoc($qry_pgn);

	$rowCount = $row_pgn['pgnNum'];

    

    //initialize pagination class

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

    $pagination =  new Pagination($pagConfig);

    

    //get rows

    

	$qry1 = mysql_query("SELECT * FROM `feedback_response` ORDER BY `response_date_time` DESC LIMIT $start,$limit");

	if (mysql_num_rows($qry1) > 0) {

		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>

					</div>

					<div class="col-lg-6 text-right">
						<p>&nbsp;</p>
						<p class="text-logs">Invoice No -  <span class="text-bold"> <?php echo $row1['invoice_no']; ?></span></p>

						<p class="text-logs">Order Source - <span class="text-bold"><?php echo $row1['order_source_name']; ?></span></p>

						<p class="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">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="fa fa-star star-checked"></span>

							<span class="fa fa-star star-checked"></span>

							<span class="fa fa-star star-checked"></span>

							<span class="fa fa-star star-checked"></span>

							<span class="fa fa-star"></span> -->

							<!-- <i class="fa fa-star-half-o star-checked" aria-hidden="true"></i>

							<i class="fa fa-star-o" aria-hidden="true"></i> -->

							<span class="text-bold">Rated <?php echo number_format($rate_row['rate'], 1); ?></span>

						</p>

						<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

		}

		echo $pagination->createLinks();

	}

}

?>