-
Notifications
You must be signed in to change notification settings - Fork 0
/
ministeroffinance.php
1016 lines (885 loc) · 32.9 KB
/
ministeroffinance.php
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
<?php
require 'navigationbar.php';
require 'db.php';
require 'regionborders.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/* Displays user information and some useful messages */
//session_start();
// Check if user is logged in using the session variable
if ( $_SESSION['logged_in'] != 1 ) {
$_SESSION['message'] = "You must log in before viewing your profile page!";
header("location: error.php");
}
else {
// Makes it easier to read
$username = $_SESSION['username'];
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email'];
$active = $_SESSION['active'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Fantasy-Sim</title>
<link rel="stylesheet" href="css/styletot.css">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#add8e6">
<meta name="msapplication-TileColor" content="#add8e6">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<div class="boxedtot">
<?php
require 'ageing.php';
$showmarketprep=$_GET["market"];
$showmarket=$mysqli->escape_string($showmarketprep);
$boycotcost=50;
$result = $mysqli->query("SELECT * FROM users WHERE username='$username'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$nationality=$row['nationality'];
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$finance=$row['finance'];
//$gold=$row['gold'];
//$vat=$row['vat'];
//$worktax=$row['worktax'];
$nodecisions=$row['nodecisions'];
$moneycreation=$row['moneycreation'];
$maxnodecisions=15;
$maxmoneycreation=1000;
$napcost=5;
$warcost=0;
if($finance==$username){
echo nl2br ("<div class=\"h1\">Minister of finance of $nationality</div>");
?> <hr /> <?php
echo nl2br("The max number of decisions to make is $maxnodecisions per term. $nodecisions already taken this term. \n");
echo nl2br("The max number of money to change is $maxmoneycreation per term. $moneycreation already used. \n");
//buttons for pages
?>
<div class="textbox">
<form method="post" action="">
<button type="submit" name="vatform" />Change vat</button>
<button type="submit" name="worktaxform" />Change worktax</button>
<button type="submit" name="changecurrencyform" />Create currency</button>
<button type="submit" name="buycurrencyform" />Buy currency</button>
<button type="submit" name="buyhospitalform" />Buy hospital</button>
<button type="submit" name="boycotform" />Ennact boycot</button>
<button type="submit" name="showboycotsform" />Show boycots</button>
<button type="submit" name="treasuryform" />Show treasury</button>
<button type="submit" name="transferform" />Transfer gold to other country</button>
</form>
</div>
<?php
?> <hr /> <?php
if($showmarket=="false"){
?> <div class="textbox"> <?php
//change vat
if(isset($_POST['vatform'])){
?>
<form method="post" action="">
<label for="changevat">New vat:</label>
<input type="number" size="25" required autocomplete="off" id="changevat" name="changevat" min="1" max="99" step="1" />
<button type="submit" name="vat" /><?php echo "Change vat"; ?></button>
</form>
<?php
}
if(isset($_POST['vat'])){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$finance=$row['finance'];
$nodecisions=$row['nodecisions'];
$changevat = $mysqli->escape_string($_POST['changevat']);
$changevat = (int) $changevat;
if($changevat > 100){
$changevat = 100;
}elseif($changevat < 0){
$changevat = 0;
}
if($nodecisions<$maxnodecisions){
$nodecisions=$nodecisions+1;
$sql = "UPDATE countryinfo SET nodecisions ='$nodecisions' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
$sql = "INSERT INTO congress (type, country, start, extraint) "
. "VALUES ('vat','$nationality',NOW(),'$changevat')";
mysqli_query($mysqli, $sql);
echo'<div class="boxed">Done!</div>';
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
}
echo nl2br(" \n");
//change worktax
if(isset($_POST['worktaxform'])){
?>
<form method="post" action="">
<label for="changeworktax">New worktax:</label>
<input type="number" size="25" required autocomplete="off" id="changeworktax" name="changeworktax" min="1" max="99" step="1" />
<button type="submit" name="worktax" /><?php echo "Change worktax"; ?></button>
</form>
<?php
}
if(isset($_POST['worktax'])){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$finance=$row['finance'];
$nodecisions=$row['nodecisions'];
$changeworktax = $mysqli->escape_string($_POST['changeworktax']);
$changeworktax = (int) $changeworktax;
if($changeworktax > 100){
$changeworktax = 100;
}elseif($changeworktax < 0){
$changeworktax = 0;
}
if($nodecisions<$maxnodecisions){
$nodecisions=$nodecisions+1;
$sql = "INSERT INTO congress (type, country, start, extraint) "
. "VALUES ('worktax','$nationality',NOW(),'$changeworktax')";
mysqli_query($mysqli, $sql);
$sql = "UPDATE countryinfo SET nodecisions ='$nodecisions' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
echo'<div class="boxed">Done!</div>';
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
}
?> </div> <?php
?> <div class="textbox"> <?php
//create or delete currency
if(isset($_POST['changecurrencyform'])){
?>
<form method="post" action="">
<select name="option" type="text">
<option value="create">create currency</option>
<option value="delete">delete currency</option>
</select>
<label for="currency">change in currency:</label>
<input type="number" size="25" required autocomplete="off" id="currency" name="currency" min="1" max="1000" step="1" />
<button type="submit" name="inflation" /><?php echo "Change currency"; ?></button>
</form>
<?php
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['inflation'])){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$finance=$row['finance'];
$nodecisions=$row['nodecisions'];
$money=$row['money'];
$moneycreation=$row['moneycreation'];
$option = $mysqli->escape_string($_POST['option']);
$currency = $mysqli->escape_string($_POST['currency']);
$currency = (int) $currency;
if($currency < 0){
$currency = 0;
}
$moneycreation=$moneycreation+$currency;
if($moneycreation<=$maxmoneycreation){
if($nodecisions<$maxnodecisions){
$sql = "INSERT INTO congress (type, country, start, extraint, extratext) "
. "VALUES ('inflation','$nationality',NOW(),'$currency', '$option')";
mysqli_query($mysqli, $sql);
echo'<div class="boxed">Done!</div>';
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}else{
echo'<div class="boxed">Not enough decisions!</div>';
}
}else{
echo'<div class="boxed">Limit of currency creation has been reached!</div>';
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
?> </div> <?php
?> <div class="textbox"> <?php
//currency market
echo nl2br(" \n");
if(isset($_POST['buycurrencyform'])){
?>
<form method="post" action="">
<?php
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$currency=$row['currency'];
?>
<label for="forcur">Currency to buy:</label>
<select required name="forcur" id="forcur" type="text">
<option value="<?php echo "$currency"; ?>"><?php echo "$currency"; ?></option>
<option value="gold">gold</option>
<label for="forcur">Currency to buy:</label>
<select required name="forcur" id="forcur" type="text">
<button type="submit" name="searchoffer" /><?php echo "Search offers"; ?></button>
</form>
<?php
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['searchoffer'])){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$currency=$row['currency'];
$forcur = $mysqli->escape_string($_POST['forcur']);
if($forcur == 'gold'){
$sellcur=$currency;
//echo "$sellcur";
}elseif($forcur == $currency){
$sellcur='gold';
//echo "$sellcur";
}
$result = $mysqli->query("SELECT id, offerid, sellamount, foramount FROM currencymarket WHERE sellcur='$forcur' AND forcur='$sellcur' ") or die($mysqli->error());
$count = $result->num_rows;
if($count!=0){
for ($set=array(); $row=$result->fetch_assoc(); $set[]=$row);
//print_r($set);
//sort data in descending salary/joboffer
foreach ($set as $key => $row)
{
$exchangerate[$key] = $row['sellamount'];
}
// Sort the data with wek ascending order, add $mar as the last parameter, to sort by the common key
array_multisort($exchangerate, SORT_ASC, $set);
//print_r($set);
echo nl2br(" \n");
//create forms for every item
foreach ($set as $key => $value) {
$id[$key] = $value['id'];
$offerid[$key] = $value['offerid'];
$sellamount[$key] = $value['sellamount'];
$foramount[$key] = $value['foramount'];
echo "Number of $forcur for sale: $sellamount[$key] | Exchange rate, cost $forcur per $sellcur: $foramount[$key] | Seller: $offerid[$key]";
?>
<form method="post" action="">
<input type="hidden" name="id" value="<?php echo "$id[$key]"; ?>" />
<input type="hidden" name="offerid" value="<?php echo "$offerid[$key]"; ?>" />
<input type="hidden" name="sellamount" value="<?php echo "$sellamount[$key]"; ?>" />
<input type="hidden" name="foramount" value="<?php echo "$foramount[$key]"; ?>" />
<input type="hidden" name="sellcur" value="<?php echo "$sellcur"; ?>" />
<input type="hidden" name="forcur" value="<?php echo "$forcur"; ?>" />
<label for="nobuyitems">Number of currency to buy:</label>
<input type="number" size="25" required autocomplete="off" id="nobuyitems" name="nobuyitems" min="0.01" step="0.01" />
<button type="submit" name="buy" value="<?php echo "$foramount[$key]"; ?>" /><?php echo "Buy"; ?></button>
</form>
<?php
echo nl2br(" \n");
}
}else{
echo'<div class="boxed">There are no offers on the market!</div>';
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['buy'])){
$id = $mysqli->escape_string($_POST['id']);
$id = (int) $id;
$nobuyitems = $mysqli->escape_string($_POST['nobuyitems']);
$nobuyitems = (double) $nobuyitems;
if($nobuyitems <= 0){
$nobuyitems = 1;
}
$result = $mysqli->query("SELECT * FROM currencymarket WHERE id='$id'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$sellcur=$row['sellcur'];
$forcur=$row['forcur'];
$offerid=$row['offerid'];
$sellamount=$row['sellamount'];
$foramount=$row['foramount'];
//echo "$foramount";
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
//money sold
$sellcur2=$sellcur;
if($sellcur=='gold'){
$sellcur='gold';
}else{
$sellcur='money';
}
$money=$row[$sellcur];
$money=$money+$nobuyitems;
//forcur=gold en sellcur=nec
//echo "$sellcur";
//echo "$money";
if($forcur=='gold'){
$forcur='gold';
}else{
$forcur='money';
}
$moneycreation=$row['moneycreation'];
$moneycreation=$moneycreation+$nobuyitems;
$sellamount=$sellamount-$nobuyitems;
//money bought
$money2=$row[$forcur];
//religeous tax
if($forcur=='gold'){
$result = $mysqli->query("SELECT statereligion FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$statereligion=$row['statereligion'];
if($statereligion != 'NULL'){
$result = $mysqli->query("SELECT religiontax, gold FROM religion WHERE name='$statereligion'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$reltax=$row['religiontax'];
$relgold=$row['gold'];
$reltax=$reltax/100;
$totaltax=$nobuyitems*$reltax;
$nobuyitems=$nobuyitems-$totaltax;
$relgold=$relgold+$totaltax;
$sql = "UPDATE religion SET gold ='$relgold' WHERE name='$statereligion'";
mysqli_query($mysqli, $sql);
}
}
$money2=$money2-$nobuyitems*$foramount;
//update sellamount
if($moneycreation<=$maxmoneycreation){
if($money>=0){
if($sellamount>=0){
//owner of offer money
$result = $mysqli->query("SELECT * FROM currency WHERE usercur='$offerid'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$moneyowner2=$row[$forcur];
$sql = "UPDATE countryinfo SET $sellcur ='$money', $forcur='$money2', moneycreation='$moneycreation' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
$result = $mysqli->query("SELECT * FROM currency WHERE usercur='$offerid'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$moneyowner=$row[$sellcur2];
$moneyowner=$moneyowner+$nobuyitems*$foramount;
//update money, moneyowner with forcur the same and updated sellcur
$sql = "UPDATE currency SET $sellcur ='$moneyowner', $forcur='$moneyowner2' WHERE usercur='$offerid'";
mysqli_query($mysqli, $sql);
echo "Currency transfer succesfull!";
//check if offer is sold out
if($sellamount>0){
$sql = "UPDATE currencymarket SET sellamount ='$sellamount' WHERE id='$id'";
mysqli_query($mysqli, $sql);
}elseif($sellamount==0){
$sql = "DELETE FROM currencymarket WHERE id='$id'";
mysqli_query($mysqli, $sql);
}
}else{
echo "There is not enough currency for sale!";
}
}else{
echo "You don't have enough money!";
}
}else{
echo "You already transferred the max amount of currency!";
}
}
?> </div> <?php
//buy hospital
?> <div class="textbox"> <?php
if(isset($_POST['buyhospitalform'])){
?>
<form method="post" action="">
<button type="submit" name="buyhospital" /><?php echo "Buy hospitals"; ?></button>
</form>
<?php
}
if(isset($_POST['buyhospital'])){
?>
<script>
var val = "true"
window.location = 'ministeroffinance.php?market='+val;
</script>
<?php
}
?> </div> <?php
?> <div class="textbox"> <?php
//boycot
if(isset($_POST['boycotform'])){
?>
<form method="post" action="">
<label for="diplomacy">Select country to boycot:</label>
<?php
$result = mysqli_query($mysqli,"SELECT country FROM countryinfo WHERE country != '$nationality'");
$columnValues = Array();
while ( $row = mysqli_fetch_assoc($result) ) {
$columnValues[] = $row['country'];
}
// Sort the data with wek ascending order, add $mar as the last parameter, to sort by the common key
asort($columnValues);
?>
<select required name="country2" id="country2" type="text">
<?php
// Iterating through the product array
foreach($columnValues as $item){
?>
<option value="<?php echo strtolower($item); ?>"><?php echo $item; ?></option>
<?php
}
?>
</select>
<button type="submit" name="boycot" /><?php echo "Submit"; ?></button>
</form>
<?php
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['boycot'])){
$country2 = $mysqli->escape_string($_POST['country2']);
$result2 = $mysqli->query("SELECT id FROM countryinfo WHERE country='$country2'") or die($mysqli->error());
$count = $result2->num_rows;
if($count != 0){
$result = $mysqli->query("SELECT country2 FROM diplomacy WHERE country1='$nationality' AND country2='$country2' AND type='boycot'") or die($mysqli->error());
if($result->num_rows > 0){
echo "You already have a boycot against this country!";
}else{
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$nodecisions=$row['nodecisions'];
$nodecisions=$nodecisions+1;
if($nodecisions<=$maxnodecisions){
$sql = "INSERT INTO congress (type, country, start, extratext) "
. "VALUES ('boycot','$nationality',NOW(), '$country2')";
mysqli_query($mysqli, $sql);
echo'<div class="boxed">Done!</div>';
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
$sql = "UPDATE countryinfo SET nodecisions='$nodecisions' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
$country2 = $mysqli->escape_string($_POST['country2']);
}else{
echo "The country doesn't have enough currency or decisions!";
}
}
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
//show boycots
echo nl2br(" \n");
if(isset($_POST['showboycotsform'])){
?>
<form method="post" action="">
<button type="submit" name="showboycot" /><?php echo "Show boycots"; ?></button>
</form>
<?php
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['showboycot'])){
$result = $mysqli->query("SELECT * FROM diplomacy WHERE type='boycot' AND country1='$nationality'") or die($mysqli->error());
for ($set=array(); $row=$result->fetch_assoc(); $set[]=$row);
//print_r($set);
echo nl2br(" \n");
//create forms for every item
foreach ($set as $key => $value) {
$country2[$key] = $value['country2'];
$id[$key]=$value['id'];
echo "boycot against $country2[$key]";
?>
<form method="post" action="">
<input type="hidden" name="country2" value="<?php echo "$country2[$key]"; ?>" />
<input type="hidden" name="id" value="<?php echo "$id[$key]"; ?>" />
<button type="submit" name="stop" value="<?php echo "1"; ?>" /><?php echo "End boycot"; ?></button>
</form>
<?php
echo nl2br(" \n");
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['stop'])){
$id = $mysqli->escape_string($_POST['id']);
$id = (int)$id;
$country2 = $mysqli->escape_string($_POST['country2']);
$result2 = $mysqli->query("SELECT id FROM diplomacy WHERE type='boycot' AND country1='$nationality' AND country2='$country2'") or die($mysqli->error());
$count = $result2->num_rows;
if($count != 0){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$nodecisions=$row['nodecisions'];
$nodecisions=$nodecisions+1;
if($nodecisions<=$maxnodecisions){
$sql = "INSERT INTO congress (type, country, start, extraint, extratext) "
. "VALUES ('stopboycot','$nationality',NOW(), '$id', '$country2')";
mysqli_query($mysqli, $sql);
echo'<div class="boxed">Done!</div>';
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
}
}
if(isset($_POST['treasuryform'])){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$treasurymoney=$row['treasurymoney'];
$treasurygold=$row['treasurygold'];
echo nl2br("Gold in treasury: $treasurygold \n");
echo nl2br("Money in treasury: $treasurymoney \n");
?>
<form method="post" action="">
<select name="type" type="text">
<option value="gold">Gold</option>
<option value="currency">Currency</option>
</select>
<input type="number" size="25" required autocomplete="off" id="amount" placeholder="Amount" name="amount" min="1" step="0.01" />
<button type="submit" name="addtreasury" /><?php echo "Add to treasury"; ?></button>
<button type="submit" name="retracttreasury" /><?php echo "Retract from treasury"; ?></button>
</form>
<?php
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['addtreasury'])){
$type = $mysqli->escape_string($_POST['type']);
$amount = $mysqli->escape_string($_POST['amount']);
$amount = (double) $amount;
if($amount <= 0){
$amount=1;
}
if($type=="gold" || $type=="currency"){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$gold=$row['gold'];
$money=$row['money'];
$treasurymoney=$row['treasurymoney'];
$treasurygold=$row['treasurygold'];
$nodecisions=$row['nodecisions'];
$nodecisions=$nodecisions+1;
if($nodecisions<=$maxnodecisions){
$positive=0;
if($type=="gold"){
$gold=$gold-$amount;
if($gold>=0){
$positive=1;
}
}elseif($type=="currency"){
$money=$money-$amount;
if($money>=0){
$positive=1;
}
}
if($positive==1){
$sql = "INSERT INTO congress (type, country, start, extraint, extratext) "
. "VALUES ('addtreasury','$nationality',NOW(),'$amount', '$type')";
mysqli_query($mysqli, $sql);
$sql = "UPDATE countryinfo SET nodecisions ='$nodecisions' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
echo "Done!";
}else{
echo "Not enough money/gold!";
}
}
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['retracttreasury'])){
$type = $mysqli->escape_string($_POST['type']);
$amount = $mysqli->escape_string($_POST['amount']);
$amount = (double) $amount;
if($amount <= 0){
$amount=1;
}
if($type=="gold" || $type=="currency"){
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$gold=$row['gold'];
$money=$row['money'];
$treasurymoney=$row['treasurymoney'];
$treasurygold=$row['treasurygold'];
$nodecisions=$row['nodecisions'];
$nodecisions=$nodecisions+1;
if($nodecisions<=$maxnodecisions){
$positive=0;
if($type=="gold"){
$treasurygold=$treasurygold-$amount;
if($treasurygold>=0){
$positive=1;
}
}elseif($type=="currency"){
$treasurymoney=$treasurymoney-$amount;
if($treasurymoney>=0){
$positive=1;
}
}
if($positive==1){
$sql = "INSERT INTO congress (type, country, start, extraint, extratext) "
. "VALUES ('retracttreasury','$nationality',NOW(),'$amount', '$type')";
mysqli_query($mysqli, $sql);
$sql = "UPDATE countryinfo SET nodecisions ='$nodecisions' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
echo "Done!";
}else{
echo "Not enough money/gold!";
}
}
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
//transfer money to other country
if(isset($_POST['transferform'])){
?>
<form method="post" action="">
<label for="countryselect">Select country:</label>
<?php
$result = mysqli_query($mysqli,"SELECT country FROM countryinfo WHERE country != '$nationality'");
$columnValues = Array();
while ( $row = mysqli_fetch_assoc($result) ) {
$columnValues[] = $row['country'];
}
// Sort the data with wek ascending order, add $mar as the last parameter, to sort by the common key
asort($columnValues);
?>
<select required name="countryselect" type="text">
<?php
// Iterating through the product array
foreach($columnValues as $item){
?>
<option value="<?php echo strtolower($item); ?>"><?php echo $item; ?></option>
<?php
}
?>
</select>
<input type="number" size="25" required autocomplete="off" id="nogold" name="nogold" min="1" step="0.01" />
<button type="submit" name="transfergold" />Transfer gold</button>
</form>
<?php
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
if(isset($_POST['transfergold'])){
$country = $mysqli->escape_string($_POST['countryselect']);
$nogold = $mysqli->escape_string($_POST['nogold']);
$nogold = (double) $nogold;
if($nogold <= 0){
$nogold = 1;
}
$result2 = $mysqli->query("SELECT id FROM countryinfo WHERE country='$country'") or die($mysqli->error());
$count = $result2->num_rows;
if($count != 0){
$result = $mysqli->query("SELECT nodecisions FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$nodecisions=$row['nodecisions'];
$nodecisions=$nodecisions+1;
if($nodecisions<=$maxnodecisions){
$sql = "UPDATE countryinfo SET nodecisions='$nodecisions' WHERE country='$nationality'";
mysqli_query($mysqli, $sql);
$sql = "INSERT INTO congress (type, country, start, extraint, extratext) "
. "VALUES ('transfergold','$nationality',NOW(), '$nogold', '$country')";
mysqli_query($mysqli, $sql);
echo "Done!";
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
}
}
}
?> </div> <?php
}elseif($showmarket=="true"){
$result = $mysqli->query("SELECT id, country, amount, price, owner FROM marketplace WHERE type='hospital' AND country='$nationality'") or die($mysqli->error());
$count = $result->num_rows;
if($count!=0){
for ($set=array(); $row=$result->fetch_assoc(); $set[]=$row);
//print_r($set);
//sort data in descending salary/joboffer
foreach ($set as $key => $row){
$pricesort[$key] = $row['price'];
}
// Sort the data with wek ascending order, add $mar as the last parameter, to sort by the common key
array_multisort($pricesort, SORT_ASC, $set);
//print_r($set);
echo nl2br(" \n");
foreach ($set as $key => $row){
?> <div class="listbox"> <?php
$id[$key] = $row['id'];
$country[$key] = $row['country'];
$amount[$key] = $row['amount'];
$price[$key] = $row['price'];
$owner[$key] = $row['owner'];
$type="hospital";
echo "Number of hospitals for sale: $amount[$key] | Price: $price[$key] | Owner: $owner[$key]";
?>
<form method="post" action="">
<input type="hidden" name="id" value="<?php echo "$id[$key]"; ?>" />
<input type="hidden" name="amount" value="<?php echo "$amount[$key]"; ?>" />
<input type="hidden" name="type" value="<?php echo "$type[$key]"; ?>" />
<input type="hidden" name="country" value="<?php echo "$country[$key]"; ?>" />
<input type="hidden" name="price" value="<?php echo "$price[$key]"; ?>" />
<input type="hidden" name="owner" value="<?php echo "$owner[$key]"; ?>" />
<input type="hidden" name="type" value="<?php echo "$type"; ?>" />
<label for="nobuyitems">Number to buy:</label>
<input type="number" size="25" required autocomplete="off" id="nobuyitems" name="nobuyitems" min="0.01" step="0.01" />
<button type="submit" name="buyhospital" />Buy</button>
</form>
<?php
echo nl2br(" \n");
?> </div> <?php
}
}else{
echo'<div class="boxed">There are no offers on the market!</div>';
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<?php
if(isset($_POST['buyhospital'])){
$id = $mysqli->escape_string($_POST['id']);
$nobuyitems = $mysqli->escape_string($_POST['nobuyitems']);
$nobuyitems = (int) $nobuyitems;
if($nobuyitems <=0){
$nobuyitems = 1;
}
$country = $nationality;
$result = $mysqli->query("SELECT * FROM marketplace WHERE id='$id' AND country='$country' AND type='hospital'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$type = $row['type'];
$owner = $row['owner'];
$price = $row['price'];
$amount = $row['amount'];
$result = $mysqli->query("SELECT * FROM countryinfo WHERE country='$nationality'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$cur = $row['currency'];
$vat = $row['vat'];
$countrymoney = $row['money'];
$hospital = $row['hospital'];
$price=$price*$nobuyitems;
$moneyafter=$countrymoney-$price;
if($moneyafter>=0){
$itemafter=$amount-$nobuyitems;
if($itemafter>=0){
//update buyer and country
$hospital=$hospital+$nobuyitems;
$tax=$price*($vat/100);
$moneyafter=$moneyafter+$tax;
$sql = "UPDATE countryinfo SET money ='$moneyafter', hospital ='$hospital' WHERE country='$location'";
mysqli_query($mysqli, $sql);
//update owner
$result = $mysqli->query("SELECT * FROM currency WHERE usercur='$owner'") or die($mysqli->error());
$row = mysqli_fetch_array($result);
$moneyowner = $row[$cur];
$moneyowner=$moneyowner+$price-$tax;
$sql = "UPDATE currency SET $cur ='$moneyowner' WHERE usercur='$owner'";
mysqli_query($mysqli, $sql);
echo "Added $nobuyitems $type to your inventory!";
if($itemafter>0){
$sql = "UPDATE marketplace SET amount ='$itemafter' WHERE id='$id'";
mysqli_query($mysqli, $sql);
}else{
$sql = "DELETE FROM marketplace WHERE id='$id'";
mysqli_query($mysqli, $sql);
}
}else{
echo "Not enough $type for sale!";
}
}else{
echo "You don't have enough money";
}
?>
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}