Your IP : 18.119.142.113
<?php
if(isset($_SESSION['user_id'])){
$userKey = $_SESSION['user_id'];
}
function age($ctime){
$age = (time()-$ctime)/(60*60*24*30);
return (int)$age;
}
function nextBoard($uid){
$i = 1;
while($i<=10){ $e=$i++; if(sqL2('cuser','id',$uid,'type',$e)==0){return $e; } }
}
function eligible($uid,$n){
$level = userName($uid,'level');
$level += 1;
return ($level>=$n) ? 'YES' : 'NO';
}
function efee($n){
if($n==1){$fee = 2;}
elseif($n==2){$fee = 5;}
elseif($n==3){$fee = 10;}
elseif($n==4){$fee = 20;}
elseif($n==5){$fee = 50;}
elseif($n==6){$fee = 100;}
elseif($n==7){$fee = 200;}
elseif($n==8){$fee = 500;}
elseif($n==9){$fee = 1000;}
return $fee;
}
function covcoin($id){
global $db;
$sql = $db->query("SELECT * FROM cuser WHERE id='$id' ORDER BY type DESC LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$n = $row['type'];
$fee=0;
if($n>=1){$fee += 2;}
if($n>=2){$fee += 5;}
if($n>=3){$fee += 10;}
if($n>=4){$fee += 20;}
if($n>=5){$fee += 50;}
if($n>=6){$fee += 100;}
if($n>=7){$fee += 200;}
if($n>=8){$fee += 500;}
if($n>=9){$fee += 1000;}
return $fee;
}
function sfee($n){
if($n==1){$fee = 0.5;}
elseif($n==2){$fee = 1;}
elseif($n==3){$fee = 2;}
elseif($n==4){$fee = 2;}
elseif($n==5){$fee = 3;}
elseif($n==6){$fee = 3;}
elseif($n==7){$fee = 4;}
elseif($n==8){$fee = 4;}
elseif($n==9){$fee = 5;}
return $fee;
}
function cpayRemark($n){
if($n==1){$fee = 'Received from CCI Wallet';}
elseif($n==2){$fee = 'Cycle Bonus';}
elseif($n==3){$fee = 'Referral Bonus';}
elseif($n==4){$fee = 'Withdrawal to CCI Wallet';}
elseif($n==5){$fee = 'Board Entry Fee';}
elseif($n==6){$fee = 'Service Charge';}
else{$fee = '';}
return $fee;
}
function nextMile($point){
global $db;
$sql = $db->query("SELECT * FROM logc WHERE refpoint>'$point' ORDER BY refpoint ASC LIMIT 1");
if(mysqli_num_rows($sql)==1){
$row = mysqli_fetch_assoc($sql);
return $row['refpoint']-$point;
}else{return 0; }
}
function eligibleWin($point,$peg){
return $point>=$peg ? 1 : 0;
}
function cycleProgress($uid,$type){
global $db;
$sql = $db->query("SELECT * FROM cuser WHERE id='$uid' AND type='$type' ORDER BY sn DESC LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$idx = $row['sn'];
if(mysqli_num_rows($sql)==0){return 0;}
$s = $db->query("SELECT * FROM cuser WHERE a1='$idx' OR a2='$idx' ");
$no = mysqli_num_rows($s);
return 100*$no/6;
}
function refPoint($uid){
global $db;
$p=0;
$sql = $db->query("SELECT * FROM logc WHERE sponsor='$uid' ");
while($row = mysqli_fetch_assoc($sql)){
$idx = $row['id'];
$p += colSum2('cpay','amount','id',$idx,'type',5);
}
return abs($p);
}
function colSumVx($table,$col,$cola,$vala,$colb,$valb){
global $db;
$mm = date('Y-m');
$sql=$db->query("SELECT SUM($col) AS value_sum FROM $table WHERE $cola = '$vala' AND $colb = '$valb' AND created LIKE '%$mm%' ");
$row = mysqli_fetch_assoc($sql);
return $row['value_sum'];
}
function refPointThisMonth($uid){
global $db;
$p=0;
$sql = $db->query("SELECT * FROM logc WHERE sponsor='$uid' ");
while($row = mysqli_fetch_assoc($sql)){
$idx = $row['id'];
$p += abs(colSumVx('cpay','amount','id',$idx,'type',5));
}
$db->query("UPDATE logc SET refpoint='$p' WHERE id='$uid' ");
return;
}
function updatePoint(){
global $db;
$sql = $db->query("SELECT * FROM logc ");
while($row = mysqli_fetch_assoc($sql)){
$idx = $row['id'];
refPointThisMonth($idx);
}
return;
}
class Profile
{
var $amount = 2000; //Registration Fee
var $dola = 400; // Dollar conversion to Naira
var $onePayRate = 400; // Dollar conversion to Naira
var $dolafee = 5; //Registration fee in dolla
var $minwithdraw = 10;
var $maxwithdraw = 2000;
var $withdrawcharge = 0;//0.5;
var $charge = 2.5;
//var $regfee = 10;
//User Array Keys
/* Class constructor */
function __construct()
{
global $report, $count;
if (array_key_exists('InitialSignup', $_POST)) {
$this->signupUserIni();
} elseif (array_key_exists('VerifySponsor', $_POST)) {
$this->VerifySponsor();
} elseif (array_key_exists('payWithPin', $_POST)) {
$this->payWithPin();
}
elseif (array_key_exists('RegisterWithPin', $_POST)) {
$this->RegisterWithPin();
}elseif (array_key_exists('CardApprove', $_POST)) {
$this->CardApprove();
}
elseif (array_key_exists('ProceedToLogin', $_POST)) {
session_destroy();
header("location:login.php");
} elseif (array_key_exists('LoginUsers', $_POST)) {
$this->LoginUsers();
} elseif (array_key_exists('LogoutUser', $_POST)) {
$this->LogoutUser();
} elseif (array_key_exists('changeSponsor', $_POST)) {
$_SESSION['signup'] = NULL;
} elseif (array_key_exists('changeLogin', $_POST)) {
$_SESSION['signup'] = 2;
} elseif (array_key_exists('regContinue', $_POST)) {
$_SESSION['signup'] = 5;
$head = $this->win_hash(85);
header("location: ?user_ref=$head");
} elseif (array_key_exists('searchU', $_POST)) {
$this->searchU();
}
elseif (array_key_exists('SearchUserMessage', $_POST)) {
$this->SearchUserMessage();
} elseif (array_key_exists('signupUser', $_POST)) {
$this->signupUser();
} elseif (array_key_exists('resetPass', $_POST)) {
$this->resetPass();
} elseif (array_key_exists('updateSignup', $_POST)) {
$this->updateSignup();
} elseif (array_key_exists('resetPassConfirm', $_POST)) {
$this->resetPassConfirm();
} elseif (array_key_exists('signupUserIni', $_POST)) {
$this->signupUserIni();
} elseif (isset($_GET['tr_reference'])) {
$this->confirmPayment();
} elseif (isset($_GET['ref'])) {
$this->refLink();
} elseif (isset($_GET['reff'])) {
$this->findSponsorx();
} elseif (isset($_GET['form'])) {
if ($_GET['form'] == 'reset') {
session_destroy();
header('location: signup.php');
}
} elseif (array_key_exists('changePassword', $_POST)) {
$this->changePassword();
}elseif (array_key_exists('UpdateReward', $_POST)) {
$this->UpdateReward($_POST['UpdateReward']);
} elseif (array_key_exists('changePassword2', $_POST)) {
$this->changePassword2();
} elseif (array_key_exists('UpdateUser', $_POST)) {
$this->UpdateUser();
} elseif (array_key_exists('UpdateUser2', $_POST)) {
$this->UpdateUser2();
} elseif (array_key_exists('updatePhoto', $_POST)) {
$this->updatePhoto();
} elseif (array_key_exists('updatePhoto2', $_POST)) {
$this->updatePhoto2();
} elseif (array_key_exists('EditProfile', $_POST)) {
$this->EditProfile();
} elseif (array_key_exists('UploadPicture', $_POST)) {
$this->UploadPicture();
}elseif (array_key_exists('EditProfileAdmin', $_POST)) {
$this->EditProfileAdmin();
} elseif (array_key_exists('UpgradeForex', $_POST)) {
$this->UpgradeForex();
}
elseif (array_key_exists('Uprofile', $_POST)) {$_SESSION['uidd'] = $_POST['Uprofile']; header("Location:searchuser.php?u-ref=");}
elseif (array_key_exists('ViewGeneology', $_POST)) {$_SESSION['uiddx'] = $_POST['ViewGeneology']; header("Location:admingen.php");}
elseif (array_key_exists('ChangeUserPassword', $_POST)) {
$this->ChangeUserPassword();
} elseif (array_key_exists('MessageSubmit', $_POST)) {
$this->MessageSubmit();
} elseif (array_key_exists('MessageAdminSubmit', $_POST)) {
$this->MessageAdminSubmit();
} elseif (array_key_exists('ReplyMessage', $_POST)) {
$this->ReplyMessage($_POST['receiver'], $_POST['ReplyMessage']);
} elseif (array_key_exists('DeleteMessage', $_POST)) {
$this->DeleteMessage($_POST['DeleteMessage']);
} elseif (array_key_exists('DeleteDonation', $_POST)) {
$this->DeleteDonation();
} elseif (array_key_exists('UploadMaterial', $_POST)) {
$this->UploadMaterial();
}elseif (array_key_exists('UpdateMaterial2', $_POST)) {
$this->UpdateMaterial2();
}
elseif (array_key_exists('UpdateMaterial', $_POST)) {
$this->UpdateMaterial();
}
elseif (array_key_exists('UploadNewsImage', $_POST)) {
$this->UploadNewsImage();
}
elseif (array_key_exists('UpdateNews', $_POST)) {
$this->UpdateNews();
}
elseif (array_key_exists('RequestWithdraw', $_POST)) { $this->RequestWithdraw();}
elseif (array_key_exists('applyTraining', $_POST)) { $this->applyTraining();}
elseif (array_key_exists('LockFunds', $_POST)) { $this->LockFunds();}
elseif (array_key_exists('SavingsDeposit', $_POST)) { $this->SavingsDeposit();}
elseif (array_key_exists('WithdrawMySavings', $_POST)) { $this->WithdrawMySavings();}
elseif (array_key_exists('LoanApplication', $_POST)) { $this->LoanApplication();}
elseif (array_key_exists('CardApplication', $_POST)) { $this->CardApplication();}
elseif (array_key_exists('GmRequestWithdraw', $_POST)) { $this->GmRequestWithdraw();}
elseif (array_key_exists('GmRequestTransfer', $_POST)) { $this->GmRequestTransfer();}
elseif (array_key_exists('RequestTransfer', $_POST)) { $this->RequestTransfer();}
elseif (array_key_exists('TransferToCovisEconomy', $_POST)) { $this->TransferToCovisEconomy();}
elseif (array_key_exists('CreditWallet', $_POST)) { $this->CreditWallet();}
elseif (array_key_exists('DeductWallet', $_POST)) { $this->DeductWallet();}
elseif (array_key_exists('GmRequestTransferToCci', $_POST)) { $this->GmRequestTransferToCci();}
elseif (array_key_exists('ForgertPassword', $_POST)) { $this->ForgertPassword();}
elseif (array_key_exists('ApproveWithdraw', $_POST)) { $this->ApproveWithdraw();}
elseif (array_key_exists('ReturnWithdraw', $_POST)) { $this->ReturnWithdraw();}
elseif (array_key_exists('RequestIncentive1', $_POST)) { $this->RequestIncentive1();}
elseif (array_key_exists('PromoIncent', $_POST)) { $this->PromoIncent();}
elseif (array_key_exists('ApproveIncentive1', $_POST)) { $this->ApproveIncentive1();}
elseif (array_key_exists('DeleteRequest', $_POST)) { $this->DeleteRequest();}
elseif (array_key_exists('UpdateTesti', $_POST)) { $this->UpdateTesti();}
elseif (array_key_exists('DeleteTesti', $_POST)) { $this->DeleteTesti();}
elseif (array_key_exists('ApproveTesti', $_POST)) { $this->ApproveTesti();}
elseif (array_key_exists('DisapproveTesti', $_POST)) { $this->DisapproveTesti();}
elseif (array_key_exists('ApproveDonation', $_POST)) { $this->ApproveDonation();}
elseif (array_key_exists('DisapproveDonation', $_POST)) { $this->DisapproveDonation();}
elseif (array_key_exists('PayDonation', $_POST)) { $this->PayDonation();}
elseif (array_key_exists('TerminateDonation', $_POST)) { $this->TerminateDonation();}
elseif (array_key_exists('SendMail', $_POST)) { $this->SendMail();}
elseif (array_key_exists('updateA16toA30All', $_POST)) { $this->updateA16toA30All();}
elseif (array_key_exists('DownloadMaterial', $_POST)) {
$this->DownloadMaterial($_POST['DownloadMaterial']);
} elseif (array_key_exists('DeleteMaterial', $_POST)) {
$this->DeleteMaterial($_POST['DeleteMaterial']);
} elseif (array_key_exists('BuyBook', $_POST)) {
$this->BuyBook();
}
elseif (array_key_exists('DeleteNews', $_POST)) {
$this->DeleteNews($_POST['DeleteNews']);
} elseif (array_key_exists('withdrawOrder', $_POST)) {
$this->withdrawOrder();
} elseif (array_key_exists('transferOrder', $_POST)) {
$this->transferOrder();
}elseif (array_key_exists('buyEpins', $_POST)) {
$this->buyEpins();
}elseif (array_key_exists('EnProfile', $_POST)) {
$this->EnProfile();
}
elseif (array_key_exists('SuspendAccount', $_POST)) {
$this->SuspendAccount();
}
elseif (array_key_exists('UnSuspendAccount', $_POST)) {
$this->UnSuspendAccount();
}
elseif (array_key_exists('GenerateUserPin', $_POST)) {
$this->GenerateUserPin();
}
elseif (array_key_exists('sendMessage', $_POST)) {
$this->sendMessage();
} elseif (array_key_exists('sendMessageToAll', $_POST)) {
$this->sendMessageToAll();
} elseif (array_key_exists('createPin', $_POST)) {
$this->createPin();
} elseif (array_key_exists('stg', $_POST)) {
$_SESSION['stg'] = $_POST['stg'];
} elseif (array_key_exists('resetChart', $_POST)) {
$this->resetChart();
} elseif (array_key_exists('showAwardee', $_POST)) {
$this->showAwardee();
}elseif (array_key_exists('CreateContribution', $_POST)) {
$this->CreateContribution();
}elseif (array_key_exists('PayContribution', $_POST)) {
$this->PayContribution();
}elseif (array_key_exists('UpdateContribution', $_POST)) {
$this->UpdateContribution();
}elseif (array_key_exists('DeleteContribution', $_POST)) {
$this->DeleteContribution();
}elseif (array_key_exists('StartContributionTime', $_POST)) {
$this->StartContributionTime();
}elseif (array_key_exists('ApproveMySavingsPlan', $_POST)) {
$this->ApproveMySavingsPlan();
}elseif (array_key_exists('JoinSavingContribution', $_POST)) {
$this->JoinSavingContribution();
}elseif (array_key_exists('DeclineMySavingsPlan', $_POST)) {
$this->DeclineMySavingsPlan();
}elseif (array_key_exists('approveAward', $_POST)) {
$this->approveAward();
} elseif (array_key_exists('approveWithdrawOrder', $_POST)) {
$this->approveWithdrawOrder();
} elseif (array_key_exists('approveIncentiveOrder', $_POST)) {
$this->approveIncentiveOrder();
} elseif (array_key_exists('SearchDownline', $_POST)) {
$this->SearchDownline();
} elseif (array_key_exists('SendUserMessage', $_POST)) {
$this->SendUserMessage();
} elseif (array_key_exists('DeactivateUser', $_POST)) {
$this->DeactivateUser();
} elseif (array_key_exists('UpdatePin', $_POST)) {
$this->UpdatePin();
} elseif (array_key_exists('CourseUpload', $_POST)) {
$this->CourseUpload();
} elseif (array_key_exists('processPin', $_POST)) {
$_SESSION['processPin'] = $_POST['processPin'];
} elseif (array_key_exists('replyMsg', $_POST)) {
$this->replyMsg();
} elseif (array_key_exists('verifyUser', $_POST)) {
$this->verifyUser();
} elseif (array_key_exists('updateAward', $_POST)) {
$this->updateAward();
} elseif (array_key_exists('requestEpins', $_POST)) {
$this->requestEpins();
} elseif (array_key_exists('approvePinRequest', $_POST)) {
$this->approvePinRequest();
} elseif (array_key_exists('deletePinRequest', $_POST)) {
$this->deletePinRequest();
}elseif (array_key_exists('RecalculateLevel', $_POST)) {
$this->RecalculateLevel();
}elseif (array_key_exists('RecalculateUser', $_POST)) {
$this->RecalculateUser();
}elseif (array_key_exists('RecalculateLevelx', $_POST)) {
$this->RecalculateLevelx();
}
elseif (array_key_exists('BookCat', $_POST)) {
$this->BookCat();
} elseif (array_key_exists('requestIncentive', $_POST)) {
$this->requestIncentive();
} elseif (array_key_exists('RestorePin', $_POST)) {
$this->RestorePin();
}
elseif (array_key_exists('UpdateUserSponsor', $_POST)) {
$this->UpdateRegister();
}elseif (array_key_exists('EnterGlobe', $_POST)) {
$this->EnterGlobe();
}elseif (array_key_exists('EnterGlobeAll', $_POST)) {
$this->EnterGlobeAll();
}
//training setup
elseif (array_key_exists('CreateTraining', $_POST)) { $this->CreateTraining(); }
elseif (array_key_exists('EditTraining', $_POST)) { $this->EditTraining(); }
elseif (array_key_exists('DeleteTraining', $_POST)) { $this->DeleteTraining(); }
elseif (array_key_exists('CreateTrainer', $_POST)) { $this->CreateTrainer(); }
elseif (array_key_exists('EditTrainer', $_POST)) { $this->EditTrainer(); }
elseif (array_key_exists('PhotoTraining', $_POST)) { $this->PhotoTraining(); }
elseif (array_key_exists('ActivateTraining', $_POST)) { $this->ActivateTraining(); }
elseif (array_key_exists('RegisterTrain', $_POST)) { $this->RegisterTrain(); }
elseif (array_key_exists('RegisterTrainVisit', $_POST)) { $this->RegisterTrainVisit(); }
elseif (array_key_exists('visitorPaid', $_POST)) { $this->visitorPaid(); }
//multiple accounts
elseif (array_key_exists('AddNewUsersAuto', $_POST)) { $this->AddNewUsersAuto($_POST['no']); }
elseif (array_key_exists('shareDisPay', $_POST)) { $this->shareDisPay(); }
elseif (array_key_exists('UpdateTarget', $_POST)) { $this->UpdateTarget(); }
elseif (array_key_exists('UpdateTarget2', $_POST)) { $this->UpdateTarget2(); }
elseif (array_key_exists('creditDistributors', $_POST)) { $this->creditDistributors(); }
//start circle
elseif (array_key_exists('startCircles', $_POST)) { $this->startCircles(); }
elseif (array_key_exists('joinCycler', $_POST)) { $this->joinCycler(); }
elseif (array_key_exists('FundCycler', $_POST)) { $this->FundCycler(); }
elseif (array_key_exists('FundFromCycler', $_POST)) { $this->FundFromCycler(); }
elseif (array_key_exists('PlaceOrder', $_POST)) { $this->PlaceOrder(); }
elseif (array_key_exists('GiveGlobeIncent', $_POST)) {
$this->GiveGlobeIncent();
}elseif (array_key_exists('GlobeWithdraw', $_POST)) {
$this->GlobeWithdraw();
}elseif (array_key_exists('LoanProcess', $_POST)) {
$this->LoanProcess();
}elseif (array_key_exists('LoanRetrieve', $_POST)) {
$this->LoanRetrieve();
}elseif (array_key_exists('LoanRepay', $_POST)) {
$this->LoanRepay();
}elseif (array_key_exists('LoanCancel', $_POST)) {
$this->LoanCancel();
}elseif (array_key_exists('JoinGmatrix', $_POST)) {
$this->JoinGmatrix();
}elseif (array_key_exists('TestimonyVideo', $_POST)) {
$this->TestimonyVideo();
}elseif (array_key_exists('TestimonyPhoto', $_POST)) {
$this->TestimonyPhoto();
}elseif (array_key_exists('DonationPhoto', $_POST)) {
$this->DonationPhoto();
}elseif (array_key_exists('EditDonationPhoto', $_POST)) {
$this->EditDonationPhoto();
} elseif (array_key_exists('FindUser', $_POST)) {
$_SESSION['FindUser'] = $_POST['FindUser']; header('location:searchuser.php');
} elseif (array_key_exists('FindTeam', $_POST)) {
$_SESSION['FindTeam'] = $_POST['FindTeam']; header('location:searchteam.php');
} elseif (isset($_GET['tr_referenca'])) {
$this->confirmPinPayment();
} elseif (isset($_GET['payment-confirmed']) AND isset($_SESSION['report'])) {
$report = $_SESSION['report'];
} elseif (isset($_GET['action'])) {
if ($_GET['action'] == 'logout') {
session_destroy();
header('location: ../');
exit;
}
}
return;
}
function mkt($id){
global $db;
$sn = userName($id,'sn');
$mm = date('ym');
$i = 1;
while($i<100){$e=$i++;
$sn = sqLx('user','sn',$sn,'a1');
if(sqLx('user','sn',$sn,'m')>0){ $db->query("INSERT INTO mkt(id,ref,mm) VALUES ('$id','$sn','$mm')"); return; }
}
return;
}
function addMkt(){
global $db;
$mm = date('Ym');
$sql = $db->query("SELECT * FROM user WHERE mm='$mm' ORDER BY sn DESC ");
while ($row=mysqli_fetch_assoc($sql)) {
$this->mkt($row['id']);
}
return;
}
function orderedPid($pid)
{
global $db3;
$sql = $db3->query("SELECT SUM(slot) AS value_sum FROM neworder WHERE pid = '$pid' ");
$row = mysqli_fetch_assoc($sql);
$amt = $row['value_sum'];
return $amt;
}
function PlaceOrder()
{
global $db,$db3, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$pid = $_POST['PlaceOrder'];
$slot = $_POST['slot'];
$sql = $db3->query("SELECT * FROM properties WHERE sn='$pid' ");
$row = mysqli_fetch_assoc($sql);
$name = $row['name'];
$cost = $row['currentprice'];
$sl = $row['slot'];
$slcost = $cost/$sl;
$tcost = $slcost*$slot;
$bal = $this->totalEarnings($uidx);
$x = $sl-$this->orderedPid($pid);
if($x<$slot){$report='Requested blocks is greater than available blocks ('.$x.')'; $count=1; return; }
if($bal<$tcost){$report='You have insufficient funds to complete this transaction'; $count=1; return; }
//if(sqL2('neworder','id',$id,'pid',$pid)>0){$db->query("DELETE FROM neworder WHERE id='$id' AND pid='$pid' "); }
$this->withdrawProcess($tcost,$bal, 'relox property purchase', 1);
$sql = $db3->query("INSERT into neworder (id,pid,slot,cost) VALUES ('$uid', '$pid', '$slot', '$tcost')") or die(mysqli_error($db));
$this->payCommission($uid,$tcost,$sl);
$report = "Purchase Transaction Completed Successfully";
return;
}
function uplineId($id)
{
$key = sqLx('user', 'id', $id, 'sponsor');
$sponsorid = sqLx('user', 'sn', $key, 'id');
return $sponsorid;
}
function payCommission($id,$cost,$type){
global $db;
$comm = 10;
$sn = userName($id,'sn');
$upid = $this->uplineId($id);
//
$t = 'sc';
$re = 'Trading Sales Commission';
$bonus = $cost*$comm*0.01;
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('admin','$upid','$bonus','1','sc','$tno','Relox Sales Commission')");
return;
}
//training setup
function CreateTraining(){
global $db, $report, $count;
$title = addslashes(sanitize($_POST['title']));
$location = ucwords(strtolower(addslashes(sanitize($_POST['location']))));
$cost1 = sanitize($_POST['cost1']);
$cost2 = sanitize($_POST['cost2']);
$date = sanitize($_POST['date']);
$note = addslashes(sanitize($_POST['note']));
$sql = $db->query("INSERT INTO training (title,date,cost1,cost2,locations,note) VALUES ('$title','$date','$cost1','$cost2','$location','$note') ");
if($sql){$report='Successfully Created Training'; }else{ $report='Operation Failed'; $count=1; }
return;
}
function CreateTrainer(){
global $db, $report, $count;
$note = addslashes(sanitize($_POST['note']));
$location = sanitize($_POST['location']);
$id = $this->Uid();
$training = $_GET['index'];
if(sqL2('trainer','id',$id,'training',$training)>0){
$report='You have already registered as Facilitator for this training'; $count=1; return;
}
$sql = $db->query("INSERT INTO trainer (training,id,note,location) VALUES ('$training','$id','$note','$location') ");
if($sql){$report='Successfully Registered Facilitator'; }else{ $report='Operation Failed'; $count=1; }
return;
}
function EditTrainer(){
global $db, $report, $count;
$note = addslashes(sanitize($_POST['note']));
$location = sanitize($_POST['location']);
$id = $this->Uid();
$sn = $_GET['train'];
$sql = $db->query("UPDATE trainer SET note='$note',location='$location' WHERE sn='$sn' ");
if($sql){$report='Successfully Updated Facilitator'; }else{ $report='Operation Failed'; $count=1; }
return;
}
function EditTraining(){
global $db, $report, $count;
$title = addslashes(sanitize($_POST['title']));
$location = ucwords(strtolower(addslashes(sanitize($_POST['location']))));
$cost1 = sanitize($_POST['cost1']);
$cost2 = sanitize($_POST['cost2']);
$date = sanitize($_POST['date']);
$note = addslashes(sanitize($_POST['note']));
$sn = $_GET['course'];
$sql = $db->query("UPDATE training SET title='$title',date='$date',cost1='$cost1',cost2='$cost2',locations='$location',note='$note' WHERE sn='$sn' ");
if($sql){$report='Successfully Updated Training'; }else{ $report='Operation Failed'; $count=1; }
return;
}
function ActivateTraining(){
global $db, $report, $count;
$st = $_POST['ActivateTraining'];
$sn = $_GET['course'];
$sql = $db->query("UPDATE training SET status='$st' WHERE sn='$sn' ");
if($sql){$report='Successfully Updated Training'; }else{ $report='Operation Failed'; $count=1; }
return;
}
function myTrainingPrice($amount,$stage){
if($stage==1){$p=90;}
elseif($stage==2){$p=70;}
elseif($stage==3){$p=50;}
elseif($stage==4){$p=30;}
elseif($stage==5){$p=10;}
elseif($stage==6){$p=0;}
return $p*$amount/100;
}
function sponsorBonus($amount){
return $amount*0.1;
}
function RegisterTrain(){
global $db, $report, $count;
$id=$this->Uid();
$uidx = $this->idToKey($id);
$upidx=sqLx('user','id',$id,'sponsor');
$upid = $this->keyToId($upidx);
$stage = $this->stageCalc($uidx);
$name = userName($id);
$train = explode('-', $_GET['training']);
$training = $train[0];
$location = $_POST['location'];
$type = 'Training Fee for '. sqLx('training','sn',$training,'title');
$cost = sqLx('training','sn',$training,'cost1');
$withdrawAmount = $this->myTrainingPrice($cost,$stage);//
$bal = $this->totalEarnings($uidx);
$status = 1;
$bonus = $withdrawAmount*0.1;
if(sqL2('trainee','training',$training,'id',$id)>0){
$report = 'You have already registered for this training'; $count=1;//
}
elseif ($withdrawAmount <= $bal) {
$this->withdrawProcess($withdrawAmount,$bal, $type, $status);
$sql = $db->query("INSERT INTO trainee (training,id,name,location,cost,type) VALUES ('$training','$id','$name','$location','$withdrawAmount','member') ");
if(userName($upid,'level')>1){
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('admin','$upid','$bonus','$status','tb','$tno','Training Bonus')");
}
$report = 'You have successfully registered for the training: '.sqLx('training','sn',$training,'title');
} else {
$report = 'You do not have sufficient balance to complete this transaction. Fund your wallet and try again';
$count = 1;
}
return;
}
function visitorPaid(){
global $db, $report, $count;
$reg=$_GET['reg'];
$name = sqLx('trainee2','sn',$reg,'name');
$training = sqLx('trainee2','sn',$reg,'training');
$location = sqLx('trainee2','sn',$reg,'location');
$cost = sqLx('trainee2','sn',$reg,'cost');
$phone = sqLx('trainee2','sn',$reg,'phone');
$email = sqLx('trainee2','sn',$reg,'email');
$ref = sqLx('trainee2','sn',$reg,'ref');
$bonus = $cost*0.1;
$status = 1;
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$sql = $db->query("INSERT INTO trainee (training,id,name,location,cost,phone,email,type) VALUES ('$training','','$name','$location','$cost','$phone','$email','non-member') ");
$db->query("UPDATE trainee2 SET status=2 WHERE sn='$reg' ");
if(sqL1('user','user',$ref)>0){
$sponsorid = sqLx('user','user',$ref,'id');
if(userName($sponsorid,'level')>1){
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('admin','$sponsorid','$bonus','$status','tb','$tno','Training Bonus from non-member')");
}
}
$report = 'Operation Successful';
}
function RegisterTrainVisit(){
global $db, $report, $count;
$id='';
$train = explode('-', $_GET['training']);
$training = $train[0];
$location = $_POST['location'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$note = $_POST['note'];
$ref = $_POST['ref'];
$cost = sqLx('training','sn',$training,'cost2');
$status = 1;
$sql = $db->query("INSERT INTO trainee2 (training,id,name,location,phone,email,note,cost,ref) VALUES ('$training','$id','$name','$location','$phone','$email','$note','$cost','$ref') ");
$report = 'Registration data successfully submitted. You will be notified as soon as your payment is confirmed';
return;
}
function PhotoTraining(){
global $db, $report, $count;
$sn = $_GET['course'];
$photo = $_FILES['image']['name'];
$loc = $_FILES['image']['tmp_name'];
$ext = strtolower(pathinfo($photo, PATHINFO_EXTENSION));
$newImage = "train".time().".".$ext;
$array = array('jpg', 'jpeg', 'png');
if (move_uploaded_file($loc, 'news/' . $newImage)) {
$sql = $db->query("UPDATE training SET photo='$newImage' WHERE sn='$sn' ");
$report = "Training graphics Updated Successfully";
}
else{ $report='Operation Failed'; $count=1; }
return;
}
function DeleteTraining(){
global $db, $report, $count;
$sn = $_POST['sn'];
if(sqL1('trainer','training',$sn)>0 OR sqL1('trainee','training',$sn)>0){
$report='This training cannot be deleted'; $count=1; return;
}
$sql = $db->query("DELETE FROM training WHERE sn='$sn' ");
if($sql){$report='Successfully Deleted Training'; }else{ $report='Operation Failed'; $count=1; }
return;
}
function payTopCyclers(){
$target = sqLx('setup','sn',1,'a5');
$i=1;
$sql = $db->query("SELECT * FROM logc WHERE refpoint>='$target' ");
while($row = mysqli_fetch_assoc($sql)){ $e=$i++; $id=$row['id'];
if($e<4){ $p = 'a'.$e; $pay=sqLx('setup','sn',1,$p);; }else{$pay=sqLx('setup','sn',1,'a4');}
$db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('$id','$pay',6,'0')");
}
return;
}
function joinCycler(){
global $db,$report,$count;
$uid=$this->Uid();
$type=nextBoard($uid);
$bal = colSum1('cpay','amount','id',$uid);
if($bal>=efee($type)){
if(sqL1('logc','id',$uid)==0){
$sp = strtolower(trim($_POST['sp']));
$spid = sqLx('user','user',$sp,'id');
if(sqL1('cuser','id',$spid)>0){
$db->query("INSERT INTO logc (id,sponsor) VALUES ('$uid','$spid')");
$p=refPointThisMonth($spid);
$db->query("UPDATE logc SET refpoint='$p' WHERE id='$spid' ");
}else{$report='Invalid sponsor'; $count=1; return; }
}
$this->circler($uid,$type);
$db->query("UPDATE logc SET status='$type' WHERE id='$uid' ");
$report = 'You have successfully joined board '.$type;
}else{$report = 'Insufficient Balance'; $count=1;}
return;
}
// function startCircles(){
// global $db;
// $type=1;
// $lim = $_POST['lim'];
// $sql = $db->query("SELECT * FROM user WHERE c=0 LIMIT $lim ");
// while($row=mysqli_fetch_assoc($sql)){ $id= $row['id'];
// $db->query("INSERT INTO cpay (id,amount) VALUES ('$id',2)");
// $this->circler($id,$type);
// $db->query("UPDATE user SET c=1 WHERE id='$id' ");
// }
// return;
// }
// trainin
function circler($id,$type=1){
global $db,$report;
$upline = $this->nextcupline($type);
$amt=efee($type);
$amount = '-'.$amt;
$db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('$id','$amount',5,'$type')");
$que = $db->query("SELECT * FROM cuser WHERE sn = '$upline' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
$a1 = $ro['sn'];
$a2 = $ro['a1'];
$a3 = $ro['a2'];
$g = $ro['g']+1;
$mm = date('Ym');
$nc = sqL2('cuser','id',$id,'type',$type); $sc = '-'.sfee($type);//
if($nc==2){$db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('$id','$sc',6,'$type')");}
//service charge
//Referral bonus on entry and re-entry
$spid = sqLx('logc','id',$id,'sponsor'); $bonus = $amt/10;
$pay = $pay = sqL2('cuser','id',$spid,'type',$type)>0 ? $db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('$spid','$bonus',3,'$type')") : $db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('ykahbkix','$bonus',3,'$type')");
$db->query("INSERT INTO cuser (id,a1,a2,a3,g,mm,no,type) VALUES ('$id','$a1','$a2','$a3','$g','$mm','$nc','$type')");
$active = sqL2('cuser','a1',$upline,'type',$type);
if($active>2){$active=2;}
$db->query("UPDATE cuser SET active='$active' WHERE sn = '$upline' AND type='$type' ORDER BY sn DESC LIMIT 1 ");
if($active==2){
$upupline = sqLx2('cuser','sn',$upline,'type',$type,'a1');
$no = sqL2('cuser','a2',$upupline,'type',$type);
$pay = $amt*2;
if($no>=4){$this->payAndCircle($upupline,$pay,$type); }
}
$report = 'Operation Successful ';
return;
}
function payAndCircle($id,$pay,$type=1){
global $db;
$id = sqLx('cuser','sn',$id,'id');
$spid = sqLx('logc','id',$id,'sponsor');
$spay = $pay/8;
$db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('$id','$pay',2,'$type')");
$pay = sqL2('cuser','id',$spid,'type',$type)>0 ? $db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('$spid','$spay',3,'$type')") : $db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('ykahbkix','$spay',3,'$type')");
$db->query("INSERT INTO cpay (id,amount,type,cycle) VALUES ('ykahbkix','$spay',3,'$type')");
$this->circler($id,$type);
return;
}
function nextcupline($type)
{
global $db;
$sql = $db->query("SELECT * FROM cuser WHERE type='$type' AND active < 2 ORDER BY g ASC, sn ASC LIMIT 1") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
return $row['sn'];
}
function refLink()
{
$this->VerifySponsor();
return;
}
function VerifySponsor()
{
global $db, $report, $count;
$sponsor = $_SESSION['sponsor'] = sanitize($_POST['sponsor']);
if ($this->validateUser($sponsor) == FALSE) {
$report = 'You have entered an invalid sponsor ID. Please Try Again';
$count = 1;
} else {
$report = 'Sponsor successfully verified';
$_SESSION['signup'] = 2;
}
return;
}
// function totalSavings($id,$opt=0){
// global $db;
// $sum = 0; $int=0;
// $sql = $db->query("SELECT * FROM savings WHERE id='$id' AND status=1 ");
// while($row = $sql->fetch_assoc()){ $sum += $row['amount']; $int += $row['amount']*0.02*age($row['ctime']); }
// $val = $opt==0 ? $sum : $int;
// return $val;
// }
function loanPotential($id){
$level = $this->idToKey($id,'level');
$savings = $this->savingsTotal($id);
$savings2 = 2 * $savings;
if($level<4){$potential = 0; }
elseif($level<5){$potential = $savings2<50 ? $savings2 : 50; }
elseif($level<8){$potential = $savings2<300 ? $savings2 : 300; }
elseif($level>7){$potential = $savings2<1000 ? $savings2 : 1000; }
return $potential;
}
function pinMultiplex($username)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$pin = $row['pin'];
$sq = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
return mysqli_num_rows($sq);
}
function applyTraining() {
global $db, $count, $report;
$id = $this->Uid();
$sn = $this->idToKey($id);
$whatsapp = $_POST['whatsapp'];
$telegram = $_POST['telegram'];
$training = $_POST['applyTraining'];
$amount = $_POST['price'];
$sql = $db->query("SELECT * FROM trainingapplications WHERE training = '$training' AND id = '$id'");
if($sql->num_rows > 0) {
$count = 1;
$report = "You have already Applied for this training";
} else {
$initBalance = $this->totalEarnings($sn);
if($amount > $initBalance) {
$count = 1;
$report = "Fund your wallet";
} else {
$this->withdrawProcess($amount, $initBalance, 'w', 1);
// $this->processWallet($id, $amount, 5, 1, "Withdrawals", '');
$db->query("INSERT INTO trainingapplications(whatsapp, telegram, id, training) VALUES('$whatsapp', '$telegram', '$id', '$training')");
$report = "Applied Successfully";
}
}
}
function LockFunds() {
global $db, $count, $report;
$id = $this->Uid();
$sn = $this->idToKey($id);
$initBalance = $this->totalEarnings($sn);
$amount = $_POST['amount'];
$pass = $_POST['pass'];
$pa = userName($id,'pass');
$start = time();
$end = time()+365*86400;
$ref = rand(10000000,99999999);
if($amount<50){$report='Invalid Amount'; $count=1; return; }
if($amount > $initBalance) {
$report = "You do not have sufficient funds in your wallet"; $count = 1; return;
}
if (password_verify($pass, $pa)) {
$this->withdrawProcess($amount, $initBalance, 'inv', 1);
$db->query("INSERT INTO invacc(id, amount, cos, tan, accno) VALUES('$id', '$amount', '$start', '$end', '$ref')") or die(mysqli_error($db));
$report = "CCI Capital Account Successfully Created";
}else{$report = 'Invalid password'; $count=1;}
return;
}
function findSponsorx()
{
global $db, $report, $count;
$user = strtolower($_GET['reff']);
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['reff'] = $user;
$_SESSION['sponsor'] = $this->validateUser($user, 1);
$_SESSION['sponsorId'] = $this->validateUser($user, 2);
$report = 'Sponsor Successfully Validated';
header('location: ?');
//$count='';
}
return;
}
function DeleteNews($sn){
global $db, $report, $count;
$newsImage = $_POST['newsImage'];
$path = $_SERVER["DOCUMENT_ROOT"]."/cci/profile/news/".$newsImage;
if ($sql = $db->query("DELETE FROM news WHERE sn='$sn'")) {
unlink($path);
$report = "Deleted Successfully";
}
}
function DeleteMaterial($id)
{
global $db, $report, $count;
$name = $_POST['name'];
$path = $path = $_SERVER["DOCUMENT_ROOT"]."/cci/profile/material/" . $name;
if ($sql = $db->query("DELETE FROM material WHERE sn='$id'")) {
unlink($path);
$report = "Deleted Successfully";
}
}
function BuyBook(){
global $db, $report,$count;
$sn = $_POST['BuyBook'];
$uid = $this->Uid();
$uidx = sqLx('user','id',$uid,'sn');
$stage = $this->stageCalc($uidx);
$p = 'p'.$stage;
$cost = sqLx('material','sn',$sn,$p);
$bonus = $cost*0.5;
$bonus2 = $cost*0.1;
$bonus3 = $cost*0.4;
$bal = $this->totalEarnings($uidx);
if ($cost > $bal) { $report = 'You have insufficient balance'; $count=1; return; }
$type='Purchase of E-book: '.sqLx('material','sn',$sn,'title');
$this->withdrawProcess($cost,$bal, $type, 1);
$db->query("INSERT INTO buybook (id,book,price,bonus,bonus2,bonus3) VALUES ('$uid','$sn','$cost','$bonus','$bonus2','$bonus3')");
$report = 'Successfully purchased';
if($cost==0){return; }
$g1 = sqLx('user','user','getrich','id');
$g2 = sqLx('user','user','covisadmin','id');
$upidx=sqLx('user','id',$uid,'sponsor');
$upid = $this->keyToId($upidx);
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10); $tno2 = $tno+1; $tno3=$tno+2;
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('admin','$upid','$bonus','1','eb','$tno','E-book Sales Bonus')");
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('admin','$g1','$bonus2','1','eb','$tno2','E-book Sales Bonus')");
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('admin','$g2','$bonus3','1','eb','$tno3','E-book Sales Bonus')");
return;
}
function DownloadMaterial($id)
{
global $db, $report;
$sql = $db->query("SELECT * FROM material WHERE sn='$id'");
$row = $sql->fetch_assoc();
$path = 'material/' . $row['material'];
$new_name = $row['title'] . '.' . pathinfo($row['material'], PATHINFO_EXTENSION);
// $report = $path;
if (file_exists($path)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $new_name);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length:' . filesize('material/' . $row['material']));
readfile('material/' . $row['material']);
$newcount = $row['downloads'] + 1;
$db->query("UPDATE material SET downloads='$newcount' WHERE sn='$id'");
}
}
function countEasterReg($sn){
global $db;
$start = '2021-03-12 00:00:00';
//$stop = '2021-04-10';
$stop = '2021-04-30 00:00:00';
$sql = $db->query("SELECT COUNT(*) as count FROM user WHERE sponsor = '$sn' AND created BETWEEN '$start' AND '$stop'");
$row = $sql->fetch_object();
return $row->count;
}
function UpdateNews(){
global $db, $report, $count;
$sn = $_POST['UpdateNews'];
$title = sanitize($_POST['title']);
$news = sanitize($_POST['news']);
$newsFeed = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
$loc = $_FILES['image']['tmp_name'];
$ext = strtolower(pathinfo($newsFeed, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png');
if (in_array($ext, $array)) {
if ($size < 2000000) {
$newsImage = "Covis".time().".".$ext;
if (move_uploaded_file($loc, 'news/' . $newsImage)) {
$time = time();
$sql = $db->query("UPDATE news SET title='$title', news='$news', image='$newsImage', time='$time' WHERE sn='$sn'");
// header("Location:managenews.php");
$report = "Updated Successfully";
} else {
$count = 1;
$report = "Problem Uploading Material";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 2MB";
}
} else {
$count = 1;
$report = "File Must Be in jpg,jpeg or png format only";
}
}
function UploadNewsImage(){
global $db, $report, $count;
$title = sanitize($_POST['title']);
$news = sanitize($_POST['news']);
$newsFeed = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
$loc = $_FILES['image']['tmp_name'];
$ext = strtolower(pathinfo($newsFeed, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png');
if (in_array($ext, $array)) {
if ($size < 2000000) {
$newsImage = "Covis".time().".".$ext;
if (move_uploaded_file($loc, 'news/' . $newsImage)) {
$time = time();
$sql = $db->query("INSERT INTO news(title,news,image,time) VALUES('$title','$news','$newsImage','$time')");
$report = "Uploaded Successfully";
} else {
$count = 1;
$report = "Problem Uploading Material";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 2MB";
}
} else {
$count = 1;
$report = "File Must Be in jpg or png format only";
}
}
function UploadMaterial()
{
global $db, $report, $count;
$cat = sanitize($_POST['cat']);
$title = sanitize($_POST['title']);
$p1 = sanitize($_POST['price1']);
$p2 = sanitize($_POST['price2']);
$p3 = sanitize($_POST['price3']);
$p4 = sanitize($_POST['price4']);
$description = sanitize($_POST['description']);
$material = rand().str_replace(" ", "_", $_FILES['material']['name']);
$cover = rand().str_replace(" ", "_", $_FILES['cover']['name']);
$size = $_FILES['material']['size'];
$loc = $_FILES['material']['tmp_name'];
$loc2 = $_FILES['cover']['tmp_name'];
$ext = strtolower(pathinfo($material, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png', 'pdf', 'docx');
if (in_array($ext, $array)) {
if ($size < 80000000) {
if (move_uploaded_file($loc, 'material/' . $material)) {
move_uploaded_file($loc2, 'material/' . $cover);
$ql = $db->query("INSERT INTO material(title,description,material,cover,size,cat,p1,p2,p3,p4) VALUES('$title','$description','$material','$cover','$size','$cat','$p1','$p2','$p3','$p4')");
$report = $title . " Uploaded Successfully";
} else {
$count = 1;
$report = "Problem Uploading Material";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 80MB";
}
} else {
$count = 1;
$report = "File Must Be in pdf or docx format only";
}
}
function UpdateMaterial2()
{
global $db, $report, $count;
$sn = $_GET['ebookid'];
$material = rand().str_replace(" ", "_", $_FILES['material']['name']);
$cover = rand().str_replace(" ", "_", $_FILES['cover']['name']);
$size = $_FILES['material']['size'];
$loc = $_FILES['material']['tmp_name'];
$loc2 = $_FILES['cover']['tmp_name'];
$ext = strtolower(pathinfo($material, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png', 'pdf', 'docx');
//if (in_array($ext, $array)) {
if ($size < 80000000) {
if(isset($_FILES['material'])){
move_uploaded_file($loc, 'material/' . $material);
$ql = $db->query("UPDATE material SET material='$material' WHERE sn='$sn' ");
$report = " Updated Successfully";
}
if(isset($_FILES['cover'])){
move_uploaded_file($loc2, 'material/' . $cover);
$ql = $db->query("UPDATE material SET cover='$cover' WHERE sn='$sn' ");
$report = " Updated Successfully";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 80MB";
}
return;
}
function UpdateMaterial()
{
global $db, $report, $count;
$ebook = $_GET['ebookid'];
$cat = sanitize($_POST['cat']);
$title = sanitize($_POST['title']);
$p1 = sanitize($_POST['price1']);
$p2 = sanitize($_POST['price2']);
$p3 = sanitize($_POST['price3']);
$p4 = sanitize($_POST['price4']);
$description = sanitize($_POST['description']);
$ql = $db->query("UPDATE material SET title='$title',description='$description',cat='$cat',p1='$p1',p2='$p2',p3='$p3',p4='$p4' WHERE sn='$ebook' ");
$report = $title . " Updated Successfully";
return;
}
function EditProfile()
{
global $db, $report, $count;
$id = $this->Uid();
// $firstname = sanitize($_POST['firstname']);
// $lastname = sanitize($_POST['lastname']);
// $email = sanitize($_POST['email']);
$address = sanitize($_POST['address']);
// $phone = sanitize($_POST['phone']);
$sex = sanitize($_POST['sex']);
$dob = sanitize($_POST['dob']);
$officeaddress = sanitize($_POST['officeaddress']);
$city = sanitize($_POST['city']);
$state = sanitize($_POST['state']);
$bank = sanitize($_POST['bank']);
$kinaddress = sanitize($_POST['kinaddress']);
$kinname = sanitize($_POST['kinname']);
$kinphone = sanitize($_POST['kinphone']);
$accountno = sanitize($_POST['accountno']);
//$user = userName($id,'user');
if (!isset($count)) { $sql = $db->query("UPDATE user SET address='$address',sex='$sex', dob='$dob', officeaddress='$officeaddress', kinaddress='$kinaddress', kinphone='$kinphone', kinname='$kinname', city='$city', state='$state', bank='$bank', accountno='$accountno'
WHERE id='$id'");
$report = "Updated Successfully";
} else {
$count = 1;
$report = "Error Updating Profile";
}
}
function EditProfileAdmin()
{
global $db, $report, $count;
$id = $_SESSION['FindUser'];
$firstname = sanitize($_POST['firstname']);
$lastname = sanitize($_POST['lastname']);
$email = sanitize($_POST['email']);
$address = sanitize($_POST['address']);
$phone = sanitize($_POST['phone']);
$sex = sanitize($_POST['sex']);
$dob = sanitize($_POST['dob']);
$officeaddress = sanitize($_POST['officeaddress']);
$city = sanitize($_POST['city']);
$state = sanitize($_POST['state']);
$bank = sanitize($_POST['bank']);
$kinaddress = sanitize($_POST['kinaddress']);
$kinname = sanitize($_POST['kinname']);
$kinphone = sanitize($_POST['kinphone']);
$accountno = sanitize($_POST['accountno']);
$user = userName($id,'user');
if (!isset($count)) { $sql = $db->query("UPDATE user SET firstname='$firstname',lastname='$lastname', email='$email', address='$address',phone='$phone',sex='$sex', dob='$dob', officeaddress='$officeaddress', kinaddress='$kinaddress', kinphone='$kinphone', kinname='$kinname', city='$city', state='$state', bank='$bank', accountno='$accountno',user='$user'
WHERE id='$id'");
$report = "Updated Successfully";
} else {
$count = 1;
$report = "Error Updating Profile";
}
}
function confirmPayment()
{
global $db;
$payref = $_GET['tr_reference'];
if ($_GET['tr_reference'] == $_SESSION['referenc']) {
$this->signupUser();
$_SESSION['signup'] = 4;
}
unset($_SESSION['referenc']);
header("location: ?payment-confirmed#online");
return;
}
function UploadPicture()
{
global $db, $report, $count;
$report = '';
$id = $_POST['id'];
$firstname = $_POST['firstname'];
$image_name = $_FILES['photo']['name'];
$image_loc = $_FILES['photo']['tmp_name'];
$image_type = $_FILES['photo']['type'];
$image_size = $_FILES['photo']['size'];
$ext = explode('.', $image_name);
$end = strtolower(end($ext));
if (checkExtension($end)) {
if (checkSize($image_size)) {
$new_name = $firstname . time() . '.' . $end;
$sql = $db->query("UPDATE user SET photo = '$new_name' WHERE id='$id'");
move_uploaded_file($image_loc, 'images/' . $new_name);
$report .= 'Photo Successfully Uploaded';
} else {
$count = 1;
$report .= 'Image Size Must Not Be More than 1MB';
}
} else {
$count = 1;
$report .= 'Image Must Be In Jpg,Jpeg, or Png Format only';
}
}
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;
}
function validateUser($username, $info = '')
{
global $db, $report, $count;
//$sql=$db->query("SELECT * FROM user WHERE user = '$username' OR email = '$username' " )or die(mysqli_error());
$sql = $db->query("SELECT * FROM user WHERE user = '$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 searchU()
{
global $db, $report, $count;
$username = sanitize($_POST['u-ref']);
$uid = $_SESSION['user_id'];
$uidx = IdToSn($uid);
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$sn2 = IdToSn($row['id']);
$array = array();
for($i=1;$i<=20;$i++){ $a = 'a'.$i;
array_push($array, $row[$a]);
}
if($sql->num_rows < 1){
$report = "Username Does Not Exists";
$count = 1;
}
elseif($uidx == $sn2){
$report = "This Username is Yours ";
$count = 1;
}
elseif(!in_array($uidx, $array)){
$report = "You can only search for Username in your Team";
$count = 1;
}
else{
$_SESSION['FindTeam'] = $row['id'];
header("location: searchteam.php");
}
return;
}
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['phone'] = $this->valPhone($_POST['phone']);
$_SESSION['email'] = strtolower($this->valEmpty(sanitize($_POST['email']), 'E-mail'));
$username = str_replace("'", "", strtolower($this->valEmpty($_POST['username'], 'Username')));
$_SESSION['username'] = str_replace(' ', '', trim($username));
$_SESSION['password'] = $this->valPass($_POST['password']);
$_SESSION['password2'] = $_POST['password2'];
$_SESSION['gender']=$_POST['gender'];
$_SESSION['state']=sanitize($_POST['state']);
$_SESSION['country']=sanitize($_POST['country']);
$_SESSION['upline']=$_POST['upline']??'';
if ($_SESSION['password'] != $_SESSION['password2']) {
$report .= "<br>Password confirmation failed, Try again";
$count = 1;
} elseif ($this->userExist($_SESSION['username']) == TRUE) {
$report .= "<br>A user with this username already exist. Try again.";
$count = 1;
} elseif (!isset($count)) {
$report = "<br>Login Information successfully submitted, proceed to Pin Payment";
$_SESSION['signup'] = 3;
}
return;
}
function valEmpty($field, $fname)
{
global $report, $count;
$field = sanitize(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 getStage2Pay(){
global $db;
$affectedRow = 0;
$sql = $db->query("SELECT * FROM user WHERE level BETWEEN 2 AND 4 AND wallet = 0 AND done=0 LIMIT 200 ");
while ($row = mysqli_fetch_assoc($sql)){
$uid = $row['id'];
$pay = $this->stageTeam($uid,2) * 2;
$db->query("UPDATE user SET wallet = '$pay', done=1 WHERE id = '$uid'");
$affectedRow += 1;
}
echo 'Affected Rows: '. $affectedRow;
}
function levelToStage($level){
if($level>=17){$bl=7;}
elseif($level>=14){$bl=6;}
elseif($level>=11){$bl=5;}
elseif($level>=8){$bl=4;}
elseif($level>=5){$bl=3;}
elseif($level>=2){$bl=2;}
else{$bl=1;}
return $bl;
}
function updateUserStageTeam($uid){
global $db;
$level = userName($uid,'level');
$key = $this->idToKey($uid);
$team = $this->userStageTeam($uid);
$db->query("UPDATE user SET team = '$team', done=1 WHERE id = '$uid'");
$this->levelCreate($key);//
return;
}
function getStageTeam(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level>1 AND done=0 LIMIT 200 ");
while ($row = mysqli_fetch_assoc($sql)){ $level = $row['level'];
$stage=$this->levelToStage($level);
$uid = $row['id'];
$team = $this->userStageTeam($uid);
$db->query("UPDATE user SET team = '$team', done=1 WHERE id = '$uid'");
}
return;
}
function getStageTeamx(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level>0 AND done=0 ORDER BY sn DESC LIMIT 100 ");
while ($row = mysqli_fetch_assoc($sql)){ //$level = $row['level'];
//$stage=$this->levelToStage($level);
$uid = $row['id'];
$team = $this->userStageTeam($uid);
$db->query("UPDATE user SET team = '$team', done=1 WHERE id = '$uid'");
}
return;
}
function levelToPph($level){
if($level>=17){$bl=25000;}
elseif($level>=14){$bl=50000;}
elseif($level>=11){$bl=2000;}
elseif($level>=8){$bl=150;}
elseif($level>=5){$bl=12.5;}
elseif($level>=2){$bl=2;}
else{$bl=0;}
return $bl;
}
// function levelToPphNew($level){
// if($level>=17){$bl=12500;}
// elseif($level>=14){$bl=50000;}
// elseif($level>=11){$bl=1250;}
// elseif($level>=8){$bl=100;}
// elseif($level>=5){$bl=25;}
// elseif($level>=2){$bl=2;}
// else{$bl=0;}
// return $bl;
// }
function levelToPphNew($level){
if($level>=17){$bl=5000;}
elseif($level>=14){$bl=25000;}
elseif($level>=11){$bl=500;}
elseif($level>=8){$bl=100;}
elseif($level>=5){$bl=20;}
elseif($level>=2){$bl=2;}
else{$bl=0;}
return $bl;
}
function levelPayoutx($level){
if($level==11){$bl=32204.5;}
elseif($level==10){$bl=9854.5;}
elseif($level==9){$bl=7354.5;}
elseif($level==8){$bl=7354.5;}
elseif($level==7){$bl=217;}
elseif($level==6){$bl=117;}
elseif($level==5){$bl=107;}
elseif($level==4){$bl=12.5;}
elseif($level==3){$bl=2.5;}
elseif($level==2){$bl=2.5;}
elseif($level==1){$bl=0;}
return $bl;
}
function levelPayout($level){
$bl=0;
if($level==11){$bl=7530;}
elseif($level==10){$bl=680;}
elseif($level==9){$bl=680;}
elseif($level==8){$bl=680;}
elseif($level==7){$bl=92.5;}
elseif($level==6){$bl=92.5;}
elseif($level==5){$bl=92.5;}
elseif($level==4){$bl=2.5;}
elseif($level==3){$bl=2.5;}
elseif($level==2){$bl=2.5;}
elseif($level==1){$bl=0;}
return $bl;
}
// function levelPayoutNew($level){
// $bl=0;
// if($level==11){$bl=5313;}
// elseif($level==10){$bl=1163;}
// elseif($level==9){$bl=1163;}
// elseif($level==8){$bl=1163;}
// elseif($level==7){$bl=88;}
// elseif($level==6){$bl=88;}
// elseif($level==5){$bl=88;}
// elseif($level==4){$bl=0;}
// elseif($level==3){$bl=0;}
// elseif($level==2){$bl=0;}
// elseif($level==1){$bl=0;}
// return $bl;
// }
function levelPayoutNew($level){
$bl=0;
if($level==11){$bl=5487.5;}
elseif($level==10){$bl=1087.5;}
elseif($level==9){$bl=1087.5;}
elseif($level==8){$bl=1087.5;}
elseif($level==7){$bl=107.5;}
elseif($level==6){$bl=107.5;}
elseif($level==5){$bl=107.5;}
elseif($level==4){$bl=19.5;}
elseif($level==3){$bl=1.5;}
elseif($level==2){$bl=0;}
elseif($level==1){$bl=0;}
return $bl;
}
function levelPayoutNewOverall($level){
$bl=0;
if($level==11){$bl=24087.5;}
elseif($level==10){$bl=8837.5;}
elseif($level==9){$bl=8587.5;}
elseif($level==8){$bl=7337.5;}
elseif($level==7){$bl=307.5;}
elseif($level==6){$bl=157.5;}
elseif($level==5){$bl=107.5;}
elseif($level==4){$bl=19.5;}
elseif($level==3){$bl=1.5;}
elseif($level==2){$bl=0;}
elseif($level==1){$bl=0;}
return $bl;
}
function getLevelePayoutx($level){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level='$level' ");
$paylevel = mysqli_num_rows($sql)*$this->levelPayoutx($level);
if($level==3){
$sum = mysqli_num_rows($sql)*3;
}
elseif($level==4){
$sum = mysqli_num_rows($sql)*12;
}
else{
$sq = $db->query("SELECT SUM(team) AS sum FROM user WHERE level>4 AND level='$level' ");
$row = mysqli_fetch_assoc($sq);
$sum = $row['sum'];
}
return $sum*$this->levelToPphNew($level)+$paylevel;
}
function getLevelePayout($level){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level='$level' ");
$paylevel = mysqli_num_rows($sql)*$this->levelPayoutNew($level);
if($level==4){
$sq = $db->query("SELECT * FROM user WHERE level='$level' ");
$num = mysqli_num_rows($sq);
$sum = $num*12;
}else{
$sq = $db->query("SELECT SUM(team) AS sum FROM user WHERE level>1 AND level='$level' ");
$row = mysqli_fetch_assoc($sq);
$sum = $row['sum'];
}
return $sum*$this->levelToPphNew($level)+$paylevel;
}
function getUserLevelePayout($id){
global $db;//
$sql = $db->query("SELECT * FROM user WHERE id='$id' ");
$row = mysqli_fetch_assoc($sql); $level = $row['level'];
$stage = $this->stageCalc($row['sn']);
// $team = $level==4 ? 12 : $this->stageTeam($id,$stage);
$team = $this->stageTeam($id,$stage);
$pay = $this->levelPayoutNew($level);
return $team*$this->levelToPphNew($level)+$pay;
}
function getUserLevelePayoutOverall($id){
global $db;//
$sql = $db->query("SELECT * FROM user WHERE id='$id' ");
$row = mysqli_fetch_assoc($sql); $level = $row['level'];
$stage = $this->stageCalc($row['sn']);
// $referrals = $this->referral($row['sn']);
$team = $this->stageTeam($id,$stage);
$pay = $this->levelPayoutNewOverall($level);
return $team*$this->levelToPphNew($level)+$pay;//+$referrals;
}
function getUserLevelePayoutt($id){
global $db;
$sql = $db->query("SELECT * FROM user WHERE id='$id' ");
$row = mysqli_fetch_assoc($sql); $level = $row['level'];
$team = $row['team'];
$pay = $this->levelPayoutNew($level);
return $team*$this->levelToPphNew($level)+$pay;
}
function valPhone($field)
{
global $report, $count;
$field = sanitize(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) < 4) {
$report .= "<br>Password cannot be less than 6 characters! ";
$count = 1;
return;
} else {
return sanitize($field);
}
}
function pinValidity($pin)
{
global $db, $report, $count;
$sq = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
$nu = mysqli_num_rows($sq);
$ro = mysqli_fetch_assoc($sq);
$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 == 0) {
$report = 'You have entered an invalid E-PIN, verify your E-PIN and try again';
$count = 1;
$valid = FALSE;
//} elseif ($num == 1 AND $row['status'] == 0) {
}
elseif ($num == 1 AND $nu == 0) {
$valid = TRUE;
} else {
$valid = FALSE;
$report = 'This E-PIN has already been used by: ' . $this->pinUsedBy($pin) . ' as at ' . $ro['created'];
$count = 1;
}
return $valid;
}
function RegisterWithPin()
{
global $db, $count, $report;
$pin = strtoupper(sanitize($_POST['epin']));
$username = $_SESSION['username'];
$sponsor = sanitize($_POST['sponsor']);
$upline = sanitize($_POST['upline']);
$sq = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
$nu = mysqli_num_rows($sq);
$ro = mysqli_fetch_assoc($sq);
$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 ($nu > 0) { $report = 'This E-PIN has already been used by: ' . $this->pinUsedBy($pin) . ' as at ' . $ro['created'];
$count = 1;
} elseif ($nu == 0) {
$_SESSION['pin'] = $pin;
if($this->userExist($username) == TRUE){
$report = "A user with this username already exist. Try another Username. ";
$count = 1;
}
else {
if($this->verifySpUp($sponsor,$upline) == 2){
$this->Register($sponsor,$upline);
$_SESSION['signup'] = 0;
$report = "Successfully Registered directly under: ".$this->userName($upline)." (".$this->userName($upline,'user').")";
}else{ $_SESSION['signup'] = 0; $report = "Registration was not successful. Please, try again"; $count=1;}
}
}
} else {
$report = 'You have entered an invalid E-PIN, verify your E-PIN and try again';
$count = 1;
}
return;
}
function payWithPin()
{
global $db, $count, $report;
$pin = strtoupper(sanitize($_POST['epin']));
$username = $_SESSION['username'];
$sq = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
$nu = mysqli_num_rows($sq);
$ro = mysqli_fetch_assoc($sq);
$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 ($nu > 0) {
$report = 'This E-PIN has already been used by: ' . $this->pinUsedBy($pin) . ' as at ' . $ro['created'];
$count = 1;
}
// elseif ($row['status'] == 0) {
elseif ($this->pinValidity($pin) == TRUE) {
$_SESSION['pin'] = $pin;
$this->signupUser();
$used = date('Y-m-d H:i');
$sql = $db->query("UPDATE pin SET status = 1, id = '$username', used = '$used' WHERE pin = '$pin' ") or die(mysqli_error());
$_SESSION['signup'] = 4;
}
} 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 findUpline($sponsor)
{
global $db;
$key = $this->userToKey($sponsor);
$sql = $db->query("SELECT * FROM user WHERE (sn='$key' OR a1='$key' OR a2='$key' OR a3='$key' OR a4='$key' OR a5='$key' OR a6='$key' OR a7='$key' OR a8='$key' OR a9='$key' OR a10='$key' OR a11='$key' OR a12='$key' OR a13='$key')
AND active < 3 ORDER BY g ASC, sn ASC LIMIT 1") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
return $row['sn'];
}
function UpgradeForex()
{ global $db,$db2, $count, $report;
$id = $_POST['UpgradeForex'];
//$ctime=time();
if(sqL1x('user','id',$id)==0){
$db2->query("INSERT INTO user (id) VALUES ('$id')");
$rand = rand();
$db->query("INSERT INTO transfer (id,amount,type,tno) VALUES ('$id',10,'ce',$rand)");
$remark = 'transfered from CCI';
$db2->query("INSERT INTO wallet (id,cos,status,type,remark) VALUES ('$id',10,10,21,'$remark')");
}
$factor=sqLxx('user','id',$id,'sn');
header("location:https://thecoviseconomy.com/signup.php?factor=$factor");
return;
}
function signupUser()
{
global $report, $count;
$sponsor = $_SESSION['sponsor'];
$username = $_SESSION['username'];
if ($this->userExist($username) == TRUE) {
$report = "A user with this username already exist. Try another Username. ";
$count = 1;
} else {
$sponsorkey = $this->userToKey($sponsor);
$upline = ($this->Downline($sponsorkey) < 3) ? $sponsorkey : $this->findUpline($sponsor);
if(isset($_SESSION['upline'])){ $upline = $this->userToKey($_SESSION['upline']); }
if($this->verifySpUp($sponsorkey,$upline) == 2){
$this->Register($sponsorkey,$upline);
$report = "You have been successfully registered"; $count=0;// directly under ".$this->userName($username);
}else{unset($_SESSION['signup']);
$report = "Registration not successful. Please verify your sponsor and start your Registration"; $count=1;
}
}
return;
}
function verifySpUp($sponsorkey,$upline){
global $db;
$num=0;
$que = $db->query("SELECT * FROM user WHERE sn = '$sponsorkey' ") or die(mysqli_error());
$num += mysqli_num_rows($que);
$que2 = $db->query("SELECT * FROM user WHERE sn = '$upline' ") or die(mysqli_error());
$num += mysqli_num_rows($que2);
return $num;
}
function userName($user,$col='')
{
global $db;
$que = $db->query("select * FROM user WHERE sn = '$user' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
$val = ($col == '')?$ro['firstname'] . ' ' . $ro['lastname']:$ro[$col];
return $val;
}
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 pinUsedBy($pin)
{
global $db;
$que = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro['firstname'] . ' ' . $ro['lastname']. ' (' . $ro['user'].')';
}
function userName4($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']);
}
}
function userName3($user, $col = 'id')
{
global $db;
$que = $db->query("SELECT * FROM user WHERE user = '$user' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
function userToKey($user, $col = 'sn')
{
global $db;
$que = $db->query("select * FROM user WHERE user = '$user' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
function idToKey($id, $col = 'sn')
{
global $db;
$que = $db->query("SELECT * FROM user WHERE id = '$id' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return mysqli_num_rows($que)>0 ? $ro[$col]:'';
}
function idToKeyGm($id, $col = 'sn')
{
global $db;
$que = $db->query("SELECT * FROM globeuser WHERE id = '$id' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
function snToUserGm($key)
{
global $db;
$que = $db->query("SELECT * FROM globeuser WHERE sn = '$key' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $this->idToKey($ro['id'],'user');
}
function snToUser($key)
{
global $db;
$que = $db->query("SELECT * FROM user WHERE sn = '$key' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro['user'];
}
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)
{
global $db, $report, $count;
//$sql=$db->query("SELECT * FROM user WHERE user = '$username' OR email = '$email' " )or die(mysqli_error());
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") 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, $upline)
{
global $db, $report, $count;
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
$phone = $_SESSION['phone'];
$email = $_SESSION['email'];
$username = $_SESSION['username'];
$gender = $_SESSION['gender'];
$state = $_SESSION['state'];
$country = $_SESSION['country'];
$password = $_SESSION['password'];
$password2 = $_SESSION['password2'];
$pwd = password_hash($password, PASSWORD_BCRYPT);
$pin = $_SESSION['pin'];
$que = $db->query("SELECT * FROM user WHERE sn = '$upline' ") 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'];
$a12 = $ro['a11'];
$a13 = $ro['a12'];
$a14 = $ro['a13'];
$a15 = $ro['a14'];
$a16 = $ro['a15'];
$a17 = $ro['a16'];
$a18 = $ro['a17'];
$a19 = $ro['a18'];
$a20 = $ro['a19'];
$a21 = $ro['a20'];
$a22 = $ro['a21'];
$a23 = $ro['a22'];
$a24 = $ro['a23'];
$a25 = $ro['a24'];
$a26 = $ro['a25'];
$a27 = $ro['a26'];
$a28 = $ro['a27'];
$a29 = $ro['a28'];
$a30 = $ro['a29'];
$g = $ro['g']+1;
$mm = date('Ym');
$id = $this->win_hashs(8);
if(empty($sponsor) OR empty($a1) OR empty($username) OR empty($pwd) OR empty($firstname) OR $this->active($upline)>2){
unset($_SESSION['signup']); $report='Sorry, Registration failed. Please repeat your registration '; $count=1;
}else{
$reg = $db->query("INSERT INTO user (id,sponsor,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,firstname,lastname,phone,email,sex,state,country,user,pass,pin,mm,g)
VALUES('$id','$sponsor','$a1','$a2','$a3','$a4','$a5','$a6','$a7','$a8','$a9','$a10','$a11','$a12','$a13','$a14','$a15','$a16','$a17','$a18','$a19','$a20','$a21','$a22','$a23','$a24','$a25','$a26','$a27','$a28','$a29','$a30','$firstname','$lastname','$phone','$email','$gender','$state',',$country','$username','$pwd','$pin','$mm','$g')") or die('Cannot Connect to Server');
// $down = $db->query("SELECT * FROM user WHERE a1 = '$upline' ") or die(mysqli_error());
// $nd = mysqli_num_rows($down);
$used = date('Y-m-d H:i');
// if($this->activePin($pin)>0){
//if ($this->pinValidity($pin) == TRUE) {
if ($reg){
$sql = $db->query("UPDATE pin SET status = 1, id = '$username', used = '$used' WHERE pin = '$pin' ") or die(mysqli_error()); }
$this->mkt($id);
$nd = $this->active($upline);
$upd = $db->query("UPDATE user SET active='$nd' WHERE sn = '$upline' ");
$sp = sqL1('user','sponsor',$sponsor);;
$updx = $db->query("UPDATE user SET sp='$sp' WHERE sn = '$sponsor' ");
if($this->level1($a1)==1){ $this->levelUpdate($this->idToKey($id)); }
$this->emailer($email);
//if($this->level2($a2)==2){$sql = $db->query("UPDATE user SET level='2' WHERE sn = '$a2' ");}
$_SESSION['signup'] = 4;
if(isset($_SESSION['upline'])){ unset($_SESSION['upline']); }
}
return;
}
function userAlt($user){
$new = sqL1('user','user',$user)==0 ? $user : $user.rand(10000,99999);
return $new;
}
function pickUser($username){
global $db;
$sql = $db->query("SELECT * FROM user WHERE user LIKE '%$username%' ") or die(mysqli_error());
$num = mysqli_num_rows($sql);
return $username.$num.'a';
}
function pickPin($uid,$opt=1){
global $db;
$sql = $db->query("SELECT * FROM pin WHERE rep = '$uid' AND status=0 ORDER BY rand() LIMIT 1 ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
return $opt==1 ? $row['pin'] : mysqli_num_rows($sql);
}
function AddNewUsersAuto($no){
global $db, $report, $count;
$uid = $this->Uid();
$uidx = userName($uid,'sn');
$sponsor = userName($uid,'user');
$pinall = sqL2('pin','rep',$uid,'status',0);
$cost = $no*0.1;
$balance = $this->totalEarnings($uidx);
if($pinall<$no){$report='You do not have enough number of PINs for this transaction.'; $count=1; return;}
if($balance<$cost){$report='You need to have a service charge of $'.number_format($cost,2).' in your wallet to complete this transaction'; $count=1; return;}
$i=1;
while($i<=$no){ $e=$i++;
$pickuser = $this->pickUser($sponsor);
if($this->pickPin($uid,2)==1){$pickpin = $this->pickPin($uid);
$this->RegisterAuto($sponsor, $pickpin, $pickuser);
}else{$report = 'Successfully registered '.($e-1).' new accounts'; return; }
}
//debit cost
$this->withdrawProcess($cost,$balance, 'mr', 1);
$report = 'Successfully registered '.$no.' new accounts'; return;
return;
}
function RegisterAuto($sponsor, $pin, $username)
{
global $db, $report, $count;
//$username = $this->userAlt($user);
$sponsorkey = $this->userToKey($sponsor);
$sql = $db->query("SELECT * FROM user WHERE user = '$sponsor' ") or die(mysqli_error());
$row = mysqli_fetch_array($sql);
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$phone = $row['phone'];
$email = $row['email'];
//$username = $this->getNewUser($sponsor);//['username'];
$gender = $row['sex'];
$state = $row['state'];
$country = $row['country'];
$pwd = $row['pass'];
// $password2 = $_SESSION['password2'];
// $pwd = password_hash($password, PASSWORD_BCRYPT);
// $pin = $_SESSION['pin'];
$upline = $this->findUpline($sponsor);
$que = $db->query("SELECT * FROM user WHERE sn = '$upline' ") 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'];
$a12 = $ro['a11'];
$a13 = $ro['a12'];
$a14 = $ro['a13'];
$a15 = $ro['a14'];
$a16 = $ro['a15'];
$a17 = $ro['a16'];
$a18 = $ro['a17'];
$a19 = $ro['a18'];
$a20 = $ro['a19'];
$a21 = $ro['a20'];
$a22 = $ro['a21'];
$a23 = $ro['a22'];
$a24 = $ro['a23'];
$a25 = $ro['a24'];
$a26 = $ro['a25'];
$a27 = $ro['a26'];
$a28 = $ro['a27'];
$a29 = $ro['a28'];
$a30 = $ro['a29'];
$g = $ro['g']+1;
$mm = date('Ym');
$id = $this->win_hashs(8);
//indicate auto reg
$reg = $db->query("INSERT INTO user (id,sponsor,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,firstname,lastname,phone,email,sex,state,country,user,pass,pin,mm,g,a)
VALUES('$id','$sponsorkey','$a1','$a2','$a3','$a4','$a5','$a6','$a7','$a8','$a9','$a10','$a11','$a12','$a13','$a14','$a15','$a16','$a17','$a18','$a19','$a20','$a21','$a22','$a23','$a24','$a25','$a26','$a27','$a28','$a29','$a30','$firstname','$lastname','$phone','$email','$gender','$state',',$country','$username','$pwd','$pin','$mm','$g',1)") or die('Cannot Connect to Server');
$used = date('Y-m-d H:i');
$sql = $db->query("UPDATE pin SET status = 1, id = '$username', used = '$used' WHERE pin = '$pin' ");
$nd = $this->active($upline);
$db->query("UPDATE user SET active='$nd' WHERE sn = '$upline' ");
$sp = sqL1('user','sponsor',$sponsorkey);
$db->query("UPDATE user SET sp='$sp' WHERE sn = '$sponsorkey' ");
if($this->level1($a1)==1){ $this->levelUpdate($this->idToKey($id)); }
$this->mkt($id);
//$this->emailer($email);
return;
}
function updateA16toA30($sn){
global $db,$report;
$key=$sn ;
$i=1; $all = '';
while($i<=30){
$e=$i++; $key = sqLx('user','sn',$key,'a1');
// $all .= $key.',';
$find = 'a'.$e ; $$find = $key; }
// $keys = explode(',', $all);
// $db->query("UPDATE user SET a17='$a17',a18='$a18',a19='$a19',a20='$a20',a21='$a21',a22='$a22',a23='$a23',a24='$a24',a25='$a25',a26='$a26',a27='$a27',a28='$a28',a29='$a29',a30='$a30',done=1 WHERE sn ='$sn' ");
$db->query("UPDATE user SET a30='$a30' WHERE sn ='$sn' ");
return;
}
function updateA16toA30All(){
global $db,$report;
$sql = $db->query("SELECT * FROM user WHERE a29>1 LIMIT 10000");
while ($row=mysqli_fetch_assoc($sql)) {
$this->updateA16toA30($row['sn']);
}
$report = 'Operation Successfully';
return;
}
function myUpline($key){
return sqLx('user','sn',$key,'a1');
}
function addMm(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE mm=0 ");
while ($row=mysqli_fetch_assoc($sql)) {
$sn = $row['sn']; $mm = str_replace('-', '', substr($row['created'], 0,7));
$db->query("UPDATE user SET mm='$mm' WHERE sn='$sn' ");
}
return;
}
function addGuser(){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE user=0 ");
while ($row=mysqli_fetch_assoc($sql)) {
$id = $row['id']; $user = $this->idToKey($id,'user');
$db->query("UPDATE globeuser SET user='$user' WHERE id='$id' ");
}
return;
}
function activePin($pin)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
return mysqli_num_rows($sql);
}
function UpdateRegister()
{
global $db, $report, $count;
$sponsor = $_POST['sponsor'];
$upline = $_POST['upline'];
$ssn = $_POST['UpdateUserSponsor'];
$que = $db->query("SELECT * FROM user WHERE sn = '$upline' ") 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'];
$a12 = $ro['a11'];
$a13 = $ro['a12'];
$a14 = $ro['a13'];
$a15 = $ro['a14'];
$a16 = $ro['a15'];
//$id = $this->win_hashs(8);
// $reg = $db->query("UPDATE user SET sponsor='$sponsor',a1='$a1',a2='$a2',a3='$a3',a4='$a4',a5='$a5',a6='$a6',a7='$a7',a8='$a8',a9='$a9',a10='$a10',a11='$a11',a12='$a12',a13='$a13',a14='$a14',a15='$a15',a16='$a16' WHERE sn='$ssn' ") or die('Cannot Connect to Server 2');
// $down = $db->query("SELECT * FROM user WHERE a1 = '$upline' ") or die(mysqli_error());
// $nd = mysqli_num_rows($down);
// $upd = $db->query("UPDATE user SET active='$nd' WHERE sn = '$upline' ");
// $sp = $this->wildSponsored($sponsor);
// $updx = $db->query("UPDATE user SET sp='$sp' WHERE sn = '$sponsor' ");
// if($this->level2($a2)==2){$sql = $db->query("UPDATE user SET level='2' WHERE sn = '$a2' ");}
//$report ='Operation Successful ';
$report='This operation is temporarily suspended. Contact super administrator';
return;
}
function message($id, $msg)
{
global $db;
$ctime = CTIME;
$msg = $db->query("INSERT INTO msg (receiverid,senderid,msg,ctime)
VALUES('$id','1','$msg','$ctime')") or die(mysqli_error());
return;
}
function BookCat()
{
global $db,$report;
$cat = ucwords($_POST['cat']);
$msg = $db->query("INSERT INTO bookcat (cat)
VALUES('$cat')") or die(mysqli_error());
$report='Operation Successful';
return;
}
function TestimonyPhoto()
{
global $db,$report,$count;
$id = $this->Uid();
$link = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
$loc = $_FILES['image']['tmp_name'];
$ext = strtolower(pathinfo($link, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png');
if (in_array($ext, $array)) {
if ($size < 2000000) {
$link2 = $this->win_hashs(15).".".$ext;
$ref=$this->win_hash(12);
if (move_uploaded_file($loc, 'news/' . $link2)) {
$note = sanitize($_POST['note']);
// $note = str_ireplace('script', '', sanitize($_POST['note']));
$sql = $db->query("INSERT INTO testimony (id,link,note,type,ref)
VALUES('$id','$link2','$note',1,'$ref')") or die(mysqli_error());
$report = "Uploaded Successfully";
} else {
$count = 1;
$report = "Problem Uploading Material";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 2MB";
}
} else {
$count = 1;
$report = "File Must Be in jpg or png format only";
}
return;
}
function DonationPhoto()
{
global $db,$report,$count;
$id = $this->Uid();
$link = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
$loc = $_FILES['image']['tmp_name'];
$ext = strtolower(pathinfo($link, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png');
if (in_array($ext, $array)) {
if ($size < 2000000) {
$link2 = $this->win_hashs(15).".".$ext;
$ref=$this->win_hash(12);
if (move_uploaded_file($loc, 'news/' . $link2)) {
$note = str_ireplace('script', '', sanitize($_POST['note']));
$title = sanitize($_POST['title']);
$sql = $db->query("INSERT INTO donation (id,link,note,title,tno) VALUES('$id','$link2','$note','$title','$ref')") or die(mysqli_error());
$report = "Donation Submitted Successfully";
} else {
$count = 1;
$report = "Problem Uploading Material";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 2MB";
}
} else {
$count = 1;
$report = "File Must Be in jpg or png format only";
}
return;
}
function EditDonationPhoto()
{
global $db,$report,$count;
$id = $this->Uid();
$ref = $_GET['donation'];
$link = $_FILES['image']['name'];
$size = $_FILES['image']['size'];
$loc = $_FILES['image']['tmp_name'];
$ext = strtolower(pathinfo($link, PATHINFO_EXTENSION));
$array = array('jpg', 'jpeg', 'png');
if (in_array($ext, $array)) {
if ($size < 2000000) {
$link2 = $this->win_hashs(15).".".$ext;
if (move_uploaded_file($loc, 'news/' . $link2)) {
$note = str_ireplace('script', '', sanitize($_POST['note']));
$title = sanitize($_POST['title']);
$sql = $db->query("UPDATE donation SET link='$link2',note='$note',title='$title' WHERE tno='$ref' ") or die(mysqli_error());
$report = "Donation Updated Successfully";
} else {
$count = 1;
$report = "Problem Uploading Material";
}
} else {
$count = 1;
$report = "File shouldn't be larger than 2MB";
}
} else {
$count = 1;
$report = "File Must Be in jpg or png format only";
}
return;
}
function TestimonyVideo()
{
global $db,$report;
$id = $this->Uid();
$ref=$this->win_hash(12);
$link = sanitize($_POST['link']);
$note = sanitize($_POST['note1']);
// $link = str_ireplace('script', '', sanitize($_POST['link']));
// $note = str_ireplace('script', '', sanitize($_POST['note1']));
$sql = $db->query("INSERT INTO testimony (id,link,note,type,ref)
VALUES('$id','$link','$note',2,$ref)") or die(mysqli_error());
$report='Operation Successful';
return;
}
function PayDonation()
{
global $db,$report,$count;
$id = $this->Uid();
$uidx = $this->idToKey($id);
$ref=$_GET['donation'];
$amount = sanitize($_POST['amount']);
$initBalance = $this->totalEarnings($uidx);
$type = "d";
$status = 1;
if($initBalance>=$amount AND $amount>0){
$this->withdrawProcess($amount,$initBalance, $type, $status);
$sql = $db->query("INSERT INTO donate (id,dsn,amount)
VALUES('$id','$ref','$amount')") or die(mysqli_error());
$report='You have Successfully donated $'.$amount;
}else{
$report = 'You have insufficient balance. Fund your wallet and try again';
$count=1;
}
return;
}
function TerminateDonation()
{
global $db,$report,$count;
$id = $this->Uid();
$rec = $_SESSION['bene'];
$ref=$_GET['donation'];
$amount = $_POST['amount'];
$tno=rand();
$sql = $db->query("UPDATE donation SET rec='$rec', amount='$amount', status=2 WHERE tno='$ref' ") ;
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno) VALUES ('$id','$rec','$amount','1','dt','$tno')");
if($sql){
$report='You have Successfully terminated a donation of $'.$amount;
}else{
$report = 'Operation failed. You can try again';
$count=1;
}
unset($_SESSION['bene']);
return;
}
function ApproveTesti()
{
global $db,$report;
$ref=$_GET['tes'];
$sql = $db->query("UPDATE testimony SET status=1 WHERE ref='$ref' ") or die(mysqli_error());
$report='Operation Successful';
return;
}
function DisapproveTesti()
{
global $db,$report;
$ref=$_GET['tes'];
$sql = $db->query("UPDATE testimony SET status=0 WHERE ref='$ref' ") or die(mysqli_error());
$report='Operation Successful';
return;
}
function ApproveDonation()
{
global $db,$report;
$ref=$_GET['donation'];
$sql = $db->query("UPDATE donation SET status=1 WHERE tno='$ref' ") or die(mysqli_error());
$report='Operation Successful';
return;
}
function DisapproveDonation()
{
global $db,$report;
$ref=$_GET['donation'];
$sql = $db->query("UPDATE donation SET status=0 WHERE tno='$ref' ") or die(mysqli_error());
$report='Operation Successful';
return;
}
function DeleteTesti()
{
global $db,$report;
$ref=$_GET['tes'];
$sql = $db->query("DELETE FROM testimony WHERE ref='$ref' ") or die(mysqli_error());
$report='Operation Successful';
return;
}
function checkTestimony($id)
{
global $db,$report;
$sql = $db->query("SELECT * FROM testimony WHERE id='$id' AND status=1 ") or die(mysqli_error());
$num1= mysqli_num_rows($sql);
$sql2 = $db->query("SELECT * FROM withdraw WHERE id='$id' AND type='w' ") or die(mysqli_error());
$num2= mysqli_num_rows($sql2);
$res = ($num1==0 AND $num2>0) ? FALSE : TRUE ;
return $res;
}
function UpdateTesti()
{
global $db,$report;
$ref=$_GET['tes'];
$note = str_ireplace('script', '', sanitize($_POST['note']));
$link = $_POST['link'];
$sql = $db->query("UPDATE testimony SET link='$link', note='$note' WHERE ref='$ref' ") or die(mysqli_error());
$report='Operation Successful';
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 win_hashs($length)
{
return substr(str_shuffle(str_repeat('123456789abcdefghijklmnopqrstuvwxyz', $length)), 0, $length);
}
function resetPass()
{
global $db, $report, $count;
$email = strtolower(trim(sanitize($_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.covisclubinternational.com/accountreset.php?request-index=' . $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, $count;
$username = $_SESSION['username'];
$firstname = ucwords(strtolower($this->valEmpty($_POST['firstname'], 'Surname')));
$lastname = ucwords(strtolower($this->valEmpty($_POST['lastname'], 'Other Names')));
$country = $_POST['country'];
$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');
$course = $_POST['course'];
$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';
if (isset($_SESSION['user_id'])) {
define('upload', 'photo/');
} else {
define('upload', 'dashboard/photo/');
}
$success = move_uploaded_file($_FILES['image']['tmp_name'], upload . $photo);
$db->query("UPDATE user SET country='$country', 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' ");
$id = $this->userName3($username);
$this->courseOrder2($id, $course); //submit required course
$report = 'User Registration Information Successfully Updated!';
$count = 0;
$_SESSION['signup'] = 6;
return;
}
function courseOrder2($userkey, $course)
{
global $db;
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$sql = $db->query("INSERT INTO download (id,course,tno) VALUES ('$userkey','$course','$tno')");
return;
}
function resetPassOrder()
{
global $db;
$order = isset($_GET['request-index']) ? $_GET['request-index'] : '';
$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, $reset;
$pwd1 = md5($_POST['password']);
$pwd2 = md5($_POST['password2']);
$reset_order = $this->win_hash(41);
$code = $this->resetPassOrder() ? $_GET['request-index'] : 0;
if ($pwd1 == $pwd2) {
$db->query("UPDATE user SET pass='$pwd1', code='$reset_order' WHERE code = '$code' ");
$report = 'User Password Successfully Changed! You can now login to your account';
//header('location: ./login.php');
$reset = 2;
} else {
$report = 'New Password Mismatch, Try Again';
$count = 1;
}
return;
}
function Alert()
{
global $report, $count;
if ($count > 0) {
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">×</button>
<i class="icon fa fa-ban"></i> <b>' . $report . ' </b>
</div>';
} else {
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">×</button>
<i class="icon fa fa-check"></i> <b>' . $report . '</b>
</div>';
}
//if(isset($report)){ unset($_SESSION['report']); }
return;
}
function emailerAll($email, $message, $subject)
{
global $firstname;
$headers = 'From: Covis Club International <admin@covisclubinternational.com>' . "\r\n";
$headers .= 'Reply-To: admin@covisclubinternational.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)
{
$headers = 'From: COVIS CLUB International <admin@covisclubinternational.com>' . "\r\n";
$headers .= 'Reply-To: admin@covisclubinternational.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 International';
$mailmessage = "<p>Welcome " . ucwords($_SESSION['username']) . '<br>Congratulation! You have successfully signed up with COVIS CLUB International. <br>COVIS CLUB International (CCI) is a community of Entrepreneurs, inspired and motivated enough to create wealth for themselves and to help others achieve same. As Member of Covis Club, you will have access to our Digital Library where you can download unlimited information products, contained in Different Topics and Categories..</p>
<p>
We are a group of Entrepreneurs and internet oriented people of like minds who believe that anyone can have and build a successful business online and offline. So as a group, we help each other to become successful by bringing our resources and ideas together. So far it has been awesome, producing outstanding results.. </p>
<p> <br>
Login to your account using your username and password at <br>
https://covisclubinternational.com/login.php
<br><br> </p>';
$send = mail($email, $subject, $mailmessage, $headers);
return;
}
function replyMsg()
{
global $db, $report, $count;
$mid = $_GET['reply'];
$reply = addslashes($_POST['replyMsg']);
if (strlen($reply) > 5) {
$msg = $db->query("INSERT INTO replymsg (mid,reply) VALUES('$mid','$reply')") or die(mysqli_error());
$report = 'Reply sent successfully';
} else {
$report = 'Message too short';
$count = 1;
}
return;
}
function verifyUser()
{
global $db, $report, $count;
$username = $_POST['user'];
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") or die(mysqli_error());
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_assoc($sql);
$_SESSION['recKey'] = $row['id'];
$report = 'Beneficiary successfully verified';
} else {
$report = 'Invalid Beneficiary, try again';
$count = 1;
}
return;
}
function SendUserMessage()
{
global $report;
$rec = $_POST['SendUserMessage'];
$message = addslashes($_POST['msg']);
$subject = addslashes($_POST['subject']);
$this->message($rec, 'Admin', $message, $subject);
$report = 'Your message was successfully sent';
return;
}
function SearchDownline()
{
global $db, $report, $count;
$randomKey = $this->userName('sn');
$username = $_POST['u-ref'];
$a = 1;
$nu = 0;
while ($a <= 16) {
$b = $a++;
$gen = 'a' . $b;
$qu = $db->query("SELECT * FROM user WHERE $gen = '$randomKey' AND user = '$username' ") or die(mysqli_error());
$nu += mysqli_num_rows($qu);
}
if ($nu > 0) {
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$uref = sha1($row['sn']);
header("location: generations.php?u-ref=$uref");
} else {
$report = 'Error! search could find the user in your team. confirm and try again';
$count = 1;
}
return;
}
//*
function LoginUsers()
{
global $db, $report, $count;
$username = strtolower(sanitize($_POST['username']));
$username = str_replace(' ', '', $username);
$password = $_POST['password'];
$sql = $db->query("SELECT * FROM user WHERE user='$username' ");
if (mysqli_num_rows($sql) == 1) {
$row = mysqli_fetch_array($sql);
$status = $row['status'];
if (password_verify($password, $row['pass'])) {
if ($status == 1) {
$_SESSION['user_id'] = $row['id'];
header('location: .');
} else {
$report = 'Your user account has been deactivated, contact the system administrator ';
$count = 1;
}
} else {
$report = 'Invalid Login details, Try again';
$count = 1;
}
} else {
$report = 'Invalid Login details, Try again.';
$count = 1;
}
return;
}
//*
function EnProfile()
{
$_SESSION['user_id'] = $_POST['EnProfile'];
//header('location: profile/');
return;
}
function validLayer()
{
if (strlen($this->layerKey()) != 32) {
unset($_SESSION['user_id']);
} else {
}
return;
}
function updateUser()
{
global $db, $report, $userKey;
$state = sanitize($_POST['state']);
$city = sanitize($_POST['city']);
$address = addslashes(sanitize($_POST['address']));
$phone = sanitize($_POST['phone']);
$bank = sanitize($_POST['bank']);
$accountno = sanitize($_POST['accountno']);
$db->query("UPDATE user SET state='$state', city='$city', phone='$phone', address='$address', bank='$bank', accountno='$accountno' WHERE id = '$userKey' ");
$report = 'User Information Successfully Updated!';
return;
}
function SuspendAccount()
{
global $db, $report;
$id = $_POST['SuspendAccount'];
$db->query("UPDATE user SET status=0 WHERE id = '$id' ");
$report = 'User Account Successfully Suspended!';
return;
}
function UnSuspendAccount()
{
global $db, $report;
$id = $_POST['UnSuspendAccount'];
$db->query("UPDATE user SET status=1 WHERE id = '$id' ");
$report = 'User Account Successfully Restored!';
return;
}
function RestorePin()
{
global $db, $report;
$pin = $_POST['RestorePin'];
$db->query("UPDATE pin SET status=0, id='' WHERE pin = '$pin' ");
$report = 'PIN Successfully Restored!';
return;
}
function DeactivateUser()
{
global $db, $report;
$userKey = $_POST['DeactivateUser'];
$status = ($this->uName($userKey, 'status') == 1) ? 0 : 1;
$act = ($status == 0) ? 'Deactivated!' : 'Activated!';
$db->query("UPDATE user SET status='$status' WHERE id = '$userKey' ");
$report = $this->uName($userKey) . ' has been successfully ' . $act;
return;
}
function UpdatePin()
{
global $db, $report, $count;
$userKey = $_POST['UpdatePin'];
$pin = $_POST['pin'];
$user = $this->uName($userKey);
if ($this->pinValidity($pin) == TRUE) {
$db->query("UPDATE user SET pin='$pin' WHERE id = '$userKey' ");
$db->query("UPDATE pin SET status=1, id='$user' WHERE pin = '$pin' ");
$report = $this->uName($userKey) . ' has been successfully activated';
} else {
$this->pinValidity($pin);
}
return;
}
function CourseUpload()
{
global $db, $report, $count;
$title = sanitize($_POST['title']);
$doc = str_replace(" ", "-", $_FILES['doc']['name']);
define('upload', 'train/');
if (isset($title) AND isset($doc) AND strlen($doc) > 5 AND strlen($title) > 5) {
$success = move_uploaded_file($_FILES['doc']['tmp_name'], upload . $doc);
$sqlw = $db->query("INSERT INTO course (title,file) VALUES ('$title','$doc') ");
$report = 'Course Material Successfully Uploaded!';
} else {
$report = 'You have entered an incomplete information';
$count = 1;
}
return;
}
function pinMultiple($username)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$pin = $row['pin'];
$sq = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
return mysqli_num_rows($sq);
}
function pinMultiple2($username)
{
global $db;
$list = '';
$a = 1;
$sql = $db->query("SELECT * FROM user WHERE user = '$username' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$pin = $row['pin'];
$sq = $db->query("SELECT * FROM user WHERE pin = '$pin' ") or die(mysqli_error());
while ($ro = mysqli_fetch_assoc($sq)) {
$b = $a++;
$list .= '<p>' . $b . '. ' . $ro['pin'] . ' ' . $ro['user'] . '</p>';
}
return $list;
}
function updateUser2()
{
global $db, $report;
$keys = $_GET['u-ref'];
$state = sanitize($_POST['state']);
$email = sanitize($_POST['email']);
$lastname = sanitize($_POST['lastname']);
$city = sanitize($_POST['city']);
$address = addslashes(sanitize($_POST['address']));
$phone = sanitize($_POST['phone']);
$bank = sanitize($_POST['bank']);
$accountno = sanitize($_POST['accountno']);
$db->query("UPDATE user SET lastname='$lastname', state='$state', city='$city', phone='$phone', address='$address', bank='$bank', email='$email', accountno='$accountno' WHERE sha1(sn) = '$keys' ");
$report = 'User Information Successfully Updated!';
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 updatePhoto2()
{
global $db, $report;
$keys = $_GET['u-ref'];
$name = 'a' . date('ymdhis') . $_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 sha1(sn) = '$keys' ");
$report = 'User Profile Photo Successfully Update!';
return;
}
function SearchUserMessage(){
global $db,$report,$count;
$user = sanitize($_POST['username']);
$sql = $db->query("SELECT * FROM user WHERE user='$user'");
if($sql->num_rows < 1){$report = "Username Does Not Exists"; $count = 1;}
else{
$row = $sql->fetch_assoc();
header("Location:?ugh=".$row['id']);
}
}
function MessageSubmit()
{
global $db, $report, $count;
$id = $this->Uid();
$message = sanitize($_POST['message']);
$time = time();
$sql = $db->query("INSERT INTO msg(msg,senderid,receiverid,ctime) VALUES('$message','$id',1,'$time') ");
$report = "Message Sent Successfully";
}
function chkLogin()
{
if(!isset($_SESSION['user_id'])){
header('location: login.php');
exit;
}
return;
}
function LogoutUser()
{
// $_SESSION['user_id'] == '';
session_destroy();
header('location: login.php');
return;
}
function DeleteMessage($sn)
{
global $db, $report, $count;
$db->query("DELETE FROM msg WHERE sn='$sn'");
$report = "Deleted Successfully";
$count = 1;
}
function DeleteDonation()
{
global $db, $report, $count;
$ref = $_POST['DeleteDonation'];
$sql = $db->query("SELECT * FROM donate WHERE dsn='$ref' ");
if(mysqli_num_rows($sql)==0){
$db->query("DELETE FROM donation WHERE tno='$ref'");
$report = "Donation Deleted Successfully";
}else{
$report='You cannot delete this donation. It contains record of payments'; $count=1;
}
return;
}
function ReplyMessage($id, $sn)
{
global $db, $report;
$message = sanitize($_POST['reply']);
$time = time();
$db->query("INSERT INTO msg(msg,senderid,receiverid,reply,ctime) VALUES('$message','','$id','$sn','$time')");
$report = "Sent";
}
function MessageAdminSubmit()
{
global $db, $report, $count;
$id = $_POST['id'];
$message = sanitize($_POST['message']);
$time = time();
$sql = $db->query("INSERT INTO msg(msg,senderid,receiverid,ctime) VALUES('$message',1,'$id','$time') ");
$report = "Message Sent Successfully";
}
function ChangeUserPassword()
{
global $db, $report, $count;
$id = $this->Uid();
$pass = userName($id, 'pass');
$password = sanitize($_POST['pwd']);
$new_pass = sanitize($_POST['newpwd']);
$retype = sanitize($_POST['retype']);
if ($new_pass != $retype) {
$report = "Confirm Password Must Be the Same With New Password";
$count = 1;
}
elseif (!password_verify($password, $pass)) {
$report = "Wrong Password";
$count = 1;
} elseif (strlen($new_pass) <= 3) {
$report = "Sorry Password Must Be More Than 3 Characters";
$count = 1;
} else {
$original = bcrypt($new_pass);
$sql = $db->query("UPDATE user SET pass='$original' WHERE id='$id'");
$report = "Password Changed Successfully";
}
}
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;
}
function changePassword2()
{
global $db, $report, $count;
$keys = $_GET['u-ref'];
$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 sha1(sn) = '$keys' ");
$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
//Total Downlines
function Downlines()
{
global $db, $userKey;
$randomKey = $this->userName('sn');
$a = 1;
$nu = 0;
while ($a <= 16) {
$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;
$randomKey = $this->userName('sn');
$qu = $db->query("select * FROM user WHERE sponsor = '$randomKey' ") or die(mysqli_error());
$nu = mysqli_num_rows($qu);
return $nu;
}
function userSponsored($key)
{
global $db;
$qu = $db->query("select * FROM user WHERE sponsor = '$key' ") 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;
$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 wildGen($key, $e)
{
global $db;
$gen = 'a' . $e;
$q = $db->query("SELECT * FROM user WHERE $gen ='$key' ") or die(mysqli_error());
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 <= 16) {
$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;
}
}
function findLevel($key)
{
global $db;
$a = 1;
$level = 1;
while ($a <= 16) {
$b = $a++;
$nu = 0;
$gen = 'a' . $b;
$target = MATRIX ** $b;
$qu = $db->query("SELECT * FROM user WHERE $gen = '$key' ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
if ($this->wildSponsored($row['sn']) > 1) {
$nu += 1;
}
if ($nu == $target) {
if ($this->wildSponsored($key) > 1) {
$level = $b + 1;
} else {
$level = $b + 1;
}
}
}
}
if ($this->wildSponsored($key) < 2) {
$level = 0;
}
return $level;
}
//
function level1($key)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE a1='$key' ") or die(mysqli_error());
$head = $sql->num_rows;
if ($head == 3) {
return 1;
} else {
return 0;
}
}
function active($key)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE a1='$key' ") or die(mysqli_error());
$head = $sql->num_rows;
$team = ($head > 2) ? 3 : $head;
return $team;
}
function stageLevel($key)
{
$stlevel = 0;
$level = $this->userLevel($key);
if ($level == 1) {
$stlevel = 1;
} elseif ($level == 2) {
$stlevel = 0;
} elseif ($level == 3) {
$stlevel = 1;
} elseif ($level == 4) {
$stlevel = 2;
} elseif ($level == 5) {
$stlevel = 0;
} elseif ($level == 6) {
$stlevel = 1;
} elseif ($level == 7) {
$stlevel = 2;
} elseif ($level == 8) {
$stlevel = 0;
} elseif ($level == 9) {
$stlevel = 1;
} elseif ($level == 10) {
$stlevel = 2;
} elseif ($level == 11) {
$stlevel = 0;
}
elseif ($level == 12) {
$stlevel = 1;
}
elseif ($level == 13) {
$stlevel = 2;
}
elseif ($level == 14) {
$stlevel = 0;
}
elseif ($level == 15) {
$stlevel = 1;
}
elseif ($level == 16) {
$stlevel = 2;
}
elseif ($level == 17) {
$stlevel = 0;
}
return $stlevel;
}
function ApproveIncentive1(){
global $db,$report,$count;
$sn = $_POST['ApproveIncentive1'];
$db->query("UPDATE incentive SET status='1' WHERE sn='$sn'");
$report = "Approved Successfully";
}
function DeleteRequest(){
global $db,$report,$count;
$sn = $_POST['DeleteRequest'];
$db->query("DELETE FROM incentive WHERE sn='$sn'");
$report = "Delete Successfully";
}
function ReturnWithdraw(){
global $db,$report,$count;
$id = $_POST['ReturnWithdraw'];
$transaction = $_POST['transaction'];
$sql = $db->query("DELETE FROM withdraw WHERE id='$id' AND type='w' AND tno='$transaction'");
$report = "Returned Successfully";
}
function ApproveWithdraw(){
global $db,$report,$count;
$sn = $_POST['ApproveWithdraw'];
$db->query("UPDATE withdraw SET status='1' WHERE sn='$sn'");
$report = "Approved Successfully";
}
function RequestIncentive1(){
global $db,$report,$count;
$id = $_POST['id'];
$stage = $_POST['stage'];
$level = $_POST['level'];
$incentive = sanitize($_POST['RequestIncentive1']);
if($db->query("INSERT INTO incentive(id,incentive,stage,level) VALUES('$id','$incentive','$stage','$level')")){
$report = "Request Submitted Successfully";
}
else {
$count = 1;
$report = "Error Submitting Request";
}
}
function PromoIncent(){
global $db,$report;
$val = explode('-',$_POST['PromoIncent']);
$id = $val[0]; $item = $val[1];
$sql1 = $db->query("SELECT * FROM levels WHERE promo<='$item' AND promo != 0 ");
while($row = $sql1->fetch_assoc()){
$incentive=strtoupper($row['award2']); $stage = $row['stg']; $level = $row['level'];
$db->query("INSERT INTO incentive(id,incentive,stage,level,promo) VALUES('$id','$incentive','$stage','$level',1)");
}
$report = "Request Submitted Successfully";
return;
}
function ForgertPassword(){
global $db, $report, $count;
$username = sanitize($_POST['username']);
$email = sanitize($_POST['email']);
// $phone = sanitize($_POST['phone']);
$sql = $db->query("SELECT * FROM user WHERE user='$username' AND email='$email'");
if($sql->num_rows < 1){
$count = 1;
$report = "Sorry Username or Email does not exist";
}
else {
$password = substr(str_shuffle(str_repeat('123456789abcdefghijk', 6)), 0, 6);
$pass = password_hash($password, PASSWORD_BCRYPT);
$sql1 = $db->query("UPDATE user SET pass='$pass' WHERE user='$username' AND email='$email'");
$subject= 'Password Changed';
$message = '<p>Password Changed Succesfully<br> Your New Password is: '.$password.'.<br> Please, change this password as soon as you login';
$this->emailerAll($email, $message, $subject);
$report = "Password Request Successful, Check Your Mail for the new password ";
}
}
function RequestTransfer(){
global $db, $report, $count;
$uid = $_POST['id'];
$uidx = $this->idToKey($uid);
$username = sanitize($_POST['recipient']);
$uid2 = $this->userName3($username);
$amount = sanitize($_POST['amount']);
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
// $initBalance = $_POST['balance'];
$stage = $this->stageCalc($uidx);
$lev = $this->stageLevel($uidx);
$initBalance = $this->totalEarnings($uidx);
$type = "t";
$status = 1;
$sql1 = $db->query("SELECT * FROM user WHERE user='$username'");
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif(userName($uid,'user') == $username){
$report = "Cannot Transfer To The Same Account, Please Check Username And Try Again";
$count = 1;
}
elseif($sql1->num_rows < 1){
$count = 1;
$report = "Username Does Not Exist";
}
elseif($_POST['amount'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 10000){
$count = 1;
$report = "Cannot Transfer More than $10,000";
}
elseif(password_verify($pass, $password)){
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $initBalance - $amount;
$sql = $db->query("INSERT INTO transfer (id,id2,inibalance,amount,finalbalance,status,type,tno) VALUES ('$uid','$uid2','$initBalance','$amount','$finalbalance','$status','$type','$tno')");
$_SESSION['report'] = "$".$amount. " Transfered Successfully To ".$username;
header("Location:?#");
}
else {
$report = "Invalid authentication";
$count = 1;
}
}
function FundCycler(){
global $db, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$amount = sanitize($_POST['amount']);
$initBalance = $this->totalEarnings($uidx);
$type = "tc";
$status = 1;
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['amount'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 1000){
$count = 1;
$report = "Cannot Transfer More than $1,000";
}
else{
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$db->query("INSERT INTO transfer (id,amount,status,type,tno,remark) VALUES ('$uid','$amount','$status','tc','$tno','Transfer to Cycler Wallet')");
$db->query("INSERT INTO cpay (id,amount,cycle,type) VALUES ('$uid','$amount','0','1')");
$report = "$".$amount. " Successfully Funded ";
}
return;
}
function FundFromCycler(){
global $db, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$amount = sanitize($_POST['amount']);
$initBalance = colSum1('cpay','amount','id',$uid);
$type = "tc";
$status = 1;
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['amount'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 1000){
$count = 1;
$report = "Cannot Transfer More than $1,000";
}
else{
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$db->query("INSERT INTO transfer (id2,amount,status,type,tno,remark) VALUES ('$uid','$amount','$status','tc','$tno','Received from Cycler Wallet')");
$amount = '-'.$amount;
$db->query("INSERT INTO cpay (id,amount,cycle,type) VALUES ('$uid','$amount','0','4')");
$report = "$".abs($amount). " Successfully Withdrawn to CCI Wallet ";
}
return;
}
function TransferToCovisEconomy(){
global $db,$db2, $report, $count;
$uid = $_POST['id'];
$uidx = $this->idToKey($uid);
// $username = sanitize($_POST['recipient']);
$uid2 = '';//$this->userName3($username);
$amount = sanitize($_POST['amount']);
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
// $initBalance = $_POST['balance'];
$stage = $this->stageCalc($uidx);
$lev = $this->stageLevel($uidx);
$initBalance = $this->totalEarnings($uidx);
$type = "t";
$status = 1;
$sql = $db2->query("SELECT * FROM users WHERE id = '$uid'");
if($sql->num_rows < 1) {
$report = "OOPs!!! You don not have an account in Covis Economy";
}
elseif($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['amount'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 10000){
$count = 1;
$report = "Cannot Transfer More than $10,000";
}
elseif(password_verify($pass, $password)){
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $initBalance - $amount;
$sql = $db->query("INSERT INTO transfer (id,id2,inibalance,amount,finalbalance,status,type,tno) VALUES ('$uid','$uid2','$initBalance','$amount','$finalbalance','$status','$type','$tno')");
$remark = 'Transfered from CCI';
$ctime = time();
$db2->query("INSERT INTO wallet (id,cos,status,type,remark,ctime) VALUES ('$uid','$amount',10,21,'$remark','$ctime')");
$_SESSION['report'] = "$".$amount. " Transfered Successfully To Your CovisEconomy Account";
header("Location:?#");
}
else {
$report = "Invalid authentication";
$count = 1;
}
}
function CreateContribution() {
global $db, $report, $count;
$title = sanitize($_POST['title']);
$amount = sanitize($_POST['amount']);
$participant = sanitize($_POST['participant']);
// $start = strtotime($_POST['start']);
// $end = strtotime($_POST['end']);
$id = $_POST['id'];
$shared = $_POST['shared'] ?? 1;
$period = $participant / $shared;
// $end = strtotime('+'.$period.'months',$start);
$customId = $this->win_hashs(5);
if($participant < 5 || $participant > 12){
$report = "Participant cannot be less than 5 or more than 12";
$count = 1;
return ;
}
if(!checkCovisEconomy($id)){
$report = "Oops!!!, Only Available for Covis Economy Users";
$count = 1;
return;
}
$sql = $db->query("INSERT INTO contributions(id, title, amount, participant, user_id, shared, period)
VALUES('$customId','$title', '$amount', '$participant', '$id', '$shared', '$period')");
if($sql){
$db->query("INSERT INTO contributionparticipants(user_id, savings_id, status)
VALUES('$id', '$customId', 1)");
$_SESSION['report'] = $report = 'Savings Contribution Created Successfully';
header("Location: ?");
} else {
$count = 1;
$report = 'Error Creating ';
return;
}
// $report = 'Date: '. $_POST['start'];
//
// $res = file_get_contents('https://www.locklizard-evals.com/enterprise5/Interop.php?un=EstherSamuelFountain&pw=vGy274bPfg5kmK30&action=add_customer&name=Esther%20Sam&email=samuelesther435@gmail.com&start_date=05-26-2021&end_type=unlimited&licenses=1');
//
// $response = substr($res, 0, 2);
// if($response == 'OK'){
// $id = substr($res, 4, 5); // Gets the ID for you
// if(is_numeric($id)) // New Registration occurred
// // Perform your operation here
// $report = 'Code: '.$id.' response: '.$response;
// else
// $report = 'response: '.$response. ' Code: '.$id;
// }
}
function UpdateContribution() {
global $db, $report, $count;
$sn = $_POST['UpdateContribution'];
$title = sanitize($_POST['title']);
$amount = sanitize($_POST['amount']);
$participant = sanitize($_POST['participant']);
// $start = strtotime($_POST['start']);
$id = $_POST['id'];
$shared = $_POST['shared'] ?? 1;
if($participant < 5 || $participant > 12){
$report = "Participant cannot be less than 5 or more than 12";
$count = 1;
return ;
}
$period = $participant / $shared;
// $end = strtotime('+'.$period.'months',$start);
$customId = $this->win_hashs(5);
$sql =
$db->query("UPDATE contributions SET title='$title',
amount='$amount', participant='$participant', period='$period', shared='$shared' WHERE sn = '$sn' AND user_id='$id'");
if($sql){
$_SESSION['report'] = $report = 'Savings Contribution Updated Successfully';
header("Location: ?");
} else {
$count = 1;
$report = 'Error Updating ';
return;
}
}
function shareContributionMoney($uid){
global $db, $report, $count;
$sql1 = $db->query("SELECT * FROM contributionparticipants WHERE user_id = '$uid'");
if($sql1->num_rows > 0){
$time = time();
$sql = $db->query("SELECT * FROM contributions WHERE start <= '$time' AND stop >= '$time'");
while($row = $sql->fetch_object()){
$month = floor(($time - $row->start) / 2592000);
$totalPaid = checkParticipant($row->id, 1) / $row->shared;
$j = $totalPaid + 1;
$totalParticipant = checkParticipant($row->id);
if($totalParticipant != $row->participant){
continue;
}
for ($i = $j; $i <= $month; $i++){
$sql2 = $db->query("SELECT * FROM contributedmoney WHERE month = '$i' AND savings_id = '$row->id'");
if($sql2->num_rows == $totalParticipant){
$totalShare = totalShare($row->id, $i);
$this->payShare($row->id, $row->shared , $totalShare);
} else {
break;
}
}
}
}
}
function payShare($savings, $total, $totalShare) {
global $db;
$amount = $totalShare / $total;
$title = getContributionField($savings);
$sql = $db->query("SELECT * FROM contributionparticipants WHERE savings_id = '$savings' AND paid = 0 LIMIT `$total`");
// die($totalShare);
while($row = $sql->fetch_object()){
$db->query("UPDATE contributionparticipants SET paid = 1 WHERE savings_id = '$row->savings_id' AND user_id = '$row->user_id'");
$tno = $this->win_hash(10);
$db->query("INSERT INTO transfer (id,id2,inibalance,amount,finalbalance,status,type,tno) VALUES ('','$row->user_id','','$amount','', 1,'Ajo','$tno')");
// $this->processWallet($row->user_id, $amount, 5, 31, $title. 'Contribution Share Received', '');
}
}
function PayContribution(){
global $db, $report, $count;
$amount = $_POST['amountM'];
$savings_id = $_POST['savingsM'];
$month = $_POST['monthM'];
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
// $balance = $this->wallet($uid);
$balance = $this->totalEarnings($uidx);
if($amount <= $balance){
// $this->processWallet($uid, $amount, 5,4, 'Contribution Deductions for Month '.$month, '');
$this->withdrawProcess($amount, $balance, 'Ajo', 1);
$db->query("INSERT INTO contributedmoney(user_id, savings_id, amount, month)
VALUES('$uid', '$savings_id', '$amount', '$month')");
$_SESSION['report'] = $report = 'Payment Made Successfully';
header("Location: ?");
} else {
$count = 1;
$report = "Insufficient Balance, Please Fund your wallet";
}
}
function DeleteContribution(){
global $db, $report, $count;
$id = $_POST['DeleteContribution'];
$activeParticioant = activeParticipant($id);
if($activeParticioant > 1){
$report = "Unable to delete Plan";
$count = 1;
return ;
}
$db->query("DELETE FROM contributions WHERE id = '$id'");
$db->query("DELETE FROM contributionparticipants WHERE savings_id = '$id'");
$_SESSION['report'] = $report = "Deleted Successfully";
header("LOCation: ?");
}
function StartContributionTime(){
global $report, $count, $db;
$id = $_POST['StartContributionTime'];
$start = time();
$period = getContributionField($id, 'period');
$activeParticipant = activeParticipant($id);
$maxParticipant = getContributionField($id, 'participant');
if($activeParticipant != $maxParticipant){
$report = "Make sure Active Participants is the same as the Max Participants of "
. $maxParticipant;
$count = 1;
return;
}
$end = strtotime('+'.$period.'months',$start);
$db->query("UPDATE contributions SET start = '$start', stop = '$end' WHERE id = '$id'");
$report = "Started Successfully, Enjoy the ";
}
function ApproveMySavingsPlan(){
global $db, $report, $count;
$sn = $_POST['ApproveMySavingsPlan'];
$sql = $db->query("UPDATE contributionparticipants SET status = 1 WHERE sn = '$sn'");
if($sql){
$_SESSION['report'] = $report = "Approved Successfully";
header("Location: ?");
} else {
$count = 1;
$report = "Error Occurred";
}
}
function JoinSavingContribution(){
global $db, $report, $count;
$savings = $_POST['JoinSavingContribution'];
$uid = $this->Uid();
$activeParticipants = activeParticipant($savings);
$maxParticipants = getContributionField($savings, 'participant');
if($activeParticipants == $maxParticipants){
$report = "Oops!!!, Unable to Join, No of participants exceeded";
$count = 1;
return;
}
if(!checkCovisEconomy($uid)){
$report = "Oops!!!, Only Available for Covis Economy Users";
$count = 1;
return;
}
$sql = $db->query("INSERT INTO contributionparticipants(user_id, savings_id) VALUES('$uid', '$savings')");
if($sql) {
$_SESSION['report'] = $report = "Successfully Joined " . getContributionField($savings) . " Contribution Plan";
header("Location: ?");
}
else{
$count = 1;
$report = "An Error Occurred";
}
}
function DeclineMySavingsPlan(){
global $db, $report, $count;
$sn = $_POST['DeclineMySavingsPlan'];
$sql = $db->query("DELETE FROM contributionparticipants WHERE sn = '$sn'");
if($sql){
$_SESSION['report'] = $report = "Declined Successfully";
header("Location: ?");
} else {
$count = 1;
$report = "An Error Occurred";
}
}
function CreditWallet(){
global $db, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$username = sanitize($_POST['recipient']);
$des = sanitize($_POST['des']);
$uid2 = $this->userName3($username);
$amount = sanitize($_POST['amount']);
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
// $initBalance = $_POST['balance'];
$stage = $this->stageCalc($uidx);
$lev = $this->stageLevel($uidx);
$initBalance = $this->totalEarnings($uidx);
$type = "cw";
$status = 1;
$sql1 = $db->query("SELECT * FROM user WHERE user='$username'");
if(userName($uid,'user') == $username){
$report = "Cannot Transfer To The Same Account, Please Check Username And Try Again";
$count = 1;
}
elseif($sql1->num_rows < 1){
$count = 1;
$report = "Username Does Not Exist";
}
elseif($_POST['amount'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 3000){
$count = 1;
$report = "Cannot Transfer More than $3,000";
}
elseif(password_verify($pass, $password)){
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $initBalance - $amount;
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('$uid','$uid2','$amount','$status','$type','$tno','$des')");
$report = "$".$amount. " Transfered Successfully To ".$username;
// header("Location:?#");
}
else {
$report = "Invalid authentication";
$count = 1;
}
return;
}
function DeductWallet(){
global $db, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$username = sanitize($_POST['recipient']);
$des = sanitize($_POST['des']);
$uid2 = $this->userName3($username);
$amount = '-'.$_POST['amount'];
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
// $initBalance = $_POST['balance'];
$stage = $this->stageCalc($uidx);
$lev = $this->stageLevel($uidx);
$initBalance = $this->totalEarnings($uidx);
$type = "cw";
$status = 1;
$sql1 = $db->query("SELECT * FROM user WHERE user='$username'");
if(userName($uid,'user') == $username){
$report = "Cannot Deduct from Same Account, Please Check Username And Try Again";
$count = 1;
}
elseif($sql1->num_rows < 1){
$count = 1;
$report = "Username Does Not Exist";
}
elseif(password_verify($pass, $password)){
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $initBalance - $amount;
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno,remark) VALUES ('$uid','$uid2','$amount','$status','$type','$tno','$des')");
$report = "$".abs($amount). " Deducted Successfully To ".$username;
// header("Location:?#");
}
else {
$report = "Invalid authentication";
$count = 1;
}
return;
}
function RequestWithdraw(){
global $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$amount = $_POST['withdraw']+$this->charge;
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
//$initBalance = $_POST['balance'];
$stage = $this->stageCalc($uidx);
$lev = $this->stageLevel($uidx);
$initBalance = $this->totalEarnings($uidx);
$type = "w";
$status = 0;
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['withdraw'] < 10){
$count = 1;
$report = "Minimum Withdrawal is $10";
}
elseif(userName($uid,'accountno')==''){
$count = 1;
$report = "Please Update Your Bank Account Details";
}
elseif($amount > 10000){
$count = 1;
$report = "Cannot Withdraw More than $10000";
}
elseif($this->checkTestimony($uid)==FALSE){
$count = 1;
$report = "You need to submit a testimony of previous withdrawal before you can make the next one";
}
elseif(password_verify($pass, $password)){
$this->withdrawProcess($amount,$initBalance, $type, $status);
header("Location:?");
$_SESSION['report'] = "Withdraw Request Successfully Submitted";
}
elseif($_POST['authenticate'] == '' || $_POST['withdrawals']== ''){
$report = "Invalid authentication";
$count = 1;
}
else {
$report = "Please Withdrawal field and Authentication field are required";
$count = 1;
}
}
function SavingsDeposit(){
global $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$amount = $_POST['withdraw'];
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
//$initBalance = $_POST['balance'];
//$stage = $this->stageCalc($uidx);
//$lev = $this->stageLevel($uidx);
$initBalance = $this->totalEarnings($uidx);
$type = "s";
$status = 1;
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['withdraw'] < 1){
$count = 1;
$report = "Minimum Withdrawal is $1";
}
elseif(userName($uid,'accountno')==''){
$count = 1;
$report = "Please Update Your Bank Account Details";
}
elseif($amount > 10000){
$count = 1;
$report = "Cannot Withdraw More than $10000";
}
elseif(password_verify($pass, $password)){
$this->withdrawProcess($amount,$initBalance, $type, $status);
$this->savingsProcess($amount,$initBalance, $type, $status);
//header("Location:?");
$report = "Savings Deposit Successfully Submitted";
}
elseif($_POST['authenticate'] == '' || $_POST['withdrawals']== ''){
$report = "Invalid authentication";
$count = 1;
}
else {
$report = "Please Withdrawal field and Authentication field are required";
$count = 1;
}
}
function WithdrawMySavings(){
global $db, $report, $count;
$uid = $this->Uid();
$amount = $this->savingsTotal($uid)+$this->savingsTotal($uid,2);
$type = 'sw';
//header("Location:?");
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$sql = $db->query("INSERT INTO transfer (id,id2,amount,status,type,tno) VALUES ('admin','$uid','$amount',1,'$type','$tno')");
$db->query("UPDATE savings SET status=3 WHERE id='$uid' AND status=1 ");
$report = "Your savings have been Successfully withdrawn into your wallet. You can place cash withdrawal from there";
return;
}
function savingsTotal($uid,$opt=''){
global $db;
$sql = $db->query("SELECT * FROM savings WHERE id='$uid' AND status=1 ");
$sum = 0; $int=0;
while($row = $sql->fetch_assoc()){
$sum += $row['amount'];
$int += $row['amount']*0.02*age($row['ctime']);
}
$res = $opt=='' ? $sum : $int;
return $res;
}
function LoanApplication(){
global $db, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$amount = $_POST['amount'];
$duration = $_POST['duration'];
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
$potential = $this->loanPotential($uid);
if($duration==30){$mt=1;}elseif($duration==60){$mt=2;}elseif($duration==90){$mt=3;}
$interest = $amount*$mt*0.07; // 7% interest rate
$type = "la";
$status = 0;
if($amount > $potential){
$report = "You cannot access more than your loan potential";
$count = 1;
}
elseif(userName($uid,'accountno')==''){
$count = 1;
$report = "Please Update Your Bank Account Details";
}
elseif(password_verify($pass, $password)){
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$ctime = time();
$sql = $db->query("INSERT INTO myloan (id,amount,interest,duration,status,type,tno) VALUES ('$uid','$amount','$interest','$duration','$status','$type','$tno')");
$report = "Loan Application Request Successfully Submitted";
}
elseif($_POST['authenticate'] == '' || $_POST['amount']== ''){
$report = "Please Amount field and Authentication field are required";
$count = 1;
}
else {
$report = "Invalid authentication";
$count = 1;
}
}
function CardApprove(){
global $db, $report, $count;
$id = $_POST['user'];
$uidx = $this->idToKey($id);
$bal= $this->totalEarnings($uidx);
$status = 1;
$sql = $db->query("UPDATE c_request SET status='$status' WHERE id='$id'");
$report = "Processed Successfully";
return;
}
function CardApplication()
{
global $db, $report, $count;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$id = $_SESSION['user_id'];
$bal= $this->totalEarnings($uidx);
$user = $_POST['user'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$bvn = $_POST['bvn'];
$status = 0;
$expire=1606330373;//time()+30*60*60*24;
if(time() > $expire){
$amount=12;
}
else{
$amount=12;
}
if (strlen($_POST['bvn']) != 11){
$report = 'invalid bvn'; $count=1;
}
else{
if($bal>=$amount){
$type = "Card Withdrawal";
$this->withdrawProcess($amount, $bal, $type, $status);
$sql = $db->query("INSERT INTO c_request (id, firstname,lastname,phone,email,bvn,status) VALUES ('$id','$firstname','$lastname','$phone','$email','$bvn','$status')");
$report = 'Request Information Successfully ! '.$amt.'';}
else{
$report = 'Insufficient Fund '.$amt.'';
$count = 1;
}
}
return;
}
function Stat($status)
{
if($status==1){$r='<span class="text-primary">Completed</span>'; }
elseif($status==2){$r='<span class="text-success">Approved</span>'; }
elseif($status==3){$r='<span class="text-warning">Ready for Delivery</span>'; }
elseif($status==4){$r='<span class="text-success">Delivered</span>'; }
else{$r='<span class="text-danger">Pending</span>';}
return $r;
}
function GmRequestTransfer(){
global $report, $count;
$user = $_POST['recipient'];
if($this->userExist($user) == TRUE){
$id2 = $this->userToKey($user,'id');
$uid = $_POST['reci'];
$uidy = $this->linkGlobe($uid);
$amount = $_POST['withdraw'];//+$this->charge;
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
//$initBalance = $_POST['balance'];
$initBalance = $this->gmBalance($uidy,$uid);
$type = "gmt";
$status = 3;
if($uid==$id2){
$report = "You can not transfer funds to yourself";
$count = 1;
}
elseif($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['withdraw'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 1000){
$count = 1;
$report = "Cannot Transfer More than $1000";
}
elseif(password_verify($pass, $password)){
$this->withdrawProcessGm($amount,$initBalance, $type, $status,$id2);
$report = "Transfer Transaction Successfully Completed";
}
elseif($_POST['authenticate'] == '' || $_POST['withdraw']== ''){
$report = "Invalid authentication";
$count = 1;
}
else {
$report = "Please Withdrawal field and Authentication field are required";
$count = 1;
}
}else{ $report = "You have entered an invalid username. Check and try again";
$count = 1;}
return;
}
function GmRequestTransferToCci(){
global $report, $count;
// $user = $_POST['recipient'];
// if($this->userExist($user) == TRUE){
$id2 = '';//$this->userToKey($user,'id');
$uid = $_POST['reci'];
$uidy = $this->linkGlobe($uid);
$amount = $_POST['withdraw'];//+$this->charge;
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
//$initBalance = $_POST['balance'];
$initBalance = $this->gmBalance($uidy,$uid);
$type = "gmt";
$status = 3;
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['withdraw'] < 1){
$count = 1;
$report = "Minimum Transfer is $1";
}
elseif($amount > 1000){
$count = 1;
$report = "Cannot Transfer More than $1000";
}
elseif(password_verify($pass, $password)){
$this->withdrawProcessGmToCci($amount,$initBalance, $type, $status,$id2);
$report = "Transfer Transaction Successfully Completed";
}
elseif($_POST['authenticate'] == '' || $_POST['withdraw']== ''){
$report = "Invalid authentication";
$count = 1;
}
else {
$report = "Transaction not successful";
$count = 1;
}
return;
}
function GmRequestWithdraw(){
global $report, $count;
$uid = $_POST['GmRequestWithdraw'];
$uidy = $this->linkGlobe($uid);
$amount = $_POST['withdraw']+$this->charge;
$pass = $_POST['authenticate'];
$password = userName($uid,'pass');
//$initBalance = $_POST['balance'];
$initBalance = $this->gmBalance($uidy,$uid);
$type = "gmw";
$status = 0;
if($amount > $initBalance){
$report = "Insufficient Balance";
$count = 1;
}
elseif($_POST['withdraw'] < 10){
$count = 1;
$report = "Minimum Withdrawal is $10";
}
elseif(userName($uid,'accountno')==''){
$count = 1;
$report = "Please Update Your Bank Account Details";
}
elseif($amount > 10000){
$count = 1;
$report = "Cannot Withdraw More than $10000";
}
elseif(password_verify($pass, $password)){
$this->withdrawProcessGm($amount,$initBalance, $type, $status);
$report = "Withdraw Request Successfully Submitted";
}
elseif($_POST['authenticate'] == '' || $_POST['withdraw']== ''){
$report = "Invalid authentication";
$count = 1;
}
else {
$report = "Please Withdrawal field and Authentication field are required";
$count = 1;
}
return;
}
function trStatus($status)
{
if($status==0){$r='<font color="red">Awaiting Confirmarion</font>'; }
elseif($status==1){$r='<font color="blue">Transaction Processing</font>'; }
elseif($status==2){$r='<font color="brown">Ready for Delivery</font>'; }
elseif($status==3){$r='<font color="green">Transaction Complete</font>'; }
else{$r='';}
return $r;
}
function loanStatus($status)
{
if($status==0){$r='<font color="red">Awaiting Confirmarion</font>'; }
elseif($status==1){$r='<font color="blue">Transaction Processing</font>'; }
elseif($status==2){$r='<font color="brown">Ready for disbursement</font>'; }
elseif($status==3){$r='<font color="green">Loan Active</font>'; }
elseif($status==4){$r='<font color="green">Loan Settled</font>'; }
else{$r='';}
return $r;
}
function withdrawRemark($type)
{
if($type=='s'){$r='Savings Withdrawal'; }
elseif($type=='lr'){$r='Loan Retrieval'; }
elseif($type=='w'){$r='Cash Withdrawal'; }
elseif($type=='p'){$r='PIN purchase'; }
elseif($type=='d'){$r='Donation Transfered'; }
elseif($type=='Card Withdrawal'){$r='Card Withdrawal'; }
else{$r='';}
return $r;
}
function splitEarnings($uidx,$stage,$lev){
$total = $this->totalEarnings($uidx);
return (int)($total/5);
}
function checkTransferGain($uidx){
global $db;
$id = snToId($uidx);
$sql = $db->query("SELECT SUM(amount) AS sum FROM transfer WHERE id2='$id'");
$row = $sql->fetch_assoc();
return $row['sum'];
}
function checkTransfer($uidx){
global $db;
$id = snToId($uidx);
$sql = $db->query("SELECT SUM(amount) AS sum FROM transfer WHERE id='$id'");
$row = $sql->fetch_assoc();
return $row['sum'];
}
function checkWithdraw($uidx){
global $db;
$id = snToId($uidx);
$sql = $db->query("SELECT SUM(amount) AS sum FROM withdraw WHERE id='$id'");
$row = $sql->fetch_assoc();
return $row['sum'];
}
function myTopups($uidx){
global $db;
$id = snToId($uidx);
$sql = $db->query("SELECT SUM(Price) AS sum FROM orders WHERE OrderingEmployeeID='$id' AND Status=1");
$row = $sql->fetch_assoc();
return $row['sum']/$this->dola;
}
function totalEarnings($uidx){
$uid = $this->keyToId($uidx);
$referrals = $this->referral($uidx);
$matrix = $this->matrixBonus($uidx);
$withdraw = $this->checkWithdraw($uidx);
$transfer = $this->checkTransfer($uidx);
$transfergain = $this->checkTransferGain($uidx);
$mytopup = $this->myTopups($uidx);
$total = ($referrals + $matrix + $transfergain) - ($withdraw + $transfer + $mytopup) - $this->onePayDebit($uid);// - userName($uid,'wallet');
return $total;
}
function totalEarnings2($uidx){
$uid = $this->keyToId($uidx);
$referrals = $this->referral($uidx);
$matrix = $this->matrixBonus($uidx);//
$withdraw = $this->checkWithdraw($uidx);
$transfer = $this->checkTransfer($uidx);
$transfergain = $this->checkTransferGain($uidx);
$mytopup = $this->myTopups($uidx);
$total = ($referrals + $matrix + $transfergain) - ($withdraw + $transfer + $mytopup) - $this->onePayDebit($uid);
return $total;
}
function onePayDebit($uid){
global $db;
$sql = $db->query("SELECT SUM(price) AS value_sum FROM onepaydebit WHERE userid = '$uid' ");
$row = mysqli_fetch_assoc($sql);
$amt = $row['value_sum']/400;
return $amt;
}
function onePayPlus($uid){
global $db;
$sql = $db->query("SELECT SUM(price) AS value_sum FROM onepaydebit WHERE userid = '$uid' AND price<0 ");
$row = mysqli_fetch_assoc($sql);
$amt = $row['value_sum']/400;
return $amt;
}
function onePayMinus($uid){
global $db;
$sql = $db->query("SELECT SUM(price) AS value_sum FROM onepaydebit WHERE userid = '$uid' AND price>0 ");
$row = mysqli_fetch_assoc($sql);
$amt = $row['value_sum']/400;
return $amt;
}
function onePayRemark($n){
if($n==1){$r='Funding OnePayNg from CCI'; }
elseif($n==2){$r='Charges on Funding OnePayNg'; }
elseif($n==3){$r='Funds Received from OnePayNg'; }
else{$r='Other charges'; }
return $r;
}
function payPerHead(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level BETWEEN 5 AND 12 ");
return mysqli_num_rows($sql)*12.5;
}
function negativeBal(){
global $db;
$sq = $db->query("SELECT * FROM neg ORDER BY sn DESC LIMIT 1 ");
$ro = $sq->fetch_assoc();
$lsn = isset($ro['ssn']) ? $ro['ssn'] : 0;
$sql = $db->query("SELECT * FROM user WHERE sn>'$lsn' LIMIT 2000");
while($row = $sql->fetch_assoc()){
$ssn = $row['sn'];
$bal = $this->totalEarnings($ssn);
if($bal<0){
$s = $db->query("INSERT INTO neg(ssn,bal) VALUES('$ssn','$bal')"); }
}
return ;
}
function stageCalc($key){
$level = $this->keyToLevel($key);
if($level>=17){$bl=7;}
elseif($level>=14){$bl=6;}
elseif($level>=11){$bl=5;}
elseif($level>=8){$bl=4;}
elseif($level>=5){$bl=3;}
elseif($level>=2){$bl=2;}
else{$bl=1;}
return $bl;
}
function keyToId($sn, $col = 'id')
{
global $db;
$que = $db->query("SELECT * FROM user WHERE sn = '$sn' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
function userLevel($key)
{
return $this->keyToId($key,'level');
}
function referral($key)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE sponsor='$key'");
$no = $sql->num_rows;
return $no;
}
function UpdateReward($id){
global $db,$report,$count;
$award = $_POST['awards'];
$incentives = $_POST['incentives'];
$sql = $db->query("UPDATE levels SET award='$award', award2='$incentives' WHERE sn='$id'");
$report = "Updated Successfully";
}
function userlevelNo2(){
global $db;
$sum = 0;
$sql = $db->query("SELECT * FROM user WHERE level=2");
while($row = $sql->fetch_assoc()){
if($this->level2($row['sn'])==2){$sum += 1; }
}
return $sum;
}
// function userlevelNo3($level){
// global $db;
// $sum = 0;
// $sql = $db->query("SELECT * FROM user WHERE level=2");
// while($row = $sql->fetch_assoc()){
// if($this->level3($row['sn'])==$level){
// $sum += 1;
// }
// }
// return $sum;
// }
function userlevelNo1(){
global $db;
$sum= 0;
$sql = $db->query("SELECT * FROM user WHERE active = 3 ");
$sql2 = $db->query("SELECT * FROM user WHERE level = 2 ");
return $sql->num_rows-$sql2->num_rows;
}
function userlevelNo(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE active = 0");
//$sql2 = $db->query("SELECT * FROM user WHERE level = 2 ");
return $sql->num_rows;
}
function team1($key)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE a1='$key' OR a2='$key' ") or die(mysqli_error());
$head = $sql->num_rows;
return $head;
}
function score($key)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE a1='$key' OR a2='$key' OR a3='$key' OR a4='$key' OR a5='$key' OR a6='$key' OR a7='$key' OR a8='$key' OR a9='$key' OR a10='$key' OR a11='$key' OR a12='$key' OR a13='$key' OR a14='$key' OR a15='$key' OR a16='$key' ") or die(mysqli_error());
$head = $sql->num_rows;
return $head;
}
// function level3($key)
// {
// global $db;
// $num = 0;
// $level = 0;
// $sql = $db->query("SELECT * FROM user WHERE (a1='$key' OR a2='$key' OR a3='$key' OR a4='$key' OR a5='$key' OR a6='$key') AND level=2 ") or die(mysqli_error());
// while ($row = $sql->fetch_assoc()) {
// $num += 1;
// }
// if ($num >= 1092) {
// $level = 8;
// }
// elseif ($num >= 363) {
// $level = 7;
// }
// elseif ($num >= 120) {
// $level = 6;
// }elseif ($num >= 39) {
// $level = 5;
// } elseif ($num >= 12) {
// $level = 4;
// } elseif ($num >= 3) {
// $level = 3;
// }
// return $level;
// }
/*
function findLevelx($key){
global $db;
//$key = $this->userName('sn');
$level = 0; $prog=1;
$a = 1; $sq=$db->query("SELECT * FROM levels " );
while($row = mysqli_fetch_assoc($sq)){$b = $a++;
$gen = 'a'.$b; $target = MATRIX**$b;
$sql=$db->query("SELECT * FROM user WHERE $gen = '$key' AND active = 2 " )or die(mysqli_error());
if($this->CheckSponsor($sql)==$target AND $prog==1){$level += 1; $prog=1; }else{$prog=0;}
}
$levels = ($this->wildSponsored($key)>1) ? $level+1 : $level;
return $levels;
}
*/
function CheckSponsor($sql)
{
$num = 0;
while ($row = mysqli_fetch_assoc($sql)) {
if ($this->wildSponsored($row['sn']) > 1) {
$num += 1;
}
}
return $num;
}
function matrixAward()
{
global $db;
$randomKey = $this->userName('sn');
$level = $this->wildLevel2($randomKey) + 1;
$award = 0;
$sql = $db->query("SELECT * FROM levels WHERE sn <= '$level' ");
while ($row = mysqli_fetch_assoc($sql)) {
$award += (int)$row['award'];
}
return $award;
}
// 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;
$level = $this->findLevelx($key);
if ($level == 0) {
$stagelevel = 0;
$stage = 'Waiting';
$stg = 1;
$nextstagelevel = 1;
} elseif ($level == 1) {
$stagelevel = 0;
$stage = 'Induct';
$stg = 2;
$nextstagelevel = 3;
} elseif ($level == 2) {
$stagelevel = 1;
$stage = 'Induct';
$stg = 2;
$nextstagelevel = 3;
} elseif ($level == 3) {
$stagelevel = 0;
$stage = 'Stage 1';
$stg = 3;
$nextstagelevel = 6;
} elseif ($level == 4) {
$stagelevel = 1;
$stage = 'Stage 1';
$stg = 3;
$nextstagelevel = 6;
} elseif ($level == 5) {
$stagelevel = 2;
$stage = 'Stage 1';
$stg = 3;
$nextstagelevel = 6;
} elseif ($level == 6) {
$stagelevel = 0;
$stage = 'Stage 2';
$stg = 4;
$nextstagelevel = 9;
} elseif ($level == 7) {
$stagelevel = 1;
$stage = 'Stage 2';
$stg = 4;
$nextstagelevel = 9;
} elseif ($level == 8) {
$stagelevel = 2;
$stage = 'Stage 2';
$stg = 4;
$nextstagelevel = 9;
} elseif ($level == 9) {
$stagelevel = 0;
$stage = 'Stage 3';
$stg = 5;
$nextstagelevel = 12;
} elseif ($level == 10) {
$stagelevel = 1;
$stage = 'Stage 3';
$stg = 5;
$nextstagelevel = 12;
} elseif ($level == 11) {
$stagelevel = 2;
$stage = 'Stage 3';
$stg = 5;
$nextstagelevel = 12;
} elseif ($level == 12) {
$stagelevel = 0;
$stage = 'Stage 4';
$stg = 6;
$nextstagelevel = 15;
} elseif ($level == 13) {
$stagelevel = 1;
$stage = 'Stage 4';
$stg = 6;
$nextstagelevel = 15;
} elseif ($level == 14) {
$stagelevel = 2;
$stage = 'Stage 4';
$stg = 6;
$nextstagelevel = 15;
} elseif ($level == 15) {
$stagelevel = 0;
$stage = 'Stage 5';
$stg = 7;
$nextstagelevel = 18;
} elseif ($level == 16) {
$stagelevel = 1;
$stage = 'Stage 5';
$stg = 7;
$nextstagelevel = 18;
} elseif ($level == 17) {
$stagelevel = 2;
$stage = 'Stage 5';
$stg = 7;
$nextstagelevel = 18;
} elseif ($level == 18) {
$stagelevel = 0;
$stage = 'Stage 6';
$stg = 8;
$nextstagelevel = 21;
} elseif ($level == 19) {
$stagelevel = 1;
$stage = 'Stage 6';
$stg = 8;
$nextstagelevel = 21;
} elseif ($level == 20) {
$stagelevel = 2;
$stage = 'Stage 6';
$stg = 8;
$nextstagelevel = 21;
} elseif ($level == 21) {
$stagelevel = 0;
}
//stg = stages counting from 1;
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 cLevel1($key)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE a1='$key' ") or die(mysqli_error());
$head = mysqli_num_rows($sql);
$moveto = ($head == 3) ? 1 : 0;
if($moveto==1){
$db->query("UPDATE user SET level='$moveto' WHERE sn='$key' ");
}
return;
}
function cLevel2($key)
{//
global $db;
$level = $this->keyToLevel($key);
$sql = $db->query("SELECT * FROM user WHERE a2='$key' ") or die(mysqli_error());
$head = mysqli_num_rows($sql);
$moveto = ($head == 9) ? 2 : $level;
if($moveto==2){
$db->query("UPDATE user SET level='$moveto' WHERE sn='$key' ");
}
return;
}
function levelToEven($level){
if($level>=17){$bl=17;}
elseif($level>=14){$bl=14;}
elseif($level>=11){$bl=11;}
elseif($level>=8){$bl=8;}
elseif($level>=5){$bl=5;}
elseif($level>=2){$bl=2;}
else{$bl=0;}
return $bl;
}
function stageToEven($stage){
if($stage==7){$bl=17;}
elseif($stage==6){$bl=14;}
elseif($stage==5){$bl=11;}
elseif($stage==4){$bl=8;}
elseif($stage==3){$bl=5;}
elseif($stage==2){$bl=2;}
elseif($stage==1){$bl=0;}
else{$bl=0;}
return $bl;
}
function levelUpdate($key){
global $db;
$i=1;
$sql = $db->query("SELECT * FROM user WHERE sn='$key' ");
$row=mysqli_fetch_assoc($sql);
while($i <= 16) { $e=$i++; $a = 'a'.$e;
$sn = $row[$a];
if($sn == 0){return;}
elseif($e==1){$this->cLevel1($sn); }
elseif($e==2){$this->cLevel2($sn); }
else{$this->levelCreate($sn); }
}
return;
}
function levelCreate($key)
{
global $db;
$s3date = date('ymd');
$mm = $this->keyToId($key,'mm');
$s3 = $mm>202202 ? 3 : 1;
$level = $this->keyToLevel($key);
$even = $this->levelToEven($level);
$uid = $this->keyToId($key);
$num = $this->userStageTeam($uid);
if($num >=39){$moveto = $even+3; }
elseif($num >=12){$moveto = $even+2; }
elseif($num >=3){$moveto = $even+1; }
else{$moveto = $level; }
if($moveto>$level AND $moveto>2 AND $this->team1($key)>11){
if($moveto==5){$s3date = time();}
$sql = $db->query("UPDATE user SET level='$moveto',s3='$moveto',s3date='$s3date' WHERE sn='$key' ");
$this->update30GenUpline($key,$moveto);
}
return;
}
function update30GenUpline($key,$level){
global $db;
$sql = $db->query("SELECT * FROM user WHERE sn='$key' ");
$i=1;
while($i <= 20) { $e=$i++; $a = 'a'.$e; $sn = $row[$a];
$db->query("UPDATE user SET x=0 WHERE sn='$sn' AND level='$level' ");
}
return;
}
function levelDownlines($key){
global $db;
$level = $this->keyToLevel($key);
$even = $this->levelToEven($level);
$sql = $level>1 ? $db->query("SELECT * FROM user WHERE (a1='$key' OR a2='$key' OR a3='$key' OR a4='$key') AND level>='$even' ") : $db->query("SELECT * FROM user WHERE a1='$key' OR a2='$key' ");
return mysqli_num_rows($sql);
}
// function legStageTeam($key){
// global $db;
// $sql = $db->query("SELECT * FROM user WHERE (sn='$key' OR a1='$key' OR a2='$key' OR a3='$key') AND level>=5 ");
// return mysqli_num_rows($sql);
// }
function RecalculateLevel(){
global $db,$report;
$sq = $db->query("SELECT * FROM user WHERE level>1 ORDER BY level DESC");
while($row=mysqli_fetch_assoc($sq)){
$this->levelCreate($row['sn']);
}
$report = 'System matrix successfully recalculated';
return;
}
function RecalculateLevelx(){
global $db,$report;
$level = $_POST['RecalculateLevelx'];
$sq = $db->query("SELECT * FROM user WHERE level='$level' ORDER BY sn DESC");
while($row=mysqli_fetch_assoc($sq)){
$this->levelCreate($row['sn']);
}
$report = 'System matrix successfully recalculated: '.$level;
return;
}
function RecalculateUser(){
global $db,$report;
$key = $_POST['RecalculateUser'];
$this->levelCreate($key);
$report = 'System matrix successfully recalculated';
return;
}
function keyToLevel($sn, $col = 'level')
{
global $db;
$que = $db->query("select * FROM user WHERE sn = '$sn' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return mysqli_num_rows($que)>0 ? $ro[$col]:'';;
}
function levelScore()
{
$lev = $this->Level() + 1;
return $this->Gen($lev);
}
function levelTarget()
{
return $this->Level(3);
}
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 0;//number_format($this->gTree(1),1).'%';
}
//stage
function Stage()
{
return $this->wildLevel2($this->userName('sn'), 1);
}
function totalEarning()
{
return $this->matrixAward() + $this->referalB();
}
function Balance()
{
return $this->totalEarning() - $this->totalWithdraw() - $this->totalPending() + $this->transfered(2) - $this->transfered();
}
// function totalWithdraw()
// {
// global $db, $userKey;
// $id = $this->userName();
// $amt = 0;
// $sq = $db->query("SELECT * FROM withdraw WHERE id='$userKey' AND status = 1 ");
// while ($row = mysqli_fetch_assoc($sq)) {
// $amt += $row['amount'];
// }
// return $amt;
// }
function totalWithdrawgm($id)
{
global $db;
$amt = 0;
$sq = $db->query("SELECT * FROM gmwithdraw WHERE id='$id' ");
while ($row = mysqli_fetch_assoc($sq)) {
$amt += $row['amount'];
}
return $amt;
}
function totalReceivedgm($id)
{
global $db;
$amt = 0;
$sq = $db->query("SELECT * FROM gmwithdraw WHERE id2='$id' ");
while ($row = mysqli_fetch_assoc($sq)) {
$amt += $row['amount'];
}
return $amt;
}
function totalPending()
{
global $db, $userKey;
$id = $this->userName();
$amt = 0;
$sq = $db->query("SELECT * FROM withdraw WHERE id='$userKey' AND status = 0 ");
while ($row = mysqli_fetch_assoc($sq)) {
$amt += $row['amount'];
}
return $amt;
}
function Stage1()
{
return $this->Level(2);
}
function legKey($keyx,$leg=0)//globe user legs
{
global $db;
$key = '';
$qu = $db->query("SELECT * FROM globeuser WHERE a1 ='$keyx' 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 myLegs($sn,$leg=0) //General user legs
{
global $db;
$key = '';
$qu = $db->query("SELECT * FROM user WHERE a1 ='$sn' 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);
// $leg1 = $key[0];
// $leg2 = $key[1];
// $leg3 = $key[2];
$legkey = !empty($key[$leg]) ? $key[$leg] : '';
return $legkey;
}
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 uName($id, $col = 'user')
{
global $db;
$que = $db->query("SELECT * FROM user WHERE id = '$id' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
function uNameUser($user, $col = 'user')
{
global $db;
$que = $db->query("SELECT * FROM user WHERE user = '$user' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
function courseName($id, $col = 'title')
{
global $db;
$que = $db->query("SELECT * FROM course WHERE sn = '$id' ") or die(mysqli_error());
$ro = mysqli_fetch_array($que);
return $ro[$col];
}
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 monthChartData()
{
$range = '';
$cm = date('m');
$a = $cm - 5;
while ($a <= $cm) {
$b = $a++;
$c = $this->monthlyRegistered($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;
}
//chart data of user monthly sponsor
function monthUserInducted()
{
$range = '';
$cm = date('m');
$a = $cm - 5;
while ($a <= $cm) {
$b = $a++;
$c = $this->inductedPerMonth($b);
$range .= $c . ', ';
}
return $range;
}
//maximum monthly entry// $tim = max(explode(",", $profile->monthUserSponsor()));
function maxMonthly()
{
$max = max(explode(",", $this->monthEntryData()));
return $max;
}
function maxMonthlyAll()
{
$max = max(explode(",", $this->monthChartData()));
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 <= 16) {
$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;
}
function monthlyRegistered($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;
}
//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;
}
//Calculate the amunt of members sponsored by a user monthly
function inductedPerMonth($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 && $this->wildSponsored($row['sn']) > 1) {
$num += 1;
}
}
return $num;
}
// function matrixBonus($stg,$level){
// global $db;
// $sn = stageNo($stg,$level);
// $i = 1;
// $sql = $db->query("SELECT SUM(award) AS sum FROM levels WHERE sn<='$sn'");
// $row = $sql->fetch_assoc();
// return $row['sum'];
// }
function matrixBonus($key){
global $db;
$uid = $this->keyToId($key);
return $this->getUserLevelePayout($uid);//$total;//
}
function getreward($stg,$level,$col=''){
global $db;
$sql= $db->query("SELECT * FROM levels WHERE stg='$stg' AND level='$level'");
$row = $sql->fetch_assoc();
$value = ($col=='')?$row['award']:$row['award2'];
return $value;
}
function countLevelUsers($lev){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level = '$lev' ");
return $sql->num_rows;
}
function countLevelUsersPaid($lev){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level BETWEEN '$lev' AND 10 ");
return $sql->num_rows;
}
function countLevelGmUsers($lev){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE level = '$lev' ");
return $sql->num_rows;
}
function getreward1($lev){
global $db;
$level = $lev+1;
$sql = $db->query("SELECT * FROM levels WHERE sn='$level' ");
$row = $sql->fetch_assoc();
return $row['sn'];
}
function nextReward($stage,$lev, $col=''){
global $db;
$sql = $db->query("SELECT * FROM levels WHERE stg='$stage' AND level='$lev'");
$row = $sql->fetch_assoc();
$sn = $row['sn']+1;
$sql = $db->query("SELECT * FROM levels WHERE sn='$sn'");
$row = $sql->fetch_assoc();
$value = ($col=='')?$row['award']:$row['award2'];
return $value;
}
//Count all registered users
function allUsers()
{
global $db;
$sql = $db->query("SELECT * FROM user ") or die(mysqli_error());
$num = mysqli_num_rows($sql);
return $num;
}
//Calculate the amunt of members sponsored by a user monthly
function allInductedUsers()
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE sp>1 ") or die(mysqli_error());
$num = mysqli_num_rows($sql);
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 <= 16) {
$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>' . $row['firstname'] . '</td>
<td>' . $row['user'] . '</td></tr>';
}
}
return $key;
}
function recentlyRegistered()
{
global $db;
$key = '';
$c = 0;
$nu = 0;
$qu = $db->query("SELECT * FROM user ORDER BY sn DESC LIMIT 7 ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$key .= '<tr><td><a href="javascript:void(0);" class="text-link">' . $row['firstname'] . '</a></td>
<td>' . $row['user'] . '</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 <= 16) {
$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 showMypin()
{
global $db, $userKey;
$table = '<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>E-PIN</th>
<th>PIN Date</th>
<th>Type</th>
<th>Status</th>
<th>Recipient</th>
</tr>
</thead>
<tbody>';
$sql = $db->query("SELECT * FROM pin WHERE rep='$userKey' ORDER BY sn DESC");
$i = 1;
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
$user = $row['id'];
if ($row['status'] == 1) {
$st = 'used';
} else {
$st = 'active';
}
if ($row['tm'] == 'Request') {
$type = 'Request';
} else {
$type = 'Auto';
}
$uname = ($row['status'] == 1) ? ' (' . $this->uNameUser($user) . ')' : '';
$table .= '<tr>
<td >' . $e . '</td>
<td ><a href="#">' . $row['pin'] . '</a></td>
<td >' . $row['created'] . '</td>
<td >' . $row['tm'] . '</td>
<td >' . $st . '</td>
<td >' . $this->uNameUser($user, 'firstname') . ' ' . $this->uNameUser($user, 'lastname') . $uname . '</td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function showMypinRequest()
{
global $db, $userKey;
$table = '<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Number of PINs</th>
<th>Payment Details</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$sql = $db->query("SELECT * FROM payment WHERE id='$userKey' ");
$i = 1;
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
if ($row['status'] == 1) {
$st = $row['buy'] . ' Approved';
} else {
$st = 'Pending';
}
$table .= '<tr>
<td >' . $e . '</td>
<td ><a href="#">' . $row['qty'] . '</a></td>
<td >' . $row['details'] . '</td>
<td >' . $row['created'] . '</td>
<td >' . $st . '</td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function viewPinRequest()
{
global $db;
$table = '<table id="" class="table-bordered display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Username</th>
<th>Number of PINs</th>
<th>Payment Details</th>
<th>Date</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>';
$col = '';
$sql = $db->query("SELECT * FROM payment ORDER BY status ASC, created DESC LIMIT 50 ");
$i = 1;
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
if ($row['status'] == 1) {
$st = $row['buy'] . ' Approved';
$btn = '';
} else {
$st = 'Pending';
$btn = '<button type="submit" class="btn btn-xs btn-primary" name="processPin" value="' . $row['sn'] . '">Process</button>';
}
// if(isset($_SESSION['processPin'])){
$col = ($_SESSION['processPin'] == $row['sn']) ? ' bgcolor="#FF66CC"' : '';
// }
$table .= '<tr ' . $col . '>
<td >' . $e . '</td>
<td >' . $this->uName($row['id']) . '</td>
<td ><a href="#">' . $row['qty'] . '</a></td>
<td >' . $row['details'] . '</td>
<td >' . $row['created'] . '</td>
<td >' . $st . '</td>
<td >' . $btn . '</td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function showMywithdraw()
{
global $db, $userKey;
$table = '<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Transaction ID</th>
<th>Amount</th>
<th>Balance</th>
<th>Transaction Date</th>
<th>Transaction</th>
<th>Type</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$i = 1;
$sql = $db->query("SELECT * FROM withdraw WHERE id='$userKey' ORDER BY sn ASC ");
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
if ($row['status'] == 1) {
$st = 'Complete';
} else {
$st = 'Pending';
}
$type = ($row['finalbalance'] > $row['inibalance']) ? 'Credit' : 'Debit';
$table .= '<tr>
<td >' . $e . '</td>
<td >' . $row['tno'] . '</td>
<td ><a href="#">$' . $row['amount'] . '</a></td>
<td ><a href="#">$' . $row['finalbalance'] . '</a></td>
<td >' . $row['created'] . '</td>
<td >' . $row['type'] . '</td>
<td >' . $type . '</td>
<td >' . $st . '</td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function showMyawards()
{
global $db, $userKey;
$randomKey = $this->userName('sn');
$level = $this->wildLevel2($randomKey) + 1;
$table = '<table id="example23" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Stage</th>
<th>Level</th>
<th>Award</th>
<th>type</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$e = 0;
$sql = $db->query("SELECT * FROM levels WHERE sn <='$level' ORDER BY sn ASC ");
while ($row = mysqli_fetch_assoc($sql)) {
if (!empty($row['award'])) {
$e += 1;
$table .= '<tr>
<td >' . $e . '</td>
<td >' . $row['title'] . '</td>
<td ><a href="#">' . $row['level'] . '</a></td>
<td ><a href="#">$' . $row['award'] . '</a></td>
<td ><a href="#">Cash Bonus</a></td>
<td ></td>
</tr>';
}
if (!empty($row['award2'])) {
$sn = $row['sn'];
$sq = $db->query("SELECT * FROM award WHERE level='$sn' AND id='$userKey' ");
$rr = mysqli_fetch_assoc($sq);
if (mysqli_num_rows($sq) == 0) {
$action = '<form method="post"><button type="submit" name="requestIncentive" class="btn btn-primary btn-xs" value="' . $row['sn'] . '">Request</button></form>';
} elseif (mysqli_num_rows($sq) == 1 AND $rr['remark'] == 0) {
$action = 'Pending';
} else {
$action = 'Supplied';
}
$e += 1;
$table .= '<tr>
<td >' . $e . '</td>
<td >' . $row['title'] . '</td>
<td ><a href="#">' . $row['level'] . '</a></td>
<td ><a href="#">' . $row['award2'] . '</a></td>
<td ><a href="#">Incentive</a></td>
<td >' . $action . '</td>
</tr>';
}
}
$sql = $db->query("SELECT * FROM user WHERE sponsor = '$randomKey' ORDER BY sn ASC ");
while ($row = mysqli_fetch_assoc($sql)) {
$e += 1;
$table .= '<tr>
<td >' . $e . '</td>
<td ></td>
<td ><a href="#"></a></td>
<td ><a href="#">$2</a></td>
<td ><a href="#">Referal Bonus</a></td>
<td ></td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function requestIncentive()
{
global $db, $userKey, $report, $count;
$sn = sanitize($_POST['requestIncentive']);
$sql = $db->query("SELECT * FROM award WHERE level='$sn' AND id='$userKey' ");
if (mysqli_num_rows($sql) > 0) {
$report = 'Sorry, You have previously requested for this incentive';
$count = 1;
} else {
$db->query("INSERT into award (id,level) VALUES ('$userKey','$sn') ");
$report = 'Request successfully submitted';
}
return;
}
function showAwardee()
{
global $db, $stg;
$_SESSION['sta'] = isset($_POST['stage']) ? sanitize($_POST['stage']) : $_SESSION['sta'];
$_SESSION['lv'] = isset($_POST['level']) ? sanitize($_POST['level']) : $_SESSION['lv'];
$stg = $this->stagetoLevel($_SESSION['sta'], $_SESSION['lv']);
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Full Name</th>
<th>username</th>
<th>Bank Details</th>
<th>Award</th>
<th>Join on</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$a = 1;
$qu = $db->query("SELECT * FROM user ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$id = $this->wildUserName($row['sn'], 'id');
$checkaward = $this->checkAward($_SESSION['sta'], $_SESSION['lv'], $id);
$award = $this->levelAward($_SESSION['sta'], $_SESSION['lv']);
if (($stg != 0 && $this->wildLevel2($row['sn']) == $stg && $this->wildSponsored($row['sn'])) OR ($this->wildLevel2($row['sn']) > $stg && $checkaward == 0)) {
$b = $a++;
if ($checkaward == 0) {
$action = 'Not Awarded';
//$action = '<input type="hidden" name="amount" value="'.$award.'"> <button type="submit" name="rid" class="btn btn-success btn-xs" value="'.$id.'">Approve Award</button>';
} else {
$action = 'Awarded';
}
if (!empty($award)) {
$table .= ' <tr>
<td>' . $b . '</td>
<td>' . $row['firstname'] . ' ' . $row['lastname'] . '</td>
<td>' . $row['user'] . '</td>
<td>' . $row['bank'] . ' ' . $row['accountno'] . '</td>
<td>' . $award . '</td>
<td>' . date('d M, Y', strtotime($row['created'])) . '</td>
<td>' . $action . '</td>
</tr>';
}
}
}
$table .= ' </tbody>
</table>';
return $table;
}
function showWithdrawRequest()
{
global $db, $userKey;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Transaction ID</th>
<th>Beneficiary</th>
<th>Amount</th>
<th>Balance</th>
<th>Transaction Date</th>
<th>Transaction</th>
<th>Type</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>';
$i = 1;
if (isset($_GET['quser'])) {
$quser = $this->uNameUser($_GET['quser'], 'id');
$sql = $db->query("SELECT * FROM withdraw WHERE id='$quser' ORDER BY sn DESC LIMIT 200") or die(mysqli_error());
} else {
$sql = $db->query("SELECT * FROM withdraw ORDER BY sn DESC LIMIT 200");
}
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
if ($row['status'] == 1) {
$st = 'Complete';
$action = '';
} else {
$st = 'Pending';
$action = '<button type="submit" name="rid" class="btn btn-success btn-xs" value="' . $row['tno'] . '">Approve Request</button>';
}
$type = ($row['finalbalance'] > $row['inibalance']) ? 'Credit' : 'Debit';
//
$table .= '<tr>
<td >' . $e . '</td>
<td >' . $row['tno'] . '</td>
<td><a href="?quser=' . $this->uName($row['id']) . '">' . $this->uName($row['id']) . ', ' . $this->uName($row['id'], 'bank') . ', ' . $this->uName($row['id'], 'accountno') . '</a></td>
<td ><a href="#">$' . $row['amount'] . '</a></td>
<td ><a href="#">$' . $row['finalbalance'] . '</a></td>
<td >' . $row['created'] . '</td>
<td >' . $row['type'] . '</td>
<td >' . $type . '</td>
<td >' . $st . '</td>
<td >' . $action . '</td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function showIncentiveRequest()
{
global $db, $userKey;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Request ID</th>
<th>Beneficiary</th>
<th>Item</th>
<th>Transaction Date</th>
<th>Transaction Type</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>';
$i = 1;
$sql = $db->query("SELECT * FROM award ORDER BY sn DESC LIMIT 200 ");
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
if ($row['remark'] == 1) {
$st = 'Complete';
$action = '';
} else {
$st = 'Pending';
$action = '<button type="submit" name="rid" class="btn btn-success btn-xs" value="' . $row['sn'] . '">Approve Request</button>';
}
$type = 'Incentive Award';
$alevel = $row['level'];
$sl = $db->query("SELECT * FROM levels WHERE sn='$alevel' ORDER BY sn DESC LIMIT 200 ");
$rw = mysqli_fetch_assoc($sl);
$item = $rw['award2'];
$table .= '<tr>
<td >' . $e . '</td>
<td >' . $row['sn'] . '</td>
<td>' . $this->wildUserKeys($row['id']) . ', ' . $this->wildUserKeys($row['id'], 'bank') . ', ' . $this->wildUserKeys($row['id'], 'accountno') . '</td>
<td ><a href="#">' . $item . '</a></td>
<td >' . $row['created'] . '</td>
<td >' . $type . '</td>
<td >' . $st . '</td>
<td >' . $action . '</td>
</tr>';
}
$table .= '</tbody> </table>';
return $table;
}
function checkAward($stg, $level, $id)
{
global $db;
$sql = $db->query("SELECT * FROM levels WHERE stg='$stg' AND level = '$level' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$alevel = $row['sn'];
$qu = $db->query("SELECT * FROM award WHERE id='$id' AND level = '$alevel' ") or die(mysqli_error());
$num = mysqli_num_rows($qu);
return $num;
}
function countAward($level)
{
global $db;
$qu = $db->query("SELECT * FROM award WHERE level = '$level' ") or die(mysqli_error());
$num = mysqli_num_rows($qu);
return $num;
}
function levelAward($stg, $level)
{
global $db;
$award = '';
$qu = $db->query("SELECT * FROM levels WHERE stg='$stg' AND level = '$level' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($qu);
//if(!empty($row['award'])){$award .= $row['award'];}
if (!empty($row['award2'])) {
$award .= $row['award2'];
}
return $award;
}
function approveAward()
{
global $db, $report, $count;
$id = sanitize($_POST['approveAward']);
$stg = $_SESSION['sta'];
$level = $_SESSION['lv'];
$pa = $this->userName('pass');
$approval = md5($_POST['approval']);
if ($pa == $approval) {
$msg = $db->query("INSERT INTO award (id,stg,level)
VALUES('$id','$stg','$level')") or die(mysqli_error());
$report = 'User Successfully Awarded!';
} else {
$report = 'You have entered an invalid authorization code!';
$count = 1;
}
return;
}
function userStatistics()
{
global $db;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Stage</th>
<th>Level</th>
<th>Cash Award</th>
<th>Incentive Award</th>
<th>Count</th>
<th>Awarded</th>
<th>Not Awarded</th>
</tr>
</thead>
<tbody>';
$a = 1;
$qu = $db->query("SELECT * FROM levels ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$b = $a++;
$level = $row['sn'] - 1;
//$checkaward = $this->checkAward($_SESSION['sta'],$_SESSION['lv'],$id);
$number = $this->levelUsers($level);
$awarded = $this->countAward($row['sn']);
$notawarded = $number - $awarded;
$table .= ' <tr>
<td>' . $b . '</td>
<td>' . $row['title'] . '</td>
<td>' . $row['level'] . '</td>
<td>$' . $row['award'] . '</td>
<td>' . $row['award2'] . '</td>
<td>' . $number . '</td>
<td>' . $awarded . '</td>
<td>' . $notawarded . '</td>
</tr>';
}
$table .= ' </tbody></table>';
return $table;
}
function levelRewards()
{
global $db;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Stage</th>
<th>Level</th>
<th>Cash Reward</th>
<th>Other Reward</th>
<th>Action</th>
</tr>
</thead>
<tbody>';
$a = 1;
$qu = $db->query("SELECT * FROM levels ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$b = $a++;
$table .= ' <tr>
<td>' . $b . '</td>
<td>' . $row['title'] . '</td>
<td>' . $row['level'] . '</td>
<td><form method="post">
<input type="text" name="award" value="' . $row['award'] . '"></td>
<td>
<input type="text" name="award2" value="' . $row['award2'] . '"></td>
<td><button type="submit" name="updateAward" class="btn btn-success btn-xs" value="' . $row['sn'] . '">Update Reward</button></form></td>
</tr>';
}
$table .= ' </tbody></table>';
return $table;
}
function updateAward()
{
global $db, $report, $count;
$sn = $_POST['updateAward'];
$reward = sanitize($_POST['award']);
$reward2 = sanitize($_POST['award2']);
$sql = $db->query("UPDATE levels SET award = '$reward', award2 = '$reward2' WHERE sn = '$sn' ");
if ($sql) {
$report = 'Level Reward Successfully Updated!';
} else {
$report = 'Level Reward Update not Successful!';
$count = 1;
}
return;
}
function levelUsers($level)
{
global $db;
$count = 0;
$qu = $db->query("SELECT * FROM user ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
if ($level == $this->wildLevel2($row['sn'])) {
$count += 1;
}
}
return $count;
}
function stageUsers($stage)
{
global $db;
$count = 0;
$qu = $db->query("SELECT * FROM user WHERE st1=1") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
if ($stage == $this->wildLevel2($row['sn'], 2)) {
$count += 1;
}
}
return $count;
}
function allPins()
{
global $db;
$count = 0;
$qu = $db->query("SELECT * FROM pin ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$count += 1;
}
return $count;
}
function activePins()
{
global $db;
$count = 0;
$qu = $db->query("SELECT * FROM pin WHERE status=0 ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$count += 1;
}
return $count;
}
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 sendMessageToAll()
{
global $report;
$message = addslashes($_POST['message']);
$subject = addslashes($_POST['subject']);
$this->message(1, 'Admin', $message, $subject);
$report = 'Your message was successfully sent to all members';
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;
$usercreated = $this->uName($userKey, 'created');
$sql = $db->query("SELECT * FROM msg WHERE (rec = '$userKey' OR rec = 1 OR sender = '$userKey') AND created >= '$usercreated' ORDER BY sn DESC ") or die(mysqli_error());
$num = mysqli_num_rows($sql);
while ($row = mysqli_fetch_assoc($sql)) {
$sn = $row['sn'];
if ($row['active'] == 1) {
$sql = $db->query("UPDATE msg SET active=2 WHERE sn = '$sn' ");
}
$b = $a++;
$c = $b % 5;
if ($row['sender'] == 'Admin') {
$sender = 'Admin';
} else {
$sender = ucwords($this->uName($row['sender']));
}
if ($row['rec'] == $userKey OR $row['rec'] == 1) {
$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>' . $sender . ': ' . $row['subject'] . '</strong><br>' . htmlspecialchars($row['msg']) . '</span>
<h6 class="">' . date('d-M-y h:i A', $row['ctime']) . $this->findReply($row['sn']) . '</h6>
</li>';
}
if ($nu == 1) {
$sql = $db->query("SELECT * FROM msg WHERE (rec = '$userKey' OR rec = 1) AND created >= '$usercreated' ") or die(mysqli_error());
$num = mysqli_num_rows($sql);
$msg = $num;
}
return $msg;
}
function findReply($mid)
{
global $db;
$reply = '<br><b>Reply:</b> ';
$sq = $db->query("SELECT * FROM replymsg WHERE mid = '$mid' ") or die(mysqli_error());
while ($ro = mysqli_fetch_assoc($sq)) {
$reply .= '<li>' . htmlspecialchars($ro['reply']) . '</li>';
}
$reply = (mysqli_num_rows($sq) > 0) ? '<ul>' . $reply . '</li>' : '';
return $reply;
}
//administrator messages
function adminMsgAll()
{
global $db;
$msg = '';
$bl = ['info', 'warning', 'primary', 'danger', 'success'];
$a = 0;
if (isset($_GET['reply'])) {
$reply = $_GET['reply'];
$sq = $db->query("SELECT * FROM msg WHERE sn = '$reply' ") or die(mysqli_error());
$ro = mysqli_fetch_assoc($sq);
$user = $ro['sender'];
$sql = $db->query("SELECT * FROM msg WHERE rec = '$user' OR rec = '1' OR sender = '$user' ORDER BY sn DESC ") or die(mysqli_error());
} else {
$sql = $db->query("SELECT * FROM msg ORDER BY sn DESC LIMIT 200 ") or die(mysqli_error());
}
$num = mysqli_num_rows($sql);
while ($row = mysqli_fetch_assoc($sql)) {
$user = ($row['sender'] == 'Admin') ? $row['rec'] : $row['sender'];
$b = $a++;
$c = $b % 5;
if ($row['sender'] == 'Admin') {
$sender = 'Admin';
} else {
$sender = ucwords($this->uName($row['sender']));
}
if ($row['rec'] == '1') {
$rec = 'All';
} elseif ($row['rec'] == 'Admin') {
$rec = 'Admin';
} else {
$rec = ucwords($this->uName($row['rec']));
}
if ($row['rec'] == $user) {
$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>[' . $sender . ' - ' . $rec . '] ' . $row['subject'] . '</strong><br>' . htmlspecialchars($row['msg']) . '</span>
<h6 class="">' . date('d-M-y h:i A', $row['ctime']) . $this->findReply($row['sn']);
if ($sender != 'Admin') {
$msg .= ' <a href="?reply=' . $row['sn'] . '"> Reply</a>';
}
if (isset($_GET['reply'])) {
if ($_GET['reply'] == $row['sn']) {
$msg .= '<br><form method="post"><input class="form-control" onchange="submit" name="replyMsg" placeholder="Enter reply & press enter" autofocus></form>';
}
}
$msg .= '</h6>
</li>';
}
return $msg;
}
//administrator messages
function adminMsgUser($user)
{
global $db;
$msg = '';
$bl = ['info', 'warning', 'primary', 'danger', 'success'];
$a = 0;
$sql = $db->query("SELECT * FROM msg WHERE rec = '$user' OR rec = '1' OR sender = '$user' 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['sender'] == 'Admin') {
$sender = 'Admin';
} else {
$sender = ucwords($this->uName($row['sender']));
}
if ($row['rec'] == '1') {
$rec = 'All';
} elseif ($row['rec'] == 'Admin') {
$rec = 'Admin';
} else {
$rec = ucwords($this->uName($row['rec']));
}
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>[' . $sender . ' - ' . $rec . '] ' . $row['subject'] . '</strong><br>' . htmlspecialchars($row['msg']) . '</span>
<h6 class="">' . date('d-M-y h:i A', $row['ctime']) . ' <a href="?reply=' . $row['sn'] . '"> Reply</a></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;
$usercreated = $this->uName($userKey, 'created');
$sql = $db->query("SELECT * FROM msg WHERE (rec = '$userKey' OR rec = 1) AND active = 1 AND created >= '$usercreated' 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">' . htmlspecialchars($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 paystackCharge($amt, $opt = '')
{
$result = 100 + ($amt * 0.015);
//$result = ($result<2500) ? $result-100 : $result;
$result = ($opt == 1) ? $result + $amt : $result;
return $result;
}
function stgTost($stg)
{
if ($stg == 1) {
$s = 'Waiting';
} elseif ($stg == 2) {
$s = 'Induction';
} 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 stgTostage($stg)
{
if ($stg == 1) {
$s = 'Induction';
} elseif ($stg == 2) {
$s = 'Stage 1';
} elseif ($stg == 3) {
$s = 'Stage 2';
} elseif ($stg == 4) {
$s = 'Stage 3';
} elseif ($stg == 5) {
$s = 'Stage 4';
} elseif ($stg == 6) {
$s = 'Stage 5';
}
return $s;
}
function stagetoLevel($stage, $level)
{
if ($stage == 1 && $level == 0) {
$lev = 1;
} elseif ($stage == 1 && $level == 1) {
$lev = 2;
} elseif ($stage == 2 && $level == 0) {
$lev = 3;
} elseif ($stage == 2 && $level == 1) {
$lev = 4;
} elseif ($stage == 2 && $level == 2) {
$lev = 5;
} elseif ($stage == 3 && $level == 0) {
$lev = 6;
} elseif ($stage == 3 && $level == 1) {
$lev = 7;
} elseif ($stage == 3 && $level == 2) {
$lev = 8;
} elseif ($stage == 4 && $level == 0) {
$lev = 9;
} elseif ($stage == 4 && $level == 1) {
$lev = 10;
} elseif ($stage == 4 && $level == 2) {
$lev = 11;
} elseif ($stage == 5 && $level == 0) {
$lev = 12;
} elseif ($stage == 5 && $level == 1) {
$lev = 13;
} elseif ($stage == 5 && $level == 2) {
$lev = 14;
}
elseif ($stage == 6 && $level == 0) {
$lev = 15;
}
elseif ($stage == 6 && $level == 1) {
$lev = 16;
}
elseif ($stage == 6 && $level == 2) {
$lev = 17;
}
else {
$lev = 0;
}
return $lev;
}
function resetChart()
{
unset($_SESSION['stg']);
header('location: ?');
return;
}
function domTree($parent, $wing = 'a')
{
return 'a' . $wing . $parent . ' = {
parent: a' . $parent . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
}
//$code .= 'a'.$left[1].', ' ;
function domCode($wing, $no = 1)
{
$code = 'a' . $wing . ', ';
if ($no == 2) {
$code .= 'aa' . $wing . ', ';
$code .= 'ab' . $wing . ', ';
}
if ($no == 3) {
$code .= 'aa' . $wing . ', ';
$code .= 'ab' . $wing . ', ';
$code .= 'aaa' . $wing . ', ';
$code .= 'aba' . $wing . ', ';
$code .= 'aab' . $wing . ', ';
$code .= 'abb' . $wing . ', ';
}
return $code;
}
function domChild($parent, $wing, $no = 1)
{
$tree = 'a' . $wing . ' = {
parent: a' . $parent . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
if ($no == 2) {
$tree .= 'aa' . $wing . ' = {
parent: a' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
$tree .= 'ab' . $wing . ' = {
parent: a' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
}
if ($no == 3) {
$tree .= 'aa' . $wing . ' = {
parent: a' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
$tree .= 'ab' . $wing . ' = {
parent: a' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
//end of two
$tree .= 'aaa' . $wing . ' = {
parent: aa' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
$tree .= 'aba' . $wing . ' = {
parent: aa' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
$tree .= 'aab' . $wing . ' = {
parent: ab' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
$tree .= 'abb' . $wing . ' = {
parent: ab' . $wing . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
}
return $tree;
}
function childTree($parent, $child, $cname)
{
global $img;
return 'a' . $child . ' = {
parent: a' . $parent . ',
text:{
name: "' . $cname . '",
title: "",
contact: "",
},
link: {
href: "?u-ref=' . sha1($child) . '"
},
image: "../headshots/' . $img . '"
}, ';
}
function childTreeAll($parent, $child, $cname)
{
global $mystage;
return 'a' . $child . ' = {
parent: a' . $parent . ',
text:{
name: "' . $cname . '",
title: "",
contact: "",
},
link: {
href: "?u-ref=' . sha1($child) . '"
},
image: "../headshots/users.png"
}, ';
}
function childTreex($parent, $child, $cname)
{
global $mystage;
return 'a' . $child . ' = {
parent: a' . $parent . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/use.png"
}, ';
}
function gTreex($opt = '')
{
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;
$gen1 = $this->wildGen($randomKey, 1);
//$randomKey = $this->userName('sn');
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->userNameWild('user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/feeder.png"
},';
if ($gen1 == 0) {
$code .= 'aa' . $randomKey . ', ';
$tree .= $this->domTree($randomKey);
$code .= 'ab' . $randomKey . ', ';
$tree .= $this->domTree($randomKey, 'b');
} elseif ($gen1 == 1) {
$qu = $db->query("SELECT * FROM user WHERE a1 = '$randomKey' ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$code .= 'a' . $row['sn'] . ', ';
$tree .= $this->childTree($randomKey, $row['sn'], $row['user']);
}
$code .= 'aa' . $randomKey . ', ';
$tree .= $this->domTree($randomKey);
} else {
$qu = $db->query("SELECT * FROM user WHERE a1 = '$randomKey' ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($qu)) {
$code .= 'a' . $row['sn'] . ', ';
$tree .= $this->childTree($randomKey, $row['sn'], $row['user']);
}
}
$code .= '];';
//$report = 'Showing your '.$this->stgTost($mystage).' geneology ';
//$count = 0;
return $tree . $code;
}
function level2($key)
{
if ($this->team1($key) == 12) {
return 2;
} else {
return 0;
}
}
// function allTree($opt = '')
// {
// global $db, $key, $report, $count, $user, $randomKey, $mystage;
// 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;
// $mystage = 0;
// $code = 'chart_config = [
// config, a' . $randomKey . ', ';
// $tree = 'var config = {
// container: "#basic-example",
// nodeAlign: "BOTTOM",
// connectors: {
// type: "step"
// },
// node: {
// HTMLclass: "nodeExample1"
// }
// },';
// $tree .= 'a' . $randomKey . ' = {
// text: {
// name: "' . $this->userNameWild('user') . '",
// title: "",
// contact: "",
// },
// link: {
// href: ""
// },
// image: "../headshots/users.png"
// },';
// $a = 1;
// $x = 1;
// $nu = 0;
// while ($a <= 3) {
// $b = $a++;
// $gen = 'a' . $b;
// $qu = $db->query("SELECT * FROM user WHERE $gen = '$randomKey' ") or die(mysqli_error());
// while ($row = mysqli_fetch_assoc($qu)) {
// $child = $row['sn'];
// $parent = $row['a1'];
// // $stage = $this->wildLevel2($child,2);
// $y = $x++;
// //$x = ($b==1) ? 'a' : 'b';
// //left child
// if ($b < 3) {
// $code .= 'a' . $child . ', ';
// $tree .= $this->childTreeAll($parent, $child, $this->wildUserName($child, 'user'));
// if ($this->wildGen($child, 1) == 0) {
// $code .= 'aa' . $child . ', ';
// $tree .= $this->domTree($child, 'a');
// $code .= 'ab' . $child . ', ';
// $tree .= $this->domTree($child, 'b');
// } elseif ($this->wildGen($child, 1) == 1) {
// $code .= 'aa' . $child . ', ';
// $tree .= $this->domTree($child, 'a');
// }
// } else {
// $code .= 'a' . $child . ', ';
// $tree .= $this->childTreeAll($parent, $child, $this->wildUserName($child, 'user'));
// }
// }
// }
// $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",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->userNameWild('user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/users.png"
},';
if ($this->wildGen($randomKey, 1) == 0) {
$code .= 'aa' . $randomKey . ', ';
$tree .= 'aa' . $randomKey . ' = {
parent: a' . $randomKey . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: "registernew.php?reff=' . $this->userNameWild('user') . '"
},
image: "../headshots/reg.png"
}, ';
$code .= 'ab' . $randomKey . ', ';
$tree .= 'ab' . $randomKey . ' = {
parent: a' . $randomKey . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: "registernew.php?reff=' . $this->userNameWild('user') . '"
},
image: "../headshots/reg.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'];
$code .= 'a' . $row['sn'] . ', ';
$tree .= 'a' . $row['sn'] . ' = {
parent: a' . $row['a1'] . ',
text:{
name: "' . $row['user'] . '",
title: "",
contact: "",
},
link: {
href: "?u-ref=' . sha1($row['sn']) . '"
},
image: "../headshots/users.png"
}, ';
if ($this->wildGen($randomKey, 1) == 1 && $b == 1) {
$code .= 'aa' . $randomKey . ', ';
$tree .= 'aa' . $randomKey . ' = {
parent: a' . $randomKey . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: "registernew.php?reff=' . $this->userNameWild('user') . '"
},
image: "../headshots/reg.png"
}, ';
}
if ($this->wildGen($row['sn'], 1) == 0 && $b < 3) {
$code .= 'aa' . $row['sn'] . ', ';
$tree .= 'aa' . $row['sn'] . ' = {
parent: a' . $row['sn'] . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: "registernew.php?reff=' . $row['user'] . '"
},
image: "../headshots/reg.png"
}, ';
$code .= 'ab' . $row['sn'] . ', ';
$tree .= 'ab' . $row['sn'] . ' = {
parent: a' . $row['sn'] . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: "registernew.php?reff=' . $row['user'] . '"
},
image: "../headshots/reg.png"
}, ';
}
if ($this->wildGen($row['a1'], 1) == 1 && $b < 4) {
$user = $row['a1'];
$code .= 'aa' . $row['a1'] . ', ';
$tree .= 'aa' . $row['a1'] . ' = {
parent: a' . $row['a1'] . ',
text:{
name: "",
title: "",
contact: "",
},
link: {
href: "registernew.php?reff=' . $this->userNameWild('user') . '"
},
image: "../headshots/reg.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()
{
return $this->Sponsored() * 2;
}
function percent($p = 5)
{
return $this->amount * $p / 100;
}
//Withdrawal Methods
function confirmedWithdraw()
{
global $db, $userKey;
$status = STATUSALPHA;
$sql = $db->query("SELECT amount FROM withdraw WHERE id2 = '$userKey' 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;
$status = STATUSBETA;
$sql = $db->query("SELECT amount FROM withdraw WHERE id2 = '$userKey' 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 $report, $count;
$pin = sanitize($_POST['pins']);
$withdrawAmount = $pin * 5;
$authenticate = $_POST['authenticate'];
$type = 'p';
$status = 1;
$stage = $_POST['stage'];
$lev = $_POST['level'];
$uidx = $_POST['uidx'];
$id = $this->Uid();
$accountBalance = $this->totalEarnings($uidx);
$finalbalance = $accountBalance - $withdrawAmount;
$password1 = userName($id,'pass');
if($withdrawAmount > $accountBalance){
$report = "Insufficient Balance";
$count = 1;
}
// elseif ($withdrawAmount < $this->minwithdraw){
// $report = "Minimum Witdrawal is $".$this->minwithdraw;
// $count = 1;
// }
elseif (password_verify($authenticate, $password1)) {
$this->withdrawProcess($withdrawAmount,$accountBalance, $type, $status);
$this->sellEpins($id,$pin, 'Wallet Pay');
$_SESSION['report'] = $pin. ' PIN(s) Purchased Successfully';
header("Location:?#");
} else {
$report = 'Authentication failed or insufficient balance';
$count = 1;
}
return;
}
function confirmPinPayment()
{
global $db;
$payref = $_GET['tr_referenca'];
$epinqty = $_SESSION['pins'];
if ($_GET['tr_referenca'] == $_SESSION['referenca']) {
$this->sellEpins($epinqty, 'Card Pay');
$_SESSION['report'] = 'Payment Successful. Your newly purchases E-PINs (' . $epinqty . ') have been delivered to you';
}
unset($_SESSION['referenca']);
header("location: ?payment-confirmed=online");
return;
}
//Withdrawal Order
function approvePinRequest()
{
global $db, $epinqty, $paytype, $report, $count;
$epinqty = sanitize($_POST['pins']);
$sn = $_POST['approvePinRequest'];
//$withdrawAmount = $epinqty*10;//$this->$dolafee;
$approval = md5($_POST['approval']);
$type = 'E-PIN Request';
$status = 1;
$sq = $db->query("SELECT * FROM payment WHERE sn = '$sn' ");
$row = mysqli_fetch_assoc($sq);
$key = $row['id'];
//$accountBalance = $this->accountBalance();
//$finalbalance = $accountBalance-$withdrawAmount;
if ($this->userName('pass') == $approval) {
//$this->withdrawProcess($withdrawAmount,$type,$status);
$sql = $db->query("UPDATE payment SET status=1, buy='$epinqty' WHERE sn = '$sn' ");
$this->sellEpinsAdmin($epinqty, $key);
$report = 'Transaction Successful';
} else {
$report = 'Transaction Unsuccessful. Authentication failed or insufficient balance';
$count = 1;
}
return;
}
//Withdrawal Order
function deletePinRequest()
{
global $db, $epinqty, $paytype, $report, $count;
$sn = $_POST['deletePinRequest'];
$approval = md5($_POST['approval']);
if ($this->userName('pass') == $approval) {
$sq = $db->query("DELETE FROM payment WHERE sn = '$sn' ");
$report = 'Successfully Deleted Pin Request';
} else {
$report = 'Transaction Unsuccessful. Authentication failed';
$count = 1;
}
return;
}
//Withdrawal Order
function requestEpins()
{
global $db, $userKey, $report, $count;
$epinqty = sanitize($_POST['pins']);
$details = sanitize($_POST['details']);
$approval = md5($_POST['approval']);
$type = 'E-PIN Request';
$doc = $this->win_hashs(5) . str_replace(" ", "-", $_FILES['docc']['name']);
define('upload', 'payment/');
if (isset($doc) AND strlen($doc) > 4) {
$success = move_uploaded_file($_FILES['docc']['tmp_name'], upload . $doc);
}
if ($this->userName('pass') == $approval) {
$msg = $db->query("INSERT INTO payment (id,qty,details,type,image)
VALUES('$userKey','$epinqty','$details','$type','$doc')") or die(mysqli_error());
$report = 'Transaction Request Sent';
} else {
$report = 'Transaction Request Not Sent. Authentication failed or insufficient balance';
$count = 1;
}
return;
}
function GenerateUserPin(){
global $db,$report,$count;
$pin = sanitize($_POST['pin']);
$username = sanitize($_POST['username']);
$sql = $db->query("SELECT * FROM user WHERE user='$username' LIMIT 1");
$row = $sql->fetch_assoc();
if($sql->num_rows < 1){
$count = 1;
$report = "Username Does not Exist, Please check and Try Again";
}
else {
$id = $row['id'];
$i = 1; $sum1 = $sum2 = 0;
while ($i <= $pin){
$p = substr(str_shuffle(str_repeat('123456789', 12)), 0, 12);
$sql1=$db->query("SELECT * FROM pin WHERE pin='$p'");
if($sql1->num_rows > 0){
$sum1 += 1;
}
else {
$sum2 += 1;
$db->query("INSERT INTO pin (pin,rep,tm) VALUES('$p','$id','1')");
}
$i = $i + 1;
}
// $_SESSION['rs'] = $sum1." Rejected<br>". $sum2." PIN(s) Succcessfully Generated";
$report = $sum1." Rejected<br>". $sum2." PIN(s) Succcessfully Generated";
$msg = 'Pin purchase successful. The E-PINs you purchased (' . $sum2 . ') have been delivered to you. click on BUY & MANAGE E-PINs from the menu to see the PINs';
$this->message($id, $msg);
// header("Location:?#");
}
}
function sellEpins($id,$epinqty, $type = 'Admin Auto')
{
global $db;
$i = 1;
while ($i <= $epinqty) {
$e = $i++;
$pin = substr(str_shuffle(str_repeat('123456789', 12)), 0, 12);
$db->query("INSERT INTO pin (pin,rep,tm) VALUES('$pin','$id','$type')");
}
$msg = 'Pin purchase successful. The E-PINs you purchased (' . $epinqty . ') have been delivered to you. click on BUY & MANAGE E-PINs from the menu to see the PINs';
$this->message($id, $msg);
return;
}
function sellEpinsAdmin($epinqty, $key)
{
global $db;
$i = 1;
while ($i <= $epinqty) {
$e = $i++;
$pin = substr(str_shuffle(str_repeat('1234567890', 12)), 0, 12);
$db->query("INSERT INTO pin (pin,rep,tm) VALUES('$pin','$key','Request')");
}
$msg = 'Pin purchase successful. The E-PINs you purchased (' . $epinqty . ') have been delivered to you. click on BUY & MANAGE E-PINs from the menu to see the PINs';
$this->message($key, 'Admin', $msg, 'E-PIN Purchase');
return;
}
function withdrawOrder()
{
global $report, $count;
$withdrawAmount = sanitize($_POST['withdrawAmount']);
$currentpass = md5($_POST['currentpass']);
$withdrawAmount = $withdrawAmount + $this->withdrawcharge;
$uid = $this->Uid();
$uidx = $this->idToKey($uid);
$type = 'Cash Withdrawal';
$bal = $this->totalEarnings($uidx);
$status = 0;
if ($currentpass == $this->userName('pass') AND $withdrawAmount <= $bal) {
$this->withdrawProcess($withdrawAmount,$bal, $type, $status);
} else {
$report = 'Password confirmation failed or invalid amount, please try again';
$count = 1;
}
return;
}
function transferOrder()
{
global $db, $report, $count, $userKey;
$withdrawAmount = sanitize($_POST['withdrawAmount']);
$recKey = sanitize($_POST['reckey']);
$currentpass = md5($_POST['currentpass']);
if ($withdrawAmount < 2 OR $withdrawAmount > 4 OR $withdrawAmount > $this->Balance()) {
$report = 'You have entered an invalid amount';
$count = 1;
} else {
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
if ($currentpass == $this->userName('pass')) {
$sql = $db->query("INSERT INTO transfer (id,id2,amount,tno) VALUES ('$userKey','$recKey','$withdrawAmount','$tno')");
if ($sql) {
$report = 'Your transfer has been successfully completed';
unset($_SESSION['recKey']);
}
} else {
$report = 'Password confirmation failed, please try again';
$count = 1;
}
}
return;
}
function courseOrder()
{
global $db, $report, $count, $userKey;
$course = $_POST['course'];
$currentpass = md5($_POST['currentpass']);
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
if ($currentpass == $this->userName('pass')) {
$sql = $db->query("INSERT INTO download (id,course,tno) VALUES ('$userKey','$course','$tno')");
if ($sql) {
$report = 'Your preferred course has been successfully submited';
}
} else {
$report = 'Password confirmation failed, please try again';
$count = 1;
}
return;
}
function findCourse()
{
global $db, $userKey;
$sql = $db->query("SELECT * FROM download WHERE id='$userKey' ") or die(mysqli_error());
$find = (mysqli_num_rows($sql) > 0) ? TRUE : FALSE;
return $find;
}
function withdrawProcess($withdrawAmount, $accountBalance, $type, $status)
{
global $db,$report, $count;
$userKey = $this->Uid();
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $accountBalance - $withdrawAmount;
$sql = $db->query("INSERT INTO withdraw (id,inibalance,amount,finalbalance,status,type,tno) VALUES ('$userKey','$accountBalance','$withdrawAmount','$finalbalance','$status','$type','$tno')");
if ($sql) {
$report = 'Your withdrawal request has been successfully submitted';
$this->logdraw($tno);
}
return;
}
function withdrawProcess2($userKey, $withdrawAmount, $accountBalance, $type, $status)
{
global $db,$report, $count;
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $accountBalance - $withdrawAmount;
$sql = $db->query("INSERT INTO withdraw (id,inibalance,amount,finalbalance,status,type,tno) VALUES ('$userKey','$accountBalance','$withdrawAmount','$finalbalance','$status','$type','$tno')");
if ($sql) {
$report = 'Your withdrawal request has been successfully submitted';
$this->logdraw($tno);
}
return;
}
function savingsProcess($withdrawAmount, $accountBalance, $type, $status)
{
global $db,$report, $count;
$userKey = $this->Uid();
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$ctime = time();
$finalbalance = $accountBalance - $withdrawAmount;
$sql = $db->query("INSERT INTO savings (id,amount,ctime,finalbalance,status,type,tno) VALUES ('$userKey','$withdrawAmount','$ctime','$finalbalance','$status','$type','$tno')");
if ($sql) {
$report = 'Your savings deposit request has been successfully submitted';
$this->logdraw($tno);
}
return;
}
function withdrawProcessGm($withdrawAmount, $accountBalance, $type, $status, $recipient='')
{
global $db,$report, $count;
$userKey = $this->Uid();
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $accountBalance - $withdrawAmount;
$sql = $db->query("INSERT INTO gmwithdraw (id,id2,inibalance,amount,finalbalance,status,type,tno) VALUES ('$userKey','$recipient','$accountBalance','$withdrawAmount','$finalbalance','$status','$type','$tno')");
if ($sql) {
$report = 'Your withdrawal request has been successfully submitted';
$this->logdraw($tno);
}
return;
}
/////
function withdrawProcessGmToCci($withdrawAmount, $accountBalance, $type, $status, $recipient='')
{
global $db,$report, $count;
$userKey = $this->Uid();
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$finalbalance = $accountBalance - $withdrawAmount;
$sql = $db->query("INSERT INTO gmwithdraw (id,id2,inibalance,amount,finalbalance,status,type,tno) VALUES ('$userKey','','$accountBalance','$withdrawAmount','$finalbalance','$status','$type','$tno')");
$sql = $db->query("INSERT INTO transfer (id,id2,inibalance,amount,finalbalance,status,type,tno) VALUES ('','$userKey','$accountBalance','$withdrawAmount','$finalbalance','$status','$type','$tno')");
if ($sql) {
$report = 'Your withdrawal request has been successfully submitted';
$this->logdraw($tno);
}
return;
}
function logdraw($tno)
{
global $db;
$sql = $db->query("INSERT INTO logdraw SELECT * FROM withdraw WHERE tno = '$tno' ");
return;
}
function withdrawHistory()
{
global $db, $userKey;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Transaction No</th>
<th>Amount</th>
<th>Charges</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$i = 1;
$sql = $db->query("SELECT * FROM withdraw WHERE id = '$userKey' ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
$status = ($row['status'] == 1) ? 'Complete' : 'Pending';
$amt = ($row['type'] == 'Cash Withdrawal') ? '$' . ($row['amount'] - 0.5) : '$' . $row['amount'];
$charge = ($row['type'] == 'Cash Withdrawal') ? '$' . '0.5' : 0;
$table .= ' <tr>
<td>' . $e . '</td>
<td>' . $row['tno'] . '</td>
<td>' . $amt . '</td>
<td>' . $charge . '</td>
<td>' . $row['created'] . '</td>
<td>' . $status . '</td>
</tr>';
}
$table .= ' </tbody>
</table>';
return $table;
}
function transferHistory()
{
global $db, $userKey;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Transaction No</th>
<th>Amount</th>
<th>Type</th>
<th>Description</th>
<th>From</th>
<th>To</th>
<th>Date</th>
</tr>
</thead>
<tbody>';
$i = 1;
$amt = 0;
$sql = $db->query("SELECT * FROM transfer WHERE id = '$userKey' OR id2 = '$userKey' ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
$amt += ($row['id'] == $userKey) ? $row['amount'] : 0;
$type = ($row['id'] == $userKey) ? 'Debit' : 'Credit';
$des = ($row['id'] == $userKey) ? 'Transfer to ' . $this->uName($row['id2']) : 'Received from ' . $this->uName($row['id']);
//$sender = ($row['id']==$userKey) ? $this->uName($row['id2']) : $this->uName($row['id']);
$table .= ' <tr>
<td>' . $e . '</td>
<td>' . $row['tno'] . '</td>
<td>$' . $row['amount'] . '</td>
<td>' . $type . '</td>
<td>' . $des . '</td>
<td>' . $this->uName($row['id']) . '</td>
<td>' . $this->uName($row['id2']) . '</td>
<td>' . $row['created'] . '</td>
</tr>';
}
$table .= ' </tbody>
</table>';
return $table;
}
/*
function fileDownload(){
global $db,$userKey;
$table = '<table class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Code</th>
<th>Course</th>
<th>File</th>
<th>Date</th>
<th>Download</th>
</tr>
</thead>
<tbody>';
$i=1; $amt = 0;
$sql=$db->query("SELECT * FROM download WHERE id = '$userKey' " )or die(mysqli_error());
while($row = mysqli_fetch_assoc($sql)){ $e=$i++;
$amt += ($row['id']==$userKey) ? $row['amount'] : 0;
$type = ($row['id']==$userKey) ? 'Debit' : 'Credit';
$table .= ' <tr>
<td>'.$e.'</td>
<td>'.$row['tno'].'</td>
<td></td>
<td>my-course-material.pdf</td>
<td>'.$row['created'].'</td>
<td><button onclick="document.getElementById('link').click()">Download Now!</button>
<a id="link" href="treant/opt'.$row['course'].'.pdf" download="my-course-material.pdf" hidden></a></td>
</tr>';
}
$table .= ' </tbody>
</table>';
return $table;
}
*/
function transferHistoryAdmin()
{
global $db, $userKey;
$table = '<table id="example1" class="display nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>SN</th>
<th>Transaction No</th>
<th>Amount</th>
<th>Type</th>
<th>From</th>
<th>To</th>
<th>Date</th>
</tr>
</thead>
<tbody>';
$i = 1;
$amt = 0;
if (isset($_GET['quser'])) {
$quser = $this->uNameUser($_GET['quser'], 'id');
$sql = $db->query("SELECT * FROM transfer WHERE id = '$quser' OR id2 = '$quser' ORDER BY sn DESC ") or die(mysqli_error());
} else {
$sql = $db->query("SELECT * FROM transfer ORDER BY sn DESC LIMIT 100 ") or die(mysqli_error());
}
while ($row = mysqli_fetch_assoc($sql)) {
$e = $i++;
$amt += ($row['id'] == $userKey) ? $row['amount'] : 0;
$type = ($row['id'] == $userKey) ? 'Debit' : 'Credit';
//$sender = ($row['id']==$userKey) ? $this->uName($row['id2']) : $this->uName($row['id']);
$table .= ' <tr>
<td>' . $e . '</td>
<td>' . $row['tno'] . '</td>
<td>$' . $row['amount'] . '</td>
<td>' . $type . '</td>
<td><a href="?quser=' . $this->uName($row['id']) . '">' . $this->uName($row['id']) . '</a></td>
<td><a href="?quser=' . $this->uName($row['id2']) . '">' . $this->uName($row['id2']) . '</a></td>
<td>' . $row['created'] . '</td>
</tr>';
}
$table .= ' </tbody>
</table>';
return $table;
}
function transfered($opt = 1)
{
global $db, $userKey;
$amt = 0;
$amt2 = 0;
$sql = $db->query("SELECT * FROM transfer WHERE id = '$userKey' OR id2 = '$userKey' ") or die(mysqli_error());
while ($row = mysqli_fetch_assoc($sql)) {
$amt += ($row['id'] == $userKey) ? $row['amount'] : 0;
$amt2 += ($row['id2'] == $userKey) ? $row['amount'] : 0;
}
$sum = ($opt == 1) ? $amt : $amt2;
return $sum;
}
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 = 1;
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 approveIncentiveOrder()
{
global $db, $report, $count;
$tno = $_POST['approveIncentiveOrder'];
$currentpass = md5($_POST['currentpass']);
$status = 1;
if ($this->userName('pass') == $currentpass) {
$sql = $db->query("UPDATE award SET remark = '$status' WHERE sn = '$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) OR $this->userName('sn') == 1) {
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 wildUserKeys($key, $col = '')
{
global $db;
$que = $db->query("select * FROM user WHERE id = '$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 = '';
$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="box bg-white">
<div class="box-block">
<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">
<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="box bg-white">
<div class="box-block">
<!-- .tabs -->
<ul class="nav nav-tabs tabs customtab">
<li class="active tab col-md-6">
<a href="#profile" data-toggle="tab"> <span class="visible-xs"><i class="ti-user"></i></span> <span class="hidden-xs">Profile</span> </a>
</li>
<li class="tab col-md-6">
<a href="#settings" data-toggle="tab" aria-expanded="false"> <span class="visible-xs"><i class="ti-user"></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://covisclubinternational.com/signup.php?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://covisclubinternational.com/signup.php?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">Update Profile</h5>
<hr>
<div class="form-group">
<label class="col-md-12">Phone Number</label>
<div class="col-md-12">
<input type="text" name="phone" class="form-control" value="' . $row['phone'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Residential Address</label>
<div class="col-md-12">
<input type="text" name="address" class="form-control" value="' . $row['address'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">State</label>
<div class="col-md-12">
<input type="text" name="state" class="form-control" value="' . $row['state'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">City</label>
<div class="col-md-12">
<input type="text" name="city" class="form-control" value="' . $row['city'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Bank</label>
<div class="col-md-12">
<input type="text" name="bank" class="form-control" value="' . $row['bank'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Account Number</label>
<div class="col-md-12">
<input type="text" name="accountno" class="form-control" value="' . $row['accountno'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12"></label>
<div class="col-md-12">
<button type="submit" name="UpdateUser" class="btn btn-success">Save Update</button>
</div>
</form>
</div>
<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 userProfileDataSearch($keys, $a)
{
global $db;
$sql = $db->query("SELECT * FROM user WHERE sn = '$keys' ") or die(mysqli_error());
$row = mysqli_fetch_assoc($sql);
$activate = ($row['status'] == 1) ? '<button class="btn btn-danger" name="DeactivateUser" value="' . $row['id'] . '">Deactivate ' . ucwords($row['firstname'] . ' ' . $row['lastname']) . '</button>' : '<button class="btn btn-success" name="DeactivateUser" value="' . $row['id'] . '">Activate ' . ucwords($row['firstname'] . ' ' . $row['lastname']) . '</button>';
$updatepin = ($this->pinMultiple($row['user']) > 1) ? '<br><br><br><br>
<p>UPDATE USER PIN</p><hr class="p-0">
<p>PIN <input type="text" name="pin" class="form-control" value="' . $row['pin'] . '"></p><p><br><button class="btn btn-primary" name="UpdatePin" value="' . $row['id'] . '">Update PIN for ' . ucwords($row['firstname'] . ' ' . $row['lastname']) . '</button></p><p><br></p>' . $this->pinMultiple2($row['user']) : '';
$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="user-content text-center">
<b><br>' . ucwords($row['firstname'] . ' ' . $row['lastname']) . '</b>
<h5 class="">' . $row['email'] . '</h5> </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>
<b>SEND MESSAGE TO USER<br></b>
<form method="post">
<p><br>Message Title: <input class="form-control" name="subject"></p>
<p><br>Message: <textarea class="form-control" rows="10" name="msg"></textarea></p>
<p><br><button class="btn btn-primary pull-right" name="SendUserMessage" value="' . $row['id'] . '">Send Message to ' . ucwords($row['firstname'] . ' ' . $row['lastname']) . '</button></p></form>
<form method="post">
<br><br><br><br><br>
<p>DEACTIVATE/ACTIVATE USER</p><hr class="p-0">
<p><br>' . $activate . '</p></form>
<form method="post">
' . $updatepin . '</form>
</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://covisclubinternational.com/signup.php?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://covisclubinternational.com/signup.php?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">Update Profile</h5>
<hr>
<div class="form-group">
<label class="col-md-12">Other Names</label>
<div class="col-md-12">
<input type="text" placeholder="" name="lastname" class="form-control" value="' . $row['lastname'] . '"> </div>
</div>
<div class="form-group">
<label for="example-email" class="col-md-12">Email</label>
<div class="col-md-12">
<input type="text" placeholder="" class="form-control" name="email" value="' . $row['email'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Phone Number</label>
<div class="col-md-12">
<input type="text" name="phone" class="form-control" value="' . $row['phone'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Residential Address</label>
<div class="col-md-12">
<input type="text" name="address" class="form-control" value="' . $row['address'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">State</label>
<div class="col-md-12">
<input type="text" name="state" class="form-control" value="' . $row['state'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">City</label>
<div class="col-md-12">
<input type="text" name="city" class="form-control" value="' . $row['city'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Bank</label>
<div class="col-md-12">
<input type="text" name="bank" class="form-control" value="' . $row['bank'] . '"> </div>
</div>
<div class="form-group">
<label class="col-md-12">Account Number</label>
<div class="col-md-12">
<input type="text" name="accountno" class="form-control" value="' . $row['accountno'] . '"> </div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" name="UpdateUser2" class="btn btn-success">Save Update</button>
</div>
</div>
</form>
<form method="post" class="form-horizontal">
<h5 class="m-t-30">Password Reset</h5>
<hr>
<div class="form-group">
<label class="col-md-12">Admin 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="changePassword2" 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="updatePhoto2">Update Photograph</button>
</div>
</div>
</div>
</form>
<!-- /.tabs3 -->
</div>
</div>
</div>
</div>';
return $$a;
}
function covisSearchTree3($stage)
{
global $db;
$userkey = isset($_SESSION['searchid'])?$_SESSION['searchid']:$_SESSION['user_id'];
$randomKey = $this->idToKey($userkey);
$key = $randomKey;
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKey($userkey, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
},';
$i=1;
$n = $randomKey . ',';
$level = $this->keyToLevel($key);
$even = $this->levelToEven($level);
$even = isset($_SESSION['stage'])?$this->stageToEven($_SESSION['stage']):$even;
if($level<5 OR $_SESSION['stage']==2){
$sql = $db->query("SELECT * FROM user WHERE (a1='$key' OR a2='$key' OR a3='$key' OR a4='$key' OR a5='$key' OR a6='$key' OR a7='$key') AND level>='$even' ") or die(mysqli_error()); }else{
$sql = $db->query("SELECT * FROM user WHERE (a1='$key' OR a2='$key' OR a3='$key' OR a4='$key') AND level>='$even' ") or die(mysqli_error());
}
while ($row = mysqli_fetch_assoc($sql) AND $i<=39){ $e=$i++;
// if($this->stageCalc($row['sn'])>=$stage){
$n .= $row['sn'] . ','; }
//}
$h = explode(',', $n);
$s = count($h) - 1;
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 3) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->wildUserName($h[$e], 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
$code .= '];';
return $tree . $code;
}
function covisSearchTree()
{
global $db;
$key = isset($_SESSION['searchid'])?$_SESSION['searchid']:$_SESSION['user_id'];
$randomKey = $this->idToKey($key);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKey($key, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/st11.png"
},';
$sql = $db->query("SELECT * FROM user WHERE a1='$randomKey' OR a2='$randomKey' ");
while ($row = mysqli_fetch_assoc($sql)) {
$code .= 'a' . $row['sn'] . ', ';
$tree .= 'a' . $row['sn'] . ' = {
parent: a' . $row['a1'] . ',
text:{
name: "' . $this->wildUserName($row['sn'], 'user') . '",
title: "",
contact: "",
},
link: {
href: "?u-ref='.sha1($row['sn']).'&st=1"
},
image: "../headshots/st1.png"
}, ';
}
$code .= '];';
return $tree . $code;
}
function Uid()
{
$uid = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 0;
return $uid;
}
function covisTree($key)
{
global $db;
$randomKey = $this->idToKey($key);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKey($key, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/st11.png"
},';
$sql = $db->query("SELECT * FROM user WHERE a1='$randomKey' LIMIT 3 ");
while ($row = mysqli_fetch_assoc($sql)) { $sn=$row['sn']; $a1=$row['a1'];
$code .= 'a' . $sn . ', ';
$tree .= 'a' . $sn . ' = {
parent: a' . $a1 . ',
text:{
name: "' . $this->wildUserName($sn, 'user') . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$sn.'"
},
image: "../headshots/st1.png"
}, ';
$sq = $db->query("SELECT * FROM user WHERE a1='$sn' LIMIT 3 ");
while ($ro = mysqli_fetch_assoc($sq)) {$sn2=$ro['sn'];
$code .= 'a' . $sn2 . ', ';
$tree .= 'a' . $sn2 . ' = {
parent: a' . $sn . ',
text:{
name: "' . $this->wildUserName($sn2, 'user') . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$sn2.'"
},
image: "../headshots/st1.png"
}, ';
}
}
$code .= '];';
return $tree . $code;
}
function covisTreeS2s($key)
{
global $db;
$randomKey = $this->idToKey($key);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKey($key, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/st22.png"
},';
$sql = $db->query("SELECT * FROM user WHERE a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey' ");
while ($row = mysqli_fetch_assoc($sql)) { $l = $row['level'];
$name = $l>1 ? $this->wildUserName($row['sn'], 'user') : '...';
$img = $l>1 ? '../headshots/st2.png' : '../headshots/uses.png';
$code .= 'a' . $row['sn'] . ', ';
$tree .= 'a' . $row['sn'] . ' = {
parent: a' . $row['a1'] . ',
text:{
name: "' . $name . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$row['sn'].'"
},
image: "'.$img.'"
}, ';
}
$code .= '];';
return $tree . $code;
}
function covisTree2()
{
global $db;
$key = $_SESSION['user_id'];
$img = "users.png";
$randomKey = $this->idToKey($key);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKey($key, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$img.'"
},';
$n = $randomKey . ',';
$sql = $db->query("SELECT * FROM user WHERE a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey' ");
while ($row = mysqli_fetch_assoc($sql)) {
$n .= $row['sn'] . ',';
}
$h = explode(',', $n);
$s = count($h) - 1;
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 3) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->wildUserName($h[$e], 'user') . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$row['sn'].'"
},
image: "../headshots/'.$img.'"
}, ';
}
$code .= '];';
return $tree . $code;
}
function stageImage1($stage){
$img = $img = "st22.png";
if($stage == 2){$img = "st22.png";}
elseif($stage == 3){$img = "st33.png";}
elseif($stage == 4){$img = "st44.png";}
elseif($stage == 5){$img = "st55.png";}
elseif($stage > 5){$img = "st66.png";}
return $img;
}
function stageImage($stage){
$img = $img = "st2.png";
if($stage == 2){$img = "st2.png";}
elseif($stage == 3){$img = "st3.png";}
elseif($stage == 4){$img = "st4.png";}
elseif($stage == 5){$img = "st5.png";}
elseif($stage > 5){$img = "st6.png";}
return $img;
}
function covisTree3($stage)
{
global $db;
$userkey = $_SESSION['user_id'];
$randomKey = $this->idToKey($userkey);
$key = $randomKey;
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKey($userkey, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
},';
$i=1;
$n = $randomKey . ',';
$level = $this->keyToLevel($key);
$even = $this->levelToEven($level);
$even = isset($_SESSION['stage'])?$this->stageToEven($_SESSION['stage']):$even;
if($level<5 OR $_SESSION['stage']==2){
$sql = $db->query("SELECT * FROM user WHERE (a1='$key' OR a2='$key' OR a3='$key' OR a4='$key' OR a5='$key' OR a6='$key' OR a7='$key') AND level>='$even' ") or die(mysqli_error()); }else{
$sql = $db->query("SELECT * FROM user WHERE (a1='$key' OR a2='$key' OR a3='$key' OR a4='$key') AND level>='$even' ") or die(mysqli_error());
}
while ($row = mysqli_fetch_assoc($sql) AND $i<=39){ $e=$i++;
// if($this->stageCalc($row['sn'])>=$stage){
$n .= $row['sn'] . ','; }
// }
$h = explode(',', $n);
$s = count($h) - 1;
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 3) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->wildUserName($h[$e], 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
$code .= '];';
return $tree . $code;
}
function stageTeam($uid,$stage){
global $db;
$randomKey = $this->idToKey($uid);
$level = $this->idToKey($uid,'level');
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
$base = $this->stageToEven($stage);
$limit = $stage==2 ? 13 : 17;
$legs = [$left,$right,$leg3];
$i=0; $a=1; $b=0;
while($i<3){ $e=$i++;
$leg=$legs[$e];
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg' OR a1='$leg' OR a2='$leg' OR a3='$leg' OR a4='$leg' OR a5='$leg' OR a6='$leg' OR a7='$leg' OR a8='$leg' OR a9='$leg' OR a10='$leg' OR a11='$leg' OR a12='$leg' OR a13='$leg' OR a14='$leg' OR a15='$leg' OR a16='$leg' OR a17='$leg' OR a18='$leg' OR a19='$leg' OR a20='$leg' OR a21='$leg' OR a22='$leg' OR a23='$leg' OR a24='$leg' OR a25='$leg' OR a26='$leg' OR a27='$leg' OR a28='$leg' OR a29='$leg' OR a30='$leg') AND level >='$base' LIMIT $limit ");
$b += mysqli_num_rows($sql);
}
// if($stage==2){ $sql = $db->query("SELECT * FROM user WHERE (a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey') AND level >='$base' ");
// return mysqli_num_rows($sql);
// }
$team = $b>39 ? 39 : $b;
// if($level<3){$team=0;}elseif($level==3){$team=3;}elseif($level==4){$team=12;} //replace with 1
return $team; //replace with 2
}
function stage2l2Team($uid){
global $db;
$randomKey = $this->idToKey($uid);
$level = $this->idToKey($uid,'level');
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
$limit = 4 ;
$legs = [$left,$right,$leg3];
$i=0; $a=1; $b=0;
while($i<3){ $e=$i++;
$leg=$legs[$e];
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg' OR a1='$leg' OR a2='$leg' OR a3='$leg' OR a4='$leg' OR a5='$leg' OR a6='$leg' OR a7='$leg' OR a8='$leg' OR a9='$leg' OR a10='$leg' OR a11='$leg' OR a12='$leg' OR a13='$leg' OR a14='$leg' OR a15='$leg' OR a16='$leg' OR a17='$leg' OR a18='$leg' OR a19='$leg' OR a20='$leg' OR a21='$leg' OR a22='$leg' OR a23='$leg' OR a24='$leg' OR a25='$leg' OR a26='$leg' OR a27='$leg' OR a28='$leg' OR a29='$leg' OR a30='$leg') AND level >= 2 LIMIT $limit ");
$b += mysqli_num_rows($sql);
}
return $b;
}
function stageTeamPromo($uid){
global $db;
$stage =3;
$randomKey = $this->idToKey($uid);
$level = $this->idToKey($uid,'level');
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
$base = $this->stageToEven($stage);
$x = [];
$legs = [$left,$right,$leg3];
$i=0; $a=1; $b=0;
while($i<3){ $e=$i++;
$leg=$legs[$e];
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg' OR a1='$leg' OR a2='$leg' OR a3='$leg' OR a4='$leg' OR a5='$leg' OR a6='$leg' OR a7='$leg' OR a8='$leg' OR a9='$leg' OR a10='$leg' OR a11='$leg' OR a12='$leg' OR a13='$leg' OR a14='$leg' OR a15='$leg' OR a16='$leg' OR a17='$leg' OR a18='$leg' OR a19='$leg' OR a20='$leg' OR a21='$leg' OR a22='$leg' OR a23='$leg' OR a24='$leg' OR a25='$leg' OR a26='$leg' OR a27='$leg' OR a28='$leg' OR a29='$leg' OR a30='$leg') AND level >='$base' AND s3>0 LIMIT 8 ");
while($row = mysqli_fetch_assoc($sql)){
$x[] = array('sn'=>$row['sn'], 'id'=>$row['id'], 'leg'=>$e,'legkey'=>$leg);
}
}
return $x;
}
function payDistributor($uidx,$mm){
global $db;
$reguidx=$uidx;
$i=1; $x=$y=$w=$z=0;
$db->query("UPDATE user SET a=9 WHERE sn='$uidx' ");
while($i<=100){ $e=$i++;
$uidx = $this->keyToId($uidx,'sponsor');
if($uidx==0){return;}
if($this->keyToId($uidx,'level')==5 AND $x==0){$x = 1; $this->payDistr($uidx,0.075,1,'Sub Distributor',$reguidx,$e,$mm); }
elseif($this->keyToId($uidx,'level')==6 AND $y==0){$y = 1; $this->payDistr($uidx,0.05,2,'Distributor',$reguidx,$e,$mm); }
elseif($this->keyToId($uidx,'level')==7 AND $w==0){$w = 1; $this->payDistr($uidx,0.025,3,'Top Distributor',$reguidx,$e,$mm); }
elseif($this->keyToId($uidx,'level')>7 AND $z==0){$z = 1; $this->payDistr($uidx,0.1,3,'Mega Distributor',$reguidx,$e,$mm); return; }
}
return;
}
function shareDisPay(){
global $db,$report;
$i=1;//
$sql = $db->query("SELECT * FROM user WHERE mm>202107 AND a<9 LIMIT 200 ");
while($row = mysqli_fetch_assoc($sql)){ $e=$i++; $mm = substr($row['mm'], 2,4);
$this->payDistributor($row['sn'],$mm); }
$report = 'Operation Successful for '.$e.' users';
return;
}
function UpdateTarget(){
global $db,$report;
$d1 = $_POST['d1']; $d2 = $_POST['d2']; $d3 = $_POST['d3']; $d4 = $_POST['d4'];
$sql = $db->query("UPDATE setup SET d1='$d1', d2='$d2', d3='$d3', d4='$d4' ");
$report = 'Operation Successful';
return;
}
function UpdateTarget2(){
global $db,$report;
$a1 = $_POST['a1']; $a2 = $_POST['a2']; $a3 = $_POST['a3']; $a4 = $_POST['a4']; $a5 = $_POST['a5'];
$sql = $db->query("UPDATE setup SET a1='$a1', a2='$a2', a3='$a3', a4='$a4', a5='$a5' ");
$report = 'Operation Successful';
return;
}
function payDistr($id,$amount,$type,$remark,$rep,$g,$mm){ //$type. 1: sub distributor, 2: Distributor. //$uidx: recipient.//
global $db;
//$mm = date('ym');
if(sqL2('walletdist','rep',$rep,'id',$id)==0){
$db->query("INSERT INTO walletdist (id,amount,type,remark,rep,g,mm) VALUES ('$id','$amount','$type','$remark','$rep','$g','$mm')");
//if $gress==$tg ? add to top distributors// dont forget/ list of top 10 distributors
}
return;
}
function creditDistributor($id,$amt,$mm){
global $db;
$amt2 = '-'.$amt; //$mm = date('ym');
$rep = $this->Uid(); $g=0; $sn = userName($id,'sn');
$db->query("INSERT INTO walletdist (id,amount,type,remark,rep,g,mm) VALUES ('$sn','$amt2',0,'Distributor Monthly Bonus','$rep','$g','$mm')");
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$db->query("INSERT INTO transfer (id,id2,amount,status,type,tno) VALUES ('$rep','$id','$amt','1','db','$tno')");
return;
}
function creditDistributors(){
global $db,$report;
$pm=date('ym')-1; $i=1;
//$sql = $db->query("SELECT * FROM distributorORDER BY sn ASC ");
$sql = $db->query("SELECT * FROM distributor WHERE mm='$pm' ");
while($row = mysqli_fetch_assoc($sql)) {
$id = $row['id']; $sn = userName($id,'sn'); $amt = colSum2('walletdist','amount','id',$sn,'mm',$pm);
if($amt>1){ $e=$i++;
$this->creditDistributor($id,$amt,$pm);
}
}
$report = 'Operation Successfully Completed for '.$e.' users';
return;
}
function userStageTeam($uid){
global $db;
$randomKey = $this->idToKey($uid);
$level = $this->idToKey($uid,'level');
if($level==1){$sql = $db->query("SELECT * FROM user WHERE a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey' "); return mysqli_num_rows($sql); }
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
$base = $this->levelToEven($level);
$limit = $base==2 ? 13 : 17;
$legs = [$left,$right,$leg3];
$i=0; $a=1; $b=0;
while($i<3){ $e=$i++;
$leg=$legs[$e];
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg' OR a1='$leg' OR a2='$leg' OR a3='$leg' OR a4='$leg' OR a5='$leg' OR a6='$leg' OR a7='$leg' OR a8='$leg' OR a9='$leg' OR a10='$leg' OR a11='$leg' OR a12='$leg' OR a13='$leg' OR a14='$leg' OR a15='$leg' OR a16='$leg' OR a17='$leg' OR a18='$leg' OR a19='$leg' OR a20='$leg' OR a21='$leg' OR a22='$leg' OR a23='$leg' OR a24='$leg' OR a25='$leg' OR a26='$leg' OR a27='$leg' OR a28='$leg' OR a29='$leg' OR a30='$leg') AND level >='$base' LIMIT $limit ");
while ($row = mysqli_fetch_assoc($sql)){ $b=$a++; }
}
// if($base==2){ $sql = $db->query("SELECT * FROM user WHERE (a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey') AND level >='$base' ");
// return mysqli_num_rows($sql);
// }
return $b>39?39:$b;
// $team = $b>39 ? 39 : $b;
// return $team;
}
function userMonthTeam($uid,$mm){
$key = $this->idToKey($uid);
return sqL2('mkt','ref',$key,'mm',$mm);
}
function stageTeamLegs($uid,$stage){
global $db;
$randomKey = $this->idToKey($uid);
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
$base = $this->stageToEven($stage);
$limit = $base==2 ? 13 : 17;
$legs = [$left,$right,$leg3]; $x=0; $y=0; $z=0;
$i=0; $a=1; $b=0;
while($i<3){ $e=$i++;
$leg=$legs[$e];
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg' OR a1='$leg' OR a2='$leg' OR a3='$leg' OR a4='$leg' OR a5='$leg' OR a6='$leg' OR a7='$leg' OR a8='$leg' OR a9='$leg' OR a10='$leg' OR a11='$leg' OR a12='$leg' OR a13='$leg' OR a14='$leg' OR a15='$leg' OR a16='$leg' OR a17='$leg' OR a18='$leg' OR a19='$leg' OR a20='$leg' OR a21='$leg' OR a22='$leg' OR a23='$leg' OR a24='$leg' OR a25='$leg' OR a26='$leg' OR a27='$leg' OR a28='$leg' OR a29='$leg' OR a30='$leg') AND level >='$base' LIMIT $limit ");
while ($row = mysqli_fetch_assoc($sql)){ $b=$a++; $x += $e==0 ? 1 : 0; $y += $e==1 ? 1 : 0; $z += $e==2 ? 1 : 0;
}
}
return $x.','.$y.','.$z;
}
function covisTreeS2($uid)
{
global $db;
// $uid='tj4ybn64'; $userkey = $uid;
$randomKey = $this->idToKey($uid);
$stage = 2;//isset($_SESSION['stage'])?$_SESSION['stage']:$this->stageCalc($randomKey);
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
$leftl = $this->keyToId($left,'level');
$rightl = $this->keyToId($right,'level');
$leg3l = $this->keyToId($leg3,'level');
// $level = $this->keyToLevel($randomKey);
$base = 2;//$this->stageToEven($stage);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . userName($uid, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
},';
$h = [];
if($left>1){
$sql = $db->query("SELECT * FROM user WHERE (sn='$left' OR a1='$left' OR a2='$left' OR a3='$left' OR a4='$left' OR a5='$left' OR a6='$left' OR a7='$left' OR a8='$left' OR a9='$left' OR a10='$left' OR a11='$left' OR a12='$left' OR a13='$left' OR a14='$left' OR a15='$left' OR a16='$left' OR a17='$left' OR a18='$left' OR a19='$left' OR a20='$left' OR a21='$left' OR a22='$left' OR a23='$left' OR a24='$left' OR a25='$left' OR a26='$left' OR a27='$left' OR a28='$left' OR a29='$left' OR a30='$left') AND level > 1 LIMIT 13 ");
while ($row = mysqli_fetch_assoc($sql)){ $h[] = $row['sn']; }
$s = count($h);
if($s>0){
$un = $this->snToUser($left) ;
$im = '../headshots/'.$this->stageImage($stage) ;
$code .= 'a' . $h[0] . ', ';
$tree .= 'a' . $h[0] . ' = {
parent: a' . $randomKey . ',
text:{
name: "' . $un . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$h[0].'"
},
image: "'.$im.'"
}, ';
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 3) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->snToUser($h[$e]) . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$h[$e].'"
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
}}//left exist
$h = [];
if($right>1){
$sql = $db->query("SELECT * FROM user WHERE (sn='$right' OR a1='$right' OR a2='$right' OR a3='$right' OR a4='$right' OR a5='$right' OR a6='$right' OR a7='$right' OR a8='$right' OR a9='$right' OR a10='$right' OR a11='$right' OR a12='$right' OR a13='$right' OR a14='$right' OR a15='$right' OR a16='$right' OR a17='$right' OR a18='$right' OR a19='$right' OR a20='$right' OR a21='$right' OR a22='$right' OR a23='$right' OR a24='$right' OR a25='$right' OR a26='$right' OR a27='$right' OR a28='$right' OR a29='$right' OR a30='$right') AND level > 1 LIMIT 13 ");
while ($row = mysqli_fetch_assoc($sql)){ $h[] = $row['sn']; }
$s = count($h);
if($s>0){
$un = $this->snToUser($right);
$im = '../headshots/'.$this->stageImage($stage) ;
$code .= 'a' . $h[0] . ', ';
$tree .= 'a' . $h[0] . ' = {
parent: a' . $randomKey . ',
text:{
name: "' . $un . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$h[0].'"
},
image: "'.$im.'"
}, ';
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 3) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->snToUser($h[$e]) . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$h[$e].'"
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
}}//right exist
$h = [];
if($leg3>1){
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg3' OR a1='$leg3' OR a2='$leg3' OR a3='$leg3' OR a4='$leg3' OR a5='$leg3' OR a6='$leg3' OR a7='$leg3' OR a8='$leg3' OR a9='$leg3' OR a10='$leg3' OR a11='$leg3' OR a12='$leg3' OR a13='$leg3' OR a14='$leg3' OR a15='$leg3' OR a16='$leg3' OR a17='$leg3' OR a18='$leg3' OR a19='$leg3' OR a20='$leg3' OR a21='$leg3' OR a22='$leg3' OR a23='$leg3' OR a24='$leg3' OR a25='$leg3' OR a26='$leg3' OR a27='$leg3' OR a28='$leg3' OR a29='$leg3' OR a30='$leg3') AND level > 1 LIMIT 13 ");
while ($row = mysqli_fetch_assoc($sql)){ $h[] = $row['sn']; }
$s = count($h);
if($s>0){
$un = $this->snToUser($leg3);
$im = '../headshots/'.$this->stageImage($stage) ;
$code .= 'a' . $h[0] . ', ';
$tree .= 'a' . $h[0] . ' = {
parent: a' . $randomKey . ',
text:{
name: "' . $un . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$h[0].'"
},
image: "'.$im.'"
}, ';
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 3) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->snToUser($h[$e]) . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$h[$e].'"
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
}}//leg3 exist
$code .= '];';
return $tree . $code;
}
function covisTree4($uid)
{
global $db;
// $uid='tj4ybn64'; $userkey = $uid;
$randomKey = $this->idToKey($uid);
$stage = isset($_SESSION['stage'])?$_SESSION['stage']:$this->stageCalc($randomKey);
$left = $this->myLegs($randomKey);
$right = $this->myLegs($randomKey,1);
$leg3 = $this->myLegs($randomKey,2);
//$base = $this->globeStage($randomKey,2);
// $level = $this->keyToLevel($randomKey);
$base = $this->stageToEven($stage);
$n = $randomKey.',';
if($left>1){
$sql = $db->query("SELECT * FROM user WHERE (sn='$left' OR a1='$left' OR a2='$left' OR a3='$left' OR a4='$left' OR a5='$left' OR a6='$left' OR a7='$left' OR a8='$left' OR a9='$left' OR a10='$left' OR a11='$left' OR a12='$left' OR a13='$left' OR a14='$left' OR a15='$left' OR a16='$left' OR a17='$left' OR a18='$left' OR a19='$left' OR a20='$left' OR a21='$left' OR a22='$left' OR a23='$left' OR a24='$left' OR a25='$left' OR a26='$left' OR a27='$left' OR a28='$left' OR a29='$left' OR a30='$left') AND level >='$base' LIMIT 17 ");
while ($row = mysqli_fetch_assoc($sql)){ $n .= $row['sn'] . '.1,'; }
}//left exist
if($right>1){
$sql = $db->query("SELECT * FROM user WHERE (sn='$right' OR a1='$right' OR a2='$right' OR a3='$right' OR a4='$right' OR a5='$right' OR a6='$right' OR a7='$right' OR a8='$right' OR a9='$right' OR a10='$right' OR a11='$right' OR a12='$right' OR a13='$right' OR a14='$right' OR a15='$right' OR a16='$right' OR a17='$right' OR a18='$right' OR a19='$right' OR a20='$right' OR a21='$right' OR a22='$right' OR a23='$right' OR a24='$right' OR a25='$right' OR a26='$right' OR a27='$right' OR a28='$right' OR a29='$right' OR a30='$right') AND level >='$base' LIMIT 17 ");
while ($row = mysqli_fetch_assoc($sql)){ $n .= $row['sn'] . '.2,'; }
}//right exist
if($leg3>1){
$sql = $db->query("SELECT * FROM user WHERE (sn='$leg3' OR a1='$leg3' OR a2='$leg3' OR a3='$leg3' OR a4='$leg3' OR a5='$leg3' OR a6='$leg3' OR a7='$leg3' OR a8='$leg3' OR a9='$leg3' OR a10='$leg3' OR a11='$leg3' OR a12='$leg3' OR a13='$leg3' OR a14='$leg3' OR a15='$leg3' OR a16='$leg3' OR a17='$leg3' OR a18='$leg3' OR a19='$leg3' OR a20='$leg3' OR a21='$leg3' OR a22='$leg3' OR a23='$leg3' OR a24='$leg3' OR a25='$leg3' OR a26='$leg3' OR a27='$leg3' OR a28='$leg3' OR a29='$leg3' OR a30='$leg3') AND level >='$base' LIMIT 17 ");
while ($row = mysqli_fetch_assoc($sql)){ $n .= $row['sn'] . '.3,'; }
$h = explode(',', $n);
$s = count($h) - 1;
$s = $s>40?40:$s;
// $code .= !empty($h[0]) ? 'a' . $h[0] . ', ' : '';
// $tree .= !empty($h[0]) ? 'a' . $h[0] . ' = {
// parent: a' . $randomKey . ',
// text:{
// name: "L2:' . $this->snToUser($h[0]) . '",
// title: "",
// contact: "",
// },
// link: {
// href: ""
// },
// image: "../headshots/'.$this->stageImage($stage).'"
// }, ' : '';
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . userName($uid, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
},';
$i = 1;
while ($i < $s) {
$e = $i++;
$hx = explode('.', $h[$e]);
$par = ceil($e / 3) - 1;
$hy = explode('.', $h[$par]);
$code .= 'a' . $hx[0] . ', ';
$tree .= 'a' . $hx[0] . ' = {
parent: a' . $hy[0] . ',
text:{
name: "L'.$hx[1].':' . $this->snToUser($hx[0]) . '",
title: "",
contact: "",
},
link: {
href: "?tree='.$hx[0].'"
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
}//leg3 exist
$code .= '];';
return $tree . $code;
}
function covisTreeGlobe($uid)
{
global $db;
$randomKey = $this->linkGlobe($uid);
//$randomKey = $a;
$key = $uid;
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . userName($key, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/st1.png"
},';
$sql = $db->query("SELECT * FROM globeuser WHERE a1='$randomKey' OR a2='$randomKey' ");
while ($row = mysqli_fetch_assoc($sql)) {
$code .= 'a' . $row['sn'] . ', ';
$tree .= 'a' . $row['sn'] . ' = {
parent: a' . $row['a1'] . ',
text:{
name: "' . userName($row['id'], 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/st1.png"
}, ';
}
$code .= '];';
return $tree . $code;
}
function covisTreeGlobeAll($uid)
{
global $db;
$randomKey = $this->linkGlobe($uid);
$stage = $this->globeStage($randomKey);
//$randomKey = $a;
$key = $uid;
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKeyGm($key, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
},';
$base = $this->globeStage($randomKey,2);
$sql = $db->query("SELECT * FROM globeuser WHERE (a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey') AND level >='$base' ");
while ($row = mysqli_fetch_assoc($sql)) {
$code .= 'a' . $row['sn'] . ', ';
$tree .= 'a' . $row['sn'] . ' = {
parent: a' . $row['a1'] . ',
text:{
name: "' . $this->idToKeyGm($row['id'], 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
}, ';
}
$code .= '];';
return $tree . $code;
}
function covisTree3Globe($uid)
{
global $db;
$userkey = $uid;
$randomKey = $this->idToKeyGm($userkey);
$key = $randomKey;
$stage = $this->globeStage($randomKey);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . $this->idToKeyGm($userkey, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
},';
$i=1;
$n = $randomKey . ',';
$base = $this->globeStage($randomKey,2);
$sql = $db->query("SELECT * FROM globeuser WHERE (a1='$randomKey' OR a2='$randomKey' OR a3='$randomKey') AND level >='$base' ");
while ($row = mysqli_fetch_assoc($sql)){ $e=$i++;
// if($this->stageCalc($row['sn'])>=$stage){
$n .= $row['sn'] . ','; }
// }
$h = explode(',', $n);
$s = count($h) - 1;
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 2) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->snToUserGm($h[$e]) . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
$code .= '];';
return $tree . $code;
}
// function covisR($uid)
// {
// global $db;
// $userkey = $uid;
// $randomKey = $this->idToKeyGm($userkey);
// $key = $randomKey;
// // $stage = $this->globeStage($randomKey);
// $stage = isset($_SESSION['stages'])?$_SESSION['stages']:$this->globeStage($randomKey);
// $left = $this->legKey($randomKey);
// $right = $this->legKey($randomKey,1);
// //$base = $this->globeStage($randomKey,2);
// $base = $this->stageToBase($stage);
// return $randomKey.'/'.$userkey.'/'.$base;
// }
function covisTree4Globe($uid)
{
global $db;
$userkey = $uid;
$randomKey = $this->idToKeyGm($userkey);
$key = $randomKey;
// $stage = $this->globeStage($randomKey);
$stage = isset($_SESSION['stages'])?$_SESSION['stages']:$this->globeStage($randomKey);
$left = $this->legKey($randomKey);
$right = $this->legKey($randomKey,1);
//$base = $this->globeStage($randomKey,2);
$base = $this->stageToBase($stage);
$code = 'chart_config = [
config, a' . $randomKey . ', ';
$tree = 'var config = {
container: "#basic-example",
nodeAlign: "BOTTOM",
connectors: {
type: "step"
},
node: {
HTMLclass: "nodeExample1"
}
},';
$tree .= 'a' . $randomKey . ' = {
text: {
name: "' . userName($uid, 'user') . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage1($stage).'"
},';
if($left>1){
$i=1;
$n = '';
$sql = $db->query("SELECT * FROM globeuser WHERE (sn='$left' OR a1='$left' OR a2='$left' OR a3='$left' OR a4='$left' OR a5='$left' OR a6='$left') AND level >='$base' LIMIT 7 ");
while ($row = mysqli_fetch_assoc($sql)){ $e=$i++;
// if($this->stageCalc($row['sn'])>=$stage){
$n .= $row['sn'] . ','; }
// }
$h = explode(',', $n);
$s = count($h) - 1;
$code .= !empty($h[0]) ? 'a' . $h[0] . ', ' : '';
$tree .= !empty($h[0]) ? 'a' . $h[0] . ' = {
parent: a' . $randomKey . ',
text:{
name: "(L)' . $this->snToUserGm($h[0]) . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ' : '';
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 2) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->snToUserGm($h[$e]) . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
}//left exist
if($right>1){
$i=1;
$n = '';
$sql = $db->query("SELECT * FROM globeuser WHERE (sn='$right' OR a1='$right' OR a2='$right' OR a3='$right' OR a4='$right' OR a5='$right' OR a6='$right') AND level >='$base' LIMIT 7 ");
while ($row = mysqli_fetch_assoc($sql)){ $e=$i++;
// if($this->stageCalc($row['sn'])>=$stage){
$n .= $row['sn'] . ','; }
// }
$h = explode(',', $n);
$s = count($h) - 1;
$code .= !empty($h[0]) ? 'a' . $h[0] . ', ' : '';
$tree .= !empty($h[0]) ? 'a' . $h[0] . ' = {
parent: a' . $randomKey . ',
text:{
name: "(R)' . $this->snToUserGm($h[0]) . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ' : '';
$i = 1;
while ($i < $s) {
$e = $i++;
$par = ceil($e / 2) - 1;
$code .= 'a' . $h[$e] . ', ';
$tree .= 'a' . $h[$e] . ' = {
parent: a' . $h[$par] . ',
text:{
name: "' . $this->snToUserGm($h[$e]) . '",
title: "",
contact: "",
},
link: {
href: ""
},
image: "../headshots/'.$this->stageImage($stage).'"
}, ';
}
}//right exist
$code .= '];';
return $tree . $code;
}
function createPin()
{
global $report, $db, $userKey;
$num = sanitize($_POST['no-of-pin']);
for ($a = 1; $a <= $num; $a++) {
$pin = strtoupper($this->win_hash(12));
$sql = $db->query("INSERT INTO pin(pin,rep,tm) VALUES('$pin','$userKey','1') ");
}
$report = $num . ' PINs successfully generated';
return;
}
function sNo($sn){
global $db;
$sql = $db->query("SELECT * FROM user WHERE sn<='$sn' ");
$no = mysqli_num_rows($sql) + 10000;
$sql = $db->query("UPDATE user SET sno='$no' WHERE sn='$sn' ");
return;
}
function assignSn(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE sno=0 ");
while($row=mysqli_fetch_assoc($sql)){ $this->sNo($row['sn']); }
return;
}
function findGlobeUser($id){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE id='$id' ");
return mysqli_num_rows($sql);
}
function EnterGlobe(){
$id = $_POST['EnterGlobe'];
if($this->findGlobeUser($id)==0){
$this->registerGlobe($id);
}
return;
}
function EnterGlobeAll(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE level>3 ORDER BY sn ASC");
while($row = $sql->fetch_assoc()) { $id = $row['id'];
if($this->findGlobeUser($id)==0){
$this->registerGlobe($id);
}
}
return;
}
function JoinGmatrix(){
global $db,$report,$count;
$rec = $_POST['recipient'];
$recid = sqLx('user','user',$rec,'id');
if(!isset($recid)){
$report='You have entered an invalid username'; $count=1; return;
}
$key = sqLx('globeuser','id',$recid,'sn');
$userKey = $_POST['JoinGmatrix'];
if($this->findGlobeUser($userKey)==0){
// $sn = sqLx('user','id',$userKey,'sn');
$this->registerGlobe2($userKey,$key);
$report='Global matrix registration successful ';
}
return;
}
function globeActive($a1){
global $db;
$sq = $db->query("SELECT * FROM globeuser WHERE a1='$a1' ");
$num = mysqli_num_rows($sq);
$sq = $num==2 ? $db->query("UPDATE globeuser SET active='$num', level=1 WHERE sn='$a1' ") : $db->query("UPDATE globeuser SET active='$num' WHERE sn='$a1' ");
return;
}
function globeUser($a,$col='level'){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE sn='$a' ");
$row = mysqli_fetch_array($sql);
return $row[$col];
}
// function promoteUser($a){
// global $db;
// $level = $this->globeUser($a);
// $x = $level+1; $ax='a'.$x;
// $sql = $db->query("SELECT * FROM globeuser WHERE $ax='$a' ");
// $num = mysqli_num_rows($sql);
// $res = $num == 2**$x ? $db->query("UPDATE globeuser SET level='$x' WHERE sn='$a' ") : '';
// $res2 = $num == 2**$x ? $this->addGlobeIncent($a) : '';
// return;
// }
function promoteUser($a){
global $db;
$level = $this->globeUser($a);
$x = $level+1; $ax='a'.$x;
if($level<2){
$sql = $db->query("SELECT * FROM globeuser WHERE $ax='$a' ");
$num = mysqli_num_rows($sql);
$res = $num == 2**$x ? $db->query("UPDATE globeuser SET level='$x' WHERE sn='$a' ") : '';
$res2 = $num == 2**$x ? $this->addGlobeIncent($a) : '';
}
else{
$left = $this->legKey($a);
$right = $this->legKey($a,1);
$base = $this->globeStage($a,2);
$sqll = $db->query("SELECT * FROM globeuser WHERE (sn='$left' OR a1='$left' OR a2='$left' OR a3='$left' OR a4='$left' OR a5='$left' OR a6='$left') AND level >='$base' LIMIT 7 ");
$numl = mysqli_num_rows($sqll);
$sqlr = $db->query("SELECT * FROM globeuser WHERE (sn='$right' OR a1='$right' OR a2='$right' OR a3='$right' OR a4='$right' OR a5='$right' OR a6='$right') AND level >='$base' LIMIT 7 ");
$numr = mysqli_num_rows($sqlr);
if($numl==7 AND $numr==7){$add=3;}
elseif($numl>2 AND $numr>2){$add=2;}
elseif($numl>0 AND $numr>0){$add=1;}
else{$add=0;}
$x = $base+$add;
$res = $add>0 ? $db->query("UPDATE globeuser SET level='$x' WHERE sn='$a' ") : '';
$res2 = $add>0 ? $this->addGlobeIncent($a) : '';
}
return;
}
function linkGlobe($id,$col='sn'){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE id='$id' ");
$row = mysqli_fetch_array($sql);
return $row[$col];
}
function globeKeyToId($sn,$col='id'){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE sn='$sn' ");
$row = mysqli_fetch_array($sql);
return $row[$col];
}
function globeStage($a,$opt=1){
$level = $this->globeUser($a);
if($level>7){ $stage=4; $base=8;}
elseif($level>4){ $stage=3; $base=5;}
elseif($level>1){ $stage=2; $base=2;}
elseif($level<2){ $stage=1; $base=0;}
// if($level==''){ $stage=''; $base=0;}
if($opt>1){$stage=$base; }
return $stage;
}
function stageToBase($stage){
if($stage==4){ $base=8;}
elseif($stage==3){ $base=5;}
elseif($stage==2){ $base=2;}
elseif($stage==1){ $base=0;}
return $base;
}
function gmLevelStage($level){
if($level>7){ $stage=4; $base=8;}
elseif($level>4){ $stage=3; $base=5;}
elseif($level>1){ $stage=2; $base=2;}
else{ $stage=1; $base=0;}
return $stage;
}
function globeStageTeam($a){
global $db;
$base=$this->globeStage($a,2);
$level = $this->globeUser($a);
if($level<2){
$sql = $level<2 ? $db->query("SELECT * FROM globeuser WHERE (a1='$a' OR a2='$a') AND level>='$base' ") : $db->query("SELECT * FROM globeuser WHERE (a1='$a' OR a2='$a' OR a3='$a') AND level>='$base' ");
$num = mysqli_num_rows($sql);
}else{
$left = $this->legKey($a);
$right = $this->legKey($a,1);
$base = $this->globeStage($a,2);
$sqll = $db->query("SELECT * FROM globeuser WHERE (sn='$left' OR a1='$left' OR a2='$left' OR a3='$left' OR a4='$left' OR a5='$left' OR a6='$left') AND level >='$base' LIMIT 7 ");
$numl = mysqli_num_rows($sqll);
$sqlr = $db->query("SELECT * FROM globeuser WHERE (sn='$right' OR a1='$right' OR a2='$right' OR a3='$right' OR a4='$right' OR a5='$right' OR a6='$right') AND level >='$base' LIMIT 7 ");
$numr = mysqli_num_rows($sqlr);
$num = $numl+$numr;
}
return $num;
}
function globeEarning($a){
$s1 = 1;
$s2=2.5;
$s3=10;
$s4=30;
$team = $this->globeStageTeam($a);
$level = $this->globeUser($a);
if ($level == 0) { $se = $team*$s1; }
elseif ($level == 1) { $se = $team*$s1; }
elseif ($level == 2) { $se = 6 + $team*$s2; }
elseif ($level == 3) { $se = 6 + $team*$s2; }
elseif ($level == 4) { $se = 6 + $team*$s2; }
elseif ($level == 5) { $se = 6 + 35 + $team*$s3; }
elseif ($level == 6) { $se = 6 + 35 + $team*$s3; }
elseif ($level == 7) { $se = 6 + 35 + $team*$s3; }
elseif ($level == 8) { $se = 6 + 35 + 140 + $team*$s4; }
elseif ($level == 9) { $se = 6 + 35 + 140 + $team*$s4; }
elseif ($level == 10) {$se = 6 + 35 + 140 + $team*$s4; }
// elseif ($level == 11) {$se = 6 + 65 + 215 + $team*$s4; }
// elseif ($level == 12) {$se = $team*$s2;; }
return $se;
}
function globeStageLevel($a) {
$stlevel = 0;
$level = $this->globeUser($a);
if ($level == 1) { $stlevel = 1; }
elseif ($level == 2) { $stlevel = 0; }
elseif ($level == 3) { $stlevel = 1; }
elseif ($level == 4) { $stlevel = 2; }
elseif ($level == 5) { $stlevel = 0; }
elseif ($level == 6) { $stlevel = 1; }
elseif ($level == 7) { $stlevel = 2; }
elseif ($level == 8) { $stlevel = 0; }
elseif ($level == 9) { $stlevel = 1; }
elseif ($level == 10) {$stlevel = 2; }
elseif ($level == 11) {$stlevel = 0; }
elseif ($level == 12) {$stlevel = 1; }
return $stlevel;
}
function globeLevelIncent($level){
$incent = '';
if ($level == 1) { $incent = ''; }
elseif ($level == 2) { $incent = ''; }
elseif ($level == 3) { $incent = ''; }
elseif ($level == 4) { $incent = '$10 CHARITY BONUS'; }
elseif ($level == 5) { $incent = 'Food Stuff Worth $25'; }
elseif ($level == 6) { $incent = ''; }
elseif ($level == 7) { $incent = ''; }
elseif ($level == 8) { $incent = '$75 Shopping Allowance'; }
elseif ($level == 9) { $incent = ''; }
elseif ($level == 10) {$incent = ''; }
elseif ($level == 11) {$incent = '$125 Monthly Allowance for 1 Year'; }
elseif ($level == 12) {$incent = ''; }
return $incent;
}
function addGlobeIncent($a){
global $db;
$level = $this->globeUser($a);
$id = $this->globeKeyToId($a);
$incentive = $this->globeLevelIncent($level);
$sq = $db->query("SELECT * FROM globeincent WHERE id='$id' AND level='$level' ");
$sql = ($incentive=='' OR mysqli_num_rows($sq)>0) ? '' : $db->query("INSERT INTO globeincent (id,level,incentive) VALUES('$id','$level','$incentive') ");
// if($level>4){
// $incentive = $this->globeLevelIncent(4);
// $sql = $db->query("INSERT INTO globeincent (id,level,incentive) VALUES('$id','$level','$incentive') ");
// }
// if($level>5){
// $incentive = $this->globeLevelIncent(5);
// $sql = $db->query("INSERT INTO globeincent (id,level,incentive) VALUES('$id','$level','$incentive') ");
// }
return;
}
function GiveGlobeIncent(){
global $db;
$sn = $_POST['GiveGlobeIncent'];
$status = $_POST['status']+1;
$db->query("UPDATE globeincent SET status = '$status' WHERE sn = '$sn' ");
return;
}
function GlobeWithdraw(){
global $db;
$sn = $_POST['GlobeWithdraw'];
$status = $_POST['status']+1;
$db->query("UPDATE gmwithdraw SET status = '$status' WHERE sn = '$sn' ");
return;
}
function LoanProcess(){
global $db,$report, $userKey;
$sn = $_POST['LoanProcess'];
$ctime = time();
$sq = $db->query("SELECT * FROM myloan WHERE sn='$sn' ");
$r=mysqli_fetch_assoc($sq);
$duration = $r['duration'];
$amount = $r['amount'];
$uid2 = $r['id'];
$uid = $userKey;
$status = $r['status']+1;
$loandue = $ctime + (60*60*24*$duration);
$type='la';
$tno = substr(str_shuffle(str_repeat('1234567890', 10)), 0, 10);
$db->query("UPDATE myloan SET status = '$status' WHERE sn = '$sn' ");
if($status==3){ $db->query("UPDATE myloan SET ctime = '$ctime', loandue = '$loandue' WHERE sn = '$sn' ");
$db->query("INSERT INTO transfer (id,id2,amount,status,type,tno) VALUES ('$uid','$uid2','$amount','1','$type','$tno')");
$report = 'Loan disbursement successful';
}
return;
}
function LoanRetrieve(){
global $db,$report,$count;
$sn = $_POST['LoanRetrieve'];
$ctime = time();
$sq = $db->query("SELECT * FROM myloan WHERE sn='$sn' ");
$r=mysqli_fetch_assoc($sq);
$uid = $r['id'];
$uidx = $this->idToKey($uid);
$amount = $r['amount']+$r['interest'];
$status = $r['status']+1;
$db->query("UPDATE myloan SET status = '$status' WHERE sn = '$sn' ");
$accountBalance = $this->totalEarnings($uidx);
$this->withdrawProcess2($uid, $amount, $accountBalance, 'lr', '1');
$report='Loan settlement successfully retrieved';
return;
}
function LoanRepay(){
global $db,$report,$count;
$sn = $_POST['LoanRepay'];
$ctime = time();
$sq = $db->query("SELECT * FROM myloan WHERE sn='$sn' ");
$r=mysqli_fetch_assoc($sq);
$uid = $r['id'];
$uidx = $this->idToKey($uid);
$amount = $r['amount']+$r['interest'];
$status = $r['status']+1;
$accountBalance = $this->totalEarnings($uidx);
if($accountBalance>=$amount){
$db->query("UPDATE myloan SET status = '$status' WHERE sn = '$sn' ");
$this->withdrawProcess2($uid, $amount, $accountBalance, 'lr', '1');
$report='Loan settlement successfully retrieved';
}else{$report='You do not have sufficient balance to complete this transaction, fund your wallet and try again'; $count=1;}
return;
}
function LoanCancel(){
global $db,$report,$count;
$sn = $_POST['LoanCancel'];
$sq = $db->query("SELECT * FROM myloan WHERE sn='$sn' ");
$r=mysqli_fetch_assoc($sq);
$status = $r['status'];
$db->query("DELETE FROM myloan WHERE sn = '$sn' AND status<3 ");
return;
}
function activeLoan($id){
global $db;
$sq = $db->query("SELECT * FROM myloan WHERE id='$id' AND status<4 ");
return mysqli_num_rows($sq);
}
function addGlobeIncentAll($a){
global $db;
$sq = $db->query("SELECT * FROM globeuser WHERE level>3 ");
while($r=mysqli_fetch_assoc($sq)){ $a = $r['sn'];
$this->addGlobeIncent($a);
}
return;
}
function registerGlobe($id){
global $report, $db;
$sq = $db->query("SELECT * FROM globeuser WHERE active<2 ORDER BY a1 ASC LIMIT 1 ");
$r=mysqli_fetch_assoc($sq);
$a1 = $r['sn'];
$a2 = $r['a1'];
$a3 = $r['a2'];
$a4 = $r['a3'];
$a5 = $r['a4'];
$a6 = $r['a5'];
$a7 = $r['a6'];
$a8 = $r['a7'];
$a9 = $r['a8'];
$a10 = $r['a9'];
$active = $r['active'];
$g = $r['g']+1;
$user = userName($id,'user');
$sql = $db->query("INSERT INTO globeuser (id,user,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,g) VALUES('$id','$user','$a1','$a2','$a3','$a4','$a5','$a6','$a7','$a8','$a9','$a10','$g') ");
$this->globeActive($a1);
if($active==1){ $u = 1;
while($u<11){ $v= $u++; $w = $r['a'.$v]; $this->promoteUser($w); } }
$report = 'successful sent to global matrix ';
return;
}
function registerGlobe2($id,$key){
global $report, $db;
$sq = $db->query("SELECT * FROM globeuser WHERE (sn='$key' OR a1='$key' OR a2='$key' OR a3='$key' OR a4='$key' OR a5='$key' OR a6='$key' OR a7='$key' OR a8='$key' OR a9='$key' OR a10='$key') AND active<2 ORDER BY g ASC, sn ASC LIMIT 1");
$r=mysqli_fetch_assoc($sq);
$a1 = $r['sn'];
$a2 = $r['a1'];
$a3 = $r['a2'];
$a4 = $r['a3'];
$a5 = $r['a4'];
$a6 = $r['a5'];
$a7 = $r['a6'];
$a8 = $r['a7'];
$a9 = $r['a8'];
$a10 = $r['a9'];
$active = $r['active'];//
$g = $r['g']+1;
$user = userName($id,'user');
// $idx = sqLx('user','id',$id,'sn');
// $bal = $this->totalEarnings($idx);
// $this->withdrawProcess2($id, 5, $bal, 'gm', 1);
$sql = $db->query("INSERT INTO globeuser (id,user,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,g) VALUES('$id','$user','$a1','$a2','$a3','$a4','$a5','$a6','$a7','$a8','$a9','$a10','$g') ");
$this->globeActive($a1);
if($active==1){ $u = 1;
while($u<11){ $v= $u++; $w = $r['a'.$v]; $this->promoteUser($w); } }
$report = 'successfully sent to global matrix ';
return;
}
//REPARE OPERATIONS
function updateTeamlines2($sn){
global $db;
$key=$sn;
$i=1;
while($i<=20){ $e=$i++; $a = 'a'.$e;
$sn = sqLx('globeuser','sn', $sn,'a1');
if($sn==0){return; }
if($e>10){$db->query("UPDATE globeuser SET $a='$sn' WHERE sn='$key' "); }
}
return;
}
function updateAllTeamlines2(){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE g=10 ");
while($row = mysqli_fetch_array($sql)){ $sn = $row['sn'];
$this->updateTeamlines2($sn);
}
return;
}
function updateTeamlines($sn){
global $db;
$i=1; $gg=0;
while($i<=20){ $e=$i++; $a = 'a'.$e;
$g = sqLx('globeuser','sn',$sn,$a);
if($g>0){$gg += 1; }
}
$db->query("UPDATE globeuser SET g='$gg' WHERE sn='$sn' ");
return;
}
function updateAllTeamlines(){
global $db;
$sql = $db->query("SELECT * FROM globeuser WHERE g=10 LIMIT 1000 ");
while($row = mysqli_fetch_array($sql)){ $sn = $row['sn'];
$this->updateTeamlines($sn);
}
return;
}
function updateTeamlines3($sn){
global $db;
$i=1; $gg=0;
while($i<=30){ $e=$i++; $a = 'a'.$e;
$g = sqLx('user','sn',$sn,$a);
if($g>0){$gg += 1; }
}
$db->query("UPDATE user SET g='$gg' WHERE sn='$sn' ");
return;
}
function updateAllTeamlines3(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE g=0 ");
while($row = mysqli_fetch_array($sql)){ $sn = $row['sn'];
$this->updateTeamlines3($sn);
}
return;
}
function updateTeamlines4($sn){
global $db;
$lu = sqLx('user','sn',$sn,'a30'); $lg = sqLx('user','sn',$sn,'g');
$g = sqLx('user','sn',$lu,'g');
$gg = $g+$lg-1;
$db->query("UPDATE user SET g='$gg' WHERE sn='$sn' ");
return;
}
function updateAllTeamlines4(){
global $db;
$sql = $db->query("SELECT * FROM user WHERE a30>1 ");
while($row = mysqli_fetch_array($sql)){ $sn = $row['sn'];
$this->updateTeamlines4($sn);
}
return;
}
///repair
function gmBalance($a,$id){
return $this->globeEarning($a)-$this->totalWithdrawgm($id)+$this->totalReceivedgm($id);
}
function SendMail(){
global $db, $report,$signup;
$message=$_POST['msg'];
$subject=$_POST['subject'];
$i=1;
//$sql = $db->query("SELECT * FROM user WHERE active = 2 ");
$sql = $db->query("SELECT * FROM user");
while($row = mysqli_fetch_assoc($sql)){
$email = $row['email'];
$this->emailerAll($email,$message,$subject); $e=$i++;
}
$report='Your message was successfully sent: '.$e.' contacts';
return;
}
function SendMail2(){
global $db, $report,$signup;
$message=$_POST['msg'];
$subject=$_POST['subject'];
$rec = $_POST['rec'];
$rec2 = explode(',', $rec);
$count = count($rec2);
$i=0;
while($i<$count){$e=$i++; $email = trim($rec2[$e]);
if($email !=''){$this->emailerAll($email,$message,$subject); }
}
$report='Your message was successfully sent: '.$count.' contacts';
return;
}
}
$covis = new Profile;
$uid = $covis->Uid();
$uidx = $covis->idToKey($uid);
$stage = $covis->stageCalc($uidx);
//$do = $covis->updateA16toA30All();
$uidy = $covis->findGlobeUser($uid)==1 ? $covis->linkGlobe($uid) : '123456789';
//if(isset($report)){ $covis->Alert(); }
// if(isset($uid)){
// $covis->shareContributionMoney($uid);
// }
//$covis->AddNewUsersAuto(3);
//end of Bonus Class
// echo password_hash(123, PASSWORD_BCRYPT)
?>