From dea09d176966f4c9e40e2fd48b8ef576d9f76a3d Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Wed, 4 Jan 2023 11:34:50 +0100 Subject: [PATCH] =?UTF-8?q?Restructuration=20du=20menuAdmin=20avec=20la=20?= =?UTF-8?q?cr=C3=A9ation=20de=20fonctions=20s=C3=A9par=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/I/un.c | 405 ++++++++++++++++++++++++++++------------------------- 1 file changed, 215 insertions(+), 190 deletions(-) diff --git a/src/I/un.c b/src/I/un.c index 7c0b083..ac0ad01 100644 --- a/src/I/un.c +++ b/src/I/un.c @@ -91,7 +91,7 @@ void titreMenuPrincipal(void) { void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVilles, int* nbCandidats) { char poubelle; // Permet de stocker les caractères aspirés en trop sur stdin lors du choix dans le menu - + Candidat* candidat; // choix: Contient le choix de l'utilisateur dans le menu / id: contient id user si login / status: candidatures ouvertes ou fermées int choix, id = 0, status = readStatus(); char connexion; @@ -101,10 +101,11 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb if(connexion == 'O') identificationCandidat(&id, listePointer, nbCandidats); - - if(id != 0) - printf("\e[1;94mCandidat: %s %s, ID: %d\e[0m\n", (*listePointer)[id-1]->prenom, (*listePointer)[id-1]->nom, id); - else + + if(id != 0) { + candidat = (*listePointer)[id-1]; + printf("\e[1;94mCandidat: %s %s, ID: %d\e[0m\n", candidat->prenom, candidat->nom, id); + } else printf("\n\e[1;94mInvité\e[0m\n"); printf("-----------------------------------------------------------------------\n"); printf("\t1 - Consulter les ville possédant un IUT\n\n"); @@ -160,75 +161,28 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb case 4: if(id != 0) { printf("Candidater...\n\n"); - - //afficherCandidat((*listePointer)[id-1]); - - Candidature* candid = creerCandidature(); - - char searchIUT[LEN_MAX], searchDept[LEN_MAX]; - printf("Entrez la ville dans laquelle vous souhaitez candidater : "); - scanf("%s", searchIUT); - - if(strcasecmp(searchIUT, "q") == 0) - break; - - int i = rechercherVille(*tiutPointer, *nbVilles, searchIUT); - - if(i == -1) { - fprintf(stderr, "\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT); - break; - } - - printf("Entrez le département dans lequel vous souhaitez candidater : "); - scanf("%*c%[^\n]", searchDept); - - int found = 0; - ListeDept liste = (*tiutPointer)[i]->ldept; - - if(strcmp(liste->departement, searchDept) == 0) - found=1; - - while(liste->suiv != NULL) { - liste = liste->suiv; - if(strcmp(liste->departement, searchDept) == 0) - found=1; - } - - if(found == 0) { - fprintf(stderr, "\e[1;91mErreur: le département '%s' n'existe pas dans l'IUT '%s'.\e[0m\n\n", searchDept, searchIUT); - break; - } - - strcpy(candid->ville, searchIUT); - strcpy(candid->departement, searchDept); - - Candidat* candidat = (*listePointer)[id-1]; - - if(checkCandidature(candidat, *candid) == -1) { - fprintf(stderr, "\n\e[1;91mErreur: vous avez déjà candidaté pour le département '%s' dans l'IUT '%s'.\e[0m\n\n", searchDept, searchIUT); - break; - } - - ajouterCandidature(candidat, candid); - - printf("\n\e[1;32mVotre candidature au département '%s' à l'IUT '%s' a bien été prise en compte !\e[0m\n\n", searchDept, searchIUT); + if(status) + menuCandidat_candidater(*tiutPointer, *nbVilles, candidat); + else + fprintf(stderr, "\e[0;91mErreur : la phase de candidature est arrêtée.\n\e[0m"); } else { printf("S'identifier...\n\n"); identificationCandidat(&id, listePointer, nbCandidats); + if(id != 0) + candidat = (*listePointer)[id-1]; } break; case 5: printf("Suivre sa candidature...\n\n"); - if(id == 0) { + if(id == 0) fprintf(stderr, "\e[0;91mErreur : vous devez d'abord vous authentifier, merci de réessayer plus tard.\n\e[0m"); - } - Candidat* candidat = (*listePointer)[id-1]; if(candidat->nbCandidatures == 0) fprintf(stderr, "\e[0;91mErreur : vous n'avez aucune candidature en cours, merci de réessayer plus tard.\n\e[0m"); else afficherCandidatures(candidat->listeCandidatures, candidat->nbCandidatures); + break; default: // Permet d'aspirer les caractères en trop sur stdin (évite de répéter le message d'erreur X fois) @@ -238,7 +192,7 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb } if(id != 0) - printf("\n\e[1;94mCandidat: %s %s, ID: %d\e[0m\n", (*listePointer)[id-1]->prenom, (*listePointer)[id-1]->nom, id); + printf("\n\e[1;94mCandidat: %s %s, ID: %d\e[0m\n", candidat->prenom, candidat->nom, id); else printf("\n\e[1;94mInvité\e[0m\n"); printf("-----------------------------------------------------------------------\n"); @@ -349,125 +303,19 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil switch (choix) { case 1: printf("Modifier le nombre de place d'une formation...\n\n"); - - int nbPlaces; - char searchIUT[LEN_MAX], searchDept[LEN_MAX]; - printf("Entrez une ville (tapez q pour annuler) : "); - scanf("%s", searchIUT); - - if(strcasecmp(searchIUT, "q") == 0) - break; - - int code = afficherListeDepartement(*tiutPointer, *nbVilles, searchIUT); - - if(code) { - printf("Quel département souhaitez-vous modifier ? : "); - scanf("%s", searchDept); - printf("Entrez le nouveau nombre de places pour le département '%s' : ", searchDept); - scanf("%d", &nbPlaces); - - modifierNbPlaces(*tiutPointer, *nbVilles, searchIUT, searchDept, nbPlaces); - } - + menuAdmin_modifierPlaces(*tiutPointer, *nbVilles); break; case 2: printf("Créer un nouvel IUT...\n\n"); - - char nameIUT[LEN_MAX]; - printf("Entrez le nom de la ville (tapez q pour annuler) : "); - scanf("%s", nameIUT); - - if(strcasecmp(nameIUT, "q") == 0) - break; - - VilleIUT* ville = creerVille(); - strcpy(ville->ville, nameIUT); - - ajouterVille(tiutPointer, ville, nbVilles); - - printf("\n\e[1;32mL'IUT '%s' a bien été créé !\e[0m\n\n", nameIUT); + menuAdmin_creerIUT(tiutPointer, nbVilles); break; case 3: printf("Créer un nouveau département...\n\n"); - - char searchIUT2[LEN_MAX]; - printf("Entrez la ville dans laquelle vous souhaitez ajouter un département (tapez q pour annuler) : "); - scanf("%s", searchIUT2); - - if(strcasecmp(searchIUT2, "q") == 0) - break; - - int i2 = rechercherVille(*tiutPointer, *nbVilles, searchIUT2); - - if(i2 == -1) - fprintf(stderr, "\n\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT2); - else { - VilleIUT* ville = (*tiutPointer)[i2]; - - int nbP; - char addDept[LEN_MAX], responsable[LEN_MAX]; - - printf("Entrez le nom du nouveau département : "); - scanf("%*c%[^\n]", addDept); - - ListeDept ldept = ville->ldept; - - if(ldept != NULL) { - if(strcasecmp(ldept->departement, addDept) == 0) { - fprintf(stderr, "\n\e[1;91mErreur: le département '%s' existe déjà dans l'IUT '%s'.\e[0m\n\n", addDept, searchIUT2); - break; - } - - while(ldept->suiv != NULL) { - if(strcasecmp(ldept->suiv->departement, addDept) == 0) break; - ldept = ldept->suiv; - } - - if(ldept->suiv != NULL && strcasecmp(ldept->suiv->departement, addDept) == 0) { - fprintf(stderr, "\n\e[1;91mErreur: le département '%s' existe déjà dans l'IUT '%s'.\e[0m\n\n", addDept, searchIUT2); - break; - } - } - - - printf("Entrez le nombre de place disponibles en 1ère année : "); - scanf("%d", &nbP); - printf("Entrez le nom du responsable de ce département : "); - scanf("%*c%[^\n]", responsable); - - MaillonDept* dept = creerDepartement(addDept, nbP, responsable); - ville->ldept = ajouterDepartement(ville->ldept, dept); - - printf("\n\e[1;32mLe département '%s' a bien été ajouté à l'IUT '%s' !\e[0m\n\n", addDept, searchIUT2); - } + menuAdmin_creerDepartement(*tiutPointer, *nbVilles); break; case 4: printf("Supprimer un département...\n\n"); - - char searchIUT3[LEN_MAX]; - printf("Entrez la ville dans laquelle vous souhaitez supprimer un département (tapez q pour annuler) : "); - scanf("%s", searchIUT3); - - if(strcasecmp(searchIUT3, "q") == 0) - break; - - int i3 = rechercherVille(*tiutPointer, *nbVilles, searchIUT3); - - if(i3 == -1) - fprintf(stderr, "\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT3); - else { - VilleIUT* ville3 = *tiutPointer[i3]; - - afficherListeDepartement(*tiutPointer, *nbVilles, searchIUT3); - - char searchDept3[LEN_MAX]; - printf("Quel département souhaitez-vous supprimer ? : "); - scanf("%*c%[^\n]", searchDept3); - - ville3->ldept = supprimerDepartement(ville3->ldept, searchDept3); - - - } + menuAdmin_supprimerDepartement(*tiutPointer, *nbVilles); break; case 5: if(status) @@ -482,25 +330,7 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil break; case 6: printf("Modifier le nom du responsable d'un département...\n\n"); - - char searchIUT5[LEN_MAX], searchDept5[LEN_MAX], nom[LEN_MAX]; - printf("Dans quel IUT souhaitez-vous faire une modification ? (tapez q pour annuler) : "); - scanf("%s", searchIUT5); - - if(strcasecmp(searchIUT5, "q") == 0) - break; - - int code5 = afficherListeDepartement(*tiutPointer, *nbVilles, searchIUT5); - - if(code5 != -1) { - printf("Quel département souhaitez-vous modifier ? : "); - scanf("%s", searchDept5); - - printf("Quel est le nom du nouveau responsable : "); - scanf("%*c%[^\n]", nom); - - modifierNomResponsable(*tiutPointer, *nbVilles, searchIUT5, searchDept5, nom); - } + menuAdmin_modifierResponsable(*tiutPointer, *nbVilles); break; case 7: printf("Liste des candidats...\n"); @@ -627,6 +457,201 @@ void menuPrincipal(/* TODO: prise en compte des status actuels du recrutement */ printf("\nFermeture de l'application...\n"); } +// FONCTIONS MENU CANDIDAT + +void menuCandidat_candidater(VilleIUT** tiut, int nbVilles, Candidat* candidat) { + Candidature* candid = creerCandidature(); + + char searchIUT[LEN_MAX], searchDept[LEN_MAX]; + printf("Entrez la ville dans laquelle vous souhaitez candidater : "); + scanf("%s", searchIUT); + + if(strcasecmp(searchIUT, "q") == 0) + return; + + int i = rechercherVille(tiut, nbVilles, searchIUT); + + if(i == -1) { + fprintf(stderr, "\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT); + return; + } + + printf("Entrez le département dans lequel vous souhaitez candidater : "); + scanf("%*c%[^\n]", searchDept); + + int found = 0; + ListeDept liste = tiut[i]->ldept; + + if(strcmp(liste->departement, searchDept) == 0) + found=1; + + while(liste->suiv != NULL) { + liste = liste->suiv; + if(strcmp(liste->departement, searchDept) == 0) + found=1; + } + + if(found == 0) { + fprintf(stderr, "\e[1;91mErreur: le département '%s' n'existe pas dans l'IUT '%s'.\e[0m\n\n", searchDept, searchIUT); + return; + } + + strcpy(candid->ville, searchIUT); + strcpy(candid->departement, searchDept); + + if(checkCandidature(candidat, *candid) == -1) { + fprintf(stderr, "\n\e[1;91mErreur: vous avez déjà candidaté pour le département '%s' dans l'IUT '%s'.\e[0m\n\n", searchDept, searchIUT); + return; + } + + ajouterCandidature(candidat, candid); + + printf("\n\e[1;32mVotre candidature au département '%s' à l'IUT '%s' a bien été prise en compte !\e[0m\n\n", searchDept, searchIUT); +} + +void menuAdmin_modifierPlaces(VilleIUT** tiut, int nbVilles) { + int nbPlaces; + char searchIUT[LEN_MAX], searchDept[LEN_MAX]; + printf("Entrez une ville (tapez q pour annuler) : "); + scanf("%s", searchIUT); + + if(strcasecmp(searchIUT, "q") == 0) + return; + + int code = afficherListeDepartement(tiut, nbVilles, searchIUT); + + if(code != -1) { + printf("Quel département souhaitez-vous modifier ? : "); + scanf("%s", searchDept); + printf("Entrez le nouveau nombre de places pour le département '%s' : ", searchDept); + scanf("%d", &nbPlaces); + + modifierNbPlaces(tiut, nbVilles, searchIUT, searchDept, nbPlaces); + } +} + +void menuAdmin_creerIUT(VilleIUT*** tiutPointer, int* nbVilles) { + char nameIUT[LEN_MAX]; + printf("Entrez le nom de la ville (tapez q pour annuler) : "); + scanf("%s", nameIUT); + + if(strcasecmp(nameIUT, "q") == 0) + return; + + VilleIUT* ville = creerVille(); + strcpy(ville->ville, nameIUT); + + ajouterVille(tiutPointer, ville, nbVilles); + + printf("\n\e[1;32mL'IUT '%s' a bien été créé !\e[0m\n\n", nameIUT); +} + +void menuAdmin_creerDepartement(VilleIUT** tiut, int nbVilles) { + int i, nbP; + char searchIUT[LEN_MAX], addDept[LEN_MAX], responsable[LEN_MAX]; + + VilleIUT* ville; + ListeDept ldept; + MaillonDept* dept; + + printf("Entrez la ville dans laquelle vous souhaitez ajouter un département (tapez q pour annuler) : "); + scanf("%s", searchIUT); + + if(strcasecmp(searchIUT, "q") == 0) + return; + + i = rechercherVille(tiut, nbVilles, searchIUT); + + if(i == -1) + fprintf(stderr, "\n\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT); + else { + ville = tiut[i]; + + printf("Entrez le nom du nouveau département : "); + scanf("%*c%[^\n]", addDept); + + ldept = ville->ldept; + + if(ldept != NULL) { + if(strcasecmp(ldept->departement, addDept) == 0) { + fprintf(stderr, "\n\e[1;91mErreur: le département '%s' existe déjà dans l'IUT '%s'.\e[0m\n\n", addDept, searchIUT); + return; + } + + while(ldept->suiv != NULL) { + if(strcasecmp(ldept->suiv->departement, addDept) == 0) return; + ldept = ldept->suiv; + } + + if(ldept->suiv != NULL && strcasecmp(ldept->suiv->departement, addDept) == 0) { + fprintf(stderr, "\n\e[1;91mErreur: le département '%s' existe déjà dans l'IUT '%s'.\e[0m\n\n", addDept, searchIUT); + return; + } + } + + + printf("Entrez le nombre de place disponibles en 1ère année : "); + scanf("%d", &nbP); + printf("Entrez le nom du responsable de ce département : "); + scanf("%*c%[^\n]", responsable); + + dept = creerDepartement(addDept, nbP, responsable); + ville->ldept = ajouterDepartement(ville->ldept, dept); + + printf("\n\e[1;32mLe département '%s' a bien été ajouté à l'IUT '%s' !\e[0m\n\n", addDept, searchIUT); + } +} + +void menuAdmin_supprimerDepartement(VilleIUT** tiut, int nbVilles) { + char searchIUT[LEN_MAX], searchDept[LEN_MAX]; + + VilleIUT* ville; + + printf("Entrez la ville dans laquelle vous souhaitez supprimer un département (tapez q pour annuler) : "); + scanf("%s", searchIUT); + + if(strcasecmp(searchIUT, "q") == 0) + return; + + int i = rechercherVille(tiut, nbVilles, searchIUT); + + if(i == -1) + fprintf(stderr, "\e[1;91mErreur: la ville '%s' n'est pas dans la liste des IUT.\e[0m\n\n", searchIUT); + else { + ville = tiut[i]; + + afficherListeDepartement(tiut, nbVilles, searchIUT); + + printf("Quel département souhaitez-vous supprimer ? : "); + scanf("%*c%[^\n]", searchDept); + + ville->ldept = supprimerDepartement(ville->ldept, searchDept); + } +} + +void menuAdmin_modifierResponsable(VilleIUT** tiut, int nbVilles) { + int code; + char searchIUT[LEN_MAX], searchDept[LEN_MAX], nom[LEN_MAX]; + + printf("Dans quel IUT souhaitez-vous faire une modification ? (tapez q pour annuler) : "); + scanf("%s", searchIUT); + + if(strcasecmp(searchIUT, "q") == 0) + return; + + code = afficherListeDepartement(tiut, nbVilles, searchIUT); + + if(code != -1) { + printf("Quel département souhaitez-vous modifier ? : "); + scanf("%s", searchDept); + + printf("Quel est le nom du nouveau responsable : "); + scanf("%*c%[^\n]", nom); + + modifierNomResponsable(tiut, nbVilles, searchIUT, searchDept, nom); + } +} + VilleIUT* creerVille(void) { VilleIUT* ville = (VilleIUT*) malloc(sizeof(VilleIUT));