forked from tejapaturu/simple-website-php-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.php
More file actions
149 lines (120 loc) · 4.43 KB
/
tools.php
File metadata and controls
149 lines (120 loc) · 4.43 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
</br>
<!-- Debug info -->
<aside id='debug'>
<details open>
<summary>=Debug Show/Hide</summary>
<?php
foreach ($_POST as $key => $value)
{
${$key} = $value;
$_SESSION[$key] = $value;
}
?>
<pre>
$_SESSION contains:
<?php print_r($_SESSION); ?>
$_POST contains:
<?php print_r($_POST); ?> </pre>
</details>
</aside>
<script>
// Chnages aid value
function changeAID(AID)
{
let currentClass = document.getElementById(AID).getAttribute("class");
let currentFormAidValue = document.getElementById("form-aid").value;
if(currentClass=="site-button-unselected" && currentFormAidValue=="")
{
document.getElementById(AID).setAttribute("class", "site-button-selected");
document.getElementById("form-aid").value=AID;
}
else
{
if(currentClass=="site-button-selected" && currentFormAidValue==AID)
{
document.getElementById(AID).setAttribute("class", "site-button-unselected");
document.getElementById("form-aid").value="";
}
else if(currentClass=="site-button-unselected" && currentFormAidValue!=AID)
{
document.getElementById(document.getElementById("form-aid").value).setAttribute("class", "site-button-unselected");
document.getElementById(AID).setAttribute("class", "site-button-selected");
document.getElementById("form-aid").value=AID;
}
}
calculatePrice();
}
// Caculates total price and gst
function calculatePrice()
{
let noOfDays = Number(document.getElementById("form-days").value);
let noOfAdults = Number(document.getElementById("form-adults").value);
let noOfChildren = Number(document.getElementById("form-children").value);
let currentFormAidValue = document.getElementById("form-aid").value;
let pricePerNight;
if (currentFormAidValue == "US")
{
pricePerNight = 35.25;
}
else if (currentFormAidValue == "PS")
{
pricePerNight = 50.25;
}
else if (currentFormAidValue == "UM")
{
pricePerNight = 40.50;
}
else if (currentFormAidValue == "PM")
{
pricePerNight = 60.50;
}
else if (currentFormAidValue == "C")
{
pricePerNight = 100.00;
}
let totalPrice;
let gstPrice;
//If null, doesn't calculate price
// The default value(if no option ois selected) for no of children is 99.
if( (noOfDays=='') || (noOfAdults=='') || (noOfChildren==99) || (currentFormAidValue=="") )
{
}
//If null, doesn't calculate the price
else if (currentFormAidValue == "")
{
}
else if((currentFormAidValue == "C") || ((noOfAdults+noOfChildren)<3))
{
totalPrice = (pricePerNight * noOfDays);
gstPrice = totalPrice/10;
//Prints the Prices
document.getElementById("total-price").innerHTML = String(totalPrice.toFixed(2));
document.getElementById("gst-price").innerHTML = String(gstPrice.toFixed(2));
//Stores the price in $_POST array
document.getElementById("Total_Price").value=String(totalPrice.toFixed(2));
document.getElementById("GST_Price").value=String(gstPrice.toFixed(2));
}
else if (noOfAdults==1)
{
totalPrice = (pricePerNight * noOfDays) + ((noOfAdults-1) * 10) + ((noOfChildren-1) * 5);
gstPrice = totalPrice/10;
//Prints the Prices
document.getElementById("total-price").innerHTML = String(totalPrice.toFixed(2));
document.getElementById("gst-price").innerHTML = String(gstPrice.toFixed(2));
//Stores the price in $_POST array
document.getElementById("Total_Price").value=String(totalPrice.toFixed(2));
document.getElementById("GST_Price").value=String(gstPrice.toFixed(2));
}
else
{
totalPrice = (pricePerNight * noOfDays) + ((noOfAdults-2) * 10) + ((noOfChildren) * 5);
gstPrice = totalPrice/10;
//Prints the Prices
document.getElementById("total-price").innerHTML = String(totalPrice.toFixed(2));
document.getElementById("gst-price").innerHTML = String(gstPrice.toFixed(2));
//Stores the price in $_POST array
document.getElementById("Total_Price").value=String(totalPrice.toFixed(2));
document.getElementById("GST_Price").value=String(gstPrice.toFixed(2));
}
}
</script>