diff --git a/css/default_style.css b/css/default_style.css index 2a94eb99cd98fe79864694d761bdf5c6511ce43d..68c30196d825fe4601fe520ead18539fe6d6c3c0 100755 --- a/css/default_style.css +++ b/css/default_style.css @@ -56,6 +56,7 @@ a { a:link, a:visited { text-decoration: none; + cursor: pointer; } a:hover { diff --git a/css/location.css b/css/location.css index 9fd3dbec79bab20370abbf988c8d133554014d60..009b25bda1368a71b1e50d5cc16bc7eb3a7d3c01 100644 --- a/css/location.css +++ b/css/location.css @@ -44,16 +44,41 @@ tr td:nth-child(1),td:nth-child(2) { } tr th:nth-child(3) { +} +.edit_operation { + display: block; } .edit_button { + border: none; color: #82d800; float: left; margin-left: 15%; + cursor: pointer; } .delete_button { color: #ff0000; float: right; margin-right: 15%; + cursor: pointer; +} +.save_button { + border: none; + color: #82d800; + text-decoration: underline; + background-color: transparent; + float: left; + width: 35px; + cursor: pointer; +} +.cancel_button { + color: #ff0000; + float: right; + margin-top: 5%; + margin-right: 15%; + font-size: 0.6em; + width: 25px; + cursor: pointer; + text-decoration: underline; } .add_loc_frame { margin-top: 10%; @@ -76,4 +101,5 @@ tr th:nth-child(3) { } .add { width: 50px; + cursor: pointer; } diff --git a/css/profile.css b/css/profile.css index 866e0254c6fcbf2c8eaa298c6c4dd80d7faf20e7..ebcd394a83a5dd1251ff083231d7a085f343cf88 100755 --- a/css/profile.css +++ b/css/profile.css @@ -109,6 +109,7 @@ } .save { width: 50px; + cursor: pointer; } #profile_link { background-color: #465d43; diff --git a/profile/deletePrefLoc.php b/profile/deletePrefLoc.php deleted file mode 100644 index e9aa1749eec5f06a76555552faad89cd177f1f88..0000000000000000000000000000000000000000 --- a/profile/deletePrefLoc.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - include '../database/dbconnect.php'; - $user_id = urldecode($_GET['id']); - $deletedLoc = urldecode($_GET['loc']); - $query = mysqli_query($con,"DELETE FROM driver_prefloc WHERE driver_id='".$user_id."' AND pref_loc='".$deletedLoc."'") or die(mysqli_error($con)); - mysqli_close($con); - if ($query) { - header("Location: edit_location.php?id=$user_id"); - } -?> diff --git a/profile/edit_location.php b/profile/edit_location.php index 48d2bcdf1ee64b966c2e56c61ae5e3d12d531bac..20b9801db9c1e92242861b805f904880bf4cfd9c 100644 --- a/profile/edit_location.php +++ b/profile/edit_location.php @@ -6,6 +6,44 @@ <link rel="stylesheet" type="text/css" href="../css/header.css"> </head> <body> + <script> + function showEdit(editID,saveID,locID,dummylocID,currentlocID,formID,deleteID,cancelID) { + showSave(editID,saveID); + showCancel(deleteID,cancelID); + var temp = document.getElementById(locID).innerHTML; + document.getElementById(locID).style.display = "none"; + document.getElementById(dummylocID).value = temp; + document.getElementById(currentlocID).value = temp; + document.getElementById(formID).style.display = "block"; + } + function showSave(editID,saveID) { + document.getElementById(editID).style.display = "none"; + document.getElementById(saveID).style.display = "block"; + } + function showCancel(deleteID,cancelID) { + document.getElementById(deleteID).style.display = "none"; + document.getElementById(cancelID).style.display = "block"; + } + function copyDummytoNewLoc(dummylocID,newlocID) { + var temp = document.getElementById(dummylocID).value; + document.getElementById(newlocID).value = temp; + } + function hideEdit(editID,saveID,locID,formID,deleteID,cancelID) { + document.getElementById(editID).style.display = "block"; + document.getElementById(saveID).style.display = "none"; + document.getElementById(locID).style.display = "block"; + document.getElementById(formID).style.display = "none"; + document.getElementById(deleteID).style.display = "block"; + document.getElementById(cancelID).style.display = "none"; + } + function validateAddLoc(docID) { + var loc = document.getElementById(docID).value; + if (loc == null || loc == "") { + window.alert("Location can't be blank"); + return false; + } + } + </script> <div class="frame"> <div class="header"> <?php @@ -48,28 +86,45 @@ while($row=mysqli_fetch_assoc($query)) { echo '<tr> <td>'.$i.'</td> - <td>'.$row['pref_loc'].'</td> - <td><div class="edit_button">✎</div><div class="delete_button"><a href=deletePrefLoc.php?id='.urlencode($user_id).'&loc='.urlencode($row['pref_loc']).'>✖</a></div></td> + <td> + <div id='.'prefloc'.$i.'>'.$row['pref_loc'].'</div> + <div id='.'form_prefloc'.$i.' style="display: none"> + <input type="text" style=" height: 100%, width: 100%;" id='.'dummy_prefloc'.$i.' onkeyup="copyDummytoNewLoc(\'dummy_prefloc'.$i.'\',\'new_prefloc'.$i.'\');"> + </div> + </td> + <td> + <div class="edit_operation"> + <div class="edit_button" id='.'edit_prefloc'.$i.' onClick="showEdit(\'edit_prefloc'.$i.'\',\'save_prefloc'.$i.'\',\'prefloc'.$i.'\',\'dummy_prefloc'.$i.'\',\'current_prefloc'.$i.'\',\'form_prefloc'.$i.'\',\'delete_prefloc'.$i.'\',\'cancel_edit'.$i.'\');">✎</div> + <div id='.'save_prefloc'.$i.' style="display: none"> + <form name="edit_prefloc_form" method="POST" action="updateLocation.php" style="display: inline;" onsubmit="return validateAddLoc(\'dummy_prefloc'.$i.'\')"> + <input class="save_button" type="submit" value="Save"> + <input type="hidden" name="current_prefloc" id='.'current_prefloc'.$i.'> + <input type="hidden" name="new_prefloc" id='.'new_prefloc'.$i.'> + <input type="hidden" name="user_id" value="'.$user_id.'"> + </form> + </div> + <div class="delete_button" id='.'delete_prefloc'.$i.'><a href=updateLocation.php?id='.urlencode($user_id).'&loc='.urlencode($row['pref_loc']).'>✖</a></div> + <div class="cancel_button" id='.'cancel_edit'.$i.' style="display: none;" onClick="hideEdit(\'edit_prefloc'.$i.'\',\'save_prefloc'.$i.'\',\'prefloc'.$i.'\',\'form_prefloc'.$i.'\',\'delete_prefloc'.$i.'\',\'cancel_edit'.$i.'\');">Cancel</div> + </div> + </td> </tr>'; $i++; } } ?> + </table> </div> <div class="add_loc_frame"> <h2>Add New Location</h2> - <form name="add_location" action="updateLocation.php" method="POST"> - <input type="text" name="new_location"> - <input type="text" id="hidden_userid" name="hidden_userid" style="display: none;"> + <form name="add_location" action="updateLocation.php" method="POST" onsubmit="return validateAddLoc('add_newloc')"> + <input type="text" id="add_newloc" name="new_location"> + <input type="hidden" name="hidden_userid" value= <?php echo $user_id ?>> <input type="submit" value="ADD" class="button green add"> </form> </div> <a href=<?php echo 'profile.php?id='.$user_id; ?>><div class="button red back">BACK</div></a> </div> - <?php - echo "<script>document.getElementById('hidden_userid').value =".$user_id."</script>"; - ?> </body> </html> diff --git a/profile/edit_profile.php b/profile/edit_profile.php index fba1b06afef7c661b4a2513495d304150eaa4464..0fa02144df8440849fb616766f69d82e7ea21dad 100644 --- a/profile/edit_profile.php +++ b/profile/edit_profile.php @@ -35,7 +35,7 @@ <div class="subheader"> <div class="title"><h1>My Profile</h1></div> </div> - <form name="edit_identity" method="POST" action="updateProfile.php" enctype="multipart/form-data"> + <form name="edit_identity" method="POST" action="updateProfile.php" onsubmit="return validateForm();" enctype="multipart/form-data"> <div class="change_profilepict"> <div class="current_pict_frame"> <img id="current_profile_pict" src="../img/default_profile.jpeg"> @@ -97,6 +97,18 @@ var arrTemp = inputFile.value.split('\\'); document.getElementById("file_name").value = arrTemp[arrTemp.length - 1]; } + function validateForm() { + if (document.edit_identity.current_name.value == null || document.edit_identity.current_name.value == "") { + window.alert("Name can't be blank"); + return false; + } else if (document.edit_identity.current_phone.value == null || document.edit_identity.current_phone.value == "") { + window.alert("Phone can't be blank"); + return false; + } else if (document.edit_identity.current_phone.value.length < 9 || document.edit_identity.current_phone.value.length > 12) { + window.alert("Phone number should be 9 to 12 characters long"); + return false; + } + } </script> </body> </html> diff --git a/profile/updateLocation.php b/profile/updateLocation.php index 0334b045fe99ce117ac6c22eb33d59ae827dd4a0..64579629b530de60edb968dddcc3f63a9792886e 100644 --- a/profile/updateLocation.php +++ b/profile/updateLocation.php @@ -9,6 +9,25 @@ if ($query) { header("Location: edit_location.php?id=$user_id"); } + } else if (!empty($_POST['new_prefloc'])) { + $user_id = $_POST['user_id']; + $current_prefloc = $_POST['current_prefloc']; + $new_prefloc = $_POST['new_prefloc']; + include '../database/dbconnect.php'; + $query = mysqli_query($con,"UPDATE driver_prefloc SET pref_loc = '$new_prefloc' WHERE driver_id = '$user_id' AND pref_loc = '$current_prefloc'") or die(mysqli_error($con)); + mysqli_close($con); + if ($query) { + header("Location: edit_location.php?id=$user_id"); + } + } + } else if ($_SERVER["REQUEST_METHOD"] == "GET") { + include '../database/dbconnect.php'; + $user_id = urldecode($_GET['id']); + $deletedLoc = urldecode($_GET['loc']); + $query = mysqli_query($con,"DELETE FROM driver_prefloc WHERE driver_id='".$user_id."' AND pref_loc='".$deletedLoc."'") or die(mysqli_error($con)); + mysqli_close($con); + if ($query) { + header("Location: edit_location.php?id=$user_id"); } } ?>