HTML-Variablen für das iCal Modul

Habe hier mal noch ein Skript bauen lassen. Alle Farben etc. anpassbar. Ähnelt an das ToDo-Liste Modul von da8ter. Vielleicht kanns jemand brauchen.

<?php

//***********************************************************************************************************************
// 1. Objekt-Einstellungen
$KalenderId           = 47818; // iCal Reader Instanz
$UrlaubId             = 57046; // Boolean Variable für Urlaubstage
$TerminId_Heute       = 16507; // String Variable für Termine Heute
$TerminId_Morgen      = 11553; // String Variable für Termine Morgen
$TerminId_Uebermorgen = 10108; // String Variable für Termine Übermorgen
$TerminId_Gesamt      = 50965; // String Variable mit Profil ~HTMLBox (Diese verlinken für die Visualisierung)


//***********************************************************************************************************************
// 2. DESIGN-EINSTELLUNGEN

// --- Schriftgrößen ---
$size_box_label       = "0.65rem";
$size_box_number      = "1.6rem";
$size_list_title      = "0.65rem";
$size_list_content    = "0.85rem";

// --- Farben obere Boxen ---
$color_box1_border    = "rgba(211,105,30,0.5)";
$color_box1_text      = "#d3691e";

$color_box2_border    = "rgba(52,152,219,0.5)";
$color_box2_text      = "#3498db";

$color_box3_border    = "rgba(46,204,113,0.5)";
$color_box3_text      = "#2ecc71";

// --- Rahmen obere Boxen ---
$box1_border_width = "2px";
$box1_border_style = "solid";

$box2_border_width = "2px";
$box2_border_style = "solid";

$box3_border_width = "2px";
$box3_border_style = "solid";


//***********************************************************************************************************************
// GLOW EINSTELLUNGEN (NUR EINE Variante aktivieren!)

// STANDARD – Glow wenn Termine > 0
// $enable_glow_effect = true;

// VARIANTE 1 – Glow immer aktiv
$enable_glow_always = true;

// VARIANTE 2 – Glow erst ab bestimmter Anzahl
// $glow_min_count = 3;

// VARIANTE 3 – Dynamischer Glow (mehr Termine = stärker)
// $enable_dynamic_glow = true;

// VARIANTE 4 – Farbiger Glow nach Anzahl
// $enable_color_glow = true;


//***********************************************************************************************************************
// LISTEN DESIGN

$color_list_border    = "rgba(255,255,255,0.1)";
$list_border_width    = "1px";
$color_list_label     = "#777777";
$color_list_bg        = "rgba(255,255,255,0.03)";

// --- Allgemeines ---
$color_bg_card        = "rgba(45,45,48,1)";
$color_count_zero     = "rgba(150,150,150,0.4)";
$border_radius        = "10px";
$spacing_gap          = "12px";


//***********************************************************************************************************************
// HILFSFUNKTIONEN

function normalizeTextOutput(string $content): string
{
    $clean = trim($content);
    if ($clean === "") {
        return "Keine Termine";
    }

    return str_replace("<br>", PHP_EOL, $content);
}

function generateTopBox(
    $title,
    $count,
    $borderColor,
    $borderWidth,
    $borderStyle,
    $textColor,
    $zeroColor,
    $bgColor,
    $radius,
    $sizeLabel,
    $sizeNumber
) {
    global $enable_glow_effect;
    global $enable_glow_always;
    global $glow_min_count;
    global $enable_dynamic_glow;
    global $enable_color_glow;

    $displayColor = ($count == 0) ? $zeroColor : $textColor;
    $glow = "";

    // STANDARD
    if (isset($enable_glow_effect) && $enable_glow_effect && $count > 0) {
        $glow = "box-shadow:0 0 10px $borderColor;";
    }

    // VARIANTE 1
    if (isset($enable_glow_always) && $enable_glow_always) {
        $glow = "box-shadow:0 0 10px $borderColor;";
    }

    // VARIANTE 2
    if (isset($glow_min_count) && $count >= $glow_min_count) {
        $glow = "box-shadow:0 0 12px $borderColor;";
    }

    // VARIANTE 3
    if (isset($enable_dynamic_glow) && $enable_dynamic_glow && $count > 0) {
        $strength = min(20, 5 + ($count * 2));
        $glow = "box-shadow:0 0 {$strength}px $borderColor;";
    }

    // VARIANTE 4
    if (isset($enable_color_glow) && $enable_color_glow && $count > 0) {
        if ($count <= 2) {
            $glowColor = "#2ecc71";
        } elseif ($count <= 5) {
            $glowColor = "#f39c12";
        } else {
            $glowColor = "#e74c3c";
        }

        $glow = "box-shadow:0 0 12px $glowColor;";
    }

    return "<div style='
                flex:1;
                border:$borderWidth $borderStyle $borderColor;
                border-radius:$radius;
                padding:10px 2px;
                text-align:center;
                background:$bgColor;
                $glow'>

            <div style='font-size:$sizeLabel;color:$textColor;font-weight:bold;margin-bottom:4px;text-transform:uppercase;'>
                $title
            </div>

            <div style='font-size:$sizeNumber;color:$displayColor;font-weight:bold;line-height:1;'>
                $count
            </div>

        </div>";
}


