Your IP : 3.149.29.190


Current Path : /home/lentoinv/covisclubinternational.com/profile/lib/phpmailer/
Upload File :
Current File : //home/lentoinv/covisclubinternational.com/profile/lib/phpmailer/class01.php

<?php

//$_SESSION['user_id'] = 2; 
class Signup{
			
    /* Class constructor */
   function Signup(){
	
	   if(array_key_exists('findSponsor', $_POST)){ $this->findSponsor(); }
	   if(array_key_exists('changeSponsor', $_POST)){ $_SESSION['signup']=NULL; }
	    if(array_key_exists('changeLogin', $_POST)){ $_SESSION['signup']=2; }
	    if(array_key_exists('regContinue', $_POST)){ $_SESSION['signup']=5; 
	    $head = $this->win_hash(85); header("location: ?user_ref=$head"); }
	      if(array_key_exists('changeLogin', $_POST)){ $_SESSION['signup']=5; }
	    if(array_key_exists('signupUser', $_POST)){ $this->signupUser(); }
	   if(array_key_exists('payWithPin', $_POST)){ $this->payWithPin(); }
	   if(array_key_exists('resetPass', $_POST)){ $this->resetPass(); }
	   if(array_key_exists('updateSignup', $_POST)){ $this->updateSignup(); }
	   if(array_key_exists('resetPassConfirm', $_POST)){ $this->resetPassConfirm(); }
	   if(array_key_exists('signupUserIni', $_POST)){ $this->signupUserIni(); }
	    if(isset($_GET['ref'])){ $this->refLink(); }
	    if(isset($_GET['form'])){ if($_GET['form']=='reset'){session_destroy(); header('location: signup.php');} }
	  return;
	  }
	 

	 function refLink(){
$this->findSponsor();
	return;
}

function findSponsor(){
		global $db,$report,$count;

 $user = isset($_POST['sponsor']) ? strtolower($_POST['sponsor']) : strtolower($_GET['ref']);
     if($this->validateUser($user)==FALSE){ $report = 'You have entered an invalid sponsor ID. Please Try Again'; $count=1; 
        } else{
            $_SESSION['signup']=2;
            $_SESSION['sponsorUsername'] = $user; 
           
        $_SESSION['sponsor'] = $this->validateUser($user,1); 
          $_SESSION['sponsorId'] = $this->validateUser($user,2); 
                 $report = 'Sponsor Successfully Validated';
                  if(isset($_GET['ref'])){ header('location: signup.php'); }
 }

return;
	}



	function validateUser($username,$info=''){
		global $db,$report,$count;
			$sql=$db->query("SELECT * FROM user WHERE user = '$username' OR email = '$username' " )or die(mysqli_error()); 
$num=mysqli_num_rows($sql);
$row=mysqli_fetch_assoc($sql);
if($num==0){$res = FALSE; }else{$res = TRUE; }	
if($info==1){$res=$row['firstname'].' '.$row['lastname'];}
if($info==2){$res=$row['sn'];}
return $res;
	}




function signupUserIni(){
	global $report, $count;
	$report='';
	
   /*  $_SESSION['firstname'] = ucwords(strtolower($this->valEmpty($_POST['firstname'],'Firstname')));
     $_SESSION['lastname'] = ucwords(strtolower($this->valEmpty($_POST['lastname'],'Lastname')));
     $_SESSION['address'] = addslashes(ucwords(strtolower($this->valEmpty($_POST['address'],'Address'))));
     $_SESSION['state'] = $this->valEmpty($_POST['state'],'State');
     $_SESSION['city'] = ucwords($this->valEmpty($_POST['city'],'City'));
     $_SESSION['phone'] = $this->valPhone($_POST['phone']);
     */
$_SESSION['email'] = strtolower($this->valEmpty($_POST['email'],'E-mail'));

$_SESSION['username'] = strtolower($this->valEmpty($_POST['username'],'Username'));
$_SESSION['pwd'] = md5($this->valPass($_POST['passw']));
$_SESSION['pwd2'] = md5($_POST['passw2']);

if($_SESSION['pwd'] != $_SESSION['pwd2']){$report .= "<br>Password confirmation failed, Try again"; $count = 1; }
if($this->userExist($_SESSION['username'],$_SESSION['email'])==TRUE){
$report .= "<br>A user with this username/E-mail already exist. Try again."; 
 $count = 1;}

if(!empty($count)){ }else{
$report = "<br>Login Information successfully submitted"; 
$_SESSION['signup']=3;
//header('location: #payment');
}


return;
}


function valEmpty($field,$fname){
	global $report, $count;
	$field = trim($field);
if($field==''){$report .= "<br>".$fname." field is required! "; $count=1; return;}elseif(strlen($field)<3){$report .= "<br>".$fname." entered is too short! "; $count=1; return;}else{
return $field; }
}

function valPhone($field){
	global $report, $count;
	$field = trim($field);
if($field==''){$report .= "<br>Phone Number field is required! "; $count=1; return;}elseif(strlen($field)<11){$report .= "<br>Phone Number entered is invalid! "; $count=1; return;}else{
return $field; }
}

function valPass($field){
	global $report, $count;
if($field==''){$report .= "<br>Password field is required! "; $count=1; return;}elseif(strlen($field)<8){$report .= "<br>Password cannot be less than 8 characters! "; $count=1; return;}else{
return $field; }
}




function payWithPin(){
global $db,$count,$report,$username,$pin;
$pin = strtoupper($_POST['epin']);
$sql=$db->query("select * FROM pin WHERE pin = '$pin' " )or die(mysqli_error()); 
$row = mysqli_fetch_assoc($sql);
$num=mysqli_num_rows($sql);
if($num==1){
if($row['status']==1){$report = 'This E-PIN has already been used by: '.$this->userName2($row['id']).' as at '.$row['created']; $count=1; }elseif($row['status']==0){ 
	$this->signupUser(); 
	$sql=$db->query("UPDATE pin SET status = 1, id = '$username' WHERE pin = '$pin' " )or die(mysqli_error()); 
} 
	}else{

		$report = 'You have entered an invalid E-PIN, verify your E-PIN and try again';  $count=1;
	
}

return;
}




function payWithCoin(){
global $db,$username;
$pin = $_POST['pin'];
$sql=$db->query("SELECT * FROM pin ORDER BY sn ASC LIMIT 1 " )or die(mysqli_error()); 
$row = mysqli_fetch_assoc($sql);
$pin = $row['pin'];

	$this->signupUser(); 
	$sql=$db->query("UPDATE pin SET status = 1, id = '$username' WHERE pin = '$pin' " )or die(mysqli_error()); 
return;
}



	 function signupUser(){
	 global $report, $count, $pwd, $pwd2, $username, $email;
	 
	 /*$firstname = $_SESSION['firstname'];
	 $lastname = $_SESSION['lastname'];
	 $address = $_SESSION['address'];
	 $state = $_SESSION['state'];
	 $city = $_SESSION['city'];
$phone = $_SESSION['phone'];
*/
$email = $_SESSION['email'];

$username = $_SESSION['username'];
$pwd = $_SESSION['pwd'];
$pwd2 = $_SESSION['pwd2'];

$sponsor = $_SESSION['sponsorId']; 

if($this->userExist($username,$email)==TRUE){
$report="A user with this username/E-mail already exist. Try another Username. If you have registered before, go to login area and do password recovery ";	
 $count = 1;}elseif($pwd != $pwd2){$report="Password confirmation failed, Try again"; $count = 1; }else{

if($this->findUser($sponsor)==TRUE){	


			if($this->Downline($sponsor)<MATRIX){	
			$user = $sponsor;
			$this->Register($sponsor,$user);

						$report="You have been successfully registered directly under ".$this->userName($user);


				}        
			else{	
						$ge = 1;
					$user = $this->nextUpline($ge);
					$this->Register($sponsor,$user);
			
				$report="You have been successfully registered directly under ".$this->userName($user);
	
				}

         }else{
			 
			 $report="Sponsor Does not Exist"; $count = 1;
		      }
			  
}

return;
   }
	
	
	
	
			function userName($user){
				global $db;
			$que=$db->query("select * FROM user WHERE sn = '$user' " )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);	
				return $ro['firstname'].' '.$ro['lastname'];
			}	

			function userName2($user){
				global $db;
			$que=$db->query("select * FROM user WHERE user = '$user' " )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);	
				return $ro['firstname'].' '.$ro['lastname'];
			}	
	
	
		function findUser($user){
		global $db;
		$sql=$db->query("select * FROM user WHERE sn = '$user' " )or die(mysqli_error()); 
$num=mysqli_num_rows($sql);
if($num==0){$res = FALSE; }else{$res = TRUE; }
return $res;
	}
	
	function userExist($username,$email){
		global $db,$report,$count;
			$sql=$db->query("SELECT * FROM user WHERE user = '$username' OR email = '$email' " )or die(mysqli_error()); 
$num=mysqli_num_rows($sql);
if($num==0){$res = FALSE; }else{$res = TRUE; }	
return $res;
	}




	
	
	
	function Downline($user){
		global $db;
		$sql=$db->query("select * FROM user WHERE a1 = '$user' " )or die(mysqli_error()); 
$num=mysqli_num_rows($sql);
return $num;
	}
	
	
	
		function Register($sponsor,$user){
		global $db,$report,$count, $pwd, $username, $email, $pin;
		


$que=$db->query("select * FROM user WHERE sn = '$user' " )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);
					$a1 = $ro['sn'];
					$a2 = $ro['a1'];
					$a3 = $ro['a2'];
					$a4 = $ro['a3'];
					$a5 = $ro['a4'];
					$a6 = $ro['a5'];
					$a7 = $ro['a6'];
					$a8 = $ro['a7'];
					$a9 = $ro['a8'];
					$a10 = $ro['a9'];
					$a11 = $ro['a10'];
					$id = $this->win_hash(32);

				$reg = $db->query("INSERT INTO user (id,sponsor,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,email,user,pass,pin)
VALUES('$id','$sponsor','$a1','$a2','$a3','$a4','$a5','$a6','$a7','$a8','$a9','$a10','$email','$username','$pwd','$pin')") or die('Cannot Connect to Server');

$down=$db->query("select * FROM user WHERE a1 = '$user' " )or die(mysqli_error());
$nd=mysqli_num_rows($down);
$upd = $db->query("UPDATE user SET active = '$nd' WHERE sn = '$user' ");

$_SESSION['signup']=4;
	//$this->emailer($email);

return;
	}



