<?
//Wird benötigt um Enviroment Variable zu holen
$currDir = __DIR__;
$rootDir = dirname(dirname($currDir));
$dcDir = $rootDir . '/dc';
require_once($rootDir .  '/vendor/autoload.php');
$baseDir = rtrim(dirname(__DIR__,2),'/');
$envDir = $baseDir . '/config';
$envFilePath = $envDir . '/.env';
if (is_dir($envDir) && file_exists($envFilePath) && is_file($envFilePath) && is_readable($envFilePath)) {
    $dotenv = new \Dotenv\Dotenv($envDir);
    $dotenv->load();
}

require_once("../../mysyde/common/common_functions.inc.php");
require_once((local_environment()) ? "../../mysyde/dc.config.php" : "../../mysyde/dc-server.config.php");
db_connect();

/* ++ DuP breadcrumb mediaoslutions GmbH */
// Notwendig für Ajax 

if ($_POST['search'] != '') {

    $txt = replace_umlaut($_POST['search']);
    
    $query = "SELECT * FROM main_faq_line WHERE
             MATCH(text1, text2, hashtags) AGAINST('+*".mysqli_real_escape_string($GLOBALS['mysql_con'],$txt)."*' IN BOOLEAN MODE)";
   
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);

    echo "\n<div class=\"faq_group_container\">\n";
    echo "<div class=\"faq_headline\"><h2>Suchergebnisse</h2></div>\n";

    if (@mysqli_num_rows($result) > 0) {

        while ($questions = @mysqli_fetch_array($result)) {
            echo "<div class=\"faq_question_box\"><h3>{$questions[text1]}</h3></div>\n<div class=\"faq_answer_box\">{$questions['text2']}</div>";
        }

    } else {
        echo "Keine Ergebnisse";
    }

    echo "\n</div>\n";
}



?>

<script>
    
$(".search_result .faq_question_box").click(function(){
    $(this).toggleClass("active"),$(this).next(".faq_answer_box").slideToggle("slow");
})

$(".faq_question_box").click(function() {
    $(this).toggleClass("active"),
    $(this).next(".faq_answer_box").slideToggle("slow")
})

</script>
