Restructuration du menuAdmin avec la création de fonctions séparées

master
Alix JEUDI--LEMOINE 2 years ago
parent 8725213805
commit dea09d1769

@ -91,7 +91,7 @@ void titreMenuPrincipal(void) {
void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVilles, int* nbCandidats) { 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 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 // 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(); int choix, id = 0, status = readStatus();
char connexion; char connexion;
@ -102,9 +102,10 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb
if(connexion == 'O') if(connexion == 'O')
identificationCandidat(&id, listePointer, nbCandidats); identificationCandidat(&id, listePointer, nbCandidats);
if(id != 0) if(id != 0) {
printf("\e[1;94mCandidat: %s %s, ID: %d\e[0m\n", (*listePointer)[id-1]->prenom, (*listePointer)[id-1]->nom, id); candidat = (*listePointer)[id-1];
else 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\e[1;94mInvité\e[0m\n");
printf("-----------------------------------------------------------------------\n"); printf("-----------------------------------------------------------------------\n");
printf("\t1 - Consulter les ville possédant un IUT\n\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: case 4:
if(id != 0) { if(id != 0) {
printf("Candidater...\n\n"); printf("Candidater...\n\n");
if(status)
//afficherCandidat((*listePointer)[id-1]); menuCandidat_candidater(*tiutPointer, *nbVilles, candidat);
else
Candidature* candid = creerCandidature(); fprintf(stderr, "\e[0;91mErreur : la phase de candidature est arrêtée.\n\e[0m");
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 { } else {
printf("S'identifier...\n\n"); printf("S'identifier...\n\n");
identificationCandidat(&id, listePointer, nbCandidats); identificationCandidat(&id, listePointer, nbCandidats);
if(id != 0)
candidat = (*listePointer)[id-1];
} }
break; break;
case 5: case 5:
printf("Suivre sa candidature...\n\n"); 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"); 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) 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"); fprintf(stderr, "\e[0;91mErreur : vous n'avez aucune candidature en cours, merci de réessayer plus tard.\n\e[0m");
else else
afficherCandidatures(candidat->listeCandidatures, candidat->nbCandidatures); afficherCandidatures(candidat->listeCandidatures, candidat->nbCandidatures);
break; break;
default: default:
// Permet d'aspirer les caractères en trop sur stdin (évite de répéter le message d'erreur X fois) // 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) 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 else
printf("\n\e[1;94mInvité\e[0m\n"); printf("\n\e[1;94mInvité\e[0m\n");
printf("-----------------------------------------------------------------------\n"); printf("-----------------------------------------------------------------------\n");
@ -349,125 +303,19 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil
switch (choix) { switch (choix) {
case 1: case 1:
printf("Modifier le nombre de place d'une formation...\n\n"); printf("Modifier le nombre de place d'une formation...\n\n");
menuAdmin_modifierPlaces(*tiutPointer, *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)
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);
}
break; break;
case 2: case 2:
printf("Créer un nouvel IUT...\n\n"); printf("Créer un nouvel IUT...\n\n");
menuAdmin_creerIUT(tiutPointer, nbVilles);
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; break;
case 3: case 3:
printf("Créer un nouveau département...\n\n"); printf("Créer un nouveau département...\n\n");
menuAdmin_creerDepartement(*tiutPointer, *nbVilles);
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);
}
break; break;
case 4: case 4:
printf("Supprimer un département...\n\n"); printf("Supprimer un département...\n\n");
menuAdmin_supprimerDepartement(*tiutPointer, *nbVilles);
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);
}
break; break;
case 5: case 5:
if(status) if(status)
@ -482,25 +330,7 @@ void menuAdmin(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nbVil
break; break;
case 6: case 6:
printf("Modifier le nom du responsable d'un département...\n\n"); printf("Modifier le nom du responsable d'un département...\n\n");
menuAdmin_modifierResponsable(*tiutPointer, *nbVilles);
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);
}
break; break;
case 7: case 7:
printf("Liste des candidats...\n"); 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"); 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* creerVille(void) {
VilleIUT* ville = (VilleIUT*) malloc(sizeof(VilleIUT)); VilleIUT* ville = (VilleIUT*) malloc(sizeof(VilleIUT));

Loading…
Cancel
Save