{% extends 'layout.twig' %}

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

{% block css %}
{% endblock %}

{% block content %}

<div>
	<form id="param_account" action="compte.php?pc=moncompte" method="post">

		<table>
			{% if d.AvertissementNomPrenom %}
				<h2 class="avertissement">{{ trad.nom_prenom_valides }}</h2>
			{% endif %}
			<tr><td><b>{{ trad.login }}</b></td><td>{{ d.identifiant }}</td></tr>
			{% if d.modificationNom %}
                <tr><td><b>{{ trad.last_name }}*</b></td><td><input class="form-control" type="text" name="reg_nom" value="{{ d.user_nom }}" size="30" required></td></tr>
				<tr><td><b>{{ trad.first_name }}*</b></td><td><input class="form-control" type="text" name="reg_prenom" value="{{ d.user_prenom }}" size="30" required></td></tr>
			{% else %}
				<tr><td><b>{{ trad.last_name }}</b></td><td>{{ d.user_nom }}</td></tr>
				<tr><td><b>{{ trad.first_name }}</b></td><td>{{ d.user_prenom }}</td></tr>
			{% endif %}
			{% if d.modificationMail %}
				<tr><td><b>{{ trad.mail_user }}{% if settings.mail_user_obligatoire == 'y'%}*{%endif%}</b></td><td><input class="form-control" type="email" name="reg_email" value="{{ d.user_email }}" size="30"{% if settings.mail_user_obligatoire == 'y'%} required{%endif%}></td></tr>
			{% else %}
				<tr><td><b>{{ trad.mail_user }}{% if settings.mail_user_obligatoire == 'y'%}*{%endif%}</b></td><td>{{ d.user_email }}</td></tr>
			{% endif %}
			<tr><td><b>{{ trad.statut }}</b></td><td>{{ d.text_user_statut }}</td></tr>
		</table>
		{% if d.modificationNom %}
			<p>{{ trad.required }}</p>
		{% endif %}

		<hr>

		{% if d.modificationMDP %}
			<div>
				<p>{{ trad.pwd_msg_warning }}</p>

				<div class="form-group">
					<label class="control-label col-md-4 col-sm-6 col-xs-8" for="opwd">{{ trad.old_pwd }}</label>
					<div class="col col-md-8 col-sm-6 col-xs-6">
					<input class="form-control" id="opwd" type="password" name="reg_password_a" size="20"  /></div>
				</div>
				<div class="form-group">
					<label class="control-label col-md-4 col-sm-6 col-xs-8" for="pwd1">{{ trad.new_pwd1 }}</label>
					<div class="col col-md-8 col-sm-4 col-xs-6">
					<input id="pwd1" class="form-control" for="pwd1" type="password" name="reg_password1" size="20" onkeyup="runPassword(this.value, 'pwd1');"  /></div>
				</div>
				<div class="form-group">
					<div class="col col-md-4 col-sm-6 col-xs-8"></div>
					<div class="col col-md-8 col-sm-6 col-xs-8">
						{{trad.pwd_toot_short}} 
						{% if settings.pass_nb_min == 1 %}, {{settings.pass_nb_min}} {{trad.pass_x_min}}{% endif %}
						{% if settings.pass_nb_min > 1 %}, {{settings.pass_nb_min}}  {{trad.pass_x_mins}}{% endif %}
						{% if settings.pass_nb_maj == 1 %}, {{settings.pass_nb_maj}} {{trad.pass_x_maj}}{% endif %}
						{% if settings.pass_nb_maj > 1 %}, {{settings.pass_nb_maj}} {{trad.pass_x_majs}}{% endif %}
						{% if settings.pass_nb_ch == 1 %}, {{settings.pass_nb_ch}}  {{trad.pass_x_ch}}{% endif %}
						{% if settings.pass_nb_ch > 1 %}, {{settings.pass_nb_ch}}  {{trad.pass_x_chs}}{% endif %}
						{% if settings.pass_nb_sp == 1 %}, {{settings.pass_nb_sp}} {{trad.pass_x_sp}}{% endif %}
						{% if settings.pass_nb_sp > 1 %}, {{settings.pass_nb_sp}} {{trad.pass_x_sps}}{% endif %}
					</div>

					<div class="col col-md-4 col-sm-6 col-xs-0"></div>
					<div class="col col-md-4 col-sm-3 col-xs-6"><p class="right">{{ trad.pwd_strength }}</p></div>
					<div class="col col-md-4 col-sm-3 col-xs-6">&nbsp;
						<div id="pwd1_text" style="font-size: 11px;">&nbsp;</div>
						<div id="pwd1_bar" style="font-size: 1px; height: 3px; width: 0px; border: 1px solid white;"></div>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label col-md-4 col-sm-6 col-xs-8" for="pwd2">{{ trad.new_pwd2 }}</label>
					<div class="col col-md-8 col-sm-4 col-xs-6">
					<input class="form-control" id="pwd2" type="password" name="reg_password2" size="20"  /></div>
				</div>
			</div>
		{% else %}
			<p>{{ trad.user_change_pwd_interdit }}</p>
		{% endif %}

		<hr>

		<h3>{{ trad.default_parameter_values_title }}</h3>

		<h4>{{ trad.explain_area_list_format }}</h4>
		
		<table>
			<tr>
				<td>{{ trad.liste_area_list_format }}</td>
				<td><input type="radio" name="area_item_format" value="list" {%if d.default_list_type == 'list' %}checked{% endif %} {% if d.levelUser < settings.allow_users_modify_affichage %}disabled{% endif %} /></td>
			</tr>
			<tr>
				<td>{{ trad.select_area_list_format }}</td>
				<td><input type="radio" name="area_item_format" value="select" {%if d.default_list_type == 'select' %}checked{% endif %} {% if d.levelUser < settings.allow_users_modify_affichage %}disabled{% endif %} /></td>
			</tr>
			<tr>
				<td>{{ trad.item_area_list_format }}</td>
				<td><input type="radio" name="area_item_format" value="item" {%if d.default_list_type == 'item' %}checked{% endif %} {% if d.levelUser < settings.allow_users_modify_affichage %}disabled{% endif %} /></td>
			</tr>
		</table>


		{% if d.levelUser < settings.allow_users_modify_domaine %}

		{% else %}
			{% if settings.module_multisite == 'Oui' %}
			<h4>{{ trad.explain_default_area_and_room_and_site }}</h4>

			<table>
				<tr>
					<td>{{ trad.default_site }}</td>
					<td>
						<select class="form-control" id="id_site" name="id_site" onchange="modifier_liste_domaines();modifier_liste_ressources(2)">
							<option value="-1">{{ trad.choose_a_site }}</option>
							{% for site in sites %}
								<option value="{{ site.idsite }}" {% if site.idsite == d.default_site %} selected {% endif %}>{{ site.nomsite }}</option>
							{% endfor %}
						</select>
					</td>
				</tr>
		
			{% else %}
				<h4>{{ trad.explain_default_area_and_room }}</h4>
				<input type="hidden" id="id_site" name="id_site" value="-1" />

				<table>
			{% endif %}

				<tr>
					<td colspan="2"><div id="div_liste_domaines"></div></td>
				</tr>
				<tr>
					<td colspan="2"><div id="div_liste_ressources"><input type="hidden" id="id_area" name="id_area" value="{{ d.default_area }}" /></div></td>
				</tr>

			</table>
		{% endif %}

		<h4>{{ trad.explain_css }}</h4>
		<table>
			<tr>
				<td>{{ trad.choose_css }}</td>
				<td>
					<select class="form-control" name="default_css" {% if d.levelUser < settings.allow_users_modify_theme %}disabled{% endif %}>
						<option value="">Choix Admin</option>
						{% for theme in themes %}
							<option value="{{ theme.idtheme }}" {% if theme.idtheme == d.default_css %} selected {% endif %}>{{ theme.nomtheme }}</option>
						{% endfor %}
					</select>
				</td>
			</tr>
		</table>

		<h4>{{ trad.choose_language }}</h4>
		<table>
			<tr>
				<td>{{ trad.choose_css }}</td>
				<td>
					<select class="form-control" name="default_language" {% if d.levelUser < settings.allow_users_modify_langue %}disabled{% endif %}>
						<option value="">Choix Admin</option>
						{% for langue in langues %}
							<option value="{{ langue.idlangue }}" {% if langue.idlangue == d.default_language %} selected {% endif %}>{{ langue.nomlangue }}</option>
						{% endfor %}
					</select>
				</td>
			</tr>
		</table>

		<div id="fixe">
			<div>
				<input type="hidden" name="valid" value="yes" />
				<input type="hidden" name="day" value="{{ d.dDay }}" />
				<input type="hidden" name="month" value="{{ d.dMonth }}" />
				<input type="hidden" name="year" value="{{ d.dYear }}" />
				<input class="btn btn-primary" type="submit" value="{{ trad.save }}" />
			</div>
		
	</form>
	<form id="reset" action="compte.php" method="post">

		<div>
			<input type="hidden" name="valid" value="reset" />
			<input type="hidden" name="day" value="{{ d.dDay }}" />
			<input type="hidden" name="month" value="{{ d.dMonth }}" />
			<input type="hidden" name="year" value="{{ d.dYear }}" />
			<input type="hidden" name="id_site" value="-1" />
			<input type="hidden" name="id_area" value="-1" />
			<input type="hidden" name="id_room" value="-1" />
			<input type="hidden" name="default_css" value="" />
			<input type="hidden" name="area_item_format" value="item" />
			<input type="hidden" name="default_language" value="" />
			<input class="btn btn-primary" type="submit" value="{{ trad.reset }}" />
		</div>
	</form>
