Files
xamxam/app/templates/partials/form/fieldset-academic.php
T
Pontoporeia f9d8fab120 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
2026-07-08 13:50:03 +02:00

65 lines
2.6 KiB
PHP

<?php
/**
* Shared partial — "Cadre académique" fieldset.
*
* Variables consumed:
* callable|null $oldFn — callable($key, $default='') for old/current values.
* callable|null $withAutofocusFn — callable($field, $attrs=[]) to inject autofocus.
* array $orientations — options for the orientation select.
* array $apPrograms — options for the AP select.
* array $finalityTypes — options for the finality select.
* array $formData — raw form data (used for selected state).
*/
$oldFn = $oldFn ?? (function_exists('old') ? 'old' : fn($k, $d = '') => $d);
$withAutofocusFn = $withAutofocusFn ?? fn($field, $attrs = []) => $attrs;
$formData = $formData ?? [];
$adminMode = $adminMode ?? false;
$lockedYear = $lockedYear ?? null;
?>
<fieldset>
<legend>Cadre académique</legend>
<?php
$name = 'année'; $label = 'Année :';
$required = !$adminMode;
$type = 'number';
$placeholder = date('Y');
$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';
?>
<?php
$name = 'orientation'; $label = 'Orientation :'; $options = $orientations;
$selected = $formData['orientation'] ?? ''; $required = !$adminMode; $placeholder = '';
$attrs = $withAutofocusFn('orientation');
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
<?php
$name = 'ap'; $label = 'Atelier pluridisciplinaire :'; $options = $apPrograms;
$selected = $formData['ap'] ?? ''; $required = !$adminMode; $placeholder = '';
$attrs = $withAutofocusFn('ap');
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
<?php
$name = 'finality'; $label = 'Finalité du master :'; $options = $finalityTypes;
$selected = $formData['finality'] ?? ''; $required = !$adminMode; $placeholder = '';
$attrs = $withAutofocusFn('finality');
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
</fieldset>
<?php