PHP Classes

PHP MLM Tree Binary Plan: Manage members of a MLM tree binary plan

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (5)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 64%Total: 1,766 All time: 2,217 This week: 372Up
Version License PHP version Categories
mlm-tree 0.1GNU General Publi...5PHP 5, Databases, Content management
Description 

Author

This package can manage members of a MLM tree binary plan.

It can add representatives to a multi-level marketing binary tree stored in a MySQL database.

Each representative can be added to the left or right legs of the sponsor tree node.

The class can also update representative details, swap representative legs, add a new representative as spillover into the first available left leg, and assign a deleted representative down line to another representative.

Innovation Award
PHP Programming Innovation award nominee
December 2015
Number 8
Multi-Level Marketing (MLM) systems are systems that reward people that bring more people to become customers of a given business, as well any other people that was brought by those there entered by referral of others, thus layered in multiple levels of referrals.

MLM systems form a hierarchic tree of referred of people. This hierarchy can be represented in a binary tree.

This class can manage a binary tree of people that entered a MLM system.

Manuel Lemos
Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 58
All time rank: 618 in United States United States
Week rank: 11 Up3 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Recommendations

Recommendation for a PHP class to mlm binary tree
Generation income from 6 levels in binary MLM

unilevlemlm.php
how to create unilevel mlm site using php ann i need php code

mlm dynamic binary tree code in PHP and MySQL
mlm dynamic binary tree

Example

<?php
/*
example usage
mlmBinary ver 0.1 beta

This script requires access to a MySQL database
Set the access credentials in the mlmbinary.class.php file
use included mlm_rep.sql file to create database table
*/
include('mlmbinary.class.php');

$mbinary = new mlmBinary();

$recordID = empty($_GET['id']) ? null : $_GET['id'];

$currentRep = ( $recordID ) ? $mbinary->rRep($recordID) : null;

if( !empty(
$_REQUEST['formPosted']) ){
   
    switch(
$_REQUEST['action'] ){
        case
'getRep':
            if( !empty(
$_REQUEST['repID']) ){
               
               
$currentRep = $mbinary->rRep($_REQUEST['repID'],false);
               
$recordID = ( empty($currentRep) ) ? 0 : $currentRep->recordID;
               
            }elseif( !empty(
$_REQUEST['recordID']) ){
               
               
$currentRep = $mbinary->rRep($_REQUEST['recordID']);
               
$recordID = ( empty($currentRep) ) ? 0 : $currentRep->recordID;
               
            }
            break;
        case
'updateRep':
           
$mbinary->uRep($_REQUEST['recordID'],$_REQUEST['name'],$_REQUEST['repID'],$_REQUEST['sponsorID'],$_REQUEST['leg']);
           
$currentRep = $mbinary->rRep($_REQUEST['recordID']);
           
$recordID = $_REQUEST['recordID'];
            break;
        case
'addRep':
           
$mbinary->cRep($_REQUEST['name'],$_REQUEST['repID'],$_REQUEST['sponsorID'],$_REQUEST['leg']);
           
$currentRep = $mbinary->rRep($_REQUEST['sponsorID']);
           
$recordID = $_REQUEST['sponsorID'];
            break;
        case
'addPrim':
           
$recordID = $mbinary->cRep($_REQUEST['name'],$_REQUEST['repID'],$_REQUEST['sponsorID'],$_REQUEST['leg']);
           
$currentRep = $mbinary->rRep($recordID);
            break;
        case
'addSpill':
           
$recordID = $mbinary->cRepSpill($_REQUEST['name'],$_REQUEST['repID'],$_REQUEST['sponsorID']);
           
$currentRep = $mbinary->rRep($recordID);
            break;
        case
'swapRep':
           
$mbinary->swapReps($_REQUEST['recordID']);
           
$currentRep = $mbinary->rRep($_REQUEST['recordID']);
           
$recordID = $_REQUEST['recordID'];
            break;
        case
'delRep':
            if( !empty(
$_REQUEST['repID']) ){
               
               
$recordID = $mbinary->dRep($_REQUEST['recordID'],$_REQUEST['repID'],false);
               
            }else{
               
               
$recordID = $mbinary->dRep($_REQUEST['recordID'],$_REQUEST['sponsorID']);
               
            }
           
$currentRep = $mbinary->rRep($recordID);
            break;
    }
   
}

?>
<!DOCTYPE hmtl>
<html>
    <head>
        <title>MLM Binary Plan</title>
        <style type="text/css">
            a{
                color: black;
                text-decoration: none;
            }
            a:hover{
                color: red;
            }
            div{
                margin-top: 10px;
            }
        </style>
    </head>
    <body>
        <h3>MLM Binary Plan</h3>
        <div id="breadcrumb"><?php echo $mbinary->showBreadcrumb($recordID);?></div>
        <h4>Get Rep record</h4>
        <div>
            <form method="POST">
                Rep ID: <input type="text" name="repID"> record ID: <input type="text" name="recordID">
                <input type="hidden" name="formPosted" value="1">
                <input type="hidden" name="action" value="getRep">
                <input type="submit" value="Go">
            </form>
        </div>
