<?php
$pdo = new PDO("mysql:host=".$GLOBALS['myservername'].";charset=utf8;dbname=';dbname=".$GLOBALS['mydb'], $GLOBALS['mylogin'], $GLOBALS['mypass']);
$GLOBALS["pdo_conn"] = $pdo;
 
function get_teamleader($mandant_id){
    $statement_contact = $GLOBALS["pdo_conn"]->prepare("SELECT * FROM main_contact LEFT JOIN main_contact_department ON main_contact.id = main_contact_department.main_contact_id WHERE main_mandant_id = :main_mandant_id");
    $statement_contact->execute(array(':main_mandant_id' => $mandant_id));
    $res_contact = $statement_contact->fetchAll(PDO::FETCH_ASSOC);
    foreach ($res_contact as $key_contact => $value_contact) {
        if($value_contact['main_role_id'] == 3){
            get_contact($value_contact['image'], $value_contact['name'], $value_contact['email'], $value_contact['phone_no'], 'Teamleiter');
        }
    }
}

function get_ceo($mandant_id){
    $statement_contact = $GLOBALS["pdo_conn"]->prepare("SELECT * FROM main_contact LEFT JOIN main_contact_department ON main_contact.id = main_contact_department.main_contact_id WHERE main_mandant_id = :main_mandant_id");
    $statement_contact->execute(array(':main_mandant_id' => $mandant_id));
    $res_contact = $statement_contact->fetchAll(PDO::FETCH_ASSOC);
    foreach ($res_contact as $key_contact => $value_contact) {
        if($value_contact['main_role_id'] == 4){
            get_contact($value_contact['image'], $value_contact['name'], $value_contact['email'], $value_contact['phone_no'], 'Geschäftsführer');
        }
    }
}

function get_contact($image, $name, $email, $phone_no, $role_name) {
    echo "<div class='group_container'>";
    if($image == ""){
        echo "<div class='img_container'><img class='img-fluid' src='/userdata/intranet/contact/platzhalter.png'></div>";
    }else {
        echo "<div class='img_container'><img class='img-fluid' src='/userdata/intranet/contact/".$image."'></div>";
    }
    echo "<div class='stats_container'>";
    echo "<p class='role'>".$role_name."</p>";
    echo "<h5>".$name."</h5>";
    echo "<p>".$email."</p>";
    echo "<p>".$phone_no."</p>";
    echo "</div>";
    echo "</div>";
}
?>
<div class='firmen-informationen'>
    <?php 
        $tl = get_teamleader($GLOBALS['main_contact']['master_mandant_id']);
        $gf = get_ceo($GLOBALS['main_contact']['master_mandant_id']);
    ?>
</div>