function nextUpline($ge){
	global $db;
$sponsor = $_SESSION['sponsorId']; 
	 $gen = 'a'.$ge; 
	 
	 $matrix = MATRIX;
				$que=$db->query("SELECT * FROM user WHERE $gen = '$sponsor' AND active < '$matrix' ORDER BY sn ASC LIMIT 1" )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);
					$find = mysqli_num_rows($que);
					 $user = $ro['sn'];
					 if($find < 1){ $ge = $ge+1; $user = $this->nextUpline2($ge); }
					return $user;
					}
					
function nextUpline2($ge){
	global $db;
	$sponsor = $_SESSION['sponsorId']; 
	 $gen = 'a'.$ge; 
	 $matrix = MATRIX;
	 
				$que=$db->query("select * FROM user WHERE $gen = '$sponsor' AND active < '$matrix' ORDER BY sn ASC LIMIT 1" )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);
					$find = mysqli_num_rows($que);
					 $user = $ro['sn'];
					 if($find < 1){ $ge = $ge+1; $user = $this->nextUpline($ge); }
					return $user;
					}	
			

			
function win_hash($length){
return substr(str_shuffle(str_repeat('123456789',$length)),0,$length);	
}

function resetPass(){
	global $db,$report,$count;
	$email = strtolower(trim($_POST['emailreset']));
$sql=$db->query("SELECT * FROM user WHERE email = '$email' " )or die('Could not initiate password reset');
$row=mysqli_fetch_array($sql);
$reset_order = $this->win_hash(41);
$find = mysqli_num_rows($sql);
if($find==0){$report='This email does not exist in our system, check and try again'; $count=1;}
elseif($find==1){
	$sql=$db->query("UPDATE user SET code='$reset_order' WHERE email = '$email' " )or die('Could not initiate password reset');
$message = 'You have requested for a password reset. Follow the link below to reset your password:<br>';
$message .= 'https://www.smilewecareng.com/resetpassword?reset-order='.$reset_order;
$subject='Smile We-care Password Recovery';
$this->emailerAll($email,$message,$subject);
	$report='We have sent you an e-mail containing your password reset link. Follow the link to reset your password';
}

return;
}



function updateSignup(){
	global $db,$report;
	$username = $_SESSION['username']; 
$firstname=ucwords(strtolower($this->valEmpty($_POST['firstname'],'Surname')));
$lastname=ucwords(strtolower($this->valEmpty($_POST['lastname'],'Other Names')));

$state=$_POST['state'];
$city=ucwords(strtolower($this->valEmpty($_POST['city'],'City')));
$address=addslashes(ucwords(strtolower($this->valEmpty($_POST['address'],'Address'))));
$phone=$this->valPhone($_POST['phone']);
$bank=ucwords(strtolower($this->valEmpty($_POST['bank'],'Bank')));
$accountno=$this->valEmpty($_POST['accountno'],'Account Number');

$dob=$this->valEmpty($_POST['dob'],'Date of Birth');
$sex=$_POST['sex'];
$accname=ucwords(strtolower($this->valEmpty($_POST['accname'],'Account Name')));
//$officeaddress=addslashes(ucwords(strtolower($_POST['officeaddress'])));

	  $photo = isset($_FILES['image']) ? str_replace(' ', '-', $username).$_FILES['image']['name'] : 'user.png';
	  define('upload', 'dashboard/photo/');
	 $success = move_uploaded_file($_FILES['image']['tmp_name'], upload.$photo);
	



$db->query("UPDATE user SET state='$state', city='$city', phone='$phone', address='$address', bank='$bank', accountno='$accountno', firstname='$firstname', lastname='$lastname', sex='$sex', dob='$dob', accname='$accname', photo='$photo' WHERE user = '$username' "); 
//$sms='Your registration is successful. Your username is '.$username.'. Thank you for joining the Believers Family Network. Call '.CPHONE.'for more info.';
//sendSms($sms,$phone,$username);
$report = 'User Information Successfully Updated!';
$_SESSION['signup']=6;

	return;
}







function resetPassOrder(){
global $db;
$order = isset($_GET['reset-order']) ? $_GET['reset-order']:'';
$sql=$db->query("SELECT * FROM user WHERE code = '$order' " );
$find = mysqli_num_rows($sql);
if($find==1){return TRUE;}else{return FALSE;}
}


function resetPassConfirm(){
	global $db,$report,$count;
	$pwd1 = md5($_POST['pwd1']);
	$pwd2 = md5($_POST['pwd2']);
	$reset_order = $this->win_hash(41);
	$code = $this->resetPassOrder() ? $_GET['reset-order'] : 0;
if($pwd1==$pwd2){
$db->query("UPDATE user SET pass='$pwd1', code='$reset_order' WHERE code = '$code' "); $_SESSION['report'] = 'User Password Successfully Changed! You can now login to your account';
header('location: ./login.php'); }else{$report='New Password Mismatch, Try Again'; $count = 1;}


	  return;
}


function Alert(){
	global $report,$count;
	if($count == 0){
 echo '<div class="alert alert-success alert-dismissible" style="position:fixed; top:10px; right:10px; z-index:10000">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <i class="icon fa fa-check"></i>  &nbsp;&nbsp;'. $report .'&nbsp;&nbsp;&nbsp;&nbsp;
              </div>';	
	}
	else{
	 echo '<div class="alert alert-danger alert-dismissible" style="position:fixed; top:10px; right:10px; z-index:10000">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <i class="icon fa fa-ban"></i>   &nbsp;&nbsp;'. $report .' &nbsp;&nbsp;&nbsp;
              </div>';		
	}
	return;
}






function emailerAll($email,$message,$subject){
	global $firstname;
$headers = 'From: Covis Club <admin@smilewecareng.com>' . "\r\n";
$headers .= 'Reply-To: admin@smilewecareng.com' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$send =mail($email,$subject,$message,$headers);
return;
	}	





	function emailer($email){
	global $firstname;
$headers = 'From: Covis Club <admin@smilewecareng.com>' . "\r\n";
$headers .= 'Reply-To: admin@smilewecareng.com' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";


$subject = 'Welcome to Covis Club';
$mailmessage = "Welcome ".$firstname.'<br>Congratulation! You have successfully signed up with Covis Club, a team of  business champions with tenacious drive for financial freedom and business explossion.<br>
click the button below to login to your account using your username and password<br><br>
<a href="https://smilewecareng.com/login" style="border: thin solid #036; text-decoration:none; padding:10px 25px; margin:10px;"> Profile Login</a><br><br>Thank you for joining our team of business revolutionaries.';


$send = mail($email,$subject,$mailmessage,$headers);
return;
	}	


			
		}
		
$signup = new Signup;
		//End of abc class


		
		
		


















	
	//User Profile Class

		if(isset($_SESSION['user_id'])){	
$userKey = $_SESSION['user_id'];
}	

	
class Profile{
	var $amount = 2500;  //Registration Fee
	var $dola = 250;  // Dollar conversion to Naira
	var $dolafee = 10; //Registration fee in dolla
		


private function layerKey(){
return $_SESSION['user_id'];
}
	
	
	//User Array Keys 
	/* Class constructor */
	   function Profile(){
	 if(array_key_exists('changePassword', $_POST)){ $this->changePassword(); }
	  if(array_key_exists('updateUser', $_POST)){ $this->updateUser(); }
	   if(array_key_exists('updatePhoto', $_POST)){ $this->updatePhoto(); }
	   if(array_key_exists('LoginUsers', $_POST)){ $this->LoginUsers(); }
	    if(array_key_exists('withdrawOrder', $_POST)){ $this->withdrawOrder(); }
	     if(array_key_exists('buyEpins', $_POST)){ $this->buyEpins(); }
	     if(array_key_exists('sendMessage', $_POST)){ $this->sendMessage(); }
	     if(array_key_exists('createPin', $_POST)){ $this->createPin(); }
	     if(array_key_exists('stg', $_POST)){ $this->gTree(); }
	     if(array_key_exists('resetChart', $_POST)){ $this->resetChart(); }


	      if(isset($_GET['action'])){if($_GET['action'] =='logout'){ session_destroy(); header('location: ../'); exit; }}
	 return;
	  }
	  


function LoginUsers(){
	global $db,$report,$count;
	$username = strtolower($_POST['usern']);
	$password = md5($_POST['passwo']);
	$sql = $db->query("SELECT * FROM user WHERE user='$username' ");
	$num = mysqli_num_rows($sql);

	if($num==1){
		$row = mysqli_fetch_array($sql);
		$pass = $row['pass'];
		if($pass==$password){$_SESSION['user_id'] = $row['id']; 
		$_SESSION['signup'] = '';
		header('location:dashboard/'); 
	}else{$report='Invalid Login details, Try again'; $count=1;}
	}else{$report='Invalid Login details, Try again'; $count=1;}
 
  return;
}


function validLayer(){
if(strlen($this->layerKey()) != 32){
		unset($_SESSION['user_id']);
	}else{}
	return;
}








function updateUser(){
	global $db,$report,$userKey;
$state=$_POST['state'];
$city=$_POST['city'];
$address=addslashes($_POST['address']);
$phone=$_POST['phone'];
$bank=$_POST['bank'];
$accountno=$_POST['accountno'];


$db->query("UPDATE user SET state='$state', city='$city', phone='$phone', address='$address', bank='$bank', accountno='$accountno' WHERE id = '$this->layerKey()' "); 
$report = 'User Information Successfully Update!';

	return;
}

function updatePhoto(){
	global $db,$report,$userKey; 

	  $name = $this->userName('user').$_FILES['image']['name'];
	  define('upload', 'photo/');
	 $success = move_uploaded_file($_FILES['image']['tmp_name'], upload.$name);

$sqlw = $db->query("UPDATE user SET photo = '$name' WHERE id = '$userKey' ");
$report = 'User Profile Photo Successfully Update!';
return;
}


function changePassword(){
	global $db,$report,$count,$userKey;
	$pa = $this->userName('pass');
	  $currentpass = md5($_POST['currentpass']);
	  $newpass = md5($_POST['newpass']);
	  $newpass2 = md5($_POST['newpass2']);
	  
	  if($pa==$currentpass){
		  if($newpass==$newpass2){$db->query("UPDATE user SET pass='$newpass' WHERE id = '$userKey' "); $report = 'User Password Successfully Changed!';}else{$report='New Password Mismatch, Try Again'; $count = 1;}
		  
	  }else{$report='Password Mismatch, Try Again'; $count = 1;}

return;	  
}




	//Genrating Row Data
function userName($col=''){
				global $db,$userKey;
				
			$que=$db->query("select * FROM user WHERE id = '$userKey' " )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);	
				if(!empty($col)){return $ro[$col];}
				else{return htmlspecialchars($ro['firstname'].' '.$ro['lastname']);}
}	
	
	
	//Total Downlines
		function Downlines(){
				global $db,$userKey;
				$randomKey = $this->userName('sn');
			$a = 1;  $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; 
			$qu=$db->query("select * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			$nu += mysqli_num_rows($qu);	
			}
			return $nu;	
			}
			
		//Total Sponsored by User				
	function Sponsored(){
			global $db,$userKey;
			$randomKey = $this->userName('sn');
			$qu=$db->query("select * FROM user WHERE sponsor = '$randomKey' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			return $nu;	
			}





			
			//Points Generated By User
	function Point(){
		return ($this->Sponsored()*$this->sponsorpoint) + $this->Downlines();
	}

function teamPoint(){
		return $this->Downlines();
	}


	function sponsorPoint(){
		return $this->Sponsored()*$this->sponsorpoint;
	}
	
	function levelRate(){
		return ($this->Level()*100)+$this->pointrate;
	}

	//Loanable Amount
	function Potential(){
		return $this->Point()*$this->levelRate();
	}



	
	function Gen($e){
		global $db,$userKey;
		$randomKey = $this->userName('sn');
		$gen = 'a'.$e;
		$q=$db->query("SELECT * FROM user WHERE $gen ='$randomKey' " )or die(mysqli_error());
		return mysqli_num_rows($q);
	}

		function legGen($e,$leg){
		global $db;
		$e = ($e>0) ? $e : 1;
		$randomKey = $this->legKey($leg);
		$gen = 'a'.$e;
		$q=$db->query("SELECT * FROM user WHERE $gen ='$randomKey' " );
		return mysqli_num_rows($q);
	}

//User Stage level
function Level($t=''){
		global $db;
				$randomKey = $this->userName('sn');

				$sql=$db->query("SELECT * FROM user WHERE a1 = '$randomKey' " )or die(mysqli_error());
			$num = mysqli_num_rows($sql);	

			$a = 1;  $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; $target = MATRIX**$b;
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			if($num<MATRIX){$level=0; $targ=MATRIX;}elseif($nu==$target){$level=$b; $targ=$target;}
			}

			if($level<=1){$stagelevel=0;}
			elseif($level==2){$stagelevel=1;}
			elseif($level==3){$stagelevel=0;}
			elseif($level==4){$stagelevel=1;}
			elseif($level==5){$stagelevel=2;}
			elseif($level==6){$stagelevel=0;}
			elseif($level==7){$stagelevel=1;}
			elseif($level==8){$stagelevel=2;}
			elseif($level==9){$stagelevel=0;}
			elseif($level==10){$stagelevel=1;}
			elseif($level==11){$stagelevel=2;}
			elseif($level==12){$stagelevel=0;}
			elseif($level==13){$stagelevel=1;}
			elseif($level==14){$stagelevel=2;}
			elseif($level==15){$stagelevel=0;}
			elseif($level==16){$stagelevel=1;}
			elseif($level==17){$stagelevel=2;}
			elseif($level==18){$stagelevel=0;}
			elseif($level==19){$stagelevel=1;}
			elseif($level==20){$stagelevel=2;}
			elseif($level==21){$stagelevel=0;}

			//stg = stages counting from 1;
			if($this->Sponsored() < 2){$stage='Waiting'; $stg=1; $nextstagelevel=1; }elseif($level<1){$stage='Waiting'; $stg=1; $nextstagelevel=1; }elseif($level<3){$stage='Induct';  $stg=2; $nextstagelevel=3;}elseif($level<6){$stage='Stage 1';  $stg=3; $nextstagelevel=6;}
			elseif($level<9){$stage='Stage 2';  $stg=4; $nextstagelevel=9;}elseif($level<12){$stage='Stage 3';  $stg=5; $nextstagelevel=12;}elseif($level<15){$stage='Stage 4';  $stg=6; $nextstagelevel=15;}elseif($level<18){$stage='Stage 5';  $stg=7; $nextstagelevel=18;}elseif($level<21){$stage='Stage 6';  $stg=8; $nextstagelevel=21;}
			if($t==1){return $stage;}elseif($t==2){return $stg;}elseif($t==3){return MATRIX**($level+1);}elseif($t==4){return $nextstagelevel;}elseif($t==5){return $stagelevel;}elseif($t==7){return $stage.','.$stagelevel;}else{ return $level;}

}







//User Stage level
function wildLevel2($key,$t=''){
		global $db;
				$randomKey = $key;

				$sql=$db->query("SELECT * FROM user WHERE a1 = '$randomKey' " )or die(mysqli_error());
			$num = mysqli_num_rows($sql);	

			$a = 1;  $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; $target = MATRIX**$b;
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			if($num<MATRIX){$level=0; $targ=MATRIX;}elseif($nu==$target){$level=$b; $targ=$target;}
			}

			if($level<=1){$stagelevel=0;}
			elseif($level==2){$stagelevel=1;}
			elseif($level==3){$stagelevel=0;}
			elseif($level==4){$stagelevel=1;}
			elseif($level==5){$stagelevel=2;}
			elseif($level==6){$stagelevel=0;}
			elseif($level==7){$stagelevel=1;}
			elseif($level==8){$stagelevel=2;}
			elseif($level==9){$stagelevel=0;}
			elseif($level==10){$stagelevel=1;}
			elseif($level==11){$stagelevel=2;}
			elseif($level==12){$stagelevel=0;}
			elseif($level==13){$stagelevel=1;}
			elseif($level==14){$stagelevel=2;}
			elseif($level==15){$stagelevel=0;}
			elseif($level==16){$stagelevel=1;}
			elseif($level==17){$stagelevel=2;}
			elseif($level==18){$stagelevel=0;}
			elseif($level==19){$stagelevel=1;}
			elseif($level==20){$stagelevel=2;}
			elseif($level==21){$stagelevel=0;}

			//stg = stages counting from 1;
			//if($this->wildSponsored($key) < 2){$stage='WAITING'; $stg=1; $nextstagelevel=1; }else
			if($level<1){$stage='Waiting'; $stg=1; $nextstagelevel=1; }elseif($level<3){$stage='Induct';  $stg=2; $nextstagelevel=3;}elseif($level<6){$stage='Stage 1';  $stg=3; $nextstagelevel=6;}
			elseif($level<9){$stage='Stage 2';  $stg=4; $nextstagelevel=9;}elseif($level<12){$stage='Stage 3';  $stg=5; $nextstagelevel=12;}elseif($level<15){$stage='Stage 4';  $stg=6; $nextstagelevel=15;}elseif($level<18){$stage='Stage 5';  $stg=7; $nextstagelevel=18;}elseif($level<21){$stage='Stage 6';  $stg=8; $nextstagelevel=21;}
			if($t==1){return $stage;}elseif($t==2){return $stg;}elseif($t==3){return MATRIX**($level+1);}elseif($t==4){return $nextstagelevel;}elseif($t==5){return $stagelevel;}elseif($t==7){return $stage.','.$stagelevel;}else{ return $level;}

}




function wildSponsored($key){
			global $db,$user;
			$qu=$db->query("select * FROM user WHERE sponsor = '$key' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			return $nu;	
			}






//Wild User Stage/level statistics
function wildLevel($key,$t=''){
		global $db;
				$randomKey = $key;

				$sql=$db->query("SELECT * FROM user WHERE a1 = '$randomKey' " )or die(mysqli_error());
			$num = mysqli_num_rows($sql);	

			$a = 1;  $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; $target = MATRIX**$b;
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			if($num<MATRIX){$level=0; $targ=MATRIX;}elseif($nu==$target){$level=$b; $targ=$target;}
			}
			
				$spon=$db->query("SELECT * FROM user WHERE sponsor = '$randomKey' " )or die(mysqli_error());
			$sp = mysqli_num_rows($spon);

	$targetlev=$level+1; 
	$score =  $this->Gen($targetlev);

				if($sp < 2){$stagelevel=1; $stage='Induct';}
			elseif($level==1){$stagelevel=1; $stage='Induct';}
			elseif($level==2){$stagelevel=0; $stage='STAGE 1';}
			elseif($level==3){$stagelevel=1; $stage='STAGE 1';}
			elseif($level==4){$stagelevel=2; $stage='STAGE 1';}
			elseif($level==5){$stagelevel=0; $stage='STAGE 2';}
			elseif($level==6){$stagelevel=1; $stage='STAGE 2';}
			elseif($level==7){$stagelevel=2; $stage='STAGE 2';}
			elseif($level==8){$stagelevel=0; $stage='STAGE 3';}
			elseif($level==9){$stagelevel=1; $stage='STAGE 3';}
			elseif($level==10){$stagelevel=2; $stage='STAGE 3';}
			elseif($level==11){$stagelevel=0; $stage='STAGE 4';}
			elseif($level==12){$stagelevel=1; $stage='STAGE 4';}
			elseif($level==13){$stagelevel=2; $stage='STAGE 4';}
			elseif($level==14){$stagelevel=0; $stage='STAGE 5';}
			elseif($level==15){$stagelevel=1; $stage='STAGE 5';}
			elseif($level==16){$stagelevel=2; $stage='STAGE 5';}
			elseif($level==17){$stagelevel=0; $stage='STAGE 6';}
			elseif($level==18){$stagelevel=1; $stage='STAGE 6';}
			elseif($level==19){$stagelevel=2; $stage='STAGE 6';}
			elseif($level==20){$stagelevel=0; $stage='STAGE 7';}
			elseif($level==21){$stagelevel=1; $stage='STAGE 7';}

			//stg = stages counting from 1;
			if($this->Sponsored() < 2){ $stg=1; $nextstagelevel=1; }elseif($level<1){ $stg=1; $nextstagelevel=1; }elseif($level<2){ $stg=2; $nextstagelevel=3;}elseif($level<5){$stg=3; $nextstagelevel=6;}
			elseif($level<8){ $stg=4; $nextstagelevel=9;}elseif($level<11){ $stg=5; $nextstagelevel=12;}elseif($level<14){  $stg=6; $nextstagelevel=15;}elseif($level<17){  $stg=7; $nextstagelevel=18;}elseif($level<20){ $stg=8; $nextstagelevel=21;}
			if($t==1){return $stage;}elseif($t==2){return $stg;}elseif($t==3){return MATRIX**($level+1);}elseif($t==4){return $nextstagelevel;}elseif($t==5){return $stagelevel;}elseif($t==6){return $score;}elseif($t==7){return $stg.','.$stagelevel;}else{ return $level;}

}







function legLevel($leg,$t=''){
		global $db;
				$randomKey = $this->legKey($leg);

				$sql=$db->query("SELECT * FROM user WHERE a1 = '$randomKey' " )or die(mysqli_error());
			$num = mysqli_num_rows($sql);	

			$a = 1;  $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; $target = MATRIX**$b;
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			if($num<MATRIX){$level=0; $targ=MATRIX;}elseif($nu==$target){$level=$b; $targ=$target;}
			}

			if($level<=1){$stagelevel=0;}
			elseif($level==2){$stagelevel=1;}
			elseif($level==3){$stagelevel=0;}
			elseif($level==4){$stagelevel=1;}
			elseif($level==5){$stagelevel=2;}
			elseif($level==6){$stagelevel=0;}
			elseif($level==7){$stagelevel=1;}
			elseif($level==8){$stagelevel=2;}
			elseif($level==9){$stagelevel=0;}
			elseif($level==10){$stagelevel=1;}
			elseif($level==11){$stagelevel=2;}
			elseif($level==12){$stagelevel=0;}
			elseif($level==13){$stagelevel=1;}
			elseif($level==14){$stagelevel=2;}
			elseif($level==15){$stagelevel=0;}
			elseif($level==16){$stagelevel=1;}
			elseif($level==17){$stagelevel=2;}
			elseif($level==18){$stagelevel=0;}
			elseif($level==19){$stagelevel=1;}
			elseif($level==20){$stagelevel=2;}
			elseif($level==21){$stagelevel=0;}

			//stg = stages counting from 1;
			if($level<1){$stage='WAITING'; $stg=1; $nextstagelevel=1;}elseif($level<3){$stage='Induct';  $stg=2; $nextstagelevel=3;}elseif($level<6){$stage='STAGE 1';  $stg=3; $nextstagelevel=6;}
			elseif($level<9){$stage='STAGE 2';  $stg=4; $nextstagelevel=9;}elseif($level<12){$stage='STAGE 3';  $stg=5; $nextstagelevel=12;}elseif($level<15){$stage='STAGE 4';  $stg=6; $nextstagelevel=15;}elseif($level<18){$stage='STAGE 5';  $stg=7; $nextstagelevel=18;}elseif($level<21){$stage='STAGE 6';  $stg=8; $nextstagelevel=21;}
			if($t==1){return $stage;}elseif($t==2){return $stg;}elseif($t==3){return MATRIX**($level+1);}elseif($t==4){return $nextstagelevel;}elseif($t==5){return $stagelevel;}else{ return $level;}

}







function levelScore(){
	$lev=$this->Level()+1; 
	return $this->Gen($lev);
}


function levelTarget(){
	return $this->Level(3);
}

function levelProgress(){
	$pro = ($this->levelScore()*100)/$this->levelTarget();
	return number_format($pro,1).'%';
}


function stageLevelScore(){
	$lev=$this->Level(4); 
	return $this->Gen($lev);
}


