diff --git a/include/db_handler.h b/include/file_handler.h similarity index 85% rename from include/db_handler.h rename to include/file_handler.h index 20b45e4..07fcf46 100644 --- a/include/db_handler.h +++ b/include/file_handler.h @@ -3,8 +3,8 @@ * */ -#ifndef __DB_HANDLER_H__ -#define __DB_HANDLER_H__ +#ifndef __FILE_HANDLER_H__ +#define __FILE_HANDLER_H__ #include "main.h" #include "users.h" diff --git a/include/tui.h b/include/tui.h index 8a36406..b9e6b5a 100644 --- a/include/tui.h +++ b/include/tui.h @@ -18,6 +18,8 @@ void personSearch(list_t *person_list, int terminal_x, int terminal_y); void personInfo(node_t *_person, int terminal_x, int terminal_y); -void exportDialog(list_t _list, int terminal_x, int terminal_y) +void exportDialog(list_t *_list, int terminal_x, int terminal_y); + +void editDatabaseMenu(list_t *_person_list, int terminal_x, int terminal_y); #endif \ No newline at end of file diff --git a/src/db_handler.c b/src/file_handler.c similarity index 88% rename from src/db_handler.c rename to src/file_handler.c index 7c95b52..0d0e049 100644 --- a/src/db_handler.c +++ b/src/file_handler.c @@ -1,4 +1,4 @@ -#include "db_handler.h" +#include "file_handler.h" int loadListFromCSV(char *_filename, list_t *_list) { @@ -51,7 +51,7 @@ int saveListToCSV(char *_filename, list_t *_list) { if (cursor->user.uuid != 0) { - fprintf(f_out, "%hu,%s,%s,%u,%ld,%ld,%hhu", cursor->user.uuid, cursor->user.name, cursor->user.surname, cursor->user.department, cursor->user.last_time_event, cursor->user.total, cursor->user.available); + fprintf(f_out, "%hu,%s,%s,%u,%ld,%ld,%hhu\n", cursor->user.uuid, cursor->user.name, cursor->user.surname, cursor->user.department, cursor->user.last_time_event, cursor->user.total, cursor->user.available); } cursor = cursor->next; } diff --git a/src/main.c b/src/main.c index 06d9acd..03575f4 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include "users.h" #include "tui.h" #include "rfid_handler.h" -#include "db_handler.h" +#include "file_handler.h" void handle_sigint(int sig) { diff --git a/src/tui.c b/src/tui.c index b5c8ee3..dc94e25 100644 --- a/src/tui.c +++ b/src/tui.c @@ -3,8 +3,9 @@ #include #include #include + #include "main.h" -#include "db_handler.h" +#include "file_handler.h" #include "tui.h" void uartDialog(char *uart_adress, int terminal_x, int terminal_y) @@ -183,6 +184,10 @@ void mainMenu(list_t *person_list, int terminal_x, int terminal_y) personSearch(person_list, terminal_x, terminal_y); break; + case 4: + exportDialog(person_list, terminal_x, terminal_y); + break; + case 5: if (keyboard_input == '\n') { @@ -562,6 +567,111 @@ void personInfo(node_t *_person, int terminal_x, int terminal_y) } } -void exportDialog(list_t _list, int terminal_x, int terminal_y){ - +void exportDialog(list_t *_list, int terminal_x, int terminal_y) +{ + int win_height = 8; + int win_width = 80; + int start_y = (terminal_y - win_height) / 2; + int start_x = (terminal_x - win_width) / 2; + + WINDOW *exportdialog = newwin(win_height, win_width, start_y, start_x); + + wbkgd(exportdialog, COLOR_PAIR(6)); + + int max_rows = win_height - 2; + int total_count = 0; + box(exportdialog, 0, 0); + + wattron(exportdialog, COLOR_PAIR(1)); + wattron(exportdialog, A_BOLD); + mvwprintw(exportdialog, 0, (win_width - strlen("Copy database and save")) / 2, "%s", "Copy database and save"); + wattroff(exportdialog, A_BOLD); + wattroff(exportdialog, COLOR_PAIR(1)); + keypad(exportdialog, TRUE); + + wattron(exportdialog, COLOR_PAIR(1)); + mvwprintw(exportdialog, 2, (win_width - strlen("Enter name of exported database")) / 2, "%s", "Enter name of exported database"); + wattroff(exportdialog, COLOR_PAIR(1)); + wrefresh(exportdialog); + + char choice; + int highlight = 0; + + int text_x = (win_width - 52) / 2; + int button_x = (win_width - 7) / 2; + + char filename[51]; + + keypad(exportdialog, true); + while (1) + { + // Input array + if (highlight == 0) + wattron(exportdialog, COLOR_PAIR(2)); + else + wattron(exportdialog, COLOR_PAIR(1)); + + mvwprintw(exportdialog, 4, text_x, "[%50s]", filename); + if (!strcmp(filename, "\0")) + mvwprintw(exportdialog, 4, text_x, "[__________________________________________________]"); + + if (highlight == 0) + wattroff(exportdialog, COLOR_PAIR(2)); + else + wattroff(exportdialog, COLOR_PAIR(1)); + + // Enter button + if (highlight == 1) + wattron(exportdialog, COLOR_PAIR(2)); + else + wattron(exportdialog, COLOR_PAIR(1)); + wattron(exportdialog, A_BOLD); + + mvwprintw(exportdialog, 6, button_x - 2, " %s ", ""); + if (highlight == 1) + wattroff(exportdialog, COLOR_PAIR(2)); + else + wattroff(exportdialog, COLOR_PAIR(1)); + wattroff(exportdialog, A_BOLD); + + wrefresh(exportdialog); + + flushinp(); + choice = wgetch(exportdialog); + + if (choice == '\t') + { + highlight = !highlight; + } + + else if (choice == '\n') + { + if (highlight == 0) + { + mvwprintw(exportdialog, 4, (win_width - 52) / 2, "[__________________________________________________]"); + echo(); + wmove(exportdialog, 4, ((win_width - 52) / 2) + 1); + curs_set(1); + flushinp(); + wgetnstr(exportdialog, filename, 50); + curs_set(0); + noecho(); + } + else if (highlight == 1) + { + + if (choice == '\n') + { + saveListToCSV(filename, _list); + wclear(exportdialog); + wrefresh(exportdialog); + touchwin(stdscr); + refresh(); + delwin(exportdialog); + refresh(); + return; + } + } + } + } } \ No newline at end of file