<?
// Testprogramm
function testprogramm($sitepart)
{
    if ($_GET["id" . $sitepart["navigation_has_sitepart_id"]] <> "a") {
        echo "<a href=\"" . ml($sitepart, "id", "a") . "\">a</a> - ";
    } else {
        echo "a - ";
    }
    if ($_GET["id" . $sitepart["navigation_has_sitepart_id"]] <> "b") {
        echo "<a href=\"" . ml($sitepart, "id", "b") . "\">b</a> - ";
    } else {
        echo "b - ";
    }
    if ($_GET["id" . $sitepart["navigation_has_sitepart_id"]] <> "c") {
        echo "<a href=\"" . ml($sitepart, "id", "c") . "\">c</a>";
    } else {
        echo "c";
    }
    echo "<br /><br />";
}

// Layout Area integration - 10. August 2009 MH
function get_content($layout_area_id, $is_component_only = FALSE, &$IOCContainer = null)
{
    require_once CMS_PATH . "common/classes/Siteparts.php";
    $allSiteparts = \DynCom\mysyde\common\classes\Siteparts::get();
    $page_id      = (int)$GLOBALS["navigation"]['forward_page_id'];

    if ($page_id <= 0) {
        return;
    }

    $layout_area_code = $layout_area_id;
    $layout_area_entry_query  = "SELECT id FROM main_layout_area WHERE code = '" . $layout_area_id . "' AND main_layout_id = '" . $GLOBALS["layout"]["id"] . "'";
    $layout_area_entry_result = @mysqli_query($GLOBALS['mysql_con'], $layout_area_entry_query);

    $layout_area_entry = @mysqli_fetch_array($layout_area_entry_result);
    $layout_area_id    = $layout_area_entry["id"];



    show_component_content((int)$layout_area_id, $IOCContainer, $layout_area_code);
    if ($is_component_only === TRUE) {
        return;
    }


    $query  = "SELECT * FROM main_page_link WHERE main_page_id = " . (int)$page_id . " AND main_page_link_parent_id = 0 AND layout_area_id = " . (int)$layout_area_id . " AND active = 1 ORDER BY sorting ASC";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) > 0) {


        while ($sitepart = @mysqli_fetch_array($result)) {
            if ($sitepart['main_page_group'] == 1) {
                show_group_content($sitepart);
                continue;
            }

            // layout klassen wrapper anzeigen
            if (isset($GLOBALS["layout_classes"][$sitepart['layout_class_id']]) || $sitepart['layout_class_defined'] != "") {
                echo "<div class=\"" . $GLOBALS["layout_classes"][$sitepart['layout_class_id']]['code'] . " " . $sitepart['layout_class_defined'] . "\">";
            }

            if ($sitepart['main_sitepart_id'] > 0) {
                show_sitepart_content($sitepart['main_sitepart_id'], $sitepart['main_sitepart_header_id'], $sitepart['id'], $IOCContainer);
            } elseif ($sitepart['main_collection_setup_id'] > 0) {
                show_collection_setup_content($sitepart);
            }

            // layout klassenwrapper beenden
            if (isset($GLOBALS["layout_classes"][$sitepart['layout_class_id']]) || $sitepart['layout_class_defined'] != "") {
                echo "</div>";
            }
        }
    }
}

function forward_intern($forwardid)
{
    $link = get_link_to_navigation($forwardid);
    if (isset($_GET["live_edit"]) && $_GET["live_edit"] == 1) {
        $link .= "?live_edit=1";
    }
    header("Location: " . $link);
    exit();
}

function forward_extern($url)
{
    header("Location: " . $url);
    exit();
}

function forward_url_intern($url)
{
    if (substr($url, 0, 1) != "/") {
        $url = "/" . $url;
    }
    header("Location: " . $url);
    exit();
}

function show_group_content($_group)
{
    $query  = "SELECT * FROM main_page_link WHERE main_page_link_parent_id = '" . $_group['id'] . "' AND active = 1 ORDER BY sorting ASC";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) > 0) {

        $groupClass = isset($GLOBALS["layout_classes"][$_group['layout_class_id']]) || $_group['layout_class_defined'] != "" ? $GLOBALS["layout_classes"][$_group['layout_class_id']]['code'] . " " . $_group['layout_class_defined'] : "";

        echo "<div class=\"" . $groupClass . "\"><div class='row'>";
        echo $_group['main_page_group_link'] != "" ? "<a href='" . $_group['main_page_group_link'] . "'>" : "";

        while ($sitepart = @mysqli_fetch_array($result)) {

            // layout klassen wrapper anzeigen
            if (isset($GLOBALS["layout_classes"][$sitepart['layout_class_id']]) || $sitepart['layout_class_defined'] != "") {
                echo "<div class=\"" . $GLOBALS["layout_classes"][$sitepart['layout_class_id']]['code'] . " " . $sitepart['layout_class_defined'] . "\">";
            }

            if ($sitepart['main_sitepart_id'] > 0) {
                show_sitepart_content($sitepart['main_sitepart_id'], $sitepart['main_sitepart_header_id'], $sitepart['id']);
            } elseif ($sitepart['main_collection_setup_id'] > 0) {
                show_collection_setup_content($sitepart);
            }

            // layout klassenwrapper beenden
            if (isset($GLOBALS["layout_classes"][$sitepart['layout_class_id']]) || $sitepart['layout_class_defined'] != "") {
                echo "</div>";
            }
        }

        echo $_group['main_page_group_link'] != "" ? "</a>" : "";
        echo "</div></div>";
    }
}

function show_sitepart_content($sitepart_id, $sitepart_header_id, $link_id = NULL, &$IOCContainer = null)
{
    require_once CMS_PATH . "common/classes/Siteparts.php";
    $allSiteparts = \DynCom\mysyde\common\classes\Siteparts::get();
    $sitepartData = $allSiteparts[$sitepart_id];
    // container um das sitepart, daurch ansprechbar mit javascript
    if ($GLOBALS["live_edit_mode"] === TRUE) {
        $translation = \DynCom\mysyde\common\classes\Registry::get("translation");
        echo "<div class=\"live_edit_container\">";

        if ($sitepart_id != 1) {
            // Den Button nur einblenden wenn es sich nicht um Textcontent handelt
            echo "
			<span class=\"live_edit_overlay\" data-linkid=\"" . $link_id . "\" data-sitepartid=\"" . $sitepart_id . "\" data-sitepartheaderid=\"" . $sitepart_header_id . "\" data-pageid=\"" . $GLOBALS["page"]['id'] . "\">
				" . sprintf($translation->get("live_edit_button_sitepart"), $sitepartData['description']) . "
			</span>";
        }
    }
    $GLOBALS["navigation"]['sitepart_header_id'] = $sitepart_header_id;
    require_once(realpath(MODULE_PATH . $sitepartData['folder']) . DIRECTORY_SEPARATOR . $sitepartData['code'] . ".php");
    $function = $sitepartData['code'] . "_show";
    $refFunc = new ReflectionFunction($function);
    $noOfParams = $refFunc->getNumberOfParameters();
    $noOfReqParams = $refFunc->getNumberOfRequiredParameters();
    if ($sitepart_header_id > 0) {
        if ($noOfParams === 1) {
            $function($sitepart_header_id);
        } elseif ($noOfParams > 1) {
            $function($sitepart_header_id, $IOCContainer);
        }
    } elseif ($noOfReqParams === 0) {
        if ($noOfParams > 0 && isset($IOCContainer)) {
            $function($IOCContainer);
        } else {
            $function();
        }
    }

    if ($GLOBALS["live_edit_mode"] === TRUE) {
        echo "</div>";
    }
}

function show_collection_content($collection_id)
{
    $query    = "SELECT main_collection_setup_id FROM main_collection WHERE id = '" . $collection_id . "'";
    $result   = @mysqli_query($GLOBALS['mysql_con'], $query);
    $row      = @mysqli_fetch_array($result);
    $setup_id = $row['main_collection_setup_id'];

    show_collection_setup_content($setup_id, $collection_id);
}