//***********************************************************************************************************************
// KALENDER LADEN

ICCR_UpdateCalendar($KalenderId);
$calendar_array = json_decode(ICCR_GetCachedCalendar($KalenderId), true);

SetValue($UrlaubId, false);

$ts_heute       = mktime(0, 0, 0, date("n"), date("j"), date("Y"));
$ts_morgen      = strtotime("+1 day", $ts_heute);
$ts_uebermorgen = strtotime("+2 days", $ts_heute);
$ts_ende        = strtotime("+3 days", $ts_heute);

$text1 = "";
$text2 = "";
$text3 = "";

$count_1 = 0;
$count_2 = 0;
$count_3 = 0;

if (is_array($calendar_array)) {
    foreach ($calendar_array as $entry) {

        $status = $entry["Status"] ?? "";
        if ($status === "CANCELLED") {
            continue;
        }

        $start  = $entry["From"] ?? 0;
        $ende_t = $entry["To"] ?? 0;
        $name   = $entry["Name"] ?? "Unbenannter Termin";
        $allDay = !empty($entry["allDay"]);

        if ($start <= 0 || $ende_t <= 0) {
            continue;
        }

        $zeit = date("H:i", $start) . " Uhr ";

        // HEUTE
        if (
            ($start >= $ts_heute && $start < $ts_morgen) ||
            ($start < $ts_heute && $ende_t > $ts_heute)
        ) {
            $text1 .= "• " . ($allDay ? "" : $zeit) . $name . "<br>";
            $count_1++;

            if (stripos($name, "Urlaub") !== false) {
                SetValue($UrlaubId, true);
            }
        }

        // MORGEN
        elseif (
            ($start >= $ts_morgen && $start < $ts_uebermorgen) ||
            ($start < $ts_morgen && $ende_t > $ts_morgen)
        ) {
            $text2 .= "• " . ($allDay ? "" : $zeit) . $name . "<br>";
            $count_2++;
        }

        // ÜBERMORGEN
        elseif (
            ($start >= $ts_uebermorgen && $start < $ts_ende) ||
            ($start < $ts_uebermorgen && $ende_t > $ts_uebermorgen)
        ) {
            $text3 .= "• " . ($allDay ? "" : $zeit) . $name . "<br>";
            $count_3++;
        }
    }
}


//***********************************************************************************************************************
// LISTEN

$generateListBox = function ($label, $content) use (
    $color_list_border,
    $list_border_width,
    $color_list_label,
    $color_list_bg,
    $border_radius,
    $size_list_title,
    $size_list_content
) {
    $clean = trim($content);
    $final = ($clean === "") ? "Keine Termine" : $clean;

    return "<div style='border:$list_border_width solid $color_list_border;border-radius:$border_radius;padding:10px;background:$color_list_bg;'>
                <div style='font-size:$size_list_title;color:$color_list_label;font-weight:bold;text-transform:uppercase;margin-bottom:6px;'>$label</div>
                <div style='font-size:$size_list_content;line-height:1.4;'>$final</div>
            </div>";
};


//***********************************************************************************************************************
// HTML

$html = "<div style='font-family:sans-serif;color:white;padding:2px;'>";

$html .= "<div style='display:flex;gap:8px;margin-bottom:15px;'>";

