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
Showing
with 764 additions and 0 deletions
<?php
namespace MotaRaido\Core\Database;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
use \MotaRaido\Core\Database\Connector;
use \Closure;
class Query
{
private $dbh;
public function __construct(Connector $dbh)
{
$this->dbh = $dbh;
$this->dbh->setAttribute(Connector::ATTR_ERRMODE, Connector::ERRMODE_EXCEPTION);
$this->dbh->forceRollback();
}
public function transaction(Closure $func) {
$this->dbh->createTransaction($func);
}
public function select($tableName, $where)
{
$sql = $this->createSelectQuery($tableName, $where);
$whereParams = $this->getWhereParameters($where);
$stmp = $this->dbh->prepare($sql);
$stmp->execute($whereParams);
return $stmp->fetchAll();
}
public function insert($tableName, $values)
{
$sql = $this->createInsertQuery($tableName, $values);
$stmp = $this->dbh->prepare($sql);
$out = $stmp->execute($values);
return $out;
}
public function update($tableName, $values, $where)
{
$sql = $this->createUpdateQuery($tableName, $values, $where);
$whereParams = $this->getWhereParameters($where);
$stmp = $this->dbh->prepare($sql);
$out = $stmp->execute(array_merge($values, $whereParams));
return $out;
}
public function delete($tableName, $where)
{
$sql = $this->createDeleteQuery($tableName, $where);
$whereParams = $this->getWhereParameters($where);
$stmp = $this->dbh->prepare($sql);
$out = $stmp->execute($whereParams);
return $out;
}
protected function getWhereParameters($where)
{
$whereParams = array();
foreach ($where as $key => $value) {
$whereParams[":W_{$key}"] = $value;
}
return $whereParams;
}
protected function createSelectQuery($table, $where)
{
return "SELECT * FROM " . $table . $this->createSqlWhere($where);
}
protected function createUpdateQuery($table, $values, $where)
{
$sqlValues = array();
foreach (array_keys($values) as $key) {
$sqlValues[] = "{$key} = :{$key}";
}
return "UPDATE {$table} SET " . implode(', ', $sqlValues) . $this->createSqlWhere($where);
}
protected function createInsertQuery($table, $values)
{
$sqlValues = array();
foreach (array_keys($values) as $key) {
$sqlValues[] = ":{$key}";
}
return "INSERT INTO {$table} (" . implode(', ', array_keys($values)) . ") VALUES (" . implode(', ', $sqlValues) . ")";
}
protected function createDeleteQuery($table, $where)
{
return "DELETE FROM {$table}" . $this->createSqlWhere($where);
}
protected function createSqlWhere($where)
{
if (count((array) $where) == 0) return null;
$whereSql = array();
foreach ($where as $key => $value) {
$whereSql[] = "{$key} = :W_{$key}";
}
return ' WHERE ' . implode(' AND ', $whereSql);
}
}
\ No newline at end of file
<?php
namespace MotaRaido\Core;
if (!defined('MOTAFW')) {
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
class ErrorMessage
{
public static function get($code = null)
{
$text = 'OK';
if ($code !== null) {
switch ($code) {
case 100: $text = 'Continue'; break;
case 101: $text = 'Switching Protocols'; break;
case 200: $text = 'OK'; break;
case 201: $text = 'Created'; break;
case 202: $text = 'Accepted'; break;
case 203: $text = 'Non-Authoritative Information'; break;
case 204: $text = 'No Content'; break;
case 205: $text = 'Reset Content'; break;
case 206: $text = 'Partial Content'; break;
case 300: $text = 'Multiple Choices'; break;
case 301: $text = 'Moved Permanently'; break;
case 302: $text = 'Moved Temporarily'; break;
case 303: $text = 'See Other'; break;
case 304: $text = 'Not Modified'; break;
case 305: $text = 'Use Proxy'; break;
case 400: $text = 'Bad Request'; break;
case 401: $text = 'Unauthorized'; break;
case 402: $text = 'Payment Required'; break;
case 403: $text = 'Forbidden'; break;
case 404: $text = 'Not Found'; break;
case 405: $text = 'Method Not Allowed'; break;
case 406: $text = 'Not Acceptable'; break;
case 407: $text = 'Proxy Authentication Required'; break;
case 408: $text = 'Request Time-out'; break;
case 409: $text = 'Conflict'; break;
case 410: $text = 'Gone'; break;
case 411: $text = 'Length Required'; break;
case 412: $text = 'Precondition Failed'; break;
case 413: $text = 'Request Entity Too Large'; break;
case 414: $text = 'Request-URI Too Large'; break;
case 415: $text = 'Unsupported Media Type'; break;
case 500: $text = 'Internal Server Error'; break;
case 501: $text = 'Not Implemented'; break;
case 502: $text = 'Bad Gateway'; break;
case 503: $text = 'Service Unavailable'; break;
case 504: $text = 'Gateway Time-out'; break;
case 505: $text = 'HTTP Version not supported'; break;
default:
exit('Unknown http status code "' . htmlentities($code) . '"');
break;
}
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
// header($protocol . ' ' . $code . ' ' . $text);
$GLOBALS['http_response_code'] = $code;
$GLOBALS['http_response_code_message'] = $text;
} else {
$code = (isset($GLOBALS['http_response_code']) ? $GLOBALS['http_response_code'] : 200);
}
return [
'code' => $code,
'message' => $text
];
}
}
<?php
namespace MotaRaido\Core;
use \MotaRaido\Core\ErrorMessage;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
class Route {
private static $httpAction;
public static function setHttpAction($action) {
self::$httpAction = $action;
}
public static function get_uri() {
if (isset($_SERVER['REQUEST_URI'])) {
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
} else {
return "";
}
return '/' . ltrim($uri, '/');
}
public static function add($pattern_uri, $action = null, $middleware = null) {
self::setHttpAction(function($action) {
echo $action['code'] . ' - ' . $action['message'];
});
$request_uri = self::get_uri();
preg_match_all('/#([0-9a-zA-Z_]+)/', $pattern_uri, $names, PREG_PATTERN_ORDER);
$names = $names[0];
$pattern_uri_regex = preg_replace_callback('/#[[0-9a-zA-Z_]+/', array(__CLASS__, 'uri_regex'), $pattern_uri);
$pattern_uri_regex .= '/?';
$params = array();
if (preg_match('@^' . $pattern_uri_regex . '$@', $request_uri, $values)) {
array_shift($values);
foreach($names as $index => $value) {
$params[substr($value, 1)] = urldecode($values[$index]);
}
if (is_callable($action)) {
if(is_callable($middleware)) {
if(call_user_func($middleware)) {
call_user_func_array($action, array_values($params));
} else {
call_user_func_array(self::$httpAction, [ErrorMessage::get('401')]);
}
} else {
call_user_func_array($action, array_values($params));
}
}
}
return $params;
}
public static function uri_regex($matches) {
return '([a-zA-Z0-9_\+\-%]+)';
}
}
\ No newline at end of file
<?php
namespace MotaRaido\Core;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
use \MotaRaido\Core\Config;
class View
{
protected $data = array();
function render($view, $template = true) {
ob_start();
include_once $template ? Config::get('template')['headerWithMenu'] : Config::get('template')['header'];
include_once $view;
if($template) include_once Config::get('template')['footer'];
$str = ob_get_contents();
ob_end_clean();
echo $str;
}
public function __get($name)
{
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
}
}
function include($key, $val) {
ob_start();
require_once $val;
$str = ob_get_contents();
ob_end_clean();
$this->data[$key] = $str;
}
function assign($key, $val) {
if(!is_array($val)) $val = \htmlspecialchars($val);
$this->data[$key] = $val;
}
}
\ No newline at end of file
<?php
namespace MotaRaido\Login;
use \MotaRaido\Core\View;
use \MotaRaido\Core\Route;
if (!defined('MOTAFW')) {
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
Route::add('/', function () {
$view = new View();
$view->assign('style', CSS . "style.css");
$view->assign('title', 'Login');
$view->assign('script', JS . "app.js");
$view->render(__DIR__ . '/Login.view.php', false);
});
Route::add('/login', function () {
$view = new View();
$view->assign('style', CSS . "style.css");
$view->assign('title', 'Login');
$view->assign('script', JS . "app.js");
$view->render(__DIR__ . '/Login.view.php', false);
});
Route::add('/login/validation', function() use ($query) {
$query->transaction(function() use ($query) {
$username = $_POST['username'];
$password = $_POST['password'];
$usrData = $query->select('user', []);
$pwdData = $query->select('user', []);
$found = false;
foreach($usrData as $record) {
if($record[0] == $username && $record[1] == $password){
$found = true;
break;
}
}
if ($found) {
header('Location: /profile/' . $username);
} else {
header('Location: /login');
}
});
});
\ No newline at end of file
<?php
namespace MotaRaido\Login;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<section class="content-layout">
<header class="title">
<div>
<hr>
<h1><?php echo $this->title; ?></h1>
<hr>
</div>
</header>
<section class="form-layout">
<form action="/login/validation" method="post" name="loginform" onsubmit="return loginValidation();">
<div class="form-input">
<div>Username</div>
<input id="username" type="text" name="username">
</div>
<div class="form-input">
<div>Password</div>
<input type="password" name="password">
</div>
<div id="button-layout">
<div>
<a href="/signup">Don't have an account?</a>
</div>
<input id="register-button" type="submit" value="GO!">
</div>
</form>
</section>
</section>
<?php
namespace MotaRaido\Menu;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<div class="footer">
<div>Winarto <br /> 13515061</div>
<div>Ray Andrew <br /> 13515073</div>
<div>Adrian HP <br /> 13515091</div>
</div>
</body>
</html>
\ No newline at end of file
<?php
namespace MotaRaido\Menu;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<!DOCTYPE html>
<head>
<title><?php echo $this->title; ?></title>
<link rel="stylesheet" type="text/css" href=<?php echo CSS . 'style.css?time=' . date("H:i:s"); ?>></link>
<link rel="stylesheet" type="text/css" href=<?php echo CSS . 'profile.css?time=' . date("H:i:s"); ?>></link>
<script type='text/javascript' src=<?php echo JS . 'app.js?time=' . date("H:i:s"); ?>></script>
<script type='text/javascript' src=<?php echo JS . 'signup.js?time=' . date("H:i:s"); ?>></script>
</head>
<body>
\ No newline at end of file
<?php
namespace MotaRaido\Menu;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<!DOCTYPE html>
<head>
<title><?php echo $this->title; ?></title>
<link rel="stylesheet" type="text/css" href=<?php echo CSS . 'style.css?time=' . date("H:i:s"); ?>></link>
<link rel="stylesheet" type="text/css" href=<?php echo CSS . 'profile.css?time=' . date("H:i:s"); ?>></link>
<script type='text/javascript' src=<?php echo JS . 'app.js'; ?>></script>
</head>
<body>
<div>
<header class="header-box">
<div class="col-header-left">
<div>
<span class='logo-title'>MotoRaido</span><br />
<span class='tagline'>Anata to issho ni noru mōtā</span>
</div>
</div>
<div class="col-header-right">
<div>
Hi, <b><?php echo $this->user; ?></b> !
</div>
<div>
<a href="/login">Logout</a>
</div>
</div>
</header>
<div class='menu'>
<div class="menu-column"></div>
<div class="menu-column"></div>
<div class="menu-column"></div>
<div id="orderheader" class="menu-cell"><a href="/order/<?php echo $this->user; ?>" class="text-link">ORDER</a></div>
<div id="historyheader" class="menu-cell"><a href="/history/<?php echo $this->user; ?>" class="text-link">HISTORY</a></div>
<div id="profileheader" class="menu-cell"><a href="/profile/<?php echo $this->user; ?>" class="text-link">MY PROFILE</a></div>
</div>
</div>
\ No newline at end of file
<?php
namespace MotaRaido\Menu\History;
use \MotaRaido\Core\View;
use \MotaRaido\Core\Route;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
Route::add('/history/#user', function($user) use ($query) {
$view = new View();
$userData = $query->select('history', ['usernameUser' => $user, 'ishide' => false]);
$driverData = $query->select('history', ['usernameDriver' => $user, 'ishide' => false]);
$view->assign('user', $user);
$view->assign('title', 'History');
$view->assign('image', IMG);
$view->assign('historyUser', $userData);
$view->assign('historyDriver', $driverData);
$view->assign('script', JS . "history.js?time=" . date("H:i:s"));
$view->render(__DIR__ . '/History.view.php');
});
Route::add('/history/#user/update/#driver/#date', function($user, $driver, $date) use ($query) {
$query->transaction(function() use ($query, $user, $driver, $date) {
$query->update('history', ['ishide' => 1], ['usernameUser' => $user, 'usernameDriver' => $driver, 'dateOrder' => $date]);
});
header('Location: /history/' . $user);
});
\ No newline at end of file
<?php
namespace MotaRaido\Menu\Profile;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<?php echo $this->header; ?>
<div class="subtitle-cont subtitle-history">
TRANSACTION HISTORY
</div>
<div class="body-container">
<div class='menu'>
<div class="menu-column"></div>
<div class="menu-column"></div>
<div id="user-his" class="menu-cell" onclick="tabActive('user');">MY PREVIOUS ORDERS</div>
<div id="driver-his" class="menu-cell" onclick="tabActive('driver');">DRIVER HISTORY</div>
</div>
</div>
<div id="history-container">
<ol class="history-list order-list">
<?php foreach($this->historyUser as $history): ?>
<li class="list-text-his">
<div class="history-pic-div">
<img class="profile-pic-his" src=<?php echo $this->image . $history[1]; ?> alt="">
</div>
<span class="hide">
<a href=<?php echo "/history/". $history[0] . "/update/" . $history[1] . "/" . rawurlencode($history[4]); ?>>HIDE</a>
</span>
<div class="his-text">
<div class="date-his"><?php echo htmlentities($history[4]); ?></div>
<div class="name-his"><b><?php echo $history[1]; ?></b></div>
<div><?php echo $history[5]; ?> - <?php echo $history[6]; ?></div>
<div>
You rated : ★<?php echo $history[2]; ?>
<div>
<div>
You commented:
<div class="comment">
<?php echo $history[3]; ?>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
<ol class="history-list driver-list">
<?php foreach($this->historyDriver as $history): ?>
<li class="list-text-his">
<div class="history-pic-div">
<img class="profile-pic-his" src=<?php echo $this->image . $history[0]; ?> alt="" />
</div>
<span class="hide">
<a href=<?php echo "/history/". $history[0] . "/update/" . $history[1] . "/" . rawurlencode($history[4]); ?>>HIDE</a>
</span>
<div class="his-text">
<div class="date-his"><?php echo $history[4]; ?></div>
<div><b><?php echo $history[0]; ?></b></div>
<div><?php echo $history[5]; ?> - <?php echo $history[6]; ?></div>
<div>
gave <span><?php echo $history[2]; ?></span> stars for this order
<div>
<div>
and left comment:
<div class="comment">
<?php echo $history[3]; ?>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
</div>
<script src=<?php echo $this->script; ?>></script>
<?php echo $this->footer; ?>
\ No newline at end of file
<?php
namespace MotaRaido\Menu\Order;
use \MotaRaido\Core\View;
use \MotaRaido\Core\Route;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
Route::add('/order/#user/completeorder', function($user) use ($query) {
$driver = $_POST['driver-username'];
$from = $_POST['pickLoc'];
$dest = $_POST['dest'];
$driverInfo = $query->select('user',['username' => $driver]);
$view = new View();
$view->assign('title', 'Complete Order');
$view->assign('image', IMG . $driver);
$view->assign('from', $from);
$view->assign('dest', $dest);
$view->assign('user', $user);
$view->assign('driver', $driver);
$view->assign('drivername', $driverInfo[0][2]);
$view->render(__DIR__ . '/CompleteOrder.view.php');
});
Route::add('/order/#user/completeorder/finish', function($user) use ($query) {
$query->transaction(function() use ($query,$user) {
header('Location: /order/' . $user);
$name = $_POST['driver'];
$rating = $_POST['rating'];
$comment = $_POST['comment'];
$from = $_POST['from'];
$dest = $_POST['dest'];
$query->insert('history', ['usernameUser' => $user, 'usernameDriver' => $name, 'rating' => $rating, 'comment' => $comment, 'dateOrder' => date("Y-m-d H:i:s"), 'pickup' => $from, 'destination' => $dest, 'ishide' => 0]);
});
});
\ No newline at end of file
<?php
namespace MotaRaido\Menu\Order;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<?php echo $this->header; ?>
<div class="edit-profile-header">
Make an order
</div>
<div class="progress-container">
<div class="progress">
<div class="progress-num">1</div> Select Destination
</div>
<div class="progress">
<div class="progress-num">2</div> Select a driver
</div>
<div class="progress selected">
<div class="progress-num selected">3</div> Complete your order
</div>
</div>
<div class="edit-profile-header">
How was it?
</div>
<form action="/order/<?php echo $this->user; ?>/completeorder/finish" method="post" name="completeorder-form">
<div class="completeorder-container">
<input type='hidden' name='driver' value='<?php echo $this->driver; ?>'>
<input type='hidden' name='from' value='<?php echo $this->from; ?>'>
<input type='hidden' name='dest' value='<?php echo $this->dest; ?>'>
<img class="driver-completeorder-pic" src="<?php echo $this->image; ?>" alt="">
<div class="driver-name-disp">@<?php echo $this->driver; ?></div>
<div class="driver-fullname-disp"><?php echo $this->drivername; ?></div>
<span class="starRating">
<input id="rating5" type="radio" name="rating" value="5">
<label for="rating5">5</label>
<input id="rating4" type="radio" name="rating" value="4">
<label for="rating4">4</label>
<input id="rating3" type="radio" name="rating" value="3">
<label for="rating3">3</label>
<input id="rating2" type="radio" name="rating" value="2">
<label for="rating2">2</label>
<input id="rating1" type="radio" name="rating" value="1">
<label for="rating1">1</label>
</span>
<textarea cols="5" placeholder="Your comment..." name="comment"></textarea>
</div>
<div class="right-align">
<input class="accept-button select-driver-btn completeorder-btn" type="submit" value="Complete&#13;&#10;Order">
</div>
</form>
<?php
namespace MotaRaido\Menu\Order;
use \MotaRaido\Core\View;
use \MotaRaido\Core\Route;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
Route::add('/order/#user', function($user) use ($query) {
$query->transaction(function() use ($query, $user) {
$view = new View();
$view->assign('title', 'Order');
$view->assign('user', $user);
$view->render(__DIR__ . '/Order.view.php');
});
});
\ No newline at end of file
<?php
namespace MotaRaido\Menu\Order;
if (!defined('MOTAFW'))
{
echo 'This file can only be called via the main index.php file, and not directly';
exit();
}
?>
<div class="container">
<div class="edit-profile-header">
Make an order
</div>
<div class="progress-container">
<div class="progress selected">
<div class="progress-num">1</div> Select Destination
</div>
<div class="progress">
<div class="progress-num">2</div> Select a driver
</div>
<div class="progress">
<div class="progress-num">3</div> Complete your order
</div>
</div>
<form action=<?php echo "/order/" . $this->user . "/selectdriver"; ?> method='post'>
<div class="edit-profile-btm">
<div class="form-input">
<label for="pick-point">Picking point</label>
<input class="ep-textarea" type="text" name="pick-point" />
</div>
<div class="form-input">
<label for="destination">Destination</label>
<input class="ep-textarea" type="text" name="destination" />
</div>
<div class="form-input">
<label for="pref-driver">Preferred Driver</label>
<input class="ep-textarea" type="text" name="pref-driver" placeholder="(Optional)"/>
</div>
<div class="right-align">
<input class="accept-button select-driver-btn" id="save-profile" type="submit" value="Next" />
</div>
</div>
</form>
</div>
\ No newline at end of file