-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
1107 lines (1070 loc) · 29.8 KB
/
Copy pathclient.c
File metadata and controls
1107 lines (1070 loc) · 29.8 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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<errno.h>
int adminSession = 0;
struct adminLogin
{
char id[100];
char pass[100];
};
struct empLogin
{
char id[100];
char pass[100];
};
struct empRecord
{
char id[100];
char name[100];
int age;
char email[100];
char address[100];
char phone[100];
char role[100];
char pass[100];
int session;
};
struct custRecord
{
char id[100];
char name[100];
int age;
char email[100];
char address[100];
char phone[100];
char pass[100];
int session;
};
struct transactionRecord
{
char id[100];
char timestamp[100];
char type[100];
char aid[100];
char cid[100];
int amount;
};
struct accRecord
{
char id[100];
char cid[100];
int balance;
char status[100];
};
struct feedbackRecord
{
char id[100];
char cid[100];
char feedback[800];
};
struct modifyEmp
{
int choice;
char id[100];
int age;
char field[100];
};
struct modifyCust
{
int choice;
char id[100];
int age;
char field[100];
};
struct updateRole
{
char id[100];
char role[100];
};
struct updatePassEmp
{
char id[100];
char pass[100];
};
struct loanApp
{
char id[100];
char aid[100];
int amount;
char eid[100];
char status[100];
};
void showLoginType(int);
void shutdownSystem(int);
void adminLogout(int);
void adminAddEmployee(int);
void adminModifyCustomer(int);
void adminModifyEmployee(int);
void adminManageRoles(int);
void adminChangePasswordEmp(int);
void adminChangePasswordCust(int);
void empLogout(int, int);
void empAddCustomer(int);
void empChangePassword(int);
void empModifyCustomerDetails(int);
void empViewAssignedLoanApps(int);
void empProcessAssignedLoanApp(int);
void custLogout(int, int);
void custAddAccount(int);
void custViewBalance(int);
void custDeposit(int);
void custWithdraw(int);
void custTransfer(int);
void custTransactionHistory(int);
void custChangePassword(int);
void custFeedback(int);
void custApplyLoan(int);
void managerChangePassword(int);
void managerReviewFeedback(int);
void managerActivateAcc(int);
void managerDeactivateAcc(int);
void managerAssignLoanApp(int);
void adminMenu(int sock)
{
while(1)
{
printf("Choose your action : \n");
printf("1. Add new Bank Employee\n2. Modify Customer Details\n3. Modify Employee Details\n4. Manage Roles\n5. Change Password of Employee\n6. Change Password of Customer\n7. Logout\n8. Exit\n");
printf("Enter your choice : ");
int choice;
scanf("%d", &choice);
printf("\n");
switch(choice)
{
case 1:adminAddEmployee(sock);
break;
case 2:adminModifyCustomer(sock);
break;
case 3:adminModifyEmployee(sock);
break;
case 4:adminManageRoles(sock);
break;
case 5:adminChangePasswordEmp(sock);
break;
case 6:adminChangePasswordCust(sock);
break;
case 7:adminLogout(sock);
break;
case 8:shutdownSystem(sock);
break;
default: printf("Invalid Choice\n");
}
}
}
void empMenu(int sock)
{
while(1)
{
printf("Choose your action : \n");
printf("1. Add new Customer\n2. Modify Customer Details\n3. View Assigned Loan Applications\n4. Process Assigned Loan Applications\n5. Change Password\n6. Logout\n7. Exit\n");
printf("Enter your choice : ");
int choice;
scanf("%d", &choice);
printf("\n");
switch(choice)
{
case 1:empAddCustomer(sock);
break;
case 2:empModifyCustomerDetails(sock);
break;
case 3:empViewAssignedLoanApps(sock);
break;
case 4:empProcessAssignedLoanApp(sock);
break;
case 5:empChangePassword(sock);
break;
case 6:empLogout(sock, 0);
break;
case 7:empLogout(sock, 1);
shutdownSystem(sock);
break;
default: printf("Invalid Choice\n");
}
}
}
void custMenu(int sock)
{
while(1)
{
printf("Choose your action : \n");
printf("1. Open New Account\n2. View Account Balance\n3. Deposit Money\n4. Withdraw Money\n5. Transfer Money\n6. Apply for a Loan\n7. Change Password\n8. Add Feedback\n9. View Transaction History\n10. Logout\n11. Exit\n");
printf("Enter your choice : ");
int choice;
scanf("%d", &choice);
printf("\n");
switch(choice)
{
case 1:custAddAccount(sock);
break;
case 2:custViewBalance(sock);
break;
case 3:custDeposit(sock);
break;
case 4:custWithdraw(sock);
break;
case 5:custTransfer(sock);
break;
case 6:custApplyLoan(sock);
break;
case 7:custChangePassword(sock);
break;
case 8:custFeedback(sock);
break;
case 9:custTransactionHistory(sock);
break;
case 10:custLogout(sock, 0);
break;
case 11:custLogout(sock, 1);
shutdownSystem(sock);
break;
default: printf("Invalid Choice\n");
}
}
}
void managerMenu(int sock)
{
while(1)
{
printf("Choose your action : \n");
printf("1. Activate Customer Accounts\n2. Deactivate Customer Accounts\n3. Assign Loan Application to Employee\n4. Review Customer Feedback\n5. Change Password\n6. Logout\n7. Exit\n");
printf("Enter your choice : ");
int choice;
scanf("%d", &choice);
printf("\n");
switch(choice)
{
case 1:managerActivateAcc(sock);
break;
case 2:managerDeactivateAcc(sock);
break;
case 3:managerAssignLoanApp(sock);
break;
case 4:managerReviewFeedback(sock);
break;
case 5:managerChangePassword(sock);
break;
case 6:empLogout(sock, 0);
break;
case 7:empLogout(sock, 1);
shutdownSystem(sock);
break;
default: printf("Invalid Choice\n");
}
}
}
void adminAddEmployee(int sock)
{
struct empRecord newemp;
printf("\nEnter Employee Name : ");
scanf(" %[^\n]s", newemp.name);
printf("\nEnter Employee Age : ");
scanf("%d", &newemp.age);
printf("\nEnter Employee Email : ");
scanf(" %[^\n]s", newemp.email);
printf("\nEnter Employee Address : ");
scanf(" %[^\n]s", newemp.address);
printf("\nEnter Employee Phone : ");
scanf(" %[^\n]s", newemp.phone);
printf("\nEnter Employee Password : ");
scanf(" %[^\n]s", newemp.pass);
strcpy(newemp.role, "Employee");
newemp.session = 0;
printf("\n");
int request_type = 101;
write(sock, &request_type, sizeof(request_type));
write(sock, &newemp, sizeof(newemp));
int result;
read(sock, &result, sizeof(result));
if(result == -1)
{
printf("Employee addition has failed\n\n");
}
else
{
printf("Employee addition was successful\n\n");
}
}
void adminModifyCustomer(int sock)
{
struct modifyCust newData;
printf("Enter Customer ID whose details are to be changed : ");
scanf(" %s", newData.id);
printf("\n");
printf("Choose detail you want to change\n");
printf("1. Name\n2. Age\n3. Email\n4. Address\n5. Phone\n");
printf("Enter choice : ");
scanf("%d", &newData.choice);
printf("\n");
int request_type = 102;
write(sock, &request_type, sizeof(request_type));
switch(newData.choice)
{
case 1:printf("Enter Name : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 2:printf("Enter Age : ");
scanf("%d", &newData.age);
printf("\n");
break;
case 3:printf("Enter Email : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 4: printf("Enter Address : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 5:printf("Enter Phone : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
default: printf("Invalid Choice\n");
return;
}
write(sock, &newData, sizeof(newData));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Customer Detail Modification successful\n");
}
else
{
printf("Customer Detail Modification failed\n");
}
}
void adminModifyEmployee(int sock)
{
struct modifyEmp newData;
printf("Enter Employee ID whose details are to be changed : ");
scanf(" %s", newData.id);
printf("\n");
printf("Choose detail you want to change\n");
printf("1. Name\n2. Age\n3. Email\n4. Address\n5. Phone\n");
printf("Enter choice : ");
scanf("%d", &newData.choice);
printf("\n");
int request_type = 103;
write(sock, &request_type, sizeof(request_type));
switch(newData.choice)
{
case 1:printf("Enter Name : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 2:printf("Enter Age : ");
scanf("%d", &newData.age);
printf("\n");
break;
case 3:printf("Enter Email : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 4: printf("Enter Address : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 5:printf("Enter Phone : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
default: printf("Invalid Choice\n");
return;
}
write(sock, &newData, sizeof(newData));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Employee Detail Modification successful\n");
}
else
{
printf("Employee Detail Modification failed\n");
}
}
void adminManageRoles(int sock)
{
struct updateRole new;
printf("Enter the employee id whose role is to be changed : ");
scanf(" %s", new.id);
printf("\n");
printf("Enter the new role : ");
scanf(" %s", new.role);
int request_type = 104;
write(sock, &request_type, sizeof(request_type));
write(sock, &new, sizeof(new));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Employee role has been successfully updated\n");
}
else
{
printf("Employee role updation failed\n");
}
}
void adminChangePasswordEmp(int sock)
{
struct updatePassEmp new;
printf("Enter the employee id whose password is to be changed : ");
scanf(" %s", new.id);
printf("\n");
printf("Enter the new password : ");
scanf(" %s", new.pass);
int request_type = 105;
write(sock, &request_type, sizeof(request_type));
write(sock, &new, sizeof(new));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Employee password has been successfully updated\n");
}
else
{
printf("Employee password updation failed\n");
}
}
void adminChangePasswordCust(int sock)
{
struct updatePassEmp new;
printf("Enter the customer id whose password is to be changed : ");
scanf(" %s", new.id);
printf("\n");
printf("Enter the new password : ");
scanf(" %s", new.pass);
int request_type = 106;
write(sock, &request_type, sizeof(request_type));
write(sock, &new, sizeof(new));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Customer password has been successfully updated\n");
}
else
{
printf("Customer password updation failed\n");
}
}
void empAddCustomer(int sock)
{
struct custRecord newcust;
printf("\nEnter Customer Name : ");
scanf(" %[^\n]s", newcust.name);
printf("\nEnter Customer Age : ");
scanf("%d", &newcust.age);
printf("\nEnter Customer Email : ");
scanf(" %[^\n]s", newcust.email);
printf("\nEnter Customer Address : ");
scanf(" %[^\n]s", newcust.address);
printf("\nEnter Customer Phone : ");
scanf(" %[^\n]s", newcust.phone);
printf("\nEnter Customer Password : ");
scanf(" %[^\n]s", newcust.pass);
newcust.session = 0;
printf("\n");
int request_type = 201;
write(sock, &request_type, sizeof(request_type));
write(sock, &newcust, sizeof(newcust));
int result;
read(sock, &result, sizeof(result));
if(result == -1)
{
printf("Customer addition has failed\n\n");
}
else
{
printf("Customer addition was successful\n\n");
}
}
void empModifyCustomerDetails(int sock)
{
struct modifyCust newData;
printf("Enter Customer ID whose details are to be changed : ");
scanf(" %s", newData.id);
printf("\n");
printf("Choose detail you want to change\n");
printf("1. Name\n2. Age\n3. Email\n4. Address\n5. Phone\n");
printf("Enter choice : ");
scanf("%d", &newData.choice);
printf("\n");
int request_type = 202;
write(sock, &request_type, sizeof(request_type));
switch(newData.choice)
{
case 1:printf("Enter Name : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 2:printf("Enter Age : ");
scanf("%d", &newData.age);
printf("\n");
break;
case 3:printf("Enter Email : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 4: printf("Enter Address : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
case 5:printf("Enter Phone : ");
scanf(" %[^\n]s", newData.field);
printf("\n");
break;
default: printf("Invalid Choice\n");
return;
}
write(sock, &newData, sizeof(newData));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Customer Detail Modification successful\n");
}
else
{
printf("Customer Detail Modification failed\n");
}
}
void empViewAssignedLoanApps(int sock)
{
int request_type = 203;
struct loanApp arr[50];
char limit[100];
write(sock, &request_type, sizeof(request_type));
char eid[100];
printf("Enter your employee id: ");
scanf(" %s", eid);
write(sock, eid, sizeof(eid));
read(sock, &limit, sizeof(limit));
int lim;
sscanf(limit, "%d", &lim);
read(sock, &arr, sizeof(arr));
int i;
for(i=0;i<lim;i++)
{
//char datastring[600];
//sprintf(datastring,"%s\t%s\t%s\t%s\t%s\t%d", arr[i].id, arr[i].timestamp, arr[i].type, arr[i].aid, arr[i].cid, arr[i].amount);
printf("%s\t%s\t%d\t%s\t%s", arr[i].id, arr[i].aid, arr[i].amount, arr[i].eid, arr[i].status);
//printf("%s\n", datastring);
}
printf("\n");
}
void empProcessAssignedLoanApp(int sock)
{
int request_type = 204;
write(sock, &request_type, sizeof(request_type));
char lid[100];
printf("Enter Loan App ID : ");
scanf(" %s", lid);
write(sock, &lid, sizeof(lid));
char result[100];
read(sock, &result, sizeof(result));
if(strcmp(result, "0") == 0)
{
printf("Loan ID : %s has been approved\n", lid);
}
else
{
printf("Loan ID : %s has been rejected\n", lid);
}
}
void empChangePassword(int sock)
{
struct updatePassEmp new;
printf("Enter your employee id : ");
scanf(" %s", new.id);
printf("\n");
printf("Enter the new password : ");
scanf(" %s", new.pass);
int request_type = 206;
write(sock, &request_type, sizeof(request_type));
write(sock, &new, sizeof(new));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Your password has been successfully updated\n");
}
else
{
printf("Your password updation failed\n");
}
}
void custAddAccount(int sock)
{
struct accRecord data;
int request_type = 301;
data.balance = 10000;
write(sock, &request_type, sizeof(request_type));
write(sock, &data, sizeof(data));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Account has been successfully created\n");
char aid[100];
read(sock, aid, sizeof(aid));
printf("Account ID : %s\n", aid);
}
else
{
printf("Account creation failed\n");
}
}
void custViewBalance(int sock)
{
int request_type = 302;
char aid[100];
printf("Enter A/C Id : ");
scanf("%s",aid);
printf("\n");
write(sock, &request_type, sizeof(request_type));
write(sock, aid, sizeof(aid));
char balance[100];
read(sock, balance, sizeof(balance));
int bal;
sscanf(balance, "%d", &bal);
if(bal == -1)
printf("Account not found in your accounts\n");
else
printf("Your Account Balance : %d\n",bal);
}
void custDeposit(int sock)
{
int request_type = 303;
char aid[100];
printf("Enter A/C Id : ");
scanf(" %s", aid);
char amt[100];
printf("Enter Amount : ");
scanf(" %s", amt);
write(sock, &request_type, sizeof(request_type));
write(sock, aid, sizeof(aid));
write(sock, amt, sizeof(amt));
char result[100];
int res;
read(sock, &result, sizeof(result));
scanf(result, "%d", &res);
if(res == -1)
printf("Deposit failed\n");
else
printf("Deposit successful\n");
}
void custWithdraw(int sock)
{
int request_type = 304;
char aid[100];
printf("Enter A/C Id : ");
scanf(" %s", aid);
char amt[100];
printf("Enter Amount : ");
scanf(" %s", amt);
write(sock, &request_type, sizeof(request_type));
write(sock, aid, sizeof(aid));
write(sock, amt, sizeof(amt));
char result[100];
read(sock, &result, sizeof(result));
if(strcmp(result, "-1") == 0)
printf("Withdrawal failed due to account not being a valid account of yours\n");
else
printf("Withdrawal successful\n");
}
void custTransfer(int sock)
{
int request_type = 305;
char cid[100];
printf("Enter your Customer ID : ");
scanf(" %s", cid);
char aid1[100];
printf("Enter A/C Id 1: ");
scanf(" %s", aid1);
char aid2[100];
printf("Enter A/C Id 2 : ");
scanf(" %s", aid2);
char amt[100];
printf("Enter Amount : ");
scanf(" %s", amt);
write(sock, &request_type, sizeof(request_type));
write(sock, cid, sizeof(cid));
write(sock, aid1, sizeof(aid1));
write(sock, aid2, sizeof(aid2));
write(sock, amt, sizeof(amt));
char result[100];
read(sock, &result, sizeof(result));
if(strcmp(result, "-1") == 0)
printf("Transfer failed due to account not being a valid account of yours or not enough funds\n");
else
printf("Transfer successful\n");
}
void custTransactionHistory(int sock)
{
int request_type = 309;
struct transactionRecord arr[100];
char limit[100];
printf("Enter your customer id for authentication : ");
char cid[100];
scanf(" %s", cid);
write(sock, &request_type, sizeof(request_type));
write(sock, &cid, sizeof(cid));
//memset(limit, '\0', sizeof(limit));
read(sock, &limit, sizeof(limit));
//perror("Error");
//limit[100]='\0';
int lim;
sscanf(limit, "%d", &lim);
read(sock, &arr, sizeof(arr));
//printf("ID = %d\n", lim);
int i;
for(i=0;i<lim;i++)
{
//char datastring[600];
//sprintf(datastring,"%s\t%s\t%s\t%s\t%s\t%d", arr[i].id, arr[i].timestamp, arr[i].type, arr[i].aid, arr[i].cid, arr[i].amount);
printf("%s\t%s\t%s\t%s\t%s\t%d\n", arr[i].id, arr[i].timestamp, arr[i].type, arr[i].aid, arr[i].cid, arr[i].amount);
//printf("%s\n", datastring);
}
printf("\n");
}
void custChangePassword(int sock)
{
struct updatePassEmp new;
printf("Enter your employee id : ");
scanf(" %s", new.id);
printf("\n");
printf("Enter the new password : ");
scanf(" %s", new.pass);
int request_type = 307;
write(sock, &request_type, sizeof(request_type));
write(sock, &new, sizeof(new));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Your password has been successfully updated\n");
}
else
{
printf("Your password updation failed\n");
}
}
void custFeedback(int sock)
{
char feedback[800];
printf("Enter your feedback (Max 800 chars.) : \n");
scanf(" %[^\n]s", feedback);
int request_type = 308;
write(sock, &request_type, sizeof(request_type));
write(sock, feedback, sizeof(feedback));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Your feedback has been successfully recorded\n");
}
else
{
printf("Some error occurred while recording your feedback\n");
}
}
void custApplyLoan(int sock)
{
int request_type = 306;
struct loanApp data;
printf("Enter loan amount : ");
scanf("%d", &data.amount);
printf("Enter account id to take loan against : ");
scanf("%s", data.aid);
write(sock, &request_type, sizeof(request_type));
write(sock, &data, sizeof(data));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Loan successfully applied\n");
}
else
{
printf("Some error occurred while applying for your loan\n");
}
}
void customerLogin(int sock)
{
int request_type = 300;
struct empLogin data;
printf("Enter User ID : ");
scanf(" %s", data.id);
printf("\n");
printf("Enter Password : ");
scanf(" %s", data.pass);
write(sock, &request_type, sizeof(request_type));
write(sock, &data, sizeof(data));
int result;
read(sock, &result, sizeof(result));
if(result == 0)
{
printf("Invalid customer login credentials\n\n");
}
else
{
printf("Successfully logged in as Customer\n\n");
custMenu(sock);
}
}
void employeeLogin(int sock)
{
int request_type = 200;
struct empLogin data;
printf("Enter User ID : ");
scanf(" %s", data.id);
printf("\n");
printf("Enter Password : ");
scanf(" %s", data.pass);
write(sock, &request_type, sizeof(request_type));
write(sock, &data, sizeof(data));
int result;
read(sock, &result, sizeof(result));
if(result == 0)
{
printf("Invalid employee login credentials\n\n");
}
else
{
printf("Successfully logged in as Employee\n\n");
empMenu(sock);
}
}
void managerLogin(int sock)
{
int request_type = 400;
struct empLogin data;
printf("Enter User ID : ");
scanf(" %s", data.id);
printf("\n");
printf("Enter Password : ");
scanf(" %s", data.pass);
write(sock, &request_type, sizeof(request_type));
write(sock, &data, sizeof(data));
int result;
read(sock, &result, sizeof(result));
if(result == 0)
{
printf("Invalid manager login credentials\n\n");
}
else
{
printf("Successfully logged in as manager\n\n");
managerMenu(sock);
}
}
void managerChangePassword(int sock)
{
struct updatePassEmp new;
printf("Enter your employee id : ");
scanf(" %s", new.id);
printf("\n");
printf("Enter the new password : ");
scanf(" %s", new.pass);
int request_type = 405;
write(sock, &request_type, sizeof(request_type));
write(sock, &new, sizeof(new));
int result;
read(sock, &result, sizeof(result));
if(result != -1)
{
printf("Your password has been successfully updated\n");
}
else
{
printf("Your password updation failed\n");
}
}
void managerReviewFeedback(int sock)
{
int request_type = 404;
struct feedbackRecord arr[50];
char limit[100];
write(sock, &request_type, sizeof(request_type));
read(sock, &limit, sizeof(limit));
int lim;
sscanf(limit, "%d", &lim);
read(sock, &arr, sizeof(arr));
int i;
for(i=0;i<lim;i++)
{
//char datastring[600];
//sprintf(datastring,"%s\t%s\t%s\t%s\t%s\t%d", arr[i].id, arr[i].timestamp, arr[i].type, arr[i].aid, arr[i].cid, arr[i].amount);
printf("%s\t%s\t%s\n", arr[i].id, arr[i].cid, arr[i].feedback);
//printf("%s\n", datastring);
}
printf("\n");
}
void managerActivateAcc(int sock)
{
int request_type = 401;
printf("Enter Acc ID : ");
char aid[100];
scanf(" %s", aid);
printf("\n");
write(sock, &request_type, sizeof(request_type));
write(sock, &aid, sizeof(aid));
char result[100];
read(sock, result, sizeof(result));
if(strlen(result) != 0)
{
printf("Error activating account\n\n");
}
else
{
printf("Successfully activated account\n\n");
}
}
void managerDeactivateAcc(int sock)
{
int request_type = 402;
printf("Enter Acc ID : ");
char aid[100];
scanf(" %s", aid);
printf("\n");
write(sock, &request_type, sizeof(request_type));
write(sock, &aid, sizeof(aid));
int result;
read(sock, &result, sizeof(result));
if(result == 0)
{
printf("Error deactivating account\n\n");
}
else
{
printf("Successfully deactivated account\n\n");
}
}
void managerAssignLoanApp(int sock)
{
int request_type = 403;
printf("Enter Loan App ID : ");
char lid[100];
scanf(" %s", lid);
printf("\n");
printf("Enter employedd id to assign to : ");
char eid[100];
scanf(" %s", eid);
printf("\n");
write(sock, &request_type, sizeof(request_type));
write(sock, &lid, sizeof(lid));
write(sock, &eid, sizeof(eid));
char result[100];
read(sock, &result, sizeof(result));