</div>

{% endblock %}

{% block javascript %}
	<script type="text/javascript" src="../js/pwd_strength.js"></script>
	<script type="text/javascript">
		function modifier_liste_domaines(){
			$.ajax({
				url: "my_account_modif_listes.php",
				type: "get",
				dataType: "html",
				data: {
					id_site: $('#id_site').val(),
					// default_area : '<?php echo Settings::get("default_area"); ?>',
					default_area : '{{d.default_area}}',
					session_login:'{{d.identifiant}}',
					use_site:'{{d.use_site}}',
					type:'domaine',
				},
				success: function(returnData){
					$("#div_liste_domaines").html(returnData);
				},
				error: function(e){
					alert(e);
				}
			});
		}

		function modifier_liste_ressources(action){
			$.ajax({
				url: "my_account_modif_listes.php",
				type: "get",
				dataType: "html",
				data: {
					id_area:$('id_area').serialize(true),
					// default_room : '<?php echo Settings::get("default_room"); ?>',
					default_room : '{{d.default_room}}',
					type:'ressource',
					action:+action,
					},
				success: function(returnData){
					$("#div_liste_ressources").html(returnData);
				},
				error: function(e){
					alert(e);
				}
			});
		}
		
		modifier_liste_domaines();
		modifier_liste_ressources(1);
	</script>
{% endblock %}