diff --git a/css/profile.css b/css/profile.css index 94dbd5cff904004445f89624a545f7fb4bd0bf6b..ea790e758899f7a64bc143a1eea81103f6b57013 100644 --- a/css/profile.css +++ b/css/profile.css @@ -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; diff --git a/editpreferredlocations.php b/editpreferredlocations.php index 0678be99748741a25fd19dd0d0b74752a3eac762..ac74cd8115c2d5c0f71d15464710cda1b00aae9c 100644 --- a/editpreferredlocations.php +++ b/editpreferredlocations.php @@ -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"> diff --git a/js/editlocation.js b/js/editlocation.js index c3e9d5c3e6e1fcf5ecbffb7af23c617797c24ebb..52f52983327f3c54d76e945e238993b98f001477 100644 --- a/js/editlocation.js +++ b/js/editlocation.js @@ -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