-
Notifications
You must be signed in to change notification settings - Fork 4
/
new_booking.php
executable file
·147 lines (124 loc) · 4.56 KB
/
new_booking.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
<?php
include 'header.php';
if(!isset($_COOKIE["user"]))
{
echo '<div class="container">
<h2 class="alert alert-danger">You have to login to access this page</h2><br>
</div>';
include 'footer.php'; die;
} else if(@$_SESSION["group"]!=="Customer") {
echo '<div class="container">
<h2 class="alert alert-danger">You are no authorized to access this page</h2><br>
</div>';;
include 'footer.php'; die;
}
?>
<div class="card card-body bg-light">
<h2 class="text-center">Book New Trip</h2>
<hr>
<form>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Select the date</label>
<div class="col-sm-9">
<input type="date" class="form-control" name="date" min="<?php echo date('Y-m-d',strtotime("+1 day")); ?>">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Select the time</label>
<div class="col-sm-9">
<input type="time" class="form-control" name="time">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Enter the pickup location</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="pickt" name="pickup">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Enter the destination</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="destt" name="destination">
</div>
</div>
<div class="btn btn-block btn-primary" id="mapbtn">pick pickup and destination on map</div>
<div id="googleMap" style="width:100%;height:300px;display:none;">test</div>
<script>
j( "#mapbtn" ).click(function() {
j( "div#googleMap" ).show( "slow" );
});
function myMap() {
var mapProp= {
center:new google.maps.LatLng(6.914600, 79.973055),
zoom:10,
};
var click = 0;
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
google.maps.event.addListener(map, 'click', function(event) {
click++;
console.log(click);
if(click==1){
//1 st click
j("input#pickt").val(event.latLng.lat() + ", " + event.latLng.lng()).attr("disabled", "disabled");
j("#booking_status").html('<div class="alert alert-info">Pickup location added</div>').fadeIn("slow").delay(1000).fadeOut("slow");
}
if(click==2){
//2 st click
j("input#destt").val(event.latLng.lat() + ", " + event.latLng.lng()).attr("disabled", "disabled");
j("#booking_status").html('<div class="alert alert-info">Destination location added</div>').fadeIn("slow").delay(1000).fadeOut("slow");
j("div#googleMap").delay(100).fadeOut("slow");
j("div#mapbtn").delay(500).hide();
}
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAVBiTDLtz6mIP1cEF-MFWClav9hPVJzYw&origin&callback=myMap"></script>
</br>
<div class="input-group">
<button type="submit" id="submit" name="Register" class="btn btn-block btn-success">Book new trip</button>
</div>
<br><div id="booking_status" class="text-center"></div>
</form>
<a href="/customer.php" class="btn btn-info">Back to dashboard</a>
</div>
<script type="text/javascript">
j(document).ready(function () {
j('#submit').click(function (e) {
e.preventDefault();
if(!j(this).closest('form')[0].checkValidity()){
return false;
}
var date = j("input[name=date]").val();
var time = j("input[name=time]").val();
var pickup = j("input[name=pickup]").val();
var destination = j("input[name=destination]").val();
j('input').attr('disabled', true);
j.ajax({
type: "POST",
dataType: 'json',
url: "new_booking_process.php",
data: 'date='+ date +'&time='+ time +'&pickup='+ pickup +'&destination='+ destination +'&customer=<?php echo $_COOKIE['user']; ?>&json=true',
cache: false,
success: function(data){
if(data.result=="error"){
j("#booking_status").html('<div class="alert alert-warning">'+ data.message +'</div>').fadeIn("slow");
j('input').attr('disabled', false);
}
if(data.result=="success"){
j("#booking_status").html('<div class="alert alert-success">'+ data.message +'</div>').fadeIn("slow");
j("input#pickt").val(data.address.pickup);
j("input#destt").val(data.address.destination);
j('#submit').attr('disabled', true);
}
},
error: function(jqXHR,error, errorThrown){
j("#booking_status").html('<div class="alert alert-danger">OH! :O There was a unexpected error :(</div>').fadeIn("slow");
j('input').attr('disabled', false);
}
});
});
});
</script>
<?php
include 'footer.php';
?>