<?php
if( !empty($currentRep) ){
?>
<table width="100%" border="1">
            <tr>
                <td colspan="2" align="center"><?php echo $currentRep->name;?></td>
            </tr>
            <tr>
                <td width="50%" align="center">
<?php
   
if( !empty($currentRep->reps) ){
       
        if(
$currentRep->reps[0]->leg ){
           
           
$leftLeg = ( empty($currentRep->reps[1]) ) ? null : $currentRep->reps[1];
           
$rightLeg = $currentRep->reps[0];
           
        }else{
           
           
$leftLeg = $currentRep->reps[0];
           
$rightLeg = ( empty($currentRep->reps[1]) ) ? null : $currentRep->reps[1];
           
        }
       
    }
    if( empty(
$leftLeg) ){
?>
<div style="text-align: left;">
                        <form method="POST">
                            Name: <input type="text" name="name" value=""><br>
                            Rep ID: <input type="text" name="repID" value=""><br>
                            <input type="hidden" name="formPosted" value="1">
                            <input type="hidden" name="action" value="addRep">
                            <input type="hidden" name="sponsorID" value="<?php echo $currentRep->recordID;?>">
                            <input type="hidden" name="leg" value="0">
                            <input type="submit" value="Add">
                        </form>
                    </div>
<?php
   
}else{
?>
[<a href="?id=<?php echo $leftLeg->recordID;?>"><?php echo $leftLeg->name;?></a>]
<?php
   
}
?>
</td>
                <td width="50%" align="center">
<?php
   
if( empty($rightLeg) ){
?>
<div style="text-align: left;">
                        <form method="POST">
                            Name: <input type="text" name="name" value=""><br>
                            Rep ID: <input type="text" name="repID" value=""><br>
                            <input type="hidden" name="formPosted" value="1">
                            <input type="hidden" name="action" value="addRep">
                            <input type="hidden" name="sponsorID" value="<?php echo $currentRep->recordID;?>">
                            <input type="hidden" name="leg" value="1">
                            <input type="submit" value="Add">
                        </form>
                    </div>
<?php
   
}else{
?>
[<a href="?id=<?php echo $rightLeg->recordID;?>"><?php echo $rightLeg->name;?></a>]
<?php
   
}
?>
</td>
            </tr>
<?php
   
if( !empty($currentRep->reps) ){
?>
<tr>
                <td colspan="2" align="center">
                    <form method="POST" style="margin: 0;">
                        <input type="hidden" name="formPosted" value="1">
                        <input type="hidden" name="action" value="swapRep">
                        <input type="hidden" name="recordID" value="<?php echo $currentRep->recordID;?>">
                        <input type="submit" value="Swap Reps">
                    </form>
                </td>
            </tr>
<?php
   
}
?>
</table>
        <h4>Update Record (<?php echo $currentRep->recordID;?>)</h4>
        <form method="POST">
            Name: <input type="text" name="name" value="<?php echo $currentRep->name;?>"><br>
            Rep ID: <input type="text" name="repID" value="<?php echo $currentRep->repID;?>"><br>
            <input type="hidden" name="formPosted" value="1">
            <input type="hidden" name="action" value="updateRep">
            <input type="hidden" name="recordID" value="<?php echo $currentRep->recordID;?>">
            <input type="hidden" name="sponsorID" value="<?php echo $currentRep->sponsorID;?>">
            <input type="hidden" name="leg" value="<?php echo $currentRep->leg;?>">
            <input type="submit" value="Update">
        </form>
        <h4>Delete Record (<?php echo $currentRep->recordID;?>)</h4>
        <form method="POST">
            Assign downline to Rep ID: <input type="text" name="repID"> Record ID: <input type="text" name="sponsorID"><br>
            <input type="checkbox" name="action" value="delRep"> check box to confirm<br>
            <input type="hidden" name="formPosted" value="1">
            <input type="hidden" name="recordID" value="<?php echo $currentRep->recordID;?>">
            <input type="submit" value="Delete">
        </form>
<?php
   
if( !empty($leftLeg) AND !empty($rightLeg) ){
?>
<h4>Add Rep as spill over</h4>
        <form method="POST">
            Name: <input type="text" name="name" value=""><br>
            Rep ID: <input type="text" name="repID" value=""><br>
            <input type="hidden" name="formPosted" value="1">
            <input type="hidden" name="action" value="addSpill">
            <input type="hidden" name="sponsorID" value="<?php echo $currentRep->sponsorID;?>">
            <input type="submit" value="Add">
        </form>
<?php
   
}
}else{
?>
<h4>Primary Reps</h4>
<?php
    $primReps
= $mbinary->primReps();
    foreach(
$primReps as $primRep ){
?>
<a href="?id=<?php echo $primRep['recordID'];?>"><?php echo $primRep['name'];?></a> (<?php echo $primRep['recordID'];?>)<br>
<?php
   
}
?>
<h4>Add Rep as primary</h4>
        <form method="POST">
            Name: <input type="text" name="name" value=""><br>
            Rep ID: <input type="text" name="repID" value=""><br>
            <input type="hidden" name="formPosted" value="1">
            <input type="hidden" name="action" value="addPrim">
            <input type="hidden" name="sponsorID" value="0">
            <input type="hidden" name="leg" value="0">
            <input type="submit" value="Add">
        </form>
<?php
}
?>
</body>
</html>


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example Usage
Plain text file mlmbinary.class.php Class Main Class
Accessible without login Plain text file mlm_rep.sql Data Database table structure

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,766
This week:0
All time:2,217
This week:372Up
User Ratings User Comments (2)
 All time
Utility:90%StarStarStarStarStar
Consistency:95%StarStarStarStarStar
Documentation:-
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:64%StarStarStarStar
Rank:697
 
This was a very cool class.
5 years ago (Michael Scott McGinn)
70%StarStarStarStar
Love is coding style
7 years ago (Sab Udeh Chu Chu)
55%StarStarStar