<mt:setvar name="edit_author" value="1">
<$mt:setvar name="position_actions_bottom" value="1"$>
<mt:if name="new_object">
    <mt:setvar name="page_title" value="<__trans phrase="Create User">">
    <mt:else>
      <mt:if name="nickname">
        <mt:setvarblock name="page_title_name"><mt:var name="nickname" escape="html"></mt:setvarblock>
      <mt:else>
        <mt:setvarblock name="page_title_name"><mt:var name="name" escape="html"></mt:setvarblock>
      </mt:if>    
      <mt:setvarblock name="page_title"><__trans phrase="Edit Profile"></mt:setvarblock>
    </mt:if>
<mt:setvarblock name="related_content">
    <$mtapp:PageActions$>
</mt:setvarblock>
<mt:setvarblock name="system_msg" id="system_msg">
<mt:if name="saved">
    <mtapp:statusmsg
        id="saved"
        class="success">
        <__trans phrase="This profile has been updated.">
    </mtapp:statusmsg>
</mt:if>
<mt:if name="recovered">
    <mtapp:statusmsg
        id="recovered"
        class="success">
        <__trans phrase="A new password has been generated and sent to the email address [_1]." params="<mt:var name="email" escape="html">">
    </mtapp:statusmsg>
</mt:if>
<mt:if name="error">
    <mtapp:statusmsg
        id="generic-error"
        class="error">
        <mt:var name="error">
    </mtapp:statusmsg>
</mt:if>
</mt:setvarblock>

<mt:setvarblock name="html_head" append="1">
    <script type="text/javascript" src="<$mt:var name="static_uri"$>js/tc/client.js"></script>
</mt:setvarblock>

<mt:setvarblock name="related_content">
    <mt:unless name="new_object">
        <mtapp:widget
            id="user-properties"
            label="<__trans phrase="User properties">">
            <mt:include name="include/users_content_nav.tmpl">
        </mtapp:widget>
    </mt:unless>
</mt:setvarblock>

<mt:include name="include/header.tmpl">

<script type="text/javascript">
/* <![CDATA[ */
function reveal_api_password() {
    var pw = getByID("api_password");
    alert("<__trans phrase="Your web services password is currently">: " + pw.value);
    return false;
}
function tagDelimChoice(sel) {
    if (sel.selectedIndex == 2) {
        show("tag_delim_input");
        var el = getByID("tag_delim_input");
        if (el) el.focus();
    } else {
        hide("tag_delim_input");
    }
}

function passwordResetConfirm() {
    var username = '<mt:var name="name" escape="js">';
    var email = '<mt:var name="email" escape="js">';
    if (confirm('<__trans phrase="_WARNING_PASSWORD_RESET_SINGLE" params="'+username+'%%'+email+'">')) {
        document.forms['recover'].submit();
    }
}
function toggleDisabled( state ){
    if (state == 1) {
        state = false;
    } else if (state == 2) {
        state = true;
    }
    var elements = TC.getElementsByClassName('state_change');
    for (var i=0; i < elements.length; i++) {
        elements[i].disabled = state;
    }
}
function togglePerms(c, a) {
    if (a == '') {
        return;
    }

    if (c.checked) {
        jQuery(a).each(function(){
            this.checked = true;
            this.disabled = true;
        });
    } else {
        jQuery(a).each(function(){
            this.checked = false;
            this.disabled = false;
        });
    }
}

function removeUserpic() {
    var param = '__mode=remove_userpic'
        + '&user_id=<mt:var name="id" escape="url">'
        + '&magic_token=<mt:var name="magic_token">';
    var params = { uri: '<mt:var name="script_url">', method: 'POST', arguments: param, load: removedUserpic };
    TC.Client.call(params);
}

function removedUserpic(c) {
    var res = c.responseText;
    if (res != 'success') {
        message = '<__trans phrase="Error occurred while removing userpic." escape="js">';
        showMsg(message, 'ajax-message', 'error');
    }

    getByID('userpic_asset_id').value = '0';
    if (!DOM.hasClassName('userpic-preview', 'hidden'))
       toggleHidden('userpic-preview');
    if (!DOM.hasClassName('remove-userpic', 'hidden'))
       toggleHidden('remove-userpic');
    return false
}

function init() {
    var c = document.forms['profile'].elements['can_administer'];
    if (c.checked)
        document.forms['profile'].elements['can_administer'].onclick();
}

TC.attachLoadEvent(init);
/* ]]> */
</script>

        <form name="profile" id="profile" method="post" action="<mt:var name="script_url">">
            <input type="hidden" name="__mode" value="save" />
            <input type="hidden" name="_type" value="author" />
            <input type="hidden" name="return_args" value="<mt:var name="return_args" escape="html">" />
            <input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />
<mt:if name="editing_other_profile">
            <input type="hidden" name="_type" value="author" />
</mt:if>
<mt:if name="id">
            <input type="hidden" name="id" value="<mt:var name="id" escape="html">" />
</mt:if>
<mt:if name="new_object">
            <input type="hidden" id="status" name="status" value="1" />
</mt:if>

            <fieldset>
                <h3><__trans phrase="Profile"></h3>
<mt:if name="editing_other_profile">
    <mt:if name="editing_other_profile">
        <mt:if name="status_pending">
            <$mt:setvar name="user_status" value="user-status-pending"$>
        <mt:else>
            <mt:unless name="status_enabled">
                <$mt:setvar name="user_status" value="user-status-disabled"$>
            </mt:unless>
        </mt:if>
    </mt:if>
    <mtapp:setting
        id="status"
        label="<__trans phrase="_USER_STATUS_CAPTION">"
        label_class="left-label <$mt:var name="user_status"$>"
        hint="<__trans phrase="Status of user in the system. Disabling a user prevents that person from using the system but preserves their content and history.">">
    <select name="status" id="status" class="half-width" onchange="toggleDisabled(this.value);">
        <option <mt:if name="status_enabled">selected="selected"</mt:if> value="1"><__trans phrase="_USER_ENABLED"></option>
        <mt:if name="status_pending"><option selected="selected" value="3"><__trans phrase="_USER_PENDING"></option></mt:if>
        <option <mt:unless name="status_enabled"><mt:unless name="status_pending">selected="selected"</mt:unless></mt:unless> value="2"><__trans phrase="_USER_DISABLED"></option>
    </select>
    </mtapp:setting>
</mt:if>

<mtapp:setting
    id="name"
    required="1"
    label="<__trans phrase="Username">"
    hint="<__trans phrase="The username used to login.">">
    <input type="text" name="name" id="name" class="full-width" value="<mt:var name="name" escape="html">" <mt:unless name="auth_mode_mt"><mt:unless name="new_user_external_auth">disabled="disabled"</mt:unless></mt:unless> /><mt:unless name="auth_mode_mt"><mt:unless name="new_user_external_auth"><input name="name" type="hidden" value="<mt:var name="name" escape="html">" /></mt:unless></mt:unless>
</mtapp:setting>

<mt:if name="external_id"><mt:if name="show_external_id">
    <mtapp:setting
        id="external_id"
        label="<__trans phrase="External user ID">"
        content_class="field-content-text"
        hint="">
            <mt:var name="external_id" escape="html">
    </mtapp:setting>
</mt:if></mt:if>

<mt:unless name="new_user_external_auth">
    <mtapp:setting
        id="nickname"
        required="1"
        label="<__trans phrase="Display Name">"
        show_hint="1"
        hint="<__trans phrase="The name displayed when content from this user is published.">">
        <input type="text" name="nickname" id="nickname" class="full-width" value="<mt:var name="nickname" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
        id="email"
        required="$auth_mode_mt"
        label="<__trans phrase="Email Address">"
        hint="<__trans phrase="The email address associated with this user.">">
        <input type="text" name="email" id="email" class="full-width" value="<mt:var name="email" escape="html">" />
    </mtapp:setting>

    <mtapp:setting
        id="url"
        label="<__trans phrase="Website URL">"
        show_hint="1"
        hint="<__trans phrase="This User's website (e.g. http://www.movabletype.com/).  If the Website URL and Display Name fields are both populated, Movable Type will by default publish entries and comments with bylines linked to this URL.">">
        <input type="text" name="url" id="url" class="full-width" value="<mt:var name="url" escape="html">" />
    </mtapp:setting>

<mt:if name="id">
    <mt:if name="can_use_userpic">
    <mtapp:setting
        id="userpic_asset_id"
        label="<__trans phrase="Userpic">"
        content_class="field-content-text"
        hint="<__trans phrase="The image associated with this user.">">
        <span id="userpic-preview"<mt:unless name="userpic"> class="hidden"</mt:unless>>
            <span id="userpic-preview-userpic"><mt:var name="userpic"></span>
            <br />
        </span>
        <a href="<mt:var name="script_url">?__mode=list_asset&amp;_type=asset&amp;edit_field=userpic_asset_id&amp;blog_id=0&amp;dialog_view=1&amp;filter=userpic&amp;filter_val=<mt:var name="id" escape="url">&amp;next_mode=asset_userpic&amp;upload_mode=upload_userpic" class="mt-open-dialog"><__trans phrase="Select Userpic"></a>
        <input name="userpic_asset_id" id="userpic_asset_id" type="hidden" value="<mt:var name="userpic_asset_id" default="0" escape="html">" />
        <span id="remove-userpic"<mt:unless name="userpic"> class="hidden"</mt:unless>>
            <br />
            <a href="javascript:void(0)" onclick="removeUserpic()"><__trans phrase="Remove Userpic"></a>
            <span id="ajax-message"></span>
        </span>
    </mtapp:setting>
    </mt:if>
</mt:if>

    <mt:if name="can_modify_password">
        <mt:unless name="new_object">
            <mtapp:setting
                id="show_password"
                label="<__trans phrase="Password">"
                content_class="field-content-text">
                <a href="#" id="change-password-link"><__trans phrase="Change Password"></a>
            </mtapp:setting>
        </mt:unless>
        <div id="password-fields"<mt:unless name="new_object"> style="display: none;"</mt:unless>>
        <mt:unless name="new_object">
            <mt:if name="is_me">
                <mtapp:setting
                    id="old_pass"
                    label="<__trans phrase="Current Password">"
                    hint="<__trans phrase="Existing password required to create a new password.">">
                    <input type="password" name="old_pass" value="" id="old_pass" />
                </mtapp:setting>
            </mt:if>
        </mt:unless>

        <mt:if name="new_object">
            <mt:setvar name="password_required" value="1">
            <mt:setvar name="password_prompt" value="<__trans phrase="Initial Password">">
            <mt:setvar name="password_hint" value="<__trans phrase="Enter preferred password.">">
        <mt:else>
            <mt:setvar name="password_required" value="0">
            <mt:setvar name="password_prompt" value="<__trans phrase="New Password">">
            <mt:setvar name="password_hint" value="<__trans phrase="Enter the new password.">">
        </mt:if>
        <mtapp:setting
            id="pass"
            label="$password_prompt"
            required="$password_required"
            hint="$password_hint">
            <input type="password" name="pass" id="pass" value="" />
        </mtapp:setting>
        <mtapp:setting
            id="pass_verify"
            label="<__trans phrase="Confirm Password">"
            required="$password_required"
            hint="<__trans phrase="Repeat the password for confirmation.">">
            <input type="password" name="pass_verify" id="pass_verify" value="" />
        </mtapp:setting>
        <mt:unless name="new_object">
            <mt:if name="hint">
                <mtapp:setting
                    id="hint"
                    required="0"
                    label="<__trans phrase="Password recovery word/phrase">"
                    hint="<__trans phrase="This word or phrase is not used in the password recovery.">">
                    <input name="hint" id="hint" value="<mt:var name="hint" escape="html">" />
                </mtapp:setting>
            </mt:if>
        </mt:Unless>
        </div>
    </mt:if>

            </fieldset>
            <fieldset>
                <h3><__trans phrase="Preferences"></h3>

    <mtapp:setting
        id="preferred_language"
        label="<__trans phrase="Language">"
        show_hint="1"
        hint="<__trans phrase="Display language for the Movable Type interface.">">
        <select name="preferred_language" id="preferred_language" class="se"><mt:loop name="languages">
            <option value="<mt:var name="l_tag">"<mt:if name="l_selected"> selected="selected"</mt:if>><mt:var name="l_name"></option></mt:loop>
        </select>
    </mtapp:setting>

    <mtapp:setting
        id="text_format"
        label="<__trans phrase="Text Format">"
        show_hint="1"
        hint="<__trans phrase="Default text formatting filter when creating new entries and new pages.">">
        <select name="text_format" id="text_format" class="se">
        <mt:loop name="text_filters">
            <option value="<mt:var name="key">"<mt:if name="selected"> selected="selected"</mt:if>><mt:if name="key" eq="0"><__trans phrase="(Use Website/Blog Default)"><mt:else><mt:var name="label" escape="html"></mt:if></option>
        </mt:loop>
        </select>
    </mtapp:setting>

    <mtapp:setting
        id="tag_delim"
        label="<__trans phrase="Tag Delimiter">"
        show_hint="1"
        hint="<__trans phrase="Preferred method of separating tags.">">
        <select name="tag_delim" id="tag_delim" class="se">
            <option value="comma"<mt:if name="auth_pref_tag_delim_comma"> selected="selected"</mt:if>><__trans phrase="Comma"></option>
            <option value="space"<mt:if name="auth_pref_tag_delim_space"> selected="selected"</mt:if>><__trans phrase="Space"></option>
        </select>
    </mtapp:setting>
</mt:unless>

<mt:if name="is_me">
    <mtapp:setting
        id="api_password"
        label="<__trans phrase="Web Services Password">"
        hint="<__trans phrase="For use by Activity feeds and with XML-RPC and Atom-enabled clients.">">
        <input type="password" name="api_password" id="api_password" class="full-width" value="<mt:var name="api_password" escape="html">" />
        <a href="javascript:void(0)" onclick="return reveal_api_password()"><__trans phrase="Reveal"></a>
    </mtapp:setting>
</mt:if>
            </fieldset>

            <fieldset>
                <h3><__trans phrase="System Permissions"><a href="javascript:void(0)" onclick="return openManual('author_permissions', 'introduction')" class="help-link">?</a></h3>
    <mtapp:setting
        id="system_permissions"
        label="<__trans phrase="Permissions">"
        content_class="field-content-text"
        show_label="0">
        <ul class="inline-list">
        <mt:loop name="loaded_permissions">
            <li><input name="<mt:var name="id">" id="<mt:var name="id">" type="checkbox" value="1"<mt:if name="can_do"> checked="checked"</mt:if> <mt:unless name="new_object"><mt:unless name="editing_other_profile">disabled="disabled"</mt:unless></mt:unless> onclick="togglePerms(this, '<mt:var name="children">')" /> <label for="<mt:var name="id">"><mt:var name="label"></label></li>
        </mt:loop>
        </ul>
    </mtapp:setting>
            </fieldset>

<mt:if name="new_object">
            <fieldset>
    <mtapp:setting
        id="create_user_blog"
        label="<__trans phrase="Options">"
        content_label="field-content-text"
        hint="<__trans phrase="Create personal blog for user">"
        show_hint="0">
        <label for="create_personal_weblog">
            <input type="checkbox" id="create_personal_weblog" name="create_personal_weblog" <mt:if name="create_personal_weblog">checked="checked"<mt:else>disabled="disabled"</mt:if> />
            <__trans phrase="Create personal blog for user">
        </label>
    </mtapp:setting>
            </fieldset>
</mt:if>
<mt:setvarblock name="action_buttons">
    <mt:if name="new_object">
    <button
        type="submit"
        accesskey="s"
        title="<__trans phrase="Create User (s)">"
        class="create action primary-button"
        ><__trans phrase="Create User"></button>
    <mt:else>
    <button
        type="submit"
        accesskey="s"
        title="<__trans phrase="Save changes to this author (s)">"
        class="save action primary-button"
        ><__trans phrase="Save Changes"></button>
    </mt:if>
</mt:setvarblock>
<mt:include name="include/actions_bar.tmpl" bar_position="bottom" hide_pager="1" settings_bar="1">
        </form>

<mt:if name="auth_mode_mt">
    <mt:unless name="can_modify_password">
        <mt:unless name="new_object">
        <form name="recover" method="post" action="<mt:var name="script_url">">
            <input type="hidden" name="__mode" value="recover_profile_password" />
            <input type="hidden" name="author_id" value="<mt:var name="id" escape="html">" />
            <input type="hidden" name="return_args" value="<mt:var name="return_args" escape="html">" />
            <input type="hidden" name="magic_token" value="<mt:var name="magic_token">" />

            <fieldset class="pkg">
                <h3><__trans phrase="Password Recovery"></h3>
                <p><__trans phrase="_USAGE_PASSWORD_RESET" params="<mt:var name="email" escape="html">"></p>
                <div style="text-align: center">
                    <input class="state_change" onclick="passwordResetConfirm()" type="button" value="<__trans phrase="Initiate Password Recovery">" <mt:unless name="status_enabled">disabled</mt:unless> />
                </div>
            </fieldset>
        </form>
        </mt:unless>
    </mt:unless>
</mt:if>

<mt:setvarblock name="jq_js_include" append="1">
<mt:unless name="new_object">
    jQuery('#change-password-link').click(function(event) {
        jQuery(this).parents('#show_password-field').next('#password-fields').toggle();
        jQuery(this).parents('#show_password-field').hide();
        event.preventDefault();
    });
</mt:unless>
</mt:setvarblock>

<mt:include name="include/footer.tmpl">
