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.
Related
I'm using fullcalendar library for calendar view,
<div id="calendar">
<?PHP
include("Calendar.php");
?>
</div>
i managed to connect my fullcalendar to sql db using source code I got from internet which is Calendar.php
$sql = "SELECT id, title, start, end, color FROM tbl_calendar ";
$req = $bdd->prepare($sql);
$req->execute();
$events = $req->fetchAll();
, but how can i auto refresh my calendar?. the following is my code
$('#calendar').fullCalendar({
header: {
left: 'prev,next ',
center: 'title',
right: 'today'
},
editable: true,
eventLimit: true, // allow "more" link when too many events
selectable: true,
selectHelper: true,
select: function(start, end) {
$('#ModalAdd #start').val(moment(start).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd #end').val(moment(end).format('YYYY-MM-DD HH:mm:ss'));
$('#ModalAdd').modal('show');
},
eventRender: function(event, element) {
element.bind('dblclick', function() {
$('#ModalEdit #id').val(event.id);
$('#ModalEdit #title').val(event.title);
$('#ModalEdit #color').val(event.color);
$('#ModalEdit').modal('show');
});
},
eventDrop: function(event, delta, revertFunc) { // si changement de position
edit(event);
},
eventResize: function(event,dayDelta,minuteDelta,revertFunc) { // si changement de longueur
edit(event);
},
events: [
<?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; ?>
]
});
i tried to use several functions such as
`setInterval(function(){
$('#calendar').fullCalendar( 'removeEventSource', "Fetch.php" )
$('#calendar').fullCalendar( 'addEventSource', "Fetch.php" )
$("#calendar").fullCalendar( 'refetchEvents' )
}, 1000);`
but it doesn't refresh calendar but the calendar is keep blinking.
any solutions?
i'm having trouble with fullcalendar. im not sure whether it is my php or mysql code. the calendar displays and i can add a new event but the event does not stick to the calendar. the event data does get inserted into the database but again it does not appear on the actual calendar itself.
here is the code i have so far:
index.php
<!DOCTYPE html>
<html>
<head>
<title>FullCalendar</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel='stylesheet' type='text/css' href='css/style.css' />
<link rel='stylesheet' type='text/css' href='css/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='css/jquery-ui-1.8.11.custom.css' />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="js/jquery-ui-1.8.11.custom.min.js"></script>
<script src='js/fullcalendar.min.js'></script>
<script src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript">
$(document).ready(function() {
/* global variables */
var event_start = $('#event_start');
var event_end = $('#event_end');
var event_type = $('#event_type');
var calendar = $('#calendar');
var form = $('#dialog-form');
var event_id = $('#event_id');
var format = "MM/dd/yyyy HH:mm";
/* button to add events */
$('#add_event_button').button().click(function(){
formOpen('add');
});
/** cleaning function form */
function emptyForm() {
event_start.val("");
event_end.val("");
event_type.val("");
event_id.val("");
}
/* opening form types*/
function formOpen(mode) {
if(mode == 'add') {
/* hide button Delete , Edit and display the Add*/
$('#add').show();
$('#edit').hide();
$("#delete").button("option", "disabled", true);
}
else if(mode == 'edit') {
/* hide the Add button , display the Edit and Delete*/
$('#edit').show();
$('#add').hide();
$("#delete").button("option", "disabled", false);
}
form.dialog('open');
}
/* date time picker */
event_start.datetimepicker({hourGrid: 4, minuteGrid: 10, dateFormat: 'mm/dd/yy'});
event_end.datetimepicker({hourGrid: 4, minuteGrid: 10, dateFormat: 'mm/dd/yy'});
/* initialize full calendar */
calendar.fullCalendar({
firstDay: 1,
height: 500,
editable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
monthNames: ['January','Feburary','March','April','May','June','July','August','September','October','November','December'],
monthNamesShort: ['Jan.','Feb.','Маr','Apr.','May','Jun','Jul','Aug.','Sept.','Oct.','Nov.','Dec.'],
dayNames: ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturdat"],
dayNamesShort: ["Su","Mo","Tu","We","Th","Fr","Sa"],
buttonText: {
prev: " ◄ ",
next: " ► ",
prevYear: " << ",
nextYear: " >> ",
today: "today",
month: "month",
week: "week",
day: "day"
},
/* time format output before the event name*/
timeFormat: 'H:mm',
/* click event handler for a particular day */
dayClick: function(date, allDay, jsEvent, view) {
var newDate = $.fullCalendar.formatDate(date, format);
event_start.val(newDate);
event_end.val(newDate);
formOpen('add');
},
/* handler for event click */
eventClick: function(calEvent, jsEvent, view) {
event_id.val(calEvent.id);
event_type.val(calEvent.title);
event_start.val($.fullCalendar.formatDate(calEvent.start, format));
event_end.val($.fullCalendar.formatDate(calEvent.end, format));
formOpen('edit');
},
/* record source */
eventSources: [{
url: 'ajax.php',
type: 'POST',
data: {
op: 'source'
},
error: function() {
alert('Error connecting to the data source!');
}
}]
});
/* form handler */
form.dialog({
autoOpen: false,
buttons: [{
id: 'add',
text: 'add',
click: function() {
$.ajax({
type: "POST",
url: "ajax.php",
data: {
start: event_start.val(),
end: event_end.val(),
type: event_type.val(),
op: 'add'
},
success: function(id){
calendar.fullCalendar('renderEvent', {
id: id,
title: event_type.val(),
start: event_start.val(),
end: event_end.val(),
allDay: false
});
}
});
emptyForm();
}
},
{ id: 'edit',
text: 'edit',
click: function() {
$.ajax({
type: "POST",
url: "ajax.php",
data: {
id: event_id.val(),
start: event_start.val(),
end: event_end.val(),
type: event_type.val(),
op: 'edit'
},
success: function(id){
calendar.fullCalendar('refetchEvents');
}
});
$(this).dialog('close');
emptyForm();
}
},
{ id: 'cancel',
text: 'cancel',
click: function() {
$(this).dialog('close');
emptyForm();
}
},
{ id: 'delete',
text: 'delete',
click: function() {
$.ajax({
type: "POST",
url: "ajax.php",
data: {
id: event_id.val(),
op: 'delete'
},
success: function(id){
calendar.fullCalendar('removeEvents', id);
}
});
$(this).dialog('close');
emptyForm();
},
disabled: true
}]
});
});
</script>
</head>
<body>
<div id="calendar"></div>
<button id="add_event_button">Add Event</button>
<div id="dialog-form" title="Событие">
<p class="validateTips"></p>
<form>
<p><label for="event_type">type</label>
<input type="text" id="event_type" name="event_type" value=""></p>
<p><label for="event_start">start</label>
<input type="text" name="event_start" id="event_start"/></p>
<p><label for="event_end">end</label>
<input type="text" name="event_end" id="event_end"/></p>
<input type="hidden" name="event_id" id="event_id" value="">
</form>
</div>
</body>
</html>
ajax.php
<?php
$con=mysqli_connect("localhost","root","","fullcalendar");
$start = $_POST['start'];
$end = $_POST['end'];
$type = $_POST['type'];
$op = $_POST['op'];
$id = $_POST['id'];
switch ($op) {
case 'add':
$sql = 'INSERT INTO events (
start,
end,
type)
VALUES
("' . date("Y-m-d H:i:s", strtotime($start)) . '",
"' . date("Y-m-d H:i:s", strtotime($end)) . '",
"' . $type . '")';
if (mysqli_query($GLOBALS["___mysqli_ston"], $sql)) {
echo ((is_null($___mysqli_res = mysqli_insert_id($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
break;
case 'edit':
$sql = 'UPDATE events SET start = "' . date("Y-m-d H:i:s", strtotime($start)) . '",
end = "' . date("Y-m-d H:i:s", strtotime($end)) . '",
type = "' . $type . '"
WHERE id = "' . $id . '"';
if (mysqli_query($GLOBALS["___mysqli_ston"], $sql)) {
echo $id;
}
break;
case 'source':
$sql = 'SELECT * FROM events';
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sql);
$json = Array();
while ($row = mysqli_fetch_assoc($result)) {
$json[] = array(
'id' => $row['id'],
'title' => $row['type'],
'start' => $row['start'],
'end' => $row['end'],
'allDay' => false
);
}
echo json_encode($json);
break;
case 'delete':
$sql = 'DELETE FROM events WHERE id = "' . $id . '"';
if (mysqli_query($GLOBALS["___mysqli_ston"], $sql)) {
echo $id;
}
break;
}
i'd appreciate it if there could be any constructive input or help with this issue.
Hey guys thanks for the help. I had a look at the ajax like charlietfl said and I got a few errors thrown. They were mainly errors about the database connection but seeing as the events are getting inserted to the table it didn't seem correct. I double checked the syntax of the php and mysql and it turns out I was using a few mysql functions that have been depreciated in the newest version of php. It was recommended I changed it to match the PDO or mysqli structure to see if it would work and it did. Thanks for everybody's inputs i really appreciate it.
I have already implemented full calenedar in php. It works fine . I have called the data from database and shown it in the fullcalendar.
Now I have implemented a dropdown. I have used ajax to call controller that calls my another view.
The controller fetches the data based on the dropdown selection. By default it fetches all the data.
But i am not getting the calendar after ajax call. I have called the script to load full calendar in ajax view.
When I echo in the ajax view page, i get the required data. But I am not able to display the full calendar after the ajax call.
As suggested i have give the code.
My first view:
<link rel="stylesheet" href="http://localhost/drive_training/addons/shared_addons/modules/schedule/css/fullcalendar.print.css" rel="stylesheet" media="print" />
<link rel="stylesheet" href="http://localhost/drive_training/addons/shared_addons/modules/schedule/css/fullcalendar.css" rel="stylesheet" />
<div class="content">
<div id='input'>
<?php echo form_dropdown("package_id", $packagelist, "",'id="packageid"'); ?>
</div>
<div id='calendar'></div>
</div>
<style>
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#packageid').change(function() { //any select change on the dropdown with id country trigger this code
var packageid = $('#packageid').val();
alert(packageid);
$.ajax({
type: "POST",
url: "<?php echo base_url('admin/schedule/scheduledetails/hel') ?>", //here we are calling our user controller and get_cities method with the country_id
data: {'packageid': packageid,},
success: function(data)
{
},
error: function() {
alert('failed');
}
});
});
});
</script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
displayEventEnd: {
month: true,
basicWeek: true,
"default": true
},
defaultDate: '2014-11-12',
//editable: true,
eventLimit: true, // allow "more" link when too many events
events:
"<?php echo base_url('admin/schedule/scheduledetails/json');?>",
});
});
</script>
My controller hel function
public function hel()
{
$packageid = 9;//$_POST['packageid'];
// echo "hello";
$coursedetails = $this->course_m->where('course_id',$packageid)->get_all();
// echo "<pre>";print_r($coursedetails); echo "</pre>";
$scheduledetails = array();
foreach ($coursedetails as $details) {
$packagedays = $this->course_m->packagedays($details->id);
$presentdays = $this->attendance_m->count_attendance($details->id);
$startdate = $details->start_date;
$starttime = $details->start_time;
$endtime = $details->end_time;
$postponedays = 0;
//$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $packagedays . ' days'));
$postponedays = $this->postpone_m->count_postponedays($details->id);
if ($postponedays == 0) {
$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $packagedays . ' days'));
} else {
$add = $postponedays + $packagedays;
$enddate = date('Y-m-d', strtotime($details->start_date . ' + ' . $add . ' days'));
$postponefrom = $this->postpone_m->postponedate($details->id)->postponefrom;
$postponeto = $this->postpone_m->postponedate($details->id)->postponeto;
//echo $postponeto;die;
}
$temp = array
(
array
(
'course_id' => $details->id, //it means acutal course id
'title' => $this->training_package_m->get($details->course_id)->training_code, //course_id means packageid
'start' => $startdate . 'T' . $starttime,
'end' => $enddate . 'T' . $endtime,
'description' => 'Hello gyys how are you all',
'starttime' => $starttime,
'endtime' => $endtime,
// 'postponefrom' => $postponefrom,
//'postponeto' => $postponeto,
'postponeddays' => $postponedays,
'packagedays' => $packagedays,
),
);
$scheduledetails = array_merge($scheduledetails, $temp);
}
// echo json_encode($scheduledetails);
$data['jsondata'] = json_encode($scheduledetails);
//print_r($data['jsondata']);die;
$this->template
->title($this->module_details['name'])
->set_layout(false)
->build('admin/fullcalendarfiltered',$data);
}
My view to load through controller. i.e fullcalendarfiltered view file
<style>
#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
<div>Test Ajax</div>
<div id='calendar'></div>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
displayEventEnd: {
month: true,
basicWeek: true,
"default": true
},
defaultDate: '2014-11-22',
//editable: true,
eventLimit: true, // allow "more" link when too many events
events: "<?= $jsondata?>",
});
});
</script>
The view file displays test ajax only. when i echo the json data in view file it is echoed. But the problem is that it wont load in calendar. Infact the calendar is not displayed in fullcalendarfiltered view file
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();
I am grateful in advance of any help I receive on this. I also apologise if my error is obvious. My problem is I can't seem to find an idea on how to display all the elements of my array to populate my events.
for(var i = 0;i < count;i++)
{
// these are the arrays that contain my events
var primaryAsset = primaryAssets[i];
var release_Date = releaseDates[i];
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
weekMode: 'liquid',
weekends: true,
events: [
{
title: primaryAsset,
start: release_Date,
end: release_Date
}
]
});
}
Please create event array first then pass into full calender like
var evt = [
{
title : 'event1',
start : '2014-01-01'
},
{
title : 'event2',
start : '2014-01-05',
end : '2014-01-07'
},
{
title : 'event3',
start : '2014-01-09T12:30:00',
allDay : false
}
];
then add into full calender
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
weekMode: 'liquid',
weekends: true,
events: evt
});
This my script to get json data from php file. thats may works for you.
<script>
$('#calendar').fullCalendar(
{
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events:
{ // Render the events in the calendar
url: 'calendarData.php', // Get the URL of the json feed
error: function()
{
alert('There Was An Error While Fetching Events Or The Events Are Not Found!');
}
}
});
</script>
calendarData.php
$return_array = array();
while ($row = mysql_fetch_array($sth))
{
$event_array = array();
$event_array['id'] = $row['e_id'];
$date_start = $row['e_date_start'];
$date_end = $row['e_date_end'];
$date_start = explode(" ",$date_start);
$date_end = explode(" ", $date_end);
$date_start[0] = str_replace('-' , '/' , trim($date_start[0]));
$date_end[0] = str_replace('-' , '/' , trim($date_end[0]));
//Event Title Structure
if($row['e_title'] != "")
{
$event_array['title'] = $row['e_title'];
//Start Date Structure
if($date_start[0] != "0000/00/00" && $date_start[1] != "00:00:00")
{
$event_array['start'] = date(DATE_ISO8601, strtotime($date_start[0]." ".$date_start[1]));
}
//End Date Structure
if($date_end[0] != "0000/00/00" && $date_end[1] != "00:00:00")
{
$event_array['end'] = date(DATE_ISO8601, strtotime($date_end[0]." ".$date_end[1]));
}
//All Day Event Structure
if($row['e_allday'] == '1')
{
$event_array['allDay'] = true;
}
elseif($row['e_allday'] == '0')
{
$event_array['allDay'] = false;
}
array_push($return_array, $event_array);
}
}
echo json_encode($return_array);
Here are the steps that I took, which worked pretty slick:
1. Load the calendar, using the basic code in fullCalendar documentation:
<script>
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
})
});
</script>
make sure you can actually pull in the data from your array (it doesn't need to be in the calendar yet, just load it onto the page to verify that it works). Something like this should do it: (note, I have not tested this code, but it is close. May need to be tweeked though)
if ( have_posts() ) :
//start a while statement
while ( have_posts() ) :
the_post();
$content_types = get_the_terms( $post_id, $taxonomy_categories );
$tag_link = get_field('tag_link');
$tag_host = parse_url($tag_link);
$tag_page = $tag_host['scheme'] . '://' . $tag_host['host'];
echo the_title();
echo the_field('date');
endwhile;
endif;
add static array, to test if the array elements will be displayed on the calendar. Use code from fullCalendar documentation:
$('#calendar').fullCalendar({
events: [
{
title : 'event1',
start : '2010-01-01'
},
{
title : 'event2',
start : '2010-01-05',
end : '2010-01-07'
},
{
title : 'event3',
start : '2010-01-09T12:30:00',
allDay : false // will make the time show
}
]
});
Finally, once everything to this point is working, replace the static data with dynamic data. You can do this by wrapping it with a loop, and getting the necessary fields through php. Here is the code that I used:
<script>
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
// put your options and callbacks here
events: [
//start if
<?php
if ( have_posts() ) :
//start a while statement
while ( have_posts() ) :
the_post();
$content_types = get_the_terms( $post_id, $taxonomy_categories );
$tag_link = get_field('tag_link');
$tag_host = parse_url($tag_link);
$tag_page = $tag_host['scheme'] . '://' . $tag_host['host'];
?>
{
title : '<?php the_title();?>',
start : '<?php the_field('date');?>'
//only need one item in the array, because with the while loop, this will repeat until all the posts are added.
},
<?php
endwhile;
endif;
?>
]
})
});