Skip to content
Snippets Groups Projects
Commit f6f24aba authored by Fadhil Imam Kurnia's avatar Fadhil Imam Kurnia
Browse files

Merge branch 'project_structure' into 'master'

Project structure

See merge request !2
parents 56bcd03a 33af4ede
Branches
1 merge request!2Project structure
.idea
.container{
width: 100%;
max-width: 1200px;
margin:auto;
}
.row:before,
.row:after {
content:"";
display: table ;
clear:both;
}
[class*='col-'] {
float: left;
min-height: 1px;
width: 16.66%;
}
.col-1{ width: 16.66%; }
.col-2{ width: 33.33%; }
.col-3{ width: 50%; }
.col-4{ width: 66.66%; }
.col-5{ width: 83.33%; }
.col-6{ width: 100%; }
.tab {
outline: 1px solid #004D40;
padding-top:10px;
padding-bottom:10px;
font-weight: 900;
}
.tab.active {
background-color: #00695C;
color : #FAFAFA;
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
.img-circle {
max-width: 170px;
max-height: 170px;
border-radius: 50%;
}
\ No newline at end of file
<?php
// ----------------------- Setting Up Global Connection -----------------------------------
class DB {
private $_db;
static $_instance;
private function __construct() {
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'superadmin';
$dbname = 'db_dagojek';
$this->_db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
private function __clone(){}
public static function getInstance() {
if (!(self::$_instance instanceof self)) {
self::$_instance = new self();
}
return self::$_instance->_db;
}
}
// ------------------------------ Helper Function ----------------------------------------
function simpleCrypt( $string, $action = 'e' ) {
$secret_key = 'dagojek_key';
$secret_iv = 'dagojek_iv';
$output = false;
$encrypt_method = "AES-256-CBC";
$key = hash( 'sha256', $secret_key );
$iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
if( $action == 'e' ) {
$output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
}
else if( $action == 'd' ){
$output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
}
return $output;
}
\ No newline at end of file
<?php
require_once __DIR__.'/../model/User.php';
require_once __DIR__.'/../model/Driver.php';
class ProfilController {
public static function ProfilHandler() {
// Getting user id from url
if (!isset($_GET['u']) || $_GET['u'] == "") {
echo "Invalid parameter!";
return;
}
// Decrypt user id
$uid = simpleCrypt($_GET['u'], 'd');
// Getting driver profile
$dbconn = DB::getInstance();
$user = Driver::Create($uid, $dbconn);
if (!$user) {
echo "User not found!";
return;
}
require __DIR__.'/../view/profil.php';
}
public static function EditHandler() {
echo "TBD";
}
}
\ No newline at end of file
<?php
class Driver extends User {
public $rating;
public $sumOrder;
public static function Create($id, PDO $dbconn) {
try {
$stmt = $dbconn->prepare("
SELECT id, name, username, email, phone, rating, is_driver AS isDriver, sum_order AS sumOrder
FROM user NATURAL JOIN driver
WHERE id =:id"
);
$stmt->execute(array('id'=>$id));
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetchObject('Driver');
return $result;
} catch (PDOException $e) {
echo "Error : ".$e->getMessage();
return false;
}
}
}
\ No newline at end of file
<?php
class User {
public $id;
public $name;
public $username;
public $email;
public $phone;
public $isDriver;
public static function Create($id, PDO $conn) {
try {
$stmt = $conn->prepare("SELECT * FROM user WHERE id=$id");
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$user = $stmt->fetchObject();
$result = new User($user->id, $user->name, $user->username, $user->email, $user->phone);
$result->isDriver = $user->is_driver;
return $result;
} catch (PDOException $e) {
echo "Error : ".$e->getMessage();
return false;
}
}
}
\ No newline at end of file
......@@ -7,8 +7,8 @@ $AppInstance = Dagojek::Instance();
$AppInstance->addRoute("/", 'MainController::LoginHandler');
$AppInstance->addRoute("/login", 'MainController::LoginHandler');
$AppInstance->addRoute("/register", 'MainController::DefaultHandler');
$AppInstance->addRoute("/main/profil", 'MainController::DefaultHandler');
$AppInstance->addRoute("/main/profil/edit", 'MainController::DefaultHandler');
$AppInstance->addRoute("/main/profil", 'ProfilController::ProfilHandler');
$AppInstance->addRoute("/main/profil/edit", 'ProfilController::EditHandler');
$AppInstance->addRoute("/main/history", 'MainController::DefaultHandler');
$AppInstance->addRoute("/main/order/", 'MainController::DefaultHandler');
$AppInstance->addRoute("/main/order/select", 'MainController::DefaultHandler');
......
<html>
<head>
<title>DAGO-JEK | Profil</title>
<link rel="stylesheet" type="text/css" href="/style.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-3">Logo</div>
<div class="col-3 text-right">
<p>
Hi, <?=$user->username?><br>
Logout
</p>
</div>
</div>
<div class="row">
<div class="col-2 tab text-center">ORDER</div>
<div class="col-2 tab text-center">HISTORY</div>
<div class="col-2 tab text-center active">MY PROFILE</div>
</div>
<div class="row">
<div class="col-5"><h1>MY PROFILE</h1></div>
<div class="col-1 text-right">edit</div>
</div>
<div class="text-center">
<img class="img-circle" src="<?=$user->photo?>"/><br>
<h2>@<?=$user->username?></h2>
<p><?=$user->name?></p>
<?php if ($user->isDriver) : ?>
<p>Driver | <?=$driver_rating?> (<?=$driver_order?> vote<?=($driver_order>1)?'s':''?>)</p>
<?php else : ?>
<p>Non Driver</p>
<?php endif; ?>
<p><?=$user->email?></p>
<p><?=$user->phone?></p>
</div>
<div class="row">
<div class="col-5"><h2>PREFERED LOCATIONS</h2></div>
<div class="col-1 text-right">edit</div>
</div>
<div class="row">
<ul>
<li>Lokasi 1</li>
<li>Lokasi 2</li>
<li>Lokasi 3</li>
<li>Lokasi 4</li>
</ul>
</div>
</div>
</body>
</html>
\ 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