Initial commit. Basic and market orders functionality complete

This commit is contained in:
abhishek_almighty 2018-05-08 08:58:01 +05:30
commit fe5bfd71f9
29 changed files with 7261 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
vendor/
.idea/
includes/config.php

View File

@ -0,0 +1,49 @@
<?php
require_once '../includes/imp_files.php';
if (isset($_POST['task']) && trim($_POST['task'])=='run_OrderMatchingAlgorithm') {
if (isset($OrderClass, $UserClass, $_POST['sel1'], $_POST['sel2'])) {
$slc1 = trim($_POST['sel1']);
$slc2 = trim($_POST['sel2']);
if ($slc1 == "" || $slc2 == "") {return;}
$refresh_orders = $OrderClass->OrderMatchingService($_POST['sel1'], $_POST['sel2']);
/*If user is logged in user send him messages, if any*/
if (checkLoginStatus()) {
$std = new stdClass();
$std->user = null;
$std->order = null;
$std->error = false;
$std->msg = null;
if (isset($user_id)) {
$validate_user = $UserClass->check_user($user_id);
if($validate_user == "" || empty($validate_user)) {
$std->error = true;
$std->msg = "No such user exist. Please login again.";
echo json_encode($std);
return false;
}
$std->user = $validate_user;
$std->order = $refresh_orders;
$std->error = false;
$std->msg = "userLoggedIn";
echo json_encode($std);
} else {
return false;
}
}
}
} else {
return false;
}

102
ajax/pending_orders.php Normal file
View File

@ -0,0 +1,102 @@
<?php
require_once '../includes/imp_files.php';
if (!checkLoginStatus()) {
return false;
}
if (isset($_POST['subject']) && trim($_POST['subject'])=='placeOrder') {
$std = new stdClass();
$std->user = null;
$std->order = null;
$std->error = false;
$std->msg = null;
if (isset($_POST['sel1'], $_POST['qty'], $_POST['price'], $_POST['sel2'], $_POST['bs_rad'], $_POST['is_mkt'])) {
$WantAssetTypeId = trim($_POST['sel1']);
$OfferAssetTypeId = trim($_POST['sel2']);
$qty = (float) trim($_POST['qty']);
$price = (float) trim($_POST['price']);
$buy_sell = trim($_POST['bs_rad']);
$is_mkt = (bool) trim($_POST['is_mkt']);
$orderStatusId = 2; // 0 -> cancelled; 1 -> complete; 2 -> pending
if($WantAssetTypeId == '') {
$std->error = true;
$std->msg = "Please select first Blockchain contract.";
echo json_encode($std);
return false;
}
if($OfferAssetTypeId == '') {
$std->error = true;
$std->msg = "Please select second Blockchain contract.";
echo json_encode($std);
return false;
}
if($qty == '' || $qty < 0) {
$std->error = true;
$std->msg = "Please provide a valid quantity to be traded.";
echo json_encode($std);
return false;
}
if (!$is_mkt) {
if($price == '' || $price < 1) {
$std->error = true;
$std->msg = "Please provide a valid price. Price cannot be less than $1.";
echo json_encode($std);
return false;
}
}
if ($buy_sell=='ex-buy') {
$orderTypeId = 0; // It is a buy
$order_type = 'm-buy'; // for market req
$total_trade_val = $qty * $price;
} elseif($buy_sell=='ex-sell') {
$orderTypeId = 1; // It is a sell
$order_type = 'm-sell'; // for market req
$total_trade_val = $qty;
} else {
$std->error = true;
$std->msg = "Invalid Buy or Sell order. Please choose Buy or Sell to proceed.";
echo json_encode($std);
return false;
}
$place_order = "";
$validate_user = "";
if (isset($UserClass, $OrderClass)) {
$validate_user = $UserClass->check_user($user_id);
if($validate_user == "" || empty($validate_user)) {
$std->error = true;
$std->msg = "No such user exist. Please login again.";
echo json_encode($std);
return false;
}
if ($is_mkt) {
$place_order = $OrderClass->market_order($order_type, $qty, $OfferAssetTypeId, $WantAssetTypeId);
} else {
$place_order = $OrderClass->insert_pending_order($orderTypeId, $qty, $price, $orderStatusId, $OfferAssetTypeId, $WantAssetTypeId);
}
}
$std->user = $validate_user;
$std->order = $place_order;
$std->error = false;
$std->msg = "Order placed successfully.";
echo json_encode($std);
return false;
}
$std->error = true;
$std->msg = "Please fill all the fields.";
echo json_encode($std);
return false;
}

29
ajax/refresh_table.php Normal file
View File

@ -0,0 +1,29 @@
<?php
require_once '../includes/imp_files.php';
if (isset($_POST['task'], $_POST['bc1'], $_POST['bc2']) && trim($_POST['task'])=='refresh') {
$bc1 = $_POST['bc1'];
$bc2 = $_POST['bc2'];
$std = new stdClass();
$std->buys = null;
$std->sells = null;
$std->message = array();
$std->error = true;
if (isset($OrderClass, $UserClass)) {
$buy_list = $OrderClass->get_top_buy_sell_list(TOP_BUYS_TABLE, $bc1, $bc2, $asc_desc='DESC'); // buy
$sell_list = $OrderClass->get_top_buy_sell_list(TOP_SELLS_TABLE, $bc1, $bc2, $asc_desc='ASC'); // sell
$std->buys = $buy_list;
$std->sells = $sell_list;
$std->error = false;
}
echo json_encode($std);
} else {
return false;
}

1250
classes/Orders.php Normal file

File diff suppressed because it is too large Load Diff

2949
classes/PHPMailer.php Normal file

File diff suppressed because it is too large Load Diff

84
classes/SendMail.php Normal file
View File

