diff --git a/controller/profile.php b/controller/profile.php index 922bc10243c289cdc1500425e7ff94084202136d..ce4c864d0d3b2e83dc3831cefe0e5ea800b8cb97 100644 --- a/controller/profile.php +++ b/controller/profile.php @@ -3,11 +3,10 @@ /* Model */ include "../model/user.php"; -//TODO: tambahin redirect klo get kosong - $user = new User; $user_id = $_GET['id']; $result = $user->getUserById($user_id); +$locations = $user->getPreferredLocation($user_id); header('Content-Type: text/xml'); $xml = '<user>'; while($row = mysqli_fetch_array($result)){ @@ -15,6 +14,9 @@ while($row = mysqli_fetch_array($result)){ '</username><email>' . $row['email'] . '</email><image>' . $row['image'] . '</image><phone>' . $row['phone'] . '</phone><driver>' . $row['isDriver'] . '</driver>'; } +while($row = mysqli_fetch_array($locations)){ + $xml = $xml . '<location>'. $row['location'] .'</location>'; +} $xml = $xml . '</user>'; print $xml; diff --git a/css/dashboard.css b/css/dashboard.css index 66d729046577f9eabb151d4db17adc74fab9f183..7ff2a80ef56b9f8ff8f9555ee94a70418acba4c7 100644 --- a/css/dashboard.css +++ b/css/dashboard.css @@ -122,4 +122,8 @@ #email, #phone { font-size: 1.5rem; display: inline-block; +} +#user-location li { + font-size: 1.2rem; + margin-bottom: 5px; } \ No newline at end of file diff --git a/js/profile.js b/js/profile.js index 8d0d1aba7dab7ba339d6d3a03d5797b03d95bdcd..2f7374bd35b5f241fe496e1e936146fe760245bc 100644 --- a/js/profile.js +++ b/js/profile.js @@ -8,7 +8,8 @@ function getUserProfile(){ var name = result.getElementsByTagName('name')[0].childNodes[0].nodeValue; var email = result.getElementsByTagName('email')[0].childNodes[0].nodeValue; var phone = result.getElementsByTagName('phone')[0].childNodes[0].nodeValue; - var image =result.getElementsByTagName('image')[0].childNodes[0].nodeValue; + var image = result.getElementsByTagName('image')[0].childNodes[0].nodeValue; + var arrayLocation = result.getElementsByTagName('location'); document.getElementById('username').innerHTML = 'Hello, ' + name + '!'; document.getElementById('profile-username').innerHTML = '@' + username; @@ -16,6 +17,18 @@ function getUserProfile(){ document.getElementById('email').innerHTML = email; document.getElementById('phone').innerHTML = phone; document.getElementById('user-image').style.backgroundImage = 'url(../img/' + image + ')'; + var listOfLocation = document.getElementById('user-location'); + console.log(listOfLocation.childElementCount); + while(listOfLocation.hasChildNodes()){ + listOfLocation.removeChild(listOfLocation.lastChild); + } + for(i = 0; i < arrayLocation.length; i++){ + var loc = arrayLocation[i].firstChild.nodeValue; + var singleList = document.createElement('li'); + singleList.style.marginLeft = i*20; + singleList.innerHTML = loc; + listOfLocation.appendChild(singleList); + } } }; xmlhttp.open('GET', '../controller/profile.php?id=' + id, true); diff --git a/model/user.php b/model/user.php index 34770bd3724c7b89458ed166d115fbbde8a7077d..6b06751c0e0152163b6d36a1349f728184bc5e9e 100644 --- a/model/user.php +++ b/model/user.php @@ -91,4 +91,12 @@ class User { mysqli_close($con); return $result; } + function getPreferredLocation($id){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $query = "SELECT location FROM pref_loc WHERE id=" . $id; + $result = mysqli_query($con,$query); + mysqli_close($con); + return $result; + } } \ No newline at end of file diff --git a/view/dashboard.php b/view/dashboard.php index 56273d0b04e90efb30a96e9c8e5efec6da4fe9ac..70754db41eca68339a40a923d43d17cc2917cd4c 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -49,7 +49,9 @@ <section class="profile-wrapper"> <div class="sub-header"> <div class="sub-header-heading"><h1>MY PROFILE</h1></div> - <div class="edit-icon"><img src="../img/pencil.png" /></div> + <div class="edit-icon"> + <a href="../view/edit-profile.php?id=<?php echo $_GET['id'] ?>"><img src="../img/pencil.png" /></a> + </div> </div> <div class="user-profile"> <div id="user-image"></div> @@ -61,15 +63,11 @@ </div> <div class="sub-header"> <div class="sub-header-heading"><h1>PREFERRED LOCATION</h1></div> - <div class="edit-icon"><img src="../img/pencil.png" /></div> - </div> - <div class="user-location"> - <ul type="square" id="user-location"> - <li>a</li> - <li>b</li> - <li>c</li> - </ul> + <div class="edit-icon"> + <a href="../"><img src="../img/pencil.png" /> + </div> </div> + <div class="user-location"><ul id="user-location"></ul></div> </section> </div> </body>