From eb8cbb96e4f976c47b1ec52df6b0373808e7ea54 Mon Sep 17 00:00:00 2001 From: Fadhil Imam Kurnia <fadhilimamk@gmail.com> Date: Fri, 6 Oct 2017 09:07:27 +0700 Subject: [PATCH] Finish edit location --- src/controller/ProfilController.php | 59 +++++++++++++++++++++++++++-- src/view/profil_edit_location.php | 2 +- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/controller/ProfilController.php b/src/controller/ProfilController.php index 7d44d68..21639d7 100644 --- a/src/controller/ProfilController.php +++ b/src/controller/ProfilController.php @@ -153,7 +153,6 @@ class ProfilController { echo "Invalid parameter!"; return; } - $id = $_GET['u']; // Decrypt user id @@ -176,11 +175,65 @@ class ProfilController { } public static function AddLocationHandler() { - echo "TBD"; + + // Getting user id from url + if (!isset($_GET['u']) || $_GET['u'] == "") { + echo "Invalid parameter!"; + return; + } + $id = $_GET['u']; + + // Decrypt user id + $uid = simpleCrypt($id, 'd'); + + $location = $_POST['location']; + + // Access database + $dbconn = DB::getInstance(); + $stmt = $dbconn->prepare( + 'INSERT INTO prefered_location + (id_driver, location) + VALUES + (?,?)' + ); + $stmt->execute(array($uid, $location)); + if ($stmt === false) { + echo "Fail :"; + echo $stmt->errorCode(). "<br>"; + print_r($stmt->errorInfo()); + } else { + header('Location: /main/profil/location/edit?u='.$_GET['u']); + } } public static function DeleteLocationHandler() { - echo "TBD"; + // Getting user id from url + if (!isset($_GET['u']) || $_GET['u'] == "" || !isset($_GET['name']) || $_GET['name'] == "") { + echo "Invalid parameter!"; + return; + } + $id = $_GET['u']; + + // Decrypt user id + $uid = simpleCrypt($id, 'd'); + $name = $_GET['name']; + + // Access database + $dbconn = DB::getInstance(); + $stmt = $dbconn->prepare( + 'DELETE FROM prefered_location + WHERE + id_driver = ? AND + location = ?' + ); + $stmt->execute(array($uid,$name)); + if ($stmt === false) { + echo "Fail :"; + echo $stmt->errorCode(). "<br>"; + print_r($stmt->errorInfo()); + } else { + header('Location: /main/profil/location/edit?u='.$_GET['u']); + } } diff --git a/src/view/profil_edit_location.php b/src/view/profil_edit_location.php index 3a28e8e..4d4cea3 100644 --- a/src/view/profil_edit_location.php +++ b/src/view/profil_edit_location.php @@ -58,7 +58,7 @@ <div class="row"> <div class="col-1"></div> <div class="col-4"> - <form action="/main/profil/location/add" method="post"> + <form action="/main/profil/location/add?u=<?=$id?>" method="post"> <input type="text" name="location" style="width:83%;"> <input type="submit" value="ADD" style="width:15%;"> </form> -- GitLab