Hi,
I have to programmatically set the end date of the events.
To do this, I try to hide the end section in lightbox using this code:
scheduler.attachEvent("onLightbox", function(id){
var ev = scheduler.getEvent(id);
var sections = scheduler.config.lightbox.sections;
for(var i =0; i < sections.length; i++){
if(sections[i].name == "Orario"){
var time = scheduler.formSection("Orario");
var selectors = time.control;
for (var z = 4; z < selectors.length; z++) {
selectors[z].style.display = "none";
}
}
}
});
With “Orario”, that is the “time”
scheduler.config.lightbox.sections = [
{name: "Orario", height: 30, width: 30, type: "time", map_to: "auto"},
//Other fields.....
//.......
];
After, in db connector I create my function to calculate end_date and attach this to event “beforeInsert” and “beforeUpdate”.
As you can see, this function take another field (“tratts”) from the event, and use it to get “timeSum” from a query to another table.
function calcOre($data){
global $calendar;
$tratts = $data->get_value("tratts");
$connSum = mysqli_connect("localhost", "root", "", "test");
$connSum->set_charset("utf8");
$qSum = "SELECT SUM( TIME_TO_SEC( `durata` ) ) AS timeSum FROM trattamenti WHERE id IN (".$tratts.")";
$resSum = mysqli_query($connSum, $qSum);
$durata = 0;
if (!$resSum)
echo mysqli_error($connSum);
while ($row = mysqli_fetch_assoc($resSum)) {
$durata = $row['timeSum'];
}
$inizio = $data->get_value("start_date");
$dtInizio = new DateTime($inizio);
$fine = $dtInizio->add(new DateInterval('PT'.intval($durata).'S'));
$data->set_value("end_date",$fine->format('Y-m-d H:i'));
}
$calendar->event->attach("beforeInsert", "calcOre");
$calendar->event->attach("beforeUpdate", "calcOre");
Everything works, but unfortunately after saving,
the newly created appointment does not display correctly in the calendar and keeps the “end date” with the default value + 5min.
I have to manually reload the page to view the appointment correctly, with the end_date that saved into database.
How can I make this setting correctly?
Maybe there is a way to reload the scheduler without losing the “pagination” (for example if I’m on next month, I don’t want reloading to bring me back to today).
Thanks everyone in advance for your help