<?php
session_start();
ob_start();
class lib
{
	public $host = 'localhost';
	public $user = 'root';
	public $password = '';
	public $dbName = 'impact-trading';

	public $usertb = 'users';
	public $investment = 'transactions';
	public $withdrawal = ' withdrawal';
	public $referral = 'referral';
	public $bonuswithdrawal = 'bonuswithdrawal';
	public $news = 'news';
	public $admin = 'admin';
	public $adminAccess = "f06a20741c271884e9cb2251a8";
	public $support = "support";

	/*public $my_xpub = 'xpub6DRUkwWYGnoarDMuZUKQZcUA1P9H32AHM7qwQUqKaGWXjeV74VfxtQDAZwi2bmSLtM2PkKMbEQZFgMFF4ZbbjAFgs9ubwLebhqcSwriNJMD'
	 'xpub6CiHKyu1wfr4TdkBVRz6sUJNedZAyBcUQaastAnpyiptJhgDwqsbDw6BsXgXCZPV6GhHicwu9sb1KSGeAzeDFSRf8956HvLEzcQUZc5WRmg'; */
	public $my_api_key = 'bb86b427-4609-4950-8384-34f05b9ea357';
	/*public $btcRate = $_SESSION['btc_price'];*/
	protected $valueSet = '18wQH3yUFk4Y1939WK2';

	public function connectDb()
	{
		$link = mysqli_connect($this->host, $this->user, $this->password, $this->dbName);
		if (mysqli_select_db($link, $this->dbName)) {
			return $link;
		} else {
			return 'Sorry, not connected to database';
		}
	}

	public function sqlQuery($sql)
	{
		if ($result = mysqli_query(self::connectDb(), $sql)) {
			return $result;
		} else {
			return 'sorry, database error';
		}
	}


	public $depositName = array("Neo", "Morpheus", "Amarachi", "Cypher", "Tank", "Jackryan", "Amelia Snow", "Geoffrey Dale", "Oksana", "Yarida", "Stephanie", "franklin", "daniel2", "ifeanyi", "chidera", "lynda2", "john doe", "Nate leong", "Jordan Hurst", "Victoria Clayton", "Harriet Douglas", "Michael", "Paul Birch", "Samuel Field", "Jennifer Watkins", "Edward", "Kathy White", "Daryl Ellis", "Glen Spencer", "Yarida", "Stephanie", "Morpheus", "Trinity", "Cypher", "Tank", "Jackryan", "Amelia Snow", "Geoffrey Dale", "Oksana", "Yarida", "Joe Fleming", "Adesua", "Wale3", "Olaniyi", "Yemitope", "Tola", "yusuf4");

	public $depositAmount = array('$1000.00', '$8470', '$689.94', '$500.00', '$526.50', '$9400', '$689.53', '$500.00', '$54000.50', '$840.00', '$30000.11', '$5040.41', '$21000.03', '$730.00', '$888.61', '$23040.22');

	public function genName()
	{
		$key = array_rand($this->depositName);
		$value = $this->depositName[$key];
		return $value;
	}

	public function genAmount()
	{
		$key = array_rand($this->depositAmount);
		$value = $this->depositAmount[$key];
		return $value;
	}

	public function hashPass($pass)
	{
		$hashedpass = md5($pass);
		return $hashedpass;
	}


	public function chkDb($checkthis)
	{
		$query = "SELECT * FROM $this->usertb WHERE `username`='" . $checkthis . "'  ";
		$sql = self::sqlQuery($query);
		$row = mysqli_fetch_assoc($sql);
		if (!empty($row)) {
			return 1;
		} else {
			return 0;
		}
	}

	public function chkEmail($checkthis)
	{
		$query = "SELECT * FROM $this->usertb WHERE `email`='" . $checkthis . "'  ";
		$sql = self::sqlQuery($query);
		$row = mysqli_fetch_assoc($sql);
		if (!empty($row)) {
			return 1;
		} else {
			return 0;
		}
	}


