Jquery Fullcalendar Integration Amongst Php In Addition To Mysql

This plugin is to practise a comprehensive interactive calendar that looks similar "Google Calendar". And to perform basic operations on events (display, add, edit) dynamically through AJAX requests, it too allows to easily manipulate the diverse elements via "drag & drop".
fig: Screen dump of output

Step1 : Download the jQuery fullcalendar plugin past times here
You involve to grab the required scripts too css. You tin abide by what y'all involve to become far piece of occupation past times looking at default.html file.
The plugin comes amongst a exhibit files to examination the calendar: the advert of the folder is "Demos". Do non hesitate to explore all the files too accept a await at the source code of each page to sympathise the differences.

Step 2 : Create database called 'fullcalendar' too practise tabular array called 'evenement'
CREATE TABLE `evenement` (   `id` int(11) NOT NULL AUTO_INCREMENT,   `title` varchar(255) COLLATE utf8_bin NOT NULL,   `start` datetime NOT NULL,   `end` datetime DEFAULT NULL,   `url` varchar(255) COLLATE utf8_bin NOT NULL,   `allDay` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT 'false',   PRIMARY KEY (`id`) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=7 ; 
Step 3 : Breakdown of required files
You volition involve next 3 php files to direct maintain an AJAX asking to display, add together too edit the events.
1. events.php - We volition utilisation the code to connect to a MySql database amongst PHP too generate a json string for Fullcalendar.
2. add_events.php - We volition utilisation the code to add together events to the database.
3. update_events.php - We volition utilisation the code to update events to the database.
4. default.html - frontend of the calendar. We volition perform the ajax requests to become far dynamic calendar.
Step 4 : Complete source code
i. events.php
<?php // List of events  $json = array();   // Query that retrieves events  $requete = "SELECT * FROM evenement ORDER BY id";   // connection to the database  try {  $bdd = novel PDO('mysql:host=localhost;dbname=fullcalendar', 'root', 'root');  } catch(Exception $e) {   exit('Unable to connect to database.');  }  // Execute the inquiry  $resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));   // sending the encoded effect to success page  echo json_encode($resultat->fetchAll(PDO::FETCH_ASSOC));  ?> 
ii. add_events.php
// Values received via ajax $title = $_POST['title']; $start = $_POST['start']; $end = $_POST['end']; $url = $_POST['url']; // connection to the database endeavour { $bdd = novel PDO('mysql:host=localhost;dbname=fullcalendar', 'root', 'root'); } catch(Exception $e) { exit('Unable to connect to database.'); }  // insert the records $sql = "INSERT INTO evenement (title, start, end, url) VALUES (:title, :start, :end, :url)"; $q = $bdd->prepare($sql); $q->execute(array(':title'=>$title, ':start'=>$start, ':end'=>$end,  ':url'=>$url)); ?> 
iii. update_events.php
<?php  /* Values received via ajax */ $id = $_POST['id']; $title = $_POST['title']; $start = $_POST['start']; $end = $_POST['end'];  // connection to the database endeavour {  $bdd = novel PDO('mysql:host=localhost;dbname=fullcalendar', 'root', 'root');  } catch(Exception $e) { exit('Unable to connect to database.'); }  // update the records $sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?"; $q = $bdd->prepare($sql); $q->execute(array($title,$start,$end,$id)); ?> 
iv. default.html
<!DOCTYPE html> <html> <head> <link href='css/fullcalendar.css' rel='stylesheet' /> <script src='js/jquery-1.9.1.min.js'></script> <script src='js/jquery-ui-1.10.2.custom.min.js'></script> <script src='js/fullcalendar.min.js'></script> <script>   $(document).ready(function() {   var appointment = novel Date();   var d = date.getDate();   var one thousand = date.getMonth();   var y = date.getFullYear();    var calendar = $('#calendar').fullCalendar({    editable: true,    header: {     left: 'prev,next today',     center: 'title',     right: 'month,agendaWeek,agendaDay'    },        events: "http://localhost:8888/fullcalendar/events.php",        // Convert the allDay from string to boolean    eventRender: function(event, element, view) {     if (event.allDay === 'true') {      event.allDay = true;     } else {      event.allDay = false;     }    },    selectable: true,    selectHelper: true,    select: function(start, end, allDay) {    var championship = prompt('Event Title:');    var url = prompt('Type Event url, if exits:');    if (title) {    var start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");    var end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");    $.ajax({    url: 'http://localhost:8888/fullcalendar/add_events.php',    data: 'title='+ title+'&start='+ maiden off +'&end='+ terminate +'&url='+ url ,    type: "POST",    success: function(json) {    alert('Added Successfully');    }    });    calendar.fullCalendar('renderEvent',    {    title: title,    start: start,    end: end,    allDay: allDay    },    true // brand the trial "stick"    );    }    calendar.fullCalendar('unselect');    },        editable: true,    eventDrop: function(event, delta) {    var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");    var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");    $.ajax({    url: 'http://localhost:8888/fullcalendar/update_events.php',    data: 'title='+ event.title+'&start='+ maiden off +'&end='+ terminate +'&id='+ event.id ,    type: "POST",    success: function(json) {     alert("Updated Successfully");    }    });    },    eventResize: function(event) {    var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");    var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");    $.ajax({     url: 'http://localhost:8888/fullcalendar/update_events.php',     data: 'title='+ event.title+'&start='+ maiden off +'&end='+ terminate +'&id='+ event.id ,     type: "POST",     success: function(json) {      alert("Updated Successfully");     }    });  }       });     });  </script> <style>   body {   margin-top: 40px;   text-align: center;   font-size: 14px;   font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;    }    #calendar {   width: 900px;   margin: 0 auto;   }  </style> </head> <body> <div id='calendar'></div> </body> </html> 
How to add together delete events?
The below code has non been tested past times myself. I cause got copied it from the comment box. Hopefully it works.
 eventClick: function(event) { var conclusion = confirm("Do y'all actually desire to practise that?");  if (decision) { $.ajax({ type: "POST", url: "your url/delete_events.php",  data: "&id=" + event.id }); $('#calendar2').fullCalendar('removeEvents', event.id);  } else { } } 
delete_event.php
 $sql = "DELETE from evenement WHERE id=".$id; $q = $bdd->prepare($sql); $q->execute(); 
Ref: http://jamelbaz.com/tutos/integration-de-fullcalendar-avec-php-mysql, http://arshaw.com/fullcalendar/
Sumber http://developer-paradize.blogspot.com

Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?