function stageLevelTarget(){
	return MATRIX**($this->Level(4));//$this->Level(3);
}

function stageLevelProgress(){
	$pro = ($this->stageLevelScore()*100)/$this->stageLevelTarget();
	if($this->Sponsored()==0){$pro = 0;}elseif($this->Sponsored()==1){$pro = 50;}
	return number_format($pro,1).'%';
}


//leg statistics
function legStageLevelScore($leg){
	$lev = $this->Level(4)-1; 
	return $this->legGen($lev,$leg);
}


function legStageLevelTarget(){
	return $this->stageLevelTarget()/2 ;//$this->Level(3);
}

function legStageLevelProgress($leg){
	global $directdown;
	$pro = ($this->legStageLevelScore($leg) > 0) ? ($this->legStageLevelScore($leg)*100)/$this->legStageLevelTarget($leg) : 0;
	if($this->Sponsored()<2){ return '0.0%';}
	elseif($directdown==0){ return '0.0%';}elseif($directdown==1 && $leg==1){ return '0.0%';}elseif($directdown==1 && $leg==0){ return '100.0%';}else{
	return number_format($pro,1).'%';}
}




function proLevel($leg,$t=''){
		global $db;
		$randomKey = $this->legKey($leg);

				$sql=$db->query("SELECT * FROM user WHERE a1 = '$randomKey' " )or die(mysqli_error());
			$num = mysqli_num_rows($sql);	

			$a = 1;  $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; $target = MATRIX**$b;
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			$nu = mysqli_num_rows($qu);	
			if($num<MATRIX){$level=0; $targ=MATRIX;}elseif($nu==$target){$level=$b; $targ=$target;}
			}
			if($level<1){$stage='WAITING'; $stg=1;}elseif($level<3){$stage='Induct';  $stg=2;}elseif($level<6){$stage='STAGE 1';  $stg=3;}
			elseif($level<9){$stage='STAGE 2';  $stg=4;}elseif($level<12){$stage='STAGE 3';  $stg=5;}elseif($level<15){$stage='STAGE 4';  $stg=6;}elseif($level<18){$stage='STAGE 5';  $stg=7;}elseif($level<21){$stage='STAGE 6';  $stg=8;}
			if($t==1){return $stage;}elseif($t==2){return $stg;}else{ return $level;}

}


//stage
function Stage(){
	return $this->Level(1);
}

function Stage1(){
	return $this->Level(2);
}

//leg 1=left, 2=right
function legKey($leg=0){
global $db,$directdown;
$key = '';
		$randomKey = $this->userName('sn');
		$qu=$db->query("SELECT * FROM user WHERE a1 ='$randomKey' ORDER BY sn ASC" )or die(mysqli_error());
		$directdown = mysqli_num_rows($qu);
		while($row = mysqli_fetch_assoc($qu)){
				$key .= $row['sn'].",";
				}
				$key = explode(",", $key);
			//	$left = $key[0];
			//	$right = $key[1];
				$legkey = !empty($key[$leg]) ? $key[$leg] : '';
		return $legkey;
}

function legTable(){
	global $user;
$user = $this->legKey();
$key = '<tr><td>Left</td><td><a href="?q='.$this->userNameWild('id').'" class="text-link">'.$this->userNameWild().'</a></td>
                                            <td>'.$this->userNameWild('sn').'</td></tr>';
$user = $this->legKey(1);
$key .= '<tr><td>Right</td><td><a href="?q='.$this->userNameWild('id').'" class="text-link">'.$this->userNameWild().'</a></td>
                                            <td>'.$this->userNameWild('sn').'</td></tr>';
return $key;}


function userNameWild($col=''){
				global $db,$user;
				
			$que=$db->query("SELECT * FROM user WHERE sn = '$user' " )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);	
				if(!empty($col)){return $ro[$col];}
				else{return $ro['firstname'];}
}	




	function chartMonth(){
		$range = '';
		$cm = date('m');
		$a = $cm-5; 
			while($a<=$cm){ $b=$a++; $c = date("M", mktime(0, 0, 0, $b, 10));
			$range .= "'".$c."', ";
			}

			return $range;
	}


//chart data of total entry per 
	function monthEntryData(){
		$range = '';
		$cm = date('m');
		$a = $cm-5; 
			while($a<=$cm){ $b=$a++; $c = $this->monthDownlines($b);
			$range .= $c.', ';
			}

			return $range;
	}





	//chart data of total entry per 
	function monthEntryDataTotal(){
		$range = '';
		$cm = date('m');
		$a = $cm-5; 
			while($a<=$cm){ $b=$a++; $c = $this->entryPerMonth($b);
			$range .= $c.', ';
			}

			return $range;
	}


//chart data of user monthly sponsor
		function monthUserSponsor(){
		$range = '';
		$cm = date('m');
		$a = $cm-5; 
			while($a<=$cm){ $b=$a++; $c = $this->sponsorPerMonth($b);
			$range .= $c.', ';
			}

			return $range;
	}

//maximum monthly entry// $tim = max(explode(",", $profile->monthUserSponsor()));
	function maxMonthly(){
		$max = max(explode(",", $this->monthEntryData()));
		return $max;
	}



	//maximum monthly entry total for all users //
	function maxMonthlyTotal(){
		$max = max(explode(",", $this->monthEntryDataTotal()));
		return $max;
	}

//Calculate total monthly entry
function entryPerMonth($month){
	global $db;
	$num = 0;
	$sql=$db->query("select * FROM user " )or die(mysqli_error());
	while($row = mysqli_fetch_assoc($sql)){
$tim = (int)substr($row['created'],5,2); 
if($tim==$month){$num += 1;	}
}
return $num;
}



		function monthDownlines($month){
				global $db,$userKey;
				$randomKey = $this->userName('sn');
			$a = 1;  $num = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; 
			$sql=$db->query("select * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			while($row = mysqli_fetch_assoc($sql)){
$tim = (int)substr($row['created'],5,2); 
if($tim==$month){$num += 1;	}
}	
			}
			return $num;	
			}






//Calculate the amunt of members sponsored by a user monthly
function sponsorPerMonth($month){
	global $db;
	$randomKey = $this->userName('sn');
	$num = 0;
	$sql=$db->query("SELECT * FROM user WHERE sponsor = '$randomKey' " )or die(mysqli_error());
	while($row = mysqli_fetch_assoc($sql)){
$tim = (int)substr($row['created'],5,2); 
if($tim==$month){$num += 1;	}
}
return $num;
}




//referral table
	function Referrals(){
			global $db;
			$randomKey = $this->userName('sn');
			$table = '<table id="example23" class="display nowrap" cellspacing="0" width="100%">
                                    <thead>
                                        <tr>
                                            <th>SN</th>
                                             <th>Full Name</th>
                                            <th>username</th>
                                            
                                            <th>Phone Number</th>
                                            <th>Location</th>
                                            <th>Join on</th>
                                            <th>Stage</th>
                                        </tr>
                                    </thead>
                                   
                                    <tbody>';
$i=1;
			$sql=$db->query("select * FROM user WHERE sponsor = '$randomKey' " )or die(mysqli_error());
			while($row = mysqli_fetch_assoc($sql)){ $e=$i++;
				$mark = ($this->wildSponsored($row['sn'])<2) ? '*' : '';
				$table .= ' <tr>
                                            <td>'.$e.'</td>
                                            <td>'.$row['firstname'].' '.$row['lastname'].'</td>
                                            <td>'.$row['user'].'</td>
                                            
                                            <td>'.$row['phone'].'</td>
                                            <td>'.$row['city'].', '.$row['state'].'</td>
                                             <td>'.date('d M, Y',strtotime($row['created'])).'</td>
                                               <td>'.$mark.$this->wildLevel2($row['sn'],7).'</td>
                                        </tr>';
			}

			$table .= ' </tbody>
                                </table>';	
			return $table;	
			}