@ -0,0 +1,84 @@
<?php
/**
* Created by PhpStorm.
* User: user
* Date: 07-Jul-16
* Time: 9:23 PM
*/
class SendMail extends Orders {
private $reciever_email = array();
public $errors = array();
private $from = null;
private $sender = null;
private $subject = null;
private $body = null;
//add a field to dynamically add subject and to be sent as a parameter in do_email fn
public function do_email($reciever_email=array(), $email_from=null, $email_sender=null, $email_subject=null, $email_body=null, $attachments=array()) {
$this->reciever_email = $reciever_email;
$this->from = $email_from;
$this->sender = $email_sender;
$this->subject = $email_subject;
$this->body = $email_body;
$this->attachments = $attachments;
$mail = new PHPMailer;
// please look into the config/config.php for much more info on how to use this!
// use SMTP or use mail()
if (EMAIL_USE_SMTP) {
// Set mailer to use SMTP
$mail->IsSMTP();
//useful for debugging, shows full SMTP errors
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
// Enable SMTP authentication
$mail->SMTPAuth = EMAIL_SMTP_AUTH;
// Enable encryption, usually SSL/TLS
if (defined(EMAIL_SMTP_ENCRYPTION)) {
$mail->SMTPSecure = EMAIL_SMTP_ENCRYPTION;
}
$mail->SMTPSecure = "tls";
// Specify host server
$mail->Host = EMAIL_SMTP_HOST;
$mail->Username = EMAIL_SMTP_USERNAME;
$mail->Password = EMAIL_SMTP_PASSWORD;
$mail->Port = EMAIL_SMTP_PORT;
} else {
$mail->IsMail();
}
if(trim($email_from) != "" && !empty($reciever_email)) {
$mail->From = $email_from;
$mail->FromName = $email_sender;
$this->reciever_email[] = $reciever_email;
$mail->IsHTML(true);
foreach ($reciever_email as $rec) {
$mail->AddAddress($rec);
}
$mail->AddCC(RT);
$mail->AddCC(AB);
$mail->Subject = $email_subject;
$mail->Body = $email_body;
if ($attachments!==null && is_array($attachments) && !empty($attachments)) {
foreach ($attachments as $attachment) {
$path_to_file = $attachment;
$arr = explode('/',$attachment);
$att_file = end($arr);
$mail->AddAttachment($path_to_file, $att_file);
}
}
if(!$mail->Send()) {
$this->errors[] = "Mail could not be sent" . $mail->ErrorInfo;
return $this->errors;
} else {
return true;
}
}
return false;
}
}

235
classes/Users.php Normal file
View File

