diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..485dee64bcfb48793379b200a1afd14e85a8aaf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/public/main.css b/public/main.css deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000000000000000000000000000000000000..828a05da95303169f9da97ccfc9d2ca25274a37a --- /dev/null +++ b/public/style.css @@ -0,0 +1,51 @@ +.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 diff --git a/src/controller/Controller.php b/src/controller/Controller.php new file mode 100644 index 0000000000000000000000000000000000000000..d417e614a59a86650e41636f57064e2f47d9bd09 --- /dev/null +++ b/src/controller/Controller.php @@ -0,0 +1,53 @@ +<?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 diff --git a/src/controller/ProfilController.php b/src/controller/ProfilController.php new file mode 100644 index 0000000000000000000000000000000000000000..d5a5b9c9d8a24ee4bd3d48051eefe242118bfd1d --- /dev/null +++ b/src/controller/ProfilController.php @@ -0,0 +1,36 @@ +<?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 diff --git a/src/model/Driver.php b/src/model/Driver.php new file mode 100644 index 0000000000000000000000000000000000000000..af1cf7b4e507aa92e42562db2e1f5f1ef4842cca --- /dev/null +++ b/src/model/Driver.php @@ -0,0 +1,27 @@ +<?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 diff --git a/src/model/User.php b/src/model/User.php new file mode 100644 index 0000000000000000000000000000000000000000..780a775e9669f9d0409807a19e80353c97516fbd --- /dev/null +++ b/src/model/User.php @@ -0,0 +1,30 @@ +<?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 diff --git a/src/route.php b/src/route.php index 0b033a3664aaf90ff47110e1a6ed2f17ea3019e6..76edc5e0004fd73322974d8b1de994f3f7081497 100644 --- a/src/route.php +++ b/src/route.php @@ -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'); diff --git a/src/view/profil.php b/src/view/profil.php new file mode 100644 index 0000000000000000000000000000000000000000..fa2297d74c8c95b77399a8f65102e4242aab8b19 --- /dev/null +++ b/src/view/profil.php @@ -0,0 +1,52 @@ +<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