///waiting List

				function waitingList($no=3){
				global $db,$key;
				$randomKey = $this->userName('sn');
				$key='';
			$a = 1; $x = 1; $c=0; $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; 
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' AND active < 2 " )or die(mysqli_error());
			while($row = mysqli_fetch_assoc($qu) AND $c<$no){
				$c = $x++;
				$key .= '<tr><td><a href="javascript:void(0);" class="text-link">'.$row['firstname'].'</a></td>
                                            <td>'.$row['sn'].'</td></tr>';
                                        
				
			}	
			}
			return $key;	
			}



	function waitingList2($no=20){
				global $db,$key;
				$randomKey = $this->userName('sn');
				$table = '<table id="example23" class="display nowrap" cellspacing="0" width="100%">
                                    <thead>
                                        <tr>
                                            <th>SN</th>
                                             <th>Full Name</th>
                                            <th>username</th>
                                            
                                            <th>Phone Number</th>
                                            <th>Location</th>
                                            <th>Join on</th>
                                            
                                        </tr>
                                    </thead>
                                   
                                    <tbody>';
			$a = 1; $x = 1; $c=0; $nu = 0;
			while($a<=10){$b = $a++; $gen = 'a'.$b; 
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' AND active < 2 " )or die(mysqli_error());
			while($row = mysqli_fetch_assoc($qu) AND $c<$no){
				$c = $x++;
				$table .= ' <tr>
                                            <td>'.$c.'</td>
                                            <td>'.$row['firstname'].' '.$row['lastname'].'</td>
                                            <td>'.$row['user'].'</td>
                                            
                                            <td>'.$row['phone'].'</td>
                                            <td>'.$row['city'].', '.$row['state'].'</td>
                                             <td>'.date('d M, Y',strtotime($row['created'])).'</td>
                                        </tr>';
                                        
				
			}	
			}

			$table .= ' </tbody>
                                </table>';	
			return $table;	
			}



function sendMessage(){
	global $userKey, $report;
$message=addslashes($_POST['message']);
$subject=addslashes($_POST['subject']);

$this->message('Admin',$userKey,$message,$subject);
$report='Your message was successfully sent';
return;	
}



function message($id,$sender,$msg,$subject){
global $db;
$ctime = CTIME;
$msg = $db->query("INSERT INTO msg (rec,sender,subject,msg,ctime)
VALUES('$id','$sender','$subject','$msg','$ctime')") or die(mysqli_error());

	return;
}

//administrator messages
function adminMsg($nu=''){
global $db,$userKey;
$msg = '';
$bl = ['info','warning','primary','danger','success'];
$a = 0;
$sql=$db->query("SELECT * FROM msg WHERE rec = '$userKey' OR  sender = '$userKey' ORDER BY sn DESC " )or die(mysqli_error());
			$num = mysqli_num_rows($sql);
			while($row = mysqli_fetch_assoc($sql)){
				$b=$a++;
				$c = $b%5; 
				if($row['rec']==$userKey){$bb='bl';  $bg='';}else{$bb='br'; $bg='style="background-color:#FFFFCA"';}
$msg .= ' <li class="list-group-item '.$bb.'-'.$bl[$c].'" id="'.$row['subject'].'" '.$bg.'>
                                            
                                                    <span class="font-16"><strong>'.$row['subject'].'</strong><br>'.$row['msg'].'</span>
                                               
                                                <h6 class="">'.date('d-M-y h:i A',$row['ctime']).'</h6>
                                            
                                        </li>';
			}
			if($nu==1){$sql=$db->query("SELECT * FROM msg WHERE rec = '$userKey' " )or die(mysqli_error());
			$num = mysqli_num_rows($sql); $msg=$num;}
	return $msg;
}



//administrator messages on top nav
function adminMsg2($nu=''){
global $db,$userKey;
$msg = '';
$bl = ['info','warning','primary','danger','success'];
$a = 0;
$sql=$db->query("SELECT * FROM msg WHERE rec = '$userKey' AND active > 0  ORDER BY sn DESC" )or die(mysqli_error());
			$num = mysqli_num_rows($sql);
			while($row = mysqli_fetch_assoc($sql)){
				$b=$a++;
				$c = $b%5; 
$msg .= '<a href="messages.php#'.$row['subject'].'">
                                        
                                        <div class="mail-contnet">
                                            <h5>'.$row['subject'].'</h5>
                                            <span class="mail-desc">'.$row['msg'].'</span>
                                            <span class="time">'.date('d-M h:i A',$row['ctime']).'</span>
                                        </div>
                                    </a>';
			}
			if($nu==1){$msg=$num;}
	return $msg;
}



function stgTost($stg){
	if($stg==1){$s = 'Feeder';}
	elseif($stg==2){$s = 'Induct';}
	elseif($stg==3){$s = 'Stage 1';}
	elseif($stg==4){$s = 'Stage 2';}
	elseif($stg==5){$s = 'Stage 3';}
	elseif($stg==6){$s = 'Stage 4';}
	elseif($stg==7){$s = 'Stage 5';}
return $s; 
}

function resetChart(){
unset($_SESSION['stg']);
header('location: ?');
	return;
}

//Geneology Tree
function gTree(){
global $db,$key,$report,$count,$user,$randomKey;
if(isset($_GET['u-ref'])){ $random = $_GET['u-ref'];
$sql=$db->query("SELECT * FROM user WHERE sha1(sn) = '$random' " )or die(mysqli_error());
$ro = mysqli_fetch_assoc($sql);
$keys = $ro['sn'];
}
//$level = $this->wildLevel2($randomKey,2);


				$randomKey = isset($_GET['u-ref']) ? $keys : $this->userName('sn');
				$user=$randomKey;
				//$randomKey = $this->userName('sn');
				 if(isset($_POST['stg'])){$_SESSION['stg'] = $_POST['stg']; }elseif(isset($_SESSION['stg'])){} else{$_SESSION['stg'] = $this->wildLevel2($randomKey,2);}
				$mystage = $_SESSION['stg'];
				if($mystage==1){$show = 1;}elseif($mystage==2){$show = 2;}else{$show = 3;}

				if($mystage>$this->wildLevel2($randomKey,2)){$report = '<b>Sorry! '.$this->userNameWild().' is not yet in this stage: '.$this->stgTost($mystage).'</b>'; $count = 1; return '';}else{

				if($mystage==1){$show = 1;}elseif($mystage==2){$show = 2;}else{$show = 3;}
				$sstag = $this->wildLevel2(1);
				

				$code='chart_config = [
        config, a'.$randomKey.', ';

				$tree='var config = {
        container: "#basic-example",
        
        connectors: {
            type: "step"
        },
        node: {
            HTMLclass: "nodeExample1"
        }
    },';
				$tree.='a'.$randomKey.' = {
        text: {
            name: "'.substr($this->userNameWild(),0,7).'",
            title: "",
            contact: "",
        },
        link: {
            href: ""
        },
        image: "../headshots/'.$this->image2($mystage).'"
    },';  
//contact: "'.$this->Level(7).'",
			$a = 1; $x = 1; $c=0; $nu = 0;
			while($a<=$show){$b = $a++; $gen = 'a'.$b; 
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			while($row = mysqli_fetch_assoc($qu)){
			$user = $row['sn'];
			$stage = $this->wildLevel2($row['sn'],2);
			//Indicate waiting user with < 2 sponsored
			if($stage>=$mystage AND $this->Sponsored() >= MATRIX AND $this->wildSponsored($row['sn']) >= MATRIX){
			if($this->wildSponsored($row['a1'])<2){$s = $row['a2'];}
			elseif($this->wildSponsored($row['a2'])<2){$s = $row['a3'];}
			elseif($this->wildSponsored($row['a3'])<2){$s = $row['a4'];}
			elseif($this->wildSponsored($row['a4'])<2){$s = $row['a5'];}

			$code .= 'a'.$row['sn'].', ' ;
				$tree .= 'a'.$row['sn'].' = {
        parent: a'.$row['a1'].',
        text:{
            name: "'.substr($row['user'],0,7).'",
            title: "",
            contact: "",
        },
        link: {
            href: "?u-ref='.sha1($row['sn']).'"
        },
    
        image: "../headshots/'.$this->image2($mystage).'"
    }, ';
    //contact: "'.$this->wildLevel2($row['sn'],7).'",
				}
			}	
			}
			$code .='];';

			//$report = 'Showing your '.$this->stgTost($mystage).' geneology ';
			//$count = 0;
			return $tree.$code; }
			}


function image($key){
$level = $this->wildLevel2($key,2);
	//if($this->wildSponsored($key)<2){ $wait = 'waiting.jpg' ;}
			if($level==1){ $wait = 'feeder.png' ;}
			elseif($level==2){ $wait = 'induction.png' ;}
			elseif($level==3){ $wait = 'stage1.png' ;}
			elseif($level==4){ $wait = 'stage2.png' ;}
			elseif($level==5){ $wait = 'stage3.png' ;}
			elseif($level==6){ $wait = 'stage4.png' ;}
			elseif($level==7){ $wait = 'stage5.png' ;}
			//elseif($level<1){ $wait = 'user4.jpg' ;}
			else{ $wait = 'stage5.png' ;}
			return $wait;
}

