Scheduler for JavaScript (PHP Tutorial)

A basic tutorial on using JavaScript Scheduler in PHP. Implements drag and drop event moving and creating, extended HTML tooltip.
Jul 2, 2013
scheduler javascript php html5

JavaScript Scheduler Tutorial

Sample PHP Project

This tutorial shows how to use the standalone Scheduler for JavaScript version with PHP.

It includes a sample PHP project:

  • Loading events from the server using JSON 
  • Notifying the server about the changes (event moving, resizing, creating)
  • Displaying an extended HTML tooltip

The sample PHP project is available for download.

Example (Drag and Drop Event Moving)

<script type="text/javascript">
    var dp = new DayPilot.Scheduler("dp");
    // ...
    // http://api.daypilot.org/daypilot-scheduler-oneventmoved/ 
    dp.onEventMoved = function (args) {
        DayPilot.request(
            "backend_move.php", 
            function(req) { // success
                var response = eval("(" + req.responseText + ")");
                if (response && response.result) {
                    dp.message("Moved: " + response.message);
                }
            },
            args,
            function(req) {  // error
                dp.message("Saving failed");
            }
        );        
    };
    // ...
    dp.init();
</script>

backend_move.php

<?php
require_once '_db.php';

$insert = "UPDATE events SET start = :start, end = :end, resource = :resource WHERE id = :id";

$stmt = $db->prepare($insert);

$stmt->bindParam(':start', $start);
$stmt->bindParam(':end', $end);
$stmt->bindParam(':id', $id);
$stmt->bindParam(':resource', $resource);

$received = json_decode(file_get_contents('php://input'));

$id = $received->e->id;
$start = $received->newStart;
$end = $received->newEnd;
$resource = $received->newResource;
$stmt->execute();

class Result {}

$response = new Result();
$response->result = 'OK';
$response->message = 'Update successful';

echo json_encode($response);

?>

DayPilot for JavaScript, ASP.NET WebForms, ASP.NET MVC, Java