@ -0,0 +1,235 @@
<?php
/**
* Created by PhpStorm.
* User: user
* Date: 17-Oct-16
* Time: 9:22 AM
*/
class Users {
protected $db_connection = null;
private $user_name = null;
private $email = null;
private $name = null;
private $is_active = null;
private $user_is_logged_in = false;
private $errors = array();
public function databaseConnection()
{
// if connection already exists
if ($this->db_connection != null) {
return true;
} else {
try {
$this->db_connection = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASS);
return true;
} catch (PDOException $e) {
$this->errors[] = MESSAGE_DATABASE_ERROR . $e->getMessage();
}
}
return false;
}
private function insert_balance($CustomerId, $AssetTypeId, $Balance) {
$now = $this->time_now();
if ($this->databaseConnection()) {
$query = $this->db_connection->prepare("INSERT INTO ".CREDITS_TABLE."(`id`, `uid`, `bc`, `balance`, `insert_date`, `update_date`)
VALUES ('', :CustomerId,:AssetTypeId,:Balance,'$now','$now')");
$query->bindValue(':CustomerId', $CustomerId, PDO::PARAM_STR);
$query->bindValue(':AssetTypeId', $AssetTypeId, PDO::PARAM_STR);
$query->bindValue(':Balance', $Balance, PDO::PARAM_STR);
if($query->execute()) {
return true;
}
}
return false;
}
public function is_fb_registered($fb_id) {
if ($this->databaseConnection()) {
$now = $this->time_now();
$query = $this->db_connection->prepare("SELECT * FROM ".USERS_TABLE." WHERE `fb_id`=:fb_id");
$query->bindValue(':fb_id', $fb_id, PDO::PARAM_STR);
$query->execute();
$rowCount = $query->rowCount();
if($rowCount) {
$user_obj = $query->fetchObject();
$update_query = $this->db_connection->prepare("UPDATE ".USERS_TABLE."
SET `last_activity`='$now'
WHERE `fb_id`=:fb_id
LIMIT 1");
$update_query->bindValue(':fb_id', $fb_id, PDO::PARAM_STR);
$update_query->execute();
$_SESSION['user_id'] = $user_obj->id;
$_SESSION['user_name'] = $user_obj->uname;
$_SESSION['email'] = $user_obj->email;
if (!isset($_SESSION['last_trade_date'])) {
$_SESSION['user_last_login'] = $user_obj->last_activity;
}
return true;
} else {
$this->user_name = $_SESSION['first_name'].time();
$this->name = $_SESSION['full_name'];
$this->email = $_SESSION['email'];
$query = $this->db_connection->prepare("
INSERT INTO ".USERS_TABLE." (`id`, `fb_id`, `uname`, `email`, `name`, `registered_on`, `last_activity`, `is_active`)
VALUES ('',:fb_id,:Username,:Email,:Name,'$now','$now',0)
");
$query->bindValue(':fb_id', $fb_id, PDO::PARAM_INT);
$query->bindValue(':Username', $this->user_name, PDO::PARAM_STR);
$query->bindValue(':Email', $this->email, PDO::PARAM_STR);
$query->bindValue(':Name', $this->name, PDO::PARAM_STR);
if($query->execute()) {
$_SESSION['user_id'] = $this->db_connection->lastInsertId();
$_SESSION['user_name'] = $this->user_name;
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=RMT, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=REBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=IBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=FLOBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=RSBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=INTBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=IHWBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=DBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=RBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=PBC, $Balance=0.00, $FrozenBalance=0.00);
$this->insert_balance($_SESSION['user_id'], $AssetTypeId=ARTBC, $Balance=0.00, $FrozenBalance=0.00);
$user_exist = $this->check_user($_SESSION['user_id']);
if($user_exist) {
return true;
}
return false;
}
return false;
}
} else {
return false;
}
}
public function check_user($customerId) {
if ($this->databaseConnection()) {
$query = $this->db_connection->prepare("SELECT * FROM ".USERS_TABLE." WHERE id = :customerId AND is_active = 1 LIMIT 1");
$query->bindParam('customerId', $customerId);
if ($query->execute()) {
$row_count = $query->rowCount();
if ($row_count == 1) {
return $user_details = $query->fetchObject();
}
return false;
} else {
return false;
}
}
return false;
}
public function actions_user($u_id, $act=1) {
if ($this->databaseConnection()) {
if (!empty($u_id)) {
$act = (int) $act;
$u_id = (int) $u_id;
$query = $this->db_connection->prepare("
UPDATE ".USERS_TABLE." SET `is_active`= $act
WHERE id = :u_id
LIMIT 1
");
$query->bindParam('u_id', $u_id);
if ($query->execute()) {
return true;
}
}
}
return false;
}
public function get_total_users_count() {
if ($this->databaseConnection()) {
$total_users = 0;
$query = $this->db_connection->query("SELECT COUNT(*) AS TOTAL_COUNT FROM ".USERS_TABLE." WHERE `is_active`=1");
if ($query->rowCount()) {
$total_users = $query->fetchObject()->TOTAL_COUNT;
}
return (int) $total_users;
}
return false;
}
public function time_now() {
$n = new DateTime("now", new DateTimeZone("Asia/Kolkata"));
$now = $n->format('Y-m-d H:i:s');
return $now;
}
public function get_username($customerId=0) {
if ($this->databaseConnection()) {
$customerId = (int) $customerId;
$query = $this->db_connection->prepare("SELECT uname FROM ".USERS_TABLE." WHERE id = :id LIMIT 1");
$query->bindParam('id', $customerId);
$query->execute();
$row_count = $query->rowCount();
if ($row_count == 1) {
return $query->fetchObject()->uname;
}
}
return false;
}
public function input_user_email($email=null, $user_id=null) {
if ($this->databaseConnection()) {
$query = $this->db_connection->prepare("
UPDATE ".USERS_TABLE." SET `email`= :em WHERE id = :cid
");
$query->bindParam('em', $email);
$query->bindParam('cid', $user_id);
if ($query->execute()) {
return true;
}
}
return false;
}
public function check_customer_balance($assetType, $user_id) {
if ($this->databaseConnection()) {
$customer_balance = null;
$query = $this->db_connection->prepare("SELECT `balance`
FROM ".CREDITS_TABLE."
WHERE `uid`= :user_id AND `bc`='$assetType'");
$query->bindParam(":user_id", $user_id);
if ($query->execute()) {
if ($query->rowCount()) {
$customer_balance = $query->fetchObject();
}
}
return $customer_balance;
}
return false;
}
}

1092
classes/class.smtp.php Normal file

File diff suppressed because it is too large Load Diff

7
composer.json Normal file
View File

@ -0,0 +1,7 @@
{
"require": {
"facebook/graph-sdk": "^5.6",
"slim/slim": "^3.0",
"nesbot/carbon": "~1.21"
}
}

549
composer.lock generated Normal file
View File

@ -0,0 +1,549 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "d4de0a6f3b7d95a597083d01e7a0ab31",
"content-hash": "a0bae5c4058f9955a0318ad11a91411b",
"packages": [
{
"name": "container-interop/container-interop",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/container-interop/container-interop.git",
"reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8",
"reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8",
"shasum": ""
},
"require": {
"psr/container": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Interop\\Container\\": "src/Interop/Container/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Promoting the interoperability of container objects (DIC, SL, etc.)",
"homepage": "https://github.com/container-interop/container-interop",
"time": "2017-02-14 19:40:03"
},
{
"name": "facebook/graph-sdk",
"version": "5.6.2",
"source": {
"type": "git",
"url": "https://github.com/facebook/php-graph-sdk.git",
"reference": "030f8c5b9b1a6c09e71719fd638b66ea4daa2f10"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/facebook/php-graph-sdk/zipball/030f8c5b9b1a6c09e71719fd638b66ea4daa2f10",
"reference": "030f8c5b9b1a6c09e71719fd638b66ea4daa2f10",
"shasum": ""
},
"require": {
"php": "^5.4|^7.0"
},
"require-dev": {
"guzzlehttp/guzzle": "~5.0",
"mockery/mockery": "~0.8",
"phpunit/phpunit": "~4.0"
},
"suggest": {
"guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client",
"paragonie/random_compat": "Provides a better CSPRNG option in PHP 5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.x-dev"
}
},
"autoload": {
"psr-4": {
"Facebook\\": "src/Facebook/"
},
"files": [
"src/Facebook/polyfills.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Facebook Platform"
],
"authors": [
{
"name": "Facebook",
"homepage": "https://github.com/facebook/php-graph-sdk/contributors"
}
],
"description": "Facebook SDK for PHP",
"homepage": "https://github.com/facebook/php-graph-sdk",
"keywords": [
"facebook",
"sdk"
],
"time": "2018-02-14 23:24:51"
},
{
"name": "nesbot/carbon",
"version": "1.27.0",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "ef81c39b67200dcd7401c24363dcac05ac3a4fe9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/ef81c39b67200dcd7401c24363dcac05ac3a4fe9",
"reference": "ef81c39b67200dcd7401c24363dcac05ac3a4fe9",
"shasum": ""
},
"require": {
"php": ">=5.3.9",
"symfony/translation": "~2.6 || ~3.0 || ~4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2",
"phpunit/phpunit": "^4.8.35 || ^5.7"
},
"type": "library",
"autoload": {
"psr-4": {
"": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Brian Nesbitt",
"email": "brian@nesbot.com",
"homepage": "http://nesbot.com"
}
],
"description": "A simple API extension for DateTime.",
"homepage": "http://carbon.nesbot.com",
"keywords": [
"date",
"datetime",
"time"
],
"time": "2018-04-23 09:02:57"
},
{
"name": "nikic/fast-route",
"version": "v1.3.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/FastRoute.git",
"reference": "181d480e08d9476e61381e04a71b34dc0432e812"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/FastRoute/zipball/181d480e08d9476e61381e04a71b34dc0432e812",
"reference": "181d480e08d9476e61381e04a71b34dc0432e812",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35|~5.7"
},
"type": "library",
"autoload": {
"psr-4": {
"FastRoute\\": "src/"
},
"files": [
"src/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nikita Popov",
"email": "nikic@php.net"
}
],
"description": "Fast request router for PHP",
"keywords": [
"router",
"routing"
],
"time": "2018-02-13 20:26:39"
},
{
"name": "pimple/pimple",
"version": "v3.2.3",
"source": {
"type": "git",
"url": "https://github.com/silexphp/Pimple.git",
"reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/silexphp/Pimple/zipball/9e403941ef9d65d20cba7d54e29fe906db42cf32",
"reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"psr/container": "^1.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^3.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2.x-dev"
}
},
"autoload": {
"psr-0": {
"Pimple": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
}
],
"description": "Pimple, a simple Dependency Injection Container",
"homepage": "http://pimple.sensiolabs.org",
"keywords": [
"container",
"dependency injection"
],
"time": "2018-01-21 07:42:36"
},
{
"name": "psr/container",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"time": "2017-02-14 16:28:37"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06 14:39:51"
},
{
"name": "slim/slim",
"version": "3.10.0",
"source": {
"type": "git",
"url": "https://github.com/slimphp/Slim.git",
"reference": "d8aabeacc3688b25e2f2dd2db91df91ec6fdd748"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/d8aabeacc3688b25e2f2dd2db91df91ec6fdd748",
"reference": "d8aabeacc3688b25e2f2dd2db91df91ec6fdd748",
"shasum": ""
},
"require": {
"container-interop/container-interop": "^1.2",
"nikic/fast-route": "^1.0",
"php": ">=5.5.0",
"pimple/pimple": "^3.0",
"psr/container": "^1.0",
"psr/http-message": "^1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0",
"squizlabs/php_codesniffer": "^2.5"
},
"type": "library",
"autoload": {
"psr-4": {
"Slim\\": "Slim"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Rob Allen",
"email": "rob@akrabat.com",
"homepage": "http://akrabat.com"
},
{
"name": "Josh Lockhart",
"email": "hello@joshlockhart.com",
"homepage": "https://joshlockhart.com"
},
{
"name": "Gabriel Manricks",
"email": "gmanricks@me.com",
"homepage": "http://gabrielmanricks.com"
},
{
"name": "Andrew Smith",
"email": "a.smith@silentworks.co.uk",
"homepage": "http://silentworks.co.uk"
}
],
"description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs",
"homepage": "https://slimframework.com",
"keywords": [
"api",
"framework",
"micro",
"router"
],
"time": "2018-04-19 19:29:08"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/78be803ce01e55d3491c1397cf1c64beb9c1b63b",
"reference": "78be803ce01e55d3491c1397cf1c64beb9c1b63b",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.7-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"time": "2018-01-30 19:27:44"
},
{
"name": "symfony/translation",
"version": "v3.4.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
"reference": "80e19eaf12cbb546ac40384e5c55c36306823e57"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/80e19eaf12cbb546ac40384e5c55c36306823e57",
"reference": "80e19eaf12cbb546ac40384e5c55c36306823e57",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/config": "<2.8",
"symfony/dependency-injection": "<3.4",
"symfony/yaml": "<3.4"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/config": "~2.8|~3.0|~4.0",
"symfony/dependency-injection": "~3.4|~4.0",
"symfony/finder": "~2.8|~3.0|~4.0",
"symfony/intl": "^2.8.18|^3.2.5|~4.0",
"symfony/yaml": "~3.4|~4.0"
},
"suggest": {
"psr/log": "To use logging capability in translator",
"symfony/config": "",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Translation\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Translation Component",
"homepage": "https://symfony.com",
"time": "2018-02-22 06:28:18"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}

88
fbconfig.php Normal file
View File

@ -0,0 +1,88 @@
<?php
if(!session_id()) {
session_start();
}
require_once 'includes/imp_files.php';
require_once 'vendor/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => APP_ID,
'app_secret' => APP_SECRET,
'default_graph_version' => 'v2.12',
]);
$helper = $fb->getRedirectLoginHelper();
if (isset($_GET['state'])) {
$helper->getPersistentDataHandler()->set('state', $_GET['state']);
}
//$helper = $fb->getRedirectLoginHelper();
$permissions = ['email']; // optional
try {
if (isset($_SESSION['facebook_access_token'])) {
$accessToken = $_SESSION['facebook_access_token'];
} else {
$accessToken = $helper->getAccessToken();
}
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
if (isset($_SESSION['facebook_access_token'])) {
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
} else {
// getting short-lived access token
$_SESSION['facebook_access_token'] = (string) $accessToken;
// OAuth 2.0 client handler
$oAuth2Client = $fb->getOAuth2Client();
// Exchanges a short-lived access token for a long-lived one
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
// setting default access token to be used in script
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
}
// redirect the user back to the same page if it has "code" GET variable
if (isset($_GET['code'])) {
header('Location: ./');
}
// getting basic info about user
try {
$profile_request = $fb->get('/me?fields=name,first_name,last_name,email');
$profile = $profile_request->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
session_destroy();
// redirecting user back to app login page
header("Location: ./");
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// printing $profile array on the screen which holds the basic info about user
$name = isset($profile['name']) ? $profile['name'] : null;
$first_name = isset($profile['first_name']) ? $profile['first_name'] : null;
$last_name = isset($profile['last_name']) ? $profile['last_name'] : null;
$email = isset($profile['email']) ? $profile['email'] : null;
//$gender = isset($profile['gender']) ? $profile['gender'] : null;
$fb_id = isset($profile['id']) ? $profile['id'] : null;
$_SESSION['first_name'] = $first_name;
$_SESSION['full_name'] = $name;
$_SESSION['email'] = $email;
$_SESSION['fb_id'] = $fb_id;
// Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token']
} else {
// replace your website URL same as added in the developers.facebook.com/apps e.g. if you used http instead of https and you used non-www version or www version of your website then you must add the same here
$loginUrl = $helper->getLoginUrl('http://localhost/files/Bitcoin_Projects/bc_exchange/fbconfig.php', $permissions);
}

7
includes/autoload.php Normal file
View File

@ -0,0 +1,7 @@
<?php
function __autoload($class_name) {
$class = explode("_", $class_name);
$path = implode("/", $class).".php";
require_once($path);
}

View File

@ -0,0 +1,62 @@
<?php
/*Please make a config.php file with correct values same like below*/
/** NOTE: The session values must match DB values of users table */
/*Change these values according to your configurations*/
define("DB_HOST", "localhost");
define("DB_NAME", "YOUR-DB");
define("DB_USER", "root");
define("DB_PASS", "");
define("MESSAGE_DATABASE_ERROR", "Failed to connect to database.");
define("EMAIL_USE_SMTP", true);
define("EMAIL_SMTP_HOST", "YOUR HOSTING");
define("EMAIL_SMTP_AUTH", true);
define("EMAIL_SMTP_USERNAME", "USERNAME");
define("EMAIL_SMTP_PASSWORD", "PASSWORD");
define("EMAIL_SMTP_PORT", 587); //587
define("EMAIL_SMTP_ENCRYPTION", "ssl");
/*EMAILS*/
define("RT", "");
define("RM", "");
define("PI", "");
define("AB", "");
define("RMGM", "");
define("FINANCE", "");
/*YOUR CRYPTOCURRENCIES*/
define("RMT", "RMT");
define("REBC", "REBC");
define("IBC", "IBC");
define("FLOBC", "FLOBC");
define("RSBC", "RSBC");
define("INTBC", "INTBC");
define("IHWBC", "IHWBC");
define("DBC", "DBC");
define("RBC", "RBC");
define("PBC", "PBC");
define("ARTBC", "ARTBC");
define("EMAIL_SENDER_NAME", "Ranchi Mall");
//define("EMAIL_SUBJECT", "Ranchi Mall Fund Transfer Request.");
//define("EMAIL_SUBJECT_RTM_TRANSFER", "Ranchi Mall RMT Transfer Request.");
//define("EMAIL_SUBJECT_BTC_TO_CASH", "Ranchi Mall BTC To CASH exchange Request.");
/*YOUR TABLES IN DB*/
define("TOP_BUYS_TABLE", "BUYS TABLE");
define("TOP_SELLS_TABLE", "SELLS TABLE");
define("USERS_TABLE", "USER TABLE");
define("CREDITS_TABLE", "BALANCE TABLE");
define("ORDERS_TABLE", "ORDERS TABLE");
define("TX_TABLE", "TRANSACTION TABLE");
/*FACEBOOK DETAILS*/
define("APP_ID", 'YOUR FB APP ID');
define("APP_SECRET", 'YOUR FB APP PASSWORD');
/*ADMIN DETAILS*/
define("ADMIN_FB_ID", "ADMIN FB APP ID");
define("ADMIN_ID", "ADMIN ID NUMBER IN USER TABLE");
define("ADMIN_UNAME", "ADMIN USERNAME IN USER TABLE IN DB");

56
includes/defines.php Normal file
View File

@ -0,0 +1,56 @@
<?php
if(!isset($_SESSION)) {
session_start();
}
//SITE DOMAIN NAME WITH HTTP
defined("SITE_URL") || define("SITE_URL", "http://".$_SERVER['SERVER_NAME']);
//DIRECTORY SEPARATOR
defined("DS") || define("DS", DIRECTORY_SEPARATOR);
//ROOT PATH
defined("ROOT_PATH") || define("ROOT_PATH", realpath(dirname(__FILE__) . DS . ".." . DS));
//CLASSES DIR
defined("CLASSES_DIR") || define("CLASSES_DIR", "classes");
//INCLUDES DIR
defined("INCLUDES_DIR") || define("INCLUDES_DIR", "includes");
//VIEWS DIR
defined("VIEWS_DIR") || define("VIEWS_DIR", "views");
//CONFIG DIR
defined("CONFIG_DIR") || define("CONFIG_DIR", "config");
if(isset($_SESSION['user_name'])) {
//USER DIR
defined("USER_DIR") || define("USER_DIR", "user". DS .$_SESSION['user_name']. DS ."uploads". DS);
} else {
//USER DIR
defined("USER_DIR") || define("USER_DIR", null);
}
//JS DIR
defined("JS_DIR") || define("JS_DIR", "js");
//STYLE DIR
defined("STYLE_DIR") || define("STYLE_DIR", "style");
//add all above directories to the include path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(ROOT_PATH.DS.CLASSES_DIR),
realpath(ROOT_PATH.DS.INCLUDES_DIR),
realpath(ROOT_PATH.DS.VIEWS_DIR),
realpath(ROOT_PATH.DS.CONFIG_DIR),
realpath(ROOT_PATH.DS.USER_DIR),
realpath(ROOT_PATH.DS.JS_DIR),
realpath(ROOT_PATH.DS.STYLE_DIR),
get_include_path()
)));

34
includes/footer.php Normal file
View File

@ -0,0 +1,34 @@
<div id="MsgModel" class="modal fade bs-MsgModel-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" style="top:33%; text-align: center;">
<div class="vertical-alignment-helper">
<div class="modal-dialog modal-lg vertical-align-center">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabelMsg"></h4>
</div>
<div class="modal-body">
<ul class="msg-ul"></ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="<?=JS_DIR?>/jquery-3.2.1.min.js"></script>
<script src="<?=JS_DIR?>/main.js"></script>
<script src="<?=JS_DIR?>/bootstrap.min.js"></script>
<script src="<?=JS_DIR?>/notify.js"></script>
<script>
$(function () {
'use strict'
$('[data-toggle="offcanvas"]').on('click', function () {
$('.offcanvas-collapse').toggleClass('open')
})
})
</script>
</body>
</html>

105
includes/functions.php Normal file
View File

@ -0,0 +1,105 @@
<?php
/**
* Created by PhpStorm.
* User: Abhishek Kumar Sinha
* Date: 10/3/2017
* Time: 6:33 PM
*/
function round_it($num=0, $deci=2) {
$decimal = abs(number_format((float)$num, $deci, '.', ''));
return $decimal;
}
function redirect_to($url=null) {
header('Location: '.$url);
exit;
}
function checkLoginStatus() {
if(!isset($_SESSION['fb_id']) || !isset($_SESSION['user_id']) || !isset($_SESSION['user_name'])) {
return false;
}
return true;
}
function extract_int($string) {
$int = intval(preg_replace('/[^0-9]+/', '', $string), 10);
return $int;
}
function bitcoin_price_today() {
$bit_price = null;
try {
$url = "https://bitpay.com/api/rates";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
$rate = $data[1]["rate"];
$usd_price = 1;
$bit_price = round($rate/$usd_price , 8);
} catch(Exception $e) {
$bit_price = null;
}
return (float) $bit_price;
}
function bitcoin_calculator($usd=0) {
$btc_usd_price = bitcoin_price_today();
if (($usd > 0) && ($btc_usd_price > 0)) {
return (float) $usd/$btc_usd_price;
}
return false;
}
function wapol_str($string) {
if(preg_match('/[^a-z:\-0-9]/i', $string)) {
return false;
} else {
return true;
}
}
function sendReqtoURL($addr, $tokens) {
$url = 'http://ranchimall.net/test/test.php';
$myvars = 'addr=' . $addr . '&tokens=' . $tokens;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
curl_close($ch);
return (int) $response;
}
function is_email($email='') {
$email = trim($email);
if ($email != null) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return true;
}
}
return false;
}
function validate_decimal_place($num=0, $decimal_allowed=2) {
$num = (float) $num;
$decimal_places = strlen(substr(strrchr($num, "."), 1));
//if(($decimal_places > 0) && ($decimal_places <= $decimal_allowed)) {
if($decimal_places <= $decimal_allowed) {
return true;
}
return false;
}