function image2($level){

			if($level==1){ $wait = 'feeder.png' ;}
			elseif($level==2){ $wait = 'induction.png' ;}
			elseif($level==3){ $wait = 'stage1.png' ;}
			elseif($level==4){ $wait = 'stage2.png' ;}
			elseif($level==5){ $wait = 'stage3.png' ;}
			elseif($level==6){ $wait = 'stage4.png' ;}
			elseif($level==7){ $wait = 'stage5.png' ;}
			//elseif($level<1){ $wait = 'user4.jpg' ;}
			else{ $wait = 'stage5.png' ;}
			return $wait;
}

//Geneology Tree
function gTreeAll(){
global $db,$key,$user;
$show = 3;
if(isset($_GET['u-ref'])){ $random = $_GET['u-ref'];
$sql=$db->query("SELECT * FROM user WHERE sha1(sn) = '$random' " )or die(mysqli_error());
$ro = mysqli_fetch_assoc($sql);
$key = $ro['sn'];
}
				$randomKey = isset($_GET['u-ref']) ? $key : $this->userName('sn');
				$mystage = $this->wildLevel2($randomKey,2);
				$sstag = $this->Level(1);
				$user = $randomKey;

				$code='chart_config = [
        config, a'.$randomKey.', ';

				$tree='var config = {
        container: "#basic-example",
        
        connectors: {
            type: "step"
        },
        node: {
            HTMLclass: "nodeExample1"
        }
    },';
				$tree.='a'.$randomKey.' = {
        text: {
            name: "'.substr($this->userNameWild(),0,7).'",
            title: "",
            contact: "'.$this->wildLevel2($randomKey,7).'",
        },
        link: {
            href: ""
        },
        image: "../headshots/users.png"
    },';  
//   contact: "'.$this->wildLevel2($randomKey,7).'",
			$a = 1; $x = 1; $c=0; $nu = 0;
			while($a<=$show){$b = $a++; $gen = 'a'.$b; 
			$qu=$db->query("SELECT * FROM user WHERE $gen = '$randomKey' " )or die(mysqli_error());
			while($row = mysqli_fetch_assoc($qu)){
			$user = $row['sn'];
			
			$wait = ($this->wildSponsored($row['sn'])<2) ? 'userw.png' : 'user.png';//Indicate waiting user with < 2 sponsored
			
			$code .= 'a'.$row['sn'].', ' ;
				$tree .= 'a'.$row['sn'].' = {
        parent: a'.$row['a1'].',
        text:{
            name: "'.substr($row['user'],0,7).'",
            title: "",
            contact: "'.$this->wildLevel2($row['sn'],7).'",
        },
        link: {
            href: "?u-ref='.sha1($row['sn']).'"
        },
    
        image: "../headshots/users.png"
    }, ';
				}
			}	
			//contact: "'.$this->wildLevel2($row['sn'],7).'",
			$code .='];';
			
			return $tree.$code;
			}





function stageEarning($opt=''){
$stage = 2**$this->Level();
$total = 0;
$a=1;
while($a<=$this->Level()){$b=$a++;
$total += 2**$b;
}
if($opt==1){return 1.5*$total;}else{return 1.5*$stage;}
}
	//user Rank		
			
	function Rank($user){
			if($this->Downlines()<3){$rank = 0;}elseif($this->Downlines()<12){$rank = 1;}elseif($this->Downlines()<39){$rank = 2;}elseif($this->Downlines()<120){$rank = 3;}elseif($this->Downlines()<363){$rank = 4;}elseif($this->Downlines()<1092){$rank = 5;}elseif($this->Downlines()<3279){$rank = 6;}elseif($this->Downlines()<9840){$rank = 7;}elseif($this->Downlines()<29523){$rank = 8;}elseif($this->Downlines()<88572){$rank = 9;}else{$rank = 10;}
	return $rank;
	}
	
	//Bonus Types
	function matrixB(){
		global $id;
	return $this->Downlines()*$this->percent()/$this->dola;	
	}
	
	function referalB(){
	global $id;
		return $this->Sponsored()*2;	
	}
	
		function pointB(){
	global $id;
		return $this->Point()*$this->percent(1)/$this->dola;	
	}
	
	function percent($p=5){
	return	$this->amount*$p/100;
	}

	//Withdrawal Methods

function totalEarning(){
	return $this->referalB()+$this->matrixB();
}

function confirmedWithdraw(){
	global $db,$userKey,$key;
	$key = md5($userKey);
	$status = STATUSALPHA;
	
	$sql = $db->query("SELECT amount FROM withdraw WHERE id2 = '$key' AND status = '$status' ");
	$amt = 0;
	while($row = mysqli_fetch_assoc($sql)){
		$amt += $row['amount'];
	}
	return $amt; 
}





function userWithdraw(){
	
	return $this->confirmedWithdraw()+$this->pendingWithdraw(); 
}


function pendingWithdraw(){
global $db,$userKey;
	$key = md5($userKey);
	$status = STATUSBETA;
	
	$sql = $db->query("SELECT amount FROM withdraw WHERE id2 = '$key' AND status = '$status' ");
	$amt = 0;
	while($row = mysqli_fetch_assoc($sql)){
		$amt += $row['amount'];
	}
	return $amt; 
}

function accountBalance(){
	return $this->totalEarning()-$this->confirmedWithdraw()-$this->pendingWithdraw();
}


	function possibleEpin(){
		return (int)($this->accountBalance()/$this->dolafee);
	}


//Withdrawal Order
	function buyEpins(){
		global $epinqty,$paytype;
	$epinqty = $_POST['epinqty'];
	$withdrawAmount = $epinqty*$this->dolafee;
	$currentpass = md5($_POST['currentpass']);
	$paytype = 'E-PIN Purchase';
	$payby=$_SESSION['payby'];
if($payby==2){ $type = 'E-PIN Purchase from Bonus Wallet'; }elseif($payby==3){ $type = 'E-PIN Purchase from Investment Wallet'; }
	$status = STATUSALPHA;
	$this->withdrawProcess($withdrawAmount,$currentpass,$type,$status);
return;
}


	function withdrawOrder(){
		$withdrawAmount = $_POST['withdrawAmount'];
		$currentpass = md5($_POST['currentpass']);
		$withdrawAmount = $withdrawAmount + ($withdrawAmount*0.02);
		
		$payby=$_SESSION['payby'];
if($payby==2){ $type = 'Bonus Cash Withdrawal'; }elseif($payby==3){ $type = 'Investment Cash Withdrawal'; }

		$status = STATUSBETA;
$this->withdrawProcess($withdrawAmount,$currentpass,$type,$status);
return;
}


	function investFromWallet(){
		$withdrawAmount = $_POST['withdrawAmount'];
		$currentpass = md5($_POST['currentpass']);
		$type = 'Bonus Cash Withdrawal';
		$status = STATUSBETA;
$this->withdrawProcess($withdrawAmount,$currentpass,$type,$status);
return;
}





			function withdrawProcess($withdrawAmount,$currentpass,$type,$status){
		global $db, $userKey, $report, $count,$dd, $ww, $epinqty,$inv,$paytype;
	
		
		$key = md5($userKey);

		$accountBalance = $this->accountBalance();
		$tno = substr(str_shuffle(str_repeat('1234567890',16)),0,16);
		$id = rand(1010,9898);

		if($paytype=='E-PIN Purchase'){$this->minwithdraw=25;}

		if($_SESSION['payby']==3){
			$key = $userKey;
			$accountBalance = $this->invTotalInt();
		}
			$finalbalance = $accountBalance-$withdrawAmount;
		
		if($withdrawAmount<=$accountBalance && $withdrawAmount>=$this->minwithdraw){
			if($this->userName('pass')==$currentpass){
$sql = $db->query("INSERT INTO withdraw (id,id2,inibalance,amount,finalbalance,status,type,ww,ymd,tno) VALUES ('$id','$key','$accountBalance','$withdrawAmount','$finalbalance','$status','$type','$ww','$dd','$tno')");

if($sql){ $this->logdraw($tno);
 
if($paytype=='E-PIN Purchase'){
	$this->sellEpins();
	$report = 'Your have successfully purchased '.$epinqty.' E-PINs for $'.$withdrawAmount;
}else{$report = 'Your have successfully palced withdrawal order for $'.$withdrawAmount;
}
  }
			
}else{


$report = 'Password confirmation failed, please try again'; $count = 1;
			}

		}else{
			$report = 'You have entered an invalid amount. You can place a Withdrawal order for any amount greater than $'.$this->minwithdraw.' and less than or equal to $'.(int)$this->accountBalance(); $count=1;
		}

return;
	}





function logdraw($tno){
	global $db;
$sql = $db->query("INSERT INTO logdraw SELECT * FROM withdraw WHERE tno = '$tno' ");
return;
}



