<style>
    .error{
        font-weight: bold;
        color:red;
    }
</style>
<input type="hidden" name="userdata[user_id]" value="[% $userdata.user_id %]">
<input type="hidden" name="save" id="SaveValue" value="1">
<input type="hidden" name="SaveAvatar" id="SaveAvatar" value="1" />
<input type="hidden" name="CropAvatar" id="CropAvatar" value="0" />
<input type="hidden" name="UploadAvatar" id="UploadAvatar" value="0" />
<input type="hidden" name="RemoveAvatar" id="RemoveAvatar" value="0" />
<input type="hidden" name="AvatarPath" id="AvatarPath" value="[% if $AvatarPath %][% $AvatarPath %][% else %]0[% /if %]" />


<div class="form-group row mb-3">

    [% if $errors.name %]<br><span class="error">[% $errors.name %]</span>[% /if %]

    <label class="control-label col-md-3 col-sm-3 col-xs-1cl2">
        [% $user->gettext('Name') %]
        <span class="required">*</span>
    </label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="text" class="form-control" name="userdata[name]"  placeholder="[% $user->gettext('Name') %]" value="[% $userdata.name %]" required="required" />
    </div>
</div>
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">
        [% $user->gettext('Benutzername') %]
        <span class="required">*</span>
    </label>
    

    <div class="col-md-9 col-sm-9 col-xs-12">
        [% if $hasRightToEditOwnProfile %]
            <input type="text" readonly class="form-control-plaintext" value="[% $userdata.username %]">
        [% else %]
            <input type="text" class="form-control" name="userdata[username]"  placeholder="[% $user->gettext('Benutzername') %]" value="[% $userdata.username %]" required="required" />
            [% if $errors.username %]<br><span class="error" style="">[% $errors.username %]</span>[% /if %]
        [% /if %]
    </div>
    
</div>
[% if $Tools->isSennebogen() %]
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">
        [% $user->gettext('ProAlpha Account') %]
    </label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="text" class="form-control" name="userdata[paaccount]"  placeholder="[% $user->gettext('PA Accountkürzel') %]" value="[% $userdata.paaccount %]" />
    </div>
</div>
[% /if %]


<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Email') %]
        <span class="required">*</span>
    </label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        [% if $hasRightToEditOwnProfile %]
            <input type="text" readonly class="form-control-plaintext" value="[% $userdata.email %]">
        [% else %]
            <input type="text" type="email" class="form-control" name="userdata[email]"   value="[% $userdata.email %]" required="required" autocomplete="off" />
            [% if $errors.email %]<br><span class="error">[% $errors.email %]</span>[% /if %]
        [% /if %]
    </div>
</div>
[% if $user->hasRight(1301) || $user->UserID  == $userdata.user_id %]
    <div class="form-group row mb-3">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Neues Passwort') %]
            [% if !$userdata.user_id %]
                <span class="required">*</span>
            [% /if %]
        </label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="password" class="form-control [% if !$userdata.user_id %]required[% /if %]" name="userdata[pwd]"   autocomplete="off" [% if !$userdata.user_id %]required="required"[% /if %] />
            [% if $errors.pwd %]<br><span class="error">[% $errors.pwd %]</span>[% /if %]
        </div>
    </div>
    <div class="form-group row mb-3">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Passwort best&auml;tigen') %]
            [% if !$userdata.user_id %]
                <span class="required">*</span>
            [% /if %]
        </label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="password" class="form-control [% if !$userdata.user_id %]required[% /if %]" name="userdata[verifypwd]"   autocomplete="off" [% if !$userdata.user_id %]required="required"[% /if %] />
            [% if $errors.verifypwd %]<br><span class="error">[% $errors.verifypwd %]</span>[% /if %]
        </div>
    </div>
[% /if %]
[% if $user->hasRight(1006) %]
    <div class="form-group row mb-3">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Gruppe') %]</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <select size="8" class="selectbox required" name="groupid[]" id="groupids" multiple >
                [% html_options options=$groups selected=$userdata.groups %]
            </select>
            <span class="required" title="[% $user->gettext('Mindestens einen Eintrag wählen') %]"></span>
            <span id="LicenceError" class="error" style="display:none;" ><br />[% $user->gettext('Sie können keine weiteren Benutzer als Supporter definieren.<br />Wähle Sie andere Gruppen oder erweiteren Sie die Lizenz.') %]</span>
            [% if $errors.groupid %]<br><span class="error">[% $errors.groupid %]</span>[% /if %]
        </div>
    </div>
