{% extends 'layout.twig' %}

{% import 'messagesysteme.twig' as msgSyst %}
{% import 'champs.twig' as form %}
{% import 'planning.twig' as planning %}

{% block css %}
{{d.cssTypeResa |raw}}
{% endblock %}

{% block content %}

<section>

<!-- ! MenuHG  -->
	{% if d.pview != 1 %}
		{{ planning.menuGauche(settings, trad, d.selecteursG, d.miniCalentrier, d.selectionDateDirecte, d.legende) }}
		{{ planning.menuHaut(settings, trad, d.selecteursH, d.miniCalentrier, d.selectionDateDirecte, d.legende) }}

		<div id='planning2'>
	{% else %}
		<div id="print_planning">
	{% endif %}

	<table class="jour floatthead table-striped table-bordered">
		<caption>

            <div class="{{d.classJour}}">
                {% if d.pview != 1 %} <!-- liens mois avant-après et imprimante si page non imprimable -->
                    <div class="ligne23">
                        <div class="left">
                            <button class="btn btn-default btn-xs" onclick="javascript: location.href='app.php?p=jour&amp;year={{d.yy}}&amp;month={{d.ym}}&amp;day={{d.yd}}&amp;room={{d.room}}';" ><i class="fa-solid fa-angles-left"></i> {{trad.daybefore}}</button>
                        </div>

                        {{ planning.imprimante(settings, d.paramUrl) }}

                        <div class="right">
                            <button class="btn btn-default btn-xs" onclick="javascript: location.href='app.php?p=jour&amp;year={{d.ty}}&amp;month={{d.tm}}&amp;day={{d.td}}&amp;room={{d.room}}';">{{trad.dayafter}} <i class="fa-solid fa-angles-right"></i></button>
                        </div>
                    </div>
                {% endif %}
            </div>

			<div>
				{% if d.pview != 1 %} <!-- afficher ou cacher le menu si page non imprimable -->
					<div class="left">
						<div id="voir"><button class="btn btn-default btn-sm" onClick="afficheMenuHG({{d.positionMenu}})" title="{{trad.show_left_menu}}"><i class="fas fa-bars"></i></button></div>
						<div id="cacher"><button class="btn btn-default btn-sm" onClick="afficheMenuHG(0)" title="{{trad.hide_left_menu}}"><i class="fas fa-bars"></i></button></div> 
					</div>
				{% endif %}

				<h4 class="titre">
					{{d.nomDomaine}} - {{trad.all_areas}} {{d.jourCycle}}<br>
					{{d.jourActuel}}
				</h4>

				{% if d.pview == 1 and d.precedent == 1 %}
					<span id="lienPrecedent">
						<button class="btn btn-default btn-xs" onclick="javascript:history.back();">Précedent</button>
					</span>
				{% endif %}
			</div>
		</caption>
		<thead>
			<tr>
                <td class="cell_hours" style="width:8%;">{% if d.usePeriode == "y" %}{{trad.period}}{% else %}{{trad.time}}{% endif %}</td>
				{% for ressource in colonnesRess %}
					<th style="width:{{ressource.largeur}}%;" {% if ressource.ress.4 == 0 %}class="avertissement"{% endif %}>
                        <a id="afficherBoutonSelection{{ressource.a}}" class="lienPlanning" href="#" onclick="afficherMoisSemaine({{ressource.a}})" style="display:inline;">{{ressource.ress.0}}</a>
                        <a id="cacherBoutonSelection{{ressource.a}}" class="lienPlanning" href="#" onclick="cacherMoisSemaine({{ressource.a}})" style="display:none;">{{ressource.ress.0}}</a>
                        {% if d.pview != 1 %}
                            <!--Description-->{% if ressource.ress.3 %}<br>{{ressource.ress.3}}{% endif %}
                            <!--Capacité-->{% if ressource.ress.1 > 0 %}<br><span class="small">({{ressource.ress.1}} {% if ressource.ress.1 > 1 %}{{trad.number_max2}}{% else %}{{trad.number_max}}{% endif %})</span>{% endif %}
                            <!--Ress indispo-->{% if ressource.ress.4 == 0 %}<br><span class="texte_ress_tempo_indispo">{{trad.ressource_temporairement_indisponible}}</span>{% endif %}
                            <!--Modération-->{% if ressource.ress.7 == 1 %}<br><span class="texte_ress_moderee">{{trad.reservations_moderees}}</span>{% endif %}
                            <!--Commentaire-->{% if ressource.ress.9 == "y" and ressource.ress.10 != "" %}<br>{{ressource.ress.10|raw}}{% endif %}
                            <br>
                            <!--FicheRessource-->{% if ressource.ficheRessource %}<a href="javascript:centrerpopup('app.php?p=ressourcefiche&id_room={{ressource.ress.2}}',600,480,'scrollbars=yes,statusbar=no,resizable=yes')" title="{{trad.fiche_ressource}}"><i class="fa-solid fa-magnifying-glass"></i></a> {% endif %}
                            <!--Accès à la conf de la ress-->{% if ressource.accessConfig %}<a href="./admin/admin.php?p=admin_edit_room&room={{ressource.ress.2}}"><i class="fa-solid fa-gear"></i></a>{% endif %}
                            <!--Ressource emprunté-->{{ressource.ressourceEmpruntee|raw}}
							<span id="boutonSelection{{ressource.a}}" style="display:none;">
                                <input type="button" class="btn btn-default btn-xs" title="{{trad.see_week_for_this_room}}" onclick="javascript: location.href='app.php?p=semaine&amp;year={{d.gYear}}&amp;month={{d.gMonth}}&amp;day={{d.gDay}}&amp;room={{ressource.ress.2}}';" value="{{trad.week}}"/>
                                <input type="button" class="btn btn-default btn-xs" title="{{trad.see_month_for_this_room}}" onclick="javascript: location.href='app.php?p=mois&amp;year={{d.gYear}}&amp;month={{d.gMonth}}&amp;day={{d.gDay}}&amp;room={{ressource.ress.2}}';" value="{{trad.month}}"/>
                            </span>
                        {% endif %}
                    </th>
				{% endfor %}
			</tr>
		</thead>
		<tbody>
            {% for ligne in lignesHoraires %}
                <tr>
                    <td class="{{ligne.classHoraire}}">{{ligne.horairePeriode}}</td>
                    {% for cellule in ligne.cellulesJours %}
                        <td rowspan="{{cellule.rowspan}}" class="{{cellule.class}}">
							{% if cellule.statut == 1 %} <!-- Réservable -->
								<a href="app.php?p=editentree&room={{cellule.ressource}}&amp;year={{d.gYear}}&amp;month={{d.gMonth}}&amp;day={{d.gDay}}&amp;page=jour&amp;room_back={{cellule.ressource}}&amp;{% if d.usePeriode == "y" %}period={{ligne.periode}}{% else %}hour={{ligne.heure}}&amp;minute={{ligne.minute}}{% endif %}" title="{{trad.cliquez_pour_effectuer_une_reservation}}">
									<i class="fa-solid fa-plus"></i>
								</a>
							{% elseif cellule.statut == 2 %} <!-- Possède une réservation -->
								
								{% if cellule.ficheResa %}
									{% if settings.display_level_view_entry == 0 %}
										<a title="{{cellule.titre}}" data-width="675" onclick="request({{cellule.idresa}},{{d.gDay}},{{d.gMonth}},{{d.gYear}},{{d.room}},'jour',readData);" data-rel="popup_name" class="poplight lienCellule">
									{% else %}
										<a class="lienCellule" title="{{cellule.titre}}" href="app.php?p=vuereservation&id={{cellule.idresa}}&amp;day={{d.gDay}}&amp;month={{d.gMonth}}&amp;year={{d.gYear}}&amp;page=jour">
									{% endif %}
										{{cellule.descr|raw}}
									</a>
								{% else %}
									{{cellule.descr|raw}}
								{% endif %}
							{% elseif cellule.statut == 3 %} <!-- Hors résa -->
								<i class="fa-solid fa-xmark" title="{{trad.reservation_impossible}}" style="color:red"></i>
							{% endif %}
						</td>
                    {% endfor %}
                </tr>
            {% endfor %}
		</tbody>

	</table>

		{% if d.pview != 1 %}
			<div id="toTop">
				<b>{{trad.top_of_page}}</b>
			</div>
		{% endif %}

	</div>
	<div id="popup_name" class="popup_block"></div>
</section>


{% endblock %}

{% block javascript %}
	{% if d.pview != 1 %}
		{{ planning.erreurMailAuto(settings, trad, d.sessionMessageErreur) }}
		{{ planning.boutonRetourHaut() }}
	{% endif %}
	{% if d.popupMessage %}
		{{ planning.popupMsg(settings, d.popupMessage, d.popupAffiche) }}
	{% endif %}
	<script type="text/javascript">
		$('table.table-bordered td').each(function(){
			var $row = $(this);
			var height = $row.height();
			var h2 = $row.find('a').height();
			$row.find('a').css('min-height', height);
			$row.find('a').css('padding-top', height/2 - h2/2);

		});
		$(document).ready(function(){
			$("#popup_name").draggable({containment: "#container"});
			$("#popup_name").resizable();
			afficheMenuHG('{{d.positionMenu}}');
			if ( $(window).scrollTop() == 0 )
				$("#toTop").hide(1);
		});
	</script>
{% endblock %}