404 lines
23 KiB
PHP
404 lines
23 KiB
PHP
<?php
|
|
/**
|
|
* Template Profil Intervenant
|
|
* Affiche le formulaire de gestion du compte et des informations personnelles
|
|
* Shortcode: [crvi_intervenant_profil]
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
$user = wp_get_current_user();
|
|
$user_id = $user->ID;
|
|
|
|
// Récupérer tous les champs ACF pour pré-remplir le formulaire
|
|
$telephone = '';
|
|
$jours_disponibilite = [];
|
|
$indisponibilites_ponctuelles = [];
|
|
$heures_de_permanences = [];
|
|
if (function_exists('get_field')) {
|
|
$telephone = get_field('telephone', 'user_' . $user_id);
|
|
if (!is_string($telephone)) {
|
|
$telephone = '';
|
|
}
|
|
|
|
$jours_disponibilite = get_field('jours_de_disponibilite', 'user_' . $user_id);
|
|
if (!is_array($jours_disponibilite)) {
|
|
$jours_disponibilite = [];
|
|
}
|
|
|
|
$indisponibilites_ponctuelles = get_field('indisponibilitee_ponctuelle', 'user_' . $user_id);
|
|
if (!is_array($indisponibilites_ponctuelles)) {
|
|
$indisponibilites_ponctuelles = [];
|
|
}
|
|
|
|
$heures_de_permanences = get_field('heures_de_permanences', 'user_' . $user_id);
|
|
if (!is_array($heures_de_permanences)) {
|
|
$heures_de_permanences = [];
|
|
}
|
|
}
|
|
|
|
// Labels des types d'indisponibilité
|
|
$types_indisponibilite = [
|
|
'conge' => 'Congé',
|
|
'absence' => 'Absence',
|
|
'maladie' => 'Maladie'
|
|
];
|
|
|
|
// Fonction pour convertir une date au format d/m/Y vers YYYY-MM-DD pour les champs date
|
|
function convert_date_to_input($date_str) {
|
|
if (empty($date_str)) {
|
|
return '';
|
|
}
|
|
// Si déjà au format YYYY-MM-DD, retourner tel quel
|
|
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $date_str)) {
|
|
return $date_str;
|
|
}
|
|
// Si au format d/m/Y, convertir
|
|
if (preg_match('/^(\d{2})\/(\d{2})\/(\d{4})$/', $date_str, $matches)) {
|
|
return $matches[3] . '-' . $matches[2] . '-' . $matches[1];
|
|
}
|
|
return '';
|
|
}
|
|
|
|
// Labels des jours
|
|
$jours_labels = [
|
|
'lundi' => 'Lundi',
|
|
'mardi' => 'Mardi',
|
|
'mercredi' => 'Mercredi',
|
|
'jeudi' => 'Jeudi',
|
|
'vendredi' => 'Vendredi',
|
|
'samedi' => 'Samedi',
|
|
'dimanche' => 'Dimanche'
|
|
];
|
|
?>
|
|
|
|
<div class="crvi-intervenant-profile" id="intervenant-profile-container">
|
|
<div class="container-fluid py-4">
|
|
<!-- En-tête -->
|
|
<div class="row mb-4">
|
|
<div class="col-12">
|
|
<h1 class="h2 mb-2">
|
|
<i class="fas fa-user me-2"></i>Mon Profil
|
|
</h1>
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light rounded p-3">
|
|
<div class="container-fluid">
|
|
<ul class="navbar-nav me-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="<?php echo esc_url(home_url('/espace-intervenant')); ?>">
|
|
<i class="fas fa-home me-1"></i>Hub
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="<?php echo esc_url(home_url('/espace-intervenant-agenda')); ?>">
|
|
<i class="fas fa-calendar-alt me-1"></i>Agenda
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="<?php echo esc_url(home_url('/espace-intervenant-profil')); ?>">
|
|
<i class="fas fa-user me-1"></i>Mon Profil
|
|
</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="<?php echo esc_url(home_url('/encodage-permanences')); ?>">
|
|
<i class="fas fa-clock me-1"></i>Permanences
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Afficher les messages de conflit d'indisponibilités -->
|
|
<?php
|
|
if (class_exists('ESI_CRVI_AGENDA\controllers\CRVI_Plugin')) {
|
|
\ESI_CRVI_AGENDA\controllers\CRVI_Plugin::display_intervenant_conflicts_frontend();
|
|
}
|
|
?>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-8 offset-lg-2">
|
|
<!-- Section Informations modifiables -->
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-header bg-primary text-white">
|
|
<h3 class="h5 mb-0">
|
|
<i class="fas fa-edit me-2"></i>Mes informations personnelles
|
|
</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<form id="profile-form">
|
|
<!-- Informations non modifiables (affichage seul) -->
|
|
<div class="row mb-3">
|
|
<div class="col-md-4">
|
|
<label class="form-label text-muted">Nom</label>
|
|
<input type="text" class="form-control" id="profile-nom" value="<?php echo esc_attr($user->last_name); ?>" readonly>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label text-muted">Prénom</label>
|
|
<input type="text" class="form-control" id="profile-prenom" value="<?php echo esc_attr($user->first_name); ?>" readonly>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label class="form-label text-muted">Email</label>
|
|
<input type="email" class="form-control" id="profile-email" value="<?php echo esc_attr($user->user_email); ?>" readonly>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Téléphone (modifiable) -->
|
|
<div class="mb-3">
|
|
<label for="profile-telephone" class="form-label">
|
|
Téléphone <span class="text-danger">*</span>
|
|
</label>
|
|
<div class="input-group">
|
|
<input type="tel" class="form-control" id="profile-telephone" name="telephone" value="<?php echo esc_attr($telephone); ?>" required>
|
|
<button class="btn btn-outline-secondary" type="button" id="edit-telephone-btn">
|
|
<i class="fas fa-edit"></i> Modifier
|
|
</button>
|
|
</div>
|
|
<small class="form-text text-muted">Vous pouvez modifier votre numéro de téléphone</small>
|
|
</div>
|
|
|
|
<!-- Boutons d'action -->
|
|
<div class="d-flex gap-2">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-save me-2"></i>Enregistrer les modifications
|
|
</button>
|
|
<button type="button" class="btn btn-outline-secondary" id="cancel-profile-btn">
|
|
Annuler
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Section Disponibilités -->
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-header bg-primary text-white">
|
|
<h3 class="h5 mb-0">
|
|
<i class="fas fa-calendar-check me-2"></i>Mes disponibilités
|
|
</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<form id="disponibilites-form">
|
|
<!-- Jours de disponibilité (checkboxes) -->
|
|
<div class="mb-4">
|
|
<label class="form-label fw-bold">Jours de disponibilité</label>
|
|
<div id="profile-jours-disponibilite-checkboxes" class="row g-3">
|
|
<?php foreach ($jours_labels as $jour_value => $jour_label) :
|
|
$is_checked = in_array($jour_value, $jours_disponibilite, true);
|
|
?>
|
|
<div class="col-md-3 col-sm-4 col-6">
|
|
<div class="form-check">
|
|
<input
|
|
class="form-check-input"
|
|
type="checkbox"
|
|
value="<?php echo esc_attr($jour_value); ?>"
|
|
id="jour-<?php echo esc_attr($jour_value); ?>"
|
|
name="jours_disponibilite[]"
|
|
<?php echo $is_checked ? 'checked' : ''; ?>
|
|
>
|
|
<label class="form-check-label" for="jour-<?php echo esc_attr($jour_value); ?>">
|
|
<?php echo esc_html($jour_label); ?>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<small class="form-text text-muted">Cochez les jours où vous êtes disponible</small>
|
|
</div>
|
|
|
|
<!-- Heures de permanences (checkboxes) -->
|
|
<div class="mb-4">
|
|
<label class="form-label fw-bold">Tranches horaires</label>
|
|
<div id="profile-heures-permanences-checkboxes" class="row g-3">
|
|
<?php
|
|
$heures_choices = [
|
|
'09:00' => '09:00 → 10:00',
|
|
'10:00' => '10:00 → 11:00',
|
|
'11:00' => '11:00 → 12:00',
|
|
'12:00' => '12:00 → 13:00',
|
|
'13:00' => '13:00 → 14:00',
|
|
'14:00' => '14:00 → 15:00',
|
|
'15:00' => '15:00 → 16:00',
|
|
'16:00' => '16:00 → 17:00',
|
|
];
|
|
foreach ($heures_choices as $hval => $hlabel) :
|
|
$is_checked = in_array($hval, $heures_de_permanences, true);
|
|
?>
|
|
<div class="col-md-3 col-sm-4 col-6">
|
|
<div class="form-check">
|
|
<input
|
|
class="form-check-input"
|
|
type="checkbox"
|
|
value="<?php echo esc_attr($hval); ?>"
|
|
id="heure-<?php echo esc_attr($hval); ?>"
|
|
name="heures_permanences[]"
|
|
<?php echo $is_checked ? 'checked' : ''; ?>
|
|
>
|
|
<label class="form-check-label" for="heure-<?php echo esc_attr($hval); ?>">
|
|
<?php echo esc_html($hlabel); ?>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<small class="form-text text-muted">Cochez les créneaux horaires où vous êtes disponible</small>
|
|
</div>
|
|
|
|
<!-- Indisponibilités ponctuelles -->
|
|
<div class="mb-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<label class="form-label fw-bold mb-0">Mes indisponibilités ponctuelles</label>
|
|
<button type="button" class="btn btn-sm btn-outline-primary" id="add-indisponibilite-btn">
|
|
<i class="fas fa-plus me-1"></i>Ajouter une indisponibilité
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Liste des indisponibilités existantes -->
|
|
<div id="profile-indisponibilites-list" class="indisponibilites-list mb-3">
|
|
<?php if (!empty($indisponibilites_ponctuelles)) : ?>
|
|
<?php foreach ($indisponibilites_ponctuelles as $index => $indispo) :
|
|
$debut = $indispo['debut'] ?? '';
|
|
$fin = $indispo['fin'] ?? '';
|
|
$type = $indispo['type'] ?? 'conge';
|
|
$commentaire = $indispo['commentaire'] ?? '';
|
|
$type_label = $types_indisponibilite[$type] ?? $type;
|
|
|
|
// Convertir les dates pour l'affichage
|
|
$debut_formatted = $debut;
|
|
$fin_formatted = $fin;
|
|
|
|
// Si les dates sont au format d/m/Y, les formater pour l'affichage
|
|
if (preg_match('/^(\d{2})\/(\d{2})\/(\d{4})$/', $debut)) {
|
|
$debut_formatted = $debut;
|
|
}
|
|
if (preg_match('/^(\d{2})\/(\d{2})\/(\d{4})$/', $fin)) {
|
|
$fin_formatted = $fin;
|
|
}
|
|
|
|
// Afficher la période
|
|
$periode_text = '';
|
|
if ($debut_formatted && $fin_formatted) {
|
|
if ($debut_formatted === $fin_formatted) {
|
|
$periode_text = 'Le ' . $debut_formatted;
|
|
} else {
|
|
$periode_text = 'Du ' . $debut_formatted . ' au ' . $fin_formatted;
|
|
}
|
|
} elseif ($debut_formatted) {
|
|
$periode_text = 'Le ' . $debut_formatted;
|
|
}
|
|
?>
|
|
<div class="indisponibilite-item indispo-<?php echo esc_attr($type); ?>" data-index="<?php echo esc_attr($index); ?>">
|
|
<div>
|
|
<strong><?php echo esc_html($periode_text); ?></strong>
|
|
<?php
|
|
$badge_class = 'badge-indispo-unknown';
|
|
if ($type === 'conge') $badge_class = 'badge-indispo-conge';
|
|
elseif ($type === 'absence') $badge_class = 'badge-indispo-absence';
|
|
elseif ($type === 'maladie') $badge_class = 'badge-indispo-maladie';
|
|
?>
|
|
<span class="badge <?php echo esc_attr($badge_class); ?> ms-2"><?php echo esc_html($type_label); ?></span>
|
|
<?php if ($commentaire) : ?>
|
|
<p class="mb-0 text-muted mt-1"><?php echo esc_html($commentaire); ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<button type="button" class="btn-remove" onclick="removeIndisponibilite(<?php echo esc_attr($index); ?>)" title="Supprimer">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else : ?>
|
|
<div id="profile-indisponibilites-empty" class="alert alert-info">
|
|
<i class="fas fa-info-circle me-2"></i>Aucune indisponibilité prévue.
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Zone pour ajouter une nouvelle indisponibilité -->
|
|
<div id="indisponibilite-form-container" style="display: none;">
|
|
<div class="card border-primary">
|
|
<div class="card-header bg-light">
|
|
<h6 class="mb-0">Nouvelle indisponibilité</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row g-3">
|
|
<div class="col-md-6">
|
|
<label for="indispo-debut" class="form-label">Date de début <span class="text-danger">*</span></label>
|
|
<input type="date" class="form-control" id="indispo-debut">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label for="indispo-fin" class="form-label">Date de fin <span class="text-danger">*</span></label>
|
|
<input type="date" class="form-control" id="indispo-fin">
|
|
</div>
|
|
<div class="col-md-6">
|
|
<label for="indispo-type" class="form-label">Type <span class="text-danger">*</span></label>
|
|
<select class="form-select" id="indispo-type">
|
|
<option value="">Sélectionnez un type</option>
|
|
<option value="conge">Congé</option>
|
|
<option value="absence">Absence</option>
|
|
<option value="maladie">Maladie</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-12">
|
|
<label for="indispo-commentaire" class="form-label">Commentaire</label>
|
|
<textarea class="form-control" id="indispo-commentaire" rows="2" placeholder="Optionnel"></textarea>
|
|
</div>
|
|
</div>
|
|
<div class="mt-3 d-flex gap-2">
|
|
<button type="button" class="btn btn-primary btn-sm" id="save-indisponibilite-btn">
|
|
<i class="fas fa-save me-1"></i>Enregistrer
|
|
</button>
|
|
<button type="button" class="btn btn-outline-secondary btn-sm" id="cancel-indisponibilite-btn">
|
|
Annuler
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Bouton de sauvegarde -->
|
|
<div class="d-flex gap-2">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-save me-2"></i>Enregistrer les disponibilités
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Section Départements et spécialisations (consultation seule) -->
|
|
<div class="card shadow-sm">
|
|
<div class="card-header bg-light">
|
|
<h3 class="h5 mb-0">
|
|
<i class="fas fa-building me-2"></i>Départements et spécialisations
|
|
</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">Départements</label>
|
|
<div id="profile-departements" class="badge-container">
|
|
<!-- Sera rempli par JavaScript -->
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label">Spécialisations</label>
|
|
<div id="profile-specialisations" class="badge-container">
|
|
<!-- Sera rempli par JavaScript -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<small class="text-muted">
|
|
<i class="fas fa-lock me-1"></i>
|
|
Ces informations sont gérées par l'administrateur.
|
|
</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|