mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
link creation: fieldset with checkboxes for objet restriction, TFE checked by default
link creation: fieldset with checkboxes for objet restriction, TFE checked by default; password/expiration in second fieldset 'Accès'
This commit is contained in:
@@ -32,8 +32,10 @@ switch ($action) {
|
||||
App::redirect('/admin/acces.php', error: "La date d'expiration doit être dans le futur.");
|
||||
}
|
||||
}
|
||||
$objetRaw = $_POST['objet_restriction'] ?? '';
|
||||
$objetRestriction = in_array($objetRaw, ['tfe', 'thèse', 'frart'], true) ? $objetRaw : null;
|
||||
$objetRaw = $_POST['objet_restriction'] ?? ['tfe'];
|
||||
$validObjet = ['tfe', 'thèse', 'frart'];
|
||||
$selected = is_array($objetRaw) ? array_intersect($objetRaw, $validObjet) : [];
|
||||
$objetRestriction = !empty($selected) ? implode(',', $selected) : 'tfe';
|
||||
$link = $shareLink->create(1, $password, $expiresAt, $objetRestriction);
|
||||
$logger->logLinkCreate(
|
||||
$link['slug'] ?? '',
|
||||
|
||||
@@ -249,8 +249,8 @@ function renderShareLinkForm(string $slug, array $link): void
|
||||
// Determine allowed objet values for this link
|
||||
$siteSettings = Database::getInstance()->getAllSettings();
|
||||
$objetRestriction = $link['objet_restriction'] ?? null;
|
||||
if ($objetRestriction !== null) {
|
||||
$allowedObjet = [$objetRestriction];
|
||||
if ($objetRestriction !== null && $objetRestriction !== '') {
|
||||
$allowedObjet = explode(',', $objetRestriction);
|
||||
} else {
|
||||
$allowedObjet = ['tfe'];
|
||||
if (($siteSettings['objet_these_enabled'] ?? '1') === '1') $allowedObjet[] = 'thèse';
|
||||
|
||||
@@ -54,9 +54,12 @@ class ShareLink
|
||||
$slug = self::generateSlug();
|
||||
$passwordHash = $password !== null ? password_hash($password, PASSWORD_BCRYPT) : null;
|
||||
$validObjet = ['tfe', 'thèse', 'frart'];
|
||||
$objetRestriction = ($objetRestriction !== null && in_array($objetRestriction, $validObjet, true))
|
||||
? $objetRestriction
|
||||
: null;
|
||||
if ($objetRestriction !== null && $objetRestriction !== '') {
|
||||
$parts = array_intersect(explode(',', $objetRestriction), $validObjet);
|
||||
$objetRestriction = !empty($parts) ? implode(',', $parts) : 'tfe';
|
||||
} else {
|
||||
$objetRestriction = 'tfe';
|
||||
}
|
||||
|
||||
$stmt = $this->db->getConnection()->prepare(
|
||||
'INSERT INTO share_links (slug, objet_restriction, password_hash, is_active, created_by, expires_at)
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
}
|
||||
$fullUrl = $baseUrl . '/partage/' . htmlspecialchars($link['slug']);
|
||||
$created = date('d/m/Y H:i', strtotime($link['created_at']));
|
||||
$expires = $link['expires_at'] ? date('d/m/Y', strtotime($link['expires_at'])) : '—';
|
||||
$expires = $link['expires_at'] ? date('d/m/Y H:i', strtotime($link['expires_at'])) : '—';
|
||||
$hasPassword = !empty($link['password_hash']);
|
||||
?>
|
||||
<tr>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
$statusLabel = $isExpired ? 'Expiré' : ($link['is_active'] ? 'Actif' : 'Désactivé');
|
||||
$fullUrl = $baseUrl . '/partage/' . htmlspecialchars($link['slug']);
|
||||
$created = date('d/m/Y H:i', strtotime($link['created_at']));
|
||||
$expires = $link['expires_at'] ? date('d/m/Y', strtotime($link['expires_at'])) : '-';
|
||||
$expires = $link['expires_at'] ? date('d/m/Y H:i', strtotime($link['expires_at'])) : '-';
|
||||
$hasLinkPassword = !empty($link['password_hash']);
|
||||
$linkName = $link['name'] ?? '';
|
||||
$linkExpiresVal = $link['expires_at'] ? date('Y-m-d\TH:i', strtotime($link['expires_at'])) : '';
|
||||
@@ -144,7 +144,7 @@
|
||||
<?php foreach ($archivedLinks as $link): ?>
|
||||
<?php
|
||||
$created = date('d/m/Y H:i', strtotime($link['created_at']));
|
||||
$expires = $link['expires_at'] ? date('d/m/Y', strtotime($link['expires_at'])) : '-';
|
||||
$expires = $link['expires_at'] ? date('d/m/Y H:i', strtotime($link['expires_at'])) : '-';
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
@@ -320,16 +320,21 @@
|
||||
<form method="post" action="actions/acces-etudiante.php" class="admin-form">
|
||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
||||
<input type="hidden" name="action" value="create">
|
||||
<div>
|
||||
<label for="create-objet">Type d'objet (optionnel)</label>
|
||||
<select id="create-objet" name="objet_restriction">
|
||||
<option value="">- Tous les types -</option>
|
||||
<option value="tfe">TFE</option>
|
||||
<option value="thèse">Thèse</option>
|
||||
<option value="frart">Frart</option>
|
||||
</select>
|
||||
<small>Restreint ce lien à un seul type de soumission.</small>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Type d'objet</legend>
|
||||
<label style="display:flex;align-items:center;gap:var(--space-2xs);font-weight:400;">
|
||||
<input type="checkbox" name="objet_restriction[]" value="tfe" checked> TFE (par défaut)
|
||||
</label>
|
||||
<label style="display:flex;align-items:center;gap:var(--space-2xs);font-weight:400;">
|
||||
<input type="checkbox" name="objet_restriction[]" value="thèse"> Thèse
|
||||
</label>
|
||||
<label style="display:flex;align-items:center;gap:var(--space-2xs);font-weight:400;">
|
||||
<input type="checkbox" name="objet_restriction[]" value="frart"> Frart
|
||||
</label>
|
||||
<small>Le lien sera restreint aux types cochés. Par défaut : TFE uniquement.</small>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Accès</legend>
|
||||
<div>
|
||||
<label for="create-password">Mot de passe (optionnel)</label>
|
||||
<input type="password" id="create-password" name="password" autocomplete="new-password">
|
||||
@@ -340,18 +345,6 @@
|
||||
<input type="datetime-local" id="create-expires" name="expires_at">
|
||||
<small>Laissez vide pour qu'il n'expire jamais.</small>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Année académique verrouillée</legend>
|
||||
<div>
|
||||
<label for="create-locked-year">Année (optionnel)</label>
|
||||
<input type="number" id="create-locked-year" name="locked_year"
|
||||
min="2000" max="<?= date('Y') + 3 ?>" placeholder="<?= date('Y') ?>">
|
||||
<small style="max-width:42ch;">
|
||||
Si renseignée, le formulaire masquera le champ Année et forcera cette valeur.
|
||||
Ainsi les identifiants TFE (ex: <strong><?= date('Y') ?>-001</strong>) correspondront
|
||||
à la bonne année. Laissez vide pour laisser l'étudiant·e choisir.
|
||||
</small>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="admin-form-footer">
|
||||
<button type="submit" class="btn btn--primary">Créer le lien</button>
|
||||
|
||||
Reference in New Issue
Block a user