78
includes/header.php Normal file
View File

@ -0,0 +1,78 @@
<?php
// Turn off error reporting
//error_reporting(0);
//@ini_set('display_errors', 0);
$tradersList = array();
$buy_list = array();
$sell_list = array();
include_once 'fbconfig.php';
$validate_user = null;
if (isset($UserClass)) {
if (isset($fb_id)):
// check if user already registered
$validate_user = $UserClass->is_fb_registered($fb_id);
if($validate_user == "" || $validate_user == false) {
redirect_to('index.php');
}
endif;
//$tradersList = $OrderClass->UserBalanceList();
//$buy_list[] = $OrderClass->get_top_buy_sell_list(TOP_BUYS_TABLE, $asc_desc='DESC'); // buy
//$sell_list[] = $OrderClass->get_top_buy_sell_list(TOP_SELL_TABLE, $asc_desc='ASC'); // sell
}
$fullName = isset($_SESSION['full_name']) ? $_SESSION['full_name'] : "";
$user_logged_in = false;
$action_class_market = 'fb_log_in';
$action_class_buy_sell = 'fb_log_in';
if(checkLoginStatus()) {
$user_logged_in = true;
$action_class_market = 'market_submit_btn';
$action_class_buy_sell = 'process';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="<?=STYLE_DIR?>/bootstrap.min.css">
<!-- Custom styles for this template -->
<link href="<?=STYLE_DIR?>/offcanvas.css" rel="stylesheet">
</head>
<body class="bg-light">
<nav class="navbar navbar-expand-md fixed-top navbar-dark bg-dark">
<a class="navbar-brand" href="#">Ranchi Mall Blockchain Contract</a>
<button class="navbar-toggler p-0 border-0" type="button" data-toggle="offcanvas">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
<div class="nav-scroller bg-white box-shadow">
<nav class="nav nav-underline">
<a class="nav-link active" href="#">Dashboard</a>
<a class="nav-link" href="#">
Investors
<span class="badge badge-pill bg-light align-text-bottom">127</span>
</a>
<a class="nav-link" href="#">Exchange</a>
<?php if($user_logged_in) { ?>
<a class="nav-link" href="logout.php">Log Out</a>
<?php } elseif(isset($loginUrl)) {?>
<a href="<?=$loginUrl?>" role="button" class="pull-right popup nav-link" name="fb_login">
<div class="btn btn--facebook ">
Continue with Facebook
</div>
</a>
<?php } ?>
</nav>
</div>

47
includes/imp_files.php Normal file
View File

@ -0,0 +1,47 @@
<?php
/**
* Created by PhpStorm.
* User: Abhishek Kumar Sinha
* Date: 10/3/2017
* Time: 7:49 PM
*/
if(!isset($_SESSION)) {
session_start();
}
require_once 'defines.php';
require_once 'config.php';
include_once 'autoload.php';
include_once 'functions.php';
//if logged in store user DB details
$fb_id = null;
$user_name = null;
$user_id = null;
$log_fullName = null;
$user_email = null;
if (checkLoginStatus()) {
if (isset($_SESSION['fb_id'], $_SESSION['user_name'], $_SESSION['user_id'])) {
$fb_id = $_SESSION['fb_id'];
$user_name = $_SESSION['user_name'];
$user_id = $_SESSION['user_id'];
} else {
redirect_to("logout.php");
}
$log_fullName = isset($_SESSION['full_name']) ? $_SESSION['full_name'] : '';
$user_email = isset($_SESSION['email']) ? $_SESSION['email'] : '';
}
$UserClass = null;
$OrderClass = null;
$ApiClass = null;
$MailClass = null;
if (class_exists('Users') && class_exists('Orders') && class_exists('SendMail')) {
$UserClass = new Users();
$OrderClass = new Orders();
//$ApiClass = new Api();
$MailClass = new SendMail();
}

11
index.php Normal file
View File

@ -0,0 +1,11 @@
<?php
ob_start();
date_default_timezone_set('Asia/Kolkata');
?>
<?php require_once "includes/imp_files.php";?>
<?php include_once 'includes/header.php'; ?>
<?php include_once 'views/home.php' ?>
<?php include_once 'includes/footer.php'; ?>

7
js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

4
js/jquery-3.2.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

205
js/main.js Normal file
View File

@ -0,0 +1,205 @@
/**
* Created by Abhishek Kumar Sinha on 5/1/2018.
*/
$(document).ready(function() {
load_fresh_table_data();
run_OrderMatchingAlgorithm();
});
$(document).on('click', '#is_mkt', function() {
$('#ex-price').val('').toggle();
});
$(document).on('click', '#ex-sub', function() {
var btn = $(this);
var sel1 = $('#sel-bc-1').val();
var sel2 = $('#sel-bc-2').val();
var pr = $('#ex-price').val();
var qty = $('#ex-qty').val();
var bs_rad = $("input[name='gridRadios']:checked").val();
var is_mkt = $('#is_mkt').is(":checked");
btn.prop( "disabled", true );
place_order(sel1, sel2, pr, qty, bs_rad, is_mkt, btn);
});
function displayNotice(msg, _type) {
var v = '<li>'+msg+'</li>';
switch (_type) {
case 'success':
$('#MsgModel').find('ul.msg-ul').removeClass('text-danger text-warning').addClass('text-info').html(v);
break;
case 'failure':
$('#MsgModel').find('ul.msg-ul').removeClass('text-info text-warning').addClass('text-danger').html(v);
break;
case 'warning':
$('#MsgModel').find('ul.msg-ul').removeClass('text-danger text-info').addClass('text-warning').html(v);
break;
default:
$('#MsgModel').find('ul.msg-ul').removeClass('text-danger text-warning').addClass('text-info').html(v);
}
$('#MsgModel').modal('toggle');
}
function place_order(sel1, sel2, pr, qty, bs_rad, is_mkt, btn) {
var subject = 'placeOrder';
$.ajax({
method: 'post',
url: 'ajax/pending_orders.php',
data: { subject:subject, sel1:sel1, sel2:sel2, price:pr, qty:qty, bs_rad:bs_rad, is_mkt:is_mkt},
error: function(xhr, status, error) {
console.log(xhr.responseText);
},
success: function(data) {
console.log(data);
btn.prop( "disabled", false);
var IS_JSON = true;
try {
var d = jQuery.parseJSON(data);
}
catch(err) {
IS_JSON = false;
}
if(IS_JSON) {
if(d.error == true) {
$msg = d.msg;
displayNotice($msg, "failure");
} else if(d.order != null && d.order.error == true && d.order.message != null) {
displayNotice(d.order.message, "failure");
} else if(d.user == '') {
displayNotice('There was a problem in identifying the user.', "failure");
} else {
$('#empty_msg').hide();
var trade = "";
if($.trim(bs_rad)=="ex-buy") {
trade = "buy";
} else if ($.trim(bs_rad)=="ex-sell") {
trade = "sell";
}
displayNotice('You entered a '+trade+' order for '+qty + ' ' + sel1+ ' at '+pr+ ' '+sel2+'.', "success");
run_OrderMatchingAlgorithm();
}
} else {
displayNotice('Something went wrong. Please contact the administrator.', "failure");
}
}
});
}
function myTimeoutFunction() {
run_OrderMatchingAlgorithm();
setTimeout(myTimeoutFunction, 20000);
}
myTimeoutFunction();
// Update tables a/c to change in select
$(document).on('change', ".selbc", function() {
load_fresh_table_data();
});
// function to check if JSON data is array or not
function isArray(what) {
return Object.prototype.toString.call(what) === '[object Array]';
}
function load_fresh_table_data() {
var bc1 = $('#sel-bc-1').val();
var bc2 = $('#sel-bc-2').val();
$.ajax({
method:'post',
url:'ajax/refresh_table.php',
data: { task : 'refresh', bc1:bc1, bc2:bc2},
error: function(xhr, status, error) {
console.log(xhr.responseText);
},
success: function(data) {
if(data !== '') {
var d = jQuery.parseJSON(data);
console.log(d);
//get_my_balance();
var t = '';
if(isArray(d.buys) && d.buys.length !== 0) {
for (var j=0; j<=d.buys.length-1 ; j++) {
t += '';
t += '<tr id="'+d.buys[j].order_id+'">';
t += '<td> '+d.buys[j].name+'</td>';
t += '<td> '+d.buys[j].price+'</td>';
t += '<td>'+d.buys[j].quantity+'</td>';
t += '</tr>';
}
}
$('#bd-buy').html(t);
var v = '';
if(isArray(d.sells) && d.sells.length !== 0) {
for (var k=0; k<=d.sells.length-1 ; k++) {
v += '';
v += '<tr id="'+d.sells[k].order_id+'">';
v += '<td>'+d.sells[k].name+'</td>';
v += '<td> '+d.sells[k].price+'</td>';
v += '<td>'+d.sells[k].quantity+'</td>';
v += '</tr>';
}
}
$('#bd-sell').html(v);
}
}
});
}
function run_OrderMatchingAlgorithm() {
var sel1 = $('#sel-bc-1').val();
var sel2 = $('#sel-bc-2').val();
if($.trim(sel1) == '' || $.trim(sel2) == '') {
return;
}
$.ajax({
method:'post',
async: true,
url:'ajax/OrderMatchingAlgorithmAjax.php',
data: { task : 'run_OrderMatchingAlgorithm', sel1:sel1, sel2:sel2},
error: function(xhr, status, error) {
console.log(xhr.responseText);
},
success: function(data) {
load_fresh_table_data();
var IS_JSON = true;
try {
var d = jQuery.parseJSON(data);
}
catch(err) {
IS_JSON = false;
}
if(IS_JSON) {
if (d.error == false && d.msg=="userLoggedIn") {
if (isArray(d.order) && d.order.length != 0) {
for (var k = 0; k <= d.order.length - 1; k++) {
$.notify({
message: d.order[k]
},{
type: 'success'
});
}
}
}
}
}
});
}

4
js/notify.js Normal file

File diff suppressed because one or more lines are too long

5
logout.php Normal file
View File

@ -0,0 +1,5 @@
<?php
session_start();
session_destroy();
header("Location: index.php"); // you can enter home page here ( Eg : header("Location: " ."http://www.krizna.com");
?>

7
pages.php Normal file
View File

@ -0,0 +1,7 @@
<?php include_once 'includes/header.php'; ?>
<div class="container-fluid my-3 p-3 bg-white rounded box-shadow">
...
</div>
<?php include_once 'includes/footer.php'; ?>

7
style/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

80
style/offcanvas.css Normal file
View File

@ -0,0 +1,80 @@
html,
body {
overflow-x: hidden; /* Prevent scroll on narrow devices */
}
body {
padding-top: 56px;
}
@media (max-width: 767.98px) {
.offcanvas-collapse {
position: fixed;
top: 56px; /* Height of navbar */
bottom: 0;
width: 100%;
padding-right: 1rem;
padding-left: 1rem;
overflow-y: auto;
background-color: var(--gray-dark);
transition: -webkit-transform .3s ease-in-out;
transition: transform .3s ease-in-out;
transition: transform .3s ease-in-out, -webkit-transform .3s ease-in-out;
-webkit-transform: translateX(100%);
transform: translateX(100%);
}
.offcanvas-collapse.open {
-webkit-transform: translateX(-1rem);
transform: translateX(-1rem); /* Account for horizontal padding on navbar */
}
}
.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}
.nav-scroller .nav {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
color: rgba(255, 255, 255, .75);
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
.nav-underline .nav-link {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: .875rem;
color: var(--secondary);
}
.nav-underline .nav-link:hover {
color: var(--blue);
}
.nav-underline .active {
font-weight: 500;
color: var(--gray-dark);
}
.text-white-50 { color: rgba(255, 255, 255, .5); }
.bg-purple { background-color: var(--purple); }
.border-bottom { border-bottom: 1px solid #e5e5e5; }
.box-shadow { box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); }
.lh-100 { line-height: 1; }
.lh-125 { line-height: 1.25; }
.lh-150 { line-height: 1.5; }

105
views/home.php Normal file
View File

@ -0,0 +1,105 @@
<main role="main" class="container">
<div class="d-flex align-items-center p-3 my-3 text-white-50 bg-purple rounded box-shadow">
<img class="mr-3" src="https://getbootstrap.com/assets/brand/bootstrap-outline.svg" alt="" width="48" height="48">
<div class="lh-100">
<h6 class="mb-0 text-white lh-100">Ranchi Mall</h6>
<small>Small Ideas. Big Dreams</small>
</div>
<div class="d-flex">
<select class="form-control selbc" name="sel-bc-1" id="sel-bc-1">
<option value=""> Select first coin..</option>
<option value="REBC">Real Estate</option>
<option value="IBC">Incorporation</option>
<option value="FLOBC">Flo</option>
</select>
<select class="form-control selbc" name="sel-bc-2" id="sel-bc-2">
<option value="">Select second coin..</option>
<option value="RMT">RMT</option>
<option value="REBC">Real Estate</option>
<option value="IBC">Incorporation</option>
<option value="FLOBC">Flo</option>
</select>
</div>
</div>
<div class="my-3 p-3 bg-white rounded box-shadow">
<div class="form-group row">
<label for="ex-price" class="col-sm-2 col-form-label">Enter Price</label>
<div class="col-sm-10">
<input type="number" class="form-control" name="ex-price" id="ex-price"/>
</div>
</div>
<div class="form-group row">
<label for="ex-qty" class="col-sm-2 col-form-label">Enter Quantity</label>
<div class="col-sm-10">
<input type="number" class="form-control" name="ex-qty" id="ex-qty"/>
</div>
</div>
<fieldset class="form-group">
<div class="row">
<legend class="col-form-label col-sm-2 pt-0">Choose buy or sell</legend>
<div class="col-sm-10">
<div class="form-check">
<input class="form-check-input" type="radio" name="gridRadios" id="ex-rad-buy" value="ex-buy">
<label class="form-check-label" for="ex-rad-buy">
Buy
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="gridRadios" id="ex-rad-sell" value="ex-sell">
<label class="form-check-label" for="ex-rad-sell">
Sell
</label>
</div>
</div>
</div>
</fieldset>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="is_mkt">
<label class="form-check-label" for="is_mkt">Buy instantly at market rate?</label>
</div>
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary" id="ex-sub" name="ex-sub">Submit</button>
</div>
</div>
</div>
<div class="my-3 p-3 bg-white rounded box-shadow">
<div class="row">
<div class="col">
<div class="table-responsive">
<h6>Buy list</h6>
<table class="table-borderless table-sm">
<thead>
<tr>
<th>Buyer</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody id="bd-buy"></tbody>
</table>
</div>
</div>
<div class="col">
<div class="table-responsive">
<h6>Sell list</h6>
<table class="table-borderless table-sm">
<thead>
<tr>
<th>Buyer</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody id="bd-sell"></tbody>
</table>
</div>
</div>
</div>
</div>
</main>