$html .= generateTopBox("Heute", $count_1, $color_box1_border, $box1_border_width, $box1_border_style, $color_box1_text, $color_count_zero, $color_bg_card, $border_radius, $size_box_label, $size_box_number);
$html .= generateTopBox("Morgen", $count_2, $color_box2_border, $box2_border_width, $box2_border_style, $color_box2_text, $color_count_zero, $color_bg_card, $border_radius, $size_box_label, $size_box_number);
$html .= generateTopBox("Übermorgen", $count_3, $color_box3_border, $box3_border_width, $box3_border_style, $color_box3_text, $color_count_zero, $color_bg_card, $border_radius, $size_box_label, $size_box_number);

$html .= "</div>";

$html .= "<div style='display:flex;flex-direction:column;gap:$spacing_gap;'>";
$html .= $generateListBox("Termine Heute", $text1);
$html .= $generateListBox("Termine Morgen", $text2);
$html .= $generateListBox("Termine Übermorgen", $text3);
$html .= "</div></div>";


//***********************************************************************************************************************
// VARIABLEN SETZEN

SetValueString($TerminId_Heute, normalizeTextOutput($text1));
SetValueString($TerminId_Morgen, normalizeTextOutput($text2));
SetValueString($TerminId_Uebermorgen, normalizeTextOutput($text3));
SetValueString($TerminId_Gesamt, $html);

Danke für das Script :slight_smile:

Ich bekomm leider die Termine für Morgen, Übermorgen nicht angezeigt, obwohl ich welche eingetragen habe. Einen Fehler erhalte ich beim ausführen des Script nicht.

Die Daten habe ich mit Ical Calender Reader eingelesen.

LG Michael

Kann das sein das die Schrift noch weiß ist?

Die Variablen werden nicht befüllt bei mir?

Habe es gerade wieder getestet. Passt…

Probiere mal dieses Skript aus:

<?php

//***********************************************************************************************************************
// 1. Objekt-Einstellungen
$KalenderId           = 28575; // iCal Reader Instanz
$UrlaubId             = 57046; // Boolean Variable für Urlaubstage
$TerminId_Heute       = 16507; // String Variable für Termine Heute
$TerminId_Morgen      = 11553; // String Variable für Termine Morgen
$TerminId_Uebermorgen = 10108; // String Variable für Termine Übermorgen
$TerminId_Gesamt      = 50965; // String Variable mit Profil ~HTMLBox


//***********************************************************************************************************************
// 2. THEME UMSCHALTUNG

$theme_mode = "auto";  
// "dark" | "light" | "auto"


//***********************************************************************************************************************
// 3. ICON SYSTEM

$enable_icons = true;

$icon_today        = "calendar";
$icon_tomorrow     = "clock";
$icon_overmorgen   = "star";

$icon_size_top   = 18;
$icon_size_list  = 12;


//***********************************************************************************************************************
// 4. THEME FARBEN DEFINIEREN

if($theme_mode === "light"){

    $color_bg_card      = "#ffffff";
    $color_text_main    = "#1e1e1e";
    $color_list_bg      = "rgba(0,0,0,0.03)";
    $color_list_border  = "rgba(0,0,0,0.1)";
    $color_list_label   = "#555";
    $color_count_zero   = "rgba(0,0,0,0.3)";

}
else{ // dark + auto (default dark)

    $color_bg_card      = "rgba(45,45,48,1)";
    $color_text_main    = "#ffffff";
    $color_list_bg      = "rgba(255,255,255,0.03)";
    $color_list_border  = "rgba(255,255,255,0.1)";
    $color_list_label   = "#999";
    $color_count_zero   = "rgba(150,150,150,0.4)";
}


//***********************************************************************************************************************
// 5. DESIGN SETTINGS

$enable_glow_effect = true;

$size_box_label    = "0.65rem";
$size_box_number   = "1.6rem";

$color_box1_border = "rgba(211,105,30,0.5)";
$color_box1_text   = "#d3691e";

$color_box2_border = "rgba(52,152,219,0.5)";
$color_box2_text   = "#3498db";

$color_box3_border = "rgba(46,204,113,0.5)";
$color_box3_text   = "#2ecc71";

$box_border_width  = "2px";
$box_border_style  = "solid";

$border_radius     = "10px";
$spacing_gap       = "12px";

$size_list_title   = "0.65rem";
$size_list_content = "0.85rem";
$list_border_width = "1px";


//***********************************************************************************************************************
// SVG ICON RENDERER

function renderIcon($type,$size,$color,$enabled){

    if(!$enabled) return "";

    switch($type){

        case "calendar":
            $svg='<rect x="3" y="4" width="18" height="18" rx="2" stroke="'.$color.'" fill="none" stroke-width="2"/>
                  <line x1="8" y1="2" x2="8" y2="6" stroke="'.$color.'" stroke-width="2"/>
                  <line x1="16" y1="2" x2="16" y2="6" stroke="'.$color.'" stroke-width="2"/>';
            break;

        case "clock":
            $svg='<circle cx="12" cy="12" r="9" stroke="'.$color.'" fill="none" stroke-width="2"/>
                  <line x1="12" y1="7" x2="12" y2="12" stroke="'.$color.'" stroke-width="2"/>
                  <line x1="12" y1="12" x2="16" y2="14" stroke="'.$color.'" stroke-width="2"/>';
            break;

        case "star":
            $svg='<polygon points="12,2 15,9 22,9 17,14 19,21 12,17 5,21 7,14 2,9 9,9"
                  stroke="'.$color.'" fill="none" stroke-width="2"/>';
            break;

        case "circle":
            $svg='<circle cx="12" cy="12" r="4" fill="'.$color.'"/>';
            break;

        default: return "";
    }

    return "<svg width='{$size}' height='{$size}' viewBox='0 0 24 24'
                style='vertical-align:middle;margin-right:6px;'>$svg</svg>";
}


//***********************************************************************************************************************
// HILFSFUNKTIONEN

function intersectsRange($start, $end, $rangeStart, $rangeEnd){
    return ($start < $rangeEnd) && ($end > $rangeStart);
}

function formatTermin($entry, $icon_size_list, $enable_icons){
    $start = $entry["From"];
    $zeit  = date('H:i', $start) . " Uhr ";

    return renderIcon("circle", $icon_size_list, "currentColor", $enable_icons)
         . ($entry["allDay"] ? "" : $zeit)
         . htmlspecialchars($entry["Name"])
         . "<br>";
}


//***********************************************************************************************************************
// KALENDER LADEN

ICCR_UpdateCalendar($KalenderId);
$calendar_array = json_decode(ICCR_GetCachedCalendar($KalenderId), true);

$ts_heute       = mktime(0,0,0,date("n"),date("j"),date("Y"));
$ts_morgen      = strtotime("+1 day",$ts_heute);
$ts_uebermorgen = strtotime("+2 days",$ts_heute);
$ts_ende        = strtotime("+3 days",$ts_heute);


//***********************************************************************************************************************
// EXAKTE WOCHENGRENZEN

$now = time();

// Montag dieser Woche 00:00:00
$wochentag = (int)date('N', $now); // 1=Mo ... 7=So
$ts_wochenstart = mktime(0,0,0,date('n',$now),date('j',$now)-($wochentag-1),date('Y',$now));

// Montag nächster Woche 00:00:00
$ts_naechste_woche_start = strtotime('+7 days', $ts_wochenstart);

// Montag übernächster Woche 00:00:00
$ts_uebernaechste_woche_start = strtotime('+14 days', $ts_wochenstart);


//***********************************************************************************************************************
// SAMMLER

$text1=""; $text2=""; $text3="";
$count_1=0; $count_2=0; $count_3=0;

$text_week_current = "";
$text_week_next    = "";
$count_week_current = 0;
$count_week_next    = 0;

$urlaub_aktiv = false;


//***********************************************************************************************************************
// TERMINE AUSWERTEN

if(is_array($calendar_array)){
    foreach($calendar_array as $entry){

        if(isset($entry["Status"]) && $entry["Status"] === 'CANCELLED') {
            continue;
        }

        $start = $entry["From"];
        $ende  = $entry["To"];
        $name  = isset($entry["Name"]) ? $entry["Name"] : "";

        // Heute
        if(intersectsRange($start, $ende, $ts_heute, $ts_morgen)){
            $text1 .= formatTermin($entry, $icon_size_list, $enable_icons);
            $count_1++;
        }

        // Morgen
        if(intersectsRange($start, $ende, $ts_morgen, $ts_uebermorgen)){
            $text2 .= formatTermin($entry, $icon_size_list, $enable_icons);
            $count_2++;
        }

        // Übermorgen
        if(intersectsRange($start, $ende, $ts_uebermorgen, $ts_ende)){
            $text3 .= formatTermin($entry, $icon_size_list, $enable_icons);
            $count_3++;
        }

        // Aktuelle Woche: Montag 00:00 bis nächsten Montag 00:00
        if(intersectsRange($start, $ende, $ts_wochenstart, $ts_naechste_woche_start)){
            $text_week_current .= formatTermin($entry, $icon_size_list, $enable_icons);
            $count_week_current++;
        }

        // Nächste Woche: nächsten Montag 00:00 bis übernächsten Montag 00:00
        if(intersectsRange($start, $ende, $ts_naechste_woche_start, $ts_uebernaechste_woche_start)){
            $text_week_next .= formatTermin($entry, $icon_size_list, $enable_icons);
            $count_week_next++;
        }

        // Urlaubserkennung
        if(
            stripos($name, 'urlaub') !== false ||
            stripos($name, 'ferien') !== false ||
            stripos($name, 'vacation') !== false
        ){
            if(intersectsRange($start, $ende, $ts_heute, $ts_morgen)){
                $urlaub_aktiv = true;
            }
        }
    }
}


