@ -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 ( " \n Trè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 \n Souhaitez-vous vous connecter/enregistrer maintenant ou entrer en mode invité (O/N) ? : " ) ;
@ -100,6 +111,7 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb
printf ( " \t 2 - Voir les disponibilités des départements dans un IUT \n \n " ) ;
printf ( " \t 3 - Rechercher un département \n \n " ) ;
if ( id ! = 0 ) {
if ( status )
printf ( " \t 4 - Candidater \n \n " ) ;
printf ( " \t 5 - Suivre sa candidature \n \n " ) ;
} else {
@ -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,6 +246,7 @@ void menuCandidat(VilleIUT*** tiutPointer, ListeCandidats* listePointer, int* nb
printf ( " \t 2 - Voir les disponibilités des départements dans un IUT \n \n " ) ;
printf ( " \t 3 - Rechercher un département \n \n " ) ;
if ( id ! = 0 ) {
if ( status )
printf ( " \t 4 - Candidater \n \n " ) ;
printf ( " \t 5 - Suivre sa candidature \n \n " ) ;
} else {
@ -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 ( " \t 1 - Modifier le nombre de place d'une formation \n \n " ) ;
printf ( " \t 2 - Créer un nouveau département \n \n " ) ;
printf ( " \t 3 - Supprimer un département \n \n " ) ;
printf ( " \t 4 - Lancer/arrêter la phase de candidature \n \n " ) ;
printf ( " \t 5 - Modifier le nom du responsable d'un département \n \n " ) ;
printf ( " \t 6 - Liste des candidats \n \n " ) ;
printf ( " \t 2 - Créer un nouvel IUT \n \n " ) ;
printf ( " \t 3 - Créer un nouveau département \n \n " ) ;
printf ( " \t 4 - Supprimer un département \n \n " ) ;
if ( status )
printf ( " \t 5 - Arrêter la phase de candidature \n \n " ) ;
else
printf ( " \t 5 - Lancer la phase de candidature \n \n " ) ;
printf ( " \t 6 - Modifier le nom du responsable d'un département \n \n " ) ;
printf ( " \t 7 - Liste des candidats \n \n " ) ;
printf ( " \t 9 - 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 ( strc mp( ldept - > departement , addDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( ldept - > suiv - > departement , addDept ) = = 0 ) break ;
if ( strc asec mp( ldept - > suiv - > departement , addDept ) = = 0 ) break ;
ldept = ldept - > suiv ;
}
if ( ldept - > suiv ! = NULL & & strc mp( ldept - > suiv - > departement , addDept ) = = 0 ) {
if ( ldept - > suiv ! = NULL & & strc asec mp( 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 ( " \t 1 - Modifier le nombre de place d'une formation \n \n " ) ;
printf ( " \t 2 - Créer un nouveau département \n \n " ) ;
printf ( " \t 3 - Supprimer un département \n \n " ) ;
printf ( " \t 4 - Lancer/arrêter la phase de candidature \n \n " ) ;
printf ( " \t 5 - Modifier le nom du responsable d'un département \n \n " ) ;
printf ( " \t 6 - Liste des candidats \n \n " ) ;
printf ( " \t 2 - Créer un nouvel IUT \n \n " ) ;
printf ( " \t 3 - Créer un nouveau département \n \n " ) ;
printf ( " \t 4 - Supprimer un département \n \n " ) ;
if ( status )
printf ( " \t 5 - Arrêter la phase de candidature \n \n " ) ;
else
printf ( " \t 5 - Lancer la phase de candidature \n \n " ) ;
printf ( " \t 6 - Modifier le nom du responsable d'un département \n \n " ) ;
printf ( " \t 7 - Liste des candidats \n \n " ) ;
printf ( " \t 9 - 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 * ) ) ;
if ( tiutNew = = NULL ) {
perror ( " realloc " ) ;
exit ( errno ) ;
}
* tiutPointer = tiutNew ;
* tiutPointer [ * nbVilles ] = ville ;
( * tiutPointer ) [ * nbVilles ] = ville ;
* nbVilles + = 1 ;
}
int rechercherVille ( VilleIUT * * tiut , int nbVilles , char * searchIUT ) {
int i = 0 ;
for ( i = 0 ; i < nbVilles ; i + + )
if ( strc mp( tiut [ i ] - > ville , searchIUT ) = = 0 )
if ( strc asec mp( 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 ( strc mp( ldept - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( search - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( ldept - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( ldept - > departement , searchDept ) = = 0 ) {
ldept = ldept - > suiv ;
foundDept = 1 ;
} else {
ListeDept search = ldept , tmp ;
while ( search - > suiv ! = NULL & & strc mp( search - > departement , searchDept ) ! = 0 ) {
while ( search - > suiv ! = NULL & & strc asec mp( search - > departement , searchDept ) ! = 0 ) {
tmp = search ;
search = search - > suiv ;
}
if ( strc mp( search - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( ldept - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( search - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( ldept - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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 ( strc mp( search - > departement , searchDept ) = = 0 ) {
if ( strc asec mp( 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