mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-08-10 07:11:18 +02:00
partage: lock Année field to link's locked_year when present
When a student-access share link specifies a locked_year, the Année field in the student-facing form is now pre-filled with that year and rendered as disabled+readonly, with a hidden input ensuring the value is submitted. - renderShareLinkForm() exposes from ['locked_year'] - fieldset-academic.php checks for : if set, outputs a hidden input plus the visible field locked to that value; otherwise falls back to the normal editable field
This commit is contained in:
@@ -317,6 +317,10 @@ function renderShareLinkForm(string $slug, array $link): void
|
|||||||
$oldFn = $shareOldFn;
|
$oldFn = $shareOldFn;
|
||||||
$withAutofocusFn = $shareWithAutofocusFn;
|
$withAutofocusFn = $shareWithAutofocusFn;
|
||||||
|
|
||||||
|
// Locked academic year: if the link specifies a locked year, pre-fill
|
||||||
|
// and lock the Année field so students cannot change it.
|
||||||
|
$lockedYear = $link['locked_year'] ?? null;
|
||||||
|
|
||||||
// Synopsis extra: inject fieldset_synopsis help block
|
// Synopsis extra: inject fieldset_synopsis help block
|
||||||
ob_start();
|
ob_start();
|
||||||
$helpContent = $helpFn('fieldset_synopsis');
|
$helpContent = $helpFn('fieldset_synopsis');
|
||||||
|
|||||||
@@ -15,15 +15,30 @@ $oldFn = $oldFn ?? (function_exists('old') ? 'old' : fn($k,
|
|||||||
$withAutofocusFn = $withAutofocusFn ?? fn($field, $attrs = []) => $attrs;
|
$withAutofocusFn = $withAutofocusFn ?? fn($field, $attrs = []) => $attrs;
|
||||||
$formData = $formData ?? [];
|
$formData = $formData ?? [];
|
||||||
$adminMode = $adminMode ?? false;
|
$adminMode = $adminMode ?? false;
|
||||||
|
$lockedYear = $lockedYear ?? null;
|
||||||
?>
|
?>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Cadre académique</legend>
|
<legend>Cadre académique</legend>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$name = 'année'; $label = 'Année :'; $value = $oldFn('année'); $required = !$adminMode;
|
$name = 'année'; $label = 'Année :';
|
||||||
|
$required = !$adminMode;
|
||||||
$type = 'number';
|
$type = 'number';
|
||||||
$placeholder = date('Y');
|
$placeholder = date('Y');
|
||||||
$attrs = $withAutofocusFn('année', ['min' => 2000, 'max' => date('Y') + 1]);
|
$attrs = $withAutofocusFn('année', ['min' => 2000, 'max' => date('Y') + 1]);
|
||||||
|
|
||||||
|
if ($lockedYear !== null):
|
||||||
|
// Link specifies a locked academic year: pre-fill, disable editing.
|
||||||
|
$value = (string)$lockedYear;
|
||||||
|
$attrs['disabled'] = true;
|
||||||
|
$attrs['readonly'] = true;
|
||||||
|
// Include a hidden input so the value is still submitted when the field is disabled.
|
||||||
|
?>
|
||||||
|
<input type="hidden" name="année" value="<?= htmlspecialchars((string)$lockedYear) ?>">
|
||||||
|
<?php
|
||||||
|
else:
|
||||||
|
$value = $oldFn('année');
|
||||||
|
endif;
|
||||||
include APP_ROOT . '/templates/partials/form/text-field.php';
|
include APP_ROOT . '/templates/partials/form/text-field.php';
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user