[% /if %]
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Sprache') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <select name="userdata[language_type]" size="1" class="selectbox multiple" >
            [% foreach from=$user->getAvailableLanguages() item=language %]
                <option [% if $language == $userdata.language %]selected="selected" [% /if %]value="[% $language %]">[% $language %]</option>
            [% /foreach %]
        </select>
        [% if $errors.language_type %]<br><span class="error">[% $errors.language_type %]</span>[% /if %]
    </div>
</div>


<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Benutzer sperren') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="radio" name="userdata[block]" value="0" [% if !$userdata.block %]checked="checked"[% /if %]> [% $user->gettext('Nein') %]
        <input type="radio" name="userdata[block]" value="1" [% if $userdata.block %]checked="checked"[% /if %]> [% $user->gettext('Ja') %]
    </div>
</div>
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Erh&auml;lt<br /> Emails') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="radio" name="userdata[sendEmail]" value="0" [% if !$userdata.sendemail %]checked="checked"[% /if %]> [% $user->gettext('Nein') %]
        <input type="radio" name="userdata[sendEmail]" value="1" [% if $userdata.sendemail %]checked="checked"[% /if %]> [% $user->gettext('Ja') %]
    </div>
</div>
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Suchfilter merken') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="radio" name="userdata[remfilters]" value="0" [% if !$userdata.remfilters %]checked="checked"[% /if %]> [% $user->gettext('Nein') %]
        <input type="radio" name="userdata[remfilters]" value="1" [% if $userdata.remfilters %]checked="checked"[% /if %]> [% $user->gettext('Ja') %]
    </div>
</div>
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Split Scroll') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="radio" name="userdata[showscrollingareas]" value="0" [% if !$userdata.showscrollingareas %]checked="checked"[% /if %]> [% $user->gettext('Nein') %]
        <input type="radio" name="userdata[showscrollingareas]" value="1" [% if $userdata.showscrollingareas %]checked="checked"[% /if %]> [% $user->gettext('Ja') %]
    </div>
</div>
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Tickets aus Ticketliste in neuem Tab öffnen') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="radio" name="userdata[showticketsinnewtab]" value="0" [% if !$userdata.showticketsinnewtab %]checked="checked"[% /if %]> [% $user->gettext('Nein') %]
        <input type="radio" name="userdata[showticketsinnewtab]" value="1" [% if $userdata.showticketsinnewtab %]checked="checked"[% /if %]> [% $user->gettext('Ja') %]
    </div>
</div>
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Versenden von Teams-Benachrichtigungen') %]</label>
    <div class="col-md-3 col-sm-3 col-xs-12">
        <input type="radio" name="userdata[usemsteamsnotifications]" onclick="ShowHideTeamsSettings(0)" value="0" [% if !$userdata.usemsteamsnotifications %]checked="checked"[% /if %]> [% $user->gettext('Nein') %]
        <input type="radio" name="userdata[usemsteamsnotifications]" onclick="ShowHideTeamsSettings(1)" value="1" [% if $userdata.usemsteamsnotifications %]checked="checked"[% /if %]> [% $user->gettext('Ja') %]
    </div>
    [% if !$HideGenerateTokenButton || $userdata.usemsteamsnotifications %]<span class="btn btn-outline-secondary col-md-3 col-sm-3 col-xs-12" id="btnGenerateToken" onclick="GenerateTeamsToken()">[% $user->gettext('Teams Token generieren') %]</span>[% /if %]
</div>
<div class="form-group row mb-3" id="divTeamsMail" [% if !$userdata.usemsteamsnotifications %]style="display:none"[% /if %]>
    <label class="control-label col-md-3 col-sm-3 col-xs-12">
        [% $user->gettext('EMail-Adresse in Teams') %]
    </label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <input type="text" class="form-control" name="userdata[msteamsemailaddress]"  placeholder="[% $user->gettext('EMail-Adresse in Teams') %]" value="[% $userdata.msteamsemailaddress %]" />
    </div>
</div>

