dhtmlX max events

Hi,

I would like users to not add more than 30 events in the calendar.
To do so, I have been using the “beforeInsert” in the connector:

$conn->event->attach(“beforeInsert”,“checkCounter”);

So my checkCounter is something like:

function checkCounter($action){
        
        $user_id = api_get_user_id();
        $sql = "SELECT COUNT(*) as counter FROM events WHERE event_advisor_id = '".$user_id."'". " AND YEAR(event_startdate) = YEAR( NOW( ) )";
        $result = mysql_query($sql);
        $row = mysql_fetch_assoc($result);
        if(intval(0 + $row["counter"]) >= 30){
            $action->set_value("event_text","You have already 30 dates booked");
            $action->invalid();
        } else {
            $action->set_value("event_advisor_id",api_get_user_id());
        }    
        
}

This works because only the 30 dates are saved but:

  1. The event is displayed in bold (like something unsaved)
  2. the event text is not set to “You have already 30 dates booked”
  3. I have nothing that warns the user about the fact he is over the limit

So, I would like to know:

  1. How to set the event text from a beforeInsert event
  2. How to create a popup with a warning message from the PHP script
  3. Or any way to solve this problem