diff --git a/ajax/OrderMatchingAlgorithmAjax.php b/ajax/OrderMatchingAlgorithmAjax.php index a841174..1a89f30 100644 --- a/ajax/OrderMatchingAlgorithmAjax.php +++ b/ajax/OrderMatchingAlgorithmAjax.php @@ -10,7 +10,13 @@ if (isset($_POST['task']) && trim($_POST['task'])=='run_OrderMatchingAlgorithm') if ($slc1 == "" || $slc2 == "") {return;} - $refresh_orders = $OrderClass->OrderMatchingService($_POST['sel1'], $_POST['sel2']); + $is_sel1_valid= $OrderClass->is_bc_valid($slc1, 1, null); + $is_sel2_valid= $OrderClass->is_bc_valid($slc2, null, 1); + if (!$is_sel1_valid || !$is_sel2_valid) { + return; + } + + $refresh_orders = $OrderClass->OrderMatchingService($slc1, $slc2); /*If user is logged in user send him messages, if any*/ if (checkLoginStatus()) { diff --git a/ajax/current_prices.php b/ajax/current_prices.php index f4cc17b..8dedc81 100644 --- a/ajax/current_prices.php +++ b/ajax/current_prices.php @@ -5,15 +5,55 @@ if (isset($_POST['task']) && trim($_POST['task']=='current_prices')) { $bc2 = isset($_POST['bc2']) ? $_POST['bc2'] : null; $std = new stdClass(); - $std->bc = array(); + $std->cp = array(); $std->error = true; if (isset($OrderClass)) { - $wallet = $OrderClass->tx_data(null,$bc2,null); + $is_bc_valid= $OrderClass->is_bc_valid($bc2, null, 1); + if ($is_bc_valid) { + /*$wallet = $OrderClass->tx_data(null,$bc2,null); + $rmteq = $OrderClass->tx_data(null,RMT,null); - $std->bc = $wallet; - $std->error = false; + $usd_eq = array(); + if (is_array($wallet)&&!empty($wallet)) { + foreach ($wallet as $w) { + if (isset($w->a_amount, $w->b_amount)) { + $b = $w->b_amount; + if ($w->b_amount == RMT && isset($_SESSION['RMT_TODAYS_PRICE'])) { + $b = $_SESSION['RMT_TODAYS_PRICE']; + } + $usd_eq[] = bc_to_usd($w->a_amount, $b); // bc eq in rmt * rmt eq in usd + } + } + }*/ + $bcs = $OrderClass->get_bc_list(null, 1, 1); + $bccode = array(); + $bc2_eq = array(); + $rmt_eq = array(); + $usd_eq = array(); + + $res = array( + 'BC'=>'', + 'BC2VAL'=>'', + 'RMTVAL'=>'', + 'USDVAL'=>'' + ); + if (is_array($bcs)&&!empty($bcs)) { + foreach ($bcs as $i=>$b) { + $bccode[] = $b->bc_code; + $bc2_eq[] = isset($OrderClass->get_bc1_to_bc2_eq($b->bc_code, $bc2)->a_amount) ? $OrderClass->get_bc1_to_bc2_eq($b->bc_code, $bc2)->a_amount : 0; + $rmt_eq[] = isset($OrderClass->get_bc1_to_bc2_eq($b->bc_code, RMT)->a_amount) ? $OrderClass->get_bc1_to_bc2_eq($b->bc_code, RMT)->a_amount : 0; + if (isset($_SESSION['RMT_TODAYS_PRICE'])) { + $usd_eq[] = bc_to_usd($rmt_eq[$i], $_SESSION['RMT_TODAYS_PRICE']); + } + $res=['BC'=>$bccode, 'BC2VAL'=>$bc2_eq, 'RMTVAL'=>$rmt_eq, 'USDVAL'=>$usd_eq]; + } + } + + $std->cp = $res; + $std->error = false; + } } echo json_encode($std); } diff --git a/ajax/pending_orders.php b/ajax/pending_orders.php index a44b587..e0c4bf2 100644 --- a/ajax/pending_orders.php +++ b/ajax/pending_orders.php @@ -6,13 +6,17 @@ if (!checkLoginStatus()) { } if (isset($_POST['subject']) && trim($_POST['subject'])=='placeOrder') { - + if (isset($UserClass, $OrderClass)) { $std = new stdClass(); $std->user = null; $std->order = null; $std->error = false; $std->msg = null; + $place_order = ""; + $validate_user = ""; + $msss = "Order could not be placed."; + if (isset($_POST['sel1'], $_POST['qty'], $_POST['price'], $_POST['sel2'], $_POST['bs_rad'], $_POST['is_mkt'])) { $WantAssetTypeId = trim($_POST['sel1']); $OfferAssetTypeId = trim($_POST['sel2']); @@ -31,19 +35,29 @@ if (isset($_POST['subject']) && trim($_POST['subject'])=='placeOrder') { $orderStatusId = 2; // 0 -> cancelled; 1 -> complete; 2 -> pending - if($WantAssetTypeId == '') { + $is_sel1_valid= $OrderClass->is_bc_valid($WantAssetTypeId, 1, null); + $is_sel2_valid= $OrderClass->is_bc_valid($OfferAssetTypeId, null, 1); + + if($WantAssetTypeId == '' || !$is_sel1_valid) { $std->error = true; $std->msg = "Please select first Blockchain contract."; echo json_encode($std); return false; } - if($OfferAssetTypeId == '') { + if($OfferAssetTypeId == '' || !$is_sel2_valid) { $std->error = true; $std->msg = "Please select second Blockchain contract."; echo json_encode($std); return false; } - if($qty == '' || $qty < 0) { + + if ($WantAssetTypeId==$OfferAssetTypeId) { + $std->error = true; + $std->msg = "Both contracts cannot be same. Please select different contracts to trade."; + echo json_encode($std); + return false; + } + if($qty == '' || $qty < 0.0000000001) { $std->error = true; $std->msg = "Please provide a valid quantity to be traded."; echo json_encode($std); @@ -59,6 +73,16 @@ if (isset($_POST['subject']) && trim($_POST['subject'])=='placeOrder') { } } + $isValidQty = validate_decimal_place($qty, 10); + $isValidPrice = validate_decimal_place($price, 10); + + if (!$isValidQty || !$isValidPrice) { + $std->error = true; + $std->msg = 'Please insert valid quantity and price. Maximum 10 decimal places allowed.'; + echo json_encode($std); + return false; + } + if ($buy_sell=='ex-buy') { $orderTypeId = 0; // It is a buy $order_type = 'm-buy'; // for market req @@ -74,10 +98,6 @@ if (isset($_POST['subject']) && trim($_POST['subject'])=='placeOrder') { return false; } - $place_order = ""; - $validate_user = ""; - if (isset($UserClass, $OrderClass)) { - $validate_user = $UserClass->check_user($user_id); if($validate_user == "" || empty($validate_user)) { @@ -87,21 +107,76 @@ if (isset($_POST['subject']) && trim($_POST['subject'])=='placeOrder') { return false; } + $top_tbl = null; + if ($orderTypeId == 0) { + $user_current_bal = (float) $OrderClass->check_customer_balance($OfferAssetTypeId, $user_id)->balance; + $top_tbl = TOP_BUYS_TABLE; + $user_active_orders = $OrderClass->get_active_buy_order_of_user($user_id, $OfferAssetTypeId, $top_tbl); + + $frozen_bal = 0; + if (is_array($user_active_orders) && !empty($user_active_orders)) { + foreach ($user_active_orders as $uao) { + $frozen_bal += (float) $uao->price * $uao->quantity; + } + } + $allowed_bid_amount = 0; + if ($user_current_bal > $frozen_bal) { + $allowed_bid_amount = $user_current_bal - $frozen_bal; + } + $ext_st = "You can put bid up to $OfferAssetTypeId $allowed_bid_amount only."; + $ext_st2 = ""; + if ($allowed_bid_amount == 0) { + $ext_st = "You don't have any $OfferAssetTypeId balance to spend."; + } + if ((float)$frozen_bal != 0) { + $ext_st2 = "You have already placed an order worth $OfferAssetTypeId $frozen_bal."; + } + $msss = "Insufficient Balance: $ext_st2 $ext_st"; + + } elseif ($orderTypeId == 1) { + $user_current_bal = (float) $OrderClass->check_customer_balance($WantAssetTypeId, $user_id)->balance; + $top_tbl = TOP_SELLS_TABLE; + $user_active_orders = $OrderClass->get_active_sell_order_of_user($user_id, $WantAssetTypeId, $top_tbl); + $frozen_bal = 0; + if (is_array($user_active_orders) && !empty($user_active_orders)) { + foreach ($user_active_orders as $uao) { + $frozen_bal += (float) $uao->quantity; + } + } + $allowed_bid_amount = 0; + if ($user_current_bal > $frozen_bal) { + $allowed_bid_amount = $user_current_bal - $frozen_bal; + } + $ext_st = "You can sell maximum $WantAssetTypeId $allowed_bid_amount units."; + if ($allowed_bid_amount == 0) { + $ext_st = "You don't have any $WantAssetTypeId to sell."; + } + $msss = "Insufficient Balance: You have already placed an order of $WantAssetTypeId $frozen_bal. $ext_st"; + } + + if ($frozen_bal + $total_trade_val > $user_current_bal) { + $std->error = true; + $std->msg = $msss; + 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); } + $msss = ""; + $std->user = $validate_user; + $std->order = $place_order; + $std->error = false; + $std->msg = $msss; + echo json_encode($std); + return false; } - - $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); diff --git a/ajax/refresh_table.php b/ajax/refresh_table.php index e70a22f..0e4b87d 100644 --- a/ajax/refresh_table.php +++ b/ajax/refresh_table.php @@ -1,11 +1,11 @@ buys = null; @@ -14,6 +14,19 @@ if (isset($_POST['task'], $_POST['bc1'], $_POST['bc2']) && trim($_POST['task'])= $std->error = true; if (isset($OrderClass, $UserClass)) { + if (isset($bc1) && trim($bc1)!=="") { + $is_sel1_valid= $OrderClass->is_bc_valid($bc1, 1, null); + if (!$is_sel1_valid) { + return; + } + } else {$bc1=null;} + + if (isset($bc2) && trim($bc2)!=="") { + $is_sel2_valid= $OrderClass->is_bc_valid($bc2, null, 1); + if (!$is_sel2_valid) { + return; + } + } else {$bc2=null;} $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 diff --git a/ajax/rm_root.php b/ajax/rm_root.php index aabc4d4..6623b2c 100644 --- a/ajax/rm_root.php +++ b/ajax/rm_root.php @@ -2,7 +2,7 @@ require_once '../includes/imp_files.php'; -if (!checkLoginStatus()) { +if (!checkLoginStatus() || !isset($UserClass, $OrderClass)) { return false; } @@ -43,4 +43,70 @@ if (isset($_SESSION['fb_id'], $_SESSION['user_id'], $_SESSION['user_name'])) { return false; } + if (isset($_POST['job']) && trim($_POST['job']=="inset_bc")) { + if (isset($_POST['ct_name'], $_POST['bccode'], $_POST['bcadmin'], $_POST['incpdt'])) { + $contractName = trim($_POST['ct_name']); + $bcCode = strtoupper(trim($_POST['bccode'])); + $bcAdmin = trim($_POST['bcadmin']); + $eliSel1 = (trim($_POST['ch1'])=='true'?1:0); + $eliSel2 = (trim($_POST['ch2'])=='true'?1:0); + $incp = trim($_POST['incpdt']); + + $std = new stdClass(); + $std->ctr = null; + $std->msg = null; + $std->error = true; + + if (strlen($bcCode)>8) { + $std->msg = "Blockchain Code cannot be greater than 8 characters."; + echo json_encode($std); + return false; + } + + $insertBC = $OrderClass->insert_new_bc($contractName, $bcCode, $bcAdmin, $eliSel1, $eliSel2, $incp); + + if ($insertBC) { + $std->ctr = $insertBC; + $std->msg = "New BC inserted successfully"; + $std->error = false; + } else { + $std->msg = "Failed to insert new BC."; + } + } else { + $std->msg = "Please fill all the fields"; + } + + echo json_encode($std); + return false; + } + + if (isset($_POST['updt_job']) && trim($_POST['updt_job']=="update_sel_bc")) { + if (isset($_POST['_id'])) { + $id = trim($_POST['_id']); + $exp = explode("_",$id); + $bc = $exp[1]; + $sel = $exp[0]; + $val = (int) $exp[2]; + $val = ($val=='')?1:0; + + $std = new stdClass(); + $std->res = null; + $std->val = null; + + if ($bc==''||$sel==''||$val==='') { + echo json_encode($std); + return; + } + + $res = $OrderClass->update_bc_eligibility($bc, $sel, $val); + + $std = new stdClass(); + $std->res = $res; + $std->val = $val; + $std->new_id = $sel.'_'.$bc.'_'.$val; + echo json_encode($std); + return; + } + } + } \ No newline at end of file diff --git a/ajax/sel_bc_stats.php b/ajax/sel_bc_stats.php index d10c6e4..b8476f9 100644 --- a/ajax/sel_bc_stats.php +++ b/ajax/sel_bc_stats.php @@ -11,6 +11,11 @@ if (isset($_POST['task'], $_POST['bc1'], $_POST['bc2']) && trim($_POST['task'])= $std->error = true; if (isset($OrderClass)) { + $is_sel1_valid= $OrderClass->is_bc_valid($bc1, 1, null); + $is_sel2_valid= $OrderClass->is_bc_valid($bc2, null, 1); + if (!$is_sel1_valid || !$is_sel2_valid) { + return; + } $data = $OrderClass->tx_data($bc1, $bc2, 1); if (!empty($data)) { diff --git a/ajax/tradeList.php b/ajax/tradeList.php index a560b44..5d40823 100644 --- a/ajax/tradeList.php +++ b/ajax/tradeList.php @@ -10,13 +10,21 @@ require_once '../includes/imp_files.php'; if (isset($_POST['task'],$_POST['bc1'],$_POST['bc2']) && trim($_POST['task'])=='loadTradeList') { + $bc1 = trim($_POST['bc1']); + $bc2 = trim($_POST['bc2']); + $std = new stdClass(); $std->trade_list = array(); $std->error = true; if (isset($OrderClass, $UserClass)) { + $is_sel1_valid= $OrderClass->is_bc_valid($bc1, 1, null); + $is_sel2_valid= $OrderClass->is_bc_valid($bc2, null, 1); + if (!$is_sel1_valid || !$is_sel2_valid) { + return; + } - $tradeList = $OrderClass->last_transaction_list(0,10,trim($_POST['bc1']),trim($_POST['bc2'])); + $tradeList = $OrderClass->last_transaction_list(0,10,$bc1,$bc2); $std->trade_list = $tradeList; $std->error = false; diff --git a/ajax/tradersList.php b/ajax/tradersList.php index 40a3c8a..c32748b 100644 --- a/ajax/tradersList.php +++ b/ajax/tradersList.php @@ -18,6 +18,11 @@ if (isset($_POST['task'], $_POST['bc2']) && trim($_POST['task'])=='loadTradersLi if (isset($OrderClass)) { + $is_sel2_valid= $OrderClass->is_bc_valid($bc2, null, 1); + if (!$is_sel2_valid) { + return; + } + $tradersList = $OrderClass->UserBalanceList($bc2, 1); if (is_array($tradersList) && !empty($tradersList)) { $std->traders_list = $tradersList; diff --git a/ajax/transfer_tokens.php b/ajax/transfer_tokens.php index f9014f2..75aa71a 100644 --- a/ajax/transfer_tokens.php +++ b/ajax/transfer_tokens.php @@ -1,7 +1,7 @@ is_bc_valid($bc2, null, 1); + + if ($bc2==""||$bc2==null || !$is_sel2_valid) { $mess = "Please choose a Blockchain contract from second dropdown."; $std->error = true; $std->mesg[] = $mess; @@ -65,7 +67,7 @@ if (isset($_POST['job']) && trim($_POST['job']) == "transfer_tokens") { } // Check order in sell table - $user_active_orders = $OrderClass->get_active_order_of_user($from, $bc2, TOP_SELLS_TABLE); + $user_active_orders = $OrderClass->get_active_buy_order_of_user($from, $bc2, TOP_SELLS_TABLE); $frozen_bal_sells = 0; $allowed_bid_amount = $customer_bal_fr; if (is_array($user_active_orders) && !empty($user_active_orders)) { diff --git a/ajax/update_bc_bal.php b/ajax/update_bc_bal.php index adebd9a..9cddece 100644 --- a/ajax/update_bc_bal.php +++ b/ajax/update_bc_bal.php @@ -1,10 +1,5 @@ mesg = array(); $std->error = true; - if ($bc2==""||$bc2==null) { + $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."; $std->error = true; $std->mesg[] = $mess; diff --git a/classes/Orders.php b/classes/Orders.php index 3353a3a..bafb36a 100644 --- a/classes/Orders.php +++ b/classes/Orders.php @@ -158,20 +158,29 @@ class Orders extends Users { return false; } - public function get_top_buy_sell_list($top_table, $WantAssetTypeId, $OfferAssetTypeId, $asc_desc) { + public function get_top_buy_sell_list($top_table, $WantAssetTypeId=null, $OfferAssetTypeId=null, $asc_desc) { if ($this->databaseConnection()) { $top_list = array(); + $st1 = ""; + if (trim($WantAssetTypeId) != null) { + $st1 = " AND $top_table.bc1 = '".$WantAssetTypeId."' "; + } + $st2 = ""; + if (trim($OfferAssetTypeId) != null) { + $st2 = " AND $top_table.bc2 = '".$OfferAssetTypeId."' "; + } - $query = $this->db_connection->query("SELECT $top_table.order_id, $top_table.uid, $top_table.quantity, $top_table.price, ".USERS_TABLE.".name - FROM $top_table, ".USERS_TABLE." - WHERE $top_table.uid = ".USERS_TABLE.".id - AND $top_table.bc1 = '".$WantAssetTypeId."' - AND $top_table.bc2 = '".$OfferAssetTypeId."' - ORDER BY price $asc_desc - LIMIT $this->max_top_bids - "); + $query = $this->db_connection->query(" + SELECT $top_table.order_id, $top_table.uid, $top_table.quantity, $top_table.price, ".USERS_TABLE.".name, $top_table.bc1, $top_table.bc2 + FROM $top_table, ".USERS_TABLE." + WHERE $top_table.uid = ".USERS_TABLE.".id + $st1 + $st2 + ORDER BY price $asc_desc + LIMIT $this->max_top_bids + "); if ($query) { @@ -208,12 +217,22 @@ class Orders extends Users { return false; } - public function get_active_order_of_user($user_id, $bc, $top_table) { + public function get_active_buy_order_of_user($user_id, $bc=null, $top_table) { if ($this->databaseConnection()) { + + $st = ""; + if (trim($bc)!=null) { + $st = " AND bc2 = :bc "; + } $query = $this->db_connection->prepare(" - SELECT * FROM $top_table WHERE `uid`= :uid ORDER BY `insert_dt` DESC + SELECT * FROM $top_table WHERE `uid`= :uid + ".$st." + ORDER BY `insert_dt` DESC "); $query->bindParam('uid', $user_id); + if (trim($bc)!=null) { + $query->bindParam('bc', $bc); + } $query->execute(); $arr = array(); @@ -225,6 +244,33 @@ class Orders extends Users { return false; } + public function get_active_sell_order_of_user($user_id, $bc=null, $top_table) { + if ($this->databaseConnection()) { + $st = ""; + if (trim($bc)!=null) { + $st = " AND bc1 = :bc "; + } + $query = $this->db_connection->prepare(" + SELECT * FROM $top_table WHERE `uid`= :uid + ".$st." + ORDER BY `insert_dt` DESC + "); + $query->bindParam('uid', $user_id); + if (trim($bc)!=null) { + $query->bindParam('bc', $bc); + } + $query->execute(); + + $arr = array(); + while ($qr = $query->fetchObject()) { + $arr[] = $qr; + } + return $arr; + } + return false; + } + + public function OrderMatchingQuery($bc1, $bc2) { if ($this->databaseConnection()) { @@ -1423,6 +1469,14 @@ class Orders extends Users { return false; } + public function get_bc1_to_bc2_eq($bc1, $bc2) { + $res = ""; + if (trim($bc1) !="" && trim($bc2) !="") { + $res = $this->tx_data($bc1, $bc2, $limit=1); + } + return $res; + } + public function record_root_bal_update($uid, $bal_prev, $bal_now, $bal_type) { if ($this->databaseConnection()) { $now = $this->time_now(); @@ -1570,5 +1624,110 @@ class Orders extends Users { return false; } + /*Blockchain Contract Queries*/ + + public function get_bc_list($bc_name = null, $tradable_bc1=null, $tradable_bc2=null) { + $bcl = []; + if ($this->databaseConnection()) { + $st = ''; + $st2 = ''; + if ($bc_name != null) { + $st2 = " AND bc_code=:b "; + } + if ($tradable_bc1!=null && $tradable_bc2!=null) { + $st = 'WHERE eligible_bc1 = 1 AND eligible_bc2 = 1 '.$st2; + } else if ($tradable_bc1!=null && $tradable_bc2==null) { + $st = 'WHERE eligible_bc1 = 1 '.$st2; + } else if ($tradable_bc1==null && $tradable_bc2!=null) { + $st = 'WHERE eligible_bc2 = 1 '.$st2; + } else { + if ($bc_name != null) { + $st2 = " WHERE bc_code=:b "; + } + } + + $query = $this->db_connection->prepare("SELECT * FROM ".BC_TABLE." + $st $st2 "); + + if ($bc_name != null) { + $query->bindParam('b', $bc_name); + } + $query->execute(); + + if ($query->rowCount()) { + while ($l = $query->fetchObject()) { + $bcl[] = $l; + } + } + } + return $bcl; + } + + public function is_bc_valid($bc=null, $val_bc1=null, $val_bc2=null) { + if ($this->databaseConnection()) { + $bc= trim($bc); $val_bc1=trim($val_bc1); $val_bc2=trim($val_bc2); + if ($val_bc1 == null && $val_bc2==null && $bc==null) { + return false; + } + if ($bc != null) { + if ($bc=="RMT") { + return true; + } + $bc_list = array(); + $bcs = $this->get_bc_list(null, $val_bc1, $val_bc2); + if (!empty($bcs)) { + foreach ($bcs as $bcl) { + $bc_list[] = $bcl->bc_code; + } + } + if (in_array($bc, $bc_list)) { + return true; + } + + } + } + return false; + } + + public function insert_new_bc($contractName, $contractCode, $contractAdmin, $isEligibleSel1, $isEligibleSel2, $incpDate) { + if ($this->databaseConnection()) { + + $query = $this->db_connection->prepare(" + INSERT INTO ".BC_TABLE."(`id`, `contracts`, `bc_code`, `admin`, `eligible_bc1`, `eligible_bc2`, `incp`) + VALUES('', :ctr, :bcc, :adm, $isEligibleSel1, $isEligibleSel2, :dt) + "); + $query->bindParam('ctr', $contractName); + $query->bindParam('bcc', $contractCode); + $query->bindParam('adm', $contractAdmin); + $query->bindParam('dt', $incpDate); + if ($query->execute()) { + return true; + } + } + return false; + } + + public function update_bc_eligibility($bc=null, $sel=null, $val=null) { + if ($this->databaseConnection()) { + $st = ''; + if ($sel=="tdsel1") { + $st = "SET `eligible_bc1`=".$val; + } else if ($sel=='tdsel2') { + $st = "SET `eligible_bc2`=".$val; + } + + $query = $this->db_connection->prepare(" + UPDATE ".BC_TABLE." + $st + WHERE `bc_code`= :bc + "); + $query->bindParam('bc', $bc); + if ($query->execute()) { + return true; + } + } + return false; + } + } \ No newline at end of file diff --git a/classes/Users.php b/classes/Users.php index 04ede4b..fc8768a 100644 --- a/classes/Users.php +++ b/classes/Users.php @@ -260,7 +260,7 @@ class Users { public function user_bc_bal($user_id) { if ($this->databaseConnection()) { - $query = $this->db_connection->prepare("SELECT * FROM `wallet` WHERE `uid`=:usr_id"); + $query = $this->db_connection->prepare("SELECT * FROM ".CREDITS_TABLE." WHERE `uid`=:usr_id"); $query->bindParam('usr_id', $user_id); $query->execute(); $bc_bal = array(); diff --git a/fbconfig.php b/fbconfig.php index 65f829b..d60b928 100644 --- a/fbconfig.php +++ b/fbconfig.php @@ -51,7 +51,7 @@ if (isset($accessToken)) { } // getting basic info about user try { - $profile_request = $fb->get('/me?fields=name,first_name,last_name,email'); + $profile_request = $fb->get('/me?fields=name,first_name,last_name,email,picture'); $profile = $profile_request->getGraphNode()->asArray(); } catch(Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error @@ -72,13 +72,14 @@ if (isset($accessToken)) { $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; + $profile_pic = isset($profile['picture']['url']) ? $profile['picture']['url'] : IMG_DIR.'/avavtardefault50px.png'; $_SESSION['first_name'] = $first_name; $_SESSION['full_name'] = $name; $_SESSION['email'] = $email; $_SESSION['fb_id'] = $fb_id; + $_SESSION['profile_pic'] = $profile_pic; // Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token'] diff --git a/images/avavtardefault50px.png b/images/avavtardefault50px.png new file mode 100644 index 0000000..952e838 Binary files /dev/null and b/images/avavtardefault50px.png differ diff --git a/includes/config.example.php b/includes/config.example.php index 806112e..7db4c80 100644 --- a/includes/config.example.php +++ b/includes/config.example.php @@ -61,4 +61,8 @@ 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"); \ No newline at end of file +define("ADMIN_UNAME", "ADMIN USERNAME IN USER TABLE IN DB"); + +if (isset($_SESSION['RMT_TODAYS_PRICE']) && is_float($_SESSION['RMT_TODAYS_PRICE']) && $_SESSION['RMT_TODAYS_PRICE'] > 0) { + define("RMT_CURRENT", $_SESSION['RMT_TODAYS_PRICE']); +} \ No newline at end of file diff --git a/includes/defines.php b/includes/defines.php index 4c0535f..18a490a 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -25,6 +25,9 @@ defined("VIEWS_DIR") || define("VIEWS_DIR", "views"); //CONFIG DIR defined("CONFIG_DIR") || define("CONFIG_DIR", "config"); +//CONFIG DIR +defined("IMG_DIR") || define("IMG_DIR", "images"); + if(isset($_SESSION['user_name'])) { //USER DIR defined("USER_DIR") || define("USER_DIR", "user". DS .$_SESSION['user_name']. DS ."uploads". DS); diff --git a/includes/footer.php b/includes/footer.php index a5d96b5..183c1d1 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -1,3 +1,23 @@ + + +