Skip to content
Snippets Groups Projects
Commit 911c42ef authored by Aldrich Valentino Halim's avatar Aldrich Valentino Halim
Browse files

transaction model and controller

parent 4a1a9828
1 merge request!42Projekers - 13515051 - Girvandi Ilyas
<?php
/* Model */
include "../model/order.php";
//TODO: tambahin redirect klo get kosong
$user = new Order();
$result = $user->getAllTransaction();
header('Content-Type: text/xml');
$xml = '<transaction>';
while($row = mysqli_fetch_array($result)){
$xml = $xml . '<transactionid>' . $row['transaction_id'] . '</transactionid><driverid>' . $row['driver_id']
. '</driverid><userid>' . $row['user_id']. '</userid><pickup>' . $row['pickup'] . '</pickup><destination>'.
$row['destination'] .'</destination><rating>' . $row['rating'] . '</rating><comment>'. $row['comment'].
'</comment><date>'. $row['date'] .'</date>';
}
$xml = $xml . '</transaction>';
echo $xml;
function getAllTransaction(){
//TODO: minta id dari session!!
var id = 2;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
var get = xmlhttp.responseXML;
var transactions = get.getElementsByTagName('transaction');
for(i = 0; i < transactions.length; i++){
if(transactions[i].getElementsByTagName('driverid')[0].childNodes[0].nodeValue == id){
var dateElement = document.createElement('div');
dateElement.classList.add('transaction-date');
var txt = transactions[i].getElementsByTagName('date')[0].childNodes[0].nodeValue;
var temp = txt.split("-");
var date = new Date(temp[0], txt[1], txt[2]);
dateElement.innerHTML = date.toDateString();
var cityElement = document.createElement('div');
cityElement.classList.add('transaction-city');
txt = transactions[i].getElementsByTagName('pickup')[0].childNodes[0].nodeValue;
txt = txt + '->';
txt = txt + transactions[i].getElementsByTagName('destination')[0].childNodes[0].nodeValue;
cityElement.innerHTML = txt;
var ratingElement = document.createElement('div');
ratingElement.classList.add('transaction-rating');
txt = 'gave ';
txt = txt + transactions[i].getElementsByTagName('rating')[0].childNodes[0].nodeValue;
txt = txt + ' star(s) for this order';
ratingElement.innerHTML = txt;
var commentElement = document.createElement('div');
commentElement.classList.add('transaction-comment');
txt = 'and left a comment <br />';
txt = txt + transactions[i].getElementsByTagName('comment')[0].childNodes[0].nodeValue;
commentElement.innerHTML = txt;
var singleTransaction = document.createElement('div');
singleTransaction.classList.add('single-transaction');
singleTransaction.appendChild(dateElement);
singleTransaction.appendChild(cityElement);
singleTransaction.appendChild(ratingElement);
singleTransaction.appendChild(commentElement);
singleTransaction.appendChild(document.createElement('button'));
document.getElementById('driver-info').appendChild(singleTransaction);
}
}
}
};
xmlhttp.open('GET', '../controller/transactionController.php',true);
xmlhttp.send();
}
<?php
class Order {
function getAllTransaction(){
$con = mysqli_connect('localhost','root', '', 'projekers');
mysqli_select_db($con, 'projekers');
$sql = "SELECT * FROM transaction";
$result = mysqli_query($con, $sql);
mysqli_close($con);
return $result;
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment