{% extends "account/base.html.twig" %}

{% import "common/macro_flashes.html.twig" as macro_flashes %}

{% set selected = "informations" %}

{% block stylesheet %}
    {{ parent() }}
{% endblock %}

{% block javascript %}
    {{ parent() }}
    <script type="text/javascript">
            accountApp.bootstrap({
                state: 'editAccount',
                geonameServerUrl: '{{ app['geonames.server-uri'] }}'
            });
    </script>
{% endblock %}

{% block title %}
    {{ "login:: Mon compte" | trans }}
{% endblock %}

{% block content_account %}
    <div class="row-fluid">
        <div class="span12">
            {{ macro_flashes.flashes() }}
            <form name="account" id="account" class="form-horizontal" action="{{ path("submit_update_account") }}" method="post">
                <div class="row-fluid">
                    <div class="span12 well well-small" id="phr-account" style="background: #191919;border: 1px solid #333333;">
                        <legend style="margin:10px 0" data-target="#user-info"><i class="icon-user"></i> &nbsp; {{ "Informations personnelles" | trans }}&nbsp; <a style="font-size: 11px;" href="#">({{ "edit" | trans }})</a></legend>
                        <div id="user-info" class="form-info" style="display:none">
                            <div class="control-group">
                                <label class="form_label control-label" for="form_login"><strong>{{ "admin::compte-utilisateur identifiant" | trans }}</strong></label>
                                <div class="controls">
                                    <span class="control-span">{{ app["authentication"].getUser().getLogin() }}</span>
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_gender"><strong>{{ "admin::compte-utilisateur sexe" | trans }}</strong></label>
                                <div class="controls">
                                    <select name="form_gender" class="input-small">
                                        <option value=""></option>
                                        <option {% if app["authentication"].getUser().getGender() == "0" %}selected{% endif %} value="0" >
                                            {{ "admin::compte-utilisateur:sexe: mademoiselle" | trans }}
                                        </option>
                                        <option {% if app["authentication"].getUser().getGender() == "1" %}selected{% endif %} value="1" >
                                            {{ "admin::compte-utilisateur:sexe: madame" | trans }}
                                        </option>
                                        <option {% if app["authentication"].getUser().getGender() == "2" %}selected{% endif %} value="2" >
                                            {{ "admin::compte-utilisateur:sexe: monsieur" | trans }}
                                        </option>
                                    </select>
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_lastname"><strong>{{ "admin::compte-utilisateur nom" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_lastname" id="form_lastname" value="{{ app["authentication"].getUser().getLastName() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_firstname"><strong>{{ "admin::compte-utilisateur prenom" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_firstname" id="form_firstname" value="{{ app["authentication"].getUser().getFirstName() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_firstname"><strong>{{ "admin::compte-utilisateur email" | trans }}</strong></label>
                                <div class="controls">
                                    <span class="control-span">{{ app["authentication"].getUser().getEmail() }} <a href="{{ path("account_reset_email") }}" target="_self">{{ "login:: Changer mon adresse email" | trans }}</a></span>
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label"><strong>{{ "Password" | trans }}</strong></label>
                                <div class="controls">
                                    <span class="control-span"><a href="{{ path("reset_password") }}" target="_self">{{ "admin::compte-utilisateur changer mon mot de passe" | trans }}</a></span>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_address"><strong>{{ "admin::compte-utilisateur adresse" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_address" id="form_address" value="{{ app["authentication"].getUser().getAddress() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_zip"><strong>{{ "admin::compte-utilisateur code postal" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_zip" id="form_zip" value="{{ app["authentication"].getUser().getZipCode() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_city"><strong>{{ "admin::compte-utilisateur ville" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge geoname_field" type="text" name="form_geonameid" id="form_geonameid" value="{{ app["authentication"].getUser().getGeonameId() }}" autocomplete="false"/>
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_function"><strong>{{ "admin::compte-utilisateur poste" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_function" id="form_function" value="{{ app["authentication"].getUser().getJob() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_company"><strong>{{ "admin::compte-utilisateur societe" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_company" id="form_company" value="{{ app["authentication"].getUser().getCompany() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_activity"><strong>{{ "admin::compte-utilisateur activite" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_activity" id="form_activity" value="{{ app["authentication"].getUser().getActivity() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_phone"><strong>{{ "admin::compte-utilisateur telephone" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_phone" id="form_phone" value="{{ app["authentication"].getUser().getPhone() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="form_label control-label" for="form_fax"><strong>{{ "admin::compte-utilisateur fax" | trans }}</strong></label>
                                <div class="controls">
                                    <input class="input_element input-xlarge" type="text" name="form_fax" id="form_fax" value="{{ app["authentication"].getUser().getFax() }}" />
                                    <p class="form_alert help-block"></p>
                                </div>
                            </div>
                        </div>
                        <legend style="margin:10px 0" data-target="#user-notification"><i class="icon-envelope"></i> &nbsp; {{ "Notification par email" | trans }}&nbsp; <a style="font-size: 11px;" href="#">({{ "edit" | trans }})</a></legend>
                        <div id="user-notification" class="form-info" style="display:none">
                            {% for notification_group, nots in notifications%}
                                <div class="control-group">
                                    <span class="pull-left"><strong>{{ notification_group }}</strong></span>
                                    <div class="controls">
                                        <ul class="unstyled well">
                                            {% for notification in nots %}
                                                <li>
                                                    <label class="checkbox" for="notif_{{ notification["id"] }}">
                                                        <input type="checkbox" id="notif_{{ notification["id"] }}" name="notifications[{{ notification["id"] }}]" {% if app['settings'].getUserNotificationSetting(app["authentication"].getUser(), notification["id"]) %}checked{% endif %} value="1"/>
                                                        {{ notification["description"] }}
                                                    </label>
                                                    <p class="form_alert help-block"></p>
                                                </li>
                                            {% endfor %}
                                        </ul>
                                    </div>
                                </div>
                            {% endfor %}
                        </div>
                        <legend style="margin:10px 0;border:none" data-target="#user-ftp"><i class="icon-globe"></i> &nbsp; {{ "FTP" | trans }}&nbsp; <a style="font-size: 11px;" href="#">({{ "edit" | trans }})</a></legend>
                        <div id="user-ftp" class="form-info" style="display:none">
                            {% set ftpCredential = app["authentication"].getUser().getFtpCredential() %}

                            {% if ftpCredential is not none %}
                                <div class="control-group">
                                    <div class="controls">
                                        <label class="form_label checkbox" for="form_activeFTP">{{ "admin::compte-utilisateur:ftp: Activer le compte FTP" | trans }}
                                            <input class="input_element input-xlarge" type="checkbox" name="form_activeFTP" id="form_activeFTP" {% if ftpCredential.isActive() %}checked{% endif %} onchange="if(this.checked){$('#ftpinfos').slideDown();}else{$('#ftpinfos').slideUp();}" />
                                        </label>
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                            {% endif %}

                            <div id="ftpinfos" style="display:{% if ftpCredential is none or ftpCredential.isActive() %}block{% else %}none{% endif %}">
                                <div class="control-group">
                                    <label class="form_label control-label" for="form_addressFTP"><strong>{{ "phraseanet:: adresse" | trans }}</strong></label>
                                    <div class="controls">
                                        <input class="input_element input-xlarge" type="text" name="form_addressFTP" id="form_addressFTP" value="{{ ftpCredential is not none ? ftpCredential.getAddress() : '' }}" />
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="form_label control-label" for="form_loginFTP"><strong>{{ "admin::compte-utilisateur identifiant" | trans }}</strong></label>
                                    <div class="controls">
                                        <input class="input_element input-xlarge" type="text" name="form_loginFTP" id="form_loginFTP" value="{{ ftpCredential is not none ? ftpCredential.getLogin() : '' }}" />
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="form_label control-label" for="form_pwdFTP"><strong>{{ "admin::compte-utilisateur mot de passe" | trans }}</strong></label>
                                    <div class="controls">
                                        <input class="input_element input-xlarge" type="text" name="form_pwdFTP" id="form_pwdFTP" value="{{ ftpCredential is not none ? ftpCredential.getPassword() : '' }}" />
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="form_label control-label" for="form_destFTP"><strong>{{ "admin::compte-utilisateur:ftp:  repertoire de destination ftp" | trans }}</strong></label>
                                    <div class="controls">
                                        <input class="input_element input-xlarge" type="text" name="form_destFTP" id="form_destFTP" value="{{ ftpCredential is not none ? ftpCredential.getReceptionFolder() : '' }}" />
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="form_label control-label" for="form_prefixFTPfolder"><strong>{{ "admin::compte-utilisateur:ftp: prefixe des noms de dossier ftp" | trans }}</strong></label>
                                    <div class="controls">
                                        <input class="input_element input-xlarge" type="text" name="form_prefixFTPfolder" id="form_prefixFTPfolder" value="{{ ftpCredential is not none ? ftpCredential.getRepositoryPrefixName() : '' }}" />
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <label class="form_label checkbox" for="form_passifFTP">
                                            {{ "admin::compte-utilisateur:ftp: Utiliser le mode passif" | trans }}
                                            <input class="input_element input-xlarge" type="checkbox" name="form_passifFTP" id="form_passifFTP" {% if ftpCredential is not none and ftpCredential.isPassive() %}checked{% endif %} />
                                        </label>
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="form_label control-label" for="form_retryFTP"><strong>{{ "admin::compte-utilisateur:ftp: Nombre d\'essais max" | trans }}</strong></label>
                                    <div class="controls">
                                        <input class="input_element input-xlarge" type="text" name="form_retryFTP" id="form_retryFTP" value="{{ ftpCredential is not none ? ftpCredential.getMaxRetry() : '' }}" />
                                        <p class="form_alert help-block"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="well well-large" style="border: 1px solid #333333;">
                        <div style="max-width: 400px;margin-left: 2%;display: inline-block;width: 47%;margin-right: 1%;">
                            <input type="submit" class="btn btn-info btn-block btn-large" value="{{ 'boutton::valider' | trans }}"/>

                        </div>

                        <div style="max-width: 400px;margin-left: 1%;width: 47%;display: inline-block;margin-right: 2%;float: right;">

                            {% if not user.isadmin() and not user.hasLdapCreated() and (owned_feeds|length == 0) and (initiated_validations|length == 0) %}

                                <a  href="#delete-account-process" type="button" role="button" data-toggle="modal" class="btn btn-danger btn-block btn-large">{{ 'phraseanet::account: Delete my account' | trans }}</a>

                                <!-- Modal -->
                                <div id="delete-account-process" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                        <h3 id="myModalLabel">{{ "phraseanet::account: Process to delete account" }}</h3>
                                    </div>
                                    <div class="modal-body">
                                        <p>{{ "phraseanet::account: Are you sure you want to delete your account?" | trans }} </p>
                                        <h6>{{ "phraseanet::account: List of data to be deleted" | trans }}</h6>

                                        {% if baskets|length > 0  %}
                                            - {{ 'Paniers' | trans }}
                                            <ul style="padding-left: 30px">
                                                {% for basket in baskets %}
                                                    <li>{{ basket.getName() }}</li>
                                                {% endfor %}
                                            </ul>
                                        {% endif %}

                                        {% if api_accounts|length > 0 %}
                                            - {{ "My application " | trans }}
                                            <ul style="padding-left: 30px">
                                                {% for api_account in api_accounts %}
                                                    <li>{{ api_account.getApplication().getName() ~ " => Client_id: " ~ api_account.getApplication().getClientId() }}</li>
                                                {% endfor %}
                                            </ul>
                                        {% endif%}

                                            - {{ "phraseanet::account: My phraseanet account" | trans }}
                                            <ul style="padding-left: 30px">
                                                <li>Name : {{ user.getFirstName() ~ ' ' ~ user.getLastName() }}</li>
                                                <li>Login : {{ user.getLogin() }}</li>
                                            </ul>
                                    </div>
                                    <div class="modal-footer">
                                        <label style="text-align: left;" class="form_label checkbox" for="delete_account_aggree">
                                            {% if app['conf'].get(['user_account', 'deleting_policies', 'email_confirmation']) %}
                                                {{ "phraseanet::account: I am agree to delete my account, need confirmation on mail" | trans }}
                                            {% else %}
                                                {{ "phraseanet::account: I am agree to delete my account" | trans }}
                                            {% endif %}
                                            <input class="input_element input-xlarge" type="checkbox" id="delete_account_aggree"/>
                                        </label>

                                        <button class="btn" data-dismiss="modal" aria-hidden="true">{{ "No" | trans }}</button>
                                        <a id="delete_account_confirm" class="btn btn-info" style="opacity:0.5;pointer-events: none;" >{{ "Yes" | trans }}</a>
                                    </div>
                                </div>

                            {% else %}
                                <p style="font-size: 12px"> {{ "phraseanet::account: << your account can be deleted via admin interface >> " | trans }}</p>
                            {% endif %}

                        </div>

                    </div>
                </div>
            </form>
        </div>
    </div>


    <script type="text/javascript">
        $(document).ready(function(){
            var deleteButton = $("#delete_account_confirm");
            $("#delete_account_aggree").bind("click", function(e) {
                if ($(this).is(":checked")) {
                    deleteButton.attr("href", '{{ path("account_process_delete") }}');
                    deleteButton.css({"opacity": "1", "pointer-events": "auto"});
                } else {
                    deleteButton.removeAttr("href");
                    deleteButton.css({"opacity": "0.5", "pointer-events": "none"});
                }

            });
        });
    </script>

{% endblock %}
