-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-new-charging-station.php
412 lines (378 loc) · 23.3 KB
/
add-new-charging-station.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
<?php
session_start();
include_once('db_details.php');
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
/** Fetching all system values */
$query = "SELECT * FROM system_values";
$stmt = $conn->prepare($query);
$stmt->execute();
$sys_result = $stmt->get_result();
$system_values = [];
while ($row = $sys_result->fetch_assoc()) {
$system_values[$row['name']] = $row['value'];
}
/** Fetching all stations */
$sql = "SELECT * FROM station_models";
$result = $conn->query($sql);
$station_models = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$station_models[] = $row;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EV SHARE</title>
<link rel="shortcut icon" href="assets/images/favicon.png" type="image/png">
<link rel="stylesheet" href="./assets/css/style.css">
<link rel="stylesheet" href="./assets/css/jquery.multi-select.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="./assets/js/jquery.multi-select.min.js"></script>
</head>
<body>
<!-- ====================== Header===================== -->
<div class="main-vid add-new-charging-station-sec">
<video autoplay loop muted style="transform: rotatex(180deg);">
<source src="./assets/images/wave.mp4" type="video/mp4">
</video>
<div class="container h-100 z-index-3 position-relative">
<div class="d-flex align-items-center gap-md-5 gap-2 flex-wrap mt-5">
<div class="locate-button position-relative"><a class="text-dark" href="panel-page.php">Panel</a></div>
</div>
<div class="registor justify-content-start align-items-start py-12 px-lg-0 px-sm-10">
<h2>Add New Charging station</h2>
<form id="add-station-form" action="add_station.php" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-xl-7">
<div class="row">
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">Station Name</label>
<input type="text" class="form-control form-control-lg form-control-solid" name="station_name" placeholder="" required>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">Station Model</label>
<div class="w-100 position-relative">
<div class="si-border"></div>
<select class="form-select h-55px form-select-solid ps-13" name="station_model" required>
<?php
if($station_models){
foreach($station_models as $model){
echo '<option value="'.$model['id'].'">'.$model['name'].'</option>';
}
}
?>
</select>
</div>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">Year Model</label>
<div class="w-100 position-relative">
<div class="si-border"></div>
<select class="form-select h-55px form-select-solid ps-13" name="station_year" required>
<option value="2023">2024</option>
<option value="2023">2023</option>
<option value="2020">2020</option>
<option value="2019">2019</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">Address</label>
<input id="searchInput" type="text" class="form-control form-control-lg form-control-solid" name="address" placeholder="" required>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">Charging Type</label>
<div class="w-100 position-relative dropdown-control">
<div class="si-border"></div>
<select multiple id="chargin-types" class="multi-select-container h-55px form-select-solid ps-13" name="charging_type[]" required>
<option value="TESLA 1" selected>TESLA 1</option>
<option value="TESLA 2">TESLA 2</option>
<option value="TESLA 3">TESLA 3</option>
</select>
</div>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">City</label>
<div class="w-100 position-relative">
<div class="si-border"></div>
<select class="form-select h-55px form-select-solid ps-13" name="city" required>
<option value="1">Afula</option>
<option value="2">Akko</option>
<option value="3">Arad</option>
<option value="4">Arraba</option>
<option value="5">Ashdod</option>
<option value="6">Ashkelon</option>
<option value="7">Baqa al-Gharbiyye</option>
<option value="8">Bat Yam</option>
<option value="9">Beersheba</option>
<option value="10">Beit She'an</option>
<option value="11">Beit Shemesh</option>
<option value="12">Beitar Illit</option>
<option value="13">Bnei Brak</option>
<option value="14">Dimona</option>
<option value="15">Eilat</option>
<option value="16">Elad</option>
<option value="17">Givatayim</option>
<option value="18">Giv'at Shmuel</option>
<option value="19">Hadera</option>
<option value="20">Haifa</option>
<option value="21">Herzliya</option>
<option value="22">Hod HaSharon</option>
<option value="23">Holon</option>
<option value="24">Jaffa</option>
<option value="25">Jerusalem</option>
<option value="26">Karmiel</option>
<option value="27">Kfar Saba</option>
<option value="28">Kiryat Ata</option>
<option value="29">Kiryat Bialik</option>
<option value="30">Kiryat Gat</option>
<option value="31">Kiryat Malakhi</option>
<option value="32">Kiryat Motzkin</option>
<option value="33">Kiryat Ono</option>
<option value="34">Kiryat Shmona</option>
<option value="35">Kiryat Yam</option>
<option value="36">Lod</option>
<option value="37">Ma'ale Adumim</option>
<option value="38">Ma'alot-Tarshiha</option>
<option value="39">Migdal HaEmek</option>
<option value="40">Modi'in Illit</option>
<option value="41">Modi'in-Maccabim-Re'ut</option>
<option value="42">Nahariya</option>
<option value="43">Nazareth</option>
<option value="44">Nazareth Illit (Nof HaGalil)</option>
<option value="45">Netanya</option>
<option value="46">Netivot</option>
<option value="47">Ness Ziona</option>
<option value="48">Nof HaGalil</option>
<option value="49">Ofakim</option>
<option value="50">Or Akiva</option>
<option value="51">Or Yehuda</option>
<option value="52">Petah Tikva</option>
<option value="53">Qalansawe</option>
<option value="54">Rahat</option>
<option value="55">Ramat Gan</option>
<option value="56">Ramat HaSharon</option>
<option value="57">Ramla</option>
<option value="58">Rehovot</option>
<option value="59">Rishon LeZion</option>
<option value="60">Rosh HaAyin</option>
<option value="61">Sakhnin</option>
<option value="62">Sderot</option>
<option value="63">Shefa-Amr</option>
<option value="64">Tamra</option>
<option value="65">Tayibe</option>
<option value="66">Tel Aviv</option>
<option value="67">Tiberias</option>
<option value="68">Tira</option>
<option value="69">Tirat Carmel</option>
<option value="70">Umm al-Fahm</option>
<option value="71">Yavne</option>
<option value="72">Yehud-Monosson</option>
<option value="73">Yokneam Illit</option>
<option value="74">Zefat (Safed)</option>
</select>
</div>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">Charging Capacity [kwh]</label>
<input type="number" class="form-control form-control-lg form-control-solid" name="charging_capacity" placeholder="" value="0" maxlength="5" required>
</div>
<div class="col-md-6 mb-5">
<label class="fs-3 fw-semibold text-white mr-3">How To Find</label>
<textarea class="form-control form-control-lg form-control-solid text-end h-150px" name="how_to_find" placeholder="" required></textarea>
</div>
<div class="col-md-6 mb-5">
<div class="row">
<div class="col-md-6 mb-5">
<label class="fs-3 fw-semibold text-white mr-3">Photos</label>
<div class="row">
<div class="mb-1 col-6">
<input type="file" name="image1" class="form-control form-control-lg form-control-solid" required>
</div>
<div class="mb-1 col-6">
<input type="file" name="image2" class="form-control form-control-lg form-control-solid" required>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">
Asking Price for kWh [NIS]
<span class="tooltip-pro">
<span class="tooltip-info-icon">ℹ</span>
<span class="tooltiptext">ASKING PRICE FOR KWH</span>
</span>
</label>
<input readonly type="number" class="form-control form-control-lg form-control-solid fs-1 py-1 h-55px" name="asking_price" value="0" placeholder="" required>
</div>
<div class="col-md-6 mb-5">
<label class="d-flex align-items-center fs-5 fw-semibold mb-2 text-white">
ALGORITHM Price
<span class="tooltip-pro">
<span class="tooltip-info-icon">ℹ</span>
<span class="tooltiptext">ALGORITHM Price</span>
</span></label>
<input readonly type="number" class="form-control form-control-lg form-control-solid fs-1 py-1 h-55px" name="algo_price" value="0" placeholder="" required>
<div>
<label class="mt-2 text-white">Use the suggested price <input name="using_algorithm" type="checkbox" checked/> </label>
</div>
</div>
</div>
</div>
<div class="col-xl-5">
<div id="map-canvas" style="height: 300px;width:100%"></div>
<input type="hidden" name="latitude" id="latitude" required>
<input type="hidden" name="longitude" id="longitude" required>
<div class="d-flex justify-content-end mt-9">
<button type="submit" class="btn btn-primary fs-2qx pt-1 pb-0 fw-bold rounded-pill text-Jaturat">Add Station</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCst-5X8nOQwqiboEiq0xzZs7DMCMSFkYs&libraries=places&callback=initMap" async defer></script>
<script>
var map;
const defaultLocation = {lat: 32.087925, lng: 34.756047};
const systemValues = JSON.parse('<?php echo json_encode($system_values) ?>');
$('document').ready(() => {
$('#chargin-types').multiSelect();
});
$("input[name='charging_capacity']").keyup( function() {
const algoPrice = calcAlgoPrice($(this).val());
$("input[name='algo_price']").val(algoPrice);
if($("input[name='using_algorithm']").is(':checked')){
$("input[name='asking_price']").val(algoPrice);
}
});
$("input[name='using_algorithm']").change( function() {
if($(this).is(':checked')){
$("input[name='asking_price']").val($("input[name='algo_price']").val());
$("input[name='asking_price']").prop('readonly', true);
} else {
$("input[name='asking_price']").prop('readonly', false);
}
});
function calcAlgoPrice(chargeCapacity){
if(!chargeCapacity || chargeCapacity.length == 0 || chargeCapacity == 0) return 0;
return (systemValues['profit_fee'] + systemValues['electricity_price']) * parseFloat(chargeCapacity);
}
function initMap() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: defaultLocation,
zoom: 9,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
setAutoComplete();
}
function setMarker(coordinates) {
var marker = new google.maps.Marker({
position: coordinates,
map: map,
draggable: true
});
map.setZoom(17);
google.maps.event.addListener(marker, 'dragend', function(evt) {
const coordinates = {lat: evt.latLng.lat(), lng: evt.latLng.lng()};
setCoordinateFields(coordinates);
geocodePosition(coordinates);
});
}
function setAutoComplete() {
var input = document.getElementById('searchInput');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
console.log("Autocomplete's returned place contains no geometry");
return;
}
const coordinates = place.geometry.location;
map.setCenter(coordinates);
setMarker(coordinates);
setCoordinateFields({lat: coordinates.lat(), lng: coordinates.lng()});
});
}
function setCoordinateFields(coordinates) {
document.getElementById('latitude').value = coordinates.lat;
document.getElementById('longitude').value = coordinates.lng;
}
function geocodePosition(pos) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
latLng: pos
}, function(responses) {
if (responses && responses.length > 0) {
$('#searchInput').val(get_geocode_formatted_address(responses));
}
});
}
function get_geocode_formatted_address(results){
var geocode_address_segments = get_geocode_address_segments(results);
var street = geocode_address_segments['street'];
var region = geocode_address_segments['region'];
var country = geocode_address_segments['country'];
var formatted_address = street + " " + region + ", " + country;
return formatted_address;
}
function get_geocode_address_segments(results) {
var street_number = '';
var route = '';
var region = '';
var country = '';
for (var j=0; j<results.length; j++)
{
for (var i=0; i<results[j].address_components.length; i++)
{
if(!street_number){
if (results[j].address_components[i].types[0] == "street_number") {
street_number = results[j].address_components[i].long_name+' ';
}
}
if(!route){
if (results[j].address_components[i].types[0] == "route") {
route += results[j].address_components[i].long_name;
}
}
if(!region){
if (results[j].address_components[i].types[0] == "administrative_area_level_1") {
region = results[j].address_components[i].long_name;
}
}
if(!country){
if (results[j].address_components[i].types[0] == "country") {
country = results[j].address_components[i].long_name;
}
}
if(route && region && country){
break;
}
}
}
return {
'street':street_number+route,
'region':region,
'country':country
};
}
</script>
</body>
</html>