function show_collection_setup_content($collection_setup, $group_link_table = "main_page_collection_group_link") {
    require_once(MODULE_PATH . "collection/collection_config.inc.php");
    require_once CMS_PATH . "common/classes/Siteparts.php";
    $allSiteparts = \DynCom\mysyde\common\classes\Siteparts::get();

    $collectionPreview = FALSE;
    $where             = "";
    $limit             = "";
    $fullView          = FALSE;
    $container_class   = "collection_list";
    $limitData = 9999;
    $is_view = FALSE;
    $viewResponse = array();
    $single = FALSE;

    if(isset($collection_setup['is_view']) && $collection_setup['is_view'] != NULL){
        $is_view = TRUE;
        if($collection_setup['main_collection_items'] == 0){
            $collection_setup['main_collection_items'] = 1;
        }
       
        $limit = " limit 0, " . $collection_setup['main_collection_items'];
        $limitData = $collection_setup['main_collection_items'];
        $queryData          = "SELECT *  FROM main_collection_setup_preview WHERE field_id = ".$collection_setup['field_id'].' LIMIT 1';
        $resultData         = @mysqli_query($GLOBALS['mysql_con'], $queryData);
        $rowData = @mysqli_fetch_array($resultData);
                            
         if($rowData['main_collection_view_type'] == 0){
            $single = TRUE;
            $limit = 'LIMIT 0, 1';
         }
        $where .= get_collections_from_preview($collection_setup);
    
        // for berufe
        $queryCurrent= " SELECT mcs.code, mc.* FROM main_collection_setup as mcs INNER JOIN main_collection as mc on mcs.id = mc.main_collection_setup_id  WHERE mc.id = ".$collection_setup['main_collection_id'];
        $resultCurrent = @mysqli_query($GLOBALS['mysql_con'], $queryCurrent);
        $responseCurrent = @mysqli_fetch_array($resultCurrent);
       
        $querySetup = " SELECT mcs.* FROM main_collection_setup as mcs  WHERE mcs.id = ".$collection_setup['main_collection_setup_id'];
        $resultSetup = @mysqli_query($GLOBALS['mysql_con'], $querySetup);
        //   $viewResponse = $responseSetup = @mysqli_fetch_array($resultSetup);
          $responseSetup = @mysqli_fetch_array($resultSetup);
        if($responseSetup['code'] == 'berufe'){
           
             
            // if($responseCurrent != 'berufe'){
                $querySetup = " SELECT mcs.* FROM main_collection_setup as mcs  WHERE mcs.id = ".$collection_setup['main_collection_setup_id'];
                $resultSetup = @mysqli_query($GLOBALS['mysql_con'], $querySetup);
                $viewResponse =   @mysqli_fetch_array($resultSetup);
            // }
            
           
        }
    // for berufe end
    }

    if ($collection_setup['main_collection_list'] == 2) {
        // hier wird die kollektions vorschau angezeigt, entweder 1 kollektion oder eine bestimmte anzahl
        $collectionPreview = TRUE;

        if ($collection_setup['main_collection_view_type'] == 0) {
            $limitData = 1;
            // eine bestimmte kollektion
            $where = " and main_collection.id = " . $collection_setup['main_collection_id'];
        } else {
            // liste an kollektionen mit einer bestimmten anzahl
            $limit = " limit 0, " . $collection_setup['main_collection_items'];
            $limitData = $collection_setup['main_collection_items'];
        }                       
    }
   
   
    if ($collectionPreview === FALSE && (isset($_GET['collection_id']) && (int)$_GET['collection_id'] > 0) && !$is_view) {
       
        $showedCollections = \DynCom\mysyde\common\classes\Registry::get("showedCollections");
        if ($showedCollections === null) {
            $showedCollections = array();
        }

        if (in_array($_GET['collection_id'], $showedCollections)) {
            return; // ---> collection nicht nochmal anzeigen
        }

        $showedCollections[] = $_GET['collection_id'];
        \DynCom\mysyde\common\classes\Registry::set("showedCollections", $showedCollections);

        $collection_id   = $_GET['collection_id'];
        $where           = " and main_collection.id = " . $collection_id;
        $fullView        = TRUE;
        $limitData = 1;
        $container_class = "collection_full";
    }
     
    $showRegistration = FALSE;
    if ((isset($_GET['registration']) && (int)$_GET['registration'] == 1)) {
        $showRegistration = TRUE;
    }

    // IN statement zusammenstellen um kollektionen aus gruppen auszulesen
    //IC - TH - 20170517 ---
    //$where .= get_collection_sql_in_groups($collection_setup, $group_link_table);
    //Variante 1: Nicht laden
    //$where .= get_collection_sql_in_groups($collection_setup, $group_link_table, $_GET['group_filter_id']);
    //Variante 2: LAden und ausblenden
    $where .= get_collection_sql_in_groups($collection_setup, $group_link_table);

    $where .= get_collection_tag($collection_setup);
    //IC - TH - 20170517  +++

    // datum query
    $where .= " AND (validity_from IS NULL OR validity_from <= '" . date("Y-m-d") . "') ";
    $where .= " AND (validity_to   IS NULL OR validity_to   >= '" . date("Y-m-d") . "') ";
    // $where .= " AND active = 1 ";

    $order = get_collection_order($collection_setup);
    $sql_uus = @mysqli_query($GLOBALS["mysql_con"], "SELECT * FROM main_contact_department WHERE main_contact_id = '".$_SESSION["login_id"]."';");
    // $user_uus = @mysqli_fetch_assoc($sql_uus);

     
    
    while ($row = @mysqli_fetch_array($sql_uus)) {
        $mandants[] = $row["main_mandant_id"]; 
        $department[] = $row["main_department_id"]; 
        $role[] = $row["main_role_id"]; 
        $fachbereiches[] = $row["main_bereich_id"]; 
        $einrichts[] = $row["main_einricht_id"]; 
    }

    // // die();
    // // $query       = "SELECT * FROM main_collection WHERE main_collection_setup_id = " . $collection_setup['main_collection_setup_id'] . $where . $order . $limit;
    // // $join .= " LEFT JOIN main_collection_department_link ON main_collection.id = main_collection_department_link.main_collection_id";
    // // $join .= " LEFT JOIN main_collection_role_link ON main_collection.id = main_collection_role_link.main_collection_id";
    $join_select = " GROUP_CONCAT(DISTINCT main_collection_department_link.main_department_id ORDER BY main_collection_department_link.main_department_id SEPARATOR ', ') AS department_ids";
    $join .= " LEFT JOIN main_collection_department_link ON main_collection.id = main_collection_department_link.main_collection_id";

    $join_select .= " ,GROUP_CONCAT(DISTINCT main_collection_mandant_link.main_mandant_id ORDER BY main_collection_mandant_link.main_mandant_id SEPARATOR ', ') AS mandant_ids";
    $join .= " LEFT JOIN main_collection_mandant_link ON main_collection.id = main_collection_mandant_link.main_collection_id";

    $join_select .= " ,GROUP_CONCAT(DISTINCT main_collection_role_link.main_role_id ORDER BY main_collection_role_link.main_role_id SEPARATOR ', ') AS role_ids";
    $join .= " LEFT JOIN main_collection_role_link ON main_collection.id = main_collection_role_link.main_collection_id";

    $join_select .= " ,GROUP_CONCAT(DISTINCT main_collection_fachbereich_link.main_fachbereich_id ORDER BY main_collection_fachbereich_link.main_fachbereich_id SEPARATOR ', ') AS fachbereich_ids";
    $join .= " LEFT JOIN main_collection_fachbereich_link ON main_collection.id = main_collection_fachbereich_link.main_collection_id";

    $join_select .= " ,GROUP_CONCAT(DISTINCT main_collection_einricht_link.main_einricht_id ORDER BY main_collection_einricht_link.main_einricht_id SEPARATOR ', ') AS einricht_ids";
    $join .= " LEFT JOIN main_collection_einricht_link ON main_collection.id = main_collection_einricht_link.main_collection_id";

    // $left_joint_main_mandant = "LEFT JOIN main_collection_mandant_link ON main_collection.id = main_collection_mandant_link.main_collection_id";
    // $left_joint_main_role = "LEFT JOIN main_collection_role_link ON main_collection.id = main_collection_role_link.main_collection_id";
    // $left_joint_main_fachbereich = "LEFT JOIN main_collection_fachbereich_link ON main_collection.id = main_collection_fachbereich_link.main_collection_id";
    // $left_joint_main_einricht = "LEFT JOIN main_collection_einricht_link ON main_collection.id = main_collection_einricht_link.main_collection_id";

    // $where .= " AND ((main_collection_department_link.main_collection_id IS NOT NULL AND main_department_id = ".$GLOBALS['main_contact']['current_department_id'].") OR main_collection_department_link.main_collection_id IS NULL OR main_collection_department_link.main_department_id=30)";
    // $where .= " AND ((main_collection_role_link.main_collection_id IS NOT NULL AND main_role_id = ".$GLOBALS['main_contact']['current_role_id'].") OR main_collection_role_link.main_collection_id IS NULL)";

    $query = "SELECT main_collection.*,".$join_select." FROM main_collection ".$join." WHERE main_collection_setup_id = " . $collection_setup['main_collection_setup_id'] . "  " . $where . " GROUP BY main_collection.id " .$order . $limit;
    $result      = @mysqli_query($GLOBALS['mysql_con'], $query);
    // var_dump($query);
    $collections = array();
    if($fullView == TRUE && @mysqli_num_rows($result) < 1 && $collectionPreview === FALSE && (isset($_GET['collection_id']) && (int)$_GET['collection_id'] > 0)){
        // 404
       
        $queryLanguage  = 'SELECT mn.*, ml.code as lanCode, ms.code as siteCode FROM main_navigation as mn INNER JOIN main_language as ml on mn.main_language_id = ml.id INNER JOIN main_site as ms on mn.main_site_id = ms.id WHERE mn.code= "404" AND ms.id = '.$GLOBALS['site']['id'].' LIMIT 1';
        
        $resultLanguage = @mysqli_query($GLOBALS['mysql_con'], $queryLanguage);
                if(@mysqli_num_rows($resultLanguage) != 0){
                    $rowLanguage = @mysqli_fetch_array($resultLanguage);
                         
                    $address = "/" . $rowLanguage["siteCode"] . "/" . $rowLanguage["lanCode"] . "/" . '404/'; 
                     
                    echo "<script>window.location.href='".$address."';</script>";
                    exit;
                }
        // 404 end
    }
    while ($row = @mysqli_fetch_array($result)) {
        $exisits = TRUE;
        var_dump($exisits);
        if (!empty($row['mandant_ids'])) {
            $exisits = FALSE;
            $mandant_ids = explode(", ", $row['mandant_ids']);
            foreach ($mandant_ids as $key => $value) {
                if(in_array($value, $mandants)){
                    $exisits = TRUE;
                    break;
                }
            }
        }

        if (!$exisits) {
            continue;
        }
        if (!empty($row['department_ids'])) {
            $exisits = FALSE;
            $departments = explode(", ", $row['department_ids']);
            foreach ($departments as $key => $value) {
                if(in_array($value, $department)){
                    $exisits = TRUE;
                    break;
                }
            }
        }
        
        if (!$exisits) {
            continue;
        }
        if (!empty($row['role_ids'])) {
            $exisits = FALSE;
            $role_ids = explode(", ", $row['role_ids']);
            foreach ($role_ids as $key => $value) {
                if(in_array($value, $role)){
                    $exisits = TRUE;
                    break;
                }
            }
        }
        if (!$exisits) {
            continue;
        }
        if (!empty($row['fachbereich_ids'])) {
            $exisits = FALSE;
            $fachbereich_ids = explode(", ", $row['fachbereich_ids']);
            foreach ($fachbereich_ids as $key => $value) {
                if(in_array($value, $fachbereiches)){
                    $exisits = TRUE;
                    break;
                }
            }
        }
        if (!$exisits) {
            continue;
        }
        if (!empty($row['einricht_ids'])) {
            $exisits = FALSE;
            $einricht_ids = explode(", ", $row['einricht_ids']);
            foreach ($einricht_ids as $key => $value) {
                if(in_array($value, $einrichts)){
                    $exisits = TRUE;
                    break;
                }
            }
        }
        if (!$exisits) {
            continue;
        }

        if ($exisits == TRUE) {
            $collections[$row['id']] = $row;
        }
        
    }
    $querySetup = "SELECT * FROM main_collection_setup as mcs INNER JOIN main_collection_setup_websites as mcsw on mcs.id = mcsw.main_collection_setup_id WHERE mcs.is_multidomain = 1 AND mcs.id = ".$collection_setup['main_collection_setup_id']." AND mcsw.main_site_id =  ".$GLOBALS['site']['id']." LIMIT 1";
 
    $queryResult = @mysqli_query($GLOBALS['mysql_con'], $querySetup);
    $querySetupData = array();
    $setupData = array();
    if(mysqli_num_rows($queryResult) > 0){
        $whereValid = " AND (validity_from IS NULL OR validity_from <= '" . date("Y-m-d") . "') ";
        $whereValid .= " AND (validity_to   IS NULL OR validity_to   >= '" . date("Y-m-d") . "') ";
        $queryCollection = "SELECT mc.id, mc.main_language_id, mc.main_collection_setup_id, mc.description, mc.registration,mc.registration_contactform_id, mc.modified_date, mc.modified_user, mc.validity_from, mc.validity_to, mc.sorting FROM main_collection as mc INNER JOIN main_collection_web_show as mcws on mc.id = mcws.main_collection_id WHERE mcws.main_collection_setup_id = ".$collection_setup['main_collection_setup_id']." AND mcws.main_site_id = ".$GLOBALS['site']['id']." ".$whereValid." ".$limit;     
        // print_r($queryCollection);
        $setupData = @mysqli_fetch_array($queryResult);
        $resultCollection= @mysqli_query($GLOBALS['mysql_con'], $queryCollection);
        while ($rowCollection = @mysqli_fetch_array($resultCollection)) {
            $collections[$rowCollection['id']] = $rowCollection;
            $querySetupData[] = $rowCollection;
        }
    }
    
    if (count($collections) == 0) {
        return;                                                                //--> Keine Kollektion mit der ID gefunden
    }

    if (
        $fullView === TRUE &&
        $showRegistration === TRUE &&
        $collections[$collection_id]['registration'] == 1 &&
        (int)$collections[$collection_id]['registration_contactform_id'] > 0
    ) {
        // Anmeldeformular anzeigen
        show_sitepart_content(3, $collections[$collection_id]['registration_contactform_id']);
        return;                                                                //--> Hier wird nur das Anmeldeformular angezeigt
    }


    //IC - TH - 20170517 ---
    if ($_GET['group_filter_id'] != 0)
        $filter_backlink = "?group_filter_id=" . $_GET['group_filter_id'];
    //IC - TH - 20170517 +++

    if ($fullView === true) {
        // zurueck zur uebersicht link 
        //IC - TH - 20170517 ---
        //echo "<div class=\"back_to_overview\"><a href=\"" . get_link_to_navigation($GLOBALS["navigation"]['id']) . "\">" . $GLOBALS["tc"]['back_to_overview'] . "</a></div><br />\n";
        echo "<div class=\"back_to_overview\"><a href=\"" . get_link_to_navigation($GLOBALS["navigation"]['id']) . $filter_backlink . "\">" . $GLOBALS["tc"]['back_to_overview'] . "</a></div>";
        //IC - TH - 20170517 +++
        //BC - MW - 20211115 --- insert a button, back to the last Page
        echo "<button id=\"backButton\" type=\"button\" onclick=\"history.back();\">" . $GLOBALS["tc"]['back'] . "</button>";
        //BC - MW - 20211115 +++
    }

    // alle felder sammeln
    $setup_fields = array();
    $query        = "SELECT * FROM main_collection_setup_content WHERE main_collection_setup_id = " . $collection_setup['main_collection_setup_id'] . " ORDER BY sorting ASC";
    
    $result       = @mysqli_query($GLOBALS['mysql_con'], $query);
    while ($row = @mysqli_fetch_array($result)) {
        $setup_fields[$row['id']] = $row;
    }
    
    if (count($setup_fields) == 0) {
        return;                                                                //--> Keine Felder zum anzeigen verfuegbar
    }
    

    $collection_lines = array();
    $query            = "SELECT * FROM main_collection_link WHERE main_collection_id IN (" . join(",", array_keys($collections)) . ")";
    $result           = @mysqli_query($GLOBALS['mysql_con'], $query);
    while ($row = @mysqli_fetch_array($result)) {
        
        // aufbau: z.B. $collection_lines[1][8] bedeutet:
        // 1 = main_collection_id
        // 8 = main_collection_setup_content_id

        if (!isset($collection_lines[$row['main_collection_id']])) {
            $collection_lines[$row['main_collection_id']] = array();
        }

        if (!isset($collection_lines[$row['main_collection_id']][$row['main_collection_setup_content_id']])) {
            $collection_lines[$row['main_collection_id']][$row['main_collection_setup_content_id']] = array();
        }

        $collection_lines[$row['main_collection_id']][$row['main_collection_setup_content_id']] = $row;
    }

    if (count($collection_lines) == 0) {
        return;                                                                //--> Es wurde noch kein einziges Feld ausgefuellt
    }

    // Ab hier wurde mindestens eine Zuordnung zur collection gemacht

    // setup code auslesen
    $query             = "SELECT code,linked,description FROM main_collection_setup WHERE id = " . $collection_setup['main_collection_setup_id'];
    $result            = @mysqli_query($GLOBALS['mysql_con'], $query);
    $row               = @mysqli_fetch_array($result);
    $code              = $row['code'];
    $linked            = $row['linked'];
    $setup_description = $row['description'];

    $createFullViewLink = "%s";

    $live_edit_class = "";
    if ($GLOBALS["live_edit_mode"] === TRUE) {
        $live_edit_class = " live_edit_container live_edit_collection";
    }

    //IC - TH - 20170517 ---
    $query = "select * from main_collection_setup_group where main_collection_setup_id =\"" . $collection_setup['main_collection_setup_id'] . "\"";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    $group_filter_id = $_GET['group_filter_id'];

    $coll_setup = mysqli_fetch_array(mysqli_query($GLOBALS['mysql_con'], "select * from main_collection_setup where id =" . $collection_setup['main_collection_setup_id']));

    if(isset($coll_setup['frontend_creation']) && $coll_setup['frontend_creation'] != NULL && $fullView === FALSE && $collectionPreview === FALSE){
        $translation = \DynCom\mysyde\common\classes\Registry::get("translation");
        echo "<div class='create_collection_wrapper'>";
        echo "<a class='button create_collection' href='?action=create_collection&setup_id=".$coll_setup['id']."'>".$translation->get("create_collection")."</a>";
        echo "</div>";
    }

    if ($coll_setup['show_filter'] && (mysqli_num_rows($result) > 1)) {
        echo "<div id='filter-element'></div>";
        echo "<div class=\"filter_display\">";

        if ($group_filter_id == 0)
            $selection = "a-filter";
        else
            $selection = "o-filter"; //ToDo: Anpassung Layout

        echo "<div class=\"button_filter_wrapper_2\">"
            . "<a class=\"button_filter " . $selection . "\" href=\"?group_filter_id=0#filter-element \">" . 'Alle' . "</a></div>";

        while ($group_row = mysqli_fetch_array($result)) {

            if ($group_filter_id == $group_row['id'])
                $selection = "a-filter";
            else
                $selection = "o-filter"; //ToDo: Anpassung Layout

            echo "<div class=\"button_filter_wrapper_2\">"
                . "<a class=\"button_filter " . $selection . "\" href=\"?group_filter_id=" . $group_row['id'] . "#filter-element \">" . $group_row['description'] . "</a></div>";
        }

        echo "</div>";
    }
    //IC - TH - 20170517 +++

     
    foreach ($collections as $collection_id => $collectionData) {


        //IC - TH - 20170517 ---
        //Variante 2:Laden und Ausblenden 
        //IC - RiP - 20170519 ---
        //Workaround: Alle Referenzen Anzeigen wenn $group_filter_id 0 ist
        //$query = "SELECT * FROM `main_collection_group_link` WHERE `main_collection_id` = " . $collectionData['id'] . " and `main_collection_setup_group_id` =" . $group_filter_id . " and active=1";

        /** bug behoben nur wenn Filter an ist dann soll er hide setzen DuP 20201103 **/
        $showCollection = check_web_show($collectionData['id'], $GLOBALS['language']['id'], $collectionData['main_collection_setup_id'], $collectionData['collection_for']);
        if(!$showCollection){
            continue;
        }
        if ($coll_setup['show_filter'] == 1) {

            if ($group_filter_id  == 0) {
                $query = "SELECT * FROM `main_collection_group_link` WHERE `main_collection_id` = '" . $collectionData['id'] . "' and active=1";
            } else {
                $query = "SELECT * FROM `main_collection_group_link` WHERE `main_collection_id` = '" . $collectionData['id'] . "' and `main_collection_setup_group_id` =" . $group_filter_id . " and active=1";
            }
            //IC - RiP - 20170519 ---
            $result = mysqli_query($GLOBALS['mysql_con'], $query);
            if (mysqli_num_rows($result) > 0)
                $visible = " show";
            else
                $visible = " hide";
        }

        //IC - tH - 20170517 +++



        //IC - TH - 20170517 ---
        //Variante 2:Laden und Ausblenden 
        //echo "<div class=\"" . $container_class . " " . $code . $live_edit_class . "\"><div class=\"collection_wrapper\">";

        $not_read = " ";
        if($collectionData['readable'] == 1){
            $query_read = "SELECT * FROM main_collection_read WHERE main_collection_id = ". $collectionData['id'] . " AND main_contact_id = ".$GLOBALS['main_contact']['id'];
            $result_read = @mysqli_query($GLOBALS['mysql_con'], $query_read);
            if (@mysqli_num_rows($result_read) == 0) {
                $not_read = " not_read";
            }
        }

        // breadcrumb - DuP - 20190516
        //Zuordnung der Name Collection in jeweiligen Collection Gruppe 
        $queryGroup = "SELECT * FROM `main_collection_group_link` WHERE `main_collection_id` = '" . $collectionData['id'] . "' and active=1";
        $group_result = @mysqli_query($GLOBALS['mysql_con'], $queryGroup);
        $group_row = @mysqli_fetch_array($group_result);
        $group_output = $group_row['main_collection_setup_group_id'];

        $query = "SELECT * FROM main_collection_setup_group WHERE id =\"" . $group_output . "\"";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        $row = @mysqli_fetch_array($result);
        $output = $row['description'];
        $showCollection = check_web_show($collectionData['id'], $GLOBALS['language']['id'], $collectionData['main_collection_setup_id'], $collectionData['collection_for']);
        if($showCollection && $limitData > 0  ){
            $limitData-- ; 
            echo "<div class=\"" . $container_class . " " . $code . $live_edit_class . $not_read . $visible . "\"><div class=\"collection_container " . $output . "\">";
            //IC - TH - 20170517 +++
            if ($GLOBALS["live_edit_mode"] === true) {
                $translation = Registry::get("translation");
                echo "
                    <span class=\"live_edit_overlay\" data-collection=\"true\" data-collection_setup_id=\"" . $collectionData['main_collection_setup_id'] . "\" data-collectionid=\"" . $collection_id . "\" data-pageid=\"" . $GLOBALS["page"]['id'] . "\">
                        " . sprintf($translation->get("live_edit_button_sitepart"), $setup_description) . "
                    </span>";
            }
            $queryField =  '';
            if($setupData['is_custom_collection']){
                $queryField = "SELECT * FROM main_collection_setup_content WHERE main_collection_setup_id = " . $collection_setup['main_collection_setup_id'] . " AND main_collection_id = ".$collectionData['id']." ORDER BY sorting ASC";
                $resultField = @mysqli_query($GLOBALS['mysql_con'], $queryField);
                if (@mysqli_num_rows($resultField) < 1 ) {
                    continue;
                }else{
                    $setup_fields = array();
                    while ($rowField = @mysqli_fetch_array($resultField)) {
                        $setup_fields[$rowField['id']] = $rowField;
                    }
                }
            }

            $linkShow = FALSE;


            if($coll_setup['collection_type'] == 4){
                $translation = \DynCom\mysyde\common\classes\Registry::get("translation");
                ?>
                <a class='button bookmark' href='?action=add_mark&collection_id=<?=$collectionData['id']?>'><svg xmlns="http://www.w3.org/2000/svg" width="24" height="30" viewBox="0 0 24 30">
                <g id="bx-bookmark-plus" transform="translate(-6 -3)">
                  <path id="Pfad_167" data-name="Pfad 167" d="M19.5,21V16.5H24v-3H19.5V9h-3v4.5H12v3h4.5V21Z"></path>
                  <path id="Pfad_168" data-name="Pfad 168" d="M30,33V6a3,3,0,0,0-3-3H9A3,3,0,0,0,6,6V33l12-6.858ZM9,15V6H27V27.83l-9-5.142L9,27.83Z"></path>
                </g>
              </svg></a>
                <?php
            }
            
            if(isset($_GET['action']) && $_GET['action'] == 'add_mark' && $_GET['collection_id'] != NULL){
                add_mark($_GET['collection_id']);
                return;
            }

            if($coll_setup['show_group_name'] == 1){
                echo '<div class="collection_group">'.$output.'</div>';
            }

            foreach ($setup_fields as $fieldId => $fieldData) {
                if($fullView && $fieldData['fieldtype'] == 'siteparts' && $fieldData['type_id'] == 16){

                     
                    require_once(MODULE_PATH.'faq/show_collection_faq.inc.php');
                    // print_r(MODULE_PATH . $sitepartData['folder']) . DIRECTORY_SEPARATOR . $sitepartData['code'] . ".php"));
                    // echo '<div class="fieldCheck" style="display:none"><pre>';print_r(MODULE_PATH.'faq/show_collection_faq.inc.php');echo '</pre></div>';
                    continue;
                }
                if($fullView && $fieldData['fieldtype'] == 'siteparts' && $fieldData['type_id'] == 22){

                     
                    require_once(MODULE_PATH.'table/show_collection_table.inc.php');
                    // print_r(MODULE_PATH . $sitepartData['folder']) . DIRECTORY_SEPARATOR . $sitepartData['code'] . ".php"));
                    // echo '<div class="fieldCheck" style="display:none"><pre>';print_r(MODULE_PATH.'faq/show_collection_faq.inc.php');echo '</pre></div>';
                    continue;
                }
                if (!isset($collection_lines[$collection_id])) {
                    continue;
                }

                if (!isset($collection_lines[$collection_id][$fieldId]) && $fieldData['fieldtype'] != 'collection_preview') {
                    continue;
                }

                if ($fullView === FALSE && $fieldData['is_teaser'] == 0) {
                    continue;
                }

                if ($linked == 1 && $fullView === FALSE) {
                    if ($collectionPreview === TRUE) {
                        // weiterleitung zu einer anderen seite
                        $query = "SELECT * FROM main_page_link WHERE main_collection_setup_id = '" . $collection_setup['main_collection_setup_id'] . "' AND main_collection_view_type = 0 LIMIT 1";
                        $result = mysqli_query($GLOBALS["mysql_con"], $query);
                        if (@mysqli_num_rows($result) == 1) {
                            $mainPageLink = @mysqli_fetch_array($result);
                            $query = "SELECT * FROM main_navigation WHERE forward_page_id = '" . $mainPageLink['main_page_id'] . "' LIMIT 1";
                            $result = mysqli_query($GLOBALS["mysql_con"], $query);
                            if (@mysqli_num_rows($result) == 1) {
                                $mainNavigation = @mysqli_fetch_array($result);
                                $collection_setup['main_collection_page_list_id'] = $mainNavigation["id"];
                            }
                        }
                        $fullviewLink = get_link_to_navigation($collection_setup['main_collection_page_list_id']) . get_collection_rewrite($collectionData['description'], $collection_id);
                    } else {
                        // gleiche seite nochmal laden
                        $fullviewLink = get_link_to_navigation($GLOBALS["navigation"]['id']) . get_collection_rewrite($collectionData['description'], $collection_id);
                    }

                    $createFullViewLink = '<a href="' . $fullviewLink . '" />%s</a>';
                }
                if($is_view){
                    $fullviewLink = get_link_to_navigation($collection_setup['main_collection_page_list_id']) . get_collection_rewrite($collectionData['description'], $collection_id);
                }
                $line = $collection_lines[$collection_id][$fieldId];

                /** 20200825 - Wenn Description aktiv dann soll es als Titel angezeigt werden DuP **/
                $description_title = '';

                if (isset($fieldData['show_description_title']) && $fieldData['show_description_title'] == 1) {
                    $description_title = "<span class=\"field_description_title\">" . $fieldData['fieldname'] . "</span>";
                }

                if($coll_setup['desc_title'] == 1 && $linkShow == FALSE && $fullView == TRUE && $collectionSetup['code'] == 'news'){
                    echo "<h1 class=\"collection_content ".$code."__title title custom\">";
                    echo $collectionData['description'];
                    echo '</h1>';
                    $linkShow = TRUE;
                }
                
                if($coll_setup['desc_title'] == 1 && $linkShow == FALSE){
                    echo "<h3 class=\"collection_content ".$code."__title title custom\">";
                    echo $collectionData['description'];
                    echo '</h3>';
                    $linkShow = TRUE;
                }



                echo "<div class=\"collection_content " . $fieldData['code'] . "\">";
                switch ($fieldData['fieldtype']) {
                    case 'siteparts':

                        if ($linked == 1 && $fullView === FALSE) {
                            echo '<a href="' . $fullviewLink . '" />';
                        }

                        show_sitepart_content($line['main_sitepart_id'], $line['main_sitepart_header_id']);

                        if ($linked == 1 && $fullView === FALSE) {
                            echo '</a>';
                        }

                        break;

                    case 'standard':
                    default:
                        if ($fieldData['type_id'] == 4) { // link
                            $target = '';
                            if($line['main_sitepart_header_id'] == 1){
                                $target = 'target="_blank"';
                            }
                            echo $description_title . "<a ".$target." href=\"" . $line['data'] . "\" >" . $line['linkText'] . "</a>";
                            break;
                        }

                        /** 20200812 Link entfernen vom Content DuP */

                        // if ($fieldData['type_id'] == 5) { // bild
                        //     if ($line['data'] != "" && file_exists(ROOT_PATH . PATH_ORIGINAL_FRONTEND_COLLECTION . $line['data'])) {
                        //         echo sprintf($createFullViewLink, "<img src=\"" . PATH_ORIGINAL_FRONTEND_COLLECTION . $line['data'] . "\" />");
                        //     }

                        //     break;
                        // }
                        if ($fieldData['type_id'] == 5) { // bild
                            if ($line['data'] != "" && file_exists(ROOT_PATH . "userdata/" . $line['data'])) {
                                echo sprintf("<img loading='lazy' alt=".$line['data']." src=\"/userdata/" . $line['data'] . "\" />");
                            }

                            break;
                        }

                        if ($fieldData['type_id'] == 6) { // Dropdown

                            //Get Dropdown Values
                            $setup_content = $setup_fields[$line['main_collection_setup_content_id']]['option_string'];

                            //Als Array umwandeln und Json wieder anzeigen
                            $options = explode(";", $setup_content);
                            $option_value = unserialize($line['data']);

                            // print value
                            echo $description_title . $options[$option_value];

                            break;
                        }

                        if ($fieldData['type_id'] == 3) { // Datum
                            $date = new DateTime($line['data']);
                            echo $date->format("d.m.Y");
                            break;
                        }

                        if ($fieldData['type_id'] == 8) { // Icon Dropdown
                            require(MODULE_PATH . "collection/collection_config.inc.php");
                            echo "<div class='svg_container'>".$collection_icon_images[$fieldData['code']][$line['data']]["image"]."</div>";
                            break;
                        }
                        if ($fieldData['type_id'] == 9) { // Icon Dropdown
                            // Überprüfe, ob `line['data']` nicht leer ist
                            if (!empty($line['data'])) {
                                // Teile die `line['data']` in ein Array auf, falls mehrere IDs vorhanden sind
                                $dataIds = explode(',', $line['data']); // Angenommen, IDs sind durch Kommas getrennt
                                echo "<div class='person_links'>";
                                foreach ($dataIds as $dataId) {
                                    // Bereinige den Wert von `dataId` für die sichere Verwendung in der SQL-Abfrage
                                    $dataId = mysqli_real_escape_string($GLOBALS['mysql_con'], trim($dataId));
                        
                                    // SQL-Abfrage, um den Datensatz mit der angegebenen ID abzurufen
                                    $query = "SELECT id, name FROM main_contact WHERE id = '$dataId'";
                                    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
                                    
                                    // Überprüfe, ob ein Ergebnis gefunden wurde
                                    if ($result && mysqli_num_rows($result) > 0) {
                                        $row = mysqli_fetch_array($result);
                                        
                                        // Generiere den Link mit dem Namen
                                        $name = htmlspecialchars($row['name']); // Sicher für HTML
                                        echo '<a href="/awo/de/profil/?contact=' . $dataId . '">' . $name . '</a>';
                                    }
                                }
                                echo "</div>";

                            }
                        }
                        if ($fieldData['type_id'] == 666) { // connected_form
                            show_sitepart_content(3, $line['data']);
                            break;
                        }
                        if($fieldData['type_id'] == '8888' ){
                            $queryPrev = "SELECT * FROM main_collection_setup_preview WHERE field_id = ".$fieldData['id'];
                            $resultPrev   = @mysqli_query($GLOBALS['mysql_con'], $queryPrev);
                             
                            if (@mysqli_num_rows($resultPrev) > 0) {   
                                while ($rowPrev = @mysqli_fetch_array($resultPrev)) {
                                   $limit = $rowPrev['main_collection_items'];                 
                                    $setupContent = [
                                            'main_collection_id' => $collectionData['id'],
                                            'main_collection_setup_id'  => $rowPrev['main_collection_setup_id_selected'],
                                            'main_collection_page_list_id'  => $rowPrev['main_collection_page_list_id'],
                                            'is_view'   => 1,
                                            'field_id'   => $rowPrev['field_id'],
                                            'main_collection_items' => $limit,
                                            'main_collection_view_type' => $rowPrev['main_collection_view_type']

                                    ];
                                    show_collection_setup_content($setupContent, 'main_collection_preview_group_link');
                                }
                            } 
                            // echo '<div class="prevCheck" style="display:none"><pre>';print_r($line);echo '</pre></div>';
                            break;
                        }

                        if($fieldData['type_id'] == '8889'){
                           
                            $queryLinked = "SELECT * FROM main_collection_contact_linked WHERE main_collection_id = ".$collectionData['id']." AND field_id = ".$fieldData['id'];
                            $resultLinked = @mysqli_query($GLOBALS['mysql_con'], $queryLinked);
                             
                            if (@mysqli_num_rows($resultLinked) > 0) {
                              
                               show_sitepart_content(3, $fieldData['option_string'], NULL, $IOCContainer, $fieldData['id']);
                           ?>   
                               <script>
                                   console.log("<?= $fieldData['option_string'] ;?>");
                                   $('#contact_field_id<?= $fieldData['option_string'];?>').val('<?= $fieldData['id'];?>');
                                   $('#main_collection_id<?= $fieldData['option_string'];?>').val('<?= $collectionData['id'];?>');
                                   
                               </script> 
                           <?php 
                            }
                            break;
                       }
                        //echo sprintf($createFullViewLink, nl2br($line['data']));
                        echo sprintf(nl2br($description_title . $line['data']));
                        break;
                }

                echo "</div>";
            }
            if($fullView === TRUE){
                $query_certificate = "SELECT * FROM main_certificate WHERE main_collection_id = ".$collection_id;
                $result_certificate = @mysqli_query($GLOBALS['mysql_con'], $query_certificate);
                $row_certificate = @mysqli_fetch_array($result_certificate);
                if(isset($_GET['check_certificate']) && $_GET['check_certificate']){
                    $certificate_id = $_GET['check_certificate'];
                    $current_date = new DateTime();
                    $query = "SELECT * FROM certificate_contact_submit WHERE certificate_id = ".$certificate_id." AND main_contact_id = ".$GLOBALS['main_contact']['id'];
                    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
                    $row = @mysqli_fetch_array($result);
                    if (@mysqli_num_rows($result) > 0) {
                        $query2 = "UPDATE certificate_contact_submit SET correct = 1, issue_date = '".$current_date->format('Y-m-d H:i:s')."' WHERE id = ".$row['id'];
                    }else{
                        $query2 = "INSERT INTO certificate_contact_submit (certificate_id, main_contact_id, issue_date, correct)
                        VALUES (
                            '".$certificate_id."',
                            '".$GLOBALS['main_contact']['id']."',
                            '".$current_date->format('Y-m-d H:i:s')."',
                            '1'
                        )";
                    }
                    $result2 = @mysqli_query($GLOBALS['mysql_con'], $query2);
                    ?>
                    <script>
                        const url = window.location.href.split('?')[0]
                        window.location = url;
                    </script>
                    <?php
                }
                if($row_certificate){
                    $query_submit = "SELECT * FROM certificate_contact_submit WHERE certificate_id = ".$row_certificate['id']." AND main_contact_id = ".$GLOBALS['main_contact']['id'] . " ORDER BY id DESC LIMIT 1";
                    $result_submit = @mysqli_query($GLOBALS['mysql_con'], $query_submit);
                    $row_submit = @mysqli_fetch_array($result_submit);
                    if(@mysqli_num_rows($result_submit) >= 1 && $row_submit['correct'] == 1){
                        load_certificate_submit_mask($row_submit);
                    }else{
                        echo "<div class='collection_content accept_certificate'>";
                            echo "<div class='certificate_wrapper'>";
                                echo "<div class='certificate_text'>";
                                    echo "<h3 class='certificate_headline'>Beitragszertifizierung</h3>";
                                    echo "<div class='certificate_text'>Ich bestätige, dass ich den Inhalt dieses Beitrages gelesen und verstanden habe.</div>";
                                echo "</div>";
                                echo "<a href='?check_certificate=".$row_certificate['id']."' class='certificate_button'>Beitrag zertifizieren</a>";
                            echo "</div>";
                        echo "</div>";
                    }
                }
            }
            if ($linked == 1 && $fullView === FALSE) {
                echo "<div class='collection_link'><a class='button' href='" . $fullviewLink . "'>" . $GLOBALS['tc']['learn_more'] . "</a></div>";
            }
        }
        echo "</div></div>";
    }

    // Anmeldelink anzeigen
    if (
        $fullView === TRUE &&
        $collections[$collection_id]['registration'] == 1 &&
        (int)$collections[$collection_id]['registration_contactform_id'] > 0
    ) {
        echo "<div class=\"collection_register\"><a class=\"button\" href=\"" . ml2(array('registration' => 1)) . "\">Jetzt online bewerben</a></div><br />\n";
    }
}

function get_inactive_components($page_id)
{

    $default_inactive = array();
    $query            = "SELECT id FROM main_component WHERE (main_language_id = " . (int)$GLOBALS["language"]['id'] . " OR all_languages = 1) AND default_active = 0";
    $result           = @mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) > 0) {
        while ($row = @mysqli_fetch_array($result)) {
            $default_inactive[] = $row['id'];
        }
    }

    $component_ids = array();
    $query         = "SELECT main_component_id FROM main_page_component_include_link WHERE main_page_id = '" . (int)$page_id . "' AND active = 0";
    $result        = @mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) > 0) {
        while ($row = @mysqli_fetch_array($result)) {
            $component_ids[] = $row['main_component_id'];
        }
    }

    $allComponents = array_merge($component_ids, $default_inactive);

    return $allComponents;
}

function show_component_content($layout_area_id, &$IOCContainer = null, $layout_area_code)
{
    require_once CMS_PATH . "common/classes/Siteparts.php";
    $allSiteparts  = \DynCom\mysyde\common\classes\Siteparts::get();
    $page_id       = (int)$GLOBALS["navigation"]['forward_page_id'];
    $component_ids = array();

    $query  = "SELECT id FROM main_component WHERE active = 1 AND (main_language_id = " . (int)$GLOBALS["language"]['id'] . " OR all_languages = 1) AND layout_area_id in (select id from main_layout_area where code = '" . $layout_area_code . "')";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);

    if (@mysqli_num_rows($result) == 0) {
        return "";
    }

    while ($row = @mysqli_fetch_array($result)) {
        $component_ids[] = $row['id'];
    }


    $active_components = array();
    $query             = "SELECT active, main_component_id FROM main_page_component_include_link WHERE main_page_id = '" . (int)$page_id . "' AND main_component_id IN (" . join(',', $component_ids) . ")";
    $result            = @mysqli_query($GLOBALS['mysql_con'], $query);

    if (@mysqli_num_rows($result) > 0) {
        while ($row = @mysqli_fetch_array($result)) {
            if ($row['active'] == 1) {
                $active_components[] = $row['main_component_id'];
            }
        }
    }

    // componenten filtern
    $final_components = array();
    foreach ($component_ids as $componentId) {
        if (count($active_components) && in_array($componentId, $active_components)) {
            $final_components[] = $componentId;
            continue;
        }

        if (!is_array($GLOBALS["inactive_components"]) || !in_array($componentId, $GLOBALS["inactive_components"])) {
            $final_components[] = $componentId;
            continue;
        }
    }

    if (count($final_components) == 0) {
        return "";
    }

    // componenten codes sammeln
    $componentCodes = array();
    $query          = "SELECT id, code FROM main_component WHERE id IN (" . join(',', $final_components) . ")";
    $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
    while ($row = @mysqli_fetch_array($result)) {
        $componentCodes[$row['id']] = $row['code'];
    }

    $query  = "SELECT * FROM main_component_link WHERE main_component_id IN (" . join(',', $final_components) . ")  ORDER BY main_component_id ASC, sorting ASC";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);

    if (@mysqli_num_rows($result) == 0) {
        return "";
    }

    $currentComponent = NULL;

    $live_edit_class = "";
    if ($GLOBALS["live_edit_mode"] === TRUE) {
        $live_edit_class = " live_edit_container live_edit_component";
    }

    while ($sitepart = @mysqli_fetch_array($result)) {

        if ($currentComponent !== NULL && $currentComponent != $sitepart['main_component_id']) {
            echo "</div>";
        }

        if ($currentComponent === NULL || $currentComponent != $sitepart['main_component_id']) {
            echo "<div class=\"component " . $componentCodes[$sitepart['main_component_id']] . $live_edit_class . "\">";
            if ($GLOBALS["live_edit_mode"] === TRUE) {
                $translation = \DynCom\mysyde\common\classes\Registry::get("translation");
                echo "
					<span class=\"live_edit_overlay\" data-component=\"true\" data-componentid=\"" . $sitepart['main_component_id'] . "\" data-pageid=\"" . $GLOBALS["page"]['id'] . "\">
						" . $translation->get("edit_component") . "
					</span>";
            }
        }

        if ((int)$sitepart['main_sitepart_id'] > 0) {
            // anzeige eines siteparts im baustein
            $sitepartData = $allSiteparts[$sitepart['main_sitepart_id']];
            require_once(realpath(MODULE_PATH . $sitepartData['folder']) . DIRECTORY_SEPARATOR . $sitepartData['code'] . ".php");
            $function = $sitepartData['code'] . "_show";
            $reflection = new ReflectionFunction($function);
            $noOfParams = $reflection->getNumberOfParameters();
            if ($noOfParams > 1) {
                $function($sitepart['main_sitepart_header_id'], $IOCContainer);
            } else {
                $function($sitepart['main_sitepart_header_id']);
            }
        } elseif ((int)$sitepart['main_collection_list'] == 2) {
            // anzeige einer kollektionsvorschau im baustein
            show_collection_setup_content($sitepart, "main_component_collection_group_link");
        }

        $currentComponent = $sitepart['main_component_id'];
    }
    echo "</div>";
}

function create_includes($main_layout_id, $page_id, $type)
{
    $query             = "
		SELECT id, path, default_active, type
		FROM main_layout_inclusions
		WHERE main_layout_id = '" . $main_layout_id . "' AND type = '" . $type . "'
		ORDER BY sorting ASC";
    $result            = @mysqli_query($GLOBALS['mysql_con'], $query);
    $layout_inclusions = array();
    while ($row = @mysqli_fetch_assoc($result)) {
        $layout_inclusions[$row['id']] = $row;
    }

    if (count($layout_inclusions) == 0) {
        return;
    }

    $includes_link_ids = array();
    $query             = "SELECT * FROM main_page_layout_inclusion_link WHERE main_page_id = '" . $page_id . "'";
    $result            = @mysqli_query($GLOBALS['mysql_con'], $query);
    while ($row = @mysqli_fetch_assoc($result)) {
        $includes_link_ids[$row['main_layout_includes_id']] = $row;
    }

    $time = 0;

    foreach ($layout_inclusions as $inclusion_id => $inclusion_row) {
        $include = FALSE;

        if (
            !isset($includes_link_ids[$inclusion_id]) &&
            $inclusion_row['default_active'] == 1
        ) {
            $include = TRUE;
        } elseif (isset($includes_link_ids[$inclusion_id]) && $includes_link_ids[$inclusion_id]['active'] == 1) {
            $include = TRUE;
        }

        if ($include === FALSE) {
            continue;
        }

        if (!file_exists(rtrim($_SERVER["DOCUMENT_ROOT"], '/') . $inclusion_row["path"])) {
            continue;
        }

        $filetime = filemtime(rtrim($_SERVER["DOCUMENT_ROOT"], '/') . $inclusion_row["path"]);
        if ($time < $filetime) {
            $time = $filetime;
        }

        switch ($inclusion_row['type']) {
            case 'js':
                echo "<script src=\"" . $inclusion_row["path"] . "?t=" . $filetime . "\" type=\"text/javascript\" ></script>\n";
                break;

            case 'css':
                echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"" . $inclusion_row["path"] . "?t=" . $filetime . "\"></link>\n";
                break;
        }
    }

    //if ($inclusion_row['type'] == 'css') {
    //    echo '<link rel="stylesheet" href="/layout/frontend/css/'.$main_layout_id.'/'.$page_id.'/?t='.$time.'" />\n';
    //}

    //	IF (@mysqli_num_rows($result) > 0) {
    //		WHILE ($layout_inclusions = @mysqli_fetch_assoc($result)) {
    //			$query2 = "SELECT active FROM main_page_layout_inclusion_link WHERE
    //				main_layout_inclusions_id = " . $layout_inclusions["id"] . " AND
    //				main_page_id = " . $page_id;
    //	
    //			$result2 = @mysqli_query($GLOBALS['mysql_con'],$query2);
    //			IF (@mysqli_num_rows($result2) == 0 && $layout_inclusions["default_active"] == 1) {
    //				SWITCH ($type) {
    //					CASE 'js': echo "<script src=\"" . $layout_inclusions["path"] . "\" type=\"text/javascript\" ></script>\n"; break;	
    //					CASE 'css': echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"" . $layout_inclusions["path"] . "\"></link>\n"; break;	
    //				}
    //			} ELSE {
    //				IF (@mysqli_result($result2,0) == 1) {
    //					SWITCH ($type) {
    //						CASE 'js': echo "<script src=\"" . $layout_inclusions["path"] . "\" type=\"text/javascript\"></script>\n"; break;	
    //						CASE 'css': echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"" . $layout_inclusions["path"] . "\"></link>\n"; break;	
    //					}
    //				}
    //			}
    //		}
    //	}
}

