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.
418 lines
9.3 KiB
418 lines
9.3 KiB
#include "Msae.h"
|
|
|
|
//################ fonctions listes ###################################
|
|
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 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, Departement d)
|
|
{
|
|
if(lDept == NULL)
|
|
return lDept;
|
|
if(strcmp(d.dept, lDept->d.dept) < 0)
|
|
return lDept;
|
|
if(strcmp(d.dept,lDept->d.dept) == 0)
|
|
return supprimerEntete(lDept);
|
|
lDept->suiv = supprimerDept(lDept->suiv,d);
|
|
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;
|
|
}
|
|
|
|
//################ fonction commune ###################################
|
|
|
|
Departement lireDep(FILE *flot)
|
|
{
|
|
Departement d;
|
|
fscanf(flot,"%s%d", d.dept, &d.nbP);
|
|
fgets(d.respAd,31,flot);
|
|
d.respAd[strlen(d.respAd) - 1] = '\0';
|
|
return d;
|
|
}
|
|
|
|
int chargement(VilleIUT *tiut[],int tMax)
|
|
{
|
|
FILE *flot;
|
|
int tLog = 0, pos, trouve;
|
|
char nomV[31];
|
|
Departement d;
|
|
flot = fopen("IUT.don","r");
|
|
if(flot == NULL)
|
|
{
|
|
printf("Erreur lors de l'ouverture du fichier\n");
|
|
fclose(flot);
|
|
return -1;
|
|
}
|
|
fscanf(flot, "%s", nomV);
|
|
while(!feof(flot))
|
|
{
|
|
if(tLog == tMax)
|
|
{
|
|
printf("Tableau tiut plein\n");
|
|
fclose(flot);
|
|
return -3;
|
|
}
|
|
d = lireDep(flot);
|
|
pos = rechercheIUT(tiut,tLog,nomV,&trouve);
|
|
if(trouve == 1)
|
|
{
|
|
tiut[pos]->lDept = insererDept(tiut[pos]->lDept, d);
|
|
}
|
|
else
|
|
{
|
|
insererVille(tiut, nomV, d, &tLog, tMax, pos);
|
|
}
|
|
fscanf(flot, "%s", nomV);
|
|
}
|
|
fclose(flot);
|
|
return tLog;
|
|
}
|
|
|
|
void clearpage(void)
|
|
{
|
|
char entre;
|
|
printf("\nappuyé sur la touche [ENTREE] pour continuer");
|
|
scanf("%c", &entre);
|
|
system("clear");
|
|
}
|
|
|
|
|
|
int login(void)
|
|
{
|
|
int i=3;
|
|
char id,mdp[31]="mettez20svp",mdpatrouve[31];
|
|
system("clear");
|
|
printf("################################################################\n\tBienvenue!\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t");
|
|
scanf("%c%*c",&id);
|
|
if(id=='q')
|
|
return -1;
|
|
while(id!='A' && id!='a' && id!='U' && id!='u')
|
|
{
|
|
system("clear");
|
|
printf("################################################################\n\tMauvaise saisie (q pour quitter)\n\n\n\tSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\t");
|
|
scanf("%c%*c",&id);
|
|
if(id=='q')
|
|
return -1;
|
|
}
|
|
if(id=='A' || id=='a')
|
|
{
|
|
while(i!=0)
|
|
{
|
|
printf("\n\n\n\tMot de passe :\t");
|
|
system("stty -echo");
|
|
fgets(mdpatrouve,31,stdin);
|
|
mdpatrouve[strlen(mdpatrouve)-1] = '\0';
|
|
if( strcmp(mdpatrouve,mdp) == 0 )
|
|
{
|
|
system("stty echo");
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
i--;
|
|
printf("Mot de passe incorrect, il vous reste %d chances\n",i);
|
|
}
|
|
system("stty echo");
|
|
}
|
|
return -1;
|
|
}
|
|
else return 0;
|
|
system("clear");
|
|
}
|
|
|
|
//################# fonctions affichage ###########################
|
|
|
|
void afficherTIUT(VilleIUT *tiut[], int tLog)
|
|
{
|
|
int i = 0;
|
|
printf("____________________________________\n");
|
|
printf("| Ville |\n");
|
|
for(i = 0; i < tLog; i++)
|
|
{
|
|
afficherVille(*tiut[i]);
|
|
}
|
|
printf("\n");
|
|
clearpage();
|
|
}
|
|
|
|
void afficherVille(VilleIUT v)
|
|
{
|
|
printf("|----------------------------------|\n");
|
|
printf("| %-32s |\n", v.nom);
|
|
printf("|----------------------------------|\n");
|
|
}
|
|
|
|
void afficherPlace(Departement d)
|
|
{
|
|
printf("\nPour ce département il y a %d places en 1ère année \n\n",d.nbP);
|
|
}
|
|
|
|
void afficherVilleDep(VilleIUT v)
|
|
{
|
|
ListeDept l;
|
|
printf("_________________________________________________________________________________________________________________\n");
|
|
printf("| Ville | Département |\n");
|
|
printf("|----------------------------------|----------------------------------------------------------------------------|\n");
|
|
l = v.lDept;
|
|
while(l != NULL)
|
|
{
|
|
printf("| %-32s | %-32s | %3d | %-32s |\n", v.nom, l->d.dept, l->d.nbP, l->d.respAd);
|
|
printf("|----------------------------------|----------------------------------------------------------------------------|\n");
|
|
l = l->suiv;
|
|
}
|
|
}
|
|
|
|
void afficherDep(Departement d)
|
|
{
|
|
printf("_____________________________________________________________________________\n");
|
|
printf("| Département |\n");
|
|
printf("|----------------------------------------------------------------------------|\n");
|
|
printf("| %-32s | %3d | %-32s |\n", d.dept, d.nbP, d.respAd);
|
|
printf("|----------------------------------------------------------------------------|\n");
|
|
}
|
|
|
|
//################# fonctions recherche #########################
|
|
|
|
|
|
|
|
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
|
|
{
|
|
int inf,sup,t;
|
|
inf=0;
|
|
sup=tLog-1;
|
|
while(inf<=sup)
|
|
{
|
|
t=(inf+sup)/2;
|
|
if(strcmp(ville,tiut[t]->nom)==0)
|
|
{
|
|
*trouve=1;
|
|
return t;
|
|
}
|
|
if(strcmp(ville,tiut[t]->nom)<0)
|
|
sup=t-1;
|
|
else inf=t+1;
|
|
}
|
|
*trouve=0;
|
|
return inf;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
//#################### fonctions d'insertion ###########################
|
|
|
|
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;
|
|
}
|
|
|
|
int insererVille(VilleIUT *tiut[], char nomV[], Departement d, int *tLog, int tMax, int pos)
|
|
{
|
|
int i;
|
|
if(*tLog == tMax)
|
|
{
|
|
printf("Tableau plein, insertion impossible\n");
|
|
return -1;
|
|
}
|
|
for(i = *tLog - 1; i >= pos; i--)
|
|
tiut[i + 1] = tiut[i];
|
|
tiut[pos] = (VilleIUT *)malloc(sizeof(VilleIUT));
|
|
if(tiut[pos] == NULL)
|
|
{
|
|
printf("problème d'allocation mémoire lors de l'insertion de la ville\n");
|
|
return -1;
|
|
}
|
|
strcpy(tiut[pos]->nom, nomV);
|
|
tiut[pos]->lDept = listeDeptNouv();
|
|
tiut[pos]->lDept = insererDept(tiut[pos]->lDept,d);
|
|
*tLog = *tLog + 1;
|
|
return 0;
|
|
}
|
|
|
|
//#################### fonction mise à jour ############################
|
|
|
|
void miseAJourNomDept(Departement d,ListeDept l)
|
|
{
|
|
int trouve;
|
|
char nomDept[31],choix='n';
|
|
system("clear");
|
|
afficherDep(d);
|
|
while(choix!='o' || choix!='O')
|
|
{
|
|
printf("\nQuel est le nouveau nom du département?\n");
|
|
fgets(nomDept,31,stdin);
|
|
nomDept[strlen(nomDept)-1]='\0';
|
|
rechercherDept(l,nomDept,&trouve);
|
|
if(trouve==1)
|
|
{
|
|
printf("Nom de département déjà.\n");
|
|
return;
|
|
}
|
|
printf("Êtes-vous sûr de remplacer le nom du département par %s?(o/n)\t",nomDept);
|
|
scanf("%c%*c",&choix);
|
|
}
|
|
strcpy(d.dept,nomDept);
|
|
afficherDep(d);
|
|
clearpage();
|
|
}
|
|
|
|
void miseAJourResp(Departement d)
|
|
{
|
|
char resp[31],choix='n';
|
|
system("clear");
|
|
afficherDep(d);
|
|
while(choix!='o' || choix!='O')
|
|
{
|
|
printf("\nQuel est le nouveau nom du responsable ?\t");
|
|
fgets(resp,31,stdin);
|
|
resp[strlen(resp)-1]='\0';
|
|
printf("Êtes-vous sûr de remplacer le nom du responsable par %s?(o/n)\t",resp);
|
|
scanf("%c%*c",&choix);
|
|
}
|
|
strcpy(d.respAd,resp);
|
|
afficherDep(d);
|
|
clearpage();
|
|
}
|
|
|
|
void miseAJourPlaces(Departement d)
|
|
{
|
|
int places;
|
|
char choix='n';
|
|
system("clear");
|
|
afficherDep(d);
|
|
while(choix!='o' || choix!='O')
|
|
{
|
|
printf("Quel est le nouveau nombre de place ?\t");
|
|
scanf("%d%*c",&places);
|
|
printf("Êtes-vous sûr de passer les places en première année de %d à %d ?(o/n)\t",d.nbP,places);
|
|
scanf("%c",&choix);
|
|
}
|
|
d.nbP=places;
|
|
afficherDep(d);
|
|
clearpage();
|
|
}
|
|
|
|
void miseAJourGlobale(VilleIUT *tiut[], int tLog)
|
|
{
|
|
int trouve,pos,choix=0;
|
|
char ville[31],dept[31];
|
|
MaillonDept *m;
|
|
Departement d;
|
|
system("clear");
|
|
printf("Dans quelle ville voulez-vous faire des mises à jour?\t");
|
|
scanf("%s",ville);
|
|
pos=rechercheIUT(tiut,tLog,ville,&trouve);
|
|
if(trouve!=1)
|
|
{
|
|
printf("\n\nCette ville n'existe pas\n");
|
|
clearpage();
|
|
return;
|
|
}
|
|
afficherVilleDep(*tiut[pos]);
|
|
printf("Quel département de %s voulez-vous modifier?\t",ville);
|
|
scanf("%s%*c",dept);
|
|
m=rechercherDept(tiut[pos]->lDept,dept,&trouve);
|
|
d=m->d;
|
|
if(trouve!=1)
|
|
{
|
|
printf("\n\nCe département n'existe pas dans cette ville\n");
|
|
clearpage();
|
|
return;
|
|
}
|
|
afficherDep(d);
|
|
printf("\n\n");
|
|
while(choix!=9)
|
|
{
|
|
printf("################### Menu des mises à jour ###################\n");
|
|
printf("\n\t1.Mise à jour du nom du département\n\t2.Mise à jour des places du département\n\t3.Mise à jour du responsable du département\n\t9.Quitter\n\n");
|
|
printf("\tSaisie:\t");
|
|
scanf("%d%*c",&choix);
|
|
if(choix==1)
|
|
{
|
|
miseAJourNomDept(d,tiut[pos]->lDept);
|
|
}
|
|
if(choix==2)
|
|
{
|
|
miseAJourPlaces(d);
|
|
}
|
|
if(choix==3)
|
|
{
|
|
miseAJourResp(d);
|
|
}
|
|
}
|
|
clearpage();
|
|
afficherDep(d);
|
|
}
|