From 992535a8b10b162a7671f8e530a311436a4d897f Mon Sep 17 00:00:00 2001
From: aldrichvalentino <aldrich.vh97@gmail.com>
Date: Wed, 4 Oct 2017 23:20:23 +0700
Subject: [PATCH] added preferred location view list

---
 controller/profile.php |  6 ++++--
 css/dashboard.css      |  4 ++++
 js/profile.js          | 15 ++++++++++++++-
 model/user.php         |  8 ++++++++
 view/dashboard.php     | 16 +++++++---------
 5 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/controller/profile.php b/controller/profile.php
index 922bc102..ce4c864d 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 66d72904..7ff2a80e 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 8d0d1aba..2f7374bd 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 34770bd3..6b06751c 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 56273d0b..70754db4 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>
-- 
GitLab