function create_live_edit_includes()
{
    if (isset($GLOBALS["admin_user_frontend"]) && $GLOBALS["admin_user_frontend"] !== FALSE && $GLOBALS["insert_live_edit_js"] === TRUE) {
        echo "<script src=\"/plugins/ckeditor/ckeditor.js\" type=\"text/javascript\" ></script>\n";
        echo "<script src=\"/plugins/ckeditor/adapters/jquery.js\" type=\"text/javascript\" ></script>\n";
        echo "<script src=\"/plugins/ckfinder/ckfinder.js\" type=\"text/javascript\" ></script>\n";

        echo "<script src=\"/mysyde/admin/edit_page_live.js?t=3\" type=\"text/javascript\" ></script>\n";
        echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"/layout/admin/css/live_edit.css?t=12\"></link>\n";

        // live edit modus setzen
        $GLOBALS["live_edit_mode"] = TRUE;

        // nur einmal einfuegen
        $GLOBALS["insert_live_edit_js"] = FALSE;

        // translation nochmal initalisieren
        // auch wenn das backend offen ist, im iframe sind wir im frontend
        \DynCom\mysyde\common\classes\Registry::set('translation', new \DynCom\mysyde\common\classes\Translate($GLOBALS["admin_user_frontend"]['main_language']));
    }
}

function get_layout_classes($_layout_id)
{
    $classes = array();
    $query   = "SELECT * FROM main_layout_class WHERE main_layout_id = '" . $_layout_id . "'";
    $result  = @mysqli_query($GLOBALS['mysql_con'], $query);
    while ($row = @mysqli_fetch_assoc($result)) {
        $classes[$row['id']] = $row;
    }

    return $classes;
}


//IC - TH - 20170517 ---
//function get_collection_sql_in_groups($collection_setup, $table) {
function get_collection_sql_in_groups($collection_setup, $table, $group_filter_id = 0)
{
    //IC - TH - 20170517 +++
    // Pruefen ob es gruppen gibt und ob kollektion in der gruppe ist
    $query       = "SELECT id FROM main_collection_setup_group WHERE main_collection_setup_id = '" . $collection_setup['main_collection_setup_id'] . "'";
    $result      = @mysqli_query($GLOBALS['mysql_con'], $query);
    $countGroups = @mysqli_num_rows($result);

    if ($countGroups == 0) {
        return "";                                //--> Keine gruppen angelegt, keine weitere pruefung
    }


    $link_row = "main_page_link_id";
    if ($table == "main_component_collection_group_link") {
        $link_row = "main_component_link_id";
    }

    $query = "SELECT main_collection_setup_group_id FROM " . $table . " WHERE " . $link_row . " = " . $collection_setup['id'];

    //IC - TH - 20170517 ---
    if ($group_filter_id != 0)
        $query .= " and main_collection_setup_group_id = \"" . $group_filter_id . "\"";
    //IC - TH - 20170517 +++

    $result                  = @mysqli_query($GLOBALS['mysql_con'], $query);
    $collection_setup_groups = array();
    while ($row = @mysqli_fetch_array($result)) {
        $collection_setup_groups[] = $row['main_collection_setup_group_id'];
    }

    if (count($collection_setup_groups) == 0) {
        return "";                                //--> Keine gruppen beim inhalt angecheckt
    }

    $query          = "SELECT main_collection_id FROM main_collection_group_link WHERE main_collection_setup_group_id IN (" . join(",", $collection_setup_groups) . ") AND active = 1";
    $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
    $collection_ids = array();
    while ($row = @mysqli_fetch_array($result)) {
        $collection_ids[] = $row['main_collection_id'];
    }

    if (count($collection_ids) == 0) {
        return " and main_collection.id IN(-1) ";                //--> Keine kollektion zur definierten gruppe zugeordnet
    }


    return " and main_collection.id IN(" . join(",", $collection_ids) . ") ";
}

function finalize_meta_tags()
{
    if (strpos($GLOBALS['site_title'], " | ") === FALSE) {
        $GLOBALS['site_title'] .= ' | ';
    }
    $GLOBALS['site_title'] .= $GLOBALS['language']["site_title_name"];
    $GLOBALS['meta_description'] .= substr(strip_tags($GLOBALS["language"]["meta_description"]), 0, 200);
    $GLOBALS['meta_keywords'] .= $GLOBALS["language"]["meta_keywords"];
}

function get_globals_and_sid_as_div()
{
    $json_imagecfg = base64_encode(serialize($GLOBALS["shop_setup"]["image_config"]));
    $div = <<<EOT
    <div style="display: none;" id="search_data"
        data-company="{$GLOBALS['shop']['company']}"
        data-shop_code="{$GLOBALS['shop']['code']}"
        data-language_code="{$GLOBALS["shop_language"]["code"]}"
        data-site_language="{$GLOBALS["language"]["code"]}"
        data-item_source="{$GLOBALS['shop']['item_source']}"
        data-site_code="{$GLOBALS["site"]["code"]}"
        data-sid="{$_SESSION['sid' .$GLOBALS['site']['code']]}"
        data-image_config="{$json_imagecfg}"
        data-default_img="{$GLOBALS["shop_language"]["item_placeholder_image"]}"
        data-customer_no="{$GLOBALS['shop_customer']['customer_no']}"></div>
EOT;
    return $div;
}

function get_collection_rewrite($title, $id)
{
    // Alles klein schreiben
    $str = mb_strtolower($title, 'UTF-8');

    // Alle deutschen Umlaute und Sonderfälle austauschen
    $str = str_replace(
        array('ä',    'ö',    'ü',    'ß',    ' - ',    ' + ',    '_',    ' / ',    '/'),
        array('ae',    'oe',    'ue',    'ss',    '-',    '-',    '-',    '-',    '-'),
        $str
    );

    // Alle restlichen Leerzeichen zu Bindestrichen
    $str = preg_replace('/\s/s', '-', $str);

    // Alles löschen, was nicht alphanumerisch ist
    $str = preg_replace('/[^a-z0-9_-]/isU', '', $str);

    // doppelte vorkommen von Bindestrichen entfernen
    $str = trim(preg_replace('/-+/', '-', $str), '-');

    return $str . "-" . $id . "/";
}

function get_collection_tag($collection_setup) {

    $query = "SELECT * FROM main_page_collection_tag_link WHERE main_page_link_id = '" . $collection_setup['id'] . "'";
    $result = mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) == 0) {
        return "";
    }
    $tags = array();
    while($row = @mysqli_fetch_array($result)){
        array_push($tags,$row['code']);
    }

    $tags = implode("', '", $tags);

    $query          = "SELECT main_collection_id FROM main_collection_tag WHERE code IN ('".$tags."')";
    $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
    $collection_ids = array();
    while ($row = @mysqli_fetch_array($result)) {
        $collection_ids[] = $row['main_collection_id'];
    }
    if (count($collection_ids) == 0) {
        return " and main_collection.id IN(-1) ";
    }
    return " and main_collection.id IN(" . join(",", $collection_ids) . ") ";
}

function get_collection_order($collection_setup) {

    $query = "SELECT * FROM main_page_link WHERE id = '" . $collection_setup['id'] . "'";
    $result = mysqli_query($GLOBALS['mysql_con'], $query);
    if (@mysqli_num_rows($result) == 0) {
        return " ORDER BY sorting ASC ";
    }
    $order_array = array();
    while ($row = @mysqli_fetch_array($result)) {
        $order_array = explode("_", $row['main_collection_order']);
    }

    switch ($order_array[0]) {
        case 'date':
            $order = "creation_date";
            break;
        case 'desc':
            $order = "description";
            break;
        default:
            $order = "sorting";
            break;
    }

    $direction = $order_array[1];
    return " ORDER BY " . $order . " " . $direction . " ";
}

function get_gulp_sources($src, $stylename = "style", $jsname = "script")
{
?>
    <link rel="stylesheet" href="<?= $src ?>css/global.css?time=<?= filemtime($_SERVER['DOCUMENT_ROOT']  . $src . 'css/global.css'); ?>" />
    <!-- <script src="<?= $src ?>js/<?= $jsname ?>.js?time=<?= filemtime($_SERVER['DOCUMENT_ROOT'] .  $src . 'js/' . $jsname . '.js'); ?>"></script> -->
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-config" content="/layout/frontend/b2c/dist/favicons/browserconfig.xml?v2=get">
    <meta name="theme-color" content="#ffffff">

<?
}
function getFavicon($site){
    $query = "SELECT * FROM main_site WHERE id = '" . $site . "'";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    $res = @mysqli_fetch_array($result);
    return $res['image'];
}

function check_web_show($collection_id) {

    $show = FALSE;
    $querySetup = "SELECT * FROM main_collection as mc INNER JOIN main_collection_setup as mcs on mc.main_collection_setup_id = mcs.id WHERE mc.id = '".$collection_id."' LIMIT 1";
    $resultSetup = @mysqli_query($GLOBALS['mysql_con'], $querySetup);
    $responseSetup = @mysqli_fetch_array($resultSetup);
   
    if(@mysqli_num_rows($resultSetup) != 0){
      
        if($responseSetup['is_multidomain']){
           
            $query = "SELECT *  FROM main_collection_web_show INNER JOIN main_site on main_collection_web_show.main_site_id = main_site.id WHERE main_collection_id = '" . $collection_id . "' AND main_collection_web_show.main_site_id = '".$GLOBALS['site']['id']."'";
           
            $response = @mysqli_query($GLOBALS['mysql_con'], $query);
            if (@mysqli_num_rows($response) != 0) { 
                
                while ($data = @mysqli_fetch_array($response)) {
                    
                   if($data['main_site_id'] == $GLOBALS['site']['id']){
                    $show =  TRUE;
                    break;
                   }
                }
            }
        }else{
            $show = TRUE;
        }
    }else{
        $show = TRUE;
    }
     
   
    return $show;
} 
function get_collections_from_preview($collection_setup){
    $query          = "SELECT *  FROM main_collection_setup_preview WHERE  field_id = ".$collection_setup['field_id'].' LIMIT 1';
    
    $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
    if(@mysqli_num_rows($result) == 0){
        return " ";
    }else{
        $queryCurrent= " SELECT mcs.code, mc.* FROM main_collection_setup as mcs INNER JOIN main_collection as mc on mcs.id = mc.main_collection_setup_id  WHERE mc.id = ".$collection_setup['main_collection_id'];
        $resultCurrent = @mysqli_query($GLOBALS['mysql_con'], $queryCurrent);
        $responseCurrent = @mysqli_fetch_array($resultCurrent);
        
        $querySetup = " SELECT mcs.* FROM main_collection_setup as mcs  WHERE mcs.id = ".$collection_setup['main_collection_setup_id'];
        $resultSetup = @mysqli_query($GLOBALS['mysql_con'], $querySetup);
        $responseSetup = @mysqli_fetch_array($resultSetup);
        
        
        $row = @mysqli_fetch_array($result);
       
        // 
        $collection_ids = array();
        $query = '';
        
        if($row['main_collection_view_type'] == 1){
                 
                        
                        // $query = "SELECT id FROM main_collection WHERE main_collection_setup_id = ".$collection_setup['main_collection_setup_id'] ;
                        $query = "SELECT mcpl.collection_id_selected as id FROM main_collection as mc INNER JOIN main_collection_preview_link as mcpl on mc.id = mcpl.main_collection_id WHERE mcpl.field_id = ".$collection_setup['field_id']." AND mcpl.main_collection_id = ".$collection_setup['main_collection_id'] ;
                       
             
        }
        
        else{
            
            $query = "SELECT id FROM main_collection WHERE main_collection_setup_id = ".$collection_setup['main_collection_setup_id'].' AND id = '.$row['main_collection_id_selected'];
            // echo 'singleCollection '.$query;
        }
        
         
        $result         = @mysqli_query($GLOBALS['mysql_con'], $query);
        $collection_ids = array();
        while ($row = @mysqli_fetch_array($result)) {
            $collection_ids[] = $row['id'];
        }

        if (count($collection_ids) == 0) {
             return "AND main_collection.id IN (-1)";
                       //--> Keine kollektion zur definierten gruppe zugeordnet
        }

      
        return " AND main_collection.id IN(" . join(",", $collection_ids) . ") ";
        
    }
    
}

function mandant_switch(){
    $query = "SELECT * FROM main_mandant LEFT JOIN main_contact_department ON main_mandant.id = main_contact_department.main_mandant_id WHERE main_contact_id = ".$GLOBALS['main_contact']['id'];
    $result = mysqli_query($GLOBALS["mysql_con"], $query);
    if (@mysqli_num_rows($result) <= 1) { 
        return;
    }
    echo "<div class='mandant_switch'>";
    echo "<h2>Mandanten wechseln</h2>";
    while($mandant = @mysqli_fetch_array($result)) {
        $active = "";
        if($GLOBALS['main_contact']['current_mandant_id'] == $mandant['main_mandant_id']){
            $active = 'active';
        }
    ?>
        <div class="mandant_link <?= $active?>">
            <a href='?action=change_mandant&id=<?= $mandant['main_mandant_id']?>'>
                <?= $mandant['description']?>
            </a>
        </div>
    <?php }
    echo "</div>"
    ?>
    <div class="toggle_mandant_switch"><svg xmlns="http://www.w3.org/2000/svg" width="32.063" height="33.75" viewBox="0 0 32.063 33.75">
  <path id="filter" d="M16.778,34.875H13.5V17.847L1.687,3.784V1.125H33.75V3.77L22.5,17.833V29.154Zm-1.028-2.25h.1l4.4-4.4V17.043L31.184,3.375H4.282L15.75,17.028Z" transform="translate(-1.687 -1.125)"/>
</svg>
</div>
    <?;
}

function get_mandant_variable($mandant_id){
    $query = "SELECT * FROM main_mandant WHERE id = ".$mandant_id;
    $result = mysqli_query($GLOBALS["mysql_con"], $query);
    $mandant = @mysqli_fetch_array($result);?>
    <style>
        :root{
            --clr-mandant: <?= $mandant['mandant_color']?>;
            --bg-light: <?= $mandant['mandant_bg_light']?>;
            --br: <?= $mandant['mandant_border_radius']?>px;
            --border: <?= $mandant['mandant_border_color']?>;
            --mandant_bg: url('/userdata/intranet/mandant/<?= $mandant['bg_image']?>');
        }
    </style>
    <?php
}

function get_mandant_favicon($mandant_id){
    $query = "SELECT * FROM main_mandant WHERE id = ".$mandant_id;
    $result = mysqli_query($GLOBALS["mysql_con"], $query);
    $mandant = @mysqli_fetch_array($result);
    $favicon = 'userdata/intranet/mandant/'.$mandant['favicon'];
    echo $favicon;
}

function get_mandant_logo($mandant_id){
    $query = "SELECT * FROM main_mandant WHERE id = ".$mandant_id;
    $result = mysqli_query($GLOBALS["mysql_con"], $query);
    $mandant = @mysqli_fetch_array($result);?>
    <div class='component_logo'>
        <div class='textcontent'>
            <a href='/'>
                <img alt='Mandant Logo' src='/userdata/intranet/mandant/<?= $mandant['image']?>'>
            </a>
        </div>
    </div>
    <?php
}

function add_mark($collection_id){
    $query = "SELECT * FROM main_collection_mark WHERE main_collection_id = ".$collection_id." AND main_contact_id = ".$GLOBALS['main_contact']['id'];
    $result = mysqli_query($GLOBALS["mysql_con"], $query);
    if (@mysqli_num_rows($result) == 0) {
        $query = "INSERT INTO main_collection_mark (main_collection_id, main_contact_id) VALUES (
            ".$collection_id.",
            ".$GLOBALS['main_contact']['id']."
        )";
        $result = mysqli_query($GLOBALS["mysql_con"], $query);
    }?>
    <script>
        const url = window.location.href.split('?')[0]
        window.location = url;
    </script>
<?php
}

function siteProtector($navigation_id){
    $error = "";
    $protected = 1;
    // $_SESSION['prot_'.$row['code']] = NULL;
	if($navigation_id == 18){
        if(isset($_POST['save_protected_password'])){
            if(strtolower($_POST['input_protected_password']) == 'mellon'){
                $_SESSION['prot_18'] = 1;
            }else{
                $error = "Passwort nicht korrekt.";
            }
        }

    if(!isset($_SESSION['prot_18'])){
        $protected = 0;
    ?>
    <div class='protected_overlay'>
        <div class='protected_wrapper'>
            <img style="max-width:100px;" src="/userdata/images/Sternentor%20zu%20Moria.png" alt="Sternentor zu Moria">
            <h2>Sprich, Freund, und tritt ein.</h2>
            <form method='post'>
                <div class="input_protected_group">
            <?= input("Passwort", "input_protected_password", "password",'', 45, false);?>
            </div>
            <p class='error'><?= $error?></p>
            <div class="contact-button" id="submit_button">
                <input type="submit" name="save_protected_password" class="button" id="button" value="Bring mich rein" />
            </div>
            </form>
        </div>
    </div>
    <?php }
	}
    return $protected;
}

function load_certificate_submit_mask($submit){
    $query = "SELECT * FROM main_certificate WHERE id = ".$submit['certificate_id'];
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    $row = @mysqli_fetch_array($result);

    $issue_date = new DateTime($submit['issue_date']);
    $validity_date = new DateTime($submit['issue_date']);
    $validity_date->modify('+'.$row['validity_period'].' months');
    if($submit['correct'] == 1){
      echo "<div class='learning_success_modal'>";
        echo "<div class='learning_success'>";
        ?>
        <div class="success-animation">
          <svg class="checkmark" xmlns="https://www.w3.org/2000/svg" viewBox="0 0 52 52"><circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none" /><path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8" /></svg>
        </div>
        <?php
        echo "<div class='learning_success_textcontent'>";
        echo "<h3>Du hast dieses Zertifikat am ".$issue_date->format('d.m.Y')." erhalten.</h3>";
        echo "<p>Das Zertifikat ist noch bis zum ".$validity_date->format('d.m.Y')." gültig.</p>";
        echo "</div>";
        ?>
        <div class="button_group">
          <a href="#" id="close_overlay" class=""><button>Beitrag erneut ansehen</button></a>
          <a href="/" class=""><button>zum Dashboard</button></a>
        </div>
        <?php
        echo "</div>";
      echo "</div>";
    }
}