Skip to content

Commit

Permalink
Merge pull request #52 from ktauchathuranga/develop
Browse files Browse the repository at this point in the history
👍🏻
  • Loading branch information
ktauchathuranga authored May 3, 2024
2 parents 25daa6b + 2d1d356 commit 542f2a6
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

- If your code uses `func.c`:
```
gcc main.c func.c -o main -lcrypto -lsqlite3
gcc your-code-name.c func.c -o main -lcrypto -lsqlite3
```
- If your code **DONT** uses `func.c`:
```
gcc main.c -o main -lcrypto -lsqlite3
gcc your-code-name.c -o main -lcrypto -lsqlite3
```
Replace `your-code-name.c` with code that you want to compile.

> [!NOTE]
> - You need, `openssl` library and `sqlite3` library.
Expand Down
122 changes: 117 additions & 5 deletions func.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ void stdReg()

free(data);

insertEnrollmentData(stid); // To update enrollment table


// printf("DONE!");
}
Expand Down Expand Up @@ -439,6 +441,8 @@ void tutReg()

free(data);

insertClassData(tutid); // To update class table

// printf("DONE!");
}

Expand Down Expand Up @@ -759,7 +763,7 @@ void editClass(){

// printf("\n===Edit Class===\n\n");
printf("\t1. Edit Class Details\n");
printf("\t2. Delete Class\n");
printf("\t2. Display Class\n");
printf("\t3. Back to Manage Class Menu\n");
printf("\t0. Back to Main Menu\n");
printf("======================================\n");
Expand All @@ -774,9 +778,7 @@ void editClass(){
break;

case 2:
printf("[-] Enter Class ID to Delete: ");
scanf("%d",&classID);
deleteClass(classID);
displayclasslist();
break;
case 3:
manageClass();
Expand Down Expand Up @@ -928,6 +930,7 @@ void manageTutors() {

void manageClass() {
int classChoice;
int classID;
do {
printf("============ Manage Class ============\n");
printf("1. Add Class\n");
Expand All @@ -948,7 +951,9 @@ void manageClass() {
break;
case 3:
// Add related function
displayclasslist();
printf("[-] Enter Class ID to Delete: ");
scanf("%d",&classID);
deleteClass(classID);
break;
case 0:
printf("[|] Returning to main menu.\n");
Expand Down Expand Up @@ -1178,4 +1183,111 @@ void checkAttendance() {
{
printf("[!] No Attendance Data Found for Student With Enrollment ID %d on %s.\n", enrollmentID, date);
}
}

void insertEnrollmentData(int stid)
{
sqlite3 *db;
int rc = sqlite3_open("test.db", &db);
if (rc)
{
fprintf(stderr, "[!] Can't Open Database: %s\n", sqlite3_errmsg(db));
return;
}

int lastEnrollmentID = 0;
int classID;
char enrollmentDay[20];

const char *getLastEnrollmentIDQuery = "SELECT MAX(EnrollmentID) FROM Enrollments;";
sqlite3_stmt *stmt;
rc = sqlite3_prepare_v2(db, getLastEnrollmentIDQuery, -1, &stmt, 0);
if (rc != SQLITE_OK)
{
fprintf(stderr, "[!] Failed to prepare statement: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return;
}

if (sqlite3_step(stmt) == SQLITE_ROW)
{
lastEnrollmentID = sqlite3_column_int(stmt, 0);
}

sqlite3_finalize(stmt);

printf("[-] Enter Class ID: ");
scanf("%d", &classID);
printf("[-] Enter Enrollment Day (YYYY-MM-DD): ");
scanf("%s", enrollmentDay);

char insertSQL[200];
sprintf(insertSQL, "INSERT INTO Enrollments (EnrollmentID, StudentID, ClassID, EnrollmentDate) VALUES (%d, %d, %d, '%s');", lastEnrollmentID + 1, stid, classID, enrollmentDay);
if (executeSQL(db, insertSQL) == SQLITE_OK)
{
printf("=======================================\n");
printf("[+] Enrollment Data Inserted Successfully.\n");
}
else
{
fprintf(stderr, "[!] Failed to Insert Enrollment Data.\n");
}

sqlite3_close(db);
}

void insertClassData(int tutorid)
{
sqlite3 *db;
int rc = sqlite3_open("test.db", &db);
if (rc)
{
fprintf(stderr, "[!] Can't Open Database: %s\n", sqlite3_errmsg(db));
return;
}

int lastClassID = 0;
char className[100];
char classTime[20];
char classDays[40];

const char *getLastClassIDQuery = "SELECT MAX(ClassID) FROM Classes;";
sqlite3_stmt *stmt;
rc = sqlite3_prepare_v2(db, getLastClassIDQuery, -1, &stmt, 0);
if (rc != SQLITE_OK)
{
fprintf(stderr, "[!] Failed to Prepare Statement: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return;
}

if (sqlite3_step(stmt) == SQLITE_ROW)
{
lastClassID = sqlite3_column_int(stmt, 0);
}

sqlite3_finalize(stmt);

printf("[-] Enter Class Name: ");
scanf("%s", className);

printf("[-] Enter Class Time (00:00): ");
scanf("%s", classTime);

printf("[-] Enter Class Days (day,day,day): ");
scanf("%s", classDays);

char insertSQL[300];
sprintf(insertSQL, "INSERT INTO Classes (ClassID, ClassName, TutorID, ClassTime, ClassDays) VALUES (%d, '%s', %d, '%s', '%s');", lastClassID + 1, className, tutorid, classTime, classDays);
if (executeSQL(db, insertSQL) == SQLITE_OK)
{
printf("=======================================\n");
printf("[+] Class Data Inserted Successfully.\n");
}
else
{
fprintf(stderr, "[!] Failed to Insert Class Data.\n");
}

sqlite3_close(db);
}
2 changes: 2 additions & 0 deletions func.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ void dueFee();
void markAttendance();
void checkAttendance();
void status();
void insertEnrollmentData(int stid);
void insertClassData(int tutorid);

#endif

0 comments on commit 542f2a6

Please sign in to comment.