}
if ($_SESSION["admin_status"] == 1) {
    if (isset($_GET["sup"])) {
        // recherche adherent
        $requetesel = "SELECT id_adh\n\t\t\t\tFROM " . PREFIX_DB . "cotisations \n\t\t\t\tWHERE id_cotis=" . $DB->qstr($_GET["sup"], get_magic_quotes_gpc());
        $result_adh =& $DB->Execute($requetesel);
        if (!$result_adh->EOF) {
            $id_adh = $result_adh->fields["id_adh"];
            $requetesup = "SELECT nom_adh, prenom_adh FROM " . PREFIX_DB . "adherents WHERE id_adh=" . $DB->qstr($id_adh, get_magic_quotes_gpc());
            $resultat = $DB->Execute($requetesup);
            if (!$resultat->EOF) {
                // supression record cotisation
                $requetesup = "DELETE FROM " . PREFIX_DB . "cotisations \n\t\t\t\t    \t    WHERE id_cotis=" . $DB->qstr($_GET["sup"], get_magic_quotes_gpc());
                $DB->Execute($requetesup);
                // mise a jour de l'�ch�ance
                $date_fin = get_echeance($DB, $id_adh);
                if ($date_fin != "") {
                    $date_fin_update = "'" . $date_fin[2] . "-" . $date_fin[1] . "-" . $date_fin[0] . "'";
                } else {
                    $date_fin_update = "NULL";
                }
                $requeteup = "UPDATE " . PREFIX_DB . "adherents\n\t\t\t\t\t    SET date_echeance=" . $date_fin_update . "\n\t\t\t\t\t    WHERE id_adh=" . $DB->qstr($id_adh, get_magic_quotes_gpc());
                $DB->Execute($requeteup);
                dblog("Contribution deleted:", strtoupper($resultat->fields[0]) . " " . $resultat->fields[1], $requetesup);
            }
            $resultat->Close();
        }
        $result_adh->Close();
    }
}
$date_enreg_format = $DB->SQLDate('d/m/Y', PREFIX_DB . 'cotisations.date_enreg');
        }
    }
    if (!isset($contribution['duree_mois_cotis']) || $contribution['duree_mois_cotis'] == "") {
        // On error restore entered value or default to display the form again
        if (isset($_POST['duree_mois_cotis']) && $_POST['duree_mois_cotis'] != "") {
            $contribution['duree_mois_cotis'] = $_POST['duree_mois_cotis'];
        } else {
            $contribution['duree_mois_cotis'] = PREF_MEMBERSHIP_EXT;
        }
    }
} else {
    if ($contribution["id_cotis"] == "") {
        // initialiser la structure contribution à vide (nouvelle contribution)
        $contribution['duree_mois_cotis'] = PREF_MEMBERSHIP_EXT;
        if ($cotis_extension && isset($contribution["id_adh"])) {
            $curend = get_echeance($DB, $contribution["id_adh"]);
            if ($curend == "") {
                $beg_cotis = time();
            } else {
                $beg_cotis = mktime(0, 0, 0, $curend[1], $curend[0], $curend[2]);
                if ($beg_cotis < time()) {
                    $beg_cotis = time();
                }
                // Member didn't renew on time
            }
        } else {
            $beg_cotis = time();
        }
        $contribution['date_debut_cotis'] = date("d/m/Y", $beg_cotis);
        // End date is the date of next period after this one
        $contribution['date_fin_cotis'] = beg_membership_after($beg_cotis);
                                $error_detected[] = _T("A problem happened while sending password for account:") . " \"" . $_POST["email_adh"] . "\"";
                                break;
                        }
                    }
                } else {
                    $error_detected[] = _T("Sent mail is checked but there is no email address") . " \"" . $_POST["login_adh"] . "\"";
                }
            } elseif ($_POST["mail_confirm"] == "1" && PREF_MAIL_METHOD == 0) {
                //if mail has been disabled in the preferences, we should not be here ; we do not throw an error, just a simple warning that will be show later
                $_SESSION['galette']['mail_warning'] = _T("You asked Galette to send a confirmation mail to the member, but mail has been disabled in the preferences.");
            }
        }
        // dynamic fields
        set_all_dynamic_fields($DB, 'adh', $adherent['id_adh'], $adherent['dyn']);
        // deadline
        $date_fin = get_echeance($DB, $adherent['id_adh']);
        if ($date_fin != "") {
            $date_fin_update = $DB->DBDate($date_fin[2] . '-' . $date_fin[1] . '-' . $date_fin[0]);
        } else {
            $date_fin_update = "NULL";
        }
        $requete = "UPDATE " . PREFIX_DB . "adherents\n\t\t\t\t\tSET date_echeance=" . $date_fin_update . "\n\t\t\t\t\tWHERE id_adh=" . $adherent['id_adh'];
        $DB->Execute($requete);
        if (!isset($_POST['id_adh'])) {
            header('location: ajouter_contribution.php?id_adh=' . $adherent['id_adh']);
        } elseif (!isset($_POST['del_photo']) && count($error_detected) == 0) {
            header('location: voir_adherent.php?id_adh=' . $adherent['id_adh']);
        }
    }
} else {
    if ($adherent["id_adh"] == "") {