diff --git a/src/controller/ProfilController.php b/src/controller/ProfilController.php index 7d44d68fe9fa8654d724fd443d350f9976afe34f..21639d708a01ff88fb239ae424688c2b13af467b 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 3a28e8ed83c88e0360529ef7cb84959a3ba88778..4d4cea30e692af62b532a6751d88965b05088caa 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>