FullCalendar using Database and Google Calendar - php

It is possible to display both custom event coming from the database and Google Calendar using FullCalendar? I've done to display my custom event from database and I want to display also the holidays in my country using Google Calendar. My question is, it is possible to do that in FullCalendar? Here's my code:
googleCalendarApiKey: 'AIzaSyBTYvbg3gKLNi0A8qOXMyk6q-EnzM6DZq4',
events: [ googleCalendarId:'en.philippines#holiday#group.v.calendar.google.com',
<?php foreach($events as $event):
$start = explode(" ", $event['start']);
$end = explode(" ", $event['end']);
if($start[1] == '00:00:00'){
$start = $start[0];
}else{
$start = $event['start'];
}
if($end[1] == '00:00:00'){
$end = $end[0];
}else{
$end = $event['end'];
}
?>
{
id: '<?php echo $event['id']; ?>',
title: '<?php echo $event['title']; ?>',
start: '<?php echo $start; ?>',
end: '<?php echo $end; ?>',
color: '<?php echo $event['color']; ?>',
},
<?php endforeach; ?>

events: [ googleCalendarId:'en.philippines#holiday#group.v.calendar.google.com'...JS arrays can't contain named items...not sure this will even compile in the browser. Are you getting a console error, by any chance? Even if this was valid JS, you can't specify a google calendar as one item of your events array, fullCalendar is expecting "events" to be either a URL or an array of objects, not a combination. If you want to combine data from your database with data from an external source e.g. google calendar, then what you're probably looking for is "event sources" (see https://fullcalendar.io/docs/eventSources)
This way you can give fullCalendar a list of different ways to get events. The first entry can be the data generated by your PHP code, and the second can be your Google Calendar details, which tell it to go away and download the events from Google Calendar:
Remove your events: option from the code and instead specify:
eventSources: [
//first event source:
[
<?php foreach($events as $event):
$start = explode(" ", $event['start']);
$end = explode(" ", $event['end']);
if($start[1] == '00:00:00'){
$start = $start[0];
}else{
$start = $event['start'];
}
if($end[1] == '00:00:00'){
$end = $end[0];
}else{
$end = $event['end'];
}
?>
{
id: '<?php echo $event['id']; ?>',
title: '<?php echo $event['title']; ?>',
start: '<?php echo $start; ?>',
end: '<?php echo $end; ?>',
color: '<?php echo $event['color']; ?>',
},
<?php endforeach; ?>
],
//second event source:
{
googleCalendarId:'en.philippines#holiday#group.v.calendar.google.com'
}
]
N.B. If you want to incorporate Google Calendar events, make sure you've also followed al the steps outlined at https://fullcalendar.io/docs/google-calendar

You should be able to do that with addEventSource:
$('#myCal').fullCalendar( ‘addEventSource’, source );
where
Source may be an Array/URL/Function just as in the events option.
Events will be immediately fetched from this source and placed on the
calendar.
So, source could be either the Google url or an array with your events.

Use:
eventSources: [{googleCalendarId: 'xxxxxxxxx#gmail.com', className: 'gcal-event'},{url:'events.php',}],

Related

Product management System Tracking with Google Tag Manager

I am working on Product Management system site in which on the enquiry of a product i fill a contact us form which has the info of that product as follows
as soon as the form is submitted it leads me on the thank you page where I have added the following code in order to track it using GTM
<?php
$enquiry_id = "";
$enquiry_id = $this->session->userdata('enq_id');
$product_data = "";
$product_data = $this->session->userdata('enq');
echo "<!--<pre>";
print_r($product_data);
echo "<pre>-->";
if (!empty($product_data) && !empty($enquiry_id) && isset($product_data)){
?>
<script>
<?php
foreach($product_data as $value){
?>
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': '<?php echo $enquiry_id?>' // Transaction ID.
},
'products': [{
'name': '<?php echo $value ?>',
'id': '<?php echo $enquiry_id?>',
'price': '0.0',
'quantity': 1
}]
}
}
});
<?php } ?>
</script>
<?php
$this->session->unset_userdata('enq_id');
$this->session->unset_userdata('enq');
}
?>
<script>
Now the thing is I am able to get the values in the GTM debugger as well as i can see them in view source but the values dont show up in Google Analytics , So is there any other way to get the values in the Conversion->Ecommerce section of GA.I have set the track type as Transaction in GTM.
Thanking you in advance

Database query with fullcalendar

OK I'm trying to pull events from a MySQL database to populate a calendar. The start times are stored in Unix time so I have used the following events source.
events: {
url: '/php/booking_events.php',
type: 'POST',
data: {
start: start.unix(),
end: end.unix(),
branch: branch.id_office,
instrument: inst
},
error: function() {
alert('there was an error while fetching events!');
},
}
This brings up the first problem, when I run this I get an error in dev tools saying start is not defined? Doesn't the calendar automatically generate the start and end times?
Secondly, if I manually enter parameters into my PHP it generates a JSON array then echoes it back but the script is constantly saying 'there was an error while fetching events!'
<?php
require_once('../Connections/localhost.php');
require_once("../Includes/functions.php");
//if (!isset($_POST['start']) || !isset($_POST['end'])) {
// die("Please provide a date range.");
//}
//$range_start = parseDateTime($_POST['start']);
//$range_end = parseDateTime($_POST['end']);
//$branch = GetSQLValueString($_POST['id_office'], "int");
//$inst = GetSQLValueString($_POST['instrument'], "int");
$range_start = '1433462401';
$range_end = '1433721599';
$branch = 2;
$inst = 3;
// Parse the timezone parameter if it is present.
$timezone = null;
if (isset($_POST['timezone'])) {
$timezone = new DateTimeZone($_POST['timezone']);
}
// Query database to get events
mysql_select_db($database_localhost, $localhost);
$query_Events = sprintf("SELECT hm_classes.datetime, hm_classes.id_student, hm_classes.inst FROM hm_classes INNER join hm_rooms ON hm_classes.id_room = hm_rooms.id_room WHERE datetime BETWEEN %s AND %s AND id_office = %s AND inst = %s", $range_start, $range_end, $branch, $inst);
$Events = mysql_query($query_Events, $localhost) or die(mysql_error());
while ($row = mysql_fetch_assoc($Events)){
$id = $row['id_class'];
$title = 'Booking';
$start = date('c', $row['datetime']);
$end = date('c', ($row['datetime'] + hoursToSecods($row['Session'])));
$input_arrays[]= array(id => $id, title => $title, start => $start, end => $end, allDay =>'false');
}
// Send JSON to the client.
echo json_encode($input_arrays);
?>
The echoed result of this is
[{"id":"1","title":"Booking","start":"2015-06-05T14:00:00+02:00","end":"2015-06-05T15:00:00+02:00","allDay":"false"}]
which is what I think fullcalendar is after? Any help would be greatly appreciated.
OK I think I have solved this problem, following kamlesh.bar's suggestion I went to look at http://www.jqueryajaxphp.com/fullcalendar-crud-with-jquery-and-php/.
After looking through his code I separated my AJAX request out from the main fullcalendar script and gave it it's own function.
function getEvents(){
$.ajax({
url: 'booking_events.php',
type: 'POST', // Send post data
data: {type: 'fetch',
branch: $('#branch').val(),
inst: $('#instrument').val()},
async: false,
success: function(s){
json_events = s;
}
})
}
Then in fullcalendar I set the events as
events: JSON.parse(json_events),
This is now allowing the results generated by the php to be entered into the calendar.
As for that start: stat.unix() issue, I am just using strtotime in php to change that to a Unix timeformat

Change jquery full calendar prompt input box to dropdown list

I am implementing jquery full calendar in my PHP website. when i am clicking on any date of calendar it is giving me a prompt. There is a input field asking for event title. I want to change this input field and want a drop down list in place of input field. Is it possible? This is the calendar that i am using http://fullcalendar.io/
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '<?php echo date("Y-m-d"); ?>',
selectable: true,
selectHelper: true,
select: function(start, end) {
var title = prompt('Please fill schedule title & add fees');
var eventData;
if (title) {
eventData = {
title: title,
url: 'javascript:fee_add("' + title + '","' + start +'");',
start: start,
end: end
};
$('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
<?php
if($mysql->rowCount($query) > 0)
{
$rows = $mysql->fetchArray($query);
foreach($rows as $row)
{
if($row['date_time'] !='0000-00-00 00:00:00')
{
$date1 = date_create_from_format('Y-m-d H:i:s', $row['date_time']);
$date = date('Y-m-d', $date1->getTimestamp());
$time = date('H:i', $date1->getTimestamp());
$time_hr = date('H:i:s', $date1->getTimestamp());
}
?>
{
title: '<?php echo $row["fee_title"]; ?>',
url: 'javascript:fee_edit(<?php echo $row["id"]; ?>,"<?php echo $row["fee_title"]; ?>","<?php echo $date . " " . $time_hr; ?>");',
start: '<?php echo $date; ?>T<?php echo $time ?>'
},
<?php
}
}
?>
]
});
});
</script>
</div>
<div id='calendar'></div>
This is the code i am implementing and just want dropdown list in place of title
Thanx in advance
Prompt is a built is js component. You shouldn't attempt to override it. Try using a custom dialog/modal. jQuery UI has a great dialog component that would allow you to utilize a select element or any other html you see fit.

