diff --git a/controller/edit-profile.php b/controller/edit-profile.php new file mode 100644 index 0000000000000000000000000000000000000000..a1063ff3a0f63aa516fe53768d5f3f6e9b89cde1 --- /dev/null +++ b/controller/edit-profile.php @@ -0,0 +1,42 @@ +<?php + +//TODO: Refresh page after save, image kalo ga dimasukkin pake yg lama, cek smua input gaboleh salah + +/* Model */ +include "../model/user.php"; +/* GET */ +if(!$_POST) { + $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 . '<id>' . $user_id . '</id><name>' . $row['name'] . '</name><image>' . $row['image'] . + '</image><phone>' . $row['phone'] . '</phone><driver>' . $row['isDriver'] . '</driver>'; + } + $xml = $xml . '</user>'; + + print $xml; +} + +/* POST */ + +if(isset($_POST["submit"])) { + $user = new User; + $userid = $_GET['id']; + $name = $_POST['name']; + $phone = $_POST['phone']; + $isDriver = 0; + if(isset($_POST['driver'])) { + if($_POST['driver'] == 'on') { + $isDriver = 1; + } + } + //if(isset(($_POST['image']))) + $image = $_POST['image-file']; + $user -> updateProfileById($userid,$name,$phone,$isDriver,$image); +} + + diff --git a/controller/register.php b/controller/register.php index b096b6ebf82cd8f7677c6239da88493751f95973..97310db9191a44ce433fc0ee80170b1db670f4b2 100644 --- a/controller/register.php +++ b/controller/register.php @@ -1,5 +1,5 @@ <?php -//TODO : Setelah submit redirect ke dashboard, checking user n email +//TODO : Setelah submit redirect ke dashboard dengan variable ?id=..., check semua input type gaboleh salah //model include "../model/user.php"; @@ -22,9 +22,8 @@ if(isset($_POST["email2check"])) { $user = new User; $email = $_POST["email2check"]; $sqlcheck = $user->getEmail($email); - $usernameCheck = mysqli_num_rows($sqlcheck); - - if($usernameCheck < 1) { + $emailCheck = mysqli_num_rows($sqlcheck); + if($emailCheck < 1) { echo 'ok'; exit(); } else { @@ -47,5 +46,6 @@ if(isset($_POST["register"])) { $isDriver = 1; } } - $user -> createProfile($name,$username,$email,$password,$phone,$isDriver); + $user -> createUser($name,$username,$email,$password,$phone,$isDriver); + $id = $user->getUserById($username); } diff --git a/js/edit-profile.js b/js/edit-profile.js index 316fe1ffa520b3656fb73cd2bcdbe281fd46c628..cdcf29c22d44d0d5099a72d6fe72dfdf77ad8265 100644 --- a/js/edit-profile.js +++ b/js/edit-profile.js @@ -1,24 +1,24 @@ function getUserProfile() { + var id = sessionid; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { var result = xmlhttp.responseXML; + var userid = result.getElementsByTagName('id')[0].childNodes[0].nodeValue; var name = result.getElementsByTagName('name')[0].childNodes[0].nodeValue; var phone = result.getElementsByTagName('phone')[0].childNodes[0].nodeValue; var driver = result.getElementsByTagName('driver')[0].childNodes[0].nodeValue; var image = result.getElementsByTagName('image')[0].childNodes[0].nodeValue; + document.getElementById('userid').value = userid; document.getElementById('name').value = name; document.getElementById('phone').value = phone; document.getElementById('image').src = '../img/' + image; document.getElementById('driver').checked = (driver == 1 ? true : false); } }; - xmlhttp.open('GET','../controller/edit-profile.php?id=1',true); + xmlhttp.open('GET','../controller/edit-profile.php?id=' + id,true); xmlhttp.send(); - } -function saveUserProfile() { -} \ No newline at end of file diff --git a/js/register.js b/js/register.js index aa0109b946c58c0d1588c167c45f23e30a999ca3..9d62c1ffa376346577fbcf178bac2e460e999e6b 100644 --- a/js/register.js +++ b/js/register.js @@ -45,4 +45,3 @@ function checkEmail() { } } - diff --git a/model/user.php b/model/user.php index a7c9f5c99d39a6c715466c71c97efdeb09263079..8bae331a751143a121677e5e1f7c2c9606f24bd5 100644 --- a/model/user.php +++ b/model/user.php @@ -28,7 +28,16 @@ class User { return $result; } - function saveProfileById($id, $name, $phone, $isDriver, $image) { + function getIdByUser($user) { + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con, 'projekers'); + $sql = "SELECT id FROM user WHERE username=" . $user; + $result = mysqli_query($con, $sql); + mysqli_close($con); + return $result; + } + + function updateProfileById($id, $name, $phone, $isDriver, $image) { $con = mysqli_connect('localhost','root','','projekers'); mysqli_select_db($con,'projekers'); $sql = "update user set name='" . (string)$name . "', phone ='" . (string)$phone . "', isDriver='" . @@ -37,7 +46,7 @@ class User { mysqli_close($con); } - function createProfile($name, $username, $email, $password, $phone, $isDriver) { + function createUser($name, $username, $email, $password, $phone, $isDriver) { $con = mysqli_connect('localhost','root','','projekers'); mysqli_select_db($con, 'projekers'); $image = "pikachu.jpg"; diff --git a/view/edit-profile.php b/view/edit-profile.php index 112e8ddc4ed9216af2905468506a0e436b2a90dc..a019ad23902595301866af4600a022b89a76453c 100644 --- a/view/edit-profile.php +++ b/view/edit-profile.php @@ -4,14 +4,15 @@ <link href="../css/primary.css" type="text/css" rel="stylesheet"> <link href="../css/edit-profile.css" type="text/css" rel="stylesheet"> <script> - var sessionid = "<?php echo $_GET['id']; ?>"; + var sessionid = "<?php echo $_GET['id'];?>"; </script> <script src="../js/edit-profile.js"></script> </head> <body onpageshow="getUserProfile();"> <div class="container"> <h1>EDIT PROFILE INFORMATION</h1> - <form action="#" method="post"> + <form action="../controller/edit-profile.php?id=<?php echo $_GET['id']?>" method="post" id="form"> + <input type="hidden" id="userid" value="<?php echo $_GET['id'];?>"> <div class="edit-image"> <div class="div-profile-image"> <img class="profile-image" id="image"> @@ -35,18 +36,16 @@ <div class="edit-data"> <label class="form-label">Status Driver</label> <div class="checkbox"> - <input type="checkbox" name="is-driver" id="driver"> + <input type="checkbox" name="driver" id="driver"> </div> </div> </div> - <div> <div> <a class="back" href="dashboard.php">BACK</a> - <input type="submit" value="SAVE" class="save"> + <input type="submit" value="SAVE" class="save" name="submit"> </div> </div> - </form> </div> </body> diff --git a/view/register.php b/view/register.php index 5a557b7cca96c0ebd1ebed4a7abffafaaab2d1cb..28cce869ea4bd6e9dafe04e39c3c84203966b90a 100644 --- a/view/register.php +++ b/view/register.php @@ -26,7 +26,6 @@ <div class="text-input-with-check"><input type="text" name="username" id="username" onchange="checkUsername()"> </div> - <span id="username-status"></span> <div><img src="../img/check.png" class="check-icon" id="check-icon-username"></div> <div><img src="../img/delete.png" class="delete-icon" id="delete-icon-username"></div> </div>