<?php
include_once('common.php');
?>
<?php
include_once('my-optician-wsdl-service/MyOpticianWsdlService.php');
include_once('my-optician-wsdl-service/AppointmentDetails.php');
$service_url = "http://87.127.13.154:899/DiaryWebService.svc?wsdl";
$site_id = "";
$password = "OpenGate7";
$optician_id="1502";
$wsdlClient = new MyOpticianWsdlService($service_url, $optician_id);
$site_info = $wsdlClient->getSiteInfo($optician_id, $password);
$appointment_types = $wsdlClient->getAppointmentTypes($site_info->getSite(), $site_info->getPassword());
$shops = $wsdlClient->getShops($site_info->getSite(), $site_info->getPassword());
$practitioners=null;
if(count($shops) > 0)
    $practitioners = $wsdlClient->getPractitioners($site_info->getSite(), $site_info->getPassword(), $shops[0]->getName());

echo "<pre>";
echo "\nOutput -- Start\n";
echo "Site Info: "; print_r($site_info);
echo "\n";
echo "Appointment Types: "; print_r($appointment_types);
echo "\n";
echo "Shops Info: "; print_r($shops);
echo "\n";
echo "Practitioners Info: "; print_r($practitioners);
$first_practitioner = null;
$first_appointment = null;
foreach($practitioners AS $practitioner){
    $appointment_list = $wsdlClient->getAppointments($site_info->getSite(), $site_info->getPassword(),
        $shops[0]->getName(), $practitioner->getName());
    echo "\nAppointments of ". $practitioner->getName().":";
    echo "\n\t"; print_r($appointment_list);
    echo "\n";
    $first_practitioner = $practitioner;
    $first_appointment = $appointment_list[0];
    break;
}
echo "\n==============";
echo "\n\tBooking with following details:";
echo "\n\tSite: ". $site_info->getSite();
echo "\n\tShop: ". $shops[0]->getName();
echo "\n\tPractitioner: ".$first_practitioner->getName();
echo "\n\tAppointment: ".$first_appointment->getSlotStr();

$sampleAppointment = new AppointmentDetails();

// Set sample data using setter methods
$sampleAppointment->setName('John Doe');
$sampleAppointment->setExisting('True');
$sampleAppointment->setPostcode('12345');
$sampleAppointment->setDob('1990-01-01');
$sampleAppointment->setPhone('555-1234');
$sampleAppointment->setEmail('john.doe@example.com');
$sampleAppointment->setAppointmentType($appointment_types[0]->getName());
$sampleAppointment->setComments('Sample comments');
$sampleAppointment->setPractitioner($first_practitioner->getName());
echo "\n\Person Details: ".print_r($sampleAppointment, true);


$result = $wsdlClient->postNewAppointment($site_info->getSite(), 
    $appointment_list[0]->getSlotStr(), $sampleAppointment, $shops[0]->getName());

echo "\n\tResult of booking new appointment: ". print_r($result, true);

echo "\nOutput -- End\n";
echo "</pre>";
?>