<?php
//Wird benötigt um Enviroment Variable zu holen
session_start();
$currDir = __DIR__;
$rootDir = dirname(dirname($currDir));
$mysydeDir = $rootDir . '/mysyde';

require_once($rootDir .  '/vendor/autoload.php');
require_once($rootDir . "/mysyde/frontend/frontend_functions.inc.php");
 
// $baseDir = rtrim(dirname(dirname(__DIR__,2),'/'));

$envDir = $rootDir . '/config';
$envFilePath = $envDir . '/.env';
if (is_dir($envDir) && file_exists($envFilePath) && is_file($envFilePath) && is_readable($envFilePath)) {
    $dotenv = new \Dotenv\Dotenv($envDir);
    $dotenv->load();
}
 $common = $mysydeDir ."/common/common_functions.inc.php";
require_once($common);

$connEnv = (local_environment()) ? $mysydeDir."/dc.config.php" : $mysydeDir."/dc-server.config.php";

require_once($connEnv);

db_connect();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $mandant_id = $_POST['mandant_id'];
}
selectUser($mandant_id);

function selectUser($mandant_id){ 
    $query              = "SELECT * FROM main_contact WHERE master_mandant_id = " . $mandant_id . " ORDER BY name ASC";
    $result             = @mysqli_query($GLOBALS['mysql_con'], $query);
    ?>
    <option value="">---</option>
    <?
        while ($row = @mysqli_fetch_array($result)) {
            echo "<option value=\"" . $row['id'] . "\">" . $row['name'] . "</option>";
        }
    ?>
<?php } ?>