Add legacy promoteur functionality and migration enhancements
This commit introduces several enhancements related to the legacy promoteur system. It adds a new function to check if the legacy promoteur site is enabled and updates various functions to utilize this check, ensuring that legacy features are only accessible when appropriate. Additionally, it refines the migration process for legacy accounts, including improved handling of migration statistics and event access. The admin interface is updated to reflect these changes, enhancing the overall management of legacy promoteur accounts. The version code is updated to reflect these changes.
This commit is contained in:
@ -1574,6 +1574,10 @@ function fxIsPromoteur($intComId, $intEveId)
|
||||
{
|
||||
global $objDatabase;
|
||||
|
||||
if (!fxPromoteurLegacySiteEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = "select * from inscriptions_comptes where FIND_IN_SET('" . intval($intEveId) . "',com_eve_promoteur) AND com_id = " . intval($intComId);
|
||||
$tab = $objDatabase->fxGetResults($sql);
|
||||
|
||||
@ -2041,6 +2045,31 @@ function fxGetVariable($strVarNom)
|
||||
return $strVarValeur;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupteur site : promoteur legacy (com_eve_promoteur / fxIsPromoteur) actif ?
|
||||
* Defaut : oui (1). Super admin : bouton dans inc_droite (variables.promoteur_legacy_actif).
|
||||
*/
|
||||
function fxPromoteurLegacySiteEnabled()
|
||||
{
|
||||
static $blnEnabled = null;
|
||||
|
||||
if ($blnEnabled !== null) {
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
global $objDatabase;
|
||||
|
||||
if (!isset($objDatabase)) {
|
||||
$blnEnabled = true;
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
$strVal = fxGetVariable('promoteur_legacy_actif');
|
||||
$blnEnabled = ($strVal === null || $strVal === '' || intval($strVal) === 1);
|
||||
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
function fxGetMailHeader($blnTransaction = false, $strLangue = 'fr')
|
||||
{
|
||||
if ($blnTransaction) {
|
||||
|
||||
@ -1505,13 +1505,23 @@ function fxShowMenuCompte($arrCompteClient, $strLangue)
|
||||
$strRetour .= fxShowPromoteurHubMenuLink($arrCompteClient, $strLangue);
|
||||
|
||||
// menu promoteur legacy
|
||||
if (!function_exists('fxInscrGestionUserHasLegacyPromoteurMenu')) {
|
||||
require_once dirname(__FILE__) . '/inc_fx_inscriptions_gestion.php';
|
||||
}
|
||||
|
||||
if (trim($arrCompteClient['com_eve_promoteur']) != '' || trim($arrCompteClient['com_rapports']) != '') { // si le compte client a des événements dont il est le promoteur
|
||||
$arrEvePromoteur = explode(',', $arrCompteClient['com_eve_promoteur']);
|
||||
$intNbEvePromoteur = fxcount($arrEvePromoteur);
|
||||
$strNbEvenements = '<small>(' . $intNbEvePromoteur . ' ';
|
||||
$strNbEvenements .= ($intNbEvePromoteur > 1) ? afficheTexte('compte_evenement_pluriel', 0) : afficheTexte('compte_evenement_singulier', 0);
|
||||
$strNbEvenements .= ')</small>';
|
||||
$blnLegacyPromoteurMenu = fxInscrGestionUserHasLegacyPromoteurMenu($arrCompteClient['com_id']);
|
||||
$blnHasRapports = trim($arrCompteClient['com_rapports']) != '';
|
||||
|
||||
if ($blnLegacyPromoteurMenu || $blnHasRapports) {
|
||||
if ($blnLegacyPromoteurMenu) {
|
||||
$arrEvePromoteur = explode(',', $arrCompteClient['com_eve_promoteur']);
|
||||
$intNbEvePromoteur = fxcount($arrEvePromoteur);
|
||||
$strNbEvenements = '<small>(' . $intNbEvePromoteur . ' ';
|
||||
$strNbEvenements .= ($intNbEvePromoteur > 1) ? afficheTexte('compte_evenement_pluriel', 0) : afficheTexte('compte_evenement_singulier', 0);
|
||||
$strNbEvenements .= ')</small>';
|
||||
} else {
|
||||
$strNbEvenements = '';
|
||||
}
|
||||
|
||||
$strRetour .= '
|
||||
<li class="nav-item">
|
||||
@ -1521,7 +1531,9 @@ function fxShowMenuCompte($arrCompteClient, $strLangue)
|
||||
';
|
||||
// MSIN-3880
|
||||
|
||||
$strRetour .= fxShowInfoPromoteurtitre($_SESSION['com_info'], $strLangue);
|
||||
if ($blnLegacyPromoteurMenu) {
|
||||
$strRetour .= fxShowInfoPromoteurtitre($_SESSION['com_info'], $strLangue);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1156,6 +1156,104 @@ function fxEveAccesComEventHasMigrationKit($intComId, $intEveId)
|
||||
return ($intNb != null && intval($intNb) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampon historique migration legacy (ponctuelle) par compte × evenement.
|
||||
* Ne depend pas du kit migration_legacy encore actif — journal + note de migration.
|
||||
*
|
||||
* @return array<int, string> eve_id => migrated_at (datetime)
|
||||
*/
|
||||
function fxEveAccesLegacyMigratedMapForCom($intComId)
|
||||
{
|
||||
global $objDatabase;
|
||||
|
||||
static $arrCache = array();
|
||||
|
||||
$intComId = intval($intComId);
|
||||
if ($intComId <= 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (isset($arrCache[$intComId])) {
|
||||
return $arrCache[$intComId];
|
||||
}
|
||||
|
||||
$arrCache[$intComId] = array();
|
||||
|
||||
if (!fxEveAccesIsEnabled()) {
|
||||
return $arrCache[$intComId];
|
||||
}
|
||||
|
||||
$sql = "SELECT l.eve_id, MIN(l.log_created_at) AS migrated_at
|
||||
FROM inscriptions_eve_acces_log l
|
||||
INNER JOIN inscriptions_eve_roles r ON r.role_id = l.role_id
|
||||
AND r.role_code = 'migration_legacy'
|
||||
WHERE l.com_id = $intComId
|
||||
AND l.log_action IN ('legacy_migrated', 'create')
|
||||
GROUP BY l.eve_id";
|
||||
$tab = $objDatabase->fxGetResults($sql);
|
||||
|
||||
if ($tab != null) {
|
||||
foreach ($tab as $row) {
|
||||
$intEveId = intval($row['eve_id']);
|
||||
if ($intEveId > 0) {
|
||||
$arrCache[$intComId][$intEveId] = (string)$row['migrated_at'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sqlNote = "SELECT eve_id, MIN(ea_created_at) AS migrated_at
|
||||
FROM inscriptions_eve_acces
|
||||
WHERE com_id = $intComId
|
||||
AND ea_note LIKE 'Migration depuis com_eve_promoteur%'
|
||||
GROUP BY eve_id";
|
||||
$tabNote = $objDatabase->fxGetResults($sqlNote);
|
||||
|
||||
if ($tabNote != null) {
|
||||
foreach ($tabNote as $row) {
|
||||
$intEveId = intval($row['eve_id']);
|
||||
if ($intEveId > 0 && !isset($arrCache[$intComId][$intEveId])) {
|
||||
$arrCache[$intComId][$intEveId] = (string)$row['migrated_at'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sqlEa = "SELECT ea.eve_id, MIN(ea.ea_created_at) AS migrated_at
|
||||
FROM inscriptions_eve_acces ea
|
||||
INNER JOIN inscriptions_eve_roles r ON r.role_id = ea.role_id
|
||||
AND r.role_code = 'migration_legacy'
|
||||
WHERE ea.com_id = $intComId
|
||||
GROUP BY ea.eve_id";
|
||||
$tabEa = $objDatabase->fxGetResults($sqlEa);
|
||||
|
||||
if ($tabEa != null) {
|
||||
foreach ($tabEa as $row) {
|
||||
$intEveId = intval($row['eve_id']);
|
||||
if ($intEveId > 0 && !isset($arrCache[$intComId][$intEveId])) {
|
||||
$arrCache[$intComId][$intEveId] = (string)$row['migrated_at'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $arrCache[$intComId];
|
||||
}
|
||||
|
||||
/** Migration legacy deja effectuee pour cet evenement (tampon ponctuel, pas etat temps reel). */
|
||||
function fxEveAccesComEventWasLegacyMigrated($intComId, $intEveId, $arrMigratedMap = null)
|
||||
{
|
||||
$intComId = intval($intComId);
|
||||
$intEveId = intval($intEveId);
|
||||
|
||||
if ($intComId <= 0 || $intEveId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($arrMigratedMap === null) {
|
||||
$arrMigratedMap = fxEveAccesLegacyMigratedMapForCom($intComId);
|
||||
}
|
||||
|
||||
return isset($arrMigratedMap[$intEveId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Etat migration legacy → v2 pour un compte (lecture inscriptions_comptes.com_eve_promoteur).
|
||||
*
|
||||
@ -1203,12 +1301,15 @@ function fxEveAccesMigrationStatusForCom($intComId)
|
||||
}
|
||||
}
|
||||
|
||||
$arrMigratedMap = fxEveAccesLegacyMigratedMapForCom($intComId);
|
||||
|
||||
foreach ($arrEveIds as $intEveId) {
|
||||
$blnMigrated = fxEveAccesComEventHasMigrationKit($intComId, $intEveId);
|
||||
$blnMigrated = fxEveAccesComEventWasLegacyMigrated($intComId, $intEveId, $arrMigratedMap);
|
||||
$arrOut['events'][] = array(
|
||||
'eve_id' => $intEveId,
|
||||
'eve_nom_fr' => $arrEveNames[$intEveId] ?? ('Événement #' . $intEveId),
|
||||
'migrated' => $blnMigrated,
|
||||
'migrated_at' => $arrMigratedMap[$intEveId] ?? null,
|
||||
);
|
||||
if ($blnMigrated) {
|
||||
$arrOut['migrated_count']++;
|
||||
@ -1272,6 +1373,15 @@ function fxEveAccesMigrateCompteFromLegacy($intComId, $intGrantedBy = 0)
|
||||
|
||||
if (($arrResult['state'] ?? '') === 'success') {
|
||||
$intGranted++;
|
||||
fxEveAccesWriteLog(
|
||||
intval($arrResult['ea_id'] ?? 0),
|
||||
$intComId,
|
||||
$intEveId,
|
||||
$intRoleId,
|
||||
'legacy_migrated',
|
||||
'Migration promoteur legacy (ponctuelle)',
|
||||
$intGrantedBy
|
||||
);
|
||||
} else {
|
||||
$arrErrors[] = '#' . $intEveId . ': ' . ($arrResult['message'] ?? 'erreur');
|
||||
}
|
||||
@ -1290,7 +1400,7 @@ function fxEveAccesMigrateCompteFromLegacy($intComId, $intGrantedBy = 0)
|
||||
if ($intGranted === 0 && $intSkipped > 0) {
|
||||
return array(
|
||||
'state' => 'success',
|
||||
'message' => 'Deja migre : tous les evenements legacy ont le kit migration.',
|
||||
'message' => 'Deja migre : tampon historique en place pour tous les evenements legacy.',
|
||||
'granted' => 0,
|
||||
'skipped' => $intSkipped,
|
||||
'errors' => array(),
|
||||
@ -1307,8 +1417,8 @@ function fxEveAccesMigrateCompteFromLegacy($intComId, $intGrantedBy = 0)
|
||||
);
|
||||
}
|
||||
|
||||
/** Liste comptes avec com_eve_promoteur non vide (migration globale). */
|
||||
function fxEveAccesMigrationListComptesPending()
|
||||
/** Tous les comptes avec com_eve_promoteur non vide. */
|
||||
function fxEveAccesMigrationListAllLegacyComptes()
|
||||
{
|
||||
global $objDatabase;
|
||||
|
||||
@ -1322,13 +1432,16 @@ function fxEveAccesMigrationListComptesPending()
|
||||
AND TRIM(com_eve_promoteur) <> ''
|
||||
ORDER BY com_nom ASC, com_prenom ASC";
|
||||
$tab = $objDatabase->fxGetResults($sql);
|
||||
|
||||
return ($tab != null) ? $tab : array();
|
||||
}
|
||||
|
||||
/** @deprecated Utiliser fxEveAccesMigrationListAllLegacyComptes + filtre pending si besoin. */
|
||||
function fxEveAccesMigrationListComptesPending()
|
||||
{
|
||||
$arrRows = array();
|
||||
|
||||
if ($tab == null) {
|
||||
return $arrRows;
|
||||
}
|
||||
|
||||
foreach ($tab as $row) {
|
||||
foreach (fxEveAccesMigrationListAllLegacyComptes() as $row) {
|
||||
$arrStatus = fxEveAccesMigrationStatusForCom(intval($row['com_id']));
|
||||
if ($arrStatus['pending_count'] <= 0) {
|
||||
continue;
|
||||
@ -1348,55 +1461,17 @@ function fxEveAccesMigrationListComptesPending()
|
||||
return $arrRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rapport promoteurs legacy : qui, groupe, derniere connexion, date migration v2.
|
||||
*
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
function fxEveAccesMigrationListAllLegacyReport()
|
||||
/** Nombre d'evenements legacy encore sans tampon migration (tous comptes). */
|
||||
function fxEveAccesMigrationCountPendingEvents()
|
||||
{
|
||||
global $objDatabase;
|
||||
$intPending = 0;
|
||||
|
||||
if (!fxEveAccesIsEnabled()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$sql = "SELECT c.com_id, c.com_nom, c.com_prenom, c.com_courriel, c.com_eve_promoteur,
|
||||
c.com_groupe, c.com_lastvisit,
|
||||
(SELECT MIN(ea.ea_created_at)
|
||||
FROM inscriptions_eve_acces ea
|
||||
INNER JOIN inscriptions_eve_roles r ON r.role_id = ea.role_id
|
||||
AND r.role_code = 'migration_legacy'
|
||||
WHERE ea.com_id = c.com_id AND ea.ea_statut = 'actif') AS migrated_at
|
||||
FROM inscriptions_comptes c
|
||||
WHERE c.com_eve_promoteur IS NOT NULL
|
||||
AND TRIM(c.com_eve_promoteur) <> ''
|
||||
ORDER BY c.com_nom ASC, c.com_prenom ASC";
|
||||
$tab = $objDatabase->fxGetResults($sql);
|
||||
$arrRows = array();
|
||||
|
||||
if ($tab == null) {
|
||||
return $arrRows;
|
||||
}
|
||||
|
||||
foreach ($tab as $row) {
|
||||
foreach (fxEveAccesMigrationListAllLegacyComptes() as $row) {
|
||||
$arrStatus = fxEveAccesMigrationStatusForCom(intval($row['com_id']));
|
||||
$arrRows[] = array(
|
||||
'com_id' => intval($row['com_id']),
|
||||
'com_nom' => $row['com_nom'],
|
||||
'com_prenom' => $row['com_prenom'],
|
||||
'com_courriel' => $row['com_courriel'],
|
||||
'com_groupe' => trim((string)($row['com_groupe'] ?? '')),
|
||||
'com_lastvisit' => $row['com_lastvisit'] ?? null,
|
||||
'migrated_at' => $row['migrated_at'] ?? null,
|
||||
'legacy_csv' => $arrStatus['legacy_csv'],
|
||||
'pending_count' => $arrStatus['pending_count'],
|
||||
'migrated_count' => $arrStatus['migrated_count'],
|
||||
'event_count' => count($arrStatus['events']),
|
||||
);
|
||||
$intPending += intval($arrStatus['pending_count']);
|
||||
}
|
||||
|
||||
return $arrRows;
|
||||
return $intPending;
|
||||
}
|
||||
|
||||
/** Totaux migration legacy (affichage super admin). */
|
||||
@ -1406,111 +1481,19 @@ function fxEveAccesMigrationGetStats()
|
||||
|
||||
$arrOut = array(
|
||||
'total_legacy' => 0,
|
||||
'pending_accounts' => 0,
|
||||
'done_accounts' => 0,
|
||||
'pending_events' => 0,
|
||||
);
|
||||
|
||||
if (!fxEveAccesIsEnabled()) {
|
||||
return $arrOut;
|
||||
}
|
||||
|
||||
$sql = "SELECT com_id FROM inscriptions_comptes
|
||||
WHERE com_eve_promoteur IS NOT NULL
|
||||
AND TRIM(com_eve_promoteur) <> ''";
|
||||
$tab = $objDatabase->fxGetResults($sql);
|
||||
if ($tab == null) {
|
||||
return $arrOut;
|
||||
}
|
||||
|
||||
$arrOut['total_legacy'] = count($tab);
|
||||
foreach ($tab as $row) {
|
||||
$arrStatus = fxEveAccesMigrationStatusForCom(intval($row['com_id']));
|
||||
if ($arrStatus['pending_count'] > 0) {
|
||||
$arrOut['pending_accounts']++;
|
||||
} else {
|
||||
$arrOut['done_accounts']++;
|
||||
}
|
||||
}
|
||||
$arrOut['total_legacy'] = count(fxEveAccesMigrationListAllLegacyComptes());
|
||||
$arrOut['pending_events'] = fxEveAccesMigrationCountPendingEvents();
|
||||
|
||||
return $arrOut;
|
||||
}
|
||||
|
||||
function fxEveAccesShowCompteMigrationPanel($intComId)
|
||||
{
|
||||
$arrStatus = fxEveAccesMigrationStatusForCom($intComId);
|
||||
$strT = urlencode($_GET['t'] ?? '');
|
||||
$intComId = intval($intComId);
|
||||
|
||||
if (!empty($_GET['mig_msg'])) {
|
||||
$strClass = (!empty($_GET['mig_err'])) ? 'alert-danger' : 'alert-success';
|
||||
echo '<div class="alert ' . $strClass . ' py-2">'
|
||||
. htmlspecialchars((string)$_GET['mig_msg'], ENT_QUOTES, 'UTF-8') . '</div>';
|
||||
}
|
||||
?>
|
||||
<div id="eve-acces-migration" class="border rounded p-3 mb-3 bg-light">
|
||||
<h3 class="h6 mb-2">Migration promoteur legacy → accès v2</h3>
|
||||
<p class="text-muted small mb-2">
|
||||
Source : champ <code>inscriptions_comptes.com_eve_promoteur</code> —
|
||||
kit <strong>migration_legacy</strong> (tous les droits).
|
||||
<a href="eve_acces.php?p=migrate">Migration globale</a>
|
||||
</p>
|
||||
|
||||
<?php if ($arrStatus['legacy_csv'] === '') { ?>
|
||||
<p class="text-muted small mb-0">Ce compte n'a aucun événement promoteur legacy.</p>
|
||||
<?php } else { ?>
|
||||
<p class="small mb-2">
|
||||
<strong>com_eve_promoteur :</strong>
|
||||
<code><?= htmlspecialchars($arrStatus['legacy_csv'], ENT_QUOTES, 'UTF-8') ?></code>
|
||||
</p>
|
||||
|
||||
<?php if (intval($arrStatus['role_id']) <= 0) { ?>
|
||||
<div class="alert alert-warning py-2 mb-2 small mb-0">
|
||||
Kit <code>migration_legacy</code> absent — exécuter
|
||||
<code>sql/MSIN-eve-acces-v2-phase4-role-grants-all.sql</code>.
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<table class="table table-sm table-bordered bg-white mb-2">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Événement</th>
|
||||
<th class="text-center" style="width:100px">v2 migration</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($arrStatus['events'] as $arrEvent) { ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?= htmlspecialchars($arrEvent['eve_nom_fr'], ENT_QUOTES, 'UTF-8') ?>
|
||||
<span class="text-muted small">(#<?= intval($arrEvent['eve_id']) ?>)</span>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<?php if (!empty($arrEvent['migrated'])) { ?>
|
||||
<span class="badge badge-success">OK</span>
|
||||
<?php } else { ?>
|
||||
<span class="badge badge-warning">À migrer</span>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php if ($arrStatus['pending_count'] > 0) { ?>
|
||||
<a class="btn btn-warning btn-sm"
|
||||
href="index.php?t=<?= $strT ?>&a=mod&id=<?= $intComId ?>&action=migrateveacceslegacy"
|
||||
onclick="return confirm('Migrer <?= intval($arrStatus['pending_count']) ?> evenement(s) vers le kit migration_legacy ?');">
|
||||
<i class="fa fa-exchange"></i>
|
||||
Migrer <?= intval($arrStatus['pending_count']) ?> événement(s) vers v2
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<span class="text-success small"><i class="fa fa-check"></i> Tous les événements legacy sont migrés en v2.</span>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function fxEveAccesShowCompteForm($intComId)
|
||||
{
|
||||
global $objDatabase;
|
||||
@ -1583,12 +1566,8 @@ function fxEveAccesShowCompteForm($intComId)
|
||||
<h2 id="eve-acces-v2" class="h4 mt-4">Accès aux événements</h2>
|
||||
<p class="text-muted small mb-2">
|
||||
<a href="<?= htmlspecialchars($vDomaine, ENT_QUOTES, 'UTF-8') ?>/superadm/eve_acces.php?p=kits">Gérer les kits</a>
|
||||
·
|
||||
<a href="<?= htmlspecialchars($vDomaine, ENT_QUOTES, 'UTF-8') ?>/superadm/eve_acces.php?p=migrate">Migration legacy</a>
|
||||
</p>
|
||||
|
||||
<?php fxEveAccesShowCompteMigrationPanel($intComId); ?>
|
||||
|
||||
<table class="table table-sm table-striped mb-2">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@ -14,18 +14,39 @@ function fxInscrGestionIsEntry() {
|
||||
return defined('MS1_INSCR_GESTION_ENTRY') && MS1_INSCR_GESTION_ENTRY;
|
||||
}
|
||||
|
||||
/** Utilisateur avec menu promoteur legacy (section Info promoteur). */
|
||||
function fxInscrGestionUserHasPromoteurMenu($intComId) {
|
||||
global $objDatabase;
|
||||
/** Menu promoteur legacy (tachometre) visible sur Mon compte ? */
|
||||
function fxInscrGestionUserHasLegacyPromoteurMenu($intComId)
|
||||
{
|
||||
if (!function_exists('fxPromoteurLegacySiteEnabled')) {
|
||||
require_once __DIR__ . '/inc_fonctions.php';
|
||||
}
|
||||
|
||||
$row = $objDatabase->fxGetRow(
|
||||
'SELECT com_eve_promoteur, com_rapports FROM inscriptions_comptes WHERE com_id = ' . intval($intComId)
|
||||
);
|
||||
if ($row === null) {
|
||||
if (!fxPromoteurLegacySiteEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return trim((string)$row['com_eve_promoteur']) !== '' || trim((string)$row['com_rapports']) !== '';
|
||||
global $objDatabase;
|
||||
|
||||
$row = $objDatabase->fxGetRow(
|
||||
'SELECT com_eve_promoteur FROM inscriptions_comptes WHERE com_id = ' . intval($intComId)
|
||||
);
|
||||
|
||||
return $row !== null && trim((string)$row['com_eve_promoteur']) !== '';
|
||||
}
|
||||
|
||||
/** Utilisateur avec menu promoteur legacy (section Info promoteur). */
|
||||
function fxInscrGestionUserHasPromoteurMenu($intComId) {
|
||||
if (fxInscrGestionUserHasLegacyPromoteurMenu($intComId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
global $objDatabase;
|
||||
|
||||
$row = $objDatabase->fxGetRow(
|
||||
'SELECT com_rapports FROM inscriptions_comptes WHERE com_id = ' . intval($intComId)
|
||||
);
|
||||
|
||||
return $row !== null && trim((string)$row['com_rapports']) !== '';
|
||||
}
|
||||
|
||||
/** Permissions v2 requises pour la fiche de gestion des inscriptions (web). */
|
||||
|
||||
@ -205,6 +205,14 @@ function fxPromoteurHubGetRoleLabelsByEvent($intComId)
|
||||
/** Evenements promoteur legacy (com_eve_promoteur) pour ce compte. */
|
||||
function fxPromoteurHubGetLegacyEventIds($intComId)
|
||||
{
|
||||
if (!function_exists('fxPromoteurLegacySiteEnabled')) {
|
||||
require_once __DIR__ . '/inc_fonctions.php';
|
||||
}
|
||||
|
||||
if (!fxPromoteurLegacySiteEnabled()) {
|
||||
return array();
|
||||
}
|
||||
|
||||
global $objDatabase;
|
||||
|
||||
$row = $objDatabase->fxGetRow(
|
||||
|
||||
14
sql/MSIN-eve-acces-v2-promoteur-legacy-toggle.sql
Normal file
14
sql/MSIN-eve-acces-v2-promoteur-legacy-toggle.sql
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
Interrupteur site : promoteur legacy (com_eve_promoteur) actif ou non.
|
||||
1 = legacy actif (defaut production actuelle)
|
||||
0 = legacy coupe sur le site — seuls les acces v2 comptent
|
||||
|
||||
Bouton super admin : sidebar Gestion des acces (inc_droite.php)
|
||||
Le premier clic cree la ligne si absente (enregistrer.php change-var).
|
||||
*/
|
||||
|
||||
INSERT INTO variables (var_nom, var_valeur)
|
||||
SELECT 'promoteur_legacy_actif', 1
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM variables WHERE var_nom = 'promoteur_legacy_actif'
|
||||
);
|
||||
@ -151,7 +151,20 @@ switch ($action) {
|
||||
|
||||
break;
|
||||
case 'change-var': // Code pour changer une variable
|
||||
$sqlUpdate = "UPDATE variables SET var_valeur = " . intval($_REQUEST['valeur']) . " WHERE var_nom = '" . $db->fxEscape($_REQUEST['key']) . "'";
|
||||
$strKey = $db->fxEscape($_REQUEST['key']);
|
||||
$intVal = intval($_REQUEST['valeur']);
|
||||
$intExists = intval($db->fxGetVar(
|
||||
"SELECT COUNT(*) FROM variables WHERE var_nom = '" . $strKey . "'"
|
||||
));
|
||||
|
||||
if ($intExists > 0) {
|
||||
$sqlUpdate = "UPDATE variables SET var_valeur = " . $intVal
|
||||
. " WHERE var_nom = '" . $strKey . "'";
|
||||
} else {
|
||||
$sqlUpdate = "INSERT INTO variables (var_nom, var_valeur) VALUES ('"
|
||||
. $strKey . "', " . $intVal . ")";
|
||||
}
|
||||
|
||||
$qryUpdate = $db->fxQuery($sqlUpdate);
|
||||
|
||||
if ($qryUpdate === false) {
|
||||
|
||||
@ -61,6 +61,35 @@ global $db, $objDatabase, $vblnEnvironementDev, $vDomaine, $vblnEnvironementPreP
|
||||
<?php } ?>
|
||||
|
||||
<h5 class="superadm-sidebar-subtitle">Gestion des accès</h5>
|
||||
<div class="p-3 mb-2">
|
||||
<?php
|
||||
$intLegacyActif = fxGetVariable('promoteur_legacy_actif');
|
||||
if ($intLegacyActif === null || $intLegacyActif === '') {
|
||||
$intLegacyActif = 1;
|
||||
}
|
||||
if (intval($intLegacyActif) === 1) {
|
||||
$intLegacyToggle = 0;
|
||||
$strLegacyClass = 'btn-success';
|
||||
$strLegacyLabel = '<i class="fa fa-check mr-2" aria-hidden="true"></i>Legacy promoteur actif';
|
||||
} else {
|
||||
$intLegacyToggle = 1;
|
||||
$strLegacyClass = 'btn-warning';
|
||||
$strLegacyLabel = '<i class="fa fa-pause mr-2" aria-hidden="true"></i>Legacy promoteur désactivé';
|
||||
}
|
||||
?>
|
||||
<a class="btn btn-sm rounded-0 btn-block text-left <?php echo $strLegacyClass; ?>"
|
||||
id="btn_promoteur_legacy"
|
||||
href="#"
|
||||
data-action="change-var"
|
||||
data-key="promoteur_legacy_actif"
|
||||
data-valeur="<?php echo intval($intLegacyToggle); ?>"
|
||||
title="Coupe l'accès site via com_eve_promoteur (les données fiche compte ne changent pas).">
|
||||
<?php echo $strLegacyLabel; ?>
|
||||
</a>
|
||||
<p class="small text-muted mb-0 mt-2">
|
||||
Test v2 seul : désactiver, vérifier les kits, réactiver si besoin.
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
$strSidebarScript = basename($_SERVER['SCRIPT_NAME'] ?? '');
|
||||
$strEveAccesP = $_GET['p'] ?? 'kits';
|
||||
|
||||
@ -162,23 +162,6 @@ if (isset($_GET['action']) && $_GET['action'] == 'reactivateveaccesextra') {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'migrateveacceslegacy') {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
require_once(dirname(__FILE__) . '/../php/inc_fx_eve_acces.php');
|
||||
$intGrantedBy = isset($_SESSION['usa_id']) ? intval($_SESSION['usa_id']) : 0;
|
||||
$arrResult = fxEveAccesMigrateCompteFromLegacy(intval($_GET['id']), $intGrantedBy);
|
||||
$strQ = 'index.php?t=' . urlencode($_GET['t']) . '&a=mod&id=' . intval($_GET['id'])
|
||||
. '#eve-acces-migration'
|
||||
. '&mig_msg=' . urlencode($arrResult['message']);
|
||||
if (($arrResult['state'] ?? '') !== 'success') {
|
||||
$strQ .= '&mig_err=1';
|
||||
}
|
||||
header('Location: ' . $strQ);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['action']) && $_GET['action'] == 'migrateveacceslegacyall') {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
@ -188,18 +171,27 @@ if (isset($_GET['action']) && $_GET['action'] == 'migrateveacceslegacyall') {
|
||||
$intTotalGranted = 0;
|
||||
$intTotalSkipped = 0;
|
||||
$intComptes = 0;
|
||||
foreach (fxEveAccesMigrationListComptesPending() as $arrRow) {
|
||||
$intErrors = 0;
|
||||
$arrAll = fxEveAccesMigrationListAllLegacyComptes();
|
||||
foreach ($arrAll as $arrRow) {
|
||||
$arrResult = fxEveAccesMigrateCompteFromLegacy(intval($arrRow['com_id']), $intGrantedBy);
|
||||
if (($arrResult['state'] ?? '') === 'success' || ($arrResult['granted'] ?? 0) > 0) {
|
||||
$intTotalGranted += intval($arrResult['granted'] ?? 0);
|
||||
$intTotalSkipped += intval($arrResult['skipped'] ?? 0);
|
||||
$intComptes++;
|
||||
$intTotalGranted += intval($arrResult['granted'] ?? 0);
|
||||
$intTotalSkipped += intval($arrResult['skipped'] ?? 0);
|
||||
$intComptes++;
|
||||
if (!empty($arrResult['errors'])) {
|
||||
$intErrors += count($arrResult['errors']);
|
||||
}
|
||||
}
|
||||
header('Location: eve_acces.php?p=migrate&ok=' . urlencode(
|
||||
$intTotalGranted . ' acces cree(s) sur ' . $intComptes . ' compte(s)'
|
||||
. ($intTotalSkipped > 0 ? ', ' . $intTotalSkipped . ' deja en place' : '')
|
||||
));
|
||||
$strMsg = $intTotalGranted . ' acces cree(s) sur ' . count($arrAll) . ' compte(s) promoteur legacy';
|
||||
if ($intTotalSkipped > 0) {
|
||||
$strMsg .= ', ' . $intTotalSkipped . ' deja migre(s)';
|
||||
}
|
||||
if ($intErrors > 0) {
|
||||
$strMsg .= ', ' . $intErrors . ' erreur(s) — verifier les comptes restants';
|
||||
header('Location: eve_acces.php?p=migrate&err=' . urlencode($strMsg));
|
||||
} else {
|
||||
header('Location: eve_acces.php?p=migrate&ok=' . urlencode($strMsg));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@ -243,6 +243,28 @@ function fxGetVariable($strVarNom) {
|
||||
|
||||
return $strVarValeur;
|
||||
}
|
||||
|
||||
/** @see php/inc_fonctions.php fxPromoteurLegacySiteEnabled */
|
||||
function fxPromoteurLegacySiteEnabled()
|
||||
{
|
||||
static $blnEnabled = null;
|
||||
|
||||
if ($blnEnabled !== null) {
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
global $db;
|
||||
|
||||
if (!isset($db)) {
|
||||
$blnEnabled = true;
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
$strVal = fxGetVariable('promoteur_legacy_actif');
|
||||
$blnEnabled = ($strVal === null || $strVal === '' || intval($strVal) === 1);
|
||||
|
||||
return $blnEnabled;
|
||||
}
|
||||
function print_mem() {
|
||||
/* Currently used memory */
|
||||
$mem_usage = memory_get_usage();
|
||||
|
||||
@ -1022,114 +1022,57 @@ function fxEveAccesAdminRenderMigrationPage($strFlash = '')
|
||||
|
||||
$intRoleId = fxEveAccesGetMigrationLegacyRoleId();
|
||||
$arrStats = fxEveAccesMigrationGetStats();
|
||||
$arrReport = fxEveAccesMigrationListAllLegacyReport();
|
||||
$intPending = intval($arrStats['pending_accounts']);
|
||||
$intTotal = intval($arrStats['total_legacy']);
|
||||
$intPendingEvents = intval($arrStats['pending_events']);
|
||||
|
||||
if ($strFlash !== '') {
|
||||
echo '<div class="alert alert-success">' . htmlspecialchars($strFlash, ENT_QUOTES, 'UTF-8') . '</div>';
|
||||
}
|
||||
if (!empty($_GET['err'])) {
|
||||
echo '<div class="alert alert-danger">' . htmlspecialchars((string)$_GET['err'], ENT_QUOTES, 'UTF-8') . '</div>';
|
||||
}
|
||||
?>
|
||||
<h1 class="mb-3">Migration promoteur legacy → v2</h1>
|
||||
<p class="text-muted mb-3">
|
||||
Assigne le kit <code>migration_legacy</code> pour chaque événement listé dans
|
||||
<code>com_eve_promoteur</code> sur la fiche compte. Le champ legacy n'est pas modifié.
|
||||
Action <strong>unique et globale</strong> : parcourt <strong>tous</strong> les comptes avec
|
||||
<code>com_eve_promoteur</code>, assigne le kit <code>migration_legacy</code> une fois par événement
|
||||
(tampon journal), puis ne redemande plus. Le champ legacy n'est pas modifié.
|
||||
Gérer les kits ensuite sur chaque <a href="index.php?t=<?= urlencode(base64_encode('2')) ?>&a=list">fiche compte</a>.
|
||||
</p>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-body py-3">
|
||||
<div class="row text-center">
|
||||
<div class="col-md-4">
|
||||
<div class="h4 mb-0"><?= intval($arrStats['total_legacy']) ?></div>
|
||||
<div class="small text-muted">Promoteurs legacy (total)</div>
|
||||
<div class="col-md-6">
|
||||
<div class="h4 mb-0"><?= $intTotal ?></div>
|
||||
<div class="small text-muted">Comptes promoteur legacy</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="h4 mb-0 text-success"><?= intval($arrStats['done_accounts']) ?></div>
|
||||
<div class="small text-muted">Entièrement migrés</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="h4 mb-0<?= $intPending > 0 ? ' text-warning' : '' ?>"><?= $intPending ?></div>
|
||||
<div class="small text-muted">Encore en attente</div>
|
||||
<div class="col-md-6">
|
||||
<div class="h4 mb-0<?= $intPendingEvents > 0 ? ' text-warning' : ' text-success' ?>"><?= $intPendingEvents ?></div>
|
||||
<div class="small text-muted">Événements sans tampon migration</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($intRoleId <= 0) { ?>
|
||||
<div class="alert alert-warning">
|
||||
<div class="alert alert-warning mb-0">
|
||||
Kit <code>migration_legacy</code> introuvable —
|
||||
exécuter <code>sql/MSIN-eve-acces-v2-phase4-role-grants-all.sql</code>.
|
||||
</div>
|
||||
<?php } elseif ($intPending > 0) { ?>
|
||||
<p class="mb-3">
|
||||
<a class="btn btn-warning"
|
||||
<?php } elseif ($intPendingEvents > 0) { ?>
|
||||
<p class="mb-0">
|
||||
<a class="btn btn-warning btn-lg"
|
||||
href="index.php?action=migrateveacceslegacyall"
|
||||
onclick="return confirm('Migrer <?= $intPending ?> compte(s) encore en attente ?');">
|
||||
<i class="fa fa-exchange"></i> Migrer tous les comptes en attente (<?= $intPending ?>)
|
||||
onclick="return confirm('Migrer <?= $intPendingEvents ?> evenement(s) sur <?= $intTotal ?> compte(s) promoteur legacy ?');">
|
||||
<i class="fa fa-exchange"></i> Migrer tous les promoteurs legacy
|
||||
</a>
|
||||
</p>
|
||||
<?php } else { ?>
|
||||
<div class="alert alert-success mb-0">
|
||||
<i class="fa fa-check"></i> Migration terminée — aucun événement legacy en attente.
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-striped table-hover mb-0">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th>Compte</th>
|
||||
<th>Courriel</th>
|
||||
<th>Groupe</th>
|
||||
<th>Dernière connexion</th>
|
||||
<th>Migré le</th>
|
||||
<th class="text-center">Statut</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if (count($arrReport) === 0) {
|
||||
echo '<tr><td colspan="7" class="text-muted">Aucun compte avec promoteur legacy.</td></tr>';
|
||||
} else {
|
||||
foreach ($arrReport as $arrRow) {
|
||||
$strCompteUrl = 'index.php?t=' . urlencode(base64_encode('2'))
|
||||
. '&a=mod&id=' . intval($arrRow['com_id'])
|
||||
. '#eve-acces-migration';
|
||||
$strGroupe = $arrRow['com_groupe'] !== '' ? $arrRow['com_groupe'] : '—';
|
||||
$strLastVisit = fxEveAccesAdminFormatReportDatetime($arrRow['com_lastvisit']);
|
||||
$strMigratedAt = fxEveAccesAdminFormatReportDatetime($arrRow['migrated_at']);
|
||||
$intPendingEv = intval($arrRow['pending_count']);
|
||||
?>
|
||||
<tr<?= $intPendingEv > 0 ? ' class="table-warning"' : '' ?>>
|
||||
<td><?= htmlspecialchars(trim($arrRow['com_prenom'] . ' ' . $arrRow['com_nom']), ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td><?= htmlspecialchars($arrRow['com_courriel'], ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td><?= htmlspecialchars($strGroupe, ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td class="text-nowrap small"><?= htmlspecialchars($strLastVisit, ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td class="text-nowrap small"><?= htmlspecialchars($strMigratedAt, ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td class="text-center">
|
||||
<?php if ($intPendingEv > 0) { ?>
|
||||
<span class="badge badge-warning"><?= $intPendingEv ?> / <?= intval($arrRow['event_count']) ?> à migrer</span>
|
||||
<?php } else { ?>
|
||||
<span class="badge badge-success">OK</span>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="text-right text-nowrap">
|
||||
<a class="btn btn-sm btn-outline-primary" href="<?= htmlspecialchars($strCompteUrl, ENT_QUOTES, 'UTF-8') ?>">
|
||||
Fiche
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="7" class="text-muted small font-weight-normal">
|
||||
<?= count($arrReport) ?> compte(s) —
|
||||
dernière connexion = champ <code>com_lastvisit</code> (mis à jour à chaque login sur le site).
|
||||
</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
@ -128,6 +128,16 @@ class EventAccess
|
||||
*/
|
||||
public function getLegacyEventIds(int $comId): array
|
||||
{
|
||||
$rowVar = $this->db->table('variables')
|
||||
->select('var_valeur')
|
||||
->where('var_nom', 'promoteur_legacy_actif')
|
||||
->get()
|
||||
->getRow();
|
||||
|
||||
if ($rowVar !== null && (string) $rowVar->var_valeur === '0') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$compte = $this->db->table('inscriptions_comptes')
|
||||
->select('com_eve_promoteur')
|
||||
->where('com_id', $comId)
|
||||
|
||||
Reference in New Issue
Block a user