0

I have a following problem: I have a scheduler that is used by different users. When a user adds an event to scheduler, a session variable containing his id must be passed to a processor where it is inserted into a database.

My first question is how do I bind a session variable to a form that is created with a scheduler.config.lightbox.sections:

  scheduler.config.lightbox.sections=[
        {name:"Customer Code", height:21, map_to:"text", type:"textarea" , focus:false},
    {name:"Photographer", height:21,  map_to:"pid", type:"select",
      options:scheduler.serverList("type")},
        {name:"time", height:72, type:"time", map_to:"auto"}
    ]

Is it possible to bind a session variable to it?

My second question is how do I get session variable in processor.php? Please, correct me if I'm wrong, but according to the documentation it's going to be something like this:

//... connect here
function myInsert($action){
        $new_value = rand(0,100);
        $action->set_value("name",$new_value);
}

$conn->event->attach("beforeInsert","myInsert");
// ...some code here
$conn->render_table("photographers_at_work", "id", "time, end_time, customer_code, pid"); 
Le garcon
  • 7,197
  • 9
  • 31
  • 46

1 Answers1

0

You can use onEventCreated to assign default values (such as user id) to a newly created event:

scheduler.attachEvent("onEventCreated", function(id,e){
    var event = scheduler.getEvent(id);
    event.pid = userId;
});

https://docs.dhtmlx.com/scheduler/api__scheduler_oneventcreated_event.html

This API event fires before lightbox is opened, so the lightbox will receive assigned values.

As for backend - yes, something like this should work. Couple of notes

  1. $action->set_value - the first parameter is a column name
  2. this column must be listed in properties columns you provide to connector (i.e. if you set value of column you don't have in your render_table parameters - connector will ignore it)

So something following should do:

//... connect here
function myInsert($action){
        global $userId;
        $action->set_value("pid",$userId);// ! set value of "pid" column
}

$conn->event->attach("beforeInsert","myInsert");
// ...some code here
$conn->render_table("photographers_at_work", "id", "time, end_time, customer_code, pid");

you can enable connector logging to see actual sql requests connector generates: https://docs.dhtmlx.com/connector__php__errors.html#serversidelogging

Alex Klimenkov
  • 956
  • 1
  • 5
  • 8