我已经设置了一个 jquery 完整日历,可以从 mysql 脚本中提取单位。现在我的可用单位每天根据预定的员工/单位变化。因此,每次更改日期时,我都需要更新单位。这可能与全日历有关吗?
我已经尝试过了,但似乎没有用。日历.php
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link href='../lib/fullcalendar.min.css' rel='stylesheet' />
<link href='../lib/fullcalendar.print.min.css' rel='stylesheet' media='print' />
<link href='../scheduler.min.css' rel='stylesheet' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../lib/fullcalendar.min.js'></script>
<script src='../scheduler.min.js'></script>
<script>
$(function() { // document ready
$('#calendar').fullCalendar({
defaultView: 'agendaDay',
editable: true,
selectable: true,
eventLimit: true, // allow "more" link when too many events
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaDay,agendaTwoDay,agendaWeek,month'
},
views: {
agendaTwoDay: {
type: 'agenda',
duration: { days: 2 },
// views that are more than a day will NOT do this behavior by default
// so, we need to explicitly enable it
groupByResource: true
//// uncomment this line to group by day FIRST with resources underneath
//groupByDateAndResource: true
}
},
//// uncomment this line to hide the all-day slot
//allDaySlot: false,
refetchResourcesOnNavigate: true,
resources: function(callback, start, end, timezone) {
$.ajax({
url:"units.php",
type:"POST",
data:{
start: start.format(),
end: end.format(),
timezone: timezone
},
success: function(resourceObjects) //define a variable to capture the JSON from the server
{
callback(resourceObjects); //return the new resource data to the calendar
}
})},
events: 'load.php',
select: function(start, end, allDay)
{
var title = prompt("Enter Event Title");
if(title)
{
var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss");
$.ajax({
url:"insert.php",
type:"POST",
data:{title:title, start:start, end:end},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Added Successfully");
}
})
}
},
editable:true,
eventResize:function(event)
{
var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
var title = event.title;
var id = event.id;
var resourceId = event.resourceId;
$.ajax({
url:"update.php",
type:"POST",
data:{title:title, start:start, end:end, id:id, resourceId:resourceId},
success:function(){
calendar.fullCalendar('refetchEvents');
alert('Event Update');
}
})
},
eventDrop:function(event)
{
var start = $.fullCalendar.formatDate(event.start, "Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(event.end, "Y-MM-DD HH:mm:ss");
var title = event.title;
var id = event.id;
var resourceId = event.resourceId;
$.ajax({
url:"update.php",
type:"POST",
data:{title:title, start:start, end:end, id:id, resourceId:resourceId},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Updated");
}
});
},
eventClick:function(event)
{
if(confirm("Are you sure you want to remove it?"))
{
var id = event.id;
$.ajax({
url:"delete.php",
type:"POST",
data:{id:id},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Event Removed");
}
})
}
},
});
});
</script>
<style>
body {
margin: 0;
padding: 0;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
font-size: 14px;
}
#calendar {
max-width: 99%;
margin: 50px auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
单位.php
<?php
//load.php
$start = $_POST['start'];
$end = $_POST['end'];
$tz = $_POST['timezone'];
$connect = new PDO('mysql:host=localhost;dbname=', '', 'pass');
$data = array();
$query = "select s.*, u.unit_number from schedules s
left join units u on u.id = s.unit where s.start_time like '$start%'";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach ($result as $row) {
/* Get Shift Start and calculate end time
$start = date('G:i', $row['start_time']);
$shift_lentgth = $row[''];
$end= strtotime("+ $shift_lentgth", $start);
*/
// Check unit level to give identifier
$data[] = array(
'id' => $row["id"],
'title' => $row["unit_number"]
);
}
echo json_encode($data);
?>