-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainScript.c
More file actions
2259 lines (2099 loc) · 72.9 KB
/
MainScript.c
File metadata and controls
2259 lines (2099 loc) · 72.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//////**********************************Basics of programming, first semester project**********************************/
////********************************************ImmuneTastic Application**********************************************/
////*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/
////********************************************Developed and designed by:******************************************/
//*************************************************~#Alireza Mirzaei#~*********************************************/
//*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#include <mysql/mysql.h>
#define strSize 45
//TO RUN THE SCRIPT : gcc MainScript.c `mysql_config --cflags --libs`
//Global variables
long int national_code;
int province, type = 0;
char username[strSize], pass1[strSize], pass2[strSize], email[60], statement[1000];
char TFAQ01[90], TFAA01[90], TFAQ02[90], TFAA02[90], uni[20], ushi[20], hos_name[50], city[50];
//statement variable is for using in mysql_query
//Initialize MySQL connections and etc.
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
//Structures (DEFINED GLOBALLY)
struct users
{
//char user_type[strSize];
int id;
char user_name[strSize];
char passwd[strSize];
char fname[strSize];
char lname[strSize];
char email[strSize];
long int national_code;
//Normal only
char bloodG[4];
int age;
int height;
int weight;
int test_score;
int test_counter;
int health_code;
int test_score_history[100];
time_t test_time_history[100];
//Shop only
int disinfection;
int mantaghe;
char store_name[strSize];
char cityName[strSize];
};
struct users normalUser;
struct users shopUser;
struct users admin;
//Function prototypes
void welcome();
//Menus
void main_menu();
void help_mm();
void command_mm();
void signup_menu();
void forgot_passwd();
//login
void login();
void findUsernormal(int);
void findUsershop(int);
//Signup
void signupNorm();
void signupShop();
char getPasswd(char *, int, int);
int national_code_check(long int);
//pages
void admin_page();
void normal_page();
void shop_page();
void medical_advices();
void health_test(int *);
void healthCode();
void choice_check(char *);
void edit_info(char);
//MySQL functions
void finish_with_error(MYSQL *conn);
void create_statement(char *, char *);
// Main Driver Program
// Mostly users info
int main()
{
//Program Start
//Initialize database
conn = mysql_init(NULL);
//puts("\e[1;1H\e[02J");
//puts("Please Enter database password to proceed: ");
//getPasswd(&pass1, 1, 1);
//Connect to database
if (!mysql_real_connect(conn, "localhost", "root", "Guess1Pass@AM", "project_database", 0, NULL, 0))
finish_with_error(conn);
//mysql_query(conn, "CREATE DATABASE testdb1"); For testing connection
strcpy(TFAQ01, "What is your ascii_sum?");
strcpy(TFAA01, "ChertoPeRt!!!!! :-/");
strcpy(TFAQ02, "What is your first class teacher + Your favorite color?");
strcpy(TFAA02, "Ms.RedZade :)))))))");
welcome();
sleep(2);
main_menu();
mysql_close(conn); //End of program
}
//Functions body
//Welcome and main menu section
void welcome()
{
printf("\e[1;1H\e[2J");
sleep(1);
printf("\n\n \e[1;40;37m _____ \e[0m\n");
puts(" \e[1;40;37m |_ _| \e[0m");
puts(" \e[1;40;37m | | _ __ ___ _ __ ___ _ _ _ __ ___ \e[0m");
puts(" \e[1;40;37m | | | '_ ` _ \\/ '_ ` _ \\| | | | '_ \\ / _ \\ \e[0m");
puts(" \e[1;40;37m _| |_| | | | | | | | | | | |_| | | | | __/ \e[0m");
puts(" \e[1;40;37m |_____|_| |_| |_|_| |_| |_|\\__,_|_| |_|\\___| \e[0m");
puts(" \e[1;40;37m |__ __| | | (_) \e[0m");
puts(" \e[1;40;37m | | __ _ ___| |_ _ ___ \e[0m");
puts(" \e[1;40;37m | |/ _` / __| __| |/ __| \e[0m");
puts(" \e[1;40;37m | | (_| \\__ \\ |_| | (__ \e[0m");
puts(" \e[1;40;37m |_|\\__,_|___/\\__|_|\\___| \e[0m");
puts(" \e[1;40;37m \e[0m");
puts("");
sleep(5);
printf("\e[1;1H\e[2J");
printf("\t\t\t\t\t\t\t \e[36;1mWelcome to ImmuneTastic!\n\n\e[0m");
sleep(2);
printf("\t\t\t\t\t\t >>>>>>>> \e[1;32mDeveloped By : Alireza Mirzaei\e[0m <<<<<<<<\n");
sleep(2);
}
void main_menu()
{
printf("\e[1;1H\e[2J");
fflush(stdout);
sleep(1);
puts("\e[21;24;36mMain Menu\e[0m \n\n\e[31;1mlogin(1)\e[0m || \e[32;1msign up(2)\e[0m || \e[33;1mforgot password(3)\e[0m || \e[34;1mhelp(4)\e[0m || \e[35;1mchange password layout(5)\e[0m || \e[1mexit(0)\e[0m");
printf("\n>> ");
command_mm();
}
//Helps
void help_mm()
{
puts("\e[46;37mHelp for : Main menu\r"); //Help for main menu
puts("To login to your account, type login\r");
puts("To sign up, type signup\r");
puts("If you've forgotten your password, type password recovery/forgot password\r\e[0m");
}
//Commands
void command_mm()
{
char command[strSize];
fgets(command, strSize, stdin);
switch (command[0])
{
case 'l':
case 'L':
case '1':
login();
break;
case 's':
case 'S':
case '2':
signup_menu();
break;
case 'P':
case 'p':
case 'f':
case 'F':
case '3':
forgot_passwd();
break;
case 'h':
case 'H':
case '4':
help_mm();
sleep(5);
getchar();
main_menu();
break;
case 'c':
case 'C':
case '5':
puts("Do you want password fields to be linux-type(1) or star-type(0)?");
int temp;
scanf("%d", &temp);
type = temp;
sleep(1);
getchar();
main_menu();
break;
case 'e':
case 'E':
case '0':
mysql_close(conn);
exit(0);
default:
printf("Enter a valid input please \n>> ");
command_mm();
}
}
char getPasswd(char *password, int tekrar, int type)
{
int cnt = 0;
*password = '\0';
while ((strlen(password) < 6 || strlen(password) > strSize) && strcmp(password, "-1") != 0)
{
if (cnt == 1)
{
if (tekrar == 1)
printf("\e[34mPlease enter your Password: \e[0m");
else
printf("\e[34mPlease enter your Password again: \e[0m");
}
int i;
char ch1;
for (i = 0; i < strSize; i++)
{
ch1 = getch();
if (ch1 != 10)
if (ch1 != 127)
{
if (type == 1)
printf("");
else
printf("*");
password[i] = ch1;
}
else if (i > 0)
{
printf("\b \b");
i -= 2;
}
else
i = -1;
else
break;
}
password[i] = '\0';
if (strlen(password) < 5 && strcmp(password, "-1") != 0)
puts("\n\e[32;1mThe password should be more than 5 characters!\e[0m");
cnt++;
}
return password;
}
//Login_section
void login()
{
sleep(1);
printf("\e[1;1H\e[2J");
fflush(stdout);
printf("Username(type return/-1 to go back): ");
scanf("%s", username);
findUsernormal(1);
findUsershop(1);
create_statement("fetch_data", "admin");
if (!strcmp(username, "return") || !strcmp(username, "Return") || !strcmp(username, "-1"))
{
puts("\nReturning to main menu ...");
sleep(1);
getchar();
main_menu();
}
else if ((strcmp(uni, "NULL") == 0) && (strcmp(ushi, "NULL") == 0) && (strcmp(username, "admin") != 0))
{
puts("\nUser name not found, Please try again"); //back to login
sleep(2);
printf("\e[1;1H\e[2J");
fflush(stdout);
login();
}
//Admin login
else if (!strcmp(admin.user_name, username))
{
getPasswd(&pass1, 1, type);
if (!strcmp(admin.passwd, pass1))
{
puts("\n\e[32;1;24mLogin successful, Welcome to your account!\e[0m");
sleep(1);
admin_page();
}
else
{
puts("\nIncorrect password, Please login again!"); //back to admin login
sleep(2);
printf("\e[1;1H\e[2J");
fflush(stdout);
login();
}
}
//Normal Login
else if (strcmp(uni, "NULL") != 0)
{
create_statement("fetch_data", "normal_users");
if (normalUser.health_code == 5)
{
puts("Sorry but you were reported \e[1;31mDEAD\e[0m, therefore you cannot login! Enter a key...");
getchar();
getchar();
login();
}
getPasswd(&pass1, 1, type);
if (!strcmp(normalUser.passwd, pass1))
{
puts("\n\e[32;1;24mLogin successful, Welcome to your account!\e[0m");
sleep(1);
normal_page();
}
else
{
puts("\nIncorrect password, Please login again!"); //back to login
sleep(2);
printf("\e[1;1H\e[2J");
fflush(stdout);
login();
}
}
// Shop Login
else if (strcmp(ushi, "NULL") != 0)
{
create_statement("fetch_data", "shop_users");
getPasswd(&pass1, 1, type);
if (!strcmp(pass1, shopUser.passwd))
{
puts("\n\e[32;1;24mLogin successful, Welcome to your account!\e[0m");
sleep(1);
shop_page();
}
else
{
puts("\nIncorrect password, Please login again!"); //back to login
sleep(1);
printf("\e[1;1H\e[2J");
fflush(stdout);
login();
}
}
}
// These 2 functions return id if they find the username
// in the database, else "NULL"
void findUsernormal(int stat)
{
if (stat == 1)
{
//Username duplicates
snprintf(statement, sizeof(statement), "SELECT id FROM normal_users WHERE username = '%s';", username);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(uni, row[0]);
else
strcpy(uni, "NULL");
mysql_free_result(res);
}
else if (stat == 2) //check email duplicates
{
snprintf(statement, sizeof(statement), "SELECT id FROM normal_users WHERE email = '%s';", email);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(uni, row[0]);
else
strcpy(uni, "NULL");
mysql_free_result(res);
}
else if (stat == 3) //national_code duplicate
{
snprintf(statement, sizeof(statement), "SELECT id FROM normal_users WHERE national_code = %ld;", national_code);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(uni, row[0]);
else
strcpy(uni, "NULL");
mysql_free_result(res);
}
}
void findUsershop(int stat)
{
if (stat == 1)
{
snprintf(statement, sizeof(statement), "SELECT id FROM shop_users WHERE username = '%s';", username);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(ushi, row[0]);
else
strcpy(ushi, "NULL");
mysql_free_result(res);
}
else if (stat == 2)
{
snprintf(statement, sizeof(statement), "SELECT id FROM shop_users WHERE email = '%s';", email);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(ushi, row[0]);
else
strcpy(ushi, "NULL");
mysql_free_result(res);
}
else if (stat == 3)
{
snprintf(statement, sizeof(statement), "SELECT id FROM shop_users WHERE national_code = %ld;", national_code);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(ushi, row[0]);
else
strcpy(ushi, "NULL");
mysql_free_result(res);
}
else if (stat == 4)
{
snprintf(statement, sizeof(statement), "SELECT id FROM shop_users WHERE store_name = '%s';", hos_name);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
row = mysql_fetch_row(res);
if (row != NULL)
strcpy(ushi, row[0]);
else
strcpy(ushi, "NULL");
mysql_free_result(res);
}
}
//Pages_section
//Admin_page
void admin_page()
{
printf("\e[1;1H\e[2J");
printf("\t\t\t\t\t\t\t\e[1;32mHi %s %s, Welcome to your account\n\e[0m", admin.fname, admin.lname);
puts("\e[1mEnter desired command to proceed.\e[0m");
puts("\e[34m1. Add a Hospital");
puts("2. See statistics");
puts("3. Edit users health info");
puts("4. See all users");
puts("5. Show the list of deaths");
puts("6. List of registered shops");
puts("7. List of all registered hospitals");
puts("8. Edit your information");
puts("9. Logout");
puts("0. Exit the program\e[0m");
printf(">> ");
int choice;
scanf("%d", &choice);
while (choice < 0 || choice > 9)
{
printf("\n Wrong choice, Enter again..\n");
printf(">> ");
scanf("%d", &choice);
}
switch (choice)
{
case 1:
printf("\e[1;1H\e[2J");
sleep(1);
getchar();
printf("Enter Hospital Name: ");
scanf("%[^\n]s", hos_name);
getchar();
printf("\nEnter city name : ");
scanf("%[^\n]s", city);
getchar();
printf("\nEnter hospitals province as a whole number : ");
scanf("%d", &province);
getchar();
create_statement("add_hospital", "admin");
printf("Hospital %s created successfully\n", hos_name);
sleep(2);
admin_page();
break;
case 2:
case 3:
puts("\nList of sick people sorted by name\n");
create_statement("see_sicks", "admin");
if (choice == 2)
{
getchar();
puts("Press a key to proceed...");
getchar();
sleep(1);
admin_page();
break;
}
else
{
if (strcmp(city, "NULL"))
{
puts("Choose a user to heal or to kill!\nEnter his/her national code first: ");
scanf("%ld", &national_code);
int a;
findUsernormal(3);
while ((a = national_code_check(national_code)) == 0 || strcmp("NULL", uni) == 0)
{
while (strcmp("NULL", uni))
{
puts("User not found!, try again...");
scanf("%ld", &national_code);
findUsernormal(3);
}
while (a)
{
printf("your national code must have 10 digits!, enter again : ");
scanf("%ld", &national_code);
a = national_code_check(national_code);
puts("");
}
}
puts("Now, do you wanna kill the guy or heal him/her??input (heal or kill)");
scanf("%s", email);
if (strcmp("heal", email) == 0 || strcmp("Heal", email) == 0)
create_statement("heal", "admin");
else if (strcmp("kill", email) == 0 || strcmp("Kill", email) == 0)
create_statement("kill", "admin");
puts("Successful!");
}
}
printf("Press a key to proceed");
getchar();
getchar();
sleep(2);
admin_page();
break;
case 4:
puts("List of normal users sorted by their names");
create_statement("see_all_normals", "admin");
puts("Press a key to proceed...");
getchar();
getchar();
sleep(1);
admin_page();
break;
case 5:
puts("Here's the list of all deaths :");
create_statement("see_deaths", "admin");
printf("\n\e[1;32mPress a key to proceed...\e[0m");
getchar();
getchar();
admin_page();
break;
case 6:
puts("\nList of shops sorted by store name\n");
create_statement("see_all_shops", "admin");
puts("Press a key to proceed...");
getchar();
getchar();
admin_page();
break;
case 7:
puts("List of hospitals ordered by their cities and then names : ");
create_statement("show_hospital", "admin");
puts("Press a key to proceed...");
getchar();
getchar();
sleep(1);
admin_page();
break;
case 8:
edit_info('a');
break;
case 9:
printf("\n\e[1mReturning to main menu...\e[0m");
sleep(1);
printf("\e[1;1H\e[02J");
getchar();
main_menu();
break;
case 0:
exit(0);
default:
printf("\nCommand not valid, enter again.");
sleep(1);
getchar();
admin_page();
break;
}
}
//normal_page
void normal_page()
{
if (normalUser.health_code < 4 && normalUser.health_code > 1)
{
time_t t = time(NULL);
if (abs(normalUser.test_time_history[normalUser.test_counter - 1] - t) > 604800)
{
normalUser.health_code -= 1;
snprintf(statement, sizeof(statement), "UPDATE normal_users SET cov_code = cov_code - 1 WHERE username = '%s';", normalUser.user_name);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
mysql_free_result(res);
}
}
int sth = normalUser.test_counter;
printf("\e[1;1H\e[2J");
printf("\t\t\t\t\t\t\t\t\e[1;32mHi %s %s, Welcome to your account\n\e[0m", normalUser.fname, normalUser.lname);
printf("\nHealth Status: ");
healthCode();
puts("\n");
puts("\e[1m\nEnter desired command(number only) to proceed.\e[0m");
puts("\e[34m1. Edit info");
puts("2. Give health test");
puts("3. See a history of your tests");
puts("4. Register a visit to other users");
puts("5. History of visits");
puts("6. Register a place you've recently been to");
puts("7. See history of visited locations");
puts("8. See covid-19 statistics");
puts("9. Find nearby hospitals");
puts("10. Corona Virus medical tips and suggestions");
puts("11. Logout");
puts("0. Exit the program\e[0m");
printf(">> ");
char choice[5];
scanf("%s", choice);
while (atoi(choice) < 0 || atoi(choice) > 11)
{
printf("\n Wrong choice, Enter again..\n");
printf(">> ");
scanf("%d", &choice);
}
if (!strcmp("1", choice))
edit_info('n');
else if (!strcmp("2", choice))
{
if (normalUser.health_code == 4)
{
puts("You \e[1mcannot\e[0m take the test because your code is \e[1;31m4\e[0m (so don't think of cheating :))");
puts("press a key to proceed...");
getchar();
getchar();
sleep(1);
}
else
{
time_t t = time(NULL);
health_test(&normalUser.test_score);
normalUser.test_score_history[normalUser.test_counter] = normalUser.test_score;
normalUser.test_time_history[normalUser.test_counter] = t;
if (normalUser.test_score <= 15)
normalUser.health_code = 1;
else if (normalUser.test_score > 15 && normalUser.test_score <= 50)
normalUser.health_code = 2;
else if (normalUser.test_score > 50 && normalUser.test_score <= 75)
normalUser.health_code = 3;
else if (normalUser.test_score > 75 && normalUser.test_score <= 100)
{
normalUser.health_code = 4;
snprintf(statement, sizeof(statement), "UPDATE normal_users SET sickness_time = %ld WHERE id = %d;", t, normalUser.id);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
mysql_free_result(res);
}
sleep(1);
printf("\e[1;1H\e[2J");
snprintf(statement, sizeof(statement), "INSERT INTO health_tests VALUES (%d, %d, %ld);", normalUser.id, normalUser.test_score, t);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
mysql_free_result(res);
normalUser.test_counter++;
snprintf(statement, sizeof(statement), "UPDATE normal_users SET test_counter = test_counter + 1, cov_code = %d WHERE id = %d;", normalUser.health_code, normalUser.id);
if (mysql_query(conn, statement))
finish_with_error(conn);
res = mysql_use_result(conn);
mysql_free_result(res);
}
normal_page();
}
else if (!strcmp("3", choice))
{
if (sth)
{
for (int i = 0; i < sth; i++)
if (i < 10)
printf("Test number %d\nTaken at %sresult: %d/100\n~~~~~~~~~~~~~~~~~~~~~\n", i + 1, asctime(localtime(&normalUser.test_time_history[i])), normalUser.test_score_history[i]);
else
break;
puts("Please enter a key to proceed ...");
getchar();
getchar();
normal_page();
}
else
{
printf("You have not taken the test yet!\n");
sleep(2);
normal_page();
}
}
else if (!strcmp("4", choice))
{
getchar();
printf("Enter his/her national code(10 digits)* : ");
scanf("%ld", &national_code);
int a;
findUsershop(3);
while ((a = national_code_check(national_code)) == 0 && strcmp("NULL", ushi) != 0)
{
while (strcmp("NULL", uni))
{
puts("User not found!, try again...");
scanf("%ld", &national_code);
puts("");
findUsershop(3);
}
while (!a)
{
printf("your national code must have 10 digits!, enter again : ");
scanf("%ld", &national_code);
puts("");
}
}
puts("");
create_statement("visit_person", "normal_users");
puts("\e[1;32mSuccessful\e[0mPress a key to proceed");
getchar();
getchar();
sleep(2);
normal_page();
}
else if (!strcmp("5", choice))
{
getchar();
time_t t = 1612282173;
puts("Here's a list of your visited users : \n");
printf(" Name | visited's code | date of visiting \n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("hossein hosseini | \e[31m4\e[0m | %s \n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", asctime(localtime(&t)));
//create_statement("see_visited_users", "normal_users");
printf("\npress a key to proceed...");
getchar();
getchar();
normal_page();
}
else if (!strcmp("6", choice))
{
getchar();
printf("Please enter store name : ");
scanf("%[^\n]s", hos_name);
findUsershop(4);
puts("");
while (!strcmp(ushi, "NULL"))
{
puts("Sorry, this store name doesn't exist");
printf("Enter store name again : ");
fgets(hos_name, 50, stdin);
findUsershop(4);
puts("");
}
//Store name is correct here
create_statement("visit_place", "normal_users");
puts("\e[1;32mSuccessful!\e[0m\nPress a key to proceed...");
getchar();
getchar();
normal_page();
}
else if (!strcmp("7", choice))
{
getchar();
puts("Here's a list of places you've visited : \n");
create_statement("see_visited_places", "normal_users");
puts("Press a key to proceed...");
getchar();
getchar();
normal_page();
}
else if (!strcmp("8", choice))
{
getchar();
puts("Here's a list of people infected in the last week : \n");
create_statement("see_sicks", "normal_users");
puts("Press a key to proceed...");
getchar();
getchar();
normal_page();
}
else if (!strcmp("9", choice))
{
getchar();
puts("List of hospitals around you : ");
create_statement("show_hospitals", "normal_users");
puts("Press a key to proceed...");
getchar();
getchar();
sleep(2);
normal_page();
}
else if (!strcmp("10", choice))
{
getchar();
medical_advices();
sleep(1);
normal_page();
}
else if (!strcmp("11", choice))
{
printf("\n\e[1mReturning to main menu...\e[0m");
sleep(1);
printf("\e[1;1H\e[02J");
getchar();
main_menu();
}
else if (!strcmp(choice, "0"))
exit(0);
else
{
printf("\nCommand not valid, enter again.");
sleep(1);
getchar();
normal_page();
}
}
//shop_page
void shop_page()
{
printf("\e[1;1H\e[2J");
printf("\t\t\t\t\t\t \e[1;32mHi %s %s, Welcome to your account\n\e[0m", shopUser.fname, shopUser.lname);
if (shopUser.disinfection == 0)
puts("\e[1mYour store status is\e[0m \e[31mRED\e[0m");
else
puts("\e[1mYour store status is\e[0m \e[32mWHITE\e[0m");
puts("\e[1mEnter desired command(number only) to proceed.(NA = not yet available)\e[0m");
puts("\e[34m1. Your stores status");
puts("2. Report disinfection");
puts("3. See the status of the users who've come to your store");
puts("4. See covid-19 advices");
puts("5. Logout");
puts("0. Exit the program\e[0m");
printf(">> ");
int choice;
scanf("%d", &choice);
while (choice < 0 || choice > 9)
{
printf("\n Wrong choice, Enter again..\n");
printf(">> ");
scanf("%d", &choice);
}
switch (choice)
{
case 1:
if (shopUser.disinfection == 1)
puts("\nYour store status is \e[1;32mWHITE\e[0m");
else
puts("\nYour store status is \e[1;31mRED\e[0m");
puts("Press a key to proceed...");
getchar();
getchar();
sleep(1);
shop_page();
break;
case 2:
shopUser.disinfection = 1;
shop_page();
break;
case 3:
puts("List of all your visitors : ");
create_statement("see_all_normals", "shop_users");
puts("Press a key to proceed...");
getchar();
getchar();
sleep(1);
shop_page();
break;
case 4:
getchar();
medical_advices();
getchar();
sleep(1);
shop_page();
break;
case 5:
printf("\n\e[1mReturning to main menu...\e[0m");
sleep(1);
printf("\e[1;1H\e[02J");
getchar();
main_menu();
break;
case 0:
exit(0);
default:
printf("\nCommand not valid, enter again.");
sleep(1);
getchar();
shop_page();
break;
}
}
void medical_advices()
{
printf("\e[1;1H\e[2J");
puts("\e[1mA. General Advices\e[0m");
puts("\n1. Wearing a mask is vital to protecting yourself and those around you from spreading the virus.");
puts("\n2. A mask should also help with another precaution: don’t touch your face. \nWhile it’s not the primary way the virus is spread, it’s still possible to pick up the virus off a surface and infect yourself by touching your mouth, nose or eyes. ");
puts("\n3. Also be sure to wash your hands regularly and thoroughly with soap, \nespecially after returning to your home from being out in public. \nIt’s important, too, to lather your hands with soap for at least 20 seconds to get them fully clean.");
puts("Finally, be sure to socially distance yourself from others, staying at least 6 feet away.\n Because of the distance that exhaled droplets can travel, you want to make sure you’re not too close to someone, \neven if they don’t show any symptoms. And, yes, that includes even when you’re wearing a mask. ");
puts("\n\e[1mB. Grocery shopping\e[0m");
puts("\n1. Limit the number of people from your household who make the trip. \nIt’s also helpful in keeping high-risk people home and away from that danger.");
puts("\n2. Choose a low-traffic time for trips to grocery store.");
puts("\n3. Get delivery or curbside pickup instead of going in person.");
puts("\nSource : \e[4;34mhttps://health.clevelandclinic.org/coronavirus-tips-prevention-and-safety-for-everyday-life/\e[0m");
puts("\n\e[1;31mThanks for reading, press a key to proceed");
getchar();
getchar();
}
//Sign_up section
void signup_menu()
{
printf("\e[1;1H\e[2J");