Fullcalendar Events not displaying before 9 o'clock - php

I'm using the jQuery plugin Fullcalendar so far I was able to display the data stored in my MySQL Database but it is not displaying the right way. What I mean is:
e.g.:
}
"id":"1","title":"Test",
"start":"2015-01-28 10:30:00",
"end":"2015-02-04 12:30:00",
"url":"",
"allDay":"false"
}
This is one record in my Database. It is supposed to display on my calendar
2015-01-28 10:30:00 to 2015-02-04 12:30:00.
But it's not. Instead allDay is true(even if in the database it say false) and I need to add an other day too.
e.g.: If I want to display the dates from 16-03 to 17-03, I need to add an other day -> 16-03 to 18-03 (so that it displays 16-03 to 17-03).
What I mean is when I put a record after 9 o'clock the event "box" or div extends to the right date. Other wise it doesn't extend to the right date.
But by default businessHours are false. (I even added : businessHours: false) but no success.
This is my SELECT query:
<?php
$json = array();
// Query that retrieves events
$querySQL = "SELECT * FROM evenement";
// connection to the database
try {
$bdd = new PDO("mysql:host=localhost;dbname=dbcontrol", "root", "");
} catch(Exception $e) {
exit('Unable to connect to database.');
}
// Execute the query
$result = $bdd->query($querySQL) or die(print_r($bdd->errorInfo()));
// sending the encoded result to success page
echo json_encode($result->fetchAll(PDO::FETCH_ASSOC));
?>
And this is my jQuery:
$(document).ready(function() {
var currentTime = new Date();
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events .fc-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: currentTime,
editable: true,
droppable: true,
eventBackgroundColor: '#A80000',
eventBorderColor: '#A80000',
eventLimit: true, // allow "more" link when too many events
events: {
url: './php/select-events.php',
error: function() {
$('#script-warning').show();
}
},
loading: function(bool) {
$('#loading').toggle(bool);
}
});
});

Problem -> "allDay":"false"
allDay should have a boolean value, not the string "false". Changing it to "allDay":false will make it work.

Related

AJAX data not posting using FullCalendar when trying to update

