<?php
$translation = \DynCom\mysyde\common\classes\Registry::get("translation");

function create_contact_department($contact_id) {
    $translation = \DynCom\mysyde\common\classes\Registry::get("translation");
    $query = "SELECT * FROM main_contact_department LEFT JOIN main_mandant ON main_contact_department.main_mandant_id = main_mandant.id WHERE main_contact_id = ".$contact_id. " AND main_contact_department.active = 1";
    $result = @mysqli_query($GLOBALS['mysql_con'], $query);
    while($contact = @mysqli_fetch_array($result)) {
        $mandant_id = $contact['main_mandant_id'];    
    ?>
    <div class="contact_department_wrapper">
        <h4><?= $contact['description'] ?></h4>
        <?php 
            $query_department = "SELECT DISTINCT main_department.id, main_department.description AS name FROM main_department LEFT JOIN main_department_mandant_link ON main_department.id = main_department_mandant_link.main_department_id WHERE main_mandant_id = ".$mandant_id;
            $query_role = "SELECT id,description AS name FROM main_role";
        ?>
        <?= input_select_from_sql($translation->get("top_department"), "input_department_".$mandant_id, $query_department, $contact['main_department_id'], TRUE, FALSE, "", TRUE); ?>
        <?= input_select_from_sql($translation->get("top_role"), "input_role_".$mandant_id, $query_role, $contact['main_role_id'], TRUE, FALSE, "", TRUE); ?>
        <?= input($translation->get("phone_no"), "input_phone_no_".$mandant_id, "text", $contact["phone_no"], 100); ?>
        <?= input($translation->get("email"), "input_email_".$mandant_id, "text", $contact["email"], 100); ?>
    </div>
    <?php }
}




?>
<div class="edit_profil_modal">
    <div class="profil_modal_content">
        <div class="profil_modal_container">
            <div id="closeoverlay" onclick="close_cardform();"></div>
            <div class="modal_sidebar">
                <div class="profil_modal_titel">
                    <h2><?= $translation->get("edit_profil_settings") ?></h2>
                </div>
                <p>Hier können die Einstellungen für das Profil bearbeitet werden.</p>
                <div class="overlay_sidebar_steps">
                    <ol>
                        <li class="step"><a href="#imgs"> Profil</a></li>
                        <!-- <li class="step"><a href="#gift"> Geburtstag</a></li> -->
                    </ol>
			    </div>


            </div>
            <div class="modal_section_wrapper">
                <div class="modal_section">
                    <form method='post' enctype="multipart/form-data">
                        <div class="basic_info_group form_section">
 
                        <div class="image_group form_section">
                            <h3 id="imgs">Profil</h3>
                            <p class="hint">Bitte beachten Sie die Netiquette der AWO bei der Auswahl Ihres Profil- und Hintergrundbildes. Verwenden Sie für das Profilbild ein gewöhnliches Porträtfoto, das professionell wirkt.</p>
                            <div class="image_group_inputs">
                                <div class="form_group">
                                    <?= input("Profilbild", "input_image", "file", $contact["image"]); ?>
                                    <?php
                                    $valFile = '';
                                        if($contact['image'] != '' && $contact['image'] != NULL){
                                            $valFile = $contact['image'];
                                        }
                                        ?>
                                    <?= input($translation->get("image"), "image_old", "hidden", $valFile) ?>
                                    <?php
                                        if($contact["image"] != NULL && $contact["image"] != ''){
                                            echo "<div class='img_container'>";
                                            echo "<img class='img-fluid' src='/userdata/intranet/contact/".$contact["image"]."'>";
                                            echo "</div>";

                                        }
                                    ?>
                                </div>

                                <div class="form_group">
                                    <?= 
                                    // input($translation->get("background_image"), "input_header_image", "file", $contact["header_img"]);
                                        $valFile = '';
                                        if($contact['header_img'] != '' && $contact['header_img'] != NULL){
                                            $valFile = $contact['header_img'];
                                        }
                                        ?>
                                    <!-- <?= input($translation->get("background_image"), "bg_image_old", "hidden", $valFile) ?> -->
                                    <?php
                                        // if($contact["header_img"] != NULL && $contact["header_img"] != ''){
                                        //     echo "<div class='img_container'>";
                                        //     echo "<img class='img-fluid' src='/userdata/intranet/contact/".$contact["header_img"]."'>";
                                        //     echo "</div>";

                                        // }
                                    ?>
                                </div>
                            </div>
                        </div>

                        <!-- <div class="birthday_group form_section">
                            <h3 id="gift">Geburtstag</h3>
                            <div class="birthday_group_inputs">
                                <div class="form_group">
                                    <?php
                                        $types = [
                                            '0' => $translation->get("birthday_hide"),
                                            '1' => $translation->get("birthday_hide_age"),
                                            '2' => $translation->get("birthday_show"),
                                        ];
                                        $preselect = 1;
                                        if(isset($contact['birthday_state']) ){
                                            $preselect = $contact['birthday_state'];
                                        }
                                    ?>
                                    <?= input_select($translation->get("birthday_state"), "input_birthday_state", $values = array_keys($types), $value_names = array_values($types), $preselect, FALSE, FALSE); ?>
                                </div>
                                <div class="form_group">
                                    <?= input($translation->get("birthday"), "input_birthday", "date", $contact["birthday"]) ?>
                                </div>
                            </div>
                        </div> -->

                        <div class="form_toolbar">
                            <input class="submit_button"type='submit' name='input_submit' value='Speichern'>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

