From 9e96862c96b4a05b4238cb09aa31df65455d9fab Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Wed, 4 Jan 2023 09:39:02 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20d'identificationCandidat,=20ajout?= =?UTF-8?q?=20de=20readStatus/saveStatus,=20ajout=20de=20fclose,=20ajout?= =?UTF-8?q?=20de=20strcasecmp,=20ajout=20cr=C3=A9er=20nouvel=20IUT,=20et?= =?UTF-8?q?=20mise=20de=20place=20phase=20candidature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/I/un.c | 216 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 178 insertions(+), 38 deletions(-) diff --git a/src/I/un.c b/src/I/un.c index e624db6..e2d4a27 100644 --- a/src/I/un.c +++ b/src/I/un.c @@ -24,20 +24,29 @@ void identificationCandidat(int* id, ListeCandidats* listePointer, int* nbCandid char nom[LEN_MAX]; - if(connexion == 'O') { + if(connexion == 'O' || connexion == 'o') { printf("\nTrès bien, merci de saisir votre ID : "); - scanf("%d", id); + + if(scanf("%d", id) == 0) { + *id = 0; + fprintf(stderr, "\n\e[0;91mErreur : cet ID n'existe pas !\n\n\e[0m"); + return; + } + if(*id > *nbCandidats) { *id = 0; fprintf(stderr, "\n\e[0;91mErreur : cet ID n'existe pas !\n\n\e[0m"); + return; } printf("Merci de confirmer votre nom de famille : "); scanf("%s", nom); if(strcasecmp(nom, (*listePointer)[*id-1]->nom) != 0) { + *id = 0; fprintf(stderr, "\n\e[0;91mErreur : le nom de famille ne correspond pas !\n\n\e[0m"); + return; } else { printf("\n\e[1;92mBienvenue %s %s !\n\e[1;91m" "N'oubliez pas de revenir au menu principal pour vous déconnecter à la fin de votre session !\n\n\e[0m", @@ -82,7 +91,9 @@ 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 - int choix, id = 0; // choix: Contient le choix de l'utilisateur dans le menu / id: contient id user si login + + // 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; printf("\n\nSouhaitez-vous vous connecter/enregistrer maintenant ou entrer en mode invité (O/N) ? : "); @@ -100,7 +111,8 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb printf("\t2 - Voir les disponibilités des départements dans un IUT\n\n"); printf("\t3 - Rechercher un département\n\n"); if(id != 0) { - printf("\t4 - Candidater\n\n"); + if(status) + printf("\t4 - Candidater\n\n"); printf("\t5 - Suivre sa candidature\n\n"); } else { printf("\t4 - S'identifier\n\n"); @@ -148,6 +160,58 @@ 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); } else { printf("S'identifier...\n\n"); identificationCandidat(&id, listePointer, nbCandidats); @@ -159,7 +223,12 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb if(id == 0) { fprintf(stderr, "\e[0;91mErreur : vous devez d'abord vous authentifier, merci de réessayer plus tard.\n\e[0m"); } - // TODO + + 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) @@ -177,7 +246,8 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb printf("\t2 - Voir les disponibilités des départements dans un IUT\n\n"); printf("\t3 - Rechercher un département\n\n"); if(id != 0) { - printf("\t4 - Candidater\n\n"); + if(status) + printf("\t4 - Candidater\n\n"); printf("\t5 - Suivre sa candidature\n\n"); } else { printf("\t4 - S'identifier\n\n"); @@ -240,7 +310,8 @@ void menuResponsable(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* void menuAdmin(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 - int choix; // Contient le choix de l'utilisateur dans le menu + // choix: Contient le choix de l'utilisateur dans le menu, status: contient le status actuel des recrutements + int choix, status = readStatus(); char pass[LEN_MAX]; printf("Merci d'entrer le mot de passe administrateur : "); @@ -257,11 +328,15 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil printf("--------------------------------------------------------------------\n"); printf("\t1 - Modifier le nombre de place d'une formation\n\n"); - printf("\t2 - Créer un nouveau département\n\n"); - printf("\t3 - Supprimer un département\n\n"); - printf("\t4 - Lancer/arrêter la phase de candidature\n\n"); - printf("\t5 - Modifier le nom du responsable d'un département\n\n"); - printf("\t6 - Liste des candidats\n\n"); + printf("\t2 - Créer un nouvel IUT\n\n"); + printf("\t3 - Créer un nouveau département\n\n"); + printf("\t4 - Supprimer un département\n\n"); + if(status) + printf("\t5 - Arrêter la phase de candidature\n\n"); + else + printf("\t5 - Lancer la phase de candidature\n\n"); + printf("\t6 - Modifier le nom du responsable d'un département\n\n"); + printf("\t7 - Liste des candidats\n\n"); printf("\t9 - Quitter\n"); printf("---------------------------------------------------------------------\n"); @@ -296,6 +371,23 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil 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); + break; + case 3: printf("Créer un nouveau département...\n\n"); char searchIUT2[LEN_MAX]; @@ -320,17 +412,17 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil ListeDept ldept = ville->ldept; - if(strcmp(ldept->departement, addDept) == 0) { + 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(strcmp(ldept->suiv->departement, addDept) == 0) break; + if(strcasecmp(ldept->suiv->departement, addDept) == 0) break; ldept = ldept->suiv; } - if(ldept->suiv != NULL && strcmp(ldept->suiv->departement, addDept) == 0) { + 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; } @@ -346,7 +438,7 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil printf("\n\e[1;32mLe département '%s' a bien été ajouté à l'IUT '%s' !\e[0m\n\n", addDept, searchIUT2); } break; - case 3: + case 4: printf("Supprimer un département...\n\n"); char searchIUT3[LEN_MAX]; @@ -374,11 +466,18 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil } break; - case 4: - printf("Lancer/arrêter la phase de candidature...\n\n"); - // TODO - break; case 5: + if(status) + printf("Arrêter la phase de candidature...\n\n"); + else + printf("Lancer la phase de candidature...\n\n"); + + saveStatus(status ? 0 : 1); + status = (status ? 0 : 1); + + printf("\n\e[1;32mLa phase de candidature à bien été %s !\e[0m\n\n", (status ? "lancée" : "arrêtée")); + 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]; @@ -400,7 +499,7 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil modifierNomResponsable(*tiutPointer, *nbVilles, searchIUT5, searchDept5, nom); } break; - case 6: + case 7: printf("Liste des candidats...\n"); printf("\n\e[4;37mListe des candidats (triés par ordre alphabétique) :\e[0m\n\n"); afficherListeCandidats(*listePointer, *nbCandidats); @@ -414,11 +513,15 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil printf("\n--------------------------------------------------------------------\n"); printf("\t1 - Modifier le nombre de place d'une formation\n\n"); - printf("\t2 - Créer un nouveau département\n\n"); - printf("\t3 - Supprimer un département\n\n"); - printf("\t4 - Lancer/arrêter la phase de candidature\n\n"); - printf("\t5 - Modifier le nom du responsable d'un département\n\n"); - printf("\t6 - Liste des candidats\n\n"); + printf("\t2 - Créer un nouvel IUT\n\n"); + printf("\t3 - Créer un nouveau département\n\n"); + printf("\t4 - Supprimer un département\n\n"); + if(status) + printf("\t5 - Arrêter la phase de candidature\n\n"); + else + printf("\t5 - Lancer la phase de candidature\n\n"); + printf("\t6 - Modifier le nom du responsable d'un département\n\n"); + printf("\t7 - Liste des candidats\n\n"); printf("\t9 - Quitter\n"); printf("---------------------------------------------------------------------\n"); @@ -535,16 +638,23 @@ VilleIUT* creerVille(void) { } void ajouterVille(VilleIUT*** tiutPointer, VilleIUT* ville, int* nbVilles) { - *tiutPointer = (VilleIUT**) realloc(*tiutPointer, (*nbVilles+1)*sizeof(VilleIUT*)); + VilleIUT** tiutNew = (VilleIUT**) realloc(*tiutPointer, (*nbVilles+1)*sizeof(VilleIUT*)); - *tiutPointer[*nbVilles] = ville; + if(tiutNew == NULL) { + perror("realloc"); + exit(errno); + } + + *tiutPointer = tiutNew; + + (*tiutPointer)[*nbVilles] = ville; *nbVilles += 1; } int rechercherVille(VilleIUT** tiut, int nbVilles, char* searchIUT) { int i=0; for(i=0; iville, searchIUT) == 0) + if(strcasecmp(tiut[i]->ville, searchIUT) == 0) return i; return -1; @@ -598,7 +708,7 @@ void afficherDepartement(VilleIUT** tiut, int nbVilles, char* searchDept) { ListeDept ldept = tiut[i]->ldept; if(ldept != NULL) { - if(strcmp(ldept->departement, searchDept) == 0) { + if(strcasecmp(ldept->departement, searchDept) == 0) { printf(" - %s\n", tiut[i]->ville); nb++; } else { @@ -606,7 +716,7 @@ void afficherDepartement(VilleIUT** tiut, int nbVilles, char* searchDept) { while(search->suiv != NULL) { search = search->suiv; - if(strcmp(search->departement, searchDept) == 0) { + if(strcasecmp(search->departement, searchDept) == 0) { printf(" - %s\n", tiut[i]->ville); nb++; } @@ -654,18 +764,18 @@ ListeDept ajouterDepartement(ListeDept ldept, MaillonDept* dept) { ListeDept supprimerDepartement(ListeDept ldept, char* searchDept) { int foundDept=0; - if(strcmp(ldept->departement, searchDept) == 0) { + if(strcasecmp(ldept->departement, searchDept) == 0) { ldept = ldept->suiv; foundDept = 1; } else { ListeDept search = ldept, tmp; - while(search->suiv != NULL && strcmp(search->departement, searchDept) != 0) { + while(search->suiv != NULL && strcasecmp(search->departement, searchDept) != 0) { tmp = search; search = search->suiv; } - if(strcmp(search->departement, searchDept) == 0) { + if(strcasecmp(search->departement, searchDept) == 0) { tmp->suiv = search->suiv; foundDept=1; } @@ -690,7 +800,7 @@ void modifierNbPlaces(VilleIUT** tiut, int nbVilles, char* searchIUT, char* sear ListeDept ldept = tiut[i]->ldept; if(ldept != NULL) { - if(strcmp(ldept->departement, searchDept) == 0) { + if(strcasecmp(ldept->departement, searchDept) == 0) { printf("\n\e[1;32mLe nombre de places de la formation '%s' à l'IUT '%s' est passé de %d à %d\e[0m\n\n", searchDept, searchIUT, ldept->nbP, nb); ldept->nbP = nb; foundDept = 1; @@ -698,7 +808,7 @@ void modifierNbPlaces(VilleIUT** tiut, int nbVilles, char* searchIUT, char* sear ListeDept search = ldept; while(search->suiv != NULL) { - if(strcmp(search->departement, searchDept) == 0) { + if(strcasecmp(search->departement, searchDept) == 0) { printf("\n\e[1;32mLe nombre de places de la formation '%s' à l'IUT '%s' est passé de %d à %d\e[0m\n\n", searchDept, searchIUT, search->nbP, nb); search->nbP = nb; foundDept = 1; @@ -723,7 +833,7 @@ void modifierNomResponsable(VilleIUT** tiut, int nbVilles, char* searchIUT, char ListeDept ldept = tiut[i]->ldept; if(ldept != NULL) { - if(strcmp(ldept->departement, searchDept) == 0) { + if(strcasecmp(ldept->departement, searchDept) == 0) { strcpy(ldept->responsable, nom); printf("\n\e[1;32mLe responsable de la formation '%s' à l'IUT '%s' est désormais '%s'.\e[0m\n\n", searchDept, searchIUT, ldept->responsable); foundDept = 1; @@ -732,7 +842,7 @@ void modifierNomResponsable(VilleIUT** tiut, int nbVilles, char* searchIUT, char while(search->suiv != NULL) { search = search->suiv; - if(strcmp(search->departement, searchDept) == 0) { + if(strcasecmp(search->departement, searchDept) == 0) { strcpy(search->responsable, nom); printf("\n\e[1;32mLe responsable de la formation '%s' à l'IUT '%s' est désormais '%s'.\e[0m\n\n", searchDept, searchIUT, search->responsable); foundDept = 1; @@ -860,6 +970,36 @@ VilleIUT** readVilles(int* nbVilles) { return tiut; } +int readStatus(void) { + int status; + + FILE *fe = fopen("donnees/status.don", "r"); + + if(fe == NULL) { + perror("fopen"); + exit(errno); + } + + fscanf(fe, "%d", &status); + + fclose(fe); + + return status; +} + +void saveStatus(int status) { + FILE *fe = fopen("donnees/status.don", "w"); + + if(fe == NULL) { + perror("fopen"); + exit(errno); + } + + fprintf(fe, "%d", status); + + fclose(fe); +} + void test(void) { /* Ajout des premières données