@ -1,5 +1,393 @@
# include "Jsae.h"
# include "Jsae.h"
ListeDept listeDeptNouv ( void )
{
ListeDept lDept ;
lDept = NULL ;
return lDept ;
}
ListeDept insererEntete ( ListeDept lDept , Departement d )
{
MaillonDept * m ;
m = ( MaillonDept * ) malloc ( sizeof ( MaillonDept ) ) ;
if ( m = = NULL )
{
printf ( " Problème d'allocation mémoire lors de l'insertion \n " ) ;
exit ( 1 ) ;
}
m - > d = d ;
m - > suiv = lDept ;
return m ;
}
ListeDept insererDept ( ListeDept lDept , Departement d )
{
if ( lDept = = NULL )
return insererEntete ( lDept , d ) ;
if ( strcmp ( d . dept , lDept - > d . dept ) < 0 )
return insererEntete ( lDept , d ) ;
if ( strcmp ( d . dept , lDept - > d . dept ) = = 0 )
printf ( " Département déjà présent dans cet IUT \n " ) ;
return lDept ;
lDept - > suiv = insererDept ( lDept - > suiv , d ) ;
return lDept ;
}
ListeDept supprimerEntete ( ListeDept lDept )
{
ListeDept aux ;
if ( lDept = = NULL )
{
printf ( " Opération interdite \n " ) ;
exit ( 1 ) ;
}
aux = lDept ;
lDept = lDept - > suiv ;
free ( aux ) ;
return lDept ;
}
ListeDept supprimerDept ( ListeDept lDept , char * dep )
{
if ( lDept = = NULL )
return lDept ;
if ( strcmp ( dep , lDept - > d . dept ) < 0 )
return lDept ;
if ( strcmp ( dep , lDept - > d . dept ) = = 0 )
return supprimerEntete ( lDept ) ;
lDept - > suiv = supprimerDept ( lDept - > suiv , dep ) ;
return lDept ;
}
int longueur ( ListeDept lDept )
{
int compt = 0 ;
while ( lDept ! = NULL )
{
compt = compt + 1 ;
lDept = lDept - > suiv ;
}
return compt ;
}
bool vide ( ListeDept lDept )
{
if ( lDept = = NULL )
return true ;
return false ;
}
/*int tete(Liste l){
if ( l = = NULL ) {
printf ( " Opération interdite \n " ) ;
exit ( 1 )
}
return l - > v ;
} */
ListeDept rechercherDept ( ListeDept lDept , char dept [ ] , int * trouve )
{
if ( vide ( lDept ) )
{
* trouve = 0 ;
return lDept ;
}
if ( strcmp ( dept , lDept - > d . dept ) < 0 )
{
trouve = 0 ;
return lDept ;
}
if ( strcmp ( dept , lDept - > d . dept ) = = 0 )
{
* trouve = 1 ;
return lDept ;
}
return rechercherDept ( lDept - > suiv , dept , trouve ) ;
}
void miseAJourPlaces ( VilleIUT * tiut [ ] , int tLog )
{
int trouve , pos , places ;
char ville [ 31 ] , dept [ 31 ] , choix ;
ListeDept l ;
printf ( " Dans quelle ville se situe le département concerné ? \n Saisie : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Cette ville n'existe pas, veuillez re-saisir : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
}
l = tiut [ pos ] - > lDept ;
printf ( " Quel département souhaitez-vous mettre à jour ? \n Saisie : " ) ;
scanf ( " %s%*c " , dept ) ;
printf ( " \n " ) ;
l = rechercherDept ( l , dept , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Ce département n'existe pas, veuillez-resaisir : " ) ;
scanf ( " %s%*c " , dept ) ;
printf ( " \n " ) ;
l = rechercherDept ( l , dept , & trouve ) ;
}
printf ( " Vous avez sélectionné le département %s dans la ville de %s. \n Souhaitez-vous continuez ? (O/N) \n Saisie : " , dept , ville ) ;
scanf ( " %c%*c " , & choix ) ;
printf ( " \n " ) ;
if ( choix = = ' N ' )
{
return ;
}
printf ( " Il y a actuellement %d places. \n Quel est le nouveau nombre de places ? \n Saisie : " , l - > d . nbP ) ;
scanf ( " %d%*c " , & places ) ;
printf ( " \n Vous avez saisie %d places, veuillez confirmez (O/N) \n Saisie : " , places ) ;
scanf ( " %c%*c " , & choix ) ;
printf ( " \n " ) ;
if ( choix = = ' O ' )
{
l - > d . nbP = places ;
printf ( " La mise à jour a bien été effectuée. \n " ) ;
}
return ;
}
void afficherPlace ( Departement d )
{
printf ( " \n Pour ce département il y a %d places en 1ère année \n \n " , d . nbP ) ;
}
void creerDept ( VilleIUT * tiut [ ] , int tLog )
{
Departement d ;
int pos , trouve ;
char ville [ 31 ] ;
printf ( " Dans quelle ville souhaitez-vous créer un nouveau département ? \n Saisie : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Cette ville n'existe pas, veuillez re-saisir : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
}
printf ( " Quel est le nom du département à insérer ? \n Saisie : " ) ;
scanf ( " %s%*c " , d . dept ) ;
rechercherDept ( tiut [ pos ] - > lDept , d . dept , & trouve ) ;
if ( trouve = = 1 )
{
printf ( " Erreur, le département %s existe déjà dans cet IUT \n " , d . dept ) ;
return ;
}
printf ( " Combien de place y a-t-il pour dans ce département ? \n Saisie : " ) ;
scanf ( " %d%*c " , & d . nbP ) ;
printf ( " \n " ) ;
printf ( " Quel est le nom du responsable du département ? \n Saisie : " ) ;
fgets ( d . respAd , 31 , stdin ) ;
d . respAd [ strlen ( d . respAd ) - 1 ] = ' \0 ' ;
afficherDep ( d ) ;
printf ( " pos : %d \n " , pos ) ;
tiut [ pos ] - > lDept = insererDept ( tiut [ pos ] - > lDept , d ) ;
afficherVilleDep ( * tiut [ pos ] ) ;
return ;
}
void retirerDept ( VilleIUT * tiut [ ] , int tLog )
{
int trouve , pos ;
char ville [ 31 ] , dep [ 31 ] ;
printf ( " Dans quelle ville souhaitez-vous supprimer un département ? \n Saisie : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Cette ville n'existe pas, veuillez re-saisir : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
}
printf ( " Quel est le nom du département à supprimer ? \n Saisie : " ) ;
scanf ( " %s%*c " , dep ) ;
rechercherDept ( tiut [ pos ] - > lDept , dep , & trouve ) ;
if ( trouve = = 0 )
{
printf ( " Erreur, le département %s n'existe pas dans cet IUT \n " , dep ) ;
return ;
}
tiut [ pos ] - > lDept = supprimerDept ( tiut [ pos ] - > lDept , dep ) ;
return ;
}
int login ( void )
{
int i = 3 ;
char id , mdp [ 31 ] = " mettez20svp " , mdpatrouve [ 31 ] ;
system ( " clear " ) ;
printf ( " \t ################################ Bienvenue! ################################ \n Souhaitez-vous vous connecter en tant qu'utilisateur ou administeur ? (U/A) \n Saisie : " ) ;
scanf ( " %c%*c " , & id ) ;
if ( id = = ' q ' )
{
return - 1 ;
}
while ( id ! = ' A ' & & id ! = ' a ' & & id ! = ' U ' & & id ! = ' u ' )
{
system ( " clear " ) ;
printf ( " \t #################### Mauvaise saisie ('q' pour quitter) #################### \n Souhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A) \n Saisie : " ) ;
scanf ( " %c%*c " , & id ) ;
if ( id = = ' q ' )
{
return - 1 ;
}
}
if ( id = = ' A ' | | id = = ' a ' )
{
while ( i ! = 0 )
{
printf ( " \n \n Mot de passe : " ) ;
system ( " stty -echo " ) ;
fgets ( mdpatrouve , 31 , stdin ) ;
mdpatrouve [ strlen ( mdpatrouve ) - 1 ] = ' \0 ' ;
printf ( " \n " ) ;
if ( strcmp ( mdpatrouve , mdp ) = = 0 )
{
system ( " stty echo " ) ;
system ( " clear " ) ;
return 1 ;
}
else
{
i - - ;
printf ( " Mot de passe incorrect, il vous reste %d chances \n " , i ) ;
}
system ( " stty echo " ) ;
}
return - 1 ;
}
else
{
system ( " clear " ) ;
return 0 ;
}
}
void menuAdmin ( VilleIUT * tiut [ ] , int * tLog , int tMax )
{
int select = 0 , pos ;
int trouve ;
char ville [ 31 ] ;
ListeDept l ;
printf ( " _______________________________________________________ \n " ) ;
printf ( " | MENU ADMIN | \n " ) ;
printf ( " |-----------------------------------------------------| \n " ) ;
printf ( " | 1 Afficher les villes possédant un IUT | \n " ) ;
printf ( " | 2 Afficher les départements d'un IUT | \n " ) ;
printf ( " | 3 Créer un nouveau département | \n " ) ;
printf ( " | 4 Supprimer un département | \n " ) ;
printf ( " | 5 Modifier le nombre de places dans un département | \n " ) ;
printf ( " | 6 Modifier l'intitulé d'un département | \n " ) ;
printf ( " | 7 Modifer le nom du responsable d'un département | \n " ) ;
printf ( " | 8 Lancer/Arrêter la phase de candidature | \n " ) ;
printf ( " | 9 Quitter | \n " ) ;
printf ( " |-----------------------------------------------------| \n \n " ) ;
printf ( " Saisie : " ) ;
scanf ( " %d%*c " , & select ) ;
while ( select ! = 9 )
{
system ( " clear " ) ;
if ( select = = 1 )
{
afficherTIUT ( tiut , * tLog ) ;
}
if ( select = = 2 )
{
printf ( " Pour quelle ville souhaitez-vous afficher les départements ? \n Saisie : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , * tLog , ville , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Cette ville n'existe pas, veuillez re-sasisir : " ) ;
scanf ( " %s%*c " , ville ) ;
pos = rechercheIUT ( tiut , * tLog , ville , & trouve ) ;
printf ( " \n " ) ;
}
afficherVilleDep ( * tiut [ pos ] ) ;
}
if ( select = = 3 )
{
creerDept ( tiut , * tLog ) ;
}
if ( select = = 4 )
{
retirerDept ( tiut , * tLog ) ;
}
if ( select = = 5 )
{
miseAJourPlaces ( tiut , * tLog ) ;
}
/*if(select == 6)
{
miseAJourNomDept ( tiut , * tLog ) ;
}
if ( select = = 7 )
{
miseAJourResp ( tiut , * tLog ) ;
} */
printf ( " _______________________________________________________ \n " ) ;
printf ( " | MENU ADMIN | \n " ) ;
printf ( " |-----------------------------------------------------| \n " ) ;
printf ( " | 1 Afficher les villes possédant un IUT | \n " ) ;
printf ( " | 2 Afficher les départements d'un IUT | \n " ) ;
printf ( " | 3 Créer un nouveau département | \n " ) ;
printf ( " | 4 Supprimer un département | \n " ) ;
printf ( " | 5 Modifier le nombre de places dans un département | \n " ) ;
printf ( " | 6 Modifier l'intitulé d'un département | \n " ) ;
printf ( " | 7 Modifer le nom du responsable d'un département | \n " ) ;
printf ( " | 8 Lancer/Arrêter la phase de candidature | \n " ) ;
printf ( " | 9 Quitter | \n " ) ;
printf ( " |-----------------------------------------------------| \n \n " ) ;
printf ( " Saisie : " ) ;
scanf ( " %d%*c " , & select ) ;
}
}
void menuCandidat ( VilleIUT * tiut [ ] , int * tLog , int tMax )
{
int select = 0 ;
while ( select ! = 9 )
{
system ( " clear " ) ;
printf ( " _____________________________________________________ \n " ) ;
printf ( " | AFFICHAGE CANDIDAT | \n \n " ) ;
printf ( " |---------------------------------------------------| \n " ) ;
printf ( " | 1 Afficher les villes où il y a un IUT | \n " ) ;
printf ( " | 2 Afficher tous les départements dans chaque IUT | \n " ) ;
printf ( " | 3 Nombres de places en première année | \n " ) ;
printf ( " | 4 Rechercher un département dans les IUT | \n " ) ;
printf ( " | 9 Quitter | \n " ) ;
printf ( " |---------------------------------------------------| " ) ;
scanf ( " %d%*c " , & select ) ;
}
}
void clearpage ( void )
{
char entre ;
printf ( " \n appuyé sur la touche [ENTREE] pour continuer " ) ;
scanf ( " %*c%c " , & entre ) ;
system ( " clear " ) ;
}
int chargement ( VilleIUT * tiut [ ] , int tMax )
int chargement ( VilleIUT * tiut [ ] , int tMax )
{
{
FILE * flot ;
FILE * flot ;
@ -118,7 +506,6 @@ int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
int inf , sup , t ;
int inf , sup , t ;
inf = 0 ;
inf = 0 ;
sup = tLog - 1 ;
sup = tLog - 1 ;
printf ( " Ville recherchée : %s \n " , ville ) ;
while ( inf < = sup )
while ( inf < = sup )
{
{
t = ( inf + sup ) / 2 ;
t = ( inf + sup ) / 2 ;
@ -170,51 +557,3 @@ void globale(void)
retour = login ( ) ;
retour = login ( ) ;
}
}
}
}
void miseAJourPlaces ( VilleIUT * tiut [ ] , int tLog )
{
int trouve , pos , places ;
char ville [ 31 ] , dept [ 31 ] , choix ;
ListeDept l ;
printf ( " Dans quelle ville se situe le département concerné ? \n Saisie : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Cette ville n'existe pas, veuillez re-saisir : " ) ;
scanf ( " %s%*c " , ville ) ;
printf ( " \n " ) ;
pos = rechercheIUT ( tiut , tLog , ville , & trouve ) ;
}
l = tiut [ pos ] - > lDept ;
printf ( " Quel département souhaitez-vous mettre à jour ? \n Saisie : " ) ;
scanf ( " %s%*c " , dept ) ;
printf ( " \n " ) ;
l = rechercherDept ( l , dept , & trouve ) ;
while ( trouve = = 0 )
{
printf ( " Ce département n'existe pas, veuillez-resaisir : " ) ;
scanf ( " %s%*c " , dept ) ;
printf ( " \n " ) ;
l = rechercherDept ( l , dept , & trouve ) ;
}
printf ( " Vous avez sélectionné le département %s dans la ville de %s. \n Souhaitez-vous continuez ? (O/N) \n Saisie : " , dept , ville ) ;
scanf ( " %c%*c " , & choix ) ;
printf ( " \n " ) ;
if ( choix = = ' N ' )
{
return ;
}
printf ( " Il y a actuellement %d places. \n Quel est le nouveau nombre de places ? \n Saisie : " , l - > d . nbP ) ;
scanf ( " %d%*c " , & places ) ;
printf ( " \n Vous avez saisie %d places, veuillez confirmez (O/N) \n Saisie : " , places ) ;
scanf ( " %c%*c " , & choix ) ;
printf ( " \n " ) ;
if ( choix = = ' O ' )
{
l - > d . nbP = places ;
printf ( " La mise à jour a bien été effectuée. \n " ) ;
}
return ;
}