{% extends 'dg_ufr/base_ufr.html' %}
{% load static %}
{% load custom_tag %}
{% load custom_tag_obj %}
{% load widget_tweaks %}
{% block custom_css %}
{% endblock custom_css %}
{% block m-title %} {% endblock m-title %}
{% block content %}
<section class="content">
    <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
        {% if user.is_ufr_dg %}
        {% include "dg_ufr/parts/stats_seance_ufr.html" %}
        {% else %}
        {% include "dg_ufr/parts/stats_seance_ufr_all.html" %}
        {% endif %}
        <div class="container">
            <div class="card">
                <div class="card-header text-white" style="background: #21618C">MENU<h3 class="card-title"></h3>
                </div>
                <div class="card-body">
                    <form method="post" action="#">
                        {% csrf_token %}
                    <div class="row">
                        <div class="col-md-2">
                            {% if user.is_ufr_dg %}
                            <label>Enseignant</label>
                            <select name="enseignant" class="form-control">
                                <option value="tous">---- Tout ---</option>
                                {% for ens in ufrEns %}
                                <option value="{{ ens.id }}">{{ ens }}</option>
                                {% endfor %}
                            </select>
                            {% else %}
                            <label>Enseignant (Email)</label>
                            <input type="text" name="enseignant" value="Tout" class="form-control" placeholder="Email" />
                            {% endif %}
                        </div>
                        <div class="col-md-2" hidden>
                            <label>Année</label>
                            <select name="annee" class="form-control">
                                {% for an in annees %}
                                <option value="{{ an.id }}">{{ an }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-2">
                            <label>Du (debut)</label>
                            {% render_field formF.debut class="form-control" type="date"  %}
                        </div>
                        <div class="col-md-2">
                            <label>Au (fin)</label>
                            {% render_field formF.fin class="form-control" type="date"  %}
                        </div>
                        <div class="col-md-2">
                            <label>Code Matière</label>
                            <!--<select name="ecue" class="form-control">
                                <option value="tous">&#45;&#45;&#45;&#45; Tout -&#45;&#45;</option>
                                {% for ecue in ecues %}
                                <option value="{{ ecue.id }}">{{ ecue.code }} | {{ ecue.ue.semestre }}</option>
                                {% endfor %}
                            </select>-->
                            <input type="text" name="ecue" value="Tout" class="form-control" placeholder="Code Ecue" />
                        </div>
                        <div class="col-md-2" {% if user.is_ufr_dg %}hidden{% endif %}>
                            <label>ETABLISSEMENT</label>
                            <select name="ufr" class="form-control">
                                {% for ufr in ufrs %}
                                <option value="{{ ufr.id }}">{{ ufr.code }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="col-md-2">
                            <label>Status</label>
                            <select name="status" class="form-control">
                                <option value="tous">---- Tout ---</option>
                                <option value="validé">Validé</option>
                                <option value="en attente">En attente...</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <button style="margin-top:30px;" name="seancefilter" type="submit" class='btn btn-primary'><i class="fa fa-search"></i>&nbsp; Trier</button>
                        </div>

                    </div>
                     <hr/>
                    {% if anfil %}
                    <h4>
                        <!--<td>Année: <span style="font-weight:bold;color:red;">{{anfil}}</span> | -->
                        {% if not user.is_ufr_dg %}UFR: <span style="font-weight:bold;color:red;">{{ufr.code}}</span> |{% endif %}
                        Enseignant: <span style="font-weight:bold;color:red;">{% if ens_obj %}{{ens_obj}}{% else %}Tout{% endif %}</span> |
                        Ecue: <span style="font-weight:bold;color:red;">{% if ecue_obj %}{{ecue_obj.code}}{% else %}Tout{% endif %}</span> |
                        Status: <span style="font-weight:bold;color:red;">{% if status == 'tous' %}Tout{% else %}{{status}}{% endif %}</span> |
                        <br/>
                        Du <span style="font-weight:bold;color:red;">{{debut|date:'d-m-Y'}}</span> Au <span style="font-weight:bold;color:red;">{{fin|date:'d-m-Y'}}</span>
                    </h4>
                        <a href="{% url 'EspaceEnseignant:dr_ufr_seance_pdf' ufr.id ens ecue status debut fin %}" target="_blank" class="btn btn-success"><i class="fa fa-print"></i> Imprimer</a>
                    {% endif %}
                    </form>
                </div>
                {% if anfil %}
                <hr/>
                <center>
                <div class="row col-md-8">
                    <table class="table table-bordered" style="text-align:center;">
                    <thead>
                        <tr>
                            <th>TOTAL CM</th>
                            <th>TOTAL TD</th>
                            <th>TOTAL TP</th>
                            <th>TOTAL </th>
                        </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>{{ args|get_total_seance_between:'CM' }}</td>
                        <td>{{ args|get_total_seance_between:'TD' }}</td>
                        <td>{{ args|get_total_seance_between:'TP' }}</td>
                        <td>{{ args|get_total_seance_between:'ALL' }}</td>
                    </tr>
                    </tbody>
                </table>
                </div>
                </center>
                {% endif %}
            </div>

      </div>
    </div>
</section>


<div class="card mb-3">
    <div class="card-header">
        <i class="fas fa-table"></i>
        LISTE DES SEANCES
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered table-striped" id="dataTable" width="100%" cellspacing="0">
                <thead>
                <tr>
                    <th width="100">DATE</th>
                    <th width="50">TYPE</th>
                    <th width="170">DUREE</th>
                    <th width="50">SALLE</th>
                    <th width="60">MATIERE</th>
                  {% if ens == 'tous' %}
                    <th>ENSEIGNANT</th>
                  {% endif %}
                    <th width="50">DELEGUE</th>
                    <th width="50">ADMIN</th>
                    <th width="80"></th>
                </tr>
                </thead>
                <tfoot>
                <tr>
                    <th width="100">DATE</th>
                    <th width="50">TYPE</th>
                    <th width="170">DUREE</th>
                    <th width="50">SALLE</th>
                    <th width="60">MATIERE</th>
                  {% if ens == 'tous' %}
                    <th>ENSEIGNANT</th>
                  {% endif %}
                    <th width="50">DELEGUE</th>
                    <th width="50">ADMIN</th>
                    <th width="80"></th>
                </tr>
                </tfoot>
                <tbody>
                {% for seance in seances %}
                <tr>
                    <td>{{ seance.date|date:'d-m-Y' }}</td>
                    <td>{{ seance.type_cours }}</td>
                    <td>{{ seance.debut|time:'G:i' }} - {{ seance.fin|time:'G:i' }}  &nbsp;({{seance|get_duration_between}})</td>
                    <td>{{ seance.salle.libelle }}</td>
                    <td>{{ seance.ecue.code }} : {{ seance.ecue.libelle }}</td>
                    {% if ens == 'tous' %}
                        <td>{{ seance.enseignant }}</td>
                    {% endif %}
                    <td>
                        {% if seance.etudiant_valid %}
                        <span class="badge badge-info">validée</span>
                        {% else %}
                        <span class="badge badge-secondary">en attente...</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if seance.admin_valid %}
                        <span class="badge badge-info">validée</span>
                        {% else %}
                        <span class="badge badge-secondary">en attente...</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if not seance.admin_valid and user.is_ufr_dg %}
                        <button class="btn btn-warning" data-toggle="modal" data-target="#confirm{{seance.id}}"><i class="fa fa-thumbs-up"></i> ?</button>
                         {% else %}
                        <button class="btn btn-warning" disabled><i class="fa fa-thumbs-up"></i> ?</button>                                    {% endif %}
                        {% include 'dg_ufr/parts/modal_seance_confirm.html' %}
                    </td>
                </tr>

              {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock content %}

{% block custom_js %}

{% endblock custom_js %}