You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

819 lines
21 KiB

#include "SAE.h"
bool motdepasseVerif(void)
{
char mdp[10];
int i=4;
while(i > 0)
{
printf("entrer le mot de passe administrateur : ");
system("stty -echo");
scanf("%s",mdp);
system("stty echo");
if (strcmp(mdp,"123456") == 0)
{
system("clear");
return true;
}
system("clear");
printf("\n! mots de passe faux !\n");
i = i - 1;
printf("\n! il vous reste %d tentative/s !\n",i);
}
printf("Vous avez effectuer trop de tentative retour au menu Utilisateur !\n");
return false;
}
bool verifQuit(void)
{
char choix[4];
while(1)
{
system("clear");
printf("Êtes-vous sûr de vouloir quitter ? (oui|non) : ");
scanf("%s",choix);
if (strcmp(choix,"oui")==0)
return true;
if (strcmp(choix,"non")==0)
return false;
printf("Erreur de sélection ! Veuillez réessayer \n");
}
}
bool verifSelection(void)
{
char choix[4];
while(1)
{
printf("Voulez-vous continué la sélection (oui|non) : ");
scanf("%s",choix);
if (strcmp(choix,"oui")==0)
return true;
if (strcmp(choix,"non")==0)
return false;
printf("Erreur de sélection ! Veuillez réessayer \n");
}
}
bool confirmationSup(void)
{
char choix[4];
while(1)
{
printf("Êtes-vous sûr de vouloir supprimer/moddifié : ");
scanf("%s", choix);
if (strcmp(choix,"oui")==0)
return true;
if (strcmp(choix,"non")==0)
return false;
printf("Erreur de sélection ! Veuillez réessayer \n");
}
}
int menuUtilisateurAffiche(void)
{
int choix;
printf("####################################################\n");
printf("\t\t|Menu Utilisateur|\n");
printf("\t\t------------------\n\n");
printf("1 - Consultation des IUT\n");
printf("2 - Consultation des département global par IUT\n");
printf("3 - Consultation du nombre de places pour un Département par IUT\n");
printf("4 - Consultation du nombre de places pour un Département dans un IUT\n");
printf("5 - Consultation des départements dans un IUT\n");
printf("6 - Consultation de tout les IUT ayant un département choisi\n");
printf("7 - Consultation de toute les informations des Département par IUT");
printf("\n\n9 - Connexion mode Administrateur\n");
printf("\n\n10 - Quitter\n");
printf("####################################################\n");
printf("\nSelection : ");
scanf("%d",&choix);
return choix;
}
int menuAdminAffiche(void)
{
int choix;
printf("####################################################\n");
printf("\t\tMenu Administrateur\n\n");
printf("1 - Mise à jour nombre de Places d'un Département d'un IUT\n");
printf("2 - Création d'un département dans un IUT\n");
printf("3 - Suppression d'un département dans un IUT\n");
printf("4 - Gestion des phases de candidature\n");
printf("5 - Changement d'un responsable de département\n");
printf("\n\n9 - Repasser en mode Utilisateur");
printf("\n\n10 - Quitter\n");
printf("####################################################\n");
printf("\nSelection : ");
scanf("%d",&choix);
return choix;
}
void gestionMenu(VilleIUT **tiut, int nbEle)
{
int choix;
while(1)
{
choix = menuUtilisateurAffiche();
system("clear");
switch(choix) {
case 1:
AffichageVille(tiut,nbEle);
clearpage();
break;
case 2:
AffichageGlobalDepVille(tiut, nbEle);
clearpage();
break;
case 3:
AffichageNbplaceDept(tiut, nbEle);
clearpage();
break;
case 4:
AffichageNbplaceDeptVille(tiut, nbEle);
clearpage();
break;
case 5:
AffichageDepVille(tiut, nbEle);
clearpage();
break;
case 6:
AffichageDeptVille(tiut, nbEle);
clearpage();
break;
case 7:
AffichageGlobalIUT(tiut, nbEle);
clearpage();
break;
case 9:
choix = gestionMenuAdmin(tiut, nbEle);
if (choix == -1)
if (verifQuit()) return;
break;
case 10:
if (verifQuit()) return;
break;
}
}
}
int gestionMenuAdmin(VilleIUT **tiut, int nbEle)
{
int choix;
if (!motdepasseVerif())
return 0;
while(1)
{
choix = menuAdminAffiche();
system("clear");
switch(choix){
case 1:
MiseAJourNbPlace(tiut, nbEle);
system("clear");
break;
case 2:
creationDept(tiut, nbEle);
system("clear");
break;
case 3:
suppressionDept(tiut, nbEle);
system("clear");
break;
case 4:
//affichage du nombres de places par département d'un iut
clearpage();
break;
case 5:
modifChefDept(tiut, nbEle);
system("clear");
break;
case 9:
return 0;
case 10:
return -1;
}
}
}
void global(void)
{
int tailleL, i;
VilleIUT** tab;
char nomFich[20];
strcpy(nomFich,"iut.txt");
printf("charg\n");
tab = chargementVille(nomFich,30,&tailleL);
printf("\n");
gestionMenu(tab, tailleL);
}
void AffichageVille(VilleIUT **tiut, int nbEle)
{
int i;
printf("\tIUT par ville :\n");
for(i=0;i<nbEle;i++)
{
printf("- %s\n\t",tiut[i]->ville);
}
}
void AffichageGlobalDepVille(VilleIUT **tiut, int nbEle)
{
int i;
MaillonDept *aux;
printf("\tDépartement par IUT :\n");
for(i=0;i<nbEle;i++)
{
printf("%s :\n", tiut[i]->ville);
aux = tiut[i]->idDept;
while(aux != NULL)
{
printf("|%s|\n",aux->departement);
aux = aux->suiv;
}
}
}
void AffichageNbplaceDept(VilleIUT **tiut, int nbEle)
{
int pos;
MaillonDept *aux;
for (pos = 0; pos < nbEle; pos++)
{
printf("%s -> \t", tiut[pos]->ville);
aux = tiut[pos]->idDept;
while(aux->suiv != NULL && pos < nbEle)
{
printf("|%s, %d places|\n\t",aux->departement, aux->nbPers);
aux = aux->suiv;
}
printf("\n");
}
}
int rechVille(VilleIUT **tiut, int nbEle, char code[], int *trouve)
{
int inf = 0, sup = nbEle - 1, m;
while(inf <= sup)
{
m = (inf + sup)/2;
if (strcmp(tiut[m]->ville, code)==0)
{
*trouve = 1;
return m;
}
if (strcmp(tiut[m]->ville, code)>0)
sup = m - 1;
else inf = m + 1;
}
*trouve = 0;
return inf;
}
void AffichageNbplaceDeptVille(VilleIUT **tiut, int nbEle)
{
MaillonDept *aux;
char code[30];
int pos,trouve = 0;
while(1)
{
printf("IUT : ");
scanf("%s",code);
pos = rechVille(tiut, nbEle, code,&trouve);
if (trouve == 1)
{
while(1)
{
printf("Département : ");
scanf("%s",code);
trouve = 0;
aux = rechercheDept(tiut[pos]->idDept, code);
if (aux == NULL)
printf("Département non présent à l'iut de %s",tiut[pos]->ville);
if (aux != NULL)
printf("%s -> |%s, %d places|\n",tiut[pos]->ville,aux->departement, aux->nbPers);
printf("Saisi Département :\n");
if(!verifSelection())
break;
}
}
if (trouve == 0) printf("%s n'a pas d'IUT\n",code);
printf("Saisi Département :\n");
if(!verifSelection())
break;
}
}
void AffichageDepVille(VilleIUT **tiut, int nbEle)
{
char code[30];
int pos,trouve = 0;
while(1)
{
printf("IUT : ");
scanf("%s",code);
pos = rechVille(tiut, nbEle, code,&trouve);
if (trouve == 1)
{
printf("%s :\n\t",tiut[pos]->ville);
affichageListeDept(tiut[pos]->idDept);
}
if (trouve == 0)
printf("%s n'a pas d'IUT\n",code);
printf("Saisi Ville :\n");
if(!verifSelection())
break;
}
}
void AffichageDeptVille(VilleIUT **tiut, int nbEle)
{
MaillonDept *aux;
char code[30];
int pos = 0, nbocc = 0;
while(1)
{
printf("département : ");
scanf("%s",code);
printf("\nIUT ayant un département %s : \n",code);
for(pos = 0; pos < nbEle; pos++)
{
aux = rechercheDept(tiut[pos]->idDept, code);
if(aux != NULL)
{
printf("- %s\n", tiut[pos]->ville);
nbocc = nbocc + 1;
}
}
if (nbocc == 0)
printf("aucun département %s est présent en France\n", code);
printf("Saisi Département :\n");
if(!verifSelection())
break;
}
}
void AffichageGlobalIUT(VilleIUT **tiut, int nbEle)
{
int pos = 0;
printf("Ville : \t");
while(pos < nbEle)
{
printf("-%s \n", tiut[pos]->ville);
printf("Département:\tNombre de places:\tNom du Responsable:\n");
affichageListeDept(tiut[pos]->idDept);
pos = pos + 1;
printf("\n");
}
}
void MiseAJourNbPlace(VilleIUT **tiut, int nbEle)
{
MaillonDept *aux;
int nouvNbPlace, pos, trouve;
char code[30];
while(1)
{
printf("IUT : ");
scanf("%s",code);
pos = rechVille(tiut, nbEle, code,&trouve);
if (trouve == 1)
{
while(1)
{
printf("Département : ");
scanf("%s",code);
aux = rechercheDept(tiut[pos]->idDept, code);
if (aux != NULL)
{
printf("Ancien nombre de places : %d\n",aux->nbPers);
printf("Nouveau nombre de places : ", nouvNbPlace);
scanf("%d", &nouvNbPlace);
aux->nbPers = nouvNbPlace;
printf("Mise à jour effectuer avec succès !");
break;
}
if (aux == NULL)
printf("Département non présent à l'iut de %s",tiut[pos]->ville);
printf("Saisi Département :\n");
if(!verifSelection())
break;
}
}
if (trouve == 0)
printf("Cet ville n'a pas d'IUT\n");
printf("Saisi Ville :\n");
if(!verifSelection())
break;
}
}
void creationDept(VilleIUT **tiut, int nbEle)
{
MaillonDept *aux;
char code[30], nom[30];
int trouve, pos, nbP;
while(1)
{
printf("Dans quel IUT voulez-vous créer un département : ");
scanf("%s", code);
pos = rechVille(tiut, nbEle, code, &trouve);
if (trouve == 1)
{
while(1)
{
printf("Nom du Département : ");
scanf("%s", code);
aux = rechercheDept(tiut[pos]->idDept, code);
if (aux != NULL)
printf("Département déjà existant\n");
if (aux == NULL)
{
printf("Nom du Responsable du Département de %s : ",code);
fgets(nom,30,stdin);
nom[strlen(nom)-1] = '\0';
printf("Nombre de place du Département %s : ",code);
scanf("%d", &nbP);
tiut[pos]->idDept = insererDept(tiut[pos]->idDept,code,nom,nbP);
printf("insertion du département %s effectuer \n", code);
}
printf("Saisi Département :\n");
if (!verifSelection())
break;
}
}
if (trouve == 0)
printf("Cet ville n'a pas d'IUT\n");
printf("Saisi Ville :\n");
if(!verifSelection())
break;
}
}
void suppressionDept(VilleIUT **tiut, int nbEle)
{
MaillonDept *aux;
char code[30];
int trouve, pos, nbP;
while(1)
{
printf("Dans quel IUT voulez-vous supprimer un département : ");
scanf("%s", code);
pos = rechVille(tiut, nbEle, code, &trouve);
if (trouve == 1)
{
printf("Nom du Département : ");
scanf("%s", code);
aux = rechercheDept(tiut[pos]->idDept, code);
if (aux != NULL)
if (confirmationSup())
tiut[pos]->idDept = supprimerDept(tiut[pos]->idDept, code);
if (aux == NULL)
printf("Ce Département n'existe pas dans l'IUT de %s \n",tiut[pos]->ville);
printf("Saisi Département :\n");
if (!verifSelection())
break;
}
if (trouve == 0)
printf("Cet ville n'a pas d'IUT\n");
printf("Saisi Ville :\n");
if (!verifSelection())
break;
}
}
void modifChefDept(VilleIUT **tiut, int nbEle)
{
MaillonDept *aux;
char code[30];
int trouve, pos, nbP;
while(1)
{
printf("Dans quel IUT voulez-vous modifier le chef de département : ");
scanf("%s", code);
pos = rechVille(tiut, nbEle, code, &trouve);
if (trouve == 1)
{
printf("Nom du Département : ");
scanf("%s%*c", code);
aux = rechercheDept(tiut[pos]->idDept, code);
if (aux != NULL)
{
printf("Nom de l'ancien chef de département %s de %s : %s\n",aux->departement, tiut[pos]->ville,aux->responsable);
printf("Nom du nouveau chef de département %s de %s :",aux->departement, tiut[pos]->ville);
fgets(code,30,stdin);
code[strlen(code)-1] = '\0';
strcpy(aux->responsable, code);
printf("Chef de département : %s\n",aux->responsable);
}
if (aux == NULL)
printf("Ce Département n'existe pas dans l'IUT de %s \n",tiut[pos]->ville);
printf("Saisi Département :\n");
if (!verifSelection())
break;
}
if (trouve == 0)
printf("Cet ville n'a pas d'IUT\n");
printf("Saisi Ville :\n");
if (!verifSelection())
break;
}
}
void triEchange(VilleIUT **tiut, int nbEle)
{
int pge;
while(nbEle>1)
{
pge = plusGrand(tiut, nbEle);
echanger(tiut,pge,nbEle-1);
nbEle = nbEle - 1;
}
}
int plusGrand(VilleIUT **tiut, int nbEle)
{
int pge = 0, i;
for (i = 1; i < nbEle; i++)
if (strcmp(tiut[i]->ville,tiut[pge]->ville)>0)
pge = 1;
return pge;
}
void echanger(VilleIUT **tiut, int i, int j)
{
VilleIUT *aux;
aux = tiut[i];
tiut[i] = tiut[j];
tiut[j] = aux;
}
int longueurListe(ListeDept l)
{
int cpt = 0;
while (l != NULL)
{
cpt += 1;
l = l->suiv;
}
return cpt;
}
void SauvegarderIUT(VilleIUT** tabV, int tailleL) {
int i;
FILE* flot;
flot = fopen("iut.txt","w");
for (i = 0 ; i < tailleL ; i++) {
fprintf(flot,"%s\n",tabV[i]->ville);
fprintf(flot,"%d\n",longueurListe(tabV[i]->idDept));
SauvegarderListe(tabV[i]->idDept,flot);
free(tabV[i]);
}
}
void SauvegarderListe(ListeDept l, FILE* flot) {
MaillonDept* tmp;
while (l->suiv != NULL) {
tmp = l;
fprintf(flot,"%s %d %s\n",l->departement,l->nbPers,l->responsable);
l = l->suiv;
free(tmp);
}
fprintf(flot,"%s %d %s\n",l->departement,l->nbPers,l->responsable);
free(l);
}
void clearpage(void)
{
char entre;
printf("\nappuyé sur la touche [ENTREE] pour continuer");
scanf("%*c%c", &entre);
system("clear");
}
ListeCandid ListeCandidvide(void)
{
return NULL;
}
ListeCandidDept ListeCandidDeptvide(void)
{
return NULL;
}
ListeCandidDept insererEnTeteCandidDept(ListeCandidDept l, char departement[], char deciDept[], int deciCandid)
{
MaillonCandidDept *m;
m = (MaillonCandidDept *)malloc(sizeof(MaillonCandidDept));
if (m == NULL)
{
printf("Pb maillon");
exit(1);
}
strcpy(m->departement, departement);
m->decisionDept = deciDept;
m->deciCandid = deciCandid;
m->suiv = l;
return m;
}
ListeCandidDept insererCandidDept(ListeCandidDept l, char departement[], int deciDept, int deciCandid)
{
if (l == NULL)
return insererEnTeteCandidDept(l, departement, deciDept, deciCandid);
if (strcmp(departement, l->departement) < 0)
return insererEnTeteCandidDept(l, departement, deciDept, deciCandid);
if (strcmp(departement, l->departement) == 0)
return l;
l->suiv = insererCandidDept(l->suiv, departement, deciDept, deciCandid);
return l;
}
ListeCandid insererEnTeteCandid(ListeCandid l, char *ville)
{
MaillonCandid *m;
m = (MaillonCandid *)malloc(sizeof(MaillonCandid));
if (m == NULL)
{
printf("Pb maillon");
exit(1);
}
strcpy(ville, l->iutcandid);
m->suiv = l;
return m;
}
ListeCandid insererCandid(ListeCandid l, char *ville)
{
if (l == NULL)
return insererEnTeteCandid(l, ville);
if (strcmp(ville, l->iutcandid) < 0)
return insererEnTeteCandid(l, ville);
if (strcmp(ville, l->iutcandid) == 0)
return l;
l->suiv = insererCandid(l->suiv, ville);
return l;
}
ListeCandidDept suppressionEnTeteCandidDept(ListeCandidDept l)
{
MaillonCandidDept *aux;
if(l == NULL)
{
printf("opération interdite !\n");
exit(1);
}
aux = l;
l = l->suiv;
free(aux);
return l;
}
ListeCandidDept suppressionCandidDept(ListeCandidDept l, char *departement)
{
if (l == NULL)
return l;
if (strcmp(departement, l->departement) < 0)
return l;
if (strcmp(departement, l->departement) == 0)
return suppressionEnTeteCandidDept(l);
l->suiv = suppressionCandidDept(l->suiv, departement);
return l;
}
ListeCandid suppressionEnTeteCandid(ListeCandid l)
{
MaillonCandid *aux;
if(l == NULL)
{
printf("opération interdite !\n");
exit(1);
}
aux = l;
l = l->suiv;
free(aux);
return l;
}
ListeCandid suppressionCandid(ListeCandid l, char *ville)
{
if (l == NULL)
return l;
if (strcmp(ville, l->iutcandid) < 0)
return l;
if (strcmp(ville, l->iutcandid) == 0)
while (1)
{
if (l->idCandDept == NULL)
break;
suppressionEnTeteCandidDept(l->idCandDept);
}
return suppressionEnTeteCandid(l);
l->suiv = suppressionCandid(l->suiv);
return l;
}
void afficherCandidDept(ListeCandidDept l)
{
MaillonCandidDept *aux;
aux = l;
while(aux != NULL)
{
printf("%s\t%d\t%d\n",aux->departement, aux->decisionDept, aux->decisionCandid);
aux = aux->suiv;
}
printf("\n");
}
void afficherCandid(ListeCandid l)
{
MaillonCandid *aux;
aux = l;
while(aux != NULL)
{
printf("%s\t",aux->iutcandid);
afficherCandidDept(aux->idCandDept);
aux = aux->suiv;
}
printf("\n");
}
int longueur(ListeCandid l)
{
if(l==NULL)
return 0;
return 1 + longueur(l->suiv);
}
Candidat **chargmentCandid(char *nomFich, int tphys, int *tailleL)
{
int i = 0, nbCandidat, nbCandid;
FILE *flot;
Candidat **tcandid;
tcandid = (Candidat *)malloc(sizeof(Candidat) * tphys);
if (tabV == NULL)
{
printf("Erreur malloc tcandid !\n");
exit(1);
}
flot = fopen(nomFich, "r");
if (flot == NULL)
{
printf("Problèmes d'ouverture de fichier !\n");
exit(1);
}
*tailleL = 0;
tcandid[*tailleL] = (Candidat *)malloc(sizeof(Candidat));
if (tcandid[*tailleL] == NULL)
{
printf("Erreur malloc candidat !\n");
fclose(flot);
exit(1);
}
*(tcandid[*tailleL]) = lireCandidat(flot);
while(!feof(flot))
{
}
}
Candidat lireCandidat(FILE *flot)
{
Candidat c;
fscanf(flot,"%a",&c.id);
fscanf(flot,"%s",c.nom);
fgets(c.prenom,30,flot);
c.prenom[strlen(c.prenom) - 1] = '\0';
fscanf(flot,"%d %d %d %d", c.note[0], c.note[1], c.note[2], c.note[3]);
return c;
}
ListeCandid traiterCandidIUT(ListeCandid l, FILE *flot)
{
char ville[30];
fscanf(flot,"%s",ville);
l = insererCandid(l , ville);
return l;
}
ListeCandidDept traiterCandidDept(ListeCandidDept l, FILE *flot)
{
char departement[30];
int deciDept, deciCandid;
fscanf(flot,"%s",departement);
fscanf(flot,"%d",deciDept);
fscanf(flot,"%d",deciCandid);
l = insererCandidDept(l);
return l;
}