Adding custom field in dhtmlx scheduler in PHP

1k views Asked by At

I am new to use dhtmlx scheduler. I want to use shared events with location data also. But i can't able to do, below is my serv

<?php
    require_once('../common/connector/scheduler_connector.php');
    require_once('../common/config.php');

    $user_id = intval($_GET['user']);
    $location_id = 11;
    $scheduler = new schedulerConnector($res, $dbtype);
    function default_values($action){
        global $user_id;

        $event_type = $action->get_value("event_type");
        if ($event_type == "")
            $event_type = 0;

        $action->set_value("userId",$user_id);
            $action->set_value("locationId", $location_id");
    }
    $scheduler->event->attach("beforeProcessing","default_values");

    $scheduler->render_sql("select * from events_shared where userId = ".$user_id,"event_id","start_date,end_date,text,event_type,userId");
?>

$action->set_value("locationId", $location_id"); is the only line I added to the existing sample code, which I got from the official site. I added a column in the events_shared table also.

1

There are 1 answers

0
Paul On

You need to import '$location_id' into 'function default_values' scope using a 'global' keyword:

function default_values($action){
  global $user_id, $location_id;

  $event_type = $action->get_value("event_type");
  if ($event_type == ""){
    $action->set_value("event_type",'0');
  }

  $action->set_value("userId",$user_id);
  $action->set_value("locationId", $location_id);
}

Secondly, you seem to have unclosed quote after $location_id. It should give you a syntax error:

$action->set_value("locationId", $location_id");

If you want to do the filtering by 'userId' column, you can use built-in api for filtering or escape the request before inserting them into sql query. Otherwise your queries are exposed to sql injections. Unsafe implementation:

$scheduler->render_sql("select * from events_shared where userId = ".$user_id,"event_id","start_date,end_date,text,event_type,userId");

Safe implementation:

$scheduler->filter("userId", $user_id);

$scheduler->render_table("events_shared","event_id","start_date,end_date,text,event_type,userId");

This code probably should work:

<?php
require_once('../common/connector/scheduler_connector.php');
require_once('../common/config.php');

$user_id = intval($_GET['user']);
$location_id = 11;
$scheduler = new schedulerConnector($res, $dbtype);
function default_values($action){
  global $user_id, $location_id;

  $event_type = $action->get_value("event_type");
  if ($event_type == ""){
    $action->set_value("event_type",'0');
  }

  $action->set_value("userId",$user_id);
  $action->set_value("locationId", $location_id);
}

$scheduler->event->attach("beforeProcessing","default_values");

$scheduler->filter("userId", $user_id);

$scheduler->render_table("events_shared","event_id","start_date,end_date,text,event_type,userId");