<?php

try {
    //code...


    $category_id = 0;
    if (isset($_GET['category'])) {
        $category_id = $_GET['category'];
    }

    function search($search)
    {
        $search_escaped = mysqli_real_escape_string($GLOBALS['mysql_con'], $search);
        $archiveWhere = "(is_archived = 0 OR is_archived IS NULL)";
        
        $array = array();
        $array[] = 0;
        $query = "SELECT * FROM main_collection WHERE main_collection_setup_id = 3 AND " . $archiveWhere;
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        while ($collection = @mysqli_fetch_array($result)) {

            $query3 = "SELECT * FROM main_collection WHERE id = '" . $collection['id'] . "' AND " . $archiveWhere . " AND description LIKE '%" . $search_escaped . "%'";
            $result3 = @mysqli_query($GLOBALS['mysql_con'], $query3);
            if ($result3 !== null) {
                if (@mysqli_num_rows($result3) >= 1) {
                    $array[] = $collection['id'];
                    continue;
                }
            }

            $query2 = "SELECT * FROM main_collection_link WHERE main_collection_id = '" . $collection['id'] . "'";
            $result2 = @mysqli_query($GLOBALS['mysql_con'], $query2);
            while ($link = @mysqli_fetch_array($result2)) {
                if ($link['main_sitepart_id'] == 0) {
                    $query3 = "SELECT * FROM main_collection_link WHERE id = " . $link['id'] . " AND data LIKE '%" . $search_escaped . "%'";
                    $result3 = @mysqli_query($GLOBALS['mysql_con'], $query3);
                } else if ($link['main_sitepart_id'] == 1) {
                    // HTML-Entities für Umlaute ersetzen
                    $search_html = str_replace(
                        ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß'],
                        ['&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;'],
                        $search_escaped
                    );

                    $query3 = "SELECT * FROM textcontent_header WHERE id = " . $link['main_sitepart_header_id'] . " AND content LIKE '%" . $search_html . "%'";
                    $result3 = @mysqli_query($GLOBALS['mysql_con'], $query3);
                }
                if ($result3 !== null) {
                    if (@mysqli_num_rows($result3) >= 1) {
                        $array[] = $collection['id'];
                        continue;
                    }
                }

            }
        }

        $query = "SELECT main_collection.* FROM main_collection WHERE (is_archived = 0 OR is_archived IS NULL) AND id IN (" . join(",", $array) . ")";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 0) {
            echo "Keine Suchergebnisse gefunden.";
            return;
        }

        echo "<div class='kc_category_list major_group col-xs-12'>";
        echo "<div class='row'>";
        ?>
        <h3 class='kc_current_category'>Suchergebnisse für <?= $search ?></h3>
        <?php
        echo "<div class='kc_category_line_list_post'>";
        while ($post = @mysqli_fetch_array($result)) {
            $link = get_link_to_navigation(14) . get_collection_rewrite($post['description'], $post['id']);
            ?>
            <a class="kc_post_link" href='<?= $link ?>'>
                <div class='kc_post'>
                    <h4 class='kc_post_title'><?= $post['description'] ?></h4>
                    <svg id="chevron-right" xmlns="https://www.w3.org/2000/svg" width="6.442" height="10.736"
                        viewBox="0 0 6.442 10.736">
                        <path id="Pfad_73" data-name="Pfad 73"
                            d="M15.879,8.467l1.073-1.072,5.368,5.367-5.368,5.368-1.073-1.073,4.294-4.295L15.878,8.467Z"
                            transform="translate(-15.878 -7.395)" />
                    </svg>
                </div>
            </a>
        <?php }
        echo "</div>";
        echo "</div>";
        echo "</div>";
    }

    function all_posts()
    {
        $query = "SELECT DISTINCT main_collection.* FROM main_collection LEFT JOIN knowledgecenter_collection_link ON main_collection.id = knowledgecenter_collection_link.main_collection_id WHERE main_collection_setup_id = 3 AND (main_collection.is_archived = 0 OR main_collection.is_archived IS NULL)";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        $count = @mysqli_num_rows($result);
        ?>
        <div class='kc_content_card'>
            <div class="kc_content">
                <div class="svg_content">
                    <svg id="network-globe-line" xmlns="https://www.w3.org/2000/svg" width="24.626" height="24.62"
                        viewBox="0 0 24.626 24.62">
                        <path id="Pfad_37" data-name="Pfad 37"
                            d="M16.06,2A12.31,12.31,0,0,0,3.75,14.31a7.393,7.393,0,0,0,.062,1.169A12.31,12.31,0,1,0,16.06,2Zm0,1.759a10.551,10.551,0,0,1,7.421,3.06V7.7a16.276,16.276,0,0,0-10.718.044,2.049,2.049,0,0,0-1-.536h-.22c-.106-.369-.2-.739-.281-1.117s-.123-.712-.167-1.073A10.481,10.481,0,0,1,16.06,3.759ZM13.422,8.92a14.948,14.948,0,0,1,9.822.114,14.86,14.86,0,0,1-2.735,6.155,2,2,0,0,0-2.269.5,7.875,7.875,0,0,1-.879-.554,14.069,14.069,0,0,1-4.335-4.6,1.978,1.978,0,0,0,.413-1.556ZM9.9,5.755a3.118,3.118,0,0,0,.088.563c.079.387.185.765.29,1.143a2,2,0,0,0-.967,1.978A16.109,16.109,0,0,0,5.64,12.745a10.551,10.551,0,0,1,4.273-6.99Zm0,13.814a2.058,2.058,0,0,0-1.363,1.548H7.979a10.5,10.5,0,0,1-2.427-6l.1-.167a14.86,14.86,0,0,1,4.229-4.3,2.031,2.031,0,0,0,2,.554,15.414,15.414,0,0,0,4.7,4.968c.361.237.73.457,1.1.668a2.04,2.04,0,0,0,.158.985,14.9,14.9,0,0,1-5.452,2.735,2.058,2.058,0,0,0-2.48-.976Zm6.155,5.276a10.481,10.481,0,0,1-5.109-1.328l.246-.053a2.058,2.058,0,0,0,1.38-1.574,16.2,16.2,0,0,0,6.155-3.077,2.014,2.014,0,0,0,2.638-.545,15.308,15.308,0,0,0,3.8.492h.466a10.551,10.551,0,0,1-9.575,6.1Zm5.724-7.826a2.049,2.049,0,0,0-.29-1.046,16.179,16.179,0,0,0,2.981-6.48q.659.308,1.3.686a10.551,10.551,0,0,1,.369,7.21,14.069,14.069,0,0,1-4.352-.343Z"
                            transform="translate(-3.75 -2)" />
                    </svg>
                </div>
                <div class="kc_content_text">
                    <h5><?= $count ?></h5>
                    <p>Beiträge</p>
                </div>
            </div>
            <div class="kc_content_link">
                <a href="/intranet/de/knowledgecenter-post/">Alle Beiträge ansehen</a>
                <svg id="chevron-right" xmlns="https://www.w3.org/2000/svg" width="6.442" height="10.736"
                    viewBox="0 0 6.442 10.736">
                    <path id="Pfad_73" data-name="Pfad 73"
                        d="M15.879,8.467l1.073-1.072,5.368,5.367-5.368,5.368-1.073-1.073,4.294-4.295L15.878,8.467Z"
                        transform="translate(-15.878 -7.395)" />
                </svg>
            </div>

        </div>
        <?php
    }

    function read_categories()
    {
        $query = "SELECT COUNT(*) AS count FROM knowledgecenter_category";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        $count = @mysqli_fetch_array($result); ?>
        <div class='kc_content_card'>
            <div class="kc_content">
                <div class="svg_content">
                    <svg xmlns="https://www.w3.org/2000/svg" width="22.168" height="22.179" viewBox="0 0 22.168 22.179">
                        <path id="category"
                            d="M22.042,18.2V14.917a1.583,1.583,0,0,0-1.583-1.583H14.125V10.167h1.583a1.585,1.585,0,0,0,1.583-1.583V3.833A1.585,1.585,0,0,0,15.709,2.25h-4.75A1.585,1.585,0,0,0,9.375,3.833v4.75a1.585,1.585,0,0,0,1.583,1.583h1.583v3.167H6.208a1.583,1.583,0,0,0-1.583,1.583V18.2a3.167,3.167,0,1,0,1.583,0V14.917h6.333V18.2a3.167,3.167,0,1,0,1.583,0V14.917h6.333V18.2a3.167,3.167,0,1,0,1.583,0ZM10.958,3.833h4.75v4.75H10.958ZM7,21.25a1.583,1.583,0,1,1-1.583-1.583A1.583,1.583,0,0,1,7,21.25Zm7.917,0a1.583,1.583,0,1,1-1.583-1.583,1.583,1.583,0,0,1,1.583,1.583Zm6.333,1.583a1.583,1.583,0,1,1,1.583-1.583,1.583,1.583,0,0,1-1.583,1.583Z"
                            transform="translate(-2.25 -2.25)" />
                    </svg>
                </div>
                <div class="kc_content_text">
                    <h5><?= $count['count'] ?></h5>
                    <p>Kategorien abgeschlossen</p>
                </div>
            </div>
            <div class="kc_content_link">
                <a href="/intranet/de/knowledgecenter/">Alle Kategorien ansehen</a>
                <svg id="chevron-right" xmlns="https://www.w3.org/2000/svg" width="6.442" height="10.736"
                    viewBox="0 0 6.442 10.736">
                    <path id="Pfad_73" data-name="Pfad 73"
                        d="M15.879,8.467l1.073-1.072,5.368,5.367-5.368,5.368-1.073-1.073,4.294-4.295L15.878,8.467Z"
                        transform="translate(-15.878 -7.395)" />
                </svg>
            </div>
        </div>
        <?php
    }

    function marked_posts()
    {
        $query = "SELECT COUNT(*) AS count FROM main_collection_mark INNER JOIN main_collection ON main_collection.id = main_collection_mark.main_collection_id WHERE main_contact_id = " . $GLOBALS['main_contact']['id'] . " AND (main_collection.is_archived = 0 OR main_collection.is_archived IS NULL)";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        $count = @mysqli_fetch_array($result); ?>
        <div id="show_bookmarks" class='kc_content_card'>
            <div class="kc_content">
                <div class="svg_content">
                    <svg xmlns="https://www.w3.org/2000/svg" width="16.322" height="22.851" viewBox="0 0 16.322 22.851">
                        <g id="bookmark" transform="translate(-6.75 -2.25)">
                            <path id="Pfad_87" data-name="Pfad 87"
                                d="M14.911,20.2l8.161,4.9V5.514A3.264,3.264,0,0,0,19.807,2.25H10.014A3.264,3.264,0,0,0,6.75,5.514V25.1ZM8.382,22.218,14.911,18.3l6.529,3.917V5.514a1.632,1.632,0,0,0-1.632-1.632H10.014A1.632,1.632,0,0,0,8.382,5.514v16.7Z"
                                fill-rule="evenodd" />
                        </g>
                    </svg>
                </div>
                <div class="kc_content_text">
                    <h5><?= $count['count'] ?></h5>
                    <p>Lesezeichen</p>
                </div>
            </div>
            <div class="kc_content_link">
                <a href="#">Meine Lesezeichen ansehen</a>
                <svg id="chevron-right" xmlns="https://www.w3.org/2000/svg" width="6.442" height="10.736"
                    viewBox="0 0 6.442 10.736">
                    <path id="Pfad_73" data-name="Pfad 73"
                        d="M15.879,8.467l1.073-1.072,5.368,5.367-5.368,5.368-1.073-1.073,4.294-4.295L15.878,8.467Z"
                        transform="translate(-15.878 -7.395)" />
                </svg>
            </div>
        </div>
        <?php
    }

    function bookmarks()
    {
        $query = "SELECT * FROM main_collection LEFT JOIN main_collection_mark ON main_collection.id = main_collection_mark.main_collection_id WHERE main_contact_id = " . $GLOBALS['main_contact']['id'] . " AND (main_collection.is_archived = 0 OR main_collection.is_archived IS NULL)";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        ?>
        <div class="close">
            <svg xmlns="https://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18">
                <path id="close"
                    d="M27,10.575,25.425,9,18,16.425,10.575,9,9,10.575,16.425,18,9,25.425,10.575,27,18,19.575,25.425,27,27,25.425,19.575,18Z"
                    transform="translate(-9 -9)" />
            </svg>
        </div>
        <div class="headline">
            <h2>Lesezeichen</h2>
            <div class="svg_content">
                <svg xmlns="https://www.w3.org/2000/svg" width="16.322" height="22.851" viewBox="0 0 16.322 22.851">
                    <g id="bookmark" transform="translate(-6.75 -2.25)">
                        <path id="Pfad_87" data-name="Pfad 87"
                            d="M14.911,20.2l8.161,4.9V5.514A3.264,3.264,0,0,0,19.807,2.25H10.014A3.264,3.264,0,0,0,6.75,5.514V25.1ZM8.382,22.218,14.911,18.3l6.529,3.917V5.514a1.632,1.632,0,0,0-1.632-1.632H10.014A1.632,1.632,0,0,0,8.382,5.514v16.7Z"
                            fill-rule="evenodd" />
                    </g>
                </svg>
            </div>
        </div>
        <?php
        while ($post = @mysqli_fetch_array($result)) {
            $link = get_link_to_navigation(14) . get_collection_rewrite($post['description'], $post['main_collection_id']);
            echo "<div class='bookmark_container'>";
            ?>
            <div class="bookmark_content_svg">
                <svg xmlns="https://www.w3.org/2000/svg" width="16.322" height="22.851" viewBox="0 0 16.322 22.851">
                    <g id="bookmark" transform="translate(-6.75 -2.25)">
                        <path id="Pfad_87" data-name="Pfad 87"
                            d="M14.911,20.2l8.161,4.9V5.514A3.264,3.264,0,0,0,19.807,2.25H10.014A3.264,3.264,0,0,0,6.75,5.514V25.1ZM8.382,22.218,14.911,18.3l6.529,3.917V5.514a1.632,1.632,0,0,0-1.632-1.632H10.014A1.632,1.632,0,0,0,8.382,5.514v16.7Z"
                            fill-rule="evenodd" />
                    </g>
                </svg>
            </div>
            <?php
            echo "<a class='bookmark_content'href='" . $link . "'>" . $post['description'] . "</a>";
            echo "<a class='remove_bookmark' href='?action=remove_mark&collection_id=" . $post['main_collection_id'] . "'></a>";
            echo "</div>";

        }


        if (isset($_GET['action']) && $_GET['action'] == 'remove_mark' && $_GET['collection_id'] != NULL) {
            remove_mark($_GET['collection_id']);
        }

        ?>
        <a href="/intranet/de/knowledgecenter-post/"><button class="show_all_posts">Alle Beiträge ansehen</button></a>
        <?php
    }

    function count_posts($category_id)
    {
        $query = "SELECT knowledgecenter_collection_link.* FROM knowledgecenter_collection_link INNER JOIN main_collection ON main_collection.id = knowledgecenter_collection_link.main_collection_id LEFT JOIN main_collection_mandant_link ON knowledgecenter_collection_link.main_collection_id = main_collection_mandant_link.main_collection_id WHERE knowledgecenter_category_id = " . $category_id . " AND (main_collection.is_archived = 0 OR main_collection.is_archived IS NULL)";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 0) {
            return;
        }
        $count = 0;
        $read = 0;
        while ($posts = @mysqli_fetch_array($result)) {
            $query2 = "SELECT * FROM main_collection_read WHERE main_collection_id = " . $posts['main_collection_id'] . " AND main_contact_id = " . $GLOBALS['main_contact']['id'];
            $result2 = @mysqli_query($GLOBALS['mysql_con'], $query2);
            if (@mysqli_num_rows($result2) == 1) {
                $read++;
            }
            $count++;
        }
        $percent = ($read / $count) * 100;
        $percent = round($percent, 2);
        ?>
        <div class='pct_read'>
            <div class="pct_textcontent">
                <p class="pct"><?= $percent ?>%</p>
                <p class="pct_tag"><?= $read ?>/<?= $count ?> Beiträge</p>
            </div>
            <div class='pct_status' style='width: <?= $percent ?>%'></div>
        </div>
        <?php
    }

    function get_categories($category_id)
    {
        $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"];
        }


        $left_join_main_department = "LEFT JOIN knowledgecenter_category_department_link ON knowledgecenter_category.id = knowledgecenter_category_department_link.knowledgecenter_category_id";
        $left_joint_main_mandant = "LEFT JOIN knowledgecenter_category_mandant_link ON knowledgecenter_category.id = knowledgecenter_category_mandant_link.knowledgecenter_category_id";
        $left_joint_main_role = "LEFT JOIN knowledgecenter_category_role_link ON knowledgecenter_category.id = knowledgecenter_category_role_link.knowledgecenter_category_id";
        $left_joint_main_fachbereich = "LEFT JOIN knowledgecenter_category_fachbereich_link ON knowledgecenter_category.id = knowledgecenter_category_fachbereich_link.knowledgecenter_category_id";
        $left_joint_main_einricht = "LEFT JOIN knowledgecenter_category_einricht_link ON knowledgecenter_category.id = knowledgecenter_category_einricht_link.knowledgecenter_category_id";
        $query = "SELECT DISTINCT knowledgecenter_category.* FROM knowledgecenter_category " . $left_joint_main_mandant . " " . $left_join_main_department . " " . $left_joint_main_fachbereich . " " . $left_joint_main_einricht . " " . $left_joint_main_role . " WHERE active = 1 AND parent_id = " . $category_id . " AND (knowledgecenter_category_department_link.main_department_id IN(" . implode(",", $department) . ") OR knowledgecenter_category_department_link.main_department_id IS NULL) AND (knowledgecenter_category_mandant_link.main_mandant_id IN(" . implode(",", $mandants) . ") OR knowledgecenter_category_mandant_link.main_mandant_id IS NULL) AND (knowledgecenter_category_fachbereich_link.main_fachbereich_id IN(" . implode(",", $fachbereiches) . ") OR knowledgecenter_category_fachbereich_link.main_fachbereich_id IS NULL) AND (knowledgecenter_category_einricht_link.main_einricht_id IN(" . implode(",", $einrichts) . ") OR knowledgecenter_category_einricht_link.main_einricht_id IS NULL) AND (knowledgecenter_category_role_link.main_role_id IN(" . implode(",", $role) . ") OR knowledgecenter_category_role_link.main_role_id IS NULL) ORDER BY sorting ASC";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 0) {
            return;
        }

        ?>

        <?php
        while ($category = @mysqli_fetch_array($result)) {
            $link = get_link_to_navigation(6) . '?category=' . $category['id'];
            ?>
            <a class="kc_category_link category_list_item" href='<?= $link ?>'>
                <div class='kc_category'>
                    <img class='kc_img'
                        src="<?= !empty($category['image']) ? '/userdata' . $category['image'] : '/userdata/01_Basic/platzhalter_bild_kategorie.jpg' ?>">
                    <p class='kc_tags'><?= !empty($category['tags']) ? $category['tags'] : 'Kategorie' ?></p>
                    <h3 class='kc_title'><?= $category['description'] ?></h3>
                    <!-- <?= count_posts($category['id']) ?> -->
                </div>
            </a>
        <?php }

    }

    function get_posts($category_id)
    {

        // $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"];
        }

        $left_join_main_department = "LEFT JOIN main_collection_department_link ON main_collection.id = main_collection_department_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";

        $query = "SELECT DISTINCT main_collection.* FROM main_collection " . $left_joint_main_mandant . " " . $left_join_main_department . " " . $left_joint_main_fachbereich . " " . $left_joint_main_einricht . " " . $left_joint_main_role . " LEFT JOIN knowledgecenter_collection_link ON knowledgecenter_collection_link.main_collection_id = main_collection.id WHERE knowledgecenter_collection_link.knowledgecenter_category_id = $category_id AND knowledgecenter_category_id != 0 AND (main_collection.is_archived = 0 OR main_collection.is_archived IS NULL) AND (main_collection_department_link.main_department_id IN(" . implode(",", $department) . ") OR main_collection_department_link.main_department_id IS NULL) AND (main_collection_mandant_link.main_mandant_id IN(" . implode(",", $mandants) . ") OR main_collection_mandant_link.main_mandant_id IS NULL) AND (main_collection_fachbereich_link.main_fachbereich_id IN(" . implode(",", $fachbereiches) . ") OR main_collection_fachbereich_link.main_fachbereich_id IS NULL) AND (main_collection_einricht_link.main_einricht_id IN(" . implode(",", $einrichts) . ") OR main_collection_einricht_link.main_einricht_id IS NULL) AND (main_collection_role_link.main_role_id IN(" . implode(",", $role) . ") OR main_collection_role_link.main_role_id IS NULL) ORDER BY main_collection.description ASC";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 0) {
            return;
        }
        $query_category = "SELECT * FROM knowledgecenter_category WHERE id = " . $category_id;
        $result_category = @mysqli_query($GLOBALS['mysql_con'], $query_category);
        $category = @mysqli_fetch_array($result_category);

        ?>
        <?php
        while ($post = @mysqli_fetch_array($result)) {
            $link = get_link_to_navigation(14) . get_collection_rewrite($post['description'], $post['id']);
            ?>
            <a class="kc_category_link post_list_item" href='<?= $link ?>'>
                <div class='kc_category'>
                    <img class='kc_img' src='/userdata/01_Basic/platzhalter_bild.jpg'>
                    <p class='kc_tags'>Beitrag</p>
                    <h3 class='kc_title'><?= $post['description'] ?></h3>
                    <!-- <p class="kc_hint">zum Beitrag</p> -->
                </div>
            </a>
        <?php }
        ?>
        <div class='kc_current_category'><?= $category['description'] ?></div>

        <?php
    }


    echo "<div class='kc_group_container'>";
    if (isset($_GET["category"]) || isset($_GET['search'])) {
        echo "<div class='kc_back_button'>";
        echo "<button class='back_button' onclick='history.back()'>Zurück</button>";
        echo "</div>";
    }
    if (!isset($_GET['search'])) {
        echo "<div class='col-xs-12'>";
        echo "<div class='grid_knowledgecenter'>";
        get_categories($category_id);
        get_posts($category_id);
        echo "</div>";
        echo "</div>";
    } else {
        search($_GET['search']);
    }
    // if(!isset($_GET["category"])) {

    // echo "<div class='kc_card_list col-xs-12 col-sm-12 col-md-12 col-lg-4'>";
    //     all_posts();
    //     read_categories();
    //     marked_posts();

    // echo "</div>";
    echo "<div class='my_bookmarks'>";
    bookmarks();
    echo "</div>";
    // echo "<div class='toggleSlide'>";
    // echo "Ansichtswechsel";
    // echo "</div>";
    // }
    echo "</div>";

    function remove_mark($collection_id)
    {
        $query = "DELETE 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);
        ?>
        <script>
            const url = window.location.href.split('?')[0]
            window.location = url;
        </script>
        <?php
    }
} catch (\Throwable $th) {
    echo $th;
}

?>

<script>
    $(document).ready(function () {
        // Überprüfen, ob es category_list_items gibt
        if ($('.grid_knowledgecenter .category_list_item').length === 0) {
            // Wenn keine vorhanden sind, Klasse hinzufügen
            $('.grid_knowledgecenter').addClass('no-categories');
        }
    });
</script>