I have a calendar.php file which looks up "php/get-events" to display calendar events from the database (This currently works as expected). I am trying to use "php/calendarupdate" to then update the database with the new start/end times that have been dragged, but the data posting to this page always comes back as undefined, so it's not finding it for some reason.
"Calendar.php"
<script>
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
initialDate: '2021-03-18',
editable: true,
eventDrop: function(event, delta) {
start=moment(event.start).format('Y-MM-DD HH:mm:ss');
end=moment(event.end).format('Y-MM-DD HH:mm:ss');
$.ajax({
url: 'php/calendarupdate.php',
data: 'title=' + event.title + '&start='+ event.start +'&end=' + event.end + '&id=' + event.id ,
type: "POST",
success: function(json) {
alert("Updated Successfully");
}
});
},
navLinks: true, // can click day/week names to navigate views
dayMaxEvents: true, // allow "more" link when too many events
events: {
url: '/php/get-events.php',
failure: function() {
document.getElementById('script-warning').style.display = 'block'
}
},
loading: function(bool) {
document.getElementById('loading').style.display =
bool ? 'block' : 'none';
}
});
calendar.render();
});
</script>
The following is where I get the data which successfully displays events on the calendar.
"php/get-events.php"
$stmt = $pdo->prepare("Select id,task_name,start,end,notes,task_type,status from tasks where attendees like ".$attendees);
$stmt->execute();
//$stmt->debugDumpParams();
foreach ($stmt as $row){
$rawdata[] = array('id' => $row['id'], 'title'=> $row['task_name'], 'start'=> $row['start'], 'end'=> $row['end']);
}
$rawdata = json_encode($rawdata);
echo $rawdata;
The following is the update file, which it is getting into ok, but the echo's I try to display are all undefined.
/* Values received via ajax */
echo "id -".$_POST['id'];
echo "start -".$_POST['start'];
echo "end -".$_POST['end'];
// update the records
$stmt = $pdo->prepare('UPDATE tasks SET start=?, end=? WHERE id=?');
$stmt->execute($_POST['start'], $_POST['end'], $_POST['id']);
$stmt->debugDumpParams();
It may be something simple, but from the documentation I've read, I can't seem to figure out why my variables are not posting successfully. Thanks.
You have the wrong syntax for your eventDrop signature. See https://fullcalendar.io/docs/eventDrop
It should be
eventDrop: function(info) {
And then replace
event.start
and
event.end
with
info.event.start
and
info.event.end
This will get the information you need correctly from the data which fullCalendar supplies.

jQuery FullCalendar doesn't show events issue in FireFox 33.0

I'm trying to set up jQuery FullCalendar by providing data as json feed trough fullcalendar events function. So basically this is my js code:
var calendar = $('#calendar').fullCalendar({
editable: true,
firstDay: 1,
header: {
left: 'prev, next today',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
events:
{
url: 'events.php',
type: 'POST',
cache: false,
error: function() {
alert('ERROR');
},
color: 'blue'
}
});
And my code from events.php which pulls data from database and makes as JSON feed + converting date to ISO8601 date strings as sayd in documentation.
// Query that retrieves events
$q = "SELECT * FROM evenement ORDER by id";
$r = mysqli_query($dbc, $q);
while ($row = mysqli_fetch_assoc($r))
{
$s = new DateTime($row['start']);
$e = new DateTime($row['end']);
$row['start'] = $s->format(DATE_ISO8601);
$row['end'] = $e->format(DATE_ISO8601);
$json[] = $row;
}
echo json_encode($json);
In IE11 and Chrome it shows all the events in calendar what are made in DB, but in FireFox the calendar is empty.. And returned response JSON string is:
[
{"id":"7","title":"Rino","start":"2014-10-22T11:55:46+0300","end":"2014-10-22T11:55:46+0300","url":"nav","allDay":"false"},
{"id":"8","title":"Rin","start":"2014-10-22T13:01:45+0300","end":"2014-10-22T13:01:45+0300","url":"Hello","allDay":"false"},
{"id":"9","title":"Rino","start":"2014-10-23T10:06:22+0300","end":"2014-10-23T10:06:22+0300","url":"Hello","allDay":"false"},
{"id":"10","title":"a","start":"2014-10-23T09:42:04+0300","end":"2014-10-23T09:42:04+0300","url":"a","allDay":"false"},
{"id":"11","title":"1","start":"2014-10-23T09:41:55+0300","end":"2014-10-23T09:41:55+0300","url":"1","allDay":"false"},
{"id":"12","title":"sdas","start":"2014-10-23T10:06:14+0300","end":"2014-10-23T10:06:14+0300","url":"1","allDay":"false"},
{"id":"13","title":"Prju","start":"2014-10-16T00:00:00+0300","end":"2014-10-17T00:00:00+0300","url":"undefined","allDay":"false"}
]
What am I missing, why in the Firefox it doesn't show any event? I have also tried clearing cache etc.. but without any results..

Mark date as booked in fullcalendar

I'm using http://arshaw.com/fullcalendar/ to display a full calendar to show events from a DB via json. I need to mark a date as booked by changing the color of the calender cell.
So im guessing I need something like
If (date == booked){
$(element).css("backgroundColor", "red");
}
Here is the code for populating the calendar.
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: false,
events: {
url: '{{URL::to('/json')}}',
type: 'GET',
},
'': 'h(:mm)t' ,// uppercase H for 24-hour clock
loading: function(bool) {
if (bool) $('#loading').show();
else $('#loading').hide();
}
});
});
Here is my json object
public function json()
{
$bookings = Booking::all();
//dd($bookings);
foreach ($bookings as $b)
$data[] = ['title'=>$b->status,
'start'=> $b->event_date .' ' .$b->start_time,
'end'=>$b->event_date .' ' .$b->end_time,
'description'=>'',
'color'=>'',
'status'=>$b->status,
'backgroundColor' => ($b->status ==='confirmed'?'#FFC0CB' : '#FFA500'),
'slotMinutes'=>'10',
'allDay'=>false];
//return $bookings;
return $data;
}
Ideally I'd like to send an array of dates I need to mark as booked.
If someone can nudge me in the correct direction I'd really appriciated it.
Thanks
this is how I solved it.
eventRender: function (event, element, monthView) {
if (event.title == "booked") {
var date = $.fullCalendar.formatDate( event.start , 'yyyy-MM-dd' );//event.start;
$('.fc-day[data-date="' + date + '"]').addClass('booked');
}
},

EXTJS 4: Editable grid doesn't commit changes to MySQL Database