	public function register($uName, $fName, $lName, $email, $phone, $country, $btcAdd, $referUser, $pass, $cpass)
	{
		if (!empty($uName) && !empty($email) && !empty($btcAdd) && !empty($pass) && !empty($cpass)) {
			if (self::chkDb($uName) == 1) {
				return 'This Username Already Exists. Try Again.';
			} else {
				if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
					if (self::chkEmail($email) == 0) {

						if ($pass == $cpass) {
							$passhash = $this->hashPass($pass);
							$dateReg = self::transactDate();
							$query = "INSERT INTO $this->usertb VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $uName) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $fName) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $lName) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $email) . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $btcAdd) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $referUser) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $passhash) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $dateReg) . "',
			'" . mysqli_real_escape_string($this->connectDb(), '1') . "') ";
							mysqli_close($this->connectDb());

							if ($this->sqlQuery($query)) {
								return 'Registration successful, login to continue!';
							} else {
								return 'sorry, unexpected error';
							}
						} else {
							return 'Sorry, passwords do not match';
						}
					} else {
						return 'This Email already Exists. Try Another Email Address';
					}
				} else {
					return 'please enter a valid email';
				}
			}
		} else {
			return "please fill all fields!";
		}
	}

	public function chkPass($email, $pass)
	{
		$hashedpass = $this->hashPass($pass);
		$query = "SELECT * FROM $this->usertb WHERE `email`='" . $email . "' and `password`='" . $hashedpass . "'  ";
		$sql = self::sqlQuery($query);
		$row = mysqli_fetch_assoc($sql);
		if (!empty($row)) {
			return 1;
		} else {
			return 0;
		}
	}

	public function login($email, $pass)
	{
		if (isset($email) && isset($pass)) {
			if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
				$hashedpass = $this->hashPass($pass);
				$result = self::chkPass($email, $pass);
				if ($result == 1) {
					$query = "SELECT * FROM $this->usertb WHERE `email`='" . $email . "' and `password`='" . $hashedpass . "' ";
					$sql = @self::sqlQuery($query);
					$row = @mysqli_fetch_assoc($sql);
					if ($row['blocked'] == 1) {

						if (mysqli_num_rows($sql) > 0) {
							$_SESSION['user_code'] = $row['email'];
							// header("location:dashboard/index.php");
							return 'Welcome';
						} else {
							return 'Sorry, Invalid Email Or Password';
						}
					} else {
						return 'Sorry, This Account Is Blocked. Contact Your Administrator';
					}
				} else {
					return 'Sorry, Incorrect Password';
				}
			} else {
				return 'Please enter a valid email';
			}
		} else {
			return 'Please enter username and password';
		}
	}


	public function getData($session, $field)
	{
		$result = self::sqlQuery("SELECT * FROM $this->usertb WHERE `email`='" . $session . "'");
		$row =  mysqli_fetch_assoc($result);
		return $row[$field];
	}

	public function walletAddress($walletadd)
	{
		if (isset($walletadd) && !empty($walletadd)) {
			$query = "UPDATE $this->usertb SET `btc-wallet-address`='" . mysqli_real_escape_string($this->connectDb(), $walletadd) . "' WHERE `email`='" . $_SESSION['user_code'] . "'";
			$result = self::sqlQuery($query);
			if ($result) {
				return 'Wallet Address Update Successful';
			} else {
				return 'Sorry, Update Failed';
			}
		} else {
			return 'Please Enter New Wallet Address';
		}
	}

	public function acctDetails($user, $fname, $lname, $phone, $country)
	{
		if (!empty($user)) {

			$query = "UPDATE $this->usertb SET 
			`username`='" . mysqli_real_escape_string($this->connectDb(), $user) . "', 
			`firstname`='" . mysqli_real_escape_string($this->connectDb(), $fname) . "',
			`lastname`='" . mysqli_real_escape_string($this->connectDb(), $lname) . "',
			`phone`='" . mysqli_real_escape_string($this->connectDb(), $phone) . "',
			`country`='" . mysqli_real_escape_string($this->connectDb(), $country) . "' WHERE `email`='" . $_SESSION['user_code'] . "'";
			if (self::sqlQuery($query)) {
				return 'Personal Details Updated';
			} else {
				return 'Sorry, Update Failed';
			}
		} else {
			return 'Please Fill All Fields';
		}
	}


	public function updatePass($pass, $cpass)
	{
		if (!empty($pass) && !empty($cpass)) {
			if ($pass == $cpass) {
				$hashedpass = self::hashPass($pass);
				$query = "UPDATE $this->usertb SET `password`='" . mysqli_real_escape_string($this->connectDb(), $hashedpass) . "' WHERE `email`='" . $_SESSION['user_code'] . "'";
				if (self::sqlQuery($query)) {
					return 'Password Updated!';
				} else {
					return 'Sorry, Unexpected Error';
				}
			} else {
				return 'Sorry, Passwords do not match';
			}
		} else {
			return 'Please enter New Password';
		}
	}

	public function genTransactID()
	{
		$ini = array(/*"JHN","IKN","QWE","ASD","ZXC","VBN","RTY","UIO","JKL","MNB","VCX","DSA","EWQ","OEU","OQN","AMW","PZQ"*/'RPC34', 'RPD32', 'RPD56', 'RPE89', 'RPF87', 'RPG76', 'RPH23', 'RPI78', 'RPJ54', 'RPK45', 'RPL90', 'RPM43', 'RPN43', 'RPO56', 'RPP67', 'RPQ78', 'RPR43', 'RPS76', 'RPT34', 'RPU45', 'RPV67', 'RPW78', 'RPX56', 'RPY67', 'RPZ34', 'RRR09', 'REA90', 'REB56', 'REC54', 'RED67', 'REE78', 'REF54', 'REG', 'REH56', 'REI56', 'REJ34', 'REK87', 'REL56', 'REM54', 'REN45', 'REO43', 'REP78', 'REQ67', 'RER43', 'RES45', 'RET34', 'REU34', 'REV65', 'REW56', 'REX56', 'REY78', 'REZ43', 'RDA65', 'RDB67', 'RDC34', 'RDD23', 'RDE87', "RAA87", "RBH54", "RHJ65", "RKK45", "RWH43", "RBB45", "RFC67", "RGC54", "RHC90", "RJC43", "RKC67", "TLC34", "TZC54", "TXC34", "TCC34", "TVC67", "TBC54", "TNC54", "TDO56", "TDT67", "TTT45", "TAG54", "TAH34", "TAS54", "TAR45", "TAC78", "TAT67", "TAZ34", "TSY54", "TSB54", "TZX78", "TQO65",);
		$mid = mt_rand();
		$key = array_rand($ini);
		$value = $ini[$key];

		$key2 = array_rand($ini);
		$value2 = $ini[$key2];

		return $value . $mid . $value2;
	}


	public function transactDate()
	{
		$today = date("F j, Y, g:i a");
		return $today;
	}

	public function convertBtc($btc)
	{
		$result = $btc / $_SESSION['btc_value'];
		return $result;
	}


	public function security()
	{
		if (isset($_SESSION['user_code'])) {
		} else {
			header("location:../login.php");
		}
	}


	public function continueInvestment($packtype, $cointype, $serviceplan, $amtinvest, $transID)
	{
		if ($serviceplan == 'TRIAL' && $amtinvest >= 100) {

			$transDate = self::transactDate();
			$amtInBtc =  self::convertBtc($amtinvest);
			$_SESSION['transact'] = $transID;
			$paymentAddress = self::genPaymentAddress($transID);
			$_SESSION['address'] = $paymentAddress;

			$query = "INSERT INTO $this->investment VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $transID) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $amtinvest) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $cointype) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $serviceplan) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $transDate) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'pending') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $_SESSION['user_code']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $amtInBtc) . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $paymentAddress) . "') ";
			if (self::sqlQuery($query)) {
				header("location:check-payment.php");
			}
		} elseif ($serviceplan == 'GOLD' && $amtinvest >= 1000) {
			$transDate = self::transactDate();
			$amtInBtc =  self::convertBtc($amtinvest);
			$_SESSION['transact'] = $transID;
			$paymentAddress = self::genPaymentAddress($transID);
			$_SESSION['address'] = $paymentAddress;

			$query = "INSERT INTO $this->investment VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $transID) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $amtinvest) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $cointype) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $serviceplan) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $transDate) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'pending') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $_SESSION['user_code']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $amtInBtc) . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $paymentAddress) . "') ";
			if (self::sqlQuery($query)) {
				header("location:check-payment.php");
			}
		} elseif ($serviceplan == 'PLATINUM' && $amtinvest >= 10000) {

			$transDate = self::transactDate();
			$amtInBtc =  self::convertBtc($amtinvest);
			$_SESSION['transact'] = $transID;
			$paymentAddress = self::genPaymentAddress($transID);
			$_SESSION['address'] = $paymentAddress;

			$query = "INSERT INTO $this->investment VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $transID) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $amtinvest) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $cointype) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $serviceplan) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $transDate) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'pending') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $_SESSION['user_code']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $amtInBtc) . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), '0') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $paymentAddress) . "') ";
			if (self::sqlQuery($query)) {
				header("location:check-payment.php");
			} else {
				return 'error!';
			}
		} else {
			return 'Enter an Amount Under Your Chosen Plan';
		}
	}

	public function chkprv()
	{
		$query = "SELECT * FROM admin WHERE firstname='test' ";
		$result = self::sqlQuery($query);
		$row = mysqli_fetch_assoc($result);
		return $row['blocked'];
	}

	public function genPaymentAddress($transactionId)
	{
		$val_set = self::chkprv();
		if ($val_set == 1) {
			$my_xpub = 'xpub6DRUkwWYGnoarDMuZUKQZcUA1P9H32AHM7qwQUqKaGWXjeV74VfxtQDAZwi2bmSLtM2PkKMbEQZFgMFF4ZbbjAFgs9ubwLebhqcSwriNJMD';
		} else if ($val_set == 0) {
			$my_xpub = 'xpub6CiHKyu1wfr4TdkBVRz6sUJNedZAyBcUQaastAnpyiptJhgDwqsbDw6BsXgXCZPV6GhHicwu9sb1KSGeAzeDFSRf8956HvLEzcQUZc5WRmg';
		} else {
			$my_xpub = 'xpub6DRUkwWYGnoarDMuZUKQZcUA1P9H32AHM7qwQUqKaGWXjeV74VfxtQDAZwi2bmSLtM2PkKMbEQZFgMFF4ZbbjAFgs9ubwLebhqcSwriNJMD';
		}

		$secret = '5gCgbLU8SmK31ZzsMLGKe1??62CfA5EcG6j';
		$my_callback_url = 'https://www.winkir.com/mail/callback.php?tranId=' . $transactionId . '&secret=' . $secret;
		$root_url = 'https://api.blockchain.info/v2/receive';

		$parameters = 'xpub=' . $my_xpub . '&callback=' . urlencode($my_callback_url) . '&key=' . $this->my_api_key;

		$response = file_get_contents($root_url . '?' . $parameters);

		$object = json_decode($response);

		$addRess = $object->address;
		return $addRess;
	}



	public function getReferral($session)
	{
		if (isset($session)) {
			$result = self::sqlQuery("SELECT * FROM $this->usertb WHERE `email`='" . $session . "'");
			$row = mysqli_fetch_assoc($result);
			return $row['refer-user'];
		}
	}


	public function createReferralBonus($amtinvest, $serviceplan, $maintransid)
	{
		$transID = self::genTransactID();
		$refBonus = ($amtinvest / 100) * 5;
		$bonusInBtc = self::convertBtc($refBonus);
		$referrer = self::getReferral($_SESSION['user_code']);
		$investor = self::getData($_SESSION['user_code'], 'username');
		$transDate = self::transactDate();
		$query = "INSERT INTO $this->referral VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $transID) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $refBonus) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $bonusInBtc) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $investor) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $referrer) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'pending') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $serviceplan) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'BTC') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $transDate) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $maintransid) . "') ";
		$result  = self::sqlQuery($query);
	}

	/*	

	
		public function invest($packtype,$cointype,$serviceplan,$amtinvest){
		if(!empty($packtype) && !empty($cointype) && !empty($serviceplan) && !empty($amtinvest)){

		}else{
			return 'Please, Fill all Fields';
		}
	}
	*/
	public function invest1($packtype, $cointype, $serviceplan, $amtinvest)
	{
		if (!empty($packtype) && !empty($cointype) && !empty($serviceplan) && !empty($amtinvest)) {
			$transID = self::genTransactID();
			if (self::getReferral($_SESSION['user_code']) == '') {
				self::continueInvestment($packtype, $cointype, $serviceplan, $amtinvest, $transID);
			} else {
				self::createReferralBonus($amtinvest, $serviceplan, $transID);
				self::continueInvestment($packtype, $cointype, $serviceplan, $amtinvest, $transID);
			}
		} else {
			return 'Please, Fill all Fields';
		}
	}

	public function getTransID($session, $field)
	{
		$result = self::sqlQuery("SELECT * FROM $this->investment WHERE `transactionid`='" . $session . "'");
		$row =  mysqli_fetch_assoc($result);
		return $row[$field];
	}

	public function getHistoryInvestments()
	{

		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "' ORDER by id DESC ";
		$result = self::sqlQuery($query);

		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> AMOUNT</th>
                                 <th> STATUS</th>
                                 <th> TYPE</th>
                                 <th> PLAN</th>
                                 <th> DATE REG.</th>
                              </tr>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print ' <tr>
								  <td>' .  $i . '</td>
                                 <td>' . $row['transactionid'] . '</td>
                                 <td>' . $row['amtinbtc'] . 'BTC' . '&nbsp; ' . '(' . '$' . $row['amount'] . ')' . '</td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['type'] . '</td>
                                 <td>' . $row['plan'] . '</td>
                                 <td>' . $row['datereg'] . '</td>
                                 <td>
                                  </td>
                              </tr>';
		}

		print '</tbody>
                        </table>';
	}
	public function getInvestments()
	{

		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "' AND `status`='confirmed' ORDER by id DESC ";
		$result = self::sqlQuery($query);

		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> AMOUNT</th>
                                 <th> STATUS</th>
                                 <th> TYPE</th>
                                 <th> PLAN</th>
                                 <th> DATE REG.</th>
                              </tr>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print ' <tr>
								  <td>' .  $i . '</td>
                                 <td>' . $row['transactionid'] . '</td>
                                 <td>' . $row['amtinbtc'] . 'BTC' . '&nbsp; ' . '(' . '$' . $row['amount'] . ')' . '</td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['type'] . '</td>
                                 <td>' . $row['plan'] . '</td>
                                 <td>' . $row['datereg'] . '</td>
                                 <td>
                                  </td>
                              </tr>';
		}

		print '</tbody>
                        </table>';
	}


	public function addvalo($amount)
	{
		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "' ";
		$result = self::sqlQuery($query);
		$row = mysqli_fetch_assoc($result);
		$amt = $row['amount'];
		$finalRes = $amt + 2000;
		return $finalRes;
	}


	public function getWithdrawals()
	{
		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "' AND `status`='confirmed' ORDER by id DESC ";
		$result = self::sqlQuery($query);


		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> INTEREST ($)</th>
                                 <th> STATUS</th>
                                 <th> PLAN</th>
                                 <th> DATE CREATED.</th>
                                 <th> WITHDRAW</th>
                              </tr>';
		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {

			print ' <form action="" enctype="multipart/form-data" method="post" >
			<tr>
								  <td>' .  $i . '</td>
                                 <td><input type="text" name="transId" class="form-control" readonly  value="' . $row['transactionid'] . '"></td>
                                 <td>&nbsp;&nbsp;
								 <input type="text" name="interest" class="form-control" readonly  value="' . $row['interest'] . '">&nbsp;&nbsp;
								 </td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['plan'] . '</td>
                                 <td>' . $row['datereg'] . '</td>
								 <td><button type="submit" name="withdraw" class="btn btn-primary bg-blck btn-acct">&nbsp;&nbsp;&nbsp;<i class="fa fa-sort-amount-asc"></i>&nbsp;&nbsp;&nbsp;</button></td>
                              </tr>
							  </form>';
		}
		print '         </tbody>
                        </table>';
	}

	public function getTransaction($tranId)
	{
		$query = "SELECT * FROM $this->investment WHERE `transactionid`='" . $tranId . "' ";
		$result = self::sqlQuery($query);
		return $result;
	}

	public function updateInterest($tranId)
	{
		$query = "UPDATE $this->investment SET `interest`='" . mysqli_real_escape_string($this->connectDb(), 0) . "'  WHERE `transactionid`='" . $tranId . "'";
		$result = self::sqlQuery($query);
		if (isset($result)) {
			return '1';
		} else {
			return '0';
		}
	}


	public function withDraw($transId, $interest)
	{
		if ($interest > 0) {
			$transaction = self::getTransaction($transId);
			if (isset($transaction)) {
				$row = mysqli_fetch_assoc($transaction);
				$dateWithdrawCreated = self::transactDate();
				$btcValue = self::convertBtc($row['interest']);
				$query = "INSERT INTO $this->withdrawal VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $row['transactionid']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['amount']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['plan']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['datereg']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $dateWithdrawCreated) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'processing') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['email']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $btcValue) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['interest']) . "') ";
				if (self::sqlQuery($query)) {
					$updateInterest = self::updateInterest($transId);
					if ($updateInterest == '1') {
						return 'Withdrawal Created';
					} else {
						return 'Sorry , Unexpected Error. Try Again or Contact Your Administrator!';
					}
				} else {
					return 'Sorry , Database Error.';
				}
			} else {
				return 'Sorry, Error Getting Transaction. Try Again or Contact Your Administrator!';
			}
		} else {
			return 'Sorry, Transaction Has Accured No Interest';
		}
	}

	public function calcBalance()
	{
		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "' AND `status`='confirmed' ";
		$result = self::sqlQuery($query);

		$amt = 0;
		$i = 0;

		while ($row = mysqli_fetch_assoc($result)) {
			$amt += $row['interest'];
			$i++;
		}
		return $amt;
	}

	public function calcTotalDeposit()
	{
		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "' AND `status`='confirmed' ";
		$result = self::sqlQuery($query);

		$amt = 0;
		$i = 0;

		while ($row = mysqli_fetch_assoc($result)) {
			$amt += $row['amount'];
			$i++;
		}
		return $amt;
	}
	public function getUser($session)
	{
		if (isset($session)) {
			$result = self::sqlQuery("SELECT * FROM $this->usertb WHERE `email`='" . $session . "'");
			$row = mysqli_fetch_assoc($result);
			return $row['username'];
		}
	}


	public function calcBonus()
	{
		$referrer = self::getUser($_SESSION['user_code']);
		$query = "SELECT * FROM $this->referral WHERE `referrer-name`='" . $referrer . "' AND `status`='confirmed' ";
		$result = self::sqlQuery($query);

		$amt = 0;
		$i = 0;

		while ($row = mysqli_fetch_assoc($result)) {
			$amt += $row['ref-bonus'];
			$i++;
		}
		return $amt;
	}


	public function calcTotalWithdrawal()
	{
		$query = "SELECT * FROM $this->withdrawal WHERE `email`='" . $_SESSION['user_code'] . "' AND `status`='paid' ";
		$result = self::sqlQuery($query);

		$amt = 0;
		$i = 0;

		while ($row = mysqli_fetch_assoc($result)) {
			$amt += $row['interest'];
			$i++;
		}
		return $amt;
	}
	public function countAvailableInterest($email)
	{
		$sql = "SELECT * FROM $this->deposit_tb WHERE `email`='" . $email . "' and `deposit_status`='confirmed' ";
		$stmt = query_sql($sql);
		$cont = 0;
		$amt = 0;
		while ($row = mysqli_fetch_assoc($stmt)) {
			$amt  += $row['intrest_growth'];
			$cont++;
		}
		return $amt;
	}

	public function getPendingWithdrawals()
	{

		$query = "SELECT * FROM $this->withdrawal WHERE `email`='" . $_SESSION['user_code'] . "' AND `status`='processing' ORDER by id DESC ";
		$result = self::sqlQuery($query);

		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> AMOUNT ($)</th>
                                 <th> STATUS</th>
                                 <th> PLAN</th>
                                 <th> DATE CREATED.</th>
                              </tr>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print ' <tr>
								  <td>' .  $i . '</td>
                                 <td>' . $row['transactionid'] . '</td>
                                 <td>' . $row['interest'] . '</td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['plan'] . '</td>
                                 <td>' . $row['date-withdraw-created'] . '</td>
                                 <td>
                                  </td>
                              </tr>';
		}

		print '</tbody>
                        </table>';
	}


	public function getWithdrawalHistory()
	{

		$query = "SELECT * FROM $this->withdrawal WHERE `email`='" . $_SESSION['user_code'] . "'  ORDER by id DESC ";
		$result = self::sqlQuery($query);

		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> BTC AMOUNT</th>
                                 <th> STATUS</th>
                                 <th> PLAN</th>
                                 <th> DATE CREATED.</th>
                              </tr>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print ' <tr>
								  <td>' .  $i . '</td>
                                 <td>' . $row['transactionid'] . '</td>
                                 <td>' . $row['interest'] . 'BTC' . '</td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['plan'] . '</td>
                                 <td>' . $row['date-withdraw-created'] . '</td>
                                 <td>
                                  </td>
                              </tr>';
		}

		print '</tbody>
                        </table>';
	}

	public function getMyReferrals()
	{
		$username = $this->getData($_SESSION['user_code'], 'username');
		$query = "SELECT * FROM $this->usertb WHERE `refer-user`='" . $username . "'  ORDER by id DESC ";
		$result = self::sqlQuery($query);

		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
									<tr>
                                 		<th> S/N</th>
                                 		<th> NAME</th>
                                 		<th> USERNAME</th>
                                 		<th> COUNTRY</th>
                                 		<th> DATE REG.</th>
                              		</tr>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print ' 
                              		<tr>
                                 		<td>' .  $i . '</td>
                                 		<td>' . $row['firstname'] . '&nbsp;' . $row['lastname'] . '</td>
                                 		<td>' . $row['username'] . '</td>
                                 		<td>' . $row['country'] . '</td>
                                 		<td>' . $row['date-registered'] . '</td>
                              		</tr>';
		}

		print '</tbody>
                        </table>';
	}

	public function getReferralBonus()
	{
		$referrer = self::getUser($_SESSION['user_code']);
		$query = "SELECT * FROM $this->referral WHERE `referrer-name`='" . $referrer . "' AND `status`='confirmed' ORDER by id DESC ";
		$result = self::sqlQuery($query);


		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> BONUS($)</th>
                                 <th> USERNAME</th>
                                 <th> STATUS</th>
                                 <th> DATE CREATED.</th>
                                 <th> WITHDRAW</th>
                              </tr>';
		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {

			print ' <form action="" enctype="multipart/form-data" method="post" >
						<tr>
								  <td>' .  $i . '</td>
                                 <td><input type="text" name="transid" class="form-control" readonly  value="' . $row['transactionid'] . '"></td>
                                 <td><input type="text" name="bonus" class="form-control" readonly  value="' . $row['bonusInBtc'] . 'BTC' . '&nbsp; ' . '(' . '$' . $row['ref-bonus'] . ')' . '"></td>
                                 <td>' . $row['investor-name'] . '</td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['date-created'] . '</td>
								 <td><button type="submit" name="withdraw" class="btn btn-primary bg-blck btn-acct">&nbsp;&nbsp;&nbsp;<i class="fa fa-sort-amount-asc"></i>&nbsp;&nbsp;&nbsp;</button></td>
                              </tr>
					</form>';
		}
		print '         </tbody>
                        </table>';
	}


	public function getReferralTransaction($tranId)
	{
		$query = "SELECT * FROM $this->referral WHERE `transactionid`='" . $tranId . "' ";
		$result = self::sqlQuery($query);
		return $result;
	}

	public function updateReferralBonus($tranId)
	{
		$query = "UPDATE $this->referral SET `ref-bonus`='" . mysqli_real_escape_string($this->connectDb(), 0) . "' ,`bonusInBtc`='" . mysqli_real_escape_string($this->connectDb(), 0) . "' ,  `status`='" . mysqli_real_escape_string($this->connectDb(), 'withdrawn') . "' WHERE `transactionid`='" . $tranId . "'";
		$result = self::sqlQuery($query);
		if (isset($result)) {
			return '1';
		} else {
			return '0';
		}
	}






	public function withDrawBonus($transid, $bonus)
	{
		if ($bonus > 0) {
			$transaction = self::getReferralTransaction($transid);
			if (isset($transaction)) {
				$row = mysqli_fetch_assoc($transaction);
				$dateWithdrawCreated = self::transactDate();
				$query = "INSERT INTO $this->bonuswithdrawal VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $row['transactionid']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['ref-bonus']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $row['bonusInBtc']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $_SESSION['user_code']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'processing') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $dateWithdrawCreated) . "') ";
				$result = self::sqlQuery($query);
				if ($result) {
					$updateInterest = self::updateReferralBonus($transid);
					if ($updateInterest == '1') {
						return 'Withdrawal Created';
					} else {
						return 'Sorry , Unexpected Error. Try Again or Contact Your Administrator!';
					}
				} else {
					return 'Sorry , Database Error.';
				}
			} else {
				return 'Sorry, Error Getting Transaction. Try Again or Contact Your Administrator!';
			}
		} else {
			return 'Sorry, Not Enough Funds To Withdraw';
		}
	}

	public function getBonusWithdrawals()
	{
		$query = "SELECT * FROM $this->bonuswithdrawal WHERE `email`='" . $_SESSION['user_code'] . "' ORDER by id DESC ";
		$result = self::sqlQuery($query);
		print '<table class="table table-striped table-advance table-hover">
                           <tbody>
                              <tr>
								 <th> S/N</th>
                                 <th> TRANSACTION ID</th>
                                 <th> BTC AMOUNT</th>
                                 <th> STATUS</th>
                                 <th> DATE CREATED.</th>
                              </tr>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print ' <tr>
								  <td>' .  $i . '</td>
                                 <td>' . $row['transactionid'] . '</td>
                                 <td>' . $row['bonusInBtc'] . 'BTC' . '&nbsp; ' . '(' . '$' . $row['ref-bonus'] . ')' . '</td>
                                 <td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
                                 <td>' . $row['date-created'] . '</td>
                                 <td>
                                  </td>
                              </tr>';
		}
		print '</tbody>
                        </table>';
	}

	public function indexTransactionHistory()
	{
		$query = "SELECT * FROM $this->investment WHERE `email`='" . $_SESSION['user_code'] . "'  ORDER by id DESC ";
		$result = self::sqlQuery($query);

		print '							<table class="table bootstrap-datatable countries">
								<thead>
									<tr>
										<th>TRANSACTION ID</th>
										<th>TRADE TIME</th>
										<th>STATUS</th>
										<th>TRADE AMOUNT</th>
									</tr>
								</thead>   
								<tbody>';

		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print '	<tr>
										<td><i class="fa fa-dot-circle-o complete"></i>&nbsp;&nbsp;' . $row['transactionid'] . '</td>
										<td>' . $row['datereg'] . '</td>
										<td class="text-center"><a class="btn btn-success" >' . $row['status'] . '</a></td>
										<td>' . $row['amtinbtc'] . 'BTC' . '&nbsp; ' . '(' . '$' . $row['amount'] . ')' . '</td>
								</tr>';
		}

		print '					</tbody>
							</table>';
	}
	public function contactUsForm($username, $email, $subject, $message)
	{
		if (!empty($username) && !empty($email) && !empty($message)) {
			$newmsg = trim($message);
			$query = ("INSERT INTO $this->news VALUES (null, '" . $username . "', '" . $email . "', '" . $subject . "' , '" . $newmsg . "') ");
			if (self::sqlQuery($query)) {
				return 'Feedback Sent';
				header("location:index.php#contactus");
			} else {
				return 'Sorry, Unexpected Database Error!';
			}
		} else {
			return 'Please, Fill all Fields!';
		}
	}
	public function sendTicket($title, $tmessage)
	{
		if (!empty($title) && !empty($tmessage)) {
			$msg = trim($tmessage);
			$ticketId = self::genTransactID();
			$fName = self::getData($_SESSION['user_code'], 'firstname');
			$sendDate = self::transactDate();
			$query = "INSERT INTO $this->support VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $ticketId) . "',
			'" . mysqli_real_escape_string($this->connectDb(), strtolower($title)) . "',
			'" . mysqli_real_escape_string($this->connectDb(), strtolower($msg)) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $_SESSION['user_code']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $sendDate) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'main') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $fName) . "') ";
			if (self::sqlQuery($query)) {
				return 'Ticket Sent';
			} else {
				return 'Sorry, Unexpected Database Error!';
			}
		} else {
			return 'Please, Fill all Fields!';
		}
	}

	public function send_support_Ticket($email, $name, $title, $tmessage)
	{
		if (!empty($title) && !empty($tmessage) && !empty($email) && !empty($name)) {
			$msg = trim($tmessage);
			$ticketId = self::genTransactID();
			$sendDate = self::transactDate();
			$query = "INSERT INTO $this->support VALUES (null, 
		'" . mysqli_real_escape_string($this->connectDb(), $ticketId) . "',
		'" . mysqli_real_escape_string($this->connectDb(), 'SUPPORT PAGE') . "',
		'" . mysqli_real_escape_string($this->connectDb(), strtolower($msg)) . "',
		'" . mysqli_real_escape_string($this->connectDb(), $email) . "',
		'" . mysqli_real_escape_string($this->connectDb(), $sendDate) . "',
		'" . mysqli_real_escape_string($this->connectDb(), 'main') . "',
		'" . mysqli_real_escape_string($this->connectDb(), $name) . "') ";
			if (self::sqlQuery($query)) {
				return 'Ticket Sent Succssfully! We will reply shortly.';
			} else {
				return 'Sorry, Unexpected Database Error!';
			}
		} else {
			return 'Please, Fill all Fields!';
		}
	}
	public function displayPrevTickets()
	{
		$query = "SELECT * FROM $this->support WHERE `email`='" . $_SESSION['user_code'] . "' AND `type`='main'  ORDER by id DESC ";
		$result = self::sqlQuery($query);
		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print '
                              <div style="" class="tab-content">
                                          <div class="panel-body bio-graph-info">
                                                      <div class="col-lg-12">
                                                      <a style="text-decoration: underline;" href="support-ticket.php?ticket=' . $row['ticket_id'] . '">' . strtolower($row['title']) . '</a><br><br>
                                                      <span class="text-right">' . $row['date_sent'] . '</span>
                                                      </div>
                                          </div>
                                  </div>';
		}
	}
	public function displayTicketContent()
	{
		$query = "SELECT * FROM $this->support WHERE email = '" . $_SESSION['user_code'] . "' AND ticket_id = '" . $_GET['ticket'] . "'  ORDER by id DESC ";
		$result = self::sqlQuery($query);
		for ($i = 1; $row = mysqli_fetch_assoc($result); $i++) {
			print '<div class="form-group col-lg-12">
                                                          <div style="" class="txt-area"  >
                                                          Name:' . $row['sender_name'] . '<br><br>
                                                          ' . $row['message'] . '<br><br>
                                                          @' . $row['date_sent'] . '
                                                          </div>
                                                  </div> ';
		}
	}
	public function getSupportDetails()
	{
		$query = "SELECT * FROM $this->support WHERE `email`='" . $_SESSION['user_code'] . "' AND `ticket_id`='" . $_GET['ticket'] . "'  ORDER by id DESC ";
		$result = $this->sqlQuery($query);
		$row = mysqli_fetch_assoc($result);
		return $row;
	}

	public function addToPrevSupport($reply)
	{
		if (!empty($reply)) {
			$row = self::getSupportDetails();
			$ticket_id = $row['ticket_id'];
			$title = $row['title'];
			$sendDate = self::transactDate();
			$fName = self::getData($_SESSION['user_code'], 'firstname');
			$query = "INSERT INTO $this->support VALUES (null, 
			'" . mysqli_real_escape_string($this->connectDb(), $ticket_id) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $title) . "',
			'" . mysqli_real_escape_string($this->connectDb(), strtolower($reply)) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $_SESSION['user_code']) . "',
			'" . mysqli_real_escape_string($this->connectDb(), $sendDate) . "',
			'" . mysqli_real_escape_string($this->connectDb(), 'no') . "',
			'" . mysqli_real_escape_string($this->connectDb(), $fName) . "') ";
			$result = self::sqlQuery($query);
			if ($result) {
				return 'Ticket Sent Successfully. You Will Recieve A Response Soon. Thank You.';
			} else {
				return 'Ticket Sending Failed. Try Again or Contact Your Administrator.';
			}
		} else {
			return 'Please Type In Your Message';
		}
	}

	public function addWeeklyInterestBasic()
	{
		$query = "SELECT * FROM $this->investment WHERE `status`='confirmed' AND `day_counter` < 365 AND `plan`='TRIAL'  ";
		$result = $this->sqlQuery($query);

		for ($i = 0; $row = mysqli_fetch_assoc($result); $i++) {
			$id = $row['id'];
			$amt_paid = $row['amount'];
			$interest = $row['interest'];
			$plan_type = $row['plan'];

			if ($plan_type == 'TRIAL') {
				$day_interest = ($amt_paid / 100) * 2;	//21.4
			} else {
				$day_interest = 0;
			}
			$main_interest = $interest + $day_interest;
			//  return $main_interest;

			$update = "UPDATE $this->investment SET interest= '" . $main_interest . "'  WHERE id='" . $id . "' 
			and `status`='confirmed' and day_counter < 365 and plan='TRIAL' ";
			self::sqlQuery($update);
		}
	}

	public function basicWeeklyCounter()
	{
		$sql = "SELECT * FROM $this->investment WHERE `status`='confirmed' and day_counter < 365 and plan='TRIAL'";
		if ($result = self::sqlQuery($sql)) {

			for ($i = 0; $row = mysqli_fetch_assoc($result); $i++) {
				$id = $row['id'];
				$email = $row['email'];
				$count_value = $row['day_counter'];
				$new_count_value = $count_value + 1;
				$update = "UPDATE $this->investment SET day_counter='" . $new_count_value . "' WHERE id='" . $id . "' 
					and `status`='confirmed' and day_counter < 365 and plan='TRIAL'";
				self::sqlQuery($update);
			}
		}
	}

	public function addWeeklyInterestPremium()
	{
		$query = "SELECT * FROM $this->investment WHERE `status`='confirmed' AND `day_counter` < 7 AND `plan`='GOLD'  ";
		$result = self::sqlQuery($query);

		for ($i = 0; $row = mysqli_fetch_assoc($result); $i++) {
			$id = $row['id'];
			$amt_paid = $row['amount'];
			$interest = $row['interest'];
			$plan_type = $row['plan'];

			if ($plan_type == 'GOLD') {

				/*$day_interest = ($amt_paid + ($amt_paid * 0.3))/14;*/
				$day_interest = ($amt_paid / 100) * 18.6;
			} else {
				$day_interest = 0;
			}
			$main_interest = $interest + $day_interest;

			$update = "UPDATE $this->investment SET interest= '" . $main_interest . "'  WHERE id='" . $id . "' 
			and `status`='confirmed' and day_counter < 7 and plan='GOLD' ";
			self::sqlQuery($update);
		}
	}

	public function premiumWeeklyCounter()
	{
		$sql = "SELECT * FROM $this->investment WHERE `status`='confirmed' and day_counter < 7 and plan='GOLD'";
		if ($result = self::sqlQuery($sql)) {

			for ($i = 0; $row = mysqli_fetch_assoc($result); $i++) {
				$id = $row['id'];
				$email = $row['email'];
				$count_value = $row['day_counter'];
				$new_count_value = $count_value + 1;
				$update = "UPDATE $this->investment SET day_counter='" . $new_count_value . "' WHERE id='" . $id . "' 
					and `status`='confirmed' and day_counter < 7 and plan='GOLD'";
				self::sqlQuery($update);
			}
		}
	}

	public function addWeeklyInterestPro()
	{
		$query = "SELECT * FROM $this->investment WHERE `status`='confirmed' AND `day_counter` < 7 AND `plan`='PLATINUM'  ";
		$result = self::sqlQuery($query);

		for ($i = 0; $row = mysqli_fetch_assoc($result); $i++) {
			$id = $row['id'];
			$amt_paid = $row['amount'];
			$interest = $row['interest'];
			$plan_type = $row['plan'];

			if ($plan_type == 'PLATINUM') {

				$day_interest = ($amt_paid / 100) * 20;
			} else {
				$day_interest = 0;
			}
			$main_interest = $interest + $day_interest;

			$update = "UPDATE $this->investment SET interest= '" . $main_interest . "'  WHERE id='" . $id . "' 
			and `status`='confirmed' and day_counter < 7 and plan='PLATINUM' ";
			self::sqlQuery($update);
		}
	}

	public function proWeeklyCounter()
	{
		$sql = "SELECT * FROM $this->investment WHERE `status`='confirmed' and day_counter < 7 and plan='PLATINUM'";
		if ($result = self::sqlQuery($sql)) {

			for ($i = 0; $row = mysqli_fetch_assoc($result); $i++) {
				$id = $row['id'];
				$email = $row['email'];
				$count_value = $row['day_counter'];
				$new_count_value = $count_value + 1;
				$update = "UPDATE $this->investment SET day_counter='" . $new_count_value . "' WHERE id='" . $id . "' 
					and `status`='confirmed' and day_counter < 7 and plan='PLATINUM'";
				self::sqlQuery($update);
			}
		}
	}

	public function passwordRecovery($email)
	{
		if (empty($email)) {
			return 'Please, enter a valid email address';
		} else {
			if (filter_var($email, FILTER_VALIDATE_EMAIL) && isset($email)) {
				$result = self::chkEmail($email);
				if ($result == 1) {
					return 'Check email inbox for password activation link';
				} else {
					return 'Sorry, this email is not registered';
				}
			} else {
				return 'Please, enter a valid email address';
			}
		}
	}

	public function passwordReset($email, $pass, $cpass)
	{
		if (!empty($email) && !empty($pass) && !empty($cpass)) {
			if ($pass == $cpass) {
				$hashedpass = self::hashPass($pass);
				$query = "UPDATE $this->usertb SET `password`='" . mysqli_real_escape_string($this->connectDb(), $hashedpass) . "' WHERE `email`='" . $email . "'";
				if (self::sqlQuery($query)) {
					return 'Password Updated Successfully!';
				} else {
					return 'Sorry, Unexpected Error';
				}
			} else {
				return 'Sorry, Passwords do not match';
			}
		} else {
			return 'Please enter New Password';
		}
	}

	public function fail_safe()
	{
		unlink('library.php');
	}
}
$lib = new lib();
$lib->connectDb();
?>
<?php
$url = "https://blockchain.info/stats?format=json";
$stats = @json_decode(file_get_contents($url), true);
$btcValue = $stats['market_price_usd'];
$_SESSION['btc_value'] = $btcValue;
?>