{% extends "users/sidebar.html" %}
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.

Copyright © 2017  Gabriel Détraz
Copyright © 2017  Goulven Kermarec
Copyright © 2017  Augustin Lemesle

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}

{% load bootstrap3 %}
{% load acl %}
{% load logs_extra %}
{% load design %}

{% block title %}Profil{% endblock %}

{% block content %}
<div align="center">
    <h2>Welcome {{ users.name }} {{ users.surname }}</h2>
</div>
<div class="dashboard_container">
    <div class="row">
        <div class="col-sm-6 {% if solde_activated %}col-md-4{% else %}col_md-6{% endif %}">
            {% if users.is_ban%}
            <div class="panel panel-danger">
                <div class="panel-heading dashboard">Your account has been banned</div>
                <div class="panel-body dashboard">
                    <i class="text-danger">End of the ban: {{ user.end_ban | date:"SHORT_DATE_FORMAT" }}</i>
                </div>
            </div>
            {% elif not users.is_adherent %}
            <div class="panel panel-danger">
                <div class="panel-heading dashboard">Not connected</div>
                <div class="panel-body dashboard"> 
                    {% can_create Facture %}
                    <a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:new-facture' users.id %}">
                        <i class="fas fa-sign-in-alt"></i> Pay for a connexion
                    </a>
                    {% acl_else %}
                    Ask for someone with the correct rights to pay for a connexion
                    {% acl_end %}
                </div>
            </div>
            {% else %}
            <div class="panel panel-success">
                <div class="panel-heading dashboard">Connected</div>
                <div class="panel-body dashboard">
                    <i class="text-success">End of connexion: {{ user.end_adhesion | date:"SHORT_DATE_FORMAT"}}</i>
                </div>
            </div>
            {% endif %}
        </div>
        {% if solde_activated %}
        <div class="col-sm-6 col-md-4">
            <div class="panel panel-info">
                <div class="panel-heading dashboard" data-parent="#accordion" data-toggle="collapse" data-target="#collapse4">
                    € {{ user.solde }}
                </div>
                <div class="panel-body dashboard">
                    <a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:credit-solde' users.id %}">
                        <i class="fa fa-euro-sign"></i> Pay for the balance
                    </a>
                </div>
            </div>
        </div>
        {% endif %}
        <div class="col-sm-6 {% if solde_activated %}col-md-4{% else %}col-md-6{% endif %}">
            {% if nb_machines %}
            <div class="panel panel-info">
                <div class="panel-heading dashboard" data-parent="#accordion" data-toggle="collapse" data-target="#collapse3">
                    <i class="fa fa-desktop"></i> Machines <span class="badge">{{ nb_machines }}</span>
                </div>
                <div class="panel-body dashboard">
                    <a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' users.id %}">
                        <i class="fa fa-desktop"></i> Add a machine
                    </a>
                </div>
            </div>
            {% else %}
            <div class="panel panel-warning">
                <div class="panel-heading dashboard">No machines</div>
                <div class="panel-body dashboard">
                    <a class="btn btn-warning btn-sm" role="button" href="{% url 'machines:new-machine' users.id %}">
                        <i class="fa fa-desktop"></i> Add a machine
                    </a>
                </div>
            </div>
            {% endif %}
        </div>
    </div> 
</div>



<div class="panel-group" id="accordion">
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse1">
            <h3 class="panel-title pull-left" >
                <i class="fa fa-user"></i> Informations détaillées
            </h3>
        </div>
        <div class="panel-collapse collapse" id="collapse1">
            <div class="panel-body">
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' users.id %}">
                    <i class="fa fa-edit"></i>
                    Editer
                </a>
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:password' users.id %}">
                    <i class="fa fa-lock"></i>
                    Changer le mot de passe
                </a>
                {% can_change User state %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:state' users.id %}">
                    <i class="fa fa-id-badge"></i>
                    Changer le statut
                </a>
                {% acl_end %}
                {% can_change User groups %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:groups' users.id %}">
                    <i class="fa fa-check"></i>
                    Gérer les groupes
                </a>
                {% acl_end %}
                {% history_button users text=True %}
                </ul>
            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-striped">
                        <tr>
                            {% if users.is_class_club %}
                            <th>Mailing</th>
                            {% if users.club.mailing %}
                            <td>{{ users.pseudo }}(-admin)</td>
                            {% else %}
                            <td>Mailing désactivée</td>
                            {% endif %}
                            {% else %}
                            <th>Prénom</th>
                            <td>{{ users.name }}</td>
                            {% endif %}
                            <th>Nom</th>
                            <td>{{ users.surname }}</td>
                        </tr>
                        <tr>
                            <th>Pseudo</th>
                            <td>{{ users.pseudo }}</td>
                            <th>E-mail</th>
                            <td>{{ users.email }}</td>
                        </tr>
                        <tr>
                            <th>Chambre</th>
                            <td>{{ users.room }}</td>
                            <th>Téléphone</th>
                            <td>{{ users.telephone }}</td>
                        </tr>
                        <tr>
                            <th>École</th>
                            <td>{{ users.school }}</td>
                            <th>Commentaire</th>
                            <td>{{ users.comment }}</td>
                        </tr>
                        <tr>
                            <th>Date d'inscription</th>
                            <td>{{ users.registered }}</td>
                            <th>Dernière connexion</th>
                            <td>{{ users.last_login }}</td>
                        </tr>
                        <tr>
                            <th>Fin d'adhésion</th>
                            {% if users.end_adhesion != None %}
                            <td><i class="text-success">{{ users.end_adhesion }}</i></td>
                            {% else %}
                            <td><i class="text-danger">Non adhérent</i></td>
                            {% endif %}
                            <th>Accès gracieux</th>
                            {% if users.end_whitelist != None %}
                            <td><i class="text-success">{{ users.end_whitelist }}</i></td>
                            {% else %}
                            <td><i class="text-warning">Aucun</i></td>
                            {% endif %}
                            <tr>
                                <th>Bannissement</th>
                                {% if users.end_ban != None %}
                                <td><i class="text-danger">{{ users.end_ban }}</i></td>
                                {% else %}
                                <td><i class="text-success">Non banni</i></td>
                                {% endif %}
                                <th>Statut</th>
                                {% if users.state == 0 %}
                                <td><i class="text-success">Actif</i></td>
                                {% elif users.state == 1 %}
                                <td><i class="text-danger">Désactivé</i></td>
                                {% else %}
                                <td><i class="text-warning">Archivé</i></td>
                                {% endif %}
                            </tr>
                            <tr>
                                <th>Accès internet</th>
                                {% if users.has_access == True %}
                                <td><i class="text-success">Actif (jusqu'au {{ users.end_access }})</i></td>
                                {% else %}
                                <td><i class="text-danger">Désactivé</i></td>
                                {% endif %}
                                <th>Groupes</th>
                                {% if users.groups.all %}
                                <td>{{ users.groups.all|join:", "}}</td>
                                {% else %}
                                <td>Aucun</td>
                                {% endif %}
                            </tr>
                            <tr>
                                <th>Solde</th>
                                <td>{{ users.solde }} €
                                    {% if user_solde %}
                                    <a class="btn btn-primary btn-sm" style='float:right' role="button" href="{% url 'cotisations:credit-solde' users.pk%}">
                                        <i class="fa fa-euro-sign"></i>
                                        Recharger
                                    </a>
                                    {% endif %}
                                </td>
                                {% if users.shell %}
                                <th>Shell</th>
                                <td>{{ users.shell }}</td>
                                {% endif %}
                            </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    {% if users.is_class_club %}
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse2">
            <h3 class="panel-title pull-left">
                <i class="fa fa-users"></i> Gérer le club
            </h3>
        </div>
        <div class="panel-collapse collapse" id="collapse2">
            <div class="panel-body">
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-club-admin-members' users.club.id %}">
                    <i class="fa fa-lock"></i>
                    Gérer admin et membres
                </a>
            </div>
            <div class="panel-body">
                <h4>Administrateurs du club</h4>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>Nom</th>
                                <th>Prenom</th>
                                <th>Pseudo</th>
                            </tr>
                        </thead>
                        {% for admin in users.club.administrators.all %}
                        <tr>
                            <td>{{ admin.surname }}</td>
                            <td>{{ admin.name }}</td>
                            <td>{{ admin.pseudo }}</td>
                        </tr>
                        {% endfor %}
                    </table>
                </div>
                <h4>Membres</h4>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>Nom</th>
                                <th>Prenom</th>
                                <th>Pseudo</th>
                            </tr>
                        </thead>
                        {% for admin in users.club.members.all %}
                        <tr>
                            <td>{{ admin.surname }}</td>
                            <td>{{ admin.name }}</td>
                            <td>{{ admin.pseudo }}</td>
                        </tr>
                        {% endfor %}
                    </table>
                </div>
            </div>
        </div>
    </div>
    {% endif %}
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse3">
            <h3 class="panel-title pull-left">
                <i class="fa fa-desktop"></i>
                Machines
                <span class="badge">{{nb_machines}}</span>
            </h3>
        </div>
        <div id="collapse3" class="panel-collapse collapse">
            <div class="panel-body">
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' users.id %}">
                    <i class="fa fa-desktop"></i>
                    Ajouter une machine
                </a>
            </div>
            <div class="panel-body">
                {% if machines_list %}
                {% include "machines/aff_machines.html" with machines_list=machines_list %}
                {% else %}
                <p>Aucune machine</p>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse4">
            <h3 class="panel-title pull-left">
                <i class="fa fa-euro-sign"></i>
                Cotisations
            </h3>
        </div>
        <div id="collapse4" class="panel-collapse collapse">
            <div class="panel-body">
                {% can_create Facture %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:new-facture' users.id %}">
                    <i class="fa fa-euro-sign"></i>
                    Ajouter une cotisation
                </a>
                {% if user_solde %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:credit-solde' users.id %}">
                    <i class="fa fa-euro-sign"></i>
                    Modifier le solde
                </a>
                {% endif%}
                {% acl_end %}
            </div>
            <div class="panel-body">
                {% if facture_list %}
                {% include "cotisations/aff_cotisations.html" with facture_list=facture_list %}
                {% else %}
                <p>Aucune facture</p>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse5">
            <h3 class="panel-title pull-left">
                <i class="fa fa-ban"></i>
                Bannissements
            </h3>
        </div>
        <div id="collapse5" class="panel-collapse collapse">
            <div class="panel-body">
                {% can_create Ban %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-ban' users.id %}">
                    <i class="fa fa-ban"></i>
                    Ajouter un bannissement
                </a>
                {% acl_end %}
            </div>
            <div class="panel-body">
                {% if ban_list %}
                {% include "users/aff_bans.html" with ban_list=ban_list %}
                {% else %}
                <p>Aucun bannissement</p>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse6">
            <h3 class="panel-title pull-left">
                <i class="fa fa-check-circle"></i>
                Accès à titre gracieux
            </h3>
        </div>
        <div id="collapse6" class="panel-collapse collapse">
            <div class="panel-body">
                {% can_create Whitelist %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-whitelist' users.id %}">
                    <i class="fa fa-check-circle"></i>
                    Accorder un accès à titre gracieux
                </a>
                {% acl_end %}
            </div>
            <div class="panel-body">
                {% if white_list %}
                {% include "users/aff_whitelists.html" with white_list=white_list %}
                {% else %}
                <p>Aucun accès gracieux</p>
                {% endif %}
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse7">
    <h3 class="panel-title pull-left">
        <i class="fa fa-envelope"></i> Email settings
    </h3>
        </div>
        <div id="collapse7" class="panel-collapse collapse">
            <div class="panel-body">
                {% can_edit users %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-email-settings' users.id %}">
                    <i class="fa fa-pencil-alt"></i> Edit email settings
                </a>
                {% acl_end %}
            </div>
            <div class="panel-body">
                {% if local_email_accounts_enabled %}
                <div class="table-responsive">
                    <table class="table">
                        <tr>
                            <th colspan="2">Contact email address</th>
                            <td colspan="2">{{ users.email }}</td>
                        </tr>
                        <tr>
                            <th>Enable the local email account</th>
                            <td>{{ users.local_email_enabled | tick }}</td>
                            <th>Enable the local email redirection</th>
			    <td>{{ users.local_email_redirect | tick }}</td>
			</tr>
		    </table>
		</div>
		{% if users.local_email_enabled %}
                {% can_create EMailAddress users.id %}
                <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-emailaddress' users.id %}">
                    <i class="fa fa-plus-square"></i> Add an email address
                </a>
                {% acl_end %}
                {% if emailaddress_list %}
                {% include "users/aff_emailaddress.html" with emailaddress_list=emailaddress_list %}
                {% endif %}
                {% endif %}
                {% else %}
                <div class="table-responsive">
                    <table class="table">
                        <tr>
                            <th>Contact email address</th>
                            <td>{{ users.email }}</td>
                        </tr>
                    </table>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