how to dynamically add data for events to fullCalendar?

My problem is about events for calendar, precisely speaking i dont know how to dynamically add data for events here is my code in view file
<div>
<?php $message = Message::model()->findAll(); ?>
<?php foreach($message as $messag): ?>
<?php $names[] = $messag['contacts']; ?>
<?php $date[] = $messag['send_datetime']; ?>
<?php endforeach; ?>
</div>
<script>
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: [
{
title: '<?php echo $names[0]; ?>',
start: '<?php echo $date[0]; ?>',
url: 'view/1'
},
{
title: '<?php echo $names[1]; ?>',
start: '<?php echo $date[1]; ?>',
url: 'view/2'
},
{
title: '<?php echo $names[2]; ?>',
start: '<?php echo $date[2]; ?>',
url: 'view/3'
},
{
title: '<?php echo $names[3]; ?>',
start: '<?php echo $date[3]; ?>',
url: 'view/4'
},
]
})
$('#calendar').fullCalendar('changeView', 'agendaWeek');
});
</script>
<div id='calendar'>
</div>
i dont know how to code it in such a way that it will add as many events as i have data in database. i would be very grateful if someone could help
I would load the events by ajax. You basically have two parts. The one file with datatable/javascript and the other file is the data source. It is a php file that gets all the data from database and outputs the events in json format.
to get the events from a the file use fullCalendar like this (simplified version):
$('#calendar').fullCalendar({
events: {url: 'myevents.php'}});
and in your myevents.php you make the usual database requests and out put your data like this:
<?php
//Do the Database stuff here...
//Here is a sample data for two events:
$events = array();
$agenda['allDay'] = true;
$agenda['start'] = '2014-08-25 12:00:00';
$agenda['end'] = '2014-08-30 12:00:00';
$agenda['title'] = "Hello World";
$agenda['id']= "1";
$events[] = $agenda;
$agenda['allDay'] = false;
$agenda['start'] = '2014-08-27 12:00:00';
$agenda['end'] = '2014-08-27 16:30:00';
$agenda['title'] = "Blah";
$agenda['id']= "2";
$events[] = $agenda;
echo json_encode($events);
exit();

Highchards - data loading from dbase

I'm looking for a help with loading data from dbase into Higtcharts.
The Highcharts data loading entrance looks like:
<script type="text/javascript">
jQuery(function() {
// Create the chart
window.chart = new Highcharts.StockChart({
chart: {
renderTo: 'container'
},
rangeSelector: {
selected: 1
},
title: {
text: 'USD to EUR exchange rate'
},
xAxis: {
maxZoom: 14 * 24 * 3600000 // fourteen days
},
yAxis: {
title: {
text: 'Exchange rate'
}
},
series: [{
name: 'USD to EUR',
data: usdeur
}]
});
});
</script>
and usdeur is loading as in scheme (example from external csv file):
var usdeur = [
[Date.UTC(2011,1,3),0.7488],
[Date.UTC(2011,2,6),0.6983],
[Date.UTC(2011,3,8),0.6961],
[Date.UTC(2011,4,9),0.6945]
];
from dbase SELECT I have:
$data_date = array();
$data_data = array();
foreach($STH as $row)
{
$date1 = $row['date'];
$date2 = explode("-", $date1);
$date3 = $date2[0].",".$date2[1].",".$date2[2];
$data_date[] = $date3; // date in scheme 2011,1,3
$data_data[] = $row['index_p_actual']; // data like 0.7488
}
info about date - $date_date[]
info about corelated data - $data_data[]
I want to load data online, not via any external file like csv.
And my question is - how to join $data_date and $data_data into one data pocket to receive completly virtual list like
[Date.UTC(2011,1,3),0.7488],
[Date.UTC(2011,2,6),0.6983],
[Date.UTC(2011,3,8),0.6961],
[Date.UTC(2011,4,9),0.6945]
The suggestion from highcharts is to use:
series: [{
data: [<?php echo join($data, ',') ?>]
}]
but I have $data & $date - how to join it? With php join I can use only one variable[] ...
Hmmm, or maybe another better way?
If I understood you well, I think you want to do this:
$data_date = array();
$data_data = array();
foreach($STH as $row)
{
$date1 = $row['date'];
$date2 = explode("-", $date1);
$date3 = $date2[0].",".$date2[1].",".$date2[2];
$data_date[] = $date3; // date in scheme 2011,1,3
$data_data[] = $row['index_p_actual']; // data like 0.7488
$data_highcharts[] = [$date3,$row['index_p_actual']]
}
And then you send the $data_highcharts[] to your JavaScript which will have the format:
[[date1,data1],[date2,data2],...]

Categories