Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
mvahes
/
Lennubroneerimis_tarkvara
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f0d99fff
authored
Mar 29, 2023
by
krmaet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update readdata.c
parent
e0fd525a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
30 deletions
readdata.c
readdata.c
View file @
f0d99fff
...
...
@@ -11,37 +11,33 @@
int
CheckUser
(
MYSQL
*
con
,
char
*
username
,
char
*
password
)
{
char
query
[
STR_MAX
];
char
temp
[
STR_MAX
];
int
position
;
char
query
[
512
];
sprintf
(
query
,
"SELECT password FROM profiles WHERE username = krmaet;"
)
;
int
position
;
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
;
strcpy
(
temp
,
row
[
0
]);
if
(
!
strstr
(
temp
,
password
))
while
((
row
=
mysql_fetch_row
(
result
)))
{
sprintf
(
query
,
"SELECT position FROM profiles WHERE username = %s;"
,
username
);
strcpy
(
tempPassword
,
row
[
0
]);
strcpy
(
tempPosition
,
row
[
1
]);
}
position
=
atoi
(
tempPosition
);
if
(
mysql_query
(
con
,
query
))
{
//päring serverile
printf
(
"Error getting seat data: %s
\n
"
,
mysql_error
(
con
));
exit
(
EXIT_FAILURE
);
}
MYSQL_RES
*
result
=
mysql_store_result
(
con
);
mysql_num_fields
(
result
);
MYSQL_ROW
row
;
position
=
atoi
(
row
[
0
]);
if
(
!
strcmp
(
tempPassword
,
password
))
{
if
(
position
==
ADMIN
)
{
return
ADMIN
;
...
...
@@ -50,15 +46,12 @@ int CheckUser(MYSQL *con, char *username, char *password)
{
return
ASSISTANT
;
}
else
else
if
(
position
==
CLIENT
)
{
return
CLIENT
;
}
}
else
{
return
-
1
;
}
return
-
1
;
}
void
NewTicket
(
int
*
row
,
int
*
col
,
char
*
seat
,
int
flightID
,
MYSQL
*
con
,
int
count
)
...
...
@@ -88,13 +81,13 @@ void NewTicket(int *row, int *col, char *seat, int flightID, MYSQL *con, int cou
strcpy
(
data
[
count
].
documentNum
,
docNum
);
mvwprintw
(
ticket_win
,
3
,
1
,
"Enter first name:"
);
//lisada juurde et kui on tühik siis
char
fName
[
NAME_MAX
];
//muudetakse see alakriipsuks.
wscanw
(
ticket_win
,
"%
s"
,
fName
);
char
fName
[
NAME_MAX
];
//muudetakse see alakriipsuks.
wscanw
(
ticket_win
,
"%
[^
\n
]%*c"
,
fName
);
//Reads until newline
strcpy
(
data
[
count
].
fName
,
fName
);
mvwprintw
(
ticket_win
,
5
,
1
,
"Enter last name:"
);
//sama kommentaar mis eelmisele
char
lName
[
NAME_MAX
];
wscanw
(
ticket_win
,
"%
s"
,
lName
);
wscanw
(
ticket_win
,
"%
[^
\n
]%*c"
,
lName
);
//Reads until newline
strcpy
(
data
[
count
].
lName
,
lName
);
mvwprintw
(
ticket_win
,
7
,
1
,
"Enter date of birth (Format: 'DD.Month.Year'):"
);
...
...
@@ -119,7 +112,7 @@ void NewTicket(int *row, int *col, char *seat, int flightID, MYSQL *con, int cou
mvwprintw
(
ticket_win
,
14
,
1
,
"-------------------"
);
char
*
options
[
3
]
=
{
"Small bag + Carry-On(default included in fare)"
,
"
1-Check-In 20kg suitcase"
,
"2-
Oversized(bikes, 20+kg)"
};
"
Check-In 20kg suitcase"
,
"
Oversized(bikes, 20+kg)"
};
while
(
1
)
{
for
(
i
=
0
;
i
<
3
;
i
++
)
...
...
@@ -164,6 +157,7 @@ void NewTicket(int *row, int *col, char *seat, int flightID, MYSQL *con, int cou
data
[
count
].
luggageClass
=
highlight
;
delwin
(
ticket_win
);
insertPersonIntoTable
(
con
,
data
[
count
],
row
,
col
);
}
...
...
@@ -348,6 +342,61 @@ void insertPersonIntoTable(MYSQL* con, users data, int *rows, int *cols)
printf
(
"Error creating bookings for the users: %s
\n
"
,
mysql_error
(
con
));
exit
(
EXIT_FAILURE
);
}
char
buffer
[
STR_MAX
];
sprintf
(
buffer
,
"SELECT id,destination,time FROM Flights WHERE Flights.id = %d;"
,
data
.
flight_id
);
if
(
mysql_query
(
con
,
buffer
))
{
finish_with_error
(
con
);
}
MYSQL_RES
*
result2
=
mysql_store_result
(
con
);
int
num_fields
=
mysql_num_fields
(
result2
);
MYSQL_ROW
row2
;
char
fileName
[
STR_MAX
];
sprintf
(
fileName
,
"Booking_%s.txt"
,
bookingCode
);
FILE
*
fp
=
fopen
(
fileName
,
"w"
);
//Check if file was opened
if
(
fp
==
NULL
)
{
perror
(
"Couldn't open input file!"
);
exit
(
EXIT_FAILURE
);
}
fprintf
(
fp
,
"BOOKING %s
\n
"
,
bookingCode
);
fprintf
(
fp
,
"
\n
Name: %s %s"
,
data
.
fName
,
data
.
lName
);
fprintf
(
fp
,
"
\n
Document number: %s"
,
data
.
documentNum
);
fprintf
(
fp
,
"
\n
Residency: %s"
,
data
.
residency
);
fprintf
(
fp
,
"
\n
Email: %s"
,
data
.
email
);
fprintf
(
fp
,
"
\n\n
Flight: "
);
while
((
row2
=
mysql_fetch_row
(
result2
)))
{
for
(
int
i
=
0
;
i
<
num_fields
;
i
++
)
{
fprintf
(
fp
,
"%s "
,
row
[
i
]
?
row
[
i
]
:
"NULL"
);
}
}
fprintf
(
fp
,
"
\n
Seat: %s"
,
data
.
seat
);
switch
(
data
.
luggageClass
)
{
case
0
:
fprintf
(
fp
,
"
\n
Luggage: Small bag + Carry-On(default included in fare)"
);
break
;
case
1
:
fprintf
(
fp
,
"
\n
Luggage: Check-In 20kg suitcase"
);
break
;
case
2
:
fprintf
(
fp
,
"
\n
Luggage: Oversized(bikes, 20+kg)"
);
break
;
default:
break
;
}
fclose
(
fp
);
mvwprintw
(
ticket_win
,
5
,
1
,
"Press any key to continue"
);
wgetch
(
ticket_win
);
wrefresh
(
ticket_win
);
...
...
@@ -380,7 +429,6 @@ int ShowDestinations(MYSQL *con, int *rows, int *cols)
count
++
;
}
mvwprintw
(
menu_win
,
11
,
1
,
"Count is %d"
,
count
);
mvwprintw
(
menu_win
,
12
,
1
,
"To select press (1-%d)"
,
count
);
int
selection
;
do
...
...
@@ -388,7 +436,6 @@ int ShowDestinations(MYSQL *con, int *rows, int *cols)
selection
=
wgetch
(
menu_win
)
-
48
;
if
(
selection
>
count
||
selection
<
1
)
{
mvwprintw
(
menu_win
,
11
,
1
,
"selection-%d"
,
selection
);
mvwprintw
(
menu_win
,
12
,
1
,
"Invalid selection, retry (1-%d)"
,
count
);
}
}
while
(
selection
>
count
||
selection
<
1
);
...
...
@@ -418,7 +465,7 @@ MYSQL* connectToMySQLServer()
exit
(
1
);
}
if
(
mysql_real_connect
(
con
,
"127.0.0.1"
,
"root"
,
"
teretere
"
,
if
(
mysql_real_connect
(
con
,
"127.0.0.1"
,
"root"
,
"
Tarumesiauto321
"
,
"broneeringud"
,
0
,
NULL
,
0
)
==
NULL
)
{
finish_with_error
(
con
);
...
...
@@ -453,3 +500,17 @@ int GetRand(int min, int max)
{
return
(
rand
()
%
(
max
-
min
+
1
))
+
min
;
}
int
CheckLetters
(
char
word
[
STR_MAX
])
{
int
i
;
for
(
i
=
0
;
i
<
strlen
(
word
);
i
++
)
{
if
((
word
[
i
]
>=
'a'
&&
word
[
i
]
<=
'z'
)
||
(
word
[
i
]
>=
'A'
&&
word
[
i
]
<=
'Z'
))
{
return
0
;
}
}
return
1
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment