{% extends "layout_default.phtml" %}

{% block meta_title %}{{ 'Profile'|trans }}{% endblocK %}

{# block top_content %}
<div class="title">
    <h5>Manage your profile</h5>
</div>
{% endblock #}

{% block content %}
<div class="widget simpleTabs">
    <ul class="tabs">
        <li><a href="#tab-profile">{{ 'Profile'|trans }}</a></li>
        <li><a href="#tab-password">{{ 'Change password'|trans }}</a></li>
        <li><a href="#tab-api">{{ 'API'|trans }}</a></li>
        <li><a href="#tab-gravatar">{{ 'Gravatar'|trans }}</a></li>
    </ul>

    <div class="tab_container">
        <div id="tab-profile" class="tab_content nopadding">
            <form method="post" action="{{ 'api/admin/profile/update'|link }}" class="mainForm api-form" data-api-msg="{{ 'Profile updated'|trans }}">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{{ 'Name'|trans }}</label>
                        <div class="formRight">
                            <input type="text" name="name" value="{{profile.name}}" required="required"/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Email'|trans }}</label>
                        <div class="formRight">
                            
                            <input type="text" name="email" value="{{profile.email}}" required="required"/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Signature'|trans }}</label>
                        <div class="formRight">
                            <textarea name="signature" cols="5" rows="3">{{profile.signature}}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <input type="submit" value="{{ 'Update profile'|trans }}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>
        
        <div id="tab-password" class="tab_content nopadding">
            <form method="post" action="{{ 'api/admin/profile/change_password'|link }}" class="mainForm api-form" data-api-msg="{{ 'Password changed'|trans }}">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{{ 'Password'|trans }}</label>
                        <div class="formRight">
                            <input type="password" name="password" value="" required="required"/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <div class="rowElem">
                        <label>{{ 'Password confirm'|trans }}</label>
                        <div class="formRight">
                            <input type="password" name="password_confirm" value="" required="required"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <input type="submit" value="{{ 'Change password'|trans }}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div id="tab-api" class="tab_content nopadding">
            
            <div class="help">
                <h3>{{ 'API Key'|trans }}</h3>
                <p>{{ 'API key allows integration with external applications. You will need this key for authentication.'|trans }}</p>
                <p>{{ 'External application can control every aspect of BoxBilling using this API key.'|trans }}</p>
                <p>{{ 'Warning! Resetting the key will break existing applications using it.'|trans }}</p>
            </div>
  
            <form method="post" action="{{ 'api/admin/profile/generate_api_key'|link }}" class="mainForm api-form" data-api-jsonp="onAfterKeyUpdate">
            <fieldset>
                <div class="rowElem noborder">
                    <label>{{ 'API Key'|trans }}</label>
                    <div class="formRight">
                        <input type="text" value="{{ admin.profile_get.api_token }}" id="apikey"/>
                    </div>
                    <div class="fix"></div>
                </div>
                <input type="submit" value="{{ 'Generate new key'|trans }}" class="greyishBtn submitForm" />
            </fieldset>
            </form>
        </div>

        <div id="tab-gravatar" class="tab_content">
            <h1>{{ 'Gravatar'|trans }}</h1>
            <p><img src="{{ profile.email|gravatar }}" /> {{ 'Change your avatar at'|trans }} <a target="_blank" href="http://www.gravatar.com">gravatar.com</a></p>
        </div>
    </div>
    <div class="fix"></div>	 
</div>
{% endblock %}

{% block js %}
<script type="text/javascript">
    function onAfterKeyUpdate(result)
    {
        bb.post('admin/profile/get', {}, function(result){
            $('#apikey').val(result.api_token);
            bb.msg('New API key generated. Applications using old key are now not working.');
        })
    }
</script>
{% endblock %}