<?php
include_once('common.php');
?>
<?php  
	session_start();
	$Site = $_SESSION['Site'];
	$Password = $_SESSION['Password'];
	$WebserviceAddress = $_SESSION['WebserviceAddress'];
	require_once('lib/nusoap.php');

	$client = new nusoap_client($WebserviceAddress,'wsdl');
	$client ->soap_defencoding = 'UTF-8';
	$param = array('site'=>$Site,'Password'=>$Password,'SenderIP'=>'62.133.6.123');
	$result = $client->call('GetAppointments',$param);
	$appointments = $result['GetAppointmentsResult'];
	if($appointments){
        $slot = explode('|', $appointments);
    }else{
        $slot = array();
    }
    $timeslot = array();
    $cdate = date('d/m/Y',strtotime($_POST['date']));
    if($slot){
        foreach ($slot as $key => $value) {
           if($value!=''){
              $date = explode(' ', $value);
              if(!in_array($date[1], $timeslot) && $date[0]==$cdate){
                 array_push($timeslot, $date[1]);
              }
           }
        }
    }
    $html = '';
    if($timeslot){
	    foreach ($timeslot as $key => $value){
	    	$formattime = date("h:i A", strtotime($value));
	     	$html .= '<div class="col-md-4 text-center">
	        	<ul class="time_select">
	             	<li>
	                 	<input type="radio" '.(($key==0)?'checked':'').' id="radio'.$key.'" name="appointment_time" value="'.$value.'">
	                 	<label for="radio'.$key.'">'.$formattime.'</label>
	             	</li>
	        	</ul>
	     	</div>';
	    }
	}

	echo $html;die;
?>