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 @@ }) - \ No newline at end of file + + \ No newline at end of file diff --git a/includes/functions.php b/includes/functions.php index f80e89d..2be81da 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -125,4 +125,195 @@ function rmt_price_today() { function bc_to_usd($bc_rmt_price, $current_rmt_price_in_usd) { return round(($bc_rmt_price * $current_rmt_price_in_usd), 2); +} + +function user_rmt_bal($uid=0) { + $bit_price = null; + if (!is_int($uid)) { + return false; + } + + try { + $url = "https://www.ranchimall.net/exchange/api/token_ratio/$uid/rmt"; + + $json = file_get_contents($url); + $data = json_decode($json, TRUE); + + $user_rmt_bal= $data["user"]; + } catch(Exception $e) { + $user_rmt_bal = null; + } + + return (float) $user_rmt_bal; +} + +function get_tx_hash($addr=null) { + $root_trans_hash = null; + try { + $string = "https://testnet.florincoin.info/ext/getaddress/$addr"; + $json = file_get_contents($string); + $data = json_decode($json, TRUE); + foreach ($data["last_txs"] as $cur) { + if ($cur["type"] == "vout") { + $root_trans_hash = $cur["addresses"]; + break; + } + } + } catch (Exception $e) { + return null; + } + return $root_trans_hash; +} + +function get_block_hash($root_trans_hash) { + $root_block_hash = null; + try { + $string = "https://testnet.florincoin.info/api/getrawtransaction?txid=".$root_trans_hash."&decrypt=1"; + $json = file_get_contents($string); + $data = json_decode($json, TRUE); + $root_block_hash = $data["blockhash"]; + } catch (Exception $e) { + return null; + } + return $root_block_hash; +} + +function get_block_index($root_block_hash) { + $root_block_index = null; + try { + $string = "https://testnet.florincoin.info/api/getblock?hash=".$root_block_hash; + $json = file_get_contents($string); + $root_block_index = json_decode($json, TRUE); + //$root_block_index = $data["height"]; + } catch (Exception $e) { + return null; + } + return $root_block_index; +} + +function get_current_block_count() { + $current_block_index = null; + try { + $string = "https://testnet.florincoin.info/api/getblockcount"; + $json = file_get_contents($string); + $data = json_decode($json, TRUE); + $current_block_index = $data; + } catch (Exception $e) { + return null; + } + return $current_block_index; +} + +function get_current_blockhash($block_index=null) { + $blockhash = null; + try { + $string = "https://testnet.florincoin.info/api/getblockhash?index=".$block_index; + $blockhash = file_get_contents($string); + } catch (Exception $e) { + return null; + } + return $blockhash; +} + +function listcheck($element=null) { + try { + $element = (float) $element; + if (!is_float($element)) { + throw new Exception("Invalid float value"); + } + } catch(Exception $e) { + echo 'Message: ' .$e->getMessage(); + return 1; + } + return 0; +} + +function dothemagic($blockindex=null) { + if ($blockindex==null) { + return; + } + $blockindex = (int) $blockindex; + $blockhash = get_current_blockhash($blockindex); + $blockinfo = get_block_index($blockhash); + + foreach ($blockinfo["tx"] as $transaction) { + $string = "https://testnet.florincoin.info/api/getrawtransaction?txid=".$transaction."&decrypt=1"; + $json = file_get_contents($string); + $data = json_decode($json, TRUE); + $text = substr($data["floData"], 5); + $comment_list = explode("#", $text); + + if ($comment_list[0]=='ranchimalltest') { + echo "

I just saw ranchimalltest

"; + $commentTransferAmount = $comment_list[1]; + + if (strlen($commentTransferAmount)==0) { + echo "Value for token transfer has not been specified"; + continue; + } + + $returnval = listcheck($commentTransferAmount); + if ($returnval == 1) { + continue; + } + $commentTransferAmount_arr = []; + array_push($commentTransferAmount_arr, $commentTransferAmount); + $commentTransferAmount =$commentTransferAmount_arr; + + $inputlist = []; + $querylist = []; + + foreach ($data["vin"] as $obj) { + array_push($querylist, [$obj["txid"], $obj["vout"]]); + } + + $inputval = 0; + $inputadd = ''; + + foreach ($querylist as $query) { + $string = "https://testnet.florincoin.info/api/getrawtransaction?txid=".$query[0]."&decrypt=1"; + $json = file_get_contents($string); + $content = json_decode($json, TRUE); + + foreach ($content["vout"] as $objec) { + if ($objec["n"] == $query[1]) { + $inputadd = $objec["scriptPubKey"]["addresses"][0]; + $inputval = $inputval + $objec["value"]; + } + } + } + + array_push($inputlist, [$inputadd, $inputval]); + + if (count($inputlist) > 1) { + print("Program has detected more than one input address "); + print("This transaction will be discarded"); + continue; + } + + $outputlist = []; + foreach ($data["vout"] as $obj) { + if ($obj["scriptPubKey"]["type"] == "pubkeyhash") { + if ($inputlist[0][0] == $obj["scriptPubKey"]["addresses"][0]) { + continue; + } + $temp = []; + array_push($temp, $obj["scriptPubKey"]["addresses"][0]); + array_push($temp, $obj["value"]); + array_push($outputlist, $temp); + } + } + + print("Input List"); + echo "
"; + print_r($inputlist); + echo "
"; + print("Output List"); + print_r($outputlist); + echo "
"; + + + } + } + } \ No newline at end of file diff --git a/includes/header.php b/includes/header.php index 57369b8..9df0624 100644 --- a/includes/header.php +++ b/includes/header.php @@ -18,7 +18,7 @@ if (isset($UserClass)) { $validate_user = $UserClass->is_fb_registered($fb_id); if($validate_user == "" || $validate_user == false) { - redirect_to('index.php'); + redirect_to('index.php?msg=Unknown User'); } endif; @@ -50,7 +50,7 @@ if(checkLoginStatus()) { - diff --git a/rm_root.php b/rm_root.php index 9554ba3..013c453 100644 --- a/rm_root.php +++ b/rm_root.php @@ -26,7 +26,7 @@
-

Transfer tokens

+

Transfer tokens (Please select a BC from second select box above)

@@ -134,6 +134,14 @@
+
@@ -145,8 +153,8 @@ Id User - RMT - Cash + BC + Balance Action @@ -281,20 +289,20 @@ $(document).on('click', '#bc_tr_btn', function() { var bc_bal_updt = $('#bc-bal-updt').val(); var cus_id = $('#cus_id').val(); - var sel_bc2 = $('#sel-bc-2').val(); + var sel_bc2 = $('#bc_menue_sel').val(); var job = 'update-user-bc-balance'; var btn = this; if (sel_bc2=="") { $.notify({ title: "Alert!: ", - message: "Please choose a contract from second dropdown at top." + message: "Please choose a contract from the dropdown menu." },{ type: 'warning' }); return false; } - $(btn).val('Please wait....').prop( "disabled", true ); + $(btn).prop( "disabled", true ); $.ajax({ method: 'post', @@ -304,7 +312,8 @@ console.log(xhr, status, error); }, success: function(data) { - $(btn).val('Transfer '+sel_bc2).prop( "disabled", false ); + console.log(data); + $(btn).prop( "disabled", false ); if ($.trim(data) != '' && $.trim(data) != undefined && $.trim(data) != null) { var IS_JSON = true; try { diff --git a/style/main.css b/style/main.css index 3846b0a..58774c0 100644 --- a/style/main.css +++ b/style/main.css @@ -25,7 +25,7 @@ input[type=text] { } .sel-div { display: flex; - width: 100%; + //width: 100%; } .selbc { margin-right: 5px; @@ -61,44 +61,23 @@ h5 > span { } } -.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 { +a.nav-link { + font-weight: 500; + color: var(--secondary); padding-top: .75rem; padding-bottom: .75rem; font-size: .875rem; - color: var(--secondary); } -.nav-underline .nav-link:hover { - color: var(--blue); -} - -.nav-underline .active { +a.active { font-weight: 500; color: var(--gray-dark); } +a.nav-link:hover { + color: var(--blue); +} + .text-white-50 { color: rgba(255, 255, 255, .5); } .bg-purple { background-color: var(--purple); } @@ -114,8 +93,8 @@ h5 > span { /*Extra small devices (portrait phones, less than 576px)*/ @media (max-width: 576px) { body { - //display: block; - padding-top: 56px; + display: block; + // padding-top: 56px; //font-size: 24px; width: 100%; } @@ -131,7 +110,7 @@ h5 > span { /*Small devices (landscape phones, 576px and up)*/ @media (min-width: 576px) { body { - padding-top: 56px; + //padding-top: 56px; //font-size: 18px; !important; } .lays { @@ -146,7 +125,7 @@ h5 > span { /*Medium devices (tablets, 768px and up)*/ @media (min-width: 768px) { body { - padding-top: 56px; + //padding-top: 56px; //font-size: 16px; } .lays { diff --git a/views/req_user_info.php b/views/req_user_info.php new file mode 100644 index 0000000..e264c48 --- /dev/null +++ b/views/req_user_info.php @@ -0,0 +1,52 @@ +input_user_email($email, $user_id); + if ($updateEmail) { + $_SESSION['email'] = $email; + redirect_to("index.php?msg=Email updated as $email successfully.&type=success"); + } + redirect_to("index.php?msg=Email could not be updated.&type=warning"); + } + ?> + + + +