$event[] = array("title" => $title, "start" => date('Y-m-d 02:00:00', strtotime($timestart)), "end" => date('Y-m-d 02:00:00', strtotime($timeend)), "description" => $desc, "color" => $color, "icon" => $icon, "external" => "0");
                    $calendar_end = $timeend;
                }
            }
        }
    }
    // Insert in calendar new events
    if (calendar\insert_calendar($event, $main_error)) {
        if (isset($sd_card) && !empty($sd_card)) {
            // Create calendar from database
            $calendar = array();
            calendar\read_event_from_db($calendar);
            // Read event from XML
            foreach (calendar\get_external_calendar_file() as $fileArray) {
                if ($fileArray['activ'] == 1) {
                    calendar\read_event_from_XML($fileArray['filename'], $calendar, strtotime($calendar_start) - 7200, strtotime($calendar_end));
                }
            }
        }
        echo "1";
    } else {
        echo "-1";
    }
}
/************************ Daily program Part ******************************/
// Read parameters send
$daily_program_name = "";
if (isset($_GET['daily_program_name'])) {
    $daily_program_name = $_GET['daily_program_name'];
}
$calendar_start = "";
require_once '../../libs/utilfunc_sd_card.php';
// Retrieve start and end param (Unix time format (s))
$sd_card = $_GET['sd_card'];
// Create all plugXX programm
// Read program index
$program_index = array();
programs\get_program_index_info($program_index);
// Foreach programm, create the programm
foreach ($program_index as $key => $value) {
    // Read from database program
    $program = create_program_from_database($main_error, $value['program_idx']);
    // Save programm on SD
    $file = "{$sd_card}/cnf/prg/" . "plu" . $value['plugv_filename'];
    save_program_on_sd($file, $program);
}
$data = array();
calendar\read_event_from_db($data);
// Read event from XML
foreach (calendar\get_external_calendar_file() as $fileArray) {
    if ($fileArray['activ'] == 1) {
        calendar\read_event_from_XML($fileArray['filename'], $data);
    }
}
if (!check_sd_card($sd_card)) {
    $main_error[] = __('ERROR_WRITE_CALENDAR');
} else {
    $plgidx = create_plgidx($data);
    if (count($plgidx) > 0) {
        write_plgidx($plgidx, $sd_card);
    }
}
<?php

require_once '../../libs/config.php';
require_once '../../libs/db_get_common.php';
require_once '../../libs/db_set_common.php';
require_once '../../libs/utilfunc.php';
require_once '../../libs/utilfunc_sd_card.php';
// Retrieve start and end param (Unix time format (s))
$start = $_GET['start'];
$end = $_GET['end'];
// Initializes a container array for all of the calendar events
$jsonArray = array();
// Initialise ID index
$id = 0;
$event = array();
// Gets event from db (Must be in first and before read_event_from_XML else id are not correctly incremented) !!!!!!!
$id = calendar\read_event_from_db($event, $start, $end);
// List XML file find in folder
$files = glob('../../xml/permanent/*.{xml}', GLOB_BRACE);
foreach ($files as $file) {
    // Gets element from XML
    $id = calendar\read_event_from_XML($file, $event, $id + 1, $start, $end);
}
echo json_encode($event);