1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
function Suppression_Lignes_Tables ($Table, $Nom_Var, $Valeur) {
$Req_Delete = "delete from $Table where $Nom_Var = $Valeur";
$nb = 0;
try {
$dbh = $GLOBALS['bdd']->query($Req_Delete);
$nb = $dbh->rowCount();
}
catch (PDOException $e) {
echo "<h4><br>La requete est : ".$Req_Delete;
die('<br><strong>Erreur : ' . $e->getMessage()) . "</strong></h4>";
}
//echo " -----> dans fonction, $nb lignes supprimées dans $Table / $Req_Delete";
return $nb;
}
$Purger = Recup_Param("Purge", "Les adhérents", "");
$Nb_Mois_Retention = Recup_Param("Purge", "Les adhérents", "Delai rétention");
$Date_Select = strftime("%Y-%m-%d", mktime(0, 0, 0, date('m') - $Nb_Mois_Retention, date('d'), date('Y')));
echo "<h1><u>Suppression des adhérents avant $Date_Select</u></h1>";
$corp_mail .= "<h1><u>Suppression des adhérents</u></h1>";
// Définition des tables à supprimer les adhérents
$Tables = array(
array("Nom_Table" => "scf_licencies_profil", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_droits", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_avoirs", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_competences", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_contreindic_tempo", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_cotisations", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_cotisations_2", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_formation", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_formation_2", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_DP_Piscine", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_encadrant_formation", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_formations_souhaitees", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_badges_licencies", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_infos", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_niveau", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_parm_perso", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_RIFAP", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_saisons", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_session_suivie", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_validation", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies_vehicules", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_benevolat", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_benevolat_cerfa", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_Clefs_licencies", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_certificat_medical", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_certificat_medical_hist", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_sorties_licencies", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_sorties_pers_distrib_matos", "Nom_Var" => "idPers_Distrib", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_sondages_licencies", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_remise_cheques_licencies", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_intervenants", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_log", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0)
,array("Nom_Table" => "scf_licencies", "Nom_Var" => "idLicencie", "Nb_Lignes_Supprimees" => 0) // Doit êtrer en dernière ligne
);
$GLOBALS['bdd']->beginTransaction();
$Requete = "SELECT * FROM scf_licencies a
WHERE date(a.Date_Crea) < '$Date_Select'
and a.idLicencie > 1
and not EXISTS (SELECT 't' FROM scf_licencies_saisons w, scf_saisons z
WHERE a.idLicencie = w.idLicencie
AND w.idSaison = z.idSaison
AND z.Date_Debut >= '$Date_Select')";
echo "<br>Requete : $Requete";
try {
$dbh = $GLOBALS['bdd']->query($Requete);
$Result_Req = $dbh->fetchAll();
foreach ($Result_Req as $Un_Licencie) {
$corp_mail .= "<li>Suppression de " . $Un_Licencie['Prenom'] . " " . $Un_Licencie['Nom'] . "</li>";
echo "<h3>Suppression de " . $Un_Licencie['Prenom'] . " " . $Un_Licencie['Nom'] . " = " . $Un_Licencie['idLicencie'] . "</h3>";
// Avant de supprimer l'adhérents, s'il a créé ou modifié une tâche, il faut changer de personne.
// On met par défaut l'administrateur du site
$Req_Delete = "update scf_taches_a_faire set idCrea = 1 where idCrea = " . $Un_Licencie['idLicencie'];
try {
$dbh = $GLOBALS['bdd']->query($Req_Delete);
$nb = $dbh->rowCount();
}
catch (PDOException $e) {
echo "<h4><br>La requete est : ".$Req_Delete;
die('<br><strong>Erreur : ' . $e->getMessage()) . "</strong></h4>";
}
if ($nb > 0 ) echo "<br>Nb lignes modifiés dans scf_taches_a_faire avec idCrea à " . $Un_Licencie['idLicencie'] . " = $nb";
$Req_Delete = "update scf_taches_a_faire set idModif = 1 where idModif = " . $Un_Licencie['idLicencie'];
try {
$dbh = $GLOBALS['bdd']->query($Req_Delete);
$nb = $dbh->rowCount();
}
catch (PDOException $e) {
echo "<h4><br>La requete est : ".$Req_Delete;
die('<br><strong>Erreur : ' . $e->getMessage()) . "</strong></h4>";
}
if ($nb > 0 ) echo "<br>Nb lignes modifiés dans scf_taches_a_faire avec idModif à " . $Un_Licencie['idLicencie'] . " = $nb";
foreach ($Tables as $Un_Elm) {
$nb = Suppression_Lignes_Tables($Un_Elm['Nom_Table'], $Un_Elm['Nom_Var'], $Un_Licencie['idLicencie']);
$Un_Elm['Nb_Lignes_Supprimees'] += $nb;
//echo " ---- Nb = $nb - ELM : " ; print_r($Un_Elm) ; echo "<br>";
}
}
}
catch (PDOException $e)
{
echo "<h4><br>La requete des mails du site est : ".$Requete;
die('<br><strong>Erreur : ' . $e->getMessage()) . "</strong></h4>";
}
if ($Purger != 'O') {
$corp_mail .= "<h3>Rollback car paramètre à N</h3>";
echo "<h2>Rollback car paramètre à N</h2>";
$GLOBALS['bdd']->rollback();
}
else {
$GLOBALS['bdd']->commit();
}
$count = 0;
foreach ($Tables as $Un_Elm) {
$corp_mail .= "<br>Nb lignes supprimées dans " . $Un_Elm['Nom_Table'] . " : " . $Un_Elm['Nb_Lignes_Supprimees'];
$count += $Un_Elm['Nb_Lignes_Supprimees'];
} |
Partager