<div class="form-group row mb-3">
    <label class="col-lg-3 control-label" for="DefStartPage">[% $user->gettext('Standardseite nach Anmeldung') %]</label>

    <div class="col-lg-9">
        <select  size="1" class="selectbox required multiple" name="userdata[landingpage]">
            <option value="0" [% if $userdata.landingpage =="0" %]selected="selected"[% /if %]>[% $user->gettext('-- default --') %]</option>
            <option value="1" [% if $userdata.landingpage =="1" %]selected="selected"[% /if %]>[% $user->gettext('Startseite') %]</option>
            <option value="2" [% if $userdata.landingpage =="2" %]selected="selected"[% /if %]>[% $user->gettext('Ticketliste') %]</option>
            <option value="3" [% if $userdata.landingpage =="3" %]selected="selected"[% /if %]>[% $user->gettext('Eigene offene Tickets') %]</option>
            <option value="4" [% if $userdata.landingpage =="4" %]selected="selected"[% /if %]>[% $user->gettext('Neues Ticket') %]</option>
            [% if $user->Security->Calendar %]
                <option value="5" [% if $userdata.landingpage =="5" %]selected="selected"[% /if %]>[% $user->gettext('Kalender') %]</option>
            [% /if %]
            [% if $user->Security->Workflow %]
                <option value="6" [% if $userdata.landingpage =="6" %]selected="selected"[% /if %]>[% $user->gettext('Workflow starten') %]</option>
            [% /if %]
            [% if $user->Security->Backlog %]
                <option value="7" [% if $userdata.landingpage =="7" %]selected="selected"[% /if %]>[% $user->gettext('Backlogliste') %]</option>
            [% /if %]
            <option value="8" [% if $userdata.landingpage =="7" %]selected="selected"[% /if %]>[% $user->gettext('Projektliste') %]</option>
        </select>
    </div>
</div>

[% if $user->Security->Projects %]
    <div class="form-group row mb-3">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Kostengruppe für Projekte') %]</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <select name="userdata[CostGroupID]" class="selectbox multiple" style="width:260px">
                [% html_options options=$CostGroups selected=$userdata.costgroupid %]
            </select>
        </div>
    </div>
[% /if %]
<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Signatur') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <textarea name="userdata[signatur]" id="signatur" style="width:100%;height:10em;" placeholder="[% $defaultSignatur %]">[% $userdata.signatur %]</textarea>
    </div>
</div>

<div class="form-group row mb-3">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Anmerkung') %]</label>
    <div class="col-md-9 col-sm-9 col-xs-12">
        <textarea name="userdata[remarktext]" id="remarktext" style="width:100%;height:10em;" placeholder="[% $user->gettext('Besondere Anmerkung zu diesem Benutzer') %]">[% $userdata.remarktext %]</textarea>
    </div>
</div>
[% if $smarty.const.SHOWAVATAR %] 
    [% if $AvatarPath %]
        <div class="form-group row mb-3">
            <label class="control-label col-md-3 col-sm-3 col-xs-12"></label>
            <div class="col-md-9 col-sm-9 col-xs-12">
                <div id="avatarDiv">

                    [% if !$userdata.croppedavatar || $UpdateAvatar %]
                        <a href="[% if !$AvatarFromURL %]index.php?module=user&event=cropImage&userid=[% $userdata.user_id %]&image=[% $AvatarPath%][% else %]#[% /if %]" class="[% if !$AvatarFromURL %]openInBigIFrameModal[% /if %]"><div class="img-circular">
                            </div></a>
                        [% else %]
                        <a href="[% if !$AvatarFromURL %]index.php?module=user&event=cropImage&userid=[% $userdata.user_id %]&image=[% $AvatarPath%][% else %]#[% /if %]" class="[% if !$AvatarFromURL %]openInBigIFrameModal[% /if%]"><img src="index.php?module=upload&class=download&event=ShowImage&name=[%  $userdata.croppedavatar %]" class="hm-avatar-big" /></a>
                        [% /if %]
                </div>

            </div>
        </div>
        <style>
            .img-circular{
                width: 200px;
                height: 200px;
                background-image: url('index.php?module=upload&class=download&event=ShowImage&name=[%  $AvatarPath %]');
                background-size: cover !important;
                background-position: center;
                background-repeat: no-repeat;
                display: block;
                border-radius: 100px;
                -webkit-border-radius: 100px;
                -moz-border-radius: 100px;
            }
        </style>
    [% /if %]

    <div class="form-group row mb-3" id="AvatarForm" [% if $AvatarFromURL %]style='display:none;'[% /if %]>
        <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Avatar') %]</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <div class="input-group">
                <input type="file" name="Avatar" class="form-control" [% if $AvatarFromURL %]disabled[% /if %]>
                <span class="input-group-text btn btn-outline-primary" onclick="uploadImage();">[% $user->gettext('Hochladen')%]</span>
                <span class="input-group-text btn btn-outline-primary" onclick="deleteImage();">[% $user->gettext('Löschen')%]</span>
            </div>
            <p><a href="#" id="showAvatarForm1">[% $user->gettext('...oder Avatar per URL anlegen')%]</a></p> 
        </div>
    </div>

    <div class="form-group row mb-3" id="AvatarURLForm" [% if !$AvatarFromURL %]style='display:none;'[% /if %]>
        <label class="control-label col-md-3 col-sm-3 col-xs-12">[% $user->gettext('Avatar-URL') %]</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="text" class="form-control" name="AvatarURL" [% if $AvatarFromURL %]value="[% $AvatarPath %]"[% /if %]  [% if !$AvatarFromURL %]disabled[% /if %]>
            <p><a href="#" id="showAvatarForm2">[% $user->gettext('...oder Avatar hochladen')%]</a></p> 
        </div>
    </div>
[% /if %]
<div class="ln_solid"></div>

<script>
    function uploadImage() {
        $('#SaveAvatar').val(1);
        $('#UploadAvatar').val(1);
        $('#SaveValue').val(0);
        $('#hm').submit();
    }

    function deleteImage() {
        bootbox.confirm('[% $user->gettext('Möchten Sie das Avatar wirklich löschen?') %]', function (result) {
            if (result) {
                $('#SaveAvatar').val(0);
                $('#UploadAvatar').val(0);
                $('#RemoveAvatar').val(1);
                $('#SaveValue').val(0);
                $('#hm').submit();
            }
        });

    }

    /**
     * u
     */
    function updateAvatar(avatar) {
        $('#avatarDiv').html('<a href="[% if !$AvatarFromURL %]index.php?module=user&event=cropImage&userid=[% $userdata.user_id %]&image=[% $AvatarPath%][% else %]#[% /if %]" id="newAvatar" class="openInBigIFrameModal"><img src="index.php?module=upload&class=download&event=ShowImage&name=' + avatar + '" class="hm-avatar-big" /></a>');
        $("#newAvatar").on("click", function (e) {
            e.preventDefault();
            url = $(this).attr('href');

            $("#myBigIFrameModal").modal("show");
        });

    }

    function cropImage() {
        $('#SaveAvatar').val(1);
        $('#CropAvatar').val(1);
        $('#UploadAvatar').val(1);
        $('#SaveValue').val(0);
        $('#hm').submit();
    }

    function closeIFrame() {
        $("#myBigIFrameModal").modal('hide');
    [% if $event == 'create' %]
        cropImage();
    [% else %]
        //window.location.href = window.location.href;
    [% /if %]

    }

    $('#showAvatarForm2').on("click", function (e) {
        $('#AvatarURLForm').hide();
        $('#AvatarURLForm :input').prop('disabled', true);
        $('#AvatarForm :input').prop('disabled', false);
        $('#AvatarForm').show();
    });

    $('#showAvatarForm1').on("click", function (e) {
        $('#AvatarForm').hide();
        $('#AvatarForm :input').prop('disabled', true);
        $('#AvatarURLForm :input').prop('disabled', false);
        $('#AvatarURLForm').show();
    })

    function GenerateTeamsToken()
    {
        $.get('GetTeamsCode', {}, function (res)
        {
            window.open(res, '_self');
        });
    }

    function ShowHideTeamsSettings(Value)
    {
        if (Value == 0)
        {
            $('#btnGenerateToken').hide();
            $('#divTeamsMail').hide();
        } else
        {
            $('#btnGenerateToken').show();
            $('#divTeamsMail').show();
        }
    }
</script>
