<?php 

if(isset($_SESSION['loggedin_id']))
{
   header("location:dashboard.php");
} 

include 'config.php'; 
include 'functions.php'; 

$branch_id = 0;
if(isset($_GET['branch_id'])){
    $branch_id = $_GET['branch_id'];
}
$branch   = get_single_branch($branch_id);
if (!is_array($branch)) {
    $branch = [];
}
$imgLink   = "";
$hasLogo   = false;
$required  = "";

// Safely build logo path only when branch data is available
if (!empty($branch['location']) && !empty($branch['logo'])) {
    $location = "../" . $branch['location'];
    $img      = explode(',', (string) $branch['logo']);
    if (!empty($img[0])) {
        $imgLink = 'feedback/' . $location . '/' . $img[0];
        $hasLogo = true;
    }
}

// var_dump($branch['feed_1']);
?>

<!doctype html>
<html lang="en">

<head>
    <title>Feedback Form</title>
    <!--== META TAGS ==-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--== FAV ICON ==-->
    <link rel="shortcut icon" href="images/fav.ico">

    <!-- GOOGLE FONTS -->
    <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:400,600,700" rel="stylesheet">

    <!-- FONT-AWESOME ICON CSS -->
    <link rel="stylesheet" href="css/font-awesome.min.css">

    <!--== ALL CSS FILES ==-->
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/mob.css">
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/materialize.css" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
   <script type="text/javascript">
      function promptMsg(type = 0, msg=""){
            if(type == 1)
            {
               $("#successrMsgModal").show();
               $("#successrMsgModal").find('span').html(msg);
            }
            else if(type == 0)
            {
               $("#errorMsgModal").show();
               $("#errorMsgModal").find('span').html(msg);
            }
         setTimeout(function() { 
               $("#errorMsgModal").hide();
               $("#successrMsgModal").hide();
         }, 1500);

      }
   </script>
   
</head>

<body class="feedback-page">
    <!-- ERROR MSG MODAL -->
      <div id="errorMsgModal">
          <div class="modal-content">
              <span></span>
          </div>
      </div>
      <!-- SUCCESS MSG MODAL -->
      <div id="successrMsgModal">
          <div class="modal-content">
              <span></span>
          </div>
      </div>
      
<div class="container feedback-form-container">
    
    <div class="row mb-5 form-Row justify-content-center">
        <div class="col-lg-10 col-md-12 col-sm-12 asnaff">
            
            <form method="POST" action="ajax-request.php" id="feedbackForm">
                <?php if($hasLogo): ?>
                    <img src="<?=$imgLink?>" alt="Branch logo" class="card-img-top mb-3" />
                <?php else: ?>
                    <h3 class="feedback-brand-title mb-3">
                        <?= !empty($branch['name']) ? htmlspecialchars($branch['name']) : 'Feedback Form'; ?>
                    </h3>
                <?php endif; ?>
                <div class="row">
                    <div class="input-field col s6">
                        <input name="name" id="name" type="text" class="validate">
                        <label for="name" class="feedback-label">Your Name</label>
                    </div>
                    <div class="input-field col s6">
                        <input name="number" id="number" type="text" class="validate">
                        <label for="number" class="feedback-label">Mobile Number</label>
                    </div>
                </div>

                <div class="row">
                    <div class="input-field col col-lg-6 col-md-6 col-sm-12 rating-block">
                        <h5><?= !empty($branch['feed_1']) ? $branch['feed_1'] : 'Food Quality' ?></h5>
                        <br>
                        <div class="FoodQualitymain_star_custom">
                            <i class="fa FoodQualitycustomstar fa-star FoodQuality_star_custom" FoodQualitydata-id="1"></i>
                            <i class="fa FoodQualitycustomstar fa-star-o FoodQuality_star_custom" FoodQualitydata-id="2"></i>
                            <i class="fa FoodQualitycustomstar fa-star-o FoodQuality_star_custom" FoodQualitydata-id="3"></i>
                            <i class="fa fa-star-o FoodQuality_star_custom" FoodQualitydata-id="4"></i>
                            <i class="fa fa-star-o FoodQuality_star_custom" FoodQualitydata-id="5"></i>
                            <span>(<b>1</b> Out of <b>5</b>) <b>Average</b></span>
                        </div>
                    </div>

                    <div class="input-field col col-lg-6 col-md-6 col-sm-12 rating-block">
                        <h5><?= !empty($branch['feed_2']) ? $branch['feed_2'] : 'Food Presentation' ?></h5>
                        <br>
                        <div class="FoodPresentationmain_star_custom">
                            <i class="fa FoodPresentationcustomstar fa-star FoodPresentation_star_custom" FoodPresentationdata-id="1"></i>
                            <i class="fa FoodPresentationcustomstar fa-star-o FoodPresentation_star_custom" FoodPresentationdata-id="2"></i>
                            <i class="fa FoodPresentationcustomstar fa-star-o FoodPresentation_star_custom" FoodPresentationdata-id="3"></i>
                            <i class="fa fa-star-o FoodPresentation_star_custom" FoodPresentationdata-id="4"></i>
                            <i class="fa fa-star-o FoodPresentation_star_custom" FoodPresentationdata-id="5"></i>
                            <span>(<b>1</b> Out of <b>5</b>) <b>Average</b></span>
                        </div>
                    </div>

                    <div class="input-field col col-lg-6 col-md-6 col-sm-12 rating-block">
                        <h5><?= !empty($branch['feed_3']) ? $branch['feed_3'] : 'Atmosphere' ?></h5>
                        <br>
                        <div class="Atmospheremain_star_custom">
                            <i class="fa Atmospherecustomstar fa-star Atmosphere_star_custom" Atmospheredata-id="1"></i>
                            <i class="fa Atmospherecustomstar fa-star-o Atmosphere_star_custom" Atmospheredata-id="2"></i>
                            <i class="fa Atmospherecustomstar fa-star-o Atmosphere_star_custom" Atmospheredata-id="3"></i>
                            <i class="fa fa-star-o Atmosphere_star_custom" Atmospheredata-id="4"></i>
                            <i class="fa fa-star-o Atmosphere_star_custom" Atmospheredata-id="5"></i>
                            <span>(<b>1</b> Out of <b>5</b>) <b>Average</b></span>
                        </div>
                    </div>

                    <div class="input-field col col-lg-6 col-md-6 col-sm-12 rating-block">
                        <h5><?= !empty($branch['feed_4']) ? $branch['feed_4'] : 'Ambiance' ?></h5>
                        <br>
                        <div class="Ambiancemain_star_custom">
                            <i class="fa Ambiancecustomstar fa-star Ambiance_star_custom" Ambiancedata-id="1"></i>
                            <i class="fa Ambiancecustomstar fa-star-o Ambiance_star_custom" Ambiancedata-id="2"></i>
                            <i class="fa Ambiancecustomstar fa-star-o Ambiance_star_custom" Ambiancedata-id="3"></i>
                            <i class="fa fa-star-o Ambiance_star_custom" Ambiancedata-id="4"></i>
                            <i class="fa fa-star-o Ambiance_star_custom" Ambiancedata-id="5"></i>
                            <span>(<b>1</b> Out of <b>5</b>) <b>Average</b></span>
                        </div>
                    </div>

                    <div class="input-field col col-lg-6 col-md-6 col-sm-12 rating-block">
                        <h5><?= !empty($branch['feed_5']) ? $branch['feed_5'] : 'Service' ?></h5>
                        <br>
                        <div class="Servicemain_star_custom">
                            <i class="fa Servicecustomstar fa-star Service_star_custom" Servicedata-id="1"></i>
                            <i class="fa Servicecustomstar fa-star-o Service_star_custom" Servicedata-id="2"></i>
                            <i class="fa Servicecustomstar fa-star-o Service_star_custom" Servicedata-id="3"></i>
                            <i class="fa fa-star-o Service_star_custom" Servicedata-id="4"></i>
                            <i class="fa fa-star-o Service_star_custom" Servicedata-id="5"></i>
                            <span>(<b>1</b> Out of <b>5</b>) <b>Average</b></span>
                        </div>
                    </div>
                </div>
            
                <div class="row">
                    <div class="input-field col col-lg-12 col-md-12 col-sm-12">
                        <p class="feedback-label">Message</p>
                        <textarea  class="form-control feedback-message" rows="5" name="message" id="message"></textarea>
                    </div>
                </div>
                <hr>
                <div class="row">
                    <div class="input-field col col-lg-12 col-md-12 col-sm-12">
                        <button class="waves-effect waves-light btn-large btn-log-in" type="submit">Submit Feedback</button>
                    </div>
                </div>

                <input type="hidden" name="feedbackform-request" value="1">
                <input type="hidden" name="FoodQualityrating" id="FoodQualityrating" value="3">
                <input type="hidden" name="FoodPresentationrating" id="FoodPresentationrating" value="1">
                <input type="hidden" name="Atmosphererating" id="Atmosphererating" value="1">
                <input type="hidden" name="Ambiancerating" id="Ambiancerating" value="1">
                <input type="hidden" name="Servicerating" id="Servicerating" value="1">
                <input type="hidden" name="branch_id" id="branch_id" value="<?=$branch_id;?>">
            </form>
        </div>
    </div>
</div>
  
        <div class="container" style="margin-top:250px;">
            <div class="row">
                <div class="col col-12">
                    <p></p>
                </div>
            </div>
        </div>
        
        <!--<footer>-->
        <!--  <div class="container text-center">-->
        <!--    <p>powered by <a href="https://www.itresources.com.pk" rel="noopener" target="_blank">IT Resources</a>.</p>-->
        <!--    <p><a href="https://www.itresources.com.pk" rel="noopener" target="_blank">www.itresources.com.pk</a>.</p>-->
        <!--    <p>Helpline: <a href="tel:923113917777" rel="noopener" target="_blank">0311-391-7777</a>.</p>-->
        <!--  </div>-->
        <!--</footer>-->
        
    

    <!--======== SCRIPT FILES =========-->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/materialize.min.js"></script>
    <script src="js/custom.js"></script>
     <script type="text/javascript">
          function promptMsg(type = 0, msg=""){
                if(type == 1)
                {
                   $("#successrMsgModal").show();
                   $("#successrMsgModal").find('span').html(msg);
                }
                else if(type == 0)
                {
                   $("#errorMsgModal").show();
                   $("#errorMsgModal").find('span').html(msg);
                }
             setTimeout(function() { 
                   $("#errorMsgModal").fadeOut();
                }, 1500);
    
          }
    
          $(document).ready(function() {
    
             $("#feedbackForm").on('submit', (function(e) {
                e.preventDefault();
    
                //console.log("form Submitted");
    
                $.ajax({
                   url: $(this).attr('action'),
                   type: "POST",
                   data: new FormData(this),
                   dataType: "json",
                   contentType: false,
                   cache: false,
                   processData: false,
                   success: function(data) {
                   if(data.success == 1){
                      var guestName = $.trim($("#name").val()) || "Guest";
                      $("#feedbackForm").trigger("reset"); // to reset form input fields  
                      promptMsg(1,"Thanks for your feedback, " + guestName + "!");
                      setTimeout(function() { 
                         location.reload();
                      }, 1000);
                      
                   }
                   else{
                      promptMsg(0,data.msg);
                   }
                         
                   },
                   error: function(e) {
                      console.log(e);
                   }
                });
    
          }));
          
           // STARS WORK
           FoodQualitycurrentElement = 0;
           FoodPresentationcurrentElement = 0;
           AtmospherecurrentElement = 0;
           AmbiancecurrentElement = 0;
           ServicecurrentElement = 0;
           // Food Quality
           $(".FoodQuality_star_custom").click(function(){
                var FoodQualitycurrentElement = $(this).attr('FoodQualitydata-id');

                $("#FoodQualityrating").val(FoodQualitycurrentElement);
                refreshStars(1);
                setStars(FoodQualitycurrentElement, 1);
           });
        //     $(".FoodQuality_star_custom").mouseover(function(){
        //         var FoodQualitycurrentElement = $(this).attr('FoodQualitydata-id');
                
        //         refreshStars(1);
        //         setStars(FoodQualitycurrentElement, 1);
        //   });
        //     $(".FoodQuality_star_custom").mouseout(function(){
        //         var FoodQualitycurrentElement = $("#FoodQualityrating").val();
        //         refreshStars(1);
        //         setStars(FoodQualitycurrentElement, 1);
        //   });
           
          // FoodPresentation
          $(".FoodPresentation_star_custom").click(function(){
                var FoodPresentationcurrentElement = $(this).attr('FoodPresentationdata-id');
                $("#FoodPresentationrating").val(FoodPresentationcurrentElement);
                refreshStars(2);
                setStars(FoodPresentationcurrentElement, 2);
          });
        //     $(".FoodPresentation_star_custom").mouseover(function(){
        //         var FoodPresentationcurrentElement = $(this).attr('FoodPresentationdata-id');
        //         refreshStars(2);
        //         setStars(FoodPresentationcurrentElement, 2);
        //   });
        //     $(".FoodPresentation_star_custom").mouseout(function(){
        //         var FoodPresentationcurrentElement = $("#FoodPresentationrating").val();
        //         refreshStars(2);
        //         setStars(FoodPresentationcurrentElement, 2);
        //   });
           
           
            // Atmosphere
          $(".Atmosphere_star_custom").click(function(){
                var AtmospherecurrentElement = $(this).attr('Atmospheredata-id');
                $("#Atmosphererating").val(AtmospherecurrentElement);
                refreshStars(3);
                setStars(AtmospherecurrentElement, 3);
          });
        //     $(".Atmosphere_star_custom").mouseover(function(){
        //         var AtmospherecurrentElement = $(this).attr('Atmospheredata-id');
        //         refreshStars(3);
        //         setStars(AtmospherecurrentElement, 3);
        //   });
        //     $(".Atmosphere_star_custom").mouseout(function(){
        //         var AtmospherecurrentElement = $("#Atmosphererating").val();
        //         refreshStars(3);
        //         setStars(AtmospherecurrentElement, 3);
        //   });
           
           
            // Ambiance
          $(".Ambiance_star_custom").click(function(){
                var AmbiancecurrentElement = $(this).attr('Ambiancedata-id');
                $("#Ambiancerating").val(AmbiancecurrentElement);
                refreshStars(4);
                setStars(AmbiancecurrentElement,4);
          });
        //     $(".Ambiance_star_custom").mouseover(function(){
        //         var AmbiancecurrentElement = $(this).attr('Ambiancedata-id');
        //         refreshStars(4);
        //         setStars(AmbiancecurrentElement, 4);
        //   });
        //     $(".Ambiance_star_custom").mouseout(function(){
        //         var AmbiancecurrentElement = $("#Ambiancerating").val();
        //         refreshStars(4);
        //         setStars(AmbiancecurrentElement, 4);
        //   });
           
            // Service
          $(".Service_star_custom").click(function(){
                var ServicecurrentElement = $(this).attr('Servicedata-id');
                $("#Servicerating").val(ServicecurrentElement);
                refreshStars(5);
                setStars(ServicecurrentElement,5);
          });
        //     $(".Service_star_custom").mouseover(function(){
        //         var ServicecurrentElement = $(this).attr('Servicedata-id');
        //         refreshStars(5);
        //         setStars(ServicecurrentElement, 5);
        //   });
        //     $(".Service_star_custom").mouseout(function(){
        //         var ServicecurrentElement = $("#Servicerating").val();
        //         refreshStars(5);
        //         setStars(ServicecurrentElement, 5);
        //   });
        
        function setStars(total = 0,type=0 ){
                if(type == 1){
                    var FoodQualityratingText=['Poor','Sufficient','Average','Well','Very good'];
                    $(".FoodQualitymain_star_custom").find("span").html(' (<b>'+total+'</b> Out of <b>5</b>) <b>'+FoodQualityratingText[total-1]+'</b>' );
                    for (var i = 1; i <= total; i++) {
                        $("[FoodQualitydata-id="+i+"]").removeClass("fa-star-o").addClass("fa-star FoodQualitycustomstar");
                    }
                }
                
                if(type == 2){
                    var FoodPresentationratingText=['Poor','Sufficient','Average','Well','Very good'];  
                    $(".FoodPresentationmain_star_custom").find("span").html(' (<b>'+total+'</b> Out of <b>5</b>) <b>'+FoodPresentationratingText[total-1]+'</b>' );
                    for (var i = 1; i <= total; i++) {
                        $("[FoodPresentationdata-id="+i+"]").removeClass("fa-star-o").addClass("fa-star FoodPresentationcustomstar");
                    }
                }
                
                if(type == 3){
                    var AtmosphereratingText=['Poor','Sufficient','Average','Well','Very good'];
                    $(".Atmospheremain_star_custom").find("span").html(' (<b>'+total+'</b> Out of <b>5</b>) <b>'+AtmosphereratingText[total-1]+'</b>' );
                    for (var i = 1; i <= total; i++) {
                        $("[Atmospheredata-id="+i+"]").removeClass("fa-star-o").addClass("fa-star Atmospherecustomstar");
                    }
                }
                
                if(type == 4){
                    var AmbianceratingText=['Poor','Sufficient','Average','Well','Very good'];
                    $(".Ambiancemain_star_custom").find("span").html(' (<b>'+total+'</b> Out of <b>5</b>) <b>'+AmbianceratingText[total-1]+'</b>' );
                    for (var i = 1; i <= total; i++) {
                        $("[Ambiancedata-id="+i+"]").removeClass("fa-star-o").addClass("fa-star Ambiancecustomstar");
                    }
                }
                
                if(type == 5){
                    var ServiceratingText=['Poor','Sufficient','Average','Well','Very good'];
                    $(".Servicemain_star_custom").find("span").html(' (<b>'+total+'</b> Out of <b>5</b>) <b>'+ServiceratingText[total-1]+'</b>' );
                    for (var i = 1; i <= total; i++) {
                        $("[Servicedata-id="+i+"]").removeClass("fa-star-o").addClass("fa-star Servicecustomstar");
                    }
                }
           }
           
           function refreshStars(type = 0){
                if(type == 1){
                    $(".FoodQualitymain_star_custom").find("span").html('(<b>3</b> Out of <b>5</b>) <b>Average</b>' );
                    $(".FoodQuality_star_custom").removeClass("fa-star FoodQualitycustomstar").addClass("fa-star-o");
                }
               
                if(type == 2){
                    $(".FoodPresentationmain_star_custom").find("span").html('(<b>3</b> Out of <b>5</b>) <b>Average</b>' );
                    $(".FoodPresentation_star_custom").removeClass("fa-star FoodPresentationcustomstar").addClass("fa-star-o");
                }
               
                if(type == 3){
                    $(".Atmospheremain_star_custom").find("span").html('(<b>3</b> Out of <b>5</b>) <b>Average</b>' );
                    $(".Atmosphere_star_custom").removeClass("fa-star Atmospherecustomstar").addClass("fa-star-o");
                }
               
                if(type == 4){
                    $(".Ambiancemain_star_custom").find("span").html('(<b>3</b> Out of <b>5</b>) <b>Average</b>' );
                    $(".Ambiance_star_custom").removeClass("fa-star Ambiancecustomstar").addClass("fa-star-o");
                }
               
                if(type == 5){
                    $(".Servicemain_star_custom").find("span").html('(<b>3</b> Out of <b>5</b>) <b>Average</b>' );
                    $(".Service_star_custom").removeClass("fa-star Servicecustomstar").addClass("fa-star-o");
                }       
           }
          
          
       });

   </script>
</body>

</html>