<?php
include('../config/config.php');
include('../classes/classDoctor.php');
include('../classes/classAppointment.php');
include('../classes/classPatient.php');

if(isset($_GET['doc_id'])&&$_GET['doc_id']!='')
{
	$doctor_id = base64_decode($_GET['doc_id']);
	
	$docOb = new classDoctor;
	$doc_name = $docOb->retrieveDoctorNameByDoctorID($doctor_id);
	
	$calOb = new classAppointment;
	$calOb->setLocationID($_SESSION['security']['location_id']);
	$calOb->setDoctorID($doctor_id);
	$task_array = $calOb->retrieveDoctorAppointments();
}

/*echo '<pre>';
print_r($task_array);
echo '<pre>';
*/
if(isset($task_array[0])&&$task_array[0]!='')
{
	for($cal=0;$cal<count($task_array);$cal++)
	{
		$app_timein = date('h:i a',$task_array[$cal]['app_timein']);
		$app_timeout = date('h:i a',$task_array[$cal]['app_timeout']);
		
		$patOb = new classPatient;
		$title = $app_timein.' - '.$app_timeout.' '.$patOb->retrievePatientNameByPatientID($task_array[$cal]['patient_id']);
                                    
		$calender_array[$cal]['title'] = $title;
		$calender_array[$cal]['start'] = date('Y-m-d',$task_array[$cal]['app_date']);
		//$calender_array[$cal]['end'] = date('Y-m-d',$task_array[$cal]['app_date']);
		$calender_array[$cal]['url'] = '';
	}
}
else
{
	
	$calender_array[0]['title'] = "";
	$calender_array[0]['start'] = "";
	$calender_array[0]['url'] = '';
}

?>

<script>
 var eventarrayofcal = <?php echo @json_encode($calender_array);?>
</script>

<link href='../fullcalendar/fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendar/fullcalendar.print.css' rel='stylesheet' media='print' /> 
<script src="../js/jquery-1.10.2.min.js"></script>
<script src='../fullcalendar/lib/jquery-ui.custom.min.js'></script>
<script src='../fullcalendar/fullcalendar.min.js'></script>

<script>
    $(document).ready(function() {
   
        $('#calendar').fullCalendar({
			
		 header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,basicWeek,basicDay'
			},
			
            editable: false,
			
            events: eventarrayofcal,
			
            eventDrop: function(event, delta) {
                alert(event.title + ' was moved ' + delta + ' days\n' +
                    '(should probably update your database)');
            }
            
        });
        
    });

</script> 

<style>
    #calendar {width: 85%;margin: 0 auto;}
</style>

<table width="100%">
    <tr>
   		<td width="7%"></td>
   	 	<td><h3>Appointments Of : <?php echo $doc_name;?></h3></td>
    </tr>
</table>

<div id='calendar'></div>