Добавление настраиваемого поля в планировщик dhtmlx в PHP

Я новичок в использовании планировщика dhtmlx. Я также хочу использовать общие события с данными о местоположении. Но я не могу, ниже мой серв

<?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"); это единственная строка, которую я добавил в существующий пример кода, который я получил с официального сайта. Я также добавил столбец в таблицу events_shared.


person sincerekamal    schedule 17.03.2014    source источник


Ответы (1)


Вам нужно импортировать '$location_id' в область 'function default_values', используя ключевое слово 'global':

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);
}

Во-вторых, у вас, кажется, есть незакрытая цитата после $location_id. Это должно дать вам синтаксическую ошибку:

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

Если вы хотите выполнить фильтрацию по столбцу «userId», вы можете использовать встроенный API для фильтрации или избежать запроса, прежде чем вставлять их в запрос sql. В противном случае ваши запросы подвергаются SQL-инъекциям. Небезопасная реализация:

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

Безопасная реализация:

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

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

Этот код, вероятно, должен работать:

<?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");
person Paul    schedule 19.03.2014