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.
533 lines
13 KiB
533 lines
13 KiB
#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, 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;
|
|
}
|
|
|
|
|
|
/*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é ?\nSaisie : ");
|
|
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 ?\nSaisie : ");
|
|
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.\nSouhaitez-vous continuez ? (O/N)\nSaisie : ", dept, ville);
|
|
scanf("%c%*c", &choix);
|
|
printf("\n");
|
|
if(choix == 'N')
|
|
{
|
|
return;
|
|
}
|
|
printf("Il y a actuellement %d places.\nQuel est le nouveau nombre de places ?\nSaisie : ", l->d.nbP);
|
|
scanf("%d%*c", &places);
|
|
printf("\nVous avez saisie %d places, veuillez confirmez (O/N)\nSaisie : ", 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("\nPour 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 ?\nSaisie : ");
|
|
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 ?\nSaisie : ");
|
|
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 ?\nSaisie : ");
|
|
scanf("%d%*c", &d.nbP);
|
|
printf("\n");
|
|
printf("Quel est le nom du responsable du département ?\nSaisie : ");
|
|
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;
|
|
}
|
|
|
|
|
|
int login(void)
|
|
{
|
|
int i = 3;
|
|
char id, mdp[31] = "mettez20svp", mdpatrouve[31];
|
|
system("clear");
|
|
printf("\t################################ Bienvenue! ################################\nSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur ? (U/A)\nSaisie : ");
|
|
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) ####################\nSouhaitez-vous vous connecter en tant qu'utilisateur ou administeur? (U/A)\nSaisie : ");
|
|
scanf("%c%*c",&id);
|
|
if(id == 'q')
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
if(id == 'A' || id == 'a')
|
|
{
|
|
while(i != 0)
|
|
{
|
|
printf("\n\nMot 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 ?\nSaisie : ");
|
|
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("\nappuyé sur la touche [ENTREE] pour continuer");
|
|
scanf("%*c%c", &entre);
|
|
system("clear");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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 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;
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
void afficherVille(VilleIUT v)
|
|
{
|
|
printf("|----------------------------------|\n");
|
|
printf("| %-32s |\n", v.nom);
|
|
printf("|----------------------------------|\n");
|
|
}
|
|
|
|
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");
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
int rechercheIUT(VilleIUT *tiut[], int tLog, char ville[], int *trouve)
|
|
{
|
|
int inf,sup,t;
|
|
inf = 0;
|
|
sup = tLog - 1;
|
|
printf("Ville recherchée : %s\n", ville);
|
|
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;
|
|
}
|
|
|
|
|
|
void globale(void)
|
|
{
|
|
int tLog, retour;
|
|
VilleIUT *tiut[100];
|
|
if(tiut == NULL)
|
|
{
|
|
printf("Problème d'allocation mémoire du tableau tiut\n");
|
|
exit(1);
|
|
}
|
|
tLog = chargement(tiut,100);
|
|
if(tLog < 0)
|
|
{
|
|
printf("Le programme ne peut pas fonctionner\n");
|
|
exit(1);
|
|
}
|
|
retour = login();
|
|
while(retour != -1)
|
|
{
|
|
if(retour == 1)
|
|
{
|
|
menuAdmin(tiut, &tLog, 100);
|
|
}
|
|
if(retour == 0)
|
|
{
|
|
menuCandidat(tiut, &tLog, 100);
|
|
}
|
|
retour = login();
|
|
}
|
|
} |