diff --git a/ajax/check_new_orders.php b/ajax/check_new_orders.php
index 4fc7467..780855e 100644
--- a/ajax/check_new_orders.php
+++ b/ajax/check_new_orders.php
@@ -11,7 +11,7 @@ if (!checkLoginStatus()) {
return false;
}
-$last_trade_date = $_SESSION['last_trade_date'];
+$last_trade_date = isset($_SESSION['last_trade_date'])?$_SESSION['last_trade_date']:'';
$lod = $OrderClass->get_last_order_date($last_trade_date);
diff --git a/ajax/update_bc_bal.php b/ajax/update_bc_bal.php
index 9cddece..88eeb40 100644
--- a/ajax/update_bc_bal.php
+++ b/ajax/update_bc_bal.php
@@ -2,7 +2,7 @@
require_once '../includes/imp_files.php';
-if (!checkLoginStatus()) {
+if (!checkLoginStatus() || !isset($OrderClass, $UserClass)) {
return false;
}
@@ -10,17 +10,15 @@ if (isset($_POST['job']) && trim($_POST['job']) == "update-user-bc-balance") {
if (isset($_POST['bc_bal_updt'], $_POST['cus_id'], $_POST['_bc2'])) {
$cus_id = (int)$_POST['cus_id'];
- $bc2 = trim($_POST['_bc2']);
+ $bc2 = $_POST['_bc2'];
$balance = number_format((float)$_POST['bc_bal_updt'], 10);
$std = new stdClass();
$std->mesg = array();
$std->error = true;
- $is_sel2_valid= $OrderClass->is_bc_valid($bc2, null, 1);
-
- if ($bc2==""||$bc2==null || !$is_sel2_valid) {
- $mess = "Please choose a Blockchain contract from second dropdown.";
+ if ($bc2==""||$bc2==null || !is_array($bc2) || empty($bc2)) {
+ $mess = "Please choose a Blockchain contract from the dropdown menu.";
$std->error = true;
$std->mesg[] = $mess;
echo json_encode($std);
@@ -44,14 +42,6 @@ if (isset($_POST['job']) && trim($_POST['job']) == "update-user-bc-balance") {
return false;
}
- if (!isset($OrderClass, $UserClass)) {
- $mess = "System Error!";
- $std->error = true;
- $std->mesg[] = $mess;
- echo json_encode($std);
- return false;
- }
-
$update_bal = null;
/*Restrict decimal places while updating balance*/
@@ -63,31 +53,44 @@ if (isset($_POST['job']) && trim($_POST['job']) == "update-user-bc-balance") {
return false;
}
- //Prev balance of user
- $bal_prev = (float) $OrderClass->check_customer_balance($bc2, $cus_id)->balance;
+ foreach ($bc2 as $b2) {
+ $is_sel2_valid= $OrderClass->is_bc_valid($b2, null, 1);
+ if (!$is_sel2_valid) {
+ $mess = "Unknown Blockchain contract.";
+ $std->error = true;
+ $std->mesg[] = $mess;
+ echo json_encode($std);
+ continue;
+ }
- $update_bal = $OrderClass->update_user_balance($bc2, $balance, $cus_id);
+ //Prev balance of user
+ $bal_prev = (float) $OrderClass->check_customer_balance($b2, $cus_id)->balance;
- if (!$update_bal) {
- $mess = "Failed to update balance.";
- $std->error = true;
- $std->mesg[] = $mess;
- echo json_encode($std);
- return false;
- } else if($update_bal) {
- // Record this change
- $OrderClass->record_root_bal_update($cus_id, $bal_prev, $balance, $bc2);
- $mess = "Successfully updated balance!";
- $std->error = false;
- $std->mesg[] = $mess;
- echo json_encode($std);
- return false;
- } else {
- $mess = "Something went wrong. Failed to update balance!";
- $std->error = true;
- $std->mesg[] = $mess;
- echo json_encode($std);
- return false;
+ $update_bal = $OrderClass->update_user_balance($b2, $balance, $cus_id);
+
+ if (!$update_bal) {
+ $mess = "Failed to update $b2 balance.";
+ $std->error = true;
+ $std->mesg[] = $mess;
+ echo json_encode($std);
+ //return false;
+ } else if($update_bal) {
+ // Record this change
+ $OrderClass->record_root_bal_update($cus_id, $bal_prev, $balance, $b2);
+ $mess = "Successfully updated balance!";
+ $std->error = false;
+ $std->mesg[] = $mess;
+ echo json_encode($std);
+ //return false;
+ } else {
+ $mess = "Something went wrong. Failed to update $b2 balance!";
+ $std->error = true;
+ $std->mesg[] = $mess;
+ echo json_encode($std);
+ //return false;
+ }
}
+
}
+ return;
}
\ No newline at end of file
diff --git a/api/.htaccess b/api/.htaccess
new file mode 100644
index 0000000..5397e4d
--- /dev/null
+++ b/api/.htaccess
@@ -0,0 +1,4 @@
+RewriteEngine on
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule . api.php [L]
diff --git a/api/api.php b/api/api.php
new file mode 100644
index 0000000..d1459e8
--- /dev/null
+++ b/api/api.php
@@ -0,0 +1,70 @@
+get('/user_by_email/{em}', function (Request $request, Response $response) {
+ try {
+ $UserClass = new Users();
+ $email = (string) trim($request->getAttribute('em'));
+ $is_email = is_email($email);
+ if ($is_email) {
+ $stmt = $UserClass->get_user_by_email($email);
+ $user_details = $stmt;
+
+ echo json_encode($user_details);
+ return;
+ }
+ echo '{"error": {"text": "Invalid email"}}';
+
+ } catch (PDOException $e) {
+ echo '{"error": {"text": ' . $e->getMessage() . '}}';
+ }
+ });
+
+
+ // Update RMT balance in BCX
+ $app->put('/up_val/rmt/{uid}', function (Request $request, Response $response) {
+ try {
+ $OrderClass = new Orders();
+ $data = $request->getParsedBody(); // Array([new_bal] => 115)
+ //$data = $request->getParam('new_bal'); // 115
+ $uid = $request->getAttribute('uid');
+
+ $add_bal = (float) $data['new_bal'];
+
+ $prev_bal = (float) $OrderClass->check_customer_balance($assetType = RMT, $uid)->balance;
+
+ $new_bal = $prev_bal + $add_bal;
+
+ if ($new_bal < 0) {
+ echo '{"process": {"text": "Invalid amount"}}';
+ return;
+ }
+
+ if (isset($data['pass']) && trim($data['pass'])=="secret") {
+ $update_successful = $OrderClass->update_user_balance(RMT, $new_bal, $uid);
+
+ if ($update_successful) {
+ echo '{"process": {"text": "success"}}';
+ return;
+ }
+ }
+ echo '{"process": {"text": "failed"}}';
+
+ } catch (PDOException $e) {
+ echo '{"process": {"text": ' . $e->getMessage() . '}}';
+ }
+ });
+
+ $app->run();
+}
\ No newline at end of file
diff --git a/api/viv.php b/api/viv.php
new file mode 100644
index 0000000..8062252
--- /dev/null
+++ b/api/viv.php
@@ -0,0 +1,60 @@
+truncate_tbl(VIV_TX_TBL);
+$VivClass->truncate_tbl(VIV_LOGS);
+$VivClass->truncate_tbl(VIV_WEB);
+$VivClass->truncate_tbl(VIV_EXTRA);
+
+$root_inserted = $VivClass->insertTx($root_address, 0, $root_init_value);
+if (!$root_inserted) {
+ echo "Failed to initialize root address.";
+ exit;
+}
+
+$transferDescription = "Root address = (string) $root_address has been initialized with (string) $root_init_value tokens";
+$blockchainReference = 'https://testnet.florincoin.info/tx/';
+
+$log_inserted = $VivClass->insertLogs(1, $transferDescription, 0, $blockchainReference);
+if (!$log_inserted) {
+ echo "Failed to log transfer description.";
+ exit;
+}
+
+//find root address's block
+$string = "https://testnet.florincoin.info/ext/getaddress/$root_address";
+$root_trans_hash = get_tx_hash($root_address);
+$root_block_hash = get_block_hash($root_trans_hash);
+$root_block_index = get_block_index($root_block_hash);
+echo "Root block index: ".$root_block_index."
";
+
+//get current block count
+$current_block_index = get_current_block_count()["height"];
+echo "Current Block index: ". $current_block_index."
";*/
+
+$rr = dothemagic(26679);
+print_r($rr);
+
+
+
diff --git a/classes/Orders.php b/classes/Orders.php
index bafb36a..bcc3005 100644
--- a/classes/Orders.php
+++ b/classes/Orders.php
@@ -1368,7 +1368,7 @@ class Orders extends Users {
$extraQuerry1 = "AND ".CREDITS_TABLE.".bc = :bc1";
$extraQuerry2 = "ORDER BY ".CREDITS_TABLE.".balance DESC";
} else {
- $extraQuerry2 = "ORDER BY ".USERS_TABLE.".name ASC";
+ $extraQuerry2 = "ORDER BY ".USERS_TABLE.".id ASC";
}
$query = $this->db_connection->prepare("
diff --git a/classes/Users.php b/classes/Users.php
index fc8768a..2f6a502 100644
--- a/classes/Users.php
+++ b/classes/Users.php
@@ -297,6 +297,27 @@ class Users {
return false;
}
+ public function get_user_by_email($em) {
+
+ if ($this->databaseConnection()) {
+
+ $query = $this->db_connection->prepare("SELECT * FROM ".USERS_TABLE." WHERE email = :email AND is_active = 1 LIMIT 1");
+ $query->bindParam('email', $em);
+
+ if ($query->execute()) {
+ $row_count = $query->rowCount();
+ if ($row_count == 1) {
+ return $user_details = $query->fetchObject();
+ }
+ return false;
+ } else {
+ return false;
+ }
+ }
+ return false;
+ }
+
+
}
\ No newline at end of file
diff --git a/classes/Viv.php b/classes/Viv.php
new file mode 100644
index 0000000..0cc4347
--- /dev/null
+++ b/classes/Viv.php
@@ -0,0 +1,50 @@
+databaseConnection()) {
+ $query = $this->db_connection->prepare("INSERT INTO ".VIV_TX_TBL."(`id`, `address`, `parentid`, `transferBalance`)
+ VALUES ('', :addr, :pid, :tb)");
+ $query->bindParam("addr", $address);
+ $query->bindParam("pid", $parentId);
+ $query->bindParam("tb", $transferBalance);
+ $query->execute();
+ return true;
+ }
+ return false;
+ }
+
+ public function insertLogs($primaryIDReference=null, $transferDescription=null, $transferIDConsumed=null, $blockchainReference=null) {
+ if ($this->databaseConnection()) {
+ $query = $this->db_connection->prepare("
+ INSERT INTO ".VIV_LOGS." (primaryIDReference, transferDescription, transferIDConsumed, blockchainReference)
+ VALUES (:pr, :td, :tc, :br)
+ ");
+ $query->bindParam("pr", $primaryIDReference);
+ $query->bindParam("td",$transferDescription );
+ $query->bindParam("tc", $transferIDConsumed);
+ $query->bindParam("br", $blockchainReference);
+
+ $query->execute();
+ return true;
+ }
+ return false;
+ }
+
+ public function truncate_tbl($tbl='') {
+ if ($this->databaseConnection()) {
+ $query = $this->db_connection->query("TRUNCATE TABLE ".$tbl);
+ return true;
+ }
+ return false;
+ }
+
+
+}
\ No newline at end of file
diff --git a/includes/footer.php b/includes/footer.php
index 183c1d1..d29523e 100644
--- a/includes/footer.php
+++ b/includes/footer.php
@@ -51,4 +51,5 @@
})