Skip to content
Snippets Groups Projects
Commit ef87d53b authored by adyanf's avatar adyanf
Browse files

fixing icons, handling add location

parent c3842f37
No related merge requests found
......@@ -260,7 +260,7 @@ td:nth-of-type(2n-1) {
}
.data-location .delete {
color: red;
color: #B33A3A;
font-weight: bold;
float: right;
margin-right: 10px;
......
......@@ -2,32 +2,43 @@
require('includes/config.php');
$id_active = $_GET["id_active"];
$sql = "SELECT name, phone_number, driver, image FROM users WHERE ID=$id_active LIMIT 1";
$sql = "SELECT driver FROM users WHERE ID=$id_active LIMIT 1";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
$name = $row["name"];
$phone_number = $row["phone_number"];
$driver = $row["driver"];
$image = $row["image"];
}
if ($driver == 0){
header('Location: profile.php?id_active=' . $id_active);
echo "<script>console.log(" . $driver . ")</script>";
exit;
}
if(isset($_POST["back"])){
header('Location: profile.php?id_active=' . $id_active);
echo "<script>console.log('back')</script>";
exit;
}
if(isset($_POST["submit"])) {
$name = $_POST["name"];
$phone_number = $_POST["phone"];
$driver = (!isset($_POST["driver"])) ? 0 : 1;
$location = $_POST["location"];
$sql = "INSERT INTO driver_locations (ID, location)
VALUES ('$id_active', '$location')";
$sql = "UPDATE users SET name='$name', phone_number='$phone_number', driver=$driver, image='$image' WHERE ID=$id_active";
if ($conn->query($sql) === TRUE) {
//echo "Record updated successfully";
header('Location: editpreferredlocations.php?id_active=' . $id_active);
echo "<script>console.log('get in')</script>";
exit;
} else {
//echo "Error updating record: " . $conn->error;
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$sql = "SELECT location FROM driver_locations WHERE ID=$id_active";
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
......@@ -52,28 +63,26 @@ if(isset($_POST["submit"])) {
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><input type="text" value="Pewter City" disabled></td>
<td><span class="edit"><i class="material-icons" onclick="editLocation(this)">mode_edit</i></span><span class="delete"><i class="material-icons" onclick="deleteLocation(this)">clear</i></span></td>
</tr>
<tr>
<td>2</td>
<td><input type="text" value="Saffron City" disabled></td>
<td><span class="edit"><i class="material-icons" onclick="editLocation(this)">mode_edit</i></span><span class="delete"><i class="material-icons" onclick="deleteLocation(this)">clear</i></span></td>
</tr>
<tr>
<td>3</td>
<td><input type="text" value="SkyPillar City" disabled></td>
<td><span class="edit"><i class="material-icons" onclick="editLocation(this)">mode_edit</i></span><span class="delete" onclick="deleteLocation(this)"><i class="material-icons">clear</i></span></td>
</tr>
<?php
$i = 1;
while($row = mysqli_fetch_assoc($result)) {
$location = $row["location"];
echo "
<tr>
<td>". $i ."</td>
<td><input type='text' value='". $location ."' disabled></td>
<td><span class='edit'><i class='material-icons' onclick='editLocation(this)'>mode_edit</i></span><span class='delete'><i class='material-icons' onclick='deleteLocation(this)'>delete</i></span></td>
</tr>
";
$i += 1;
} ?>
</tbody>
</table>
<div class="add-location">
<h3>ADD NEW LOCATION</h3>
<form action="">
<input type="text" name="place" required>
<input type="submit" value="ADD">
<form action="" method="post">
<input type="text" name="location" required>
<input type="submit" name="submit" value="ADD">
</form>
</div>
<div class="back">
......
......@@ -4,6 +4,8 @@ function editLocation(elmt){
row.children[1].children[0].disabled = false;
row.children[2].children[0].children[0].innerHTML = "done";
row.children[2].children[0].children[0].style.color = "#02702C";
row.children[2].children[1].children[0].innerHTML = "clear";
row.children[2].children[1].children[0].style.color = "red";
row.children[2].children[0].children[0].onclick = function(){ saveLocation(elmt, textBefore)};
row.children[2].children[1].children[0].onclick = function(){ cancelLocation(elmt, textBefore)};
}
......@@ -13,6 +15,8 @@ function saveLocation(elmt, text){
row.children[1].children[0].disabled = true;
row.children[2].children[0].children[0].innerHTML = "mode_edit";
row.children[2].children[0].children[0].style.color = "orange";
row.children[2].children[1].children[0].innerHTML = "delete";
row.children[2].children[1].children[0].style.color = "red";
row.children[2].children[0].children[0].onclick = function(){ editLocation(elmt)};
row.children[2].children[1].children[0].onclick = function(){ deleteLocation(elmt)};
}
......@@ -23,38 +27,15 @@ function cancelLocation(elmt, text){
row.children[1].children[0].disabled = true;
row.children[2].children[0].children[0].innerHTML = "mode_edit";
row.children[2].children[0].children[0].style.color = "orange";
row.children[2].children[1].children[0].innerHTML = "delete";
row.children[2].children[1].children[0].style.color = "red";
row.children[2].children[0].children[0].onclick = function(){ editLocation(elmt)};
row.children[2].children[1].children[0].onclick = function(){ deleteLocation(elmt)};
}
function deleteLocation(elmt){
var row = elmt.parentElement.parentElement.parentElement;
row.children[1].children[0].disabled = true;
}
if (confirm("Are you sure deleting the location ?") == true) {
var row = elmt.parentElement.parentElement.parentElement;
function getUsernameValidation(){
var xmlhttp = new XMLHttpRequest();
if(!xmlhttp){
return;
}
var username = document.getElementById("username");
console.log(username);
var url = "validation.php?u=" + username.value;
console.log(url);
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200){
var response = xmlhttp.responseText;
console.log(response);
if(response === "true"){
document.getElementById("wrongUsername").style.display = "none";
document.getElementById("checkUsername").style.display = "block";
}
else {
document.getElementById("checkUsername").style.display = "none";
document.getElementById("wrongUsername").style.display = "block";
}
}
}
xmlhttp.send();
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment