<?php
require_once(MODULE_PATH . "faq/faq_config.inc.php");

$siteparts     = \DynCom\mysyde\common\classes\Siteparts::get();
$pageIds       = array();
$sitepartCount = array();
$formname      = "form_edit_faq";
$translation   = \DynCom\mysyde\common\classes\Registry::get("translation");

$action = (isset($_GET['action']) ? $_GET['action'] : "");

if ($action != "" && $action != "admin_login") {
    require_once(MODULE_PATH . "faq/edit_faq.inc.php");
    exit();
}


    $faq_group_anzahl    = array();


    $query  = "SELECT id, count(*) AS anzahl FROM main_faq_setup_group GROUP BY id";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    while ($row = @mysqli_fetch_array($result, 1)) {
        $faq_group_anzahl[] = $row['anzahl'];
    }

?>

<div id="mainContent">
    <?php echo current_website_language($site, $language); ?>
    <h1><?php echo get_translation('top_faq'); ?></h1>

    <div class="dashboard_part_left">
        <h2><?php echo get_translation('top_faq'); ?></h2>

        <?php 
            $anzahl_group = count($faq_group_anzahl);
            if ($anzahl_group): ?>
                

                <a class="dashoard_box button_inhalt_collection"
                   href="<?php echo get_menu_link($_GET["level_1"] . "/config", $site, $language); ?>">
                    <span
                        class="dashboard_box_number"><?php echo(isset($anzahl_group) ? $anzahl_group : 0); ?></span>
                    <span class="dashboard_box_description"><?php echo $translation->get("faq_group"); ?></span>
                    <img src="<?php echo PATH_SETUP_ICON_FAQ . "dokumente_2.png"; ?>" />
                </a>
  

        <?php else: ?>

            <?php echo "<div class=\"infobox\">" . $translation->get("no_rows_found") . "</div>"; ?>

        <?php endif; ?>
    </div>

    <div class="dashboard_part_right">
        <h2><?php echo get_translation('last_changed_faq'); ?></h2>

        <form id="<?= $formname ?>" name="<?= $formname ?>" method="post" enctype="multipart/form-data">
            <input type="hidden" class="selected_linklist_row" name="input_id" value="" />

            <div class="requestLoader"></div>
            <div id="page_linklist">
                <?
                $query = "SELECT
        			main_faq.id, 
                    GROUP_CONCAT(' ', IF(main_faq_group_link.active = 1,main_faq_setup_group.description,NULL)) AS '".$translation->get("linked_with")."',
        			main_faq.description AS '" . $translation->get("description") . "',
        			from_unixtime(main_faq.modified_date, '%d.%m.%Y %H:%i:%s') AS '" . $translation->get("changed_on") . "', 
        			main_admin_user.name AS '" . $translation->get("changed_by") . "' 
        		from 
        			main_faq left join main_admin_user
        		ON 
        			main_faq.modified_user = main_admin_user.id
                LEFT JOIN
                    main_faq_group_link 
                ON 
                    main_faq_group_link.main_faq_id = main_faq.id
                LEFT JOIN 
                    main_faq_setup_group
                ON 
                    main_faq_setup_group.id = main_faq_group_link.main_faq_setup_group_id

        		where 
        			(main_faq.main_language_id = " . (int)$GLOBALS["language"]['id'] . ")
                GROUP BY main_faq_group_link.main_faq_id ORDER BY main_faq.modified_date desc limit 20";

                $format = array('option', 'text', 'text', 'text', 'text');
                if ($result = @mysqli_query($GLOBALS['mysql_con'], $query)) {
                    linklist($result, $formname, $format, "input_id", "edit_faq_list");
                }
                ?>
            </div>
        </form>
    </div>