Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (7)
.idea
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [QSA,L]
\ No newline at end of file
<?php
$env = getenv('DAGOJEK_ENV');
if (!$env || $env == "development") {
$env = "development";
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
require __DIR__.'/../src/app.php';
$App = DagoJek::Instance();
$App->prepareRouting();
$App->Start();
\ No newline at end of file
.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
/**
* DagoJek is a singleton class that representing DagoJek application
*/
class DagoJek {
private $routingTable = array();
private function __construct() {
// empty constructor
}
public static function Instance() {
static $instance = null;
if ($instance === null) {
$instance = new DagoJek();
}
$instance->includeAllController();
return $instance;
}
private function includeAllController() {
foreach (scandir(dirname(__FILE__)."/controller") as $filename) {
$path = dirname(__FILE__)."/controller" . '/' . $filename;
if (is_file($path)) {
require_once $path;
}
}
}
public function prepareRouting() {
require __DIR__.'/route.php';
}
private function getCurrentUri() {
$basepath = implode('/', array_slice(explode('/', $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
$uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
$uri = '/' . trim($uri, '/');
return $uri;
}
public function addRoute($route, $function) {
$data = array(
$route => $function,
);
$this->routingTable += $data;
}
public function Start() {
$base_url = $this->getCurrentUri();
if (array_key_exists ($base_url, $this->routingTable)) {
$this->routingTable[$base_url]();
} else {
die ("404 Page not Found");
}
}
}
<?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
class MainController {
public static function LoginHandler() {
echo "This is login handler";
}
public static function DefaultHandler() {
echo "This is default handler";
}
}
\ 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
<?php
// ---------------------------- LIST OF ALL BASIC ROUTES ----------------------------
$AppInstance = Dagojek::Instance();
$AppInstance->addRoute("/", 'MainController::LoginHandler');
$AppInstance->addRoute("/login", 'MainController::LoginHandler');
$AppInstance->addRoute("/register", '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');
$AppInstance->addRoute("/main/order/finish", '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