Add new Event in the future on sql condition

Hi All, I want to prevent the insertion of new event in the future based on my sql condition.
I have build an select options in lightbox with my sql query list of PERSONS.
My problem is:

When I add a new event in the future and assign to a PERSON I will control and prevent the insertion if the PERSON is unavalaible based on the date select.

Is this possible?

Thank you.

If you are using connectors - you can attach your custom code to beforeProcessing event and block saving if some data do not confirm your requirements.

Hi thank you for your answer.
Can you post a little example ?

Thank you in advance.

Assuming that you are using PHP on server side

function my_validate($action){ if (some_custom_check($action->get_value("start_date")) $action->invalid(); } $scheduler->attachEvent("beforeProcessing", "my_validate");

Thank you.
Yes i use php and mysql.
But this code must add in which file and in which position?
I use connector file called scheduler_connector.php this is the right file?

Thank you very much

need to be added into the file, which you are referencing in scheduler.load command, before render_table command.

Hi Stanislav, I have build this code for prevent the insertion of new Event in the future if the operator is not avalaible .
But don’t work.

function custom_upd_1($action){
        $res = mysql_query("SELECT presence_start,name FROM operators WHERE  name='{$action->get_value('operator')}'"); //get value when I open Lightbox
      $data = mysql_fetch_array($res);
            $presence_start = $data['presence_start'];
            $date_start_event = $action->get_value("start_date"); // get value when I open Lightbox
            if($date_start_event >= $presence_start)
            $action->invalid();

    }
    $scheduler->event->attach("beforeInsert", "custom_upd_1");

There is some error ?

Thank you.

Sondra

Looks correct, except the next line

if($date_start_event >= $presence_start)

$date_start_event is a string ( not sure about presence_start), so you need to use strtotime on it, before comparing

Hi Stanislav.

My function Work fine.

My error was strtotime.
(Stupid error !!!)

Thank you very much.

Sondra

Hi Stanislav.

There is a possibility to send an alert to scheduler when the action is invalid ?

Thank you

Sondra

$action->invalid();
This info already sent to client side. But scheduler has not any custom reaction on it.
You can use

dp.defineAction("invalid", function(xml){ // do something return true; })

Hi Stanislav thank you.

I don’t understand // do something !!

dp.defineAction("invalid", function(xml){
   if(???????????) // do something
   return true;
})

Can you post an example ?

Thank you very much.

Sondra.

This line can be replaced with your custom reaction. What do you want to be done, when some action returns “invalid” status from server side. Scheduler has not any predefined actions for such case - so you need to use a custom code here.

I understand.
Thank you Stanislav.

Sondra