//***********************************************************************************************************************
// VARIABLEN SETZEN

SetValueBoolean($UrlaubId, $urlaub_aktiv);
SetValueString($TerminId_Heute, strip_tags(str_replace("<br>", PHP_EOL, $text1 ?: "Keine Termine")));
SetValueString($TerminId_Morgen, strip_tags(str_replace("<br>", PHP_EOL, $text2 ?: "Keine Termine")));
SetValueString($TerminId_Uebermorgen, strip_tags(str_replace("<br>", PHP_EOL, $text3 ?: "Keine Termine")));


//***********************************************************************************************************************
// BOX GENERATOR

function generateTopBox($title,$count,$borderColor,$textColor,$icon){

    global $enable_glow_effect,$color_count_zero,$color_bg_card,$border_radius;
    global $size_box_label,$size_box_number,$box_border_width,$box_border_style;
    global $enable_icons,$icon_size_top,$color_text_main;

    $displayColor=($count==0)?$color_count_zero:$textColor;

    $glow="";
    if($enable_glow_effect && $count>0){
        $glow="box-shadow:0 0 12px $borderColor;";
    }

    $iconHtml=renderIcon($icon,$icon_size_top,$color_text_main,$enable_icons);

    return "<div style='flex:1;
                        border:$box_border_width $box_border_style $borderColor;
                        border-radius:$border_radius;
                        padding:10px 2px;
                        text-align:center;
                        background:$color_bg_card;
                        color:$color_text_main;
                        $glow'>
                <div style='font-size:$size_box_label;font-weight:bold;margin-bottom:4px;text-transform:uppercase;'>
                    $iconHtml$title
                </div>
                <div style='font-size:$size_box_number;color:$displayColor;font-weight:bold;line-height:1;'>
                    $count
                </div>
            </div>";
}


//***********************************************************************************************************************
// LISTENBLOCK

function buildList($title,$text){
    global $color_list_border,$border_radius,$list_border_width,$color_list_bg;
    global $size_list_title,$color_list_label,$size_list_content;

    return "<div style='border:$list_border_width solid $color_list_border;
                        border-radius:$border_radius;
                        padding:10px;
                        background:$color_list_bg;'>
                <div style='font-size:$size_list_title;color:$color_list_label;
                            font-weight:bold;text-transform:uppercase;margin-bottom:6px;'>
                    $title
                </div>
                <div style='font-size:$size_list_content;'>".($text ?: 'Keine Termine')."</div>
            </div>";
}


//***********************************************************************************************************************
// HTML AUSGABE

$html  = "<div style='font-family:sans-serif;color:$color_text_main;padding:4px;'>";
$html .= "<div style='display:flex;gap:8px;margin-bottom:15px;'>";
$html .= generateTopBox("Heute",$count_1,$color_box1_border,$color_box1_text,$icon_today);
$html .= generateTopBox("Morgen",$count_2,$color_box2_border,$color_box2_text,$icon_tomorrow);
$html .= generateTopBox("Übermorgen",$count_3,$color_box3_border,$color_box3_text,$icon_overmorgen);
$html .= "</div>";

$html .= "<div style='display:flex;flex-direction:column;gap:$spacing_gap;'>";
$html .= buildList("Termine Heute",$text1);
$html .= buildList("Termine Morgen",$text2);
$html .= buildList("Termine Übermorgen",$text3);
$html .= buildList("Diese Woche",$text_week_current);
$html .= buildList("Nächste Woche",$text_week_next);
$html .= "</div></div>";

SetValueString($TerminId_Gesamt,$html);

Habe das Skript im 1. Post angepasst.