Dear fellow EXT enthusiasts,
I'm working on a project where I need an admin panel to edit job functions.
The grid is communicating to a MySQL database using Ext.Direct. It loads the data fine.
The grid shows the id and the function name
I added a RowEditing plugin to my grid for editting the function settings.
The problem is, when I try to commit the changes I get a tiny red triangle in the upper left corner of the grid without any error code in the console. The changes don't commit to the MySQL database.
The way my program works and loads the data:
This is my functionStore:
Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
Ext.define("MCS.store.FunctionStore",
{
extend: "Ext.data.Store",
requires: "MCS.model.Functions",
model: "MCS.model.Functions",
id: "FunctionStore",
proxy:
{
type: "direct",
api:
{
read: QueryDatabase.getFunctions,
create: QueryDatabase.createFunction,
update: QueryDatabase.updateFunction,
destroy: QueryDatabase.removeFunction,
}
},
});
In the controller: when the admin panel is rendered, the store gets loaded with the following function:
loadStore: function()
{
functionStore.load();
}
This is the grid where the functions are displayed:
var rowEditingFunctions = Ext.create("Ext.grid.plugin.RowEditing",
{
clicksToMoveEditor: 1,
autoCancel: false,
listeners: {
edit: function(editor,e,opt)
{
var grid = e.grid;
var record = e.record;
console.log(record.data.functionName);
var editedrecords = grid.getStore().getUpdatedRecords();
console.log(editedrecords);
}
}
});
var functionGrid = Ext.create("Ext.grid.Panel",
{
height: 500,
width: 800,
store: functionStore,
title:"List of Job Functions - double click to edit",
columns: [
{
dataIndex: "id",
width: 50,
text: "ID"
},{
dataIndex: "functionName",
flex: 1,
text: "Function",
field:
{
type: "textfield",
allowBlank: false
}
}],
plugins: [
rowEditingFunctions
],
dockedItems: [
{
xtype: "toolbar",
store: functionStore,
dock: "bottom",
items: [
{
iconCls: "add",
text: "Add",
handler: function()
{
rowEditingFunctions.cancelEdit();
var newRecord = Ext.create("App.model.Functions");
functionStore.insert(0, newRecord);
rowEditingFunctions.startEdit(0, 0);
var sm = functionGrid.getSelectionModel();
functionGrid.on("edit", function() {
var record = sm.getSelection()
functionStore.sync();
functionStore.remove(record);
functionStore.load();
});
}
}, {
iconCls: "delete",
text: "Delete",
handler: function()
{
rowEditingFunctions.cancelEdit();
var sm = functionGrid.getSelectionModel();
Ext.Msg.show(
{
title:"Delete Record?",
msg: "You are deleting a function permanently, this cannot be undone. Proceed?",
buttons: Ext.Msg.YESNO,
icon: Ext.Msg.QUESTION,
fn: function(btn)
{
if(btn === "yes")
{
functionStore.remove(sm.getSelection());
functionStore.sync();
}
}
});
}
}]
}]
});
As u can see I added a listener to the edit event of the RowEditing plugin, this displays the array of the edited record in console like it should.
4. And finally, this is the PHP code that updates the database:
public function updateFunction(stdClass $params)
{
$db = $this->__construct();
if ($stmt = $db->prepare("UPDATE functions SET functionName=? WHERE id=?"))
{
$stmt->bind_param('si', $functionName, $id);
$functionName = $params->functionName;
$id = (int) $params->id;
$stmt->execute();
$stmt->close();
}
return $this;
}
5. The weird part: once I've added one job function, I can edit all the other functions and those changes are committed to the database...
As a side note: I'm just a beginner in EXT, trying to learn it on my own, but I have been breaking my head on this issue for the last few days so I decided to ask you guys.
Thanks for your answers in advance!
I left the bug for what it was for a few weeks and started to look into it again this week.
I found a work around solution.
I've added the following code to my controller that controls the grids:
functionGrid.on('edit', function(editor, e)
{
e.store.sync();
});
Now when I update a record, the tiny red triangle still appears but after the e.store.sync() function is completed it disappears and the database table is updated.
Not a 100% clean solution, but it does the trick
If anyone has a better solution, please let me know

Called PHP script using EXTJS alert message box

I am currently trying to call the PHP script upon clicking OK button on EXTJS message alert box.
For some reason it doesn't even display the Alert box when I use handler. However when I used Listener it displays the Alert box but doesn't call the php script upon clicking OK button. I read on different blogs and come to know Handler is the best way to go forward
I will appreciate if somebody can help me or point me to the right direction. I am using the latest release of EXTJS4
Below is the EXTJS tree panel code I've written using handler;
var treePanel = Ext.create('Ext.tree.Panel', {
id: 'tree-panel',
title: 'Available Database',
region: 'north',
split: true,
height: 360,
minSize: 150,
rootVisible: false,
autoScroll: true,
store: store,
handler: function() {
if (treePanel.getSelectionModel().hasSelection()) {
var selValue = treePanel.getSelectionModel().getSelection();
Ext.MessageBox.alert('Press OK to confirm your subscription <br>' + selValue[0].data.text,
function(btn, text) {
if (btn == 'ok') {
Ext.Ajax.request({
url: 'addSubscription.php',
params: {
nodetext: text,
parentid: selectedNode[0].data.id
},
success: function(response) {
var id = response.responseText;
grid.getView().refresh();
}
})
} else {
Ext.MessageBox.alert('Record already subscribed');
}
});
}
}
});
Ext.tree.Panel have not 'handler' property in config.
Handler is a function that is executed when you click on some of the components - such as buttons.
You can add button on your treePanel toolbar, and use button handler:
...
tbar: [{
xtype: 'button',
text: 'Subscribe',
handler: function(button) {
...
}
}],
...
See on jsfiddle: http://jsfiddle.net/FFvLa/
but doesn't call the php script upon clicking OK button.
The function must be passed as the third argument in Ext.Msg.alert:
http://jsfiddle.net/FFvLa/2/

Categories