Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct hr
- {
- char emp_ID[20];
- char emp_name[20];
- char password[30];
- };
- struct academicleader
- {
- char emp_ID[20];
- char emp_name[20];
- char password[30];
- };
- struct lecturer
- {
- char emp_ID[20];
- char emp_name[20];
- char password[30];
- };
- struct yearlyleaves
- {
- int days;
- };
- struct holidays
- {
- char description[50];
- int dd, mm, yy;
- };
- struct policies
- {
- char count[5];
- char policies[100];
- };
- struct leaveapplication
- {
- char emp_ID[20];
- char emp_name[20];
- char subject[50];
- char status[50];
- int dd, mm, yy;
- };
- int date();
- int loginHR();
- int loginAL();
- int loginL();
- char registrationHR();
- char registrationAL();
- char registrationL();
- void HRmenu();
- void lecturerview();
- void loginmenu();
- void lecturerdetails();
- int deleterecord();
- int updaterecordL();
- int searchrecordL();
- int yearlyleaves();
- int updateholidays();
- int updatepolicies();
- void policiesmenu();
- void registrationmenu();
- void academicleadermenu();
- int viewholidays();
- void lecturermenu();
- int viewFAQ();
- int leaveapplication();
- int statusview();
- int changestatus();
- /* */
- int main()
- {
- printf("========================================================================================\n");
- printf("\t\tWelcome to ABC Employees Leave Management System\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- printf("\nPlease Login Into the System to Proceed.\n\n");
- int options;
- login:
- while (1)
- {
- printf("1. Login\n");
- printf("2. Exit\n");
- fflush(stdin);
- printf("\nInput an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: loginmenu();
- break;
- case 2: exit(1);
- break;
- default: printf("\nError input. Choose only between 1 and 2.\n");
- goto login;
- }
- break;
- }
- return 0;
- }
- void loginmenu()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO LOGIN!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("\n1. Human Resource\n");
- printf("2. Academic Leader\n");
- printf("3. Lecturer\n");
- printf("4. Exit\n");
- choice:
- while (1)
- {
- fflush(stdin);
- printf("\nEnter a number: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: loginHR();
- break;
- case 2: loginAL();
- break;
- case 3: loginL();
- break;
- case 4: exit(1);
- break;
- default: printf("\nError input!! Choose only from 1 to 4.\n");
- goto choice;
- }
- break;
- }
- return;
- }
- void HRmenu()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO HR MENU!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("\n1. Register New User\n");
- printf("2. Lecturer Details\n");
- printf("3. Lecturer Leave Status\n");
- printf("4. Upload Leaves\n");
- printf("5. Upload Public and University Holidays\n");
- printf("6. Update University Leaves Policies\n");
- printf("7. Exit\n");
- choice:
- while (1)
- {
- fflush(stdin);
- printf("\nChoose an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: registrationmenu();
- break;
- case 2: lecturerdetails();
- break;
- case 3: statusview();
- break;
- case 4: yearlyleaves();
- break;
- case 5: updateholidays();
- break;
- case 6: policiesmenu();
- break;
- case 7: exit(1);
- break;
- default: printf("Error input!! Choose only from 1 to 7\n");
- goto choice;
- }
- break;
- }
- return;
- }
- void registrationmenu()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO REGISTRATION MENU!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("\n1. Register Academic Leader\n");
- printf("2. Register Lecturer\n");
- printf("3. Exit\n");
- choice:
- while (1)
- {
- fflush(stdin);
- printf("\nEnter an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: registrationAL();
- break;
- case 2: registrationL();
- break;
- case 3: exit(1);
- break;
- default: printf("Error input. Choose only from 1 to 3.\n");
- goto choice;
- }
- break;
- }
- return;
- }
- void lecturerdetails()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO LECTURER PROFILE EDITS!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("1. Search Lecturer Details\n");
- printf("2. View Lecturer Details\n");
- printf("3. Modify Lecturer Details\n");
- printf("4. Delete Lecturer Details\n");
- printf("5. Exit\n");
- choice:
- while (1) {
- fflush(stdin);
- printf("\nChoose an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: searchrecordL();
- break;
- case 2: lecturerview();
- break;
- case 3: updaterecordL();
- break;
- case 4: deleterecord();
- break;
- case 5: exit(1);
- break;
- default: printf("Error input. Choose only from 1 to 5.\n");
- goto choice;
- }
- break;
- }
- return;
- }
- void policiesmenu()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO POLICIES MENU\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("\n1. Add New Policy\n");
- printf("2. Update Policy\n");
- printf("3. Exit\n");
- choice:
- while (1) {
- fflush(stdin);
- printf("\nChoose an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: universitypolicies();
- break;
- case 2: updatepolicies();
- break;
- case 3: exit(1);
- break;
- default: printf("Error input. Choose from 1 to 3.\n");
- goto choice;
- }
- break;
- }
- return;
- }
- void academicleadermenu()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO ACADEMIC LEADER MENU!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("1. View Lecturer's Leave Application\n");
- printf("2. Approve/Reject Lecturer's Application\n");
- printf("3. Delete Leave Application\n");
- printf("4. View Public and University Holidays\n");
- printf("5. View FAQ about Lecturer Leaves\n");
- printf("6. Exit\n");
- choice:
- while (1)
- {
- fflush(stdin);
- printf("\nChoose an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: statusview();
- break;
- case 2: changestatus();
- break;
- case 3: deleterecord();
- break;
- case 4: viewholidays();
- break;
- case 5: viewFAQ();
- break;
- case 6: exit(1);
- break;
- default: printf("Error input. Choose from 1 to 6. \n");
- goto choice;
- }
- break;
- }
- return;
- }
- void lecturermenu()
- {
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO LECTURER MENU!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- int options;
- printf("\n1. Apply for Leave\n");
- printf("2. Check Status of Leave Application\n");
- printf("3. View Public and University Holidays\n");
- printf("4. View FAQ about Lecturer Leaves\n");
- printf("5. Exit\n");
- choice:
- while (1)
- {
- fflush(stdin);
- printf("\nChoose an option: ");
- scanf("%d", &options);
- switch (options)
- {
- case 1: leaveapplication();
- break;
- case 2: statusview();
- break;
- case 3: viewholidays();
- break;
- case 4: viewFAQ();
- break;
- case 5: exit(1);
- break;
- default: printf("\Error input. Choose from 1 to 5\n");
- goto choice;
- }
- break;
- }
- return;
- }
- int date()
- {
- time_t currentTime;
- time(¤tTime);
- printf("\t\t\t\t\t\t\t%s\n", ctime(¤tTime));
- return 0;
- }
- char registrationHR()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO HR REGISTRATION!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct hr record;
- printf("Enter the UserID: ");
- scanf(" %s", record.emp_ID);
- printf("\nEnter the username: ");
- scanf(" %s", record.emp_name);
- printf("\nEnter the password: ");
- scanf(" %s", record.password);
- FILE *qa;
- // open file for writing
- qa = fopen("HR.txt", "a");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // write struct to file
- fwrite(&record, sizeof(struct hr), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Successfully!!\n");
- else
- printf("ERROR!!\n");
- return 0;
- }
- int loginHR()
- {
- //system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO HR LOGIN!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- char emp_name[50];
- char password[50];
- int flag = 0;
- FILE *qb;
- struct hr record;
- printf("\nPlease Enter your Username, Password to Proceed\n\n");
- printf("\n\nUsername: ");
- scanf(" %s", emp_name);
- printf("\nPassword: ");
- scanf(" %s", password);
- qb = fopen("HR.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // read file contents till end of file
- while (fread(&record, sizeof(struct hr), 1, qb)) {
- if (strcmp(emp_name, record.emp_name) == 0 && strcmp(password, record.password) == 0)
- {
- HRmenu();
- flag = 1;
- break;
- }
- }
- fclose(qb);
- if (!flag)
- {
- printf("Incorrect data entered. Please try again!\n");
- loginHR();
- }
- return 0;
- }
- char registrationAL()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELOME TO ACADEMIC LEADER REGISTRATION!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct academicleader record;
- printf("Enter the UserID: ");
- scanf(" %s", record.emp_ID);
- printf("\nEnter the username: ");
- scanf(" %s", record.emp_name);
- printf("\nEnter the password: ");
- scanf(" %s", record.password);
- FILE *qa;
- // open file for writing
- qa = fopen("AL.txt", "a");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // write struct to file
- fwrite(&record, sizeof(struct academicleader), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Success!! !\n");
- else
- printf("ERROR!! !\n");
- return 0;
- }
- int loginAL()
- {
- //system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO ACADEMIC LEADER LOGIN!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- char emp_name[50];
- char password[50];
- int flag = 0;
- FILE *qb;
- struct academicleader record;
- printf("\nPlease Enter your Username, Password and Position to Proceed\n\n");
- printf("\n\nUsername: ");
- scanf(" %s", emp_name);
- printf("\nPassword: ");
- scanf(" %s", password);
- qb = fopen("academic.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // read file contents till end of file
- while (fread(&record, sizeof(struct academicleader), 1, qb)) {
- if (strcmp(emp_name, record.emp_name) == 0 && \
- strcmp(password, record.password) == 0)
- {
- academicleadermenu();
- flag = 1;
- break;
- }
- }
- fclose(qb);
- if (!flag)
- {
- printf("Invalid Information. Please try again!\n");
- loginAL();
- }
- return 0;
- }
- char registrationL()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO LECTURER REGISTRATION!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct lecturer record;
- printf("Enter the UserID: ");
- scanf(" %s", record.emp_ID);
- printf("\nEnter the username: ");
- scanf(" %s", record.emp_name);
- printf("\nEnter the password: ");
- scanf(" %s", record.password);
- FILE *qa;
- // open file for writing
- qa = fopen("L.txt", "a");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // write struct to file
- fwrite(&record, sizeof(struct lecturer), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Success!!\n");
- else
- printf("ERROR!!\n");
- return 0;
- }
- int loginL()
- {
- //system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO LECTURER LOGIN!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- char emp_name[50];
- char password[50];
- int flag = 0;
- FILE *qb;
- struct lecturer record;
- printf("\nPlease Enter your Username, Password to Proceed\n\n");
- printf("\n\nemp_name: ");
- scanf(" %s", emp_name);
- printf("\nPassword: ");
- scanf(" %s", password);
- qb = fopen("L.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // read file contents till end of file
- while (fread(&record, sizeof(struct lecturer), 1, qb)) {
- if (strcmp(emp_name, record.emp_name) == 0 && strcmp(password, record.password) == 0)
- {
- lecturermenu();
- flag = 1;
- break;
- }
- }
- fclose(qb);
- if (!flag)
- {
- printf("Invalid Information. Please try again!!\n");
- loginL();
- }
- return 0;
- }
- void lecturerview()
- {
- FILE *qb;
- struct lecturer record;
- // Open user.txt for reading
- qb = fopen("L.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // read file contents till end of file
- while (fread(&record, sizeof(struct lecturer), 1, qb))
- {
- //if(strcmp(positionL, person.position) == 0)
- //{
- printf("\nUserID = %s \tUsername = %s \tPassword = %s", record.emp_ID,
- record.emp_name, record.password);
- //}
- }
- return;
- fclose(qb);
- }
- int deleterecord()
- {
- FILE *fp;
- FILE *fp_temp;
- int flag = 0;
- char emp_ID[20];
- struct lecturer record;
- printf("Enter user ID: ");
- scanf(" %s", emp_ID);
- fp = fopen("L.txt", "r");
- if (!fp) {
- printf("Fail to open file");
- return -1;
- }
- fp_temp = fopen("temp.txt", "w");
- if (!fp_temp) {
- printf("Fail to open temp file.");
- return -1;
- }
- while (fread(&record, sizeof(struct lecturer), 1, fp) != NULL) {
- if (strcmp(emp_ID, record.emp_ID) == 0) {
- printf("Request have been found and actions have been taken.\n\n");
- flag = 1;
- }
- else {
- fwrite(&record, sizeof(struct lecturer), 1, fp_temp);
- }
- }
- if (!flag) {
- printf("No record with the requested details is found: %s\n\n", emp_ID);
- }
- fclose(fp);
- fclose(fp_temp);
- remove("L.txt");
- rename("temp.txt", "L.txt");
- return 0;
- }
- int updaterecordL()
- {
- FILE *fp;
- FILE *fp_temp;
- int flag = 0;
- char emp_ID[20];
- struct lecturer record;
- printf("Enter user ID: ");
- scanf(" %s", emp_ID);
- fp = fopen("L.txt", "a+");
- if (!fp) {
- printf("Fail to open file");
- return -1;
- }
- fp_temp = fopen("temp.txt", "a+");
- if (!fp_temp) {
- printf("Fail to open temp file.");
- return -1;
- }
- while (fread(&record, sizeof(struct lecturer), 1, fp) != NULL) {
- if (strcmp(emp_ID, record.emp_ID) == 0) {
- printf("Request have been found and actions have been taken.\n\n");
- flag = 1;
- printf("\nEnter new username: ");
- scanf(" %s", record.emp_name);
- printf("\nEnter new password: ");
- scanf(" %s", record.password);
- fseek(fp_temp, sizeof(struct lecturer), SEEK_CUR);
- fwrite(&record, sizeof(struct lecturer), 1, fp_temp);
- }
- else {
- fwrite(&record, sizeof(struct lecturer), 1, fp_temp);
- }
- }
- if (!flag) {
- printf("No record(s) found with the requested name: %s\n\n", emp_ID);
- }
- fclose(fp);
- fclose(fp_temp);
- remove("L.txt");
- rename("temp.txt", "L.txt");
- return 0;
- }
- int searchrecordL()
- {
- FILE *qb;
- struct lecturer record;
- char emp_ID[20];
- // Open user.txt for reading
- qb = fopen("L.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- printf("Enter Lecturer ID: ");
- scanf(" %s", emp_ID);
- // read file contents till end of file
- while (fread(&record, sizeof(struct lecturer), 1, qb))
- {
- if (strcmp(emp_ID, record.emp_ID) == 0)
- //{
- printf("\nUserID = %s \tUsername = %s \tPassword = %s", record.emp_ID,
- record.emp_ID, record.password);
- //}
- }
- return;
- fclose(qb);
- }
- int yearlyleaves()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO LEAVE UPDATER!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct yearlyleaves record;
- printf("Enter Number of Yearly Leaves: ");
- scanf(" %d", &record.days);
- printf("Yearly leaves is now set to %d days \n", record.days);
- FILE *qa;
- // open file for writing
- qa = fopen("yearlyleaves.txt", "w");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // write struct to file
- fwrite(&record, sizeof(struct yearlyleaves), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Success!!\n");
- else
- printf("ERROR!!\n");
- return 0;
- }
- int updateholidays()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO PUBLIC HOLIDAYS UPDATER!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct holidays record;
- date:
- printf("Enter date (DD/MM/YYYY format): ");
- fflush(stdin);
- scanf(" %d/%d/%d", &record.dd, &record.mm, &record.yy);
- if (record.yy >= 1900 && record.yy <= 9999)
- {
- //check month
- if (record.mm >= 1 && record.mm <= 12)
- {
- //check days
- if ((record.dd >= 1 && record.dd <= 31) && (record.mm == 1 || record.mm == 3 || record.mm == 5 || record.mm == 7 || record.mm == 8 || record.mm == 10 || record.mm == 12)) {
- printf("Valid Date.\n");
- }
- else if ((record.dd >= 1 && record.dd <= 30) && (record.mm == 4 || record.mm == 6 || record.mm == 9 || record.mm == 11)) {
- printf("Valid Date.\n");
- }
- else if ((record.dd >= 1 && record.dd <= 28) && (record.mm == 2)) {
- printf("Valid Date.\n");
- }
- else if (record.dd == 29 && record.mm == 2 && (record.yy % 400 == 0 || (record.yy % 4 == 0 && record.yy % 100 != 0))) {
- printf("Valid Date.\n");
- }
- else {
- printf("Invalid Date.\n");
- goto date;
- }
- }
- else
- {
- printf("Invalid Date.\n");
- goto date;
- }
- }
- else
- {
- printf("Invalid Date.\n");
- goto date;
- }
- printf("Enter the Description of Holiday: ");
- scanf(" %[^\n]%*c", record.description);
- printf("Public Holiday described as %s on date %d/%d/%d added\n", record.description, record.dd, record.mm, record.yy);
- FILE *qa;
- // open file for writing
- qa = fopen("holiday.txt", "a");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // write struct to file
- fwrite(&record, sizeof(struct holidays), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Success!!\n");
- else
- printf("ERROR!!\n");
- return 0;
- }
- int universitypolicies()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO ABC POLICIES UPDATER!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct policies record;
- FILE *qa;
- // open file for writing
- qa = fopen("policies.txt", "a+");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- char number[5];
- number:
- printf("Input Number of Policy: ");
- scanf(" %s", number);
- while (fread(&record, sizeof(struct policies), 1, qa)) {
- if (strcmp(record.count, number) == 0) {
- printf("\nNumber already exist! Insert another number.\n");
- goto number;
- }
- }
- strcpy(record.count, number);
- printf("\nInsert Policy: ");
- scanf(" %[^\n]%*c", record.policies);
- printf("New Policy added \n%s. %s\n", record.count, record.policies);
- // write struct to file
- fwrite(&record, sizeof(struct policies), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Success!!\n");
- else
- printf("ERROR!!\n");
- return 0;
- }
- int updatepolicies()
- {
- FILE *fp;
- FILE *fp_temp;
- int flag = 0;
- int number[5];
- struct policies record;
- printf("Enter Policy Number: ");
- scanf(" %s", number);
- fp = fopen("policies.txt", "r");
- if (!fp) {
- printf("Unable to open file");
- return -1;
- }
- fp_temp = fopen("temp.txt", "w");
- if (!fp_temp) {
- printf("Unable to open file temp file.");
- return -1;
- }
- while (fread(&record, sizeof(struct policies), 1, fp) != NULL) {
- if (strcmp(number, record.count) == 0) {
- printf("A record with requested name found and deleted.\n\n");
- flag = 1;
- printf("\nEnter new Policy: ");
- scanf(" %s", record.policies);
- fseek(fp_temp, sizeof(struct policies), SEEK_CUR);
- fwrite(&record, sizeof(struct policies), 1, fp_temp);
- printf("%s %s", record.count, record.policies);
- }
- else {
- fwrite(&record, sizeof(struct policies), 1, fp_temp);
- }
- }
- if (!flag) {
- printf("No record(s) found with the requested name: %s\n\n", number);
- }
- fclose(fp);
- fclose(fp_temp);
- remove("policies.txt");
- rename("temp.txt", "policies.txt");
- return 0;
- }
- int viewholidays()
- {
- FILE *qb;
- struct holidays record;
- // Open user.txt for reading
- qb = fopen("holiday.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nError opening file\n");
- exit(1);
- }
- // read file contents till end of file
- while (fread(&record, sizeof(struct holidays), 1, qb))
- {
- //if(strcmp(positionL, person.position) == 0)
- //{
- printf("Holiday due to %s on date %d/%d/%d\n", record.description, record.dd,
- record.mm, record.yy);
- //}
- }
- return;
- fclose(qb);
- }
- int viewFAQ()
- {
- FILE *qb;
- struct policies record;
- // Open user.txt for reading
- qb = fopen("policies.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // read file contents till end of file
- printf("FAQ About Lecturer Leave Policies are\n\n");
- while (fread(&record, sizeof(struct policies), 1, qb))
- {
- printf("%s. %s\n", record.count, record.policies);
- }
- return;
- fclose(qb);
- }
- int leaveapplication()
- {
- system("cls");
- printf("========================================================================================\n");
- printf("\t\tWELCOME TO ABC LEAVE APPLICATION!!\n");
- printf("=========================================================================================\n\n");
- date();
- printf("---------------------------------------------------------------------------------------------");
- struct leaveapplication record;
- printf("Enter the userID: ");
- scanf(" %s", record.emp_ID);
- printf("\nEnter your First Name: ");
- scanf(" %s", record.emp_name);
- printf("\nEnter your Reason: ");
- scanf(" %s", record.subject);
- char status[20] = "Pending";
- strcpy(record.status, status);
- date:
- printf("Enter the date of leave(DD/MM/YYYY format): ");
- fflush(stdin);
- scanf(" %d/%d/%d", &record.dd, &record.mm, &record.yy);
- if (record.yy >= 1900 && record.yy <= 9999)
- {
- //check month
- if (record.mm >= 1 && record.mm <= 12)
- {
- //check days
- if ((record.dd >= 1 && record.dd <= 31) && (record.mm == 1 || record.mm == 3 || record.mm == 5 || record.mm == 7 || record.mm == 8 || record.mm == 10 || record.mm == 12)) {
- printf("Valid Date.\n");
- }
- else if ((record.dd >= 1 && record.dd <= 30) && (record.mm == 4 || record.mm == 6 || record.mm == 9 || record.mm == 11)) {
- printf("Valid Date.\n");
- }
- else if ((record.dd >= 1 && record.dd <= 28) && (record.mm == 2)) {
- printf("Valid Date.\n");
- }
- else if (record.dd == 29 && record.mm == 2 && (record.yy % 400 == 0 || (record.yy % 4 == 0 && record.yy % 100 != 0))) {
- printf("Valid Date.\n");
- }
- else {
- printf("Invalid Date.\n");
- goto date;
- }
- }
- else
- {
- printf("Invalid Date.\n");
- goto date;
- }
- }
- else
- {
- printf("Invalid Date.\n");
- goto date;
- }
- FILE *qa;
- // open file for writing
- qa = fopen("leave.txt", "a");
- if (qa == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- // write struct to file
- fwrite(&record, sizeof(struct leaveapplication), 1, qa);
- fclose(qa);
- if (fwrite != 0)
- printf("\nRecord Success!!\n");
- else
- printf("ERROR!!\n");
- return 0;
- }
- int statusview()
- {
- FILE *qb;
- struct leaveapplication record;
- char userID[5];
- // Open user.txt for reading
- qb = fopen("leave.txt", "r");
- if (qb == NULL)
- {
- fprintf(stderr, "\nEOF\n");
- exit(1);
- }
- printf("Enter Lecturer ID: ");
- scanf(" %s", userID);
- // read file contents till end of file
- while (fread(&record, sizeof(struct leaveapplication), 1, qb))
- {
- if (strcmp(userID, record.emp_ID) == 0)
- //{
- printf("\nUserID = %s \tfirstname = %s \tlastname = %s \tStatus =%s \tDate = %d/%d/%d", record.emp_ID,
- record.emp_name, record.status, record.dd, record.mm, record.yy);
- //}
- }
- return;
- fclose(qb);
- }
- int changestatus()
- {
- FILE *fp;
- FILE *fp_temp;
- int flag = 0;
- char userID[5];
- struct leaveapplication record;
- printf("Enter user ID: ");
- scanf(" %s", userID);
- fp = fopen("leave.txt", "a+");
- if (!fp) {
- printf("Fail to open file");
- return -1;
- }
- fp_temp = fopen("temp.txt", "a+");
- if (!fp_temp) {
- printf("Fail to open temp file.");
- return -1;
- }
- while (fread(&record, sizeof(struct leaveapplication), 1, fp) != NULL) {
- if (strcmp(userID, record.emp_ID) == 0) {
- printf("A record with requested name found and deleted.\n\n");
- flag = 1;
- printf("\nEnter new Status: ");
- scanf(" %s", record.status);;
- fseek(fp_temp, sizeof(struct leaveapplication), SEEK_CUR);
- fwrite(&record, sizeof(struct leaveapplication), 1, fp_temp);
- }
- else {
- fwrite(&record, sizeof(struct leaveapplication), 1, fp_temp);
- }
- }
- if (!flag) {
- printf("No record(s) found with the requested name: %s\n\n", userID);
- }
- fclose(fp);
- fclose(fp_temp);
- remove("leave.txt");
- rename("temp.txt", "leave.txt");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement