diff --git a/controller/edit-location.php b/controller/add-location.php similarity index 100% rename from controller/edit-location.php rename to controller/add-location.php diff --git a/controller/edit-prefered-location.php b/controller/edit-prefered-location.php deleted file mode 100644 index b4ae86a6b70419c8dce0703d02884eb4fb083811..0000000000000000000000000000000000000000 --- a/controller/edit-prefered-location.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/* Model */ -include "../model/user.php"; - -//TODO: tambahin redirect klo get kosong - -$user = new User; -$user_id = $_GET['id']; -$result = $user->getUserById($user_id); -header('Content-Type: text/xml'); -$xml = '<user>'; -while($row = mysqli_fetch_array($result)){ - $xml = $xml . '<name>' . $row['name'] . '</name><username>' . $row['username'] . - '</username><email>' . $row['email'] . '</email><image>' . $row['image'] . - '</image><phone>' . $row['phone'] . '</phone><driver>' . $row['isDriver'] . '</driver>'; -} -$xml = $xml . '</user>'; - -print $xml; \ No newline at end of file diff --git a/controller/editsave-location.php b/controller/editsave-location.php new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/css/edit-prefered-location.css b/css/edit-prefered-location.css index 7884ac9040225b3d68f76d319be398c5703517c5..3a65d2e933cd40703ed0a29fa1c3e66df7f91309 100644 --- a/css/edit-prefered-location.css +++ b/css/edit-prefered-location.css @@ -81,10 +81,29 @@ button{ .submit{ width: 100%; + height: 40px; background-color: #82D800; border-color: #000000; border-radius: 5px; - font-size: 130%; + font: 130% Serif; padding: 0 0 0 0; color: #000000; + border-width: 1px; +} + +.backbutton{ + width: 15%; +} + +.back{ + float: left; + background-color: #d50027; + color: black; + border-color: black; + border-radius: 5px; + padding: 5px 12px; + text-decoration: none; + border-width: 1px; + border-style: outset; + font: 130% Serif; } diff --git a/css/index.css b/css/index.css index e4d51e10a871b17cc3fb69fa105342280edb3712..d15b6cb1deeb7d86afbd7ec1d4d6273e5f47be34 100644 --- a/css/index.css +++ b/css/index.css @@ -85,6 +85,6 @@ .link{ text-align: left; font-family: "Arial"; - width: 69%; + width: 68%; text-align: left; } \ No newline at end of file diff --git a/js/edit-prefered-location.js b/js/edit-prefered-location.js index 15481ca9f8f2422e37615d74890bb8967dcff9f4..76f018a3806cc796956523f4b5a2c97e94233dd7 100644 --- a/js/edit-prefered-location.js +++ b/js/edit-prefered-location.js @@ -1,6 +1,5 @@ -function hideMe(i){ - var textHidden = false; - textHidden = !textHidden; +function editsave(i){ + var submitForm = document.getElementById("locationform"+i); var textBox = document.getElementById("locationtext"+i); var inputBox = document.getElementById("locationinput"+i); var image = document.getElementById("imageeditsave"+i); @@ -11,11 +10,24 @@ function hideMe(i){ inputBox.setAttribute("style","display:block"); inputBox.value = textBox.innerHTML; image.src = "../img/floppy.png"; - } - else{ + } else { + var form = document.forms["locationform"+i]; textBox.setAttribute("style","display:block"); + inputBox.type = "hidden"; inputBox.setAttribute("style","display:none"); textBox.innerHTML = inputBox.value; image.src = "../img/pencil.png"; + form.action = "editsave-location.php"; + form.submit(); + } +} + +function del(i){ + var textBox = document.getElementById("locationtext"+i); + var form = document.forms["locationform"+i]; + var check = confirm ("Delete "+textBox.innerHTML+" from preferred location?"); + if (check === true){ + form.action = "delete-location.php"; + form.submit(); } } \ No newline at end of file diff --git a/model/user.php b/model/user.php index 779228b4fac0acca35d9416a8bd8ace39eef7688..accd1cdf593b3143a0d8ce0fbb7beb07f3062161 100644 --- a/model/user.php +++ b/model/user.php @@ -119,6 +119,24 @@ class User { mysqli_close($con); return $result; } + + function addLocation($id, $location) { + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con, 'projekers'); + $image = "pikachu.jpg"; + $sql = "INSERT INTO pref_loc (" . $id . ", '" . (string)$location . "')"; + mysqli_query($con,$sql); + mysqli_close($con); + } + + function updateLocation($id, $location) { + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con, 'projekers'); + $image = "pikachu.jpg"; + $sql = "INSERT INTO pref_loc (" . $id . ", '" . (string)$location . "')"; + mysqli_query($con,$sql); + mysqli_close($con); + } //function getD // select * from user natural join pref_loc where (location like 'bec%' or location like '%kopo%') and isDriver=1 and not id=1 } \ No newline at end of file diff --git a/view/dashboard.php b/view/dashboard.php index b38a36dbe111d59d2fdb4186d642a150229517b7..973e32c9fb9bd95fd7ebde30fca2fe236d05fe3a 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -65,7 +65,7 @@ <div class="sub-header" id="preferred-location"> <div class="sub-header-heading"><h1>PREFERRED LOCATION</h1></div> <div class="edit-icon"> - <a href="../view/edit-prefered-locations.php"><img src="../img/pencil.png" /></a> + <a href="../view/edit-prefered-locations.php?id=<?php echo $_GET['id'];?>"><img src="../img/pencil.png" /></a> </div> </div> <div class="user-location"><ul id="user-location"></ul></div> diff --git a/view/edit-prefered-locations.php b/view/edit-prefered-locations.php index 739d1e3fc732b4094ec05385be320876e73837f9..a9bdc479604be7b1ee8f0da90bd63069b7d29de1 100644 --- a/view/edit-prefered-locations.php +++ b/view/edit-prefered-locations.php @@ -11,7 +11,7 @@ <?php include "../model/user.php"; $user = new User; - $user_id = 1; + $user_id = $_GET['id']; $result = $user->getPreferredLocation($user_id); if ($result->num_rows > 0) { echo ' @@ -26,25 +26,29 @@ while($row = $result->fetch_assoc()) { echo ' <tr> - <td class="tabno">'.$i.'</td> - <td class="tabloc"> - <div id="locationtext'.$i.'">'.$row["location"].'</div> - <input class="locationinput" id="locationinput'.$i.'" type="hidden"> - </td> - <td class="tabact"> - <div class="addset" align="center"> - <div class="editsavebox"> - <button onClick=hideMe('.$i.') class="editsave"> - <img src="../img/pencil.png" class="editsavebutton" id="imageeditsave'.$i.'"> - </button> + <form name="locationform'.$i.'" method="post"> + <td class="tabno">'.$i.'</td> + <td class="tabloc"> + <input class="locationinput" id="id'.$i.'" type="hidden"> + <div id="locationtext'.$i.'">'.$row["location"].'</div> + <input class="locationinput" id="locationinput'.$i.'" type="hidden"> + <input class="oldlocation" id="oldlocation'.$i.'" type="hidden" value="'.$row["location"].'"> + </td> + <td class="tabact"> + <div class="addset" align="center"> + <div class="editsavebox"> + <button type="button" onClick=editsave('.$i.') class="editsave"> + <img src="../img/pencil.png" class="editsavebutton" id="imageeditsave'.$i.'"> + </button> + </div> + <div> + <button onClick=del('.$i.') class="delete"> + <img src="../img/delete.png" class="deletebutton" id="imagedelete'.$i.'"> + </button> + </div> </div> - <div> - <button onClick=f() class="delete"> - <img src="../img/delete.png" class="deletebutton" id="imagedelete'.$i.'"> - </button> - </div> - </div> - </td> + </td> + </form> </tr>'; $i++; } @@ -64,8 +68,12 @@ <input type="Submit" value="ADD" class="submit"> </div> </div> + <br> + <br> <div> - + <div class="backbutton"> + <a class="back" href="dashboard.php?id=<?php echo $_GET['id'];?>">BACK</a> + </div> </div> </div> </body>