<?php
include_once('inc.function.php');
include_once('confdb.php');
include_once('db.functions.php');

//$result = mysqli_query($con,"SELECT * FROM config_countries ORDER BY COUNTRY_NAME");
//$result2 = mysqli_query($con,"SELECT * FROM config_countries ORDER BY COUNTRY_NAME");
//$result3 = mysqli_query($con,"SELECT * FROM config_countries ORDER BY COUNTRY_NAME");
$results = DB::query("SELECT * FROM config_countries ORDER BY COUNTRY_NAME");
$result4 = DB::query("SELECT * FROM config_states WHERE COUNTRY_CODE = %s", $_SESSION['CUST_COUNTRY']);

include_once('header.php');
?>

<script>
function showStates(str) {
    if (str == "") {
        document.getElementById("StatesDisplay").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("StatesDisplay").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","list_states.php?q="+str,true);
        xmlhttp.send();
    }
}


</script>

   <!-- Begin page content -->
    <div class="container">
      <div class="page-header">
        <h1><img src='img/logo.jpg'/>&nbsp ONLINE BOOKING</h1>
      </div>
      <!-- CONTENT STARTS HERE -->
      <div class="stepwizard">
          <div class="stepwizard-row setup-panel">
              <div class="stepwizard-step">
                  <a href="index.php" type="button" class="btn btn-success btn-circle">1</a>
                  <p>Venue Search</p>
              </div>
              <div class="stepwizard-step">
                  <a href="booking.php" type="button" class="btn btn-success btn-circle">2</a>
                  <p>Venue Booking</p>
              </div>
              <div class="stepwizard-step">
                  <a href="booking_event.php" type="button" class="btn btn-success btn-circle">3</a>
                  <p>Event Detail</p>
              </div>
              <div class="stepwizard-step">
                  <a href="booking_contact.php" type="button" class="btn btn-success btn-circle">4</a>
                  <p>Contact Info</p>
              </div>
              <div class="stepwizard-step">
                  <a href="#step-5" type="button" class="btn btn-warning btn-circle">5</a>
                  <p>Mailing Address</p>
              </div>
              <div class="stepwizard-step">
                  <a href="#step-6" type="button" class="btn btn-danger btn-circle" disabled="disabled">6</a>
                  <p>Booking Submission</p>
              </div>
          </div>
      </div>

      <div class="progress">
        <div class="progress-bar progress-bar-striped progress-bar-success active" role="progressbar"
        aria-valuenow="90" aria-valuemin="0" aria-valuemax="100" style="width:80%">
          90%
        </div>
      </div>

      <?php if(!empty($_SESSION['MESSAGE'])) { echo $_SESSION['MESSAGE'].'<br>';  unset($_SESSION['MESSAGE']); } ?>

        <div class="row setup-content" id="step-5">
            <div class="col-xs-12">
                <div class="col-md-12">
                    <h3> Step 5: Mailing Address</h3>

                        <form role="form" method="POST" action="booking_address_process.php"> 

                        <div class="alert alert-info" role="alert"><span class="glyphicon glyphicon-ok-sign"></span> Please fill up the details below</div>
                        <div class="form-group">
                          <label for="NAME">Name:</label>
                          <input type="text" class="form-control" name="CLIENT_NAME" id="CLIENT_NAME"  value = "<?php echo $_SESSION['CLIENT_NAME']; ?>" required>
                          <p class="text-danger"><small>* required.</small></p>
                        </div>

                        <div class="form-inline">
                          <label for="TELEPHONE">Telephone:</label>
                              <select name="TELEPHONE_CCC" id="TELEPHONE_CCC" class="form-control" required>
                              <option value="0">-- Please Select --</option>
                              <option value="+6" <?php if ($_SESSION['TELEPHONE_CCC'] == "+6") { echo 'selected="selected"'; } ?>>MALAYSIA (+6)</option>
                                <?php                 
                                  //while($row = mysqli_fetch_array($result)) 
                                  foreach ($results as $row)
                                  { 
                                ?>
                               <option value="<?php echo $row['COUNTRY_CALLING_CODE']; ?>" <?php if ($_SESSION['TELEPHONE_CCC'] == $row['COUNTRY_CALLING_CODE']) { echo 'selected="selected"'; } ?>>
                                <?php echo $row['COUNTRY_NAME'].'(+'.$row['COUNTRY_CALLING_CODE'].')'; ?>
                              </option>
                                <?php } ?>
                              </select>


                          <input type="text" class="form-control" name="CLIENT_TELEPHONE" id="CLIENT_TELEPHONE" value = "<?php echo $_SESSION['CLIENT_TELEPHONE']; ?>" required>
						    <p class="text-danger"><small>* required.</small></p>
                        </div>

                      <br>

                        <div class="form-inline">
                          <label for="HANDPHONE">Handphone:</label>

                              <select name="HANDPHONE_CCC" id="HANDPHONE_CCC" class="form-control" required>
                              <option value="0">-- Please Select --</option>
                              <option value="+6" <?php if ($_SESSION['HANDPHONE_CCC'] == "+6") { echo 'selected="selected"'; } ?>>MALAYSIA (+6)</option>
                                <?php                 
                                  foreach ($results as $row3)
                                  { 
                                ?>
                               <option value="<?php echo $row3['COUNTRY_CALLING_CODE']; ?>" <?php if ($_SESSION['HANDPHONE_CCC'] == $row3['COUNTRY_CALLING_CODE']) { echo 'selected="selected"'; } ?>>
                                <?php echo $row3['COUNTRY_NAME'].'(+'.$row3['COUNTRY_CALLING_CODE'].')'; ?>
                              </option>
                                <?php } ?>
                              </select>


                          <input type="text" class="form-control" name="CLIENT_TELEPHONE2" id="CLIENT_TELEPHONE2" value = "<?php echo $_SESSION['CLIENT_TELEPHONE2']; ?>">
                        </div>

                        <br>
                          
                          <div class="form-inline">

                          <label for="FAX">Fax:</label>
                              <select name="FAX_CCC" id="FAX_CCC" class="form-control">
                              <option value="0">-- Please Select --</option>
                              <option value="+6" <?php if ($_SESSION['FAX_CCC'] == "+6") { echo 'selected="selected"'; } ?>>MALAYSIA (+6)</option>
                                <?php                 
                                  //while($row2 = mysqli_fetch_array($result2)) 
                                  foreach ($results as $row2)
                                  { 
                                ?>
                               <option value="<?php echo $row2['COUNTRY_CALLING_CODE']; ?>" <?php if ($_SESSION['FAX_CCC'] == $row2['COUNTRY_CALLING_CODE']) { echo 'selected="selected"'; } ?>>
                                <?php echo $row2['COUNTRY_NAME'].'(+'.$row2['COUNTRY_CALLING_CODE'].')'; ?>
                              </option>
                                <?php } ?>
                              </select>
                          <input type="text" class="form-control" name="CLIENT_FAX" id="CLIENT_FAX"  value = "<?php echo $_SESSION['CLIENT_FAX']; ?>">
                        
                        </div>

                        <br><br>
                        
                        <?php 
                              if($_SESSION['TYPE_CUSTOMER'] == 2){
                                  echo'
                                      <div class="form-group">
                                        <label for="COMPANY_NAME">Company Name:</label>
                                        <input type="text" class="form-control" name="COMPANY_NAME" id="COMPANY_NAME" value="'.$_SESSION[COMPANY_NAME].'" required>
                                        <p class="text-warning"><small>*Required only if you are representing on behalf of company</small></p>
                                      </div> 
                                  ';
                              }
                        ?>

                        <div class="form-group">
                          <label for="ADDRESS_1">Address 1:</label>
                          <input type="text" class="form-control" name="ADDRESS_1" id="ADDRESS_1" value="<?php echo $_SESSION['ADDRESS_1']; ?>" required>
                          <p class="text-danger"><small>* required.</small></p>
                        </div>

                        <div class="form-group">
                          <label for="ADDRESS_1">Address 2:</label>
                          <input type="text" class="form-control" name="ADDRESS_2" id="ADDRESS_2" value="<?php echo $_SESSION['ADDRESS_2']; ?>">
                          <p class="text-danger"><small>* required.</small></p>
                        </div>

                       <div class="form-group">
                          <label for="CUST_COUNTRY">Country:</label>
                              <select name="CUST_COUNTRY" id="CUST_COUNTRY" class="form-control" onchange="showStates(this.value)">
                              <option value="0">-- Select Country --</option>
                              <option value="MY">MALAYSIA</option>
                                <?php                 
                                  //while($row3 = mysqli_fetch_array($result3)) 
                                  foreach ($results as $row3)
                                  { 
                                ?>
                               <option value="<?php echo $row3['COUNTRY_SHORT']; ?>" <?php if ($_SESSION['CUST_COUNTRY'] == $row3['COUNTRY_SHORT']) { echo 'selected="selected"'; } ?>>
                                <?php echo $row3['COUNTRY_NAME']; ?>
                              </option>
                                <?php } ?>
                              </select>
                              <p class="text-danger"><small>* required.</small></p>
                        </div>

                        <?php 
                          if(isset($_SESSION['CUST_STATE']) && !empty($_SESSION['CUST_STATE'])) {
                            include_once('listed_states.php'); 
                          }
                          else { 
                            echo '<div id="StatesDisplay"></div>';
                          }
                        ?>
  
                        <button type="submit" class="btn btn-primary btn-lg pull-right">Next</button>
                    </form>
 
                </div>
            </div>
        </div>

      <!-- CONTENT ENDS HERE -->
    </div>

<?php include_once('footer.php'); ?>