Commit a93e418d by krmaet

Update changedata.c

parent d13c8963
Showing with 1 additions and 160 deletions
...@@ -6,53 +6,10 @@ ...@@ -6,53 +6,10 @@
#include <ncurses.h> #include <ncurses.h>
#include <time.h> #include <time.h>
#include "changedata.h" #include "changedata.h"
#include "readdata.h" #include "proccessing.h"
#include "main.h" #include "main.h"
int CheckUser(MYSQL *con, char *username, char *password)
{
char query[512];
int position;
//Query for password associated with the username
sprintf(query, "SELECT password, position FROM profiles WHERE username = '%s';", username);
if (mysql_query(con, query)) { //päring serverile
printf("Error getting data: %s\n", mysql_error(con));
exit(EXIT_FAILURE);
}
MYSQL_RES *result = mysql_store_result(con);
mysql_num_fields(result);
char tempPassword[128] = {" "};
char tempPosition[128] = {" "};
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
strcpy(tempPassword,row[0]);
strcpy(tempPosition,row[1]);
}
position = atoi(tempPosition);
//Check if passwords match
if (!strcmp(tempPassword, password))
{
if (position == ADMIN)
{
return ADMIN;
}
else if (position == ASSISTANT)
{
return ASSISTANT;
}
else if (position == CLIENT)
{
return CLIENT;
}
}
return -1;
}
int optionMenu(char *options[], int count, char buffer[STR_MAX], int *row, int *col) int optionMenu(char *options[], int count, char buffer[STR_MAX], int *row, int *col)
{ {
...@@ -207,123 +164,7 @@ void CheckIn(MYSQL *con, int *row, int *col) ...@@ -207,123 +164,7 @@ void CheckIn(MYSQL *con, int *row, int *col)
wrefresh(menu_win); wrefresh(menu_win);
} }
int CheckBookingDocument(MYSQL *con, char *bookingNumber, char *documentNumber, int *row, int *col)
{
WINDOW *menu_win;
clear();
refresh();
char booking[STR_MAX];
char document[STR_MAX];
char buffer[BUFFER_MAX];
menu_win = create_newwin(WIN_LENGTH, WIN_WIDTH, 1, *col / 2 - WIN_WIDTH/2);
//Ask for booking number
mvwprintw(menu_win, 1, 1, "Enter booking number");
mvwprintw(menu_win, 2, 1, "--------------------");
echo();
mvwscanw(menu_win, 3, 1, "%s", booking);
noecho();
//Ask for document number
mvwprintw(menu_win, 5, 1, "Enter document number");
mvwprintw(menu_win, 6, 1, "--------------------");
echo();
mvwscanw(menu_win, 7, 1, "%s", document);
noecho();
//Find document number associated with the booking number
sprintf(buffer, "SELECT documentNum FROM Users WHERE id IN"
"(SELECT user_id FROM Bookings WHERE bookingNumber = '%s');", booking);
if (mysql_query(con, buffer))
{
finish_with_error(con);
}
MYSQL_RES *result = mysql_store_result(con);
MYSQL_ROW row1;
row1 = mysql_fetch_row(result);
//Check if booking number exists
if (row1 == NULL)
{
mvwprintw(menu_win, 9, 1, "Booking number not found!");
mvwprintw(menu_win, 10, 1, "Press any key to continue!");
wgetch(menu_win);
return 0;
}
mysql_free_result(result);
//Check if documentNumbers match
if (!strcasecmp(row1[0], document))
{
strcpy(bookingNumber, booking);
strcpy(documentNumber, document);
wrefresh(menu_win);
delwin(menu_win);
return 1;
}
else
{
mvwprintw(menu_win, 9, 1, "Document number does not match!");
mvwprintw(menu_win, 10, 1, "Press any key to continue!");
wgetch(menu_win);
wrefresh(menu_win);
delwin(menu_win);
return 0;
}
}
int CheckBooking(MYSQL *con, char *bookingNumber, int *row, int *col)
{
WINDOW *menu_win;
clear();
refresh();
char temp[STR_MAX];
char buffer[200];
menu_win = create_newwin(WIN_LENGTH, WIN_WIDTH, 1, *col / 2 - WIN_WIDTH/2);
//Ask for booking number
mvwprintw(menu_win, 1, 1, "Enter booking number");
mvwprintw(menu_win, 2, 1, "--------------------");
echo();
mvwscanw(menu_win, 3, 1, "%s", temp);
noecho();
sprintf(buffer, "SELECT id FROM Bookings WHERE bookingNumber = '%s';", temp);
if (mysql_query(con, buffer))
{
finish_with_error(con);
}
MYSQL_RES *result = mysql_store_result(con);
MYSQL_ROW row1;
row1 = mysql_fetch_row(result);
mysql_free_result(result);
//Check if booking number exists
if (row1 != NULL)
{
strcpy(bookingNumber, temp);
wrefresh(menu_win);
delwin(menu_win);
return 1;
}
else
{
mvwprintw(menu_win, 5, 1, "Booking number does not exist!");
mvwprintw(menu_win, 6, 1, "Press any key to continue!");
wgetch(menu_win);
wrefresh(menu_win);
delwin(menu_win);
return 0;
}
}
void ChangeName(MYSQL *con, char *booking, int *row, int *col) void ChangeName(MYSQL *con, char *booking, int *row, int *col)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment