V1.23.24 Externalisation des prompts et évolutions des collaborateurs

This commit is contained in:
2026-09-11 20:25:48 +00:00
parent 05df1c5a28
commit bac56b85a0
17 changed files with 787 additions and 162 deletions
+34 -3
View File
@@ -12,15 +12,44 @@
* POST { "AGC_AgentIncr": 13, "AGC_CompetenceCode": "SITE_WEB" } : attribue.
* DELETE { "AGC_AgentIncr": 13, "AGC_CompetenceCode": "SITE_WEB" } : retire.
*
* Ne touche PAS AGN_Competences (champ texte dénormalisé prévu — voir
* réflexions du 11 septembre 2026, feuille de route point 3) : ce
* recalcul reste à câbler dans une prochaine étape, volontairement pas ici.
* À chaque attribution/retrait réussi, `ASP_Agents.AGN_Competences` (champ
* texte dénormalisé) est intégralement recalculé et écrasé à partir de
* l'état courant de `ASP_AgentsCompetences`/`ASP_Competences` — jamais un
* ajout incrémental (contrairement à AGN_Experience) puisqu'il doit
* refléter l'attribution actuelle, pas un historique cumulatif.
*/
session_start();
header('Content-Type: application/json; charset=utf-8');
require __DIR__ . '/db.php';
/**
* Recalcule et écrase AGN_Competences pour un agent à partir de l'état
* courant de la table de liaison — lu ensuite par mission_agent.php et le
* dialogue de test, au même titre qu'AGN_Identite/AGN_Experience.
*/
function recalculerCompetencesAgent(PDO $pdo, int $agentIncr): void
{
$stmt = $pdo->prepare(
'SELECT c.CMP_Libelle, c.CMP_Description
FROM ASP_AgentsCompetences ac
JOIN ASP_Competences c ON c.CMP_Code = ac.AGC_CompetenceCode
WHERE ac.AGC_AgentIncr = ?
ORDER BY c.CMP_Libelle'
);
$stmt->execute([$agentIncr]);
$texte = implode("\n", array_map(
fn(array $c) => $c['CMP_Description']
? "- {$c['CMP_Libelle']} : {$c['CMP_Description']}"
: "- {$c['CMP_Libelle']}",
$stmt->fetchAll()
));
$pdo->prepare('UPDATE ASP_Agents SET AGN_Competences = ? WHERE AGN_Incr = ?')
->execute([$texte !== '' ? $texte : null, $agentIncr]);
}
if (empty($_SESSION['USR_Code'])) {
http_response_code(401);
echo json_encode(['error' => 'Non identifié — veuillez vous connecter.']);
@@ -87,6 +116,7 @@ if ($method === 'POST') {
$pdo->prepare('INSERT INTO ASP_AgentsCompetences (AGC_AgentIncr, AGC_CompetenceCode) VALUES (?, ?)')
->execute([$agentIncr, $competenceCode]);
recalculerCompetencesAgent($pdo, $agentIncr);
echo json_encode(['success' => true]);
} catch (PDOException $e) {
http_response_code(500);
@@ -109,6 +139,7 @@ if ($method === 'DELETE') {
try {
$stmt = $pdo->prepare('DELETE FROM ASP_AgentsCompetences WHERE AGC_AgentIncr = ? AND AGC_CompetenceCode = ?');
$stmt->execute([$agentIncr, $competenceCode]);
recalculerCompetencesAgent($pdo, $agentIncr);
echo json_encode(['success' => true]);
} catch (PDOException $e) {
http_response_code(500);