function invTotalInt(){
	global $db,$userKey ;
	$status = STATUSALPHA;
	$amt=0;
	$sql = $db->query("SELECT * FROM invacc WHERE userid='$userKey' AND status='$status' ");
 while($row = mysqli_fetch_assoc($sql)){

$age = $this->accAge($row['accno'],1);
$interest = $age*$row['roi'];

 	$amt = $amt+$interest;
 }
	return $amt;
}


//from investment//
function accAge($accountno,$type=''){
	global $db,$userKey;
 $sql = $db->query("SELECT * FROM invacc WHERE accno='$accountno' ");
 $row = mysqli_fetch_assoc($sql);
 if($row['tan']>0){
 	$diff = CTIME-$row['tan'];
 $age = $diff/(86400);
$weeks = (int)($age/7);
if($age<=280){$percent = number_format((100*$age/280),1).'%';}

 if($type==1){return $weeks; }elseif($diff<3600){}elseif($diff>3600 && $age<1){ return (int)($diff/3600).' hours';} elseif($age<7){return (int)$age.' days<br>'.$percent;}elseif($age>7){return (int)($age/7).' weeks<br>'.$percent;} 
 //elseif($age>=30){return (int)($age/30).' months<br>'.$percent;}
 

 else{return; }
}


}


function approveWithdrawOrder(){
	global $db,$report,$count;
	$tno = $_POST['approveWithdrawOrder'];
	$currentpass = md5($_POST['currentpass']);

	$status = STATUSALPHA; 
if($this->userName('pass')==$currentpass){
$sql = $db->query("UPDATE logdraw SET status = '$status' WHERE tno = '$tno' ");
$sql = $db->query("UPDATE withdraw SET status = '$status' WHERE tno = '$tno' ");
if($sql){
	$report = 'Withdrawal order successfully approved';
}else{$report = 'Withdrawal approved not successful'; $count=1; }
}
else{
$report = 'Password confirmation failed, please try again'; $count = 1;	
}

return;
}


function adminLevel(){

	if($this->userName('userlevel')==(strlen($this->userName('email'))*2)){
		return TRUE;
	}else{return FALSE;}
}
	



function wildUserName($key,$col=''){
				global $db;
				
			$que=$db->query("select * FROM user WHERE sn = '$key' " )or die(mysqli_error());
					$ro=mysqli_fetch_array($que);	
				if(!empty($col)){return $ro[$col];}
				else{return htmlspecialchars($ro['firstname'].' '.$ro['lastname']);}
}



function userProfileData($a){
	global $db;
	$id = $_SESSION['user_id'];
	$sql=$db->query("SELECT * FROM user WHERE id = '$id' " )or die(mysqli_error()); 
$row=mysqli_fetch_assoc($sql);

$data = '                        <div class="col-md-4 col-xs-12">
                        <div class="white-box">
                            <div class="user-bg"> <img width="100%" alt="user" src="photo/'.$row['photo'].'">
                                <div class="overlay-box">
                                    <div class="user-content">
                                        <a href="javascript:void(0)"><img src="photo/'.$row['photo'].'" class="thumb-lg img-circle" alt="img"></a>
                                        <h4 class="text-white">'.$row['firstname'].' '.$row['lastname'].'</h4>
                                        <h5 class="text-white">'.$row['email'].'</h5> </div>
                                </div>
                            </div>

                             <hr>
                               
                                <!-- .row -->
                                <div class="row text-center m-t-10">
                                    <div class="col-md-6 col-xs-6 b-r"><strong>Sponsor</strong>
                                        <p>'.$this->wildUserName($row['sponsor']).'</p>
                                    </div>
                                    <div class="col-md-6 col-xs-6"><strong>Upline</strong>
                                        <p>'.$this->wildUserName($row['a1']).'</p>
                                    </div>
                                </div>
                                <!-- /.row -->

                            

                            
                        </div>
                    </div>';



               



                    $data2 = '<div class="col-md-8 col-xs-12">
                        <div class="white-box">
                            <!-- .tabs -->
                            <ul class="nav nav-tabs tabs customtab">
                                
                                <li class="active tab">
                                    <a href="#profile" data-toggle="tab"> <span class="visible-xs"><i class="fa fa-user"></i></span> <span class="hidden-xs">Profile</span> </a>
                                </li>
                                <li class="tab">
                                    <a href="#settings" data-toggle="tab" aria-expanded="false"> <span class="visible-xs"><i class="fa fa-cog"></i></span> <span class="hidden-xs">Edit Profile</span> </a>
                                </li>
                            </ul>
                            <!-- /.tabs -->
                            <div class="tab-content">
                               
                                <!-- .tabs2 -->
                                <div class="tab-pane active" id="profile">
                                    
                                    <h6 class="m-t-30">Profile Information</h6>
                                   <hr>
                                 
                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Phone Number</div>
                                    <div class="col-md-7 col-xs-12">'.$row['phone'].'</div>
                                    </div>
                                    <hr>
                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Gender</div>
                                    <div class="col-md-7 col-xs-12">'.$row['sex'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Birthday</div>
                                    <div class="col-md-7 col-xs-12">'.$row['dob'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Residential Address</div>
                                    <div class="col-md-7 col-xs-12">'.$row['address'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">City/State</div>
                                    <div class="col-md-7 col-xs-12">'.$row['city'].', '.$row['state'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Office Address</div>
                                    <div class="col-md-7 col-xs-12">'.$row['officeaddress'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-12 col-xs-12"><h6 class="m-t-30">Bank Account Details</h6></div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Bank Name</div>
                                    <div class="col-md-7 col-xs-12">'.$row['bank'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Account Nunmber</div>
                                    <div class="col-md-7 col-xs-12">'.$row['accountno'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Account Name</div>
                                    <div class="col-md-7 col-xs-12">'.$row['accname'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-12 col-xs-12"><h6 class="m-t-30">Referral Information</h6></div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Referral ID</div>
                                    <div class="col-md-7 col-xs-12">'.$row['user'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Referral Link</div>
                                    <div class="col-md-7 col-xs-12">https://smilewecareng.com/?ref='.$row['user'].'</div>
                                    </div>
                                    <hr>

                                    <div class="row">
                                    <div class="col-md-5 col-xs-12 font-12">Share on WhatsApp<br><br></div>
                                    <div class="col-md-7 col-xs-12"><a href="whatsapp://send?text=It\'s all about financial empowerment. We can make you smile because we care. Join us now at @    
https://smilewecareng.com/?ref='.$row['user'].'" data-action="share/whatsapp/share" class="btn btn-success">Share on WhatsApp</a></div>
                                    </div>
                                    <hr>

                                </div>
                                <!-- /.tabs2 -->
                                <!-- .tabs3 -->
                                <div class="tab-pane" id="settings">
                                    <form method="post" class="form-horizontal">
                                        <h5 class="m-t-30">Password Reset</h5>
                                    <hr>
                                        <div class="form-group">
                                            <label class="col-md-12">Old Password</label>
                                            <div class="col-md-12">
                                                <input type="password" placeholder="" name="currentpass" class="form-control"> </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="example-email" class="col-md-12">New Password</label>
                                            <div class="col-md-12">
                                                <input type="password" placeholder="" class="form-control" name="newpass" id="example-email"> </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-12">Confirm Password</label>
                                            <div class="col-md-12">
                                                <input type="password" name="newpass2" class="form-control"> </div>
                                        </div>
                                         <div class="form-group">
                                            <div class="col-sm-12">
                                                <button type="submit" name="changePassword" class="btn btn-success">Reset Password</button>
                                            </div>
                                        </div>

                                       
                                    </form>

                                     <h5 class="m-t-30">Update Profile Passport Photograph</h5>
                                    <hr>
                                    <form method="post"  enctype="multipart/form-data">
                                    <div class="row">
                    <div class="col-sm-6 ol-md-6 col-xs-12">
                      
                          
                            <label for="input-file-max-fs">Maximum Size is 200kb</label>
                            <input type="file" name="image" id="input-file-max-fs" class="dropify" data-max-file-size="200K" required /> </div>
                    </div>
                
                 <div class="form-group">
                                            <div class="col-sm-12">
                                                <button class="btn btn-success" name="updatePhoto">Update Photograph</button>
                                            </div>
                                        </div>


                                </div>
                                </form>
                                <!-- /.tabs3 -->
                            </div>
                        </div>
                    </div>';
	return $$a;
}



function  createPin(){
	global $report,$db,$signup,$userKey;

$num=$_POST['no-of-pin'];
for ($a = 1; $a<=$num; $a++){ 
$pin = strtoupper($signup->win_hash(10));
	$sql = $db->query("INSERT INTO pin(pin,rep) VALUES('$pin','$userKey') ");
}
$report = $num.' PINs successfully generated';
return;
}

	
}

$profile = new Profile; 

//end of Bonus Class





































?>

?>