From 172a0b185b95a13db9df7b9e9fa968cd91faecbb Mon Sep 17 00:00:00 2001
From: aldrichvalentino <aldrich.vh97@gmail.com>
Date: Sun, 1 Oct 2017 12:53:42 +0700
Subject: [PATCH] added GET variable for user

---
 controller/transactionController.php |  8 +++++---
 css/history.css                      |  4 ++--
 js/history.js                        |  4 ++--
 js/profile.js                        |  8 +++-----
 view/dashboard.php                   | 17 ++++++++++++-----
 5 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/controller/transactionController.php b/controller/transactionController.php
index 42434ad2..e387c092 100644
--- a/controller/transactionController.php
+++ b/controller/transactionController.php
@@ -30,14 +30,15 @@ if($isDriver) {
     <img class='user-image' src='../img/" . $image . "'/>
     <div class='transaction-info'><div class='transaction-date'>" . $row['date'] . " </div>
     <div class='user-name'>" . $username . "</div>
-    <div class='transaction-city'>" . $row['pickup'] . "=>" . $row['destination'] . "</div>
+    <div class='transaction-city'>" . $row['pickup'] . " to " . $row['destination'] . "</div>
     <div class='transaction-rating'>gave " . $row['rating'] . " star(s) for this order</div>
-    <div class='transaction-comment'>and left comment <br />" . $row['comment'] . " </div></div>
+    <div class='transaction-comment'>and left comment:<blockquote>\"" . $row['comment'] . "\"</blockquote></div></div>
     <div class='hide-button'><button id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</button></div>
     </div>";
             $i++;
         }
     }
+    header('Content-Type: text/xml');
     echo $asDriverCompletedTransaction;
 } else {
     $asUserCompletedTransaction = "";
@@ -59,12 +60,13 @@ if($isDriver) {
     <div class='user-name'>" . $fetched['name'] . "</div>
     <div class='transaction-city'>" . $row['pickup'] . " to " . $row['destination'] . "</div>
     <div class='transaction-rating'>you rated: " . $row['rating'] . "</div>
-    <div class='transaction-comment'>and left comment: <br />" . $row['comment'] . " </div></div>
+    <div class='transaction-comment'>and left comment:<blockquote>\"" . $row['comment'] . "\"</blockquote></div></div>
     <div class='hide-button'><button id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</button></div>
     </div>";
             $i++;
         }
     }
+    header('Content-Type: text/xml');
     echo $asUserCompletedTransaction;
 }
 
diff --git a/css/history.css b/css/history.css
index 829d1571..468dfd1a 100644
--- a/css/history.css
+++ b/css/history.css
@@ -15,7 +15,7 @@
     box-sizing: border-box;
 }
 .transaction-info {
-    width: 60%;
+    width: 65%;
     display: inline-block;
     font-size: initial;
     vertical-align: top;
@@ -35,7 +35,7 @@
     margin: 5px 0;
 }
 .hide-button {
-    width: 20%;
+    width: 15%;
     text-align: right;
     display: inline-block;
     font-size: initial;
diff --git a/js/history.js b/js/history.js
index 163f82b6..a53708ee 100644
--- a/js/history.js
+++ b/js/history.js
@@ -1,10 +1,10 @@
 function getAllTransaction(isDriver){
-    //TODO: minta id dari session!!
-    var id = 1;
+    var id = sessionid;
     var xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function () {
         if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
             document.getElementById('driver-info').innerHTML = xmlhttp.responseText;
+            //console.log(result.getElementById('transaction-id').innerHTML);
         }
     };
     xmlhttp.open('GET', '../controller/transactionController.php?id=' + id + '&driver=' + isDriver,true);
diff --git a/js/profile.js b/js/profile.js
index 5f4c2ba1..8d0d1aba 100644
--- a/js/profile.js
+++ b/js/profile.js
@@ -1,4 +1,5 @@
 function getUserProfile(){
+    var id = sessionid;
     var xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function () {
         if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
@@ -9,7 +10,7 @@ function getUserProfile(){
             var phone = result.getElementsByTagName('phone')[0].childNodes[0].nodeValue;
             var image =result.getElementsByTagName('image')[0].childNodes[0].nodeValue;
 
-            document.getElementById('username').innerHTML = 'Hi, ' + username + '!';
+            document.getElementById('username').innerHTML = 'Hello, ' + name + '!';
             document.getElementById('profile-username').innerHTML = '@' + username;
             document.getElementById('name').innerHTML = name;
             document.getElementById('email').innerHTML = email;
@@ -17,10 +18,7 @@ function getUserProfile(){
             document.getElementById('user-image').style.backgroundImage = 'url(../img/' + image + ')';
         }
     };
-    //var userid = 1;
-    xmlhttp.open('GET', '../controller/profile.php?id=1', true);
+    xmlhttp.open('GET', '../controller/profile.php?id=' + id, true);
     xmlhttp.send();
-
-
 }
 
diff --git a/view/dashboard.php b/view/dashboard.php
index 10165a7c..83f1f977 100644
--- a/view/dashboard.php
+++ b/view/dashboard.php
@@ -1,14 +1,24 @@
+<?php
+    session_start();
+    $_SESSION['id'] = 1;
+    $_SESSION['name'] = 'Pikachu';
+?>
+
 <html>
 <head>
     <title>User Dashboard</title>
     <link href="../css/primary.css" type="text/css" rel="stylesheet" />
     <link href="../css/dashboard.css" type="text/css" rel="stylesheet" />
     <link href="../css/history.css" type="text/css" rel="stylesheet" />
+    <script>
+        //send session id to JS files
+        var sessionid = "<?php echo $_GET['id']; ?>";
+    </script>
     <script src="../js/dashboard.js"></script>
     <script src="../js/profile.js"></script>
     <script src="../js/history.js"></script>
 </head>
-<body>
+<body onpageshow="getUserProfile()">
     <div class="container">
         <div class="header">
             <div class="logo"><img src="../img/logo.png" /></div>
@@ -19,7 +29,7 @@
         </div>
         <div class="menu">
             <button class="submenu" id="order" onclick="order_clicked()">ORDER</button>
-            <button class="submenu" id="history" onclick="history_clicked();">HISTORY</button>
+            <button class="submenu" id="history" onclick="history_clicked(); getAllTransaction(1)">HISTORY</button>
             <button class="submenu selected" id="profile" onclick="getUserProfile(); profile_clicked();">PROFILE</button>
         </div>
 
@@ -65,9 +75,6 @@
                 </ul>
             </div>
         </section>
-
-
     </div>
-
 </body>
 </html>
\ No newline at end of file
-- 
GitLab