Esempio n. 1
0
function insert_refferal_commision()
{
    global $wpdb;
    $date = date("Y-m-d H:i:s");
    $child_ids = '';
    $mlm_payout = get_option('wp_mlm_payout_settings');
    $refferal_amount = $mlm_payout['referral_commission_amount'];
    $table_prefix = mlm_core_get_table_prefix();
    if (isset($_REQUEST['userId']) && $_REQUEST['status'] == 1) {
        $table_prefix = mlm_core_get_table_prefix();
        $user_id = $_REQUEST['userId'];
        $row = $wpdb->get_row("SELECT * FROM {$table_prefix}mlm_users WHERE user_id={$user_id}");
        $sponsor_key = $row->sponsor_key;
        $child_id = $row->id;
        if ($sponsor_key != 0) {
            $sponsor = $wpdb->get_row("SELECT id FROM {$table_prefix}mlm_users WHERE user_key='" . $sponsor_key . "'");
            $sponsor_id = $sponsor->id;
            $sql = "INSERT INTO {$table_prefix}mlm_referral_commission SET date_notified ='{$date}',sponsor_id='{$sponsor_id}',child_id='{$child_id}',amount='{$refferal_amount}',payout_id='0'";
            $rs = $wpdb->query($sql);
            if (!$rs) {
                _e("<span class='error' style='color:red'>Inserting  Fail</span>");
            }
        }
    }
}
function mlmePinUpdate()
{
    $mlm_settings = get_option('wp_mlm_general_settings');
    if (isset($mlm_settings['ePin_activate']) && $mlm_settings['ePin_activate'] == '1') {
        global $wpdb;
        global $current_user;
        $user_id = $current_user->ID;
        $table_prefix = mlm_core_get_table_prefix();
        $user = get_userdata($user_id);
        $user_key = $wpdb->get_var("select user_key from {$table_prefix}mlm_users where user_id='{$user->ID}'");
        /* check that it is mlm user or not */
        $res = $wpdb->get_row("SELECT epin_no FROM {$table_prefix}mlm_epins WHERE user_key = '" . $user_key . "'");
        $path = "'" . plugins_url() . "/" . MLM_PLUGIN_NAME . "'";
        if ($wpdb->num_rows > 0) {
            $payment_status = $wpdb->get_var("select payment_status from {$table_prefix}mlm_users where user_id='{$user->ID}'");
            if ($payment_status == '1') {
                echo '<div style="background:#FFCC99;padding:10px;">' . __('Your status is already to set to Paid in the system. You cannot activate your membership again with an ePin.', 'binary-mlm-pro') . '</div>';
            } else {
                if ($payment_status == '2') {
                    echo '<div style="background:#FFCC99;padding:10px;">' . __('Your status is already set to Active in the system. You cannot activate your membership again with an ePin.', 'binary-mlm-pro') . '</div>';
                }
            }
        } else {
            $not_mlm = $wpdb->get_row("select id from {$table_prefix}mlm_users where user_id='{$user->ID}'");
            if ($wpdb->num_rows == '0') {
                echo '<div style="background:#FFCC99;padding:10px;">' . __('Not MLM User', 'binary-mlm-pro') . '</div>';
            } else {
                $payment_status = $wpdb->get_var("select payment_status from {$table_prefix}mlm_users where user_id='{$user->ID}'");
                if ($payment_status == '1') {
                    echo '<div style="background:#FFCC99;padding:10px;">' . __('Your status is already to set to Paid in the system. You cannot activate your membership again with an ePin.', 'binary-mlm-pro') . '</div>';
                } else {
                    if ($payment_status == '2') {
                        echo '<div style="background:#FFCC99;padding:10px;">' . __('Your status is already set to Active in the system. You cannot activate your membership again with an ePin.', 'binary-mlm-pro') . '</div>';
                    } else {
                        $epin = '<input type="text" name="epin" id="epin_' . $user_id . '"><input type="button" value="Update ePin" id="update_' . $user_id . '" onclick="setePinUser(' . $path . ',' . $user_id . ',document.getElementById(\'epin_' . $user_id . '\').value);"><span id="epinmsg_' . $user_id . '"></span>';
                        echo $epin;
                    }
                }
            }
        }
    } else {
        echo '<div style="background:#FFCC99;padding:10px;">' . __('Sorry. You are not allowed to access this page due to administrative permissions.', 'binary-mlm-pro') . '</div>';
    }
}
function mlm_payment_status_details_page()
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    $mlm_method = get_option('wp_mlm_payment_method');
    if ($mlm_method['mlm_payment_method'] == 'paypal') {
        if ($_POST["payment_status"] == 1) {
            $paymentStatus = 1;
        } else {
            $paymentStatus = 0;
        }
        $OrderID = $_POST["item_number"];
    } else {
        if ($mlm_method['mlm_payment_method'] == 'cardsave') {
            //echo "<pre>"; print_r($_POST); exit;
            $mlm_pay_settings = get_option('wp_mlm_payment_settings');
            $PreSharedKey = $mlm_pay_settings["mlm-pre-shared-key"];
            $MerchantID = $mlm_pay_settings["mlm-merchant-id"];
            $Password = $mlm_pay_settings["mlm-merchant-password"];
            $OrderID = $_POST["OrderID"];
            //magic quotes fix
            if (get_magic_quotes_gpc()) {
                $_POST = array_map('stripslashes', $_POST);
            }
            //Generate Hashstring - use combination of post variables and variables from config.php
            $HashString = "PreSharedKey=" . $PreSharedKey;
            $HashString = $HashString . '&MerchantID=' . $_POST["MerchantID"];
            $HashString = $HashString . '&Password='******'&StatusCode=' . $_POST["StatusCode"];
            $HashString = $HashString . '&Message=' . $_POST["Message"];
            $HashString = $HashString . '&PreviousStatusCode=' . $_POST["PreviousStatusCode"];
            $HashString = $HashString . '&PreviousMessage=' . $_POST["PreviousMessage"];
            $HashString = $HashString . '&CrossReference=' . $_POST["CrossReference"];
            $HashString = $HashString . '&AddressNumericCheckResult=' . $_POST["AddressNumericCheckResult"];
            $HashString = $HashString . '&PostCodeCheckResult=' . $_POST["PostCodeCheckResult"];
            $HashString = $HashString . '&CV2CheckResult=' . $_POST["CV2CheckResult"];
            $HashString = $HashString . '&ThreeDSecureAuthenticationCheckResult=' . $_POST["ThreeDSecureAuthenticationCheckResult"];
            $HashString = $HashString . '&CardType=' . $_POST["CardType"];
            $HashString = $HashString . '&CardClass=' . $_POST["CardClass"];
            $HashString = $HashString . '&CardIssuer=' . $_POST["CardIssuer"];
            $HashString = $HashString . '&CardIssuerCountryCode=' . $_POST["CardIssuerCountryCode"];
            $HashString = $HashString . '&Amount=' . $_POST["Amount"];
            $HashString = $HashString . '&CurrencyCode=' . $_POST["CurrencyCode"];
            $HashString = $HashString . '&OrderID=' . $OrderID;
            $HashString = $HashString . '&TransactionType=' . $_POST["TransactionType"];
            $HashString = $HashString . '&TransactionDateTime=' . $_POST["TransactionDateTime"];
            $HashString = $HashString . '&OrderDescription=' . $_POST["OrderDescription"];
            $HashString = $HashString . '&CustomerName=' . $_POST["CustomerName"];
            $HashString = $HashString . '&Address1=' . $_POST["Address1"];
            $HashString = $HashString . '&Address2=' . $_POST["Address2"];
            $HashString = $HashString . '&Address3=' . $_POST["Address3"];
            $HashString = $HashString . '&Address4=' . $_POST["Address4"];
            $HashString = $HashString . '&City=' . $_POST["City"];
            $HashString = $HashString . '&State=' . $_POST["State"];
            $HashString = $HashString . '&PostCode=' . $_POST["PostCode"];
            $HashString = $HashString . '&CountryCode=' . $_POST["CountryCode"];
            $HashString = $HashString . '&EmailAddress=' . $_POST["EmailAddress"];
            $HashString = $HashString . '&PhoneNumber=' . $_POST["PhoneNumber"];
            //Encode HashDigest using SHA1 encryption (and create HashDigest for later use) - This is used as a checksum to ensure that the form post from the gateway back to this page hasn't been tampered with.
            $HashDigest = sha1($HashString);
            if ($_POST["StatusCode"] == 0) {
                $paymentStatus = 1;
            } else {
                $paymentStatus = 0;
            }
        }
    }
    //print $HashString;
    if ($paymentStatus == 1) {
        $user_id = $wpdb->get_var("SELECT user_id FROM {$table_prefix}mlm_payment_status  WHERE `order_id`='" . $OrderID . "'");
        $user_child = $wpdb->get_var("SELECT user_id FROM {$table_prefix}mlm_users  WHERE `id`='" . $user_id . "'");
        //get no. of level
        UserStatusUpdate($user_child);
        //}  //end of for loop
        $msg = "<span style='color:green;'>Thank you. Your payment has been processed successfully.<a href=''>Click here</a> to go your Dashboard.</span>";
        _e($msg);
    } else {
        $msg = "<span style='color:red;'>Sorry. There was an error processing your payment. <a href=''>Click here</a> to go your Dashboard.</span>";
        _e($msg);
    }
}
function my_show_extra_profile_fields($user)
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    include 'js-validation-file.html';
    ?>

    <script type="text/javascript">
        var popup1, popup2, splofferpopup1;
        var bas_cal, dp_cal1, dp_cal2, ms_cal; // declare the calendars as global variables 
        window.onload = function() {
            dp_cal1 = new Epoch('dp_cal1', 'popup', document.getElementById('user_dob'));
        };
    </script>
    <h3>Extra profile information</h3>

    <table class="form-table">
        <tr>
            <th><label for="user_address1">Address1 <span class="description">(required)</span></label></th>
            <td>
                <input type="text" name="user_address1" id="user_address1" value="<?php 
    _e(esc_attr(get_the_author_meta('user_address1', $user->ID)));
    ?>
" class="regular-text" required = true /><br />
                <!-- <span class="description">You edit here your address.</span>  -->
            </td>
        </tr>

        <tr>
            <th><label for="user_address2">Address2</label></th>
            <td>
                <input type="text" name="user_address2" id="user_address2" value="<?php 
    _e(esc_attr(get_the_author_meta('user_address2', $user->ID)));
    ?>
" class="regular-text" /><br />
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

        <tr>
            <th><label for="user_city">City <span class="description">(required)</span></label></th>
            <td>
                <input type="text" name="user_city" id="user_city" value="<?php 
    _e(esc_attr(get_the_author_meta('user_city', $user->ID)));
    ?>
" class="regular-text" required = true /><br />
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

        <tr>
            <th><label for="user_state">State <span class="description">(required)</span></label></th>
            <td>
                <input type="text" name="user_state" id="user_state" value="<?php 
    _e(esc_attr(get_the_author_meta('user_state', $user->ID)));
    ?>
" class="regular-text" required = true /><br />
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

        <tr>
            <th><label for="user_postalcode">Postal Code <span class="description">(required)</span></label></th>
            <td>
                <input type="text" name="user_postalcode" id="user_postalcode" value="<?php 
    _e(esc_attr(get_the_author_meta('user_postalcode', $user->ID)));
    ?>
" class="regular-text" required = true /><br />
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

        <tr>
            <th><label for="user_country">Country <span class="description">(required)</span></label></th>
            <td>
                <?php 
    $sql = "SELECT name\n\t\t\t\t\t\t\tFROM {$table_prefix}mlm_country\n\t\t\t\t\t\t\tORDER BY name";
    $results = $wpdb->get_results($sql);
    ?>
                <select name="user_country" id="user_country" required = true >
                    <option value="">Select Country</option>
                    <?php 
    foreach ($results as $row) {
        if (esc_attr(get_the_author_meta('user_country', $user->ID)) == $row->name) {
            $selected = 'selected';
        } else {
            $selected = '';
        }
        ?>
                        <option value="<?php 
        echo $row->name;
        ?>
" <?php 
        echo $selected;
        ?>
><?php 
        echo $row->name;
        ?>
</option>
                        <?php 
    }
    ?>
                </select>
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

        <tr>
            <th><label for="user_telephone">Contact No. <span class="description">(required)</span></label></th>
            <td>
                <input type="text" name="user_telephone" id="user_telephone" value="<?php 
    _e(esc_attr(get_the_author_meta('user_telephone', $user->ID)));
    ?>
" class="regular-text" required = true /><br />
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

        <tr>
            <th><label for="user_dob">Date of Birth <span class="description">(required)</span></label></th>
            <td>
                <input type="text" name="user_dob" id="user_dob" value="<?php 
    _e(esc_attr(get_the_author_meta('user_dob', $user->ID)));
    ?>
" class="regular-text" required = true /><br />
                <!-- <span class="description">Please edit here your address.</span> -->
            </td>
        </tr>

    </table>
    <?php 
}
function myLeftGroupDetails($id = '')
{
    $table_prefix = mlm_core_get_table_prefix();
    global $wpdb;
    //get loged user's key
    if ($id == '') {
        $key = get_current_user_key();
    } else {
        $key = $wpdb->get_var("SELECT user_key FROM {$table_prefix}mlm_users WHERE user_id = {$id}");
    }
    //Total Users on My left leg
    $leftLegUsers = totalLeftLegUsers($key);
    //paid users on my left leg
    $leftLegActiveUsers = activeUsersOnLeftLeg($key);
    //show total users on left leg
    $totalLeftLegUsers = myTotalLeftLegUsers($key);
    //_e("<pre>");print_r($totalLeftLegUsers);exit;
    ?>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load('visualization', '1', {packages: ['table']});
    </script>
    <script type="text/javascript">
        var visualization;
        var data;
        var options = {'showRowNumber': true};
        function drawVisualization() {
            // Create and populate the data table.
            var dataAsJson =
                    {cols: [
                            {id: 'A', label: '<?php 
    echo _e("User Name", "binary-mlm-pro");
    ?>
', type: 'string'},
                            {id: 'B', label: '<?php 
    echo _e("User Key", "binary-mlm-pro");
    ?>
 ', type: 'string'},
                            {id: 'C', label: '<?php 
    echo _e("Sponsor", "binary-mlm-pro");
    ?>
', type: 'string'},
                            {id: 'D', label: '<?php 
    echo _e("Status", "binary-mlm-pro");
    ?>
', type: 'string'}],
                        rows: [
    <?php 
    foreach ($totalLeftLegUsers as $row) {
        ?>
                                {c: [{v: '<?php 
        echo $row['username'];
        ?>
'}, {v: '<?php 
        echo $row['user_key'];
        ?>
'}, {v: '<?php 
        echo $row['sponsor_key'];
        ?>
'}, {v: '<?php 
        echo $row['payment_status'];
        ?>
'}]},
    <?php 
    }
    ?>
                        ]};
            data = new google.visualization.DataTable(dataAsJson);
            // Set paging configuration options
            // Note: these options are changed by the UI controls in the example.
            options['page'] = 'enable';
            options['pageSize'] = 10;
            options['pagingSymbols'] = {prev: 'prev', next: 'next'};
            options['pagingButtonsConfiguration'] = 'auto';
            //options['allowHtml'] = true;
            //data.sort({column:1, desc: false});
            // Create and draw the visualization.
            visualization = new google.visualization.Table(document.getElementById('table'));
            draw();
        }
        function draw() {
            visualization.draw(data, options);
        }
        google.setOnLoadCallback(drawVisualization);
        // sets the number of pages according to the user selection.
        function setNumberOfPages(value) {
            if (value) {
                options['pageSize'] = parseInt(value, 10);
                options['page'] = 'enable';
            } else {
                options['pageSize'] = null;
                options['page'] = null;
            }
            draw();
        }
        // Sets custom paging symbols "Prev"/"Next"
        function setCustomPagingButtons(toSet) {
            options['pagingSymbols'] = toSet ? {next: 'next', prev: 'prev'} : null;
            draw();
        }
        function setPagingButtonsConfiguration(value) {
            options['pagingButtonsConfiguration'] = value;
            draw();
        }
    </script>
    <!--va-matter-->
    <div class="va-matter">
        <!--va-matterbox-->
        <div class="va-matterbox">
            <!--va-headname-->
            <div class="va-headname"><?php 
    _e('My Left Group Details', 'binary-mlm-pro');
    ?>
</div>
            <!--/va-headname-->
            <div class="va-admin-leg-details">
                <!--va-admin-mid-->
                <div class="paging">
                    <form action="">
                        <div class="left-side">
                            <?php 
    _e('Display Number of Rows', 'binary-mlm-pro');
    ?>
 : &nbsp; 
                        </div>
                        <div class="right-side">
                            <select style="font-size: 12px" onchange="setNumberOfPages(this.value)">
                                <option value="5">5</option>
                                <option selected="selected" value="10">10</option>
                                <option value="20">20</option>
                                <option  value="50">50</option>
                                <option value="100">100</option>
                                <option value="500">500</option>
                                <option value="">All</option>
                            </select>
                        </div>	
                    </form>
                    <div class="right-members">
                        <?php 
    _e('Total Users', 'binary-mlm-pro');
    ?>
: <strong><?php 
    echo $leftLegUsers;
    ?>
</strong>&nbsp;<?php 
    _e('Active Users', 'binary-mlm-pro');
    ?>
: <strong><?php 
    echo $leftLegActiveUsers;
    ?>
</strong>
                    </div>
                    <div class="va-clear"></div>
                </div>
                <div id="table"></div>
                <div class="va-clear"></div>
            </div>		
        </div>
    </div>	
    <?php 
}
function mlmRoyaltyBonus()
{
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //get no. of level
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    //most outer if condition
    if (isset($_POST['mlm_royalty_bonus_settings'])) {
        $per_ref = count(array_filter($_POST['per_ref']));
        $pay_value = count(array_filter($_POST['pay_value']));
        $level = $_POST['level'];
        if ($per_ref == 0) {
            $error .= "\n Please Specify No. of Personal Referral.";
        }
        if ($pay_value == 0) {
            $error .= "\n Please Specify Payout Value.";
        }
        if (checkInputField($level)) {
            $error .= "\n Please Select Level.";
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_royalty_bonus_settings', $_POST);
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=deduction";
            _e("<script>window.location='{$url}'</script>");
            $msg = _e("<span style='color:green;'>Your bonus has been successfully updated.</span>", 'unilevel-mlm-pro');
        }
    }
    // end outer if condition
    if ($chk != '') {
        $mlm_settings = get_option('wp_mlm_royalty_bonus_settings');
        ?>
<div class='wrap1'>
	<h2><?php 
        _e('Royalty Bonus Settings', 'unilevel-mlm-pro');
        ?>
  </h2>
	<div class="notibar msginfo">
		<a class="close"></a>
		<p><?php 
        _e('Royalty Bonus is a % bonus paid to a member on the total commissions earned by a particular level under the member.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('No. of Personal Referrers', 'unilevel-mlm-pro');
        ?>
 - </strong><?php 
        _e('This is the value of the personal referrers which would trigger a bonus distribution in the network.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Payout Value', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('This is the payout value in terms of the percentage amount that would be paid to the member.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Level', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e(' The system would calculate the total commissions for Level X under the member and distribute a bonus equal to Y% (the payout value above) of the total commissions at Level X.', 'unilevel-mlm-pro');
        ?>
</p>
<p><?php 
        _e('eg. Slab 1 = Personal Referrals = 5, Payout Value = 2 and Level = Level 1, then the system would distribute a bonus equal to 2% of the total commission earned by all the members who are at Level of that member.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Option 1', 'unilevel-mlm-pro');
        ?>
</strong></p>
<p><?php 
        _e('If the first bonus slab is as above and the second bonus slab is as follows', 'unilevel-mlm-pro');
        ?>
</p>
<p><?php 
        _e('Slab 2 = Personal Referrals = 10, Payout Value = 4 and Level = Level 1.', 'unilevel-mlm-pro');
        ?>
</p>
</br>
<p><?php 
        _e('Then, if this member has already referred 10 or more people, he would stop earning the bonus for Slab 1 as he cannot earn both 2% and 4% bonus for the same level.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Option 2', 'unilevel-mlm-pro');
        ?>
</strong></p>
<p><?php 
        _e('The first and second bonus slabs are as above and the third bonus slab is as follows:', 'unilevel-mlm-pro');
        ?>
</p>
<p><?php 
        _e('Slab 3 = Personal Referrals = 20, Payout Value = 1, Level = Level 2.', 'unilevel-mlm-pro');
        ?>
</p>
</br>
<p><?php 
        _e('Then, if this member has already reached 20 or more personal referrals, he would earn the bonus for both Slab 2 and Slab 3. As in the above Option 1 he would stop earning the commission for Slab 1 as Slab 2 is a higher version of Slab 1.', 'unilevel-mlm-pro');
        ?>
</p>

	</div>
	
	<?php 
        if ($error) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p> <strong><?php 
            _e('Please Correct the following Error', 'unilevel-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	<?php 
        if (!empty($msg)) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p><?php 
            _e($msg);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	

<?php 
        if (empty($mlm_settings)) {
            ?>
<form name="admin_bonus_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		
		
		<tr>

			<td>
				<INPUT type="button" value="<?php 
            _e('Add Row', 'unilevel-mlm-pro');
            ?>
" onclick="addRow('dataTable')" class='button-primary' />
    			<INPUT type="button" value="<?php 
            _e('Delete Row', 'unilevel-mlm-pro');
            ?>
" onclick="deleteRow('dataTable')" class='button-primary' />
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
            _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450">
		<TR>
			<TD align="left" width="10%"><strong><?php 
            _e('Select', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="40%"> <strong><?php 
            _e('No. of Personal Referrals', 'unilevel-mlm-pro');
            ?>
</strong></TD>

			<TD align="left" width="25%"> <strong><?php 
            _e('Payout Value (%)', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="25%"><strong><?php 
            _e('Level', 'unilevel-mlm-pro');
            ?>
</strong></TD>
		</TR>
	</TABLE>
	<br\>
	<TABLE id="dataTable"  cellspacing="5" cellpadding="5" border="0" width="450">
		<TR>
			<TD align="left" width="10%"><INPUT type="checkbox" name="chk[]"/></TD>
			<TD align="left" width="40%"> <INPUT type="text" name="per_ref[]" size="15" /> </TD>

			<TD align="center" width="25%"> <INPUT type="text" name="pay_value[]" size="10" /> </TD>
			<TD align="center" width="25%"> 
			<select name="level[]" id="level" >
				<option value=""><?php 
            _e('Select Level', 'unilevel-mlm-pro');
            ?>
</option> 
				<?php 
            for ($k = 1; $k <= $mlm_no_of_level; $k++) {
                ?>
				<option value="<?php 
                echo $k;
                ?>
" <?php 
                echo isset($_POST['level']) && $_POST['level'] == $k ? 'selected' : '';
                ?>
><?php 
                _e('Level ' . $k, 'unilevel-mlm-pro');
                ?>
</option>
				<?php 
            }
            ?>
				</select> </TD>
		</TR>
	</TABLE>
	
	<table border="0" width="100%">	
		<tr>
			<td>
		<p class="submit">
	<input type="submit" name="mlm_royalty_bonus_settings" id="mlm_royalty_bonus_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
			</td>
		<tr>
	</table>
</form>
</div>
<script language="JavaScript">
  populateArrays();
</script>
<?php 
        } else {
            if (!empty($mlm_settings)) {
                ?>
		
			<form name="admin_bouns_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		<tr>
			<td>
				<INPUT type="button" value="<?php 
                _e('Add Row', 'unilevel-mlm-pro');
                ?>
" onclick="addRow('dataTable')" class='button-primary'/>
    			<INPUT type="button" value="<?php 
                _e('Delete Row', 'unilevel-mlm-pro');
                ?>
" onclick="deleteRow('dataTable')" class='button-primary'/>
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
                _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450" >
		<TR>
			<TD align="left" width="10%"><strong><?php 
                _e('Select', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="40%"> <strong><?php 
                _e('No. of Personal Referrals', 'unilevel-mlm-pro');
                ?>
</strong></TD>

			<TD align="left" width="25%"> <strong><?php 
                _e('Payout Value (%)', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="25%"><strong><?php 
                _e('Level', 'unilevel-mlm-pro');
                ?>
</strong></TD>
		</TR>
	</TABLE>
	<br\>
		<TABLE id="dataTable"   cellspacing="5" cellpadding="5" border="0" width="450">
		<?php 
                $i = 0;
                while ($i < count($mlm_settings['per_ref'])) {
                    ?>
        	<TR>
           		<TD align="left" width="10%"><INPUT type="checkbox" name="chk[]"/></TD>
				<TD align="left" width="40%"> <INPUT type="text" name="per_ref[]" size="15" value="<?php 
                    echo $mlm_settings['per_ref'][$i];
                    ?>
"/> </TD>
				<TD align="left" width="25%"> 
			 <INPUT type="text" name="pay_value[]" size="10" value="<?php 
                    echo $mlm_settings['pay_value'][$i];
                    ?>
"/> </TD>
				<TD align="left" width="25%"> 
			<select name="level[]" id="level" >
				<option value=""><?php 
                    _e('Select Level', 'unilevel-mlm-pro');
                    ?>
</option> 
				<?php 
                    for ($k = 1; $k <= $mlm_no_of_level; $k++) {
                        ?>
				<option value="<?php 
                        echo $k;
                        ?>
" <?php 
                        echo $mlm_settings['level'][$i] == $k ? 'selected' : '';
                        ?>
><?php 
                        _e('Level ' . $k, 'unilevel-mlm-pro');
                        ?>
</option>
				<?php 
                    }
                    ?>
				</select> </TD>
				
				
        	</TR>    	
		<?php 
                    $i++;
                }
                ?>
		</TABLE>
	
	<p class="submit">
	<input type="submit" name="mlm_royalty_bonus_settings" id="mlm_royalty_bonus_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
</form>
</div>
<script language="JavaScript">
  populateArrays();
</script>
			<?php 
            }
        }
    } else {
        _e($msg);
    }
}
function mlmDeduction()
{
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //most outer if condition
    if (isset($_POST['mlm_withdrawal_settings'])) {
        $withdwl_mthd = count(array_filter($_POST['withdwl_mthd']));
        $withdwl_type = $_POST['withdwl_type'];
        $withdwl_amt = count(array_filter($_POST['withdwl_amt']));
        if ($withdwl_mthd == 0) {
            $error .= "\n Please Specify Name of Withdrawal Method.";
        }
        if ($withdwl_amt == 0) {
            $error .= "\n Please Specify Amount.";
        }
        if (checkInputField($withdwl_type)) {
            $error .= "\n Please Specify Type.";
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_withdrawal_method_settings', $_POST);
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=deduction";
            _e("<script>window.location='{$url}'</script>");
            $msg = _e("<span style='color:green;'>Your Withdrawal Settings has been successfully updated.</span>", 'unilevel-mlm-pro');
        }
    } else {
        if (isset($_POST['mlm_other_method_settings'])) {
            $othr_mthd = count(array_filter($_POST['othr_mthd']));
            $othr_type = $_POST['othr_type'];
            $othr_amt = count(array_filter($_POST['othr_amt']));
            if ($othr_mthd == 0) {
                $error .= "\n Please Specify Name of Other Method.";
            }
            if ($othr_amt == 0) {
                $error .= "\n Please Specify Amount.";
            }
            if (checkInputField($othr_type)) {
                $error .= "\n Please Specify Type.";
            }
            //if any error occoured
            if (!empty($error)) {
                $error = nl2br($error);
            } else {
                $chk = '';
                update_option('wp_mlm_other_method_settings', $_POST);
                $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=deduction";
                _e("<script>window.location='{$url}'</script>");
                $msg = _e("<span style='color:green;'>Your Other Method Settings has been successfully updated.</span>", 'unilevel-mlm-pro');
            }
        }
    }
    // end outer if condition
    if ($chk != '') {
        $mlm_withdrawal_settings = get_option('wp_mlm_withdrawal_method_settings');
        $mlm_other_settings = get_option('wp_mlm_other_method_settings');
        ?>
<div class='wrap1'>
	<h2><?php 
        _e('Deductions Settings', 'unilevel-mlm-pro');
        ?>
  </h2>
	<div class="notibar msginfo">
		<a class="close"></a>
		<p><?php 
        _e('These settings will define the amounts that would be deducted from the withdrawals made by members in their Member\'s Area.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Withdrawal	Methods', 'unilevel-mlm-pro');
        ?>
 - </strong></p>
<p><?php 
        _e('You can configure the various withdrawal methods and the amount (fixed or percentage) that would be deductible if the member opts for a particular method of withdrawal.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Other	deductions', 'unilevel-mlm-pro');
        ?>
 -</strong> </p>
<p><?php 
        _e('You can configure other deductions that would be deducted from a withdrawal. Typical examples could include a general service charge, withholding tax or any other amount that you like to deduct from the withdrawal amount.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Note ', 'unilevel-mlm-pro');
        ?>
 : </strong> 
<?php 
        _e('All % amounts would always apply the specified % to the actual amount withdrawn.', 'unilevel-mlm-pro');
        ?>
</p>
</div>
	
	<?php 
        if ($error) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p> <strong><?php 
            _e('Please Correct the following Error', 'unilevel-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	<?php 
        if (!empty($msg)) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p><?php 
            _e($msg);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	

<?php 
        if (empty($mlm_withdrawal_settings)) {
            ?>
<form name="admin_withdrawalsettings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		
		<tr><td><h3><?php 
            _e('Withdrawal Method', 'unilevel-mlm-pro');
            ?>
</h3></td></tr>
		<tr>

			<td>
				<INPUT type="button" value="<?php 
            _e('Add Row', 'unilevel-mlm-pro');
            ?>
" onclick="addRow('dataTable')" class='button-primary' />
    			<INPUT type="button" value="<?php 
            _e('Delete Row', 'unilevel-mlm-pro');
            ?>
" onclick="deleteRow('dataTable')" class='button-primary' />
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
            _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450">
		<TR>
			<TD align="left" width="10%"><strong><?php 
            _e('Select', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="35%"> <strong><?php 
            _e('Withdrawal Method', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="20%"> <strong><?php 
            _e('Amount', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="20%"> <strong><?php 
            _e('Min. </br>Amount', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="20%"><strong><?php 
            _e('Type', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			
			
		</TR>
	</TABLE>
	<br\>
	<TABLE id="dataTable"  cellspacing="5" cellpadding="5" border="0" width="450">
		<TR>
			<TD align="left" width="10%"><INPUT type="checkbox" name="chk[]"/></TD>
			<TD align="left" width="40%"> <INPUT type="text" name="withdwl_mthd[]" size="15" /> </TD>
			<TD align="left" width="20%"> <INPUT type="text" name="withdwl_amt[]" size="5" /> </TD>
			<TD align="left" width="20%"> <INPUT type="text" name="min_amount[]" size="5" /> </TD>
			<TD align="left" width="20%"> 
			<select name="withdwl_type[]" id="withdwl_type">
				<option value=""><?php 
            _e('Select Type', 'unilevel-mlm-pro');
            ?>
</option>
				<option value="fixed" <?php 
            echo isset($_POST['withdwl_type']) && $_POST['withdwl_type'] == 'fixed' ? 'selected' : '';
            ?>
><?php 
            _e('Fixed', 'unilevel-mlm-pro');
            ?>
</option>
				<option value="percent" <?php 
            echo isset($_POST['withdwl_type']) && $_POST['withdwl_type'] == 'percent' ? 'selected' : '';
            ?>
><?php 
            _e('Percentage', 'unilevel-mlm-pro');
            ?>
</option>
				</select> </TD>

		</TR>
	</TABLE>
	
	<table border="0" width="100%">	
		<tr>
			<td>
		<p class="submit">
	<input type="submit" name="mlm_withdrawal_settings" id="mlm_withdrawal_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
			</td>
		<tr>
	</table>
</form>

<script language="JavaScript">
  populateArrays();
</script>
<?php 
        } else {
            if (!empty($mlm_withdrawal_settings)) {
                ?>
		
			<form name="admin_withdrawal_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
	<tr><td><h3><?php 
                _e('Withdrawal Method', 'unilevel-mlm-pro');
                ?>
</h3></td></tr>
		<tr>
		<tr>
			<td>
				<INPUT type="button" value="<?php 
                _e('Add Row', 'unilevel-mlm-pro');
                ?>
" onclick="addRow('dataTable')" class='button-primary'/>
    			<INPUT type="button" value="<?php 
                _e('Delete Row', 'unilevel-mlm-pro');
                ?>
" onclick="deleteRow('dataTable')" class='button-primary'/>
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
                _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450" >
		<TR>
			<TD align="left" width="10%"><strong><?php 
                _e('Select', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="35%"> <strong><?php 
                _e('Withdrawal Method', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="20%"> <strong><?php 
                _e('Amount', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="20%"> <strong><?php 
                _e('Min. </br> Amount', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="20%"><strong><?php 
                _e('Type', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			
			
		</TR>
		
	</TABLE>
	<br\>
		<TABLE id="dataTable"   cellspacing="5" cellpadding="5" border="0" width="450">
		<?php 
                $i = 0;
                while ($i < count($mlm_withdrawal_settings['withdwl_mthd'])) {
                    ?>
        	<TR>
           		<TD  align="left" width="10%"><INPUT type="checkbox" name="chk[]"/></TD>
				<TD  align="left" width="40%"> <INPUT type="text" name="withdwl_mthd[]" size="15" value="<?php 
                    echo $mlm_withdrawal_settings['withdwl_mthd'][$i];
                    ?>
"/> </TD>
				
				<TD> <INPUT type="text" name="withdwl_amt[]" size="5" value="<?php 
                    echo $mlm_withdrawal_settings['withdwl_amt'][$i];
                    ?>
"/> </TD>
				<TD> <INPUT type="text" name="min_amount[]" size="5" value="<?php 
                    echo $mlm_withdrawal_settings['min_amount'][$i];
                    ?>
"/> </TD>
				<TD align="center" width="25%"> 
			<select name="withdwl_type[]" id="withdwl_type">
				<option value=""><?php 
                    _e('Select Type', 'unilevel-mlm-pro');
                    ?>
</option>
				<option value="fixed" <?php 
                    echo $mlm_withdrawal_settings['withdwl_type'][$i] == 'fixed' ? 'selected' : '';
                    ?>
><?php 
                    _e('Fixed', 'unilevel-mlm-pro');
                    ?>
</option>
				<option value="percent" <?php 
                    echo $mlm_withdrawal_settings['withdwl_type'][$i] == 'percent' ? 'selected' : '';
                    ?>
><?php 
                    _e('Percentage', 'unilevel-mlm-pro');
                    ?>
</option>
				</select> </TD>
				
				
				
				
        	</TR>    	
		<?php 
                    $i++;
                }
                ?>
		</TABLE>
	
	<p class="submit">
	<input type="submit" name="mlm_withdrawal_settings" id="mlm_withdrawal_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
</form>

<script language="JavaScript">
  populateArrays();
</script>
			<?php 
            }
        }
        if (empty($mlm_other_settings)) {
            ?>
<form name="admin_other_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
			<tr><td><h3><?php 
            _e('Other Deductions', 'unilevel-mlm-pro');
            ?>
</h3></td></tr>	
		
		<tr>

			<td>
				<INPUT type="button" value="<?php 
            _e('Add Row', 'unilevel-mlm-pro');
            ?>
" onclick="addRow('dataWithDrawalTable')" class='button-primary' />
    			<INPUT type="button" value="<?php 
            _e('Delete Row', 'unilevel-mlm-pro');
            ?>
" onclick="deleteRow('dataWithDrawalTable')" class='button-primary' />
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
            _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450">
		<TR>
			<TD align="left" width="10%"><strong><?php 
            _e('Select', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="40%"> <strong><?php 
            _e('Name of Deduction', 'unilevel-mlm-pro');
            ?>
</strong></TD>

			<TD align="left" width="25%"> <strong><?php 
            _e('Amount', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="25%"><strong><?php 
            _e('Type', 'unilevel-mlm-pro');
            ?>
</strong></TD>
		</TR>
	</TABLE>
	<br\>
	<TABLE id="dataWithDrawalTable"  cellspacing="5" cellpadding="5" border="0" width="450">
		<TR>
			<TD align="left" width="10%"><INPUT type="checkbox" name="chk[]"/></TD>
			<TD align="left" width="40%"> <INPUT type="text" name="othr_mthd[]" size="15" /> </TD>

			<TD align="center" width="25%"> <INPUT type="text" name="othr_amt[]" size="10" /> </TD>
			<TD align="center" width="25%"> 
			<select name="othr_type[]" id="othr_type">
				<option value=""><?php 
            _e('Select Type', 'unilevel-mlm-pro');
            ?>
</option>
				<option value="fixed" <?php 
            echo isset($_POST['othr_type']) && $_POST['othr_type'] == 'fixed' ? 'selected' : '';
            ?>
><?php 
            _e('Fixed', 'unilevel-mlm-pro');
            ?>
</option>
				<option value="percent" <?php 
            echo isset($_POST['othr_type']) && $_POST['othr_type'] == 'fixed' ? 'selected' : '';
            ?>
><?php 
            _e('Percentage', 'unilevel-mlm-pro');
            ?>
</option>
				</select> </TD>
		</TR>
	</TABLE>
	
	<table border="0" width="100%">	
		<tr>
			<td>
		<p class="submit">
	<input type="submit" name="mlm_other_method_settings" id="mlm_other_method_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
			</td>
		<tr>
	</table>
</form>
</div>
<script language="JavaScript">
  populateArrays();
</script>
<?php 
        } else {
            if (!empty($mlm_other_settings)) {
                ?>
		
			<form name="admin_other_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
	<tr><td><h3><?php 
                _e('Other Deductions', 'unilevel-mlm-pro');
                ?>
</h3></td></tr>	
	
	<tr>
			<td>
				<INPUT type="button" value="<?php 
                _e('Add Row', 'unilevel-mlm-pro');
                ?>
" onclick="addRow('dataWithDrawalTable')" class='button-primary'/>
    			<INPUT type="button" value="<?php 
                _e('Delete Row', 'unilevel-mlm-pro');
                ?>
" onclick="deleteRow('dataWithDrawalTable')" class='button-primary'/>
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
                _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450" >
		<TR>
			<TD align="left" width="10%"><strong><?php 
                _e('Select', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="40%"> <strong><?php 
                _e('Name of Deduction', 'unilevel-mlm-pro');
                ?>
</strong></TD>

			<TD align="left" width="25%"> <strong><?php 
                _e('Amount', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="25%"><strong><?php 
                _e('Type', 'unilevel-mlm-pro');
                ?>
</strong></TD>
		</TR>
	</TABLE>
	<br\>
		<TABLE id="dataWithDrawalTable"   cellspacing="5" cellpadding="5" border="0" width="450">
		<?php 
                $i = 0;
                while ($i < count($mlm_other_settings['othr_mthd'])) {
                    ?>
        	<TR>
           		<TD  align="left" width="10%"><INPUT type="checkbox" name="chk[]"/></TD>
				<TD  align="left" width="40%"> <INPUT type="text" name="othr_mthd[]" size="15" value="<?php 
                    echo $mlm_other_settings['othr_mthd'][$i];
                    ?>
"/> </TD>
				<TD align="left" width="25%"> 
			 <INPUT type="text" name="othr_amt[]" size="10" value="<?php 
                    echo $mlm_other_settings['othr_amt'][$i];
                    ?>
"/> </TD>
				<TD align="center" width="25%"> 
			<select name="othr_type[]" id="othr_type">
				<option value=""><?php 
                    _e('Select Type', 'unilevel-mlm-pro');
                    ?>
</option>
				<option value="fixed" <?php 
                    echo $mlm_other_settings['othr_type'][$i] == 'fixed' ? 'selected' : '';
                    ?>
><?php 
                    _e('Fixed', 'unilevel-mlm-pro');
                    ?>
</option>
				<option value="percent" <?php 
                    echo $mlm_other_settings['othr_type'][$i] == 'percent' ? 'selected' : '';
                    ?>
><?php 
                    _e('Percentage', 'unilevel-mlm-pro');
                    ?>
</option>
				</select> </TD>
				
				
        	</TR>    	
		<?php 
                    $i++;
                }
                ?>
		</TABLE>
	
	<p class="submit">
	<input type="submit" name="mlm_other_method_settings" id="mlm_other_method_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
</form>
</div>
<script language="JavaScript">
  populateArrays();
</script>
<?php 
            }
        }
    } else {
        _e($msg);
    }
}
function register_user_html_page()
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    global $current_user;
    get_currentuserinfo();
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    if (!empty($_GET['sp_name'])) {
        $sp_name = $_GET['sp_name'];
        ?>
		 <script>$.cookie('s_name','<?php 
        echo $sp_name;
        ?>
',{ path: '/' });</script>
	       
	       <?php 
        //setcookie("s_name", $sp_name);
    } else {
        if (!empty($_GET['sp'])) {
            $sp_name = getusernamebykey($_GET['sp']);
            ?>
		 <script>$.cookie('s_name','<?php 
            echo $sp_name;
            ?>
',{ path: '/' });</script>
	       
	       <?php 
        } else {
            $sp_name = $_COOKIE["s_name"];
        }
    }
    //echo $_COOKIE["s_name"]."hello";
    //get no. of level
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    $mlm_pay_settings = get_option('wp_mlm_payment_settings');
    $mlm_method = get_option('wp_mlm_payment_method');
    if (is_user_logged_in()) {
        $sponsor_name = $current_user->user_login;
        $readonly_sponsor = 'readonly';
        $spnsr_set = 1;
    } else {
        if (isset($_REQUEST['sp_name']) && $_REQUEST['sp_name'] != '') {
            //$sponsorName = getusernamebykey($_REQUEST['sp']);
            $sponsorName = $_REQUEST['sp_name'];
            if (isset($sponsorName) && $sponsorName != '') {
                $readonly_sponsor = 'readonly';
                $sponsor_name = $sponsorName;
            } else {
                redirectPage(home_url(), array());
                exit;
            }
        } else {
            if (isset($_COOKIE["s_name"]) && $_COOKIE["s_name"] != '') {
                $readonly_sponsor = 'readonly';
                $sponsor_name = $_COOKIE["s_name"];
            } else {
                if (isset($_REQUEST['sp']) && $_REQUEST['sp'] != '') {
                    //$sponsorName = getusernamebykey($_REQUEST['sp']);
                    $sponsorName = getusernamebykey($_REQUEST['sp']);
                    if (isset($sponsorName) && $sponsorName != '') {
                        $readonly_sponsor = 'readonly';
                        $sponsor_name = $sponsorName;
                    } else {
                        redirectPage(home_url(), array());
                        exit;
                    }
                } else {
                    // $sponsor_name = get_top_level_user();
                    //$readonly_sponsor = 'readonly';
                    $readonly_sponsor = '';
                }
            }
        }
    }
    //most outer if condition
    if (isset($_POST['submit'])) {
        $firstname = sanitize_text_field($_POST['firstname']);
        $lastname = sanitize_text_field($_POST['lastname']);
        $username = sanitize_text_field($_POST['username']);
        /******* check for the epin field ******/
        if (isset($_POST['epin']) && !empty($_POST['epin'])) {
            $epin = sanitize_text_field($_POST['epin']);
        } else {
            if (isset($_POST['epin']) && empty($_POST['epin'])) {
                $epin = '';
            }
        }
        /******* check for the epin field ******/
        $password = sanitize_text_field($_POST['password']);
        $confirm_pass = sanitize_text_field($_POST['confirm_password']);
        $email = sanitize_text_field($_POST['email']);
        $confirm_email = sanitize_text_field($_POST['confirm_email']);
        $sponsor = sanitize_text_field($_POST['sponsor']);
        /*$address1 = sanitize_text_field( $_POST['address1'] );
        		$address2 = sanitize_text_field( $_POST['address2'] );
        		city = sanitize_text_field( $_POST['city'] );
        		$state = sanitize_text_field( $_POST['state'] );
        		$postalcode = sanitize_text_field( $_POST['postalcode'] );
        		$telephone = sanitize_text_field( $_POST['telephone'] );
        		$dob = sanitize_text_field( $_POST['dob'] );*/
        //Add usernames we don't want used
        $invalid_usernames = array('admin');
        //Do username validation
        $username = sanitize_user($username);
        if (!validate_username($username) || in_array($username, $invalid_usernames)) {
            $error .= "\n Username is invalid.";
        }
        if (username_exists($username)) {
            $error .= "\n Username already exists.";
        }
        /******* check for the epin field ******/
        if (!empty($epin) && epin_exists($epin)) {
            $error .= "\n ePin already issued or wrong ePin.";
        }
        if (!empty($mlm_general_settings['sol_payment']) && empty($epin)) {
            $error .= "\n Please enter your ePin.";
        } else {
            if (empty($_POST['epin_value']) && empty($epin)) {
                $error .= "\n Please either enter the ePin or select the Product.";
            }
        }
        /******* check for the epin field ******/
        if (checkInputField($password)) {
            $error .= "\n Please enter your password.";
        }
        if (confirmPassword($password, $confirm_pass)) {
            $error .= "\n Please confirm your password.";
        }
        //Do e-mail address validation
        if (!is_email($email)) {
            $error .= "\n E-mail address is invalid.";
        }
        if (email_exists($email)) {
            $error .= "\n E-mail address is already in use.";
        }
        if (confirmEmail($email, $confirm_email)) {
            $error .= "\n Please confirm your email address.";
        }
        if (checkInputField($firstname)) {
            $error .= "\n Please enter your first name.";
        }
        if (checkInputField($lastname)) {
            $error .= "\n Please enter your last name.";
        }
        if (checkInputField($sponsor) && !empty($sponsor)) {
            $error .= "\n Please enter your sponsor name.";
        }
        if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
            $paypalId = sanitize_text_field($_POST['paypal_id']);
            if (checkInputField($paypalId)) {
                $error .= "\n Please enter your Paypal id.";
            }
        }
        /*if ( checkInputField($address1) ) 
        			$error .= "\n Please enter your address.";
        			
        		if ( checkInputField($city) ) 
        			$error .= "\n Please enter your city.";
        			
        		if ( checkInputField($state) ) 
        			$error .= "\n Please enter your state.";
        			
        		if ( checkInputField($postalcode) ) 
        			$error .= "\n Please enter your postal code.";
        			
        		if ( checkInputField($telephone) ) 
        			$error .= "\n Please enter your contact number.";
        
        		if ( checkInputField($dob) ) 
        			$error .= "\n Please enter your date of birth.";*/
        //Case If User is not fill the Sponser field
        if (empty($_POST['sponsor'])) {
            $sponsor = get_top_level_user();
        }
        $sql = "SELECT COUNT(*) num, `user_key` \n\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\tWHERE `username` = '" . $sponsor . "'";
        $intro = $wpdb->get_row($sql);
        //generate random numeric key for new user registration
        $user_key = generateKey();
        //if generated key is already exist in the DB then again re-generate key
        do {
            $check = $wpdb->get_var("SELECT COUNT(*) ck \n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `user_key` = '" . $user_key . "'");
            $flag = 1;
            if ($check == 1) {
                $user_key = generateKey();
                $flag = 0;
            }
        } while ($flag == 0);
        // outer if condition
        if (empty($error)) {
            // inner if condition
            if ($intro->num == 1) {
                $sponsor = $intro->user_key;
                $sponsor1 = $sponsor;
                //find parent key
                if (!empty($_GET['k']) && $_GET['k'] != '') {
                    $parent_key = $_GET['k'];
                } else {
                    $readonly_sponsor = '';
                    $parent_key = $sponsor;
                }
                $user = array('user_login' => $username, 'user_pass' => $password, 'first_name' => $firstname, 'last_name' => $lastname, 'user_email' => $email, 'role' => 'mlm_user');
                // return the wp_users table inserted user's ID
                $user_id = wp_insert_user($user);
                //get the selected country name from the country table
                $country = $_POST['country'];
                $sql = "SELECT name \n\t\t\t\t\t\tFROM {$table_prefix}mlm_country\n\t\t\t\t\t\tWHERE id = '" . $country . "'";
                $country1 = $wpdb->get_var($sql);
                //insert the registration form data into user_meta table
                /*add_user_meta( $user_id, 'user_address1', $address1, FALSE ); 
                		add_user_meta( $user_id, 'user_address2', $address2, FALSE );
                		add_user_meta( $user_id, 'user_city', $city, FALSE );
                		add_user_meta( $user_id, 'user_state', $state, FALSE );
                		add_user_meta( $user_id, 'user_country', $country1, FALSE );
                		add_user_meta( $user_id, 'user_postalcode', $postalcode, FALSE );
                		add_user_meta( $user_id, 'user_telephone', $telephone, FALSE );
                		add_user_meta( $user_id, 'user_dob', $dob, FALSE);*/
                /*Send e-mail to admin and new user - 
                		You could create your own e-mail instead of using this function*/
                wp_new_user_notification($user_id, $password);
                if (!empty($epin)) {
                    $pointResult = $wpdb->get_row("select p_id,point_status from {$table_prefix}mlm_epins where epin_no = '{$epin}'");
                    $pointStatus = $pointResult->point_status;
                    $productPrice = $wpdb->get_var("SELECT product_price FROM {$table_prefix}mlm_product_price WHERE p_id = '" . $pointResult->p_id . "'");
                    // to epin point status 1
                    if ($pointStatus[0] == '1') {
                        $paymentStatus = '1';
                    } else {
                        if ($pointStatus[0] == '0') {
                            $paymentStatus = '2';
                        }
                    }
                } else {
                    if (!empty($_POST['epin_value'])) {
                        $productPrice = $wpdb->get_var("SELECT product_price FROM {$table_prefix}mlm_product_price WHERE p_id = '" . $_POST['epin_value'] . "'");
                        $paymentStatus = '0';
                    } else {
                        // to non epin
                        $paymentStatus = '0';
                    }
                }
                //insert the data into fa_user table
                $insert = "INSERT INTO {$table_prefix}mlm_users\n\t\t\t\t\t\t   (\n\t\t\t\t\t\t\t\tuser_id, username, user_key, parent_key, sponsor_key, payment_status, product_price\n\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t'" . $user_id . "','" . $username . "', '" . $user_key . "', '" . $parent_key . "', '" . $sponsor . "','" . $paymentStatus . "','" . $productPrice . "'\n\t\t\t\t\t\t\t)";
                $wpdb->query($insert);
                //hierarchy code for genology
                InsertHierarchy($user_key, $sponsor);
                if (isset($epin) && !empty($epin)) {
                    $sql = "update {$table_prefix}mlm_epins set user_key='{$user_key}', date_used=now(), status=1 where epin_no ='{$epin}' ";
                    // Update epin according user_key (19-07-2013)
                    mysql_query($sql);
                    if ($paymentStatus == 1) {
                        UserStatusUpdate($user_id);
                    }
                }
                if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
                    update_user_meta($user_id, 'mlm_user_paypalid', $paypalId, FALSE);
                }
                $chk = '';
                $msg = "<span style='color:green;'>Congratulations! You have successfully registered in the system.</span>";
                $check_paid = $wpdb->get_var("SELECT payment_status FROM {$table_prefix}mlm_users WHERE user_id = '" . $user_id . "'");
                if ($check_paid == '0') {
                    PayNowOptions($user_id, 'register_user');
                }
            } else {
                $error = "\n Sponsor does not exist in the system.";
            }
        }
        //end outer if condition
    }
    //end most outer if condition
    //if any error occoured
    if (!empty($error)) {
        $error = nl2br($error);
    }
    if ($chk != '') {
        ?>

 
<script type="text/javascript">
var popup1,popup2,splofferpopup1;
var bas_cal, dp_cal1,dp_cal2, ms_cal; // declare the calendars as global variables 
window.onload = function() {
	dp_cal1 = new Epoch('dp_cal1','popup',document.getElementById('dob'));  
};

function checkUserNameAvailability(str)
{
	//alert(url); return true; 
		
	if(isSpclChar(str, 'username')==false)
	{
		document.getElementById('username').focus();
		return false;
	}
	var xmlhttp;    
	if (str!="")
  	{
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	if (xmlhttp.status==200 && xmlhttp.readyState==4)
	{
	 document.getElementById("check_user").innerHTML=xmlhttp.responseText;
	 //alert(xmlhttp.responseText);
	}
	}   
	
	xmlhttp.open("GET", "<?php 
        echo MLM_PLUGIN_URL . 'ajax/check_username.php';
        ?>
"+"?action=username&q="+str,true);
	xmlhttp.send();
     }

}


function checkReferrerAvailability(str)
{ 
	if(isSpclChar(str, 'sponsor')==false)
	{
		document.getElementById('sponsor').focus();
		return false;
	}
	var xmlhttp;    
	
	if (str!="") {
	
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	if (xmlhttp.status==200 && xmlhttp.readyState==4)
	{
	 document.getElementById("check_referrer").innerHTML=xmlhttp.responseText;
	}
	}
	xmlhttp.open("GET", "<?php 
        echo MLM_PLUGIN_URL . 'ajax/check_username.php';
        ?>
"+"?action=sponsor&q="+str,true);
	xmlhttp.send();

	}
}

function checkePinAvailability(str)
{
	var iChars = "~`!@#$%^&*()+=[]\\\';,- ./{}|\":<>?abcdefghijklmnopqrstuvwxyz";
	for (var i = 0; i < str.length; i++)
	{
    	if (iChars.indexOf(str.charAt(i)) != -1) 
		{
    		alert("<?php 
        _e('Please enter Valid ePin.', 'unilevel-mlm-pro');
        ?>
");
			document.getElementById('epin').value='';
			document.getElementById('epin').focus();
    		return false;
        }
    }
	
	var xmlhttp;    
			if (str!="")
  	{
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	if (xmlhttp.status==200 && xmlhttp.readyState==4)
	{
		document.getElementById("check_epin").innerHTML=xmlhttp.responseText;
	 //alert(xmlhttp.responseText);
	}
	}   
	
	xmlhttp.open("GET", "<?php 
        echo plugins_url() . '/' . MLM_PLUGIN_NAME . '/ajax/check_epin.php';
        ?>
"+"?q="+str,true);
	xmlhttp.send();
     }
}


function checkePinAvailability1(str)
{
	var iChars = "~`!@#$%^&*()+=[]\\\';,- ./{}|\":<>?abcdefghijklmnopqrstuvwxyz";
	for (var i = 0; i < str.length; i++)
	{
    	if (iChars.indexOf(str.charAt(i)) != -1) 
		{
    		alert("<?php 
        _e('Please enter Valid ePin.', 'unilevel-mlm-pro');
        ?>
");
			document.getElementById('epin').value='';
			document.getElementById('epin').focus();
    		return false;
        }
    }
	
	var xmlhttp;    
	/*if (str=="")
  	{
  		alert("Please enter ePin.");
		document.getElementById('epin').focus();
		return false;
  	}*/
	if (str!="")
  	{
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	if (xmlhttp.status==200 && xmlhttp.readyState==4)
	{
		
	 if(xmlhttp.responseText=='1'){
          document.getElementById("check_epin").innerHTML="<span class='msg'>Congratulations! This ePin is available.</span>";   
          document.getElementById("epin_value").disabled=true;   
         }
         else
         {
         document.getElementById("check_epin").innerHTML="<span class='errormsg'>Sorry! This ePin is not Valid or already Used .</span>";
         document.getElementById("epin_value").disabled=false;   
            }
	}
	}   
	
	xmlhttp.open("GET", "<?php 
        echo plugins_url() . '/' . MLM_PLUGIN_NAME . '/ajax/check_epin.php';
        ?>
"+"?r="+str,true);
	xmlhttp.send();
      }
}
</script>

        <?php 
        $general_setting = get_option('wp_mlm_general_settings');
        if (is_user_logged_in()) {
            if (!empty($general_setting['wp_reg']) && !empty($general_setting['reg_url']) && $user_role != 'mlm_user') {
                echo "<script>window.location ='" . site_url() . '/' . $general_setting['reg_url'] . "'</script>";
            }
        } else {
            if (!empty($general_setting['wp_reg']) && !empty($general_setting['reg_url'])) {
                echo "<script>window.location ='" . site_url() . '/' . $general_setting['reg_url'] . "'</script>";
            }
        }
        ?>
		
		
<span style='color:red;'><?php 
        echo $error;
        ?>
</span>
<?php 
        if (isset($msg) && $msg != "") {
            echo $msg;
        }
        ?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
	<form name="frm" method="post" action="" onSubmit="return formValidationNewVer();">
		<tr>
			<td><?php 
        _e('Create Username', 'unilevel-mlm-pro');
        ?>
<span style="color:red;">*</span> :</td>
			<td><input type="text" name="username" id="username" value="<?php 
        if (!empty($_POST['username'])) {
            _e(htmlentities($_POST['username']));
        }
        ?>
" maxlength="20" size="37" onBlur="checkUserNameAvailability(this.value);"><br /><div id="check_user"></div></td>
		</tr>
		<?php 
        if (isset($mlm_general_settings['ePin_activate']) && $mlm_general_settings['ePin_activate'] == '1' && isset($mlm_general_settings['sol_payment']) && $mlm_general_settings['sol_payment'] == '1') {
            ?>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr>
			<td><?php 
            _e('Enter ePin', 'unilevel-mlm-pro');
            ?>
<span style="color:red;">*</span> :</td>
			<td><input type="text" name="epin" id="epin" value="<?php 
            if (!empty($_POST['epin'])) {
                _e(htmlentities($_POST['epin']));
            }
            ?>
" maxlength="20" size="37" onBlur="checkePinAvailability(this.value);"><br /><div id="check_epin"></div></td>
		</tr>
		<?php 
        } else {
            if (isset($mlm_general_settings['ePin_activate']) && $mlm_general_settings['ePin_activate'] == '1') {
                ?>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr>
			<td><?php 
                _e('Enter ePin', 'unilevel-mlm-pro');
                ?>
 :</td>
			<td><input type="text" name="epin" id="epin" value="<?php 
                if (!empty($_POST['epin'])) {
                    _e(htmlentities($_POST['epin']));
                }
                ?>
" maxlength="20" size="37" onBlur="checkePinAvailability1(this.value);"><br /><div id="check_epin"></div></td>
		</tr>
		<?php 
            }
        }
        if ($mlm_general_settings['sol_payment'] != '1' || empty($mlm_general_settings['sol_payment'])) {
            ?>
                <tr><td colspan="2">&nbsp;</td></tr>
		<tr>
			<td><?php 
            _e('Product', 'unilevel-mlm-pro');
            ?>
 :</td>
			<td> <?php 
            $pro_price_settings = $wpdb->get_results("select * from {$table_prefix}mlm_product_price where p_id!='1'");
            ?>

                <select name="epin_value" id="epin_value" >
                <option value="">Select Product</option>
                <?php 
            foreach ($pro_price_settings as $pricedetail) {
                ?>
       
<option value="<?php 
                echo $pricedetail->p_id;
                ?>
" <?php 
                echo $epin_value == $pricedetail->p_id ? 'selected="selected"' : '';
                ?>
><?php 
                echo $pricedetail->product_name;
                ?>
</option>
<?php 
            }
            ?>
                </select></td>
		</tr>
                <?php 
        }
        ?>
		<tr><td colspan="2">&nbsp;</td></tr>
		
		<tr>
			<td><?php 
        _e('Create Password', 'unilevel-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
			<td>	<input type="password" name="password" id="password" maxlength="20" size="37" >
				<br /><span style="font-size:12px; font-style:italic; color:#006633"><?php 
        _e('Password length atleast 6 character', 'unilevel-mlm-pro');
        ?>
</span>
			</td>
		</tr>
		
		<tr><td colspan="2">&nbsp;</td></tr>
		
		<tr>
			<td><?php 
        _e('Confirm Password', 'unilevel-mlm-pro');
        ?>
  <span style="color:red;">*</span> :</td>
			<td><input type="password" name="confirm_password" id="confirm_password" maxlength="20" size="37" ></td>
		</tr>
		
		<tr><td colspan="2">&nbsp;</td></tr>

		
		<tr>
			<td><?php 
        _e('Email Address', 'unilevel-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
			<td><input type="text" name="email" id="email" value="<?php 
        if (!empty($_POST['email'])) {
            _e(htmlentities($_POST['email']));
        }
        ?>
"  size="37" ></td>
		</tr>
		
		<tr><td colspan="2">&nbsp;</td></tr><tr>
		
		<tr>
			<td><?php 
        _e('Confirm Email Address', 'unilevel-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
			<td><input type="text" name="confirm_email" id="confirm_email" value="<?php 
        if (!empty($_POST['confirm_email'])) {
            _e(htmlentities($_POST['confirm_email']));
        }
        ?>
" size="37" ></td>
		</tr>
		
		<tr><td colspan="2">&nbsp;</td></tr>
			<?php 
        if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
            ?>
				<tr>
                    <td><?php 
            _e('Paypal ID', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                    <td><input type="text" name="paypal_id" id="paypal_id" value="<?php 
            if (!empty($_POST['paypal_id'])) {
                _e(htmlentities($_POST['paypal_id']));
            }
            ?>
" size="37" ></td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr>
		  <?php 
        }
        ?>
	
		<tr>
			<td><?php 
        _e('First Name', 'unilevel-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
			<td><input type="text" name="firstname" id="firstname" value="<?php 
        if (!empty($_POST['firstname'])) {
            _e(htmlentities($_POST['firstname']));
        }
        ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'firstname');" ></td>
		</tr>
		
		<tr><td colspan="2">&nbsp;</td></tr>
		
		<tr>
			<td><?php 
        _e('Last Name', 'unilevel-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
			<td><input type="text" name="lastname" id="lastname" value="<?php 
        if (!empty($_POST['lastname'])) {
            _e(htmlentities($_POST['lastname']));
        }
        ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'lastname');"></td>
		</tr>
		
		<tr><td colspan="2">&nbsp;</td></tr>
		
		<tr>
			<?php 
        if (isset($sponsor_name) && $sponsor_name != '') {
            $spon = $sponsor_name;
        } else {
            if (isset($_POST['sponsor'])) {
                $spon = htmlentities($_POST['sponsor']);
            }
        }
        ?>
			<td><?php 
        _e('Sponsor Name', 'unilevel-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
			<td>
			<input type="text" name="sponsor" id="sponsor" value="<?php 
        if (!empty($spon)) {
            _e($spon);
        }
        ?>
" maxlength="20" size="37" onBlur="checkReferrerAvailability(this.value);" <?php 
        echo $readonly_sponsor;
        ?>
>
			<br /><div id="check_referrer"></div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
			
			<input type="submit" name="submit" id="submit" value="<?php 
        _e('Submit', 'unilevel-mlm-pro');
        ?>
" /></td>
		</tr>
	</form>
</table>
<?php 
    } else {
        _e($msg);
    }
}
function mlm_core_drop_tables()
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    mlm_core_delete_users_data();
    $wpdb->query("DROP TABLE {$table_prefix}mlm_users");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_leftleg");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_rightleg");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_country");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_currency");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_commission");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_bonus");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_payout");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_payout_master");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_referral_commission");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_epins");
}
function mlm_my_child_member_details_page()
{
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    global $current_user;
    get_currentuserinfo();
    $sponsor_name = $current_user->user_login;
    if (!empty($_GET['lvl']) && $_GET['lvl'] != '') {
        $level = $_GET['lvl'];
    }
    $res = mysql_fetch_array(mysql_query("SELECT user_key FROM {$table_prefix}mlm_users WHERE username = '******'"));
    $level_data = getLevelInfo($res['user_key'], $level);
    ?>
 
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
var visualization;
var data;
var options = {'showRowNumber': true};
function drawVisualization() {
  // Create and populate the data table.
  var dataAsJson =
  {cols:[
	{id:'A',label:'<?php 
    echo _e("Username", "unilevel-mlm-pro");
    ?>
',type:'string'},
	{id:'B',label:'<?php 
    echo _e("First Name", "unilevel-mlm-pro");
    ?>
',type:'string'},
	{id:'C',label:'<?php 
    echo _e("Last Name", "unilevel-mlm-pro");
    ?>
',type:'string'},
    {id:'D',label:'<?php 
    echo _e("Sponsor", "unilevel-mlm-pro");
    ?>
',type:'string'},
	{id:'E',label:'<?php 
    echo _e("Email", "unilevel-mlm-pro");
    ?>
',type:'string'},
    {id:'F',label:'<?php 
    echo _e("Status", "unilevel-mlm-pro");
    ?>
',type:'string'}],
  rows:[
  <?php 
    for ($i = 0; $i < count($level_data); $i++) {
        ?>
                        {c:[{v:'<?php 
        echo $level_data[$i]['username'];
        ?>
'},
                        {v:'<?php 
        echo $level_data[$i]['first_name'];
        ?>
'},
                        {v:'<?php 
        echo $level_data[$i]['last_name'];
        ?>
'},
                        {v:'<?php 
        echo $level_data[$i]['sponsor'];
        ?>
'},
						{v:'<?php 
        echo $level_data[$i]['email'];
        ?>
'},
                        {v:'<?php 
        echo $level_data[$i]['status'];
        ?>
'}]},
  <?php 
    }
    ?>
  ]};
  data = new google.visualization.DataTable(dataAsJson);
  // Set paging configuration options
  // Note: these options are changed by the UI controls in the example.
  options['page'] = 'enable';
  options['pageSize'] = 10;
  options['pagingSymbols'] = {prev: 'prev', next: 'next'};
  options['pagingButtonsConfiguration'] = 'auto';
  //options['allowHtml'] = true;
  //data.sort({column:1, desc: false});
  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  draw();
}
function draw() {
  visualization.draw(data, options);
}
google.setOnLoadCallback(drawVisualization);
// sets the number of pages according to the user selection.
function setNumberOfPages(value) {
  if (value) {
	options['pageSize'] = parseInt(value, 10);
	options['page'] = 'enable';
  } else {
	options['pageSize'] = null;
	options['page'] = null;  
  }
  draw();
}
// Sets custom paging symbols "Prev"/"Next"
function setCustomPagingButtons(toSet) {
  options['pagingSymbols'] = toSet ? {next: 'next', prev: 'prev'} : null;
  draw();  
}
function setPagingButtonsConfiguration(value) {
  options['pagingButtonsConfiguration'] = value;
  draw();
}
</script>
<!--va-matter-->
    <div class="va-matter">
    	<!--va-matterbox-->
    	<div class="va-matterbox">
        	<!--va-headname-->
        	<div class="va-headname"><strong><?php 
    _e('My Level ' . $level . ' Members', 'unilevel-mlm-pro');
    ?>
</strong></div>
            <!--/va-headname-->
			<div class="va-admin-leg-details">
            	<!--va-admin-mid-->
				<div class="paging">
				  <form action="">
					<div class="left-side" style="width:30%;float:left;">
						<?php 
    _e('Display Number of Rows', 'unilevel-mlm-pro');
    ?>
 : &nbsp; 
					</div>
					<div class="right-side">
						<select style="font-size: 12px" onchange="setNumberOfPages(this.value)">
						  <option value="5">5</option>
						  <option selected="selected" value="10">10</option>
						  <option value="20">20</option>
						  <option  value="50">50</option>
						  <option value="100">100</option>
						  <option value="500">500</option>
						   <option value="">All</option>
						</select>
					</div>	
					</form>
					<div class="right-members">
					<?php 
    _e('Total Records', 'unilevel-mlm-pro');
    ?>
: <strong><?php 
    echo count($level_data);
    ?>
</strong>
					</div>
					<div class="va-clear"></div>
				  </div>
				<div id="table"></div>
				<div class="va-clear"></div>
			</div>		
		</div>
	</div>	
		
<?php 
}
function register_user_html_page()
{
    global $wpdb, $current_user;
    $user_id = $current_user->ID;
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    include_once ABSPATH . '/wp-admin/includes/plugin.php';
    if (!empty($_GET['sp_name'])) {
        $sp_name = $wpdb->get_var("select username from {$table_prefix}mlm_users where username='******'sp_name'] . "'");
        if ($sp_name) {
            ?>
            <script type='text/javascript'>
                $.cookie('sp_name', '<?php 
            echo $sp_name;
            ?>
', {path: '/'});
            </script>
            <?php 
        }
    } else {
        if (!empty($_REQUEST['sp'])) {
            $sp_name = getusernamebykey($_REQUEST['sp']);
            if ($sp_name) {
                ?>
            <script type='text/javascript'>
                $.cookie('sp_name', '<?php 
                echo $sp_name;
                ?>
', {path: '/'});
            </script>
            <?php 
            }
        } else {
            $sp_name = empty($_COOKIE["sp_name"]) ? '' : $_COOKIE["sp_name"];
        }
    }
    get_currentuserinfo();
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    if (is_user_logged_in()) {
        $sponsor_name = $current_user->user_login;
        $readonly_sponsor = 'readonly';
    } else {
        if (isset($_REQUEST['sp']) && $_REQUEST['sp'] != '') {
            $sponsorName = getusernamebykey($_REQUEST['sp']);
            if (isset($sponsorName) && $sponsorName != '') {
                $readonly_sponsor = 'readonly';
                $sponsor_name = $sponsorName;
            } else {
                redirectPage(home_url(), array());
                exit;
            }
        } else {
            if (!empty($_REQUEST['sp_name'])) {
                $sponsorName = $_REQUEST['sp_name'];
                if (!empty($sponsorName)) {
                    $readonly_sponsor = 'readonly';
                    $sponsor_name = $sponsorName;
                } else {
                    redirectPage(home_url(), array());
                    exit;
                }
            } else {
                $readonly_sponsor = '';
            }
        }
    }
    /* script for auto insert users================================================ */
    if ($_SERVER['HTTP_HOST'] == '192.168.100.100') {
        echo '<form name="form1"action="" method="post">
      <input type="number" min="0" max="99" name="id"/>
      <input type="number" min="0" max="1" name="epin"/>
      <input type="number" min="0" max="1" name="leg"/>
      <input type="submit"/></form>';
        $epinstatus = isset($_POST['epin']) ? $_POST['epin'] : '';
        if ($epinstatus != '') {
            $epin_no = $wpdb->get_var("select epin_no from {$table_prefix}mlm_epins where  point_status='{$epinstatus}' AND status=0 limit 1 ");
        }
        if (isset($_POST['id'])) {
            $z = $_POST['id'];
            $_POST = array('firstname' => 'binary' . $z, 'lastname' => 'binary' . $z, 'username' => 'binary' . $z, 'password' => 'binary' . $z, 'confirm_password' => 'binary' . $z, 'email' => 'binary' . $z . '@gmail.com', 'confirm_email' => 'binary' . $z . '@gmail.com', 'sponsor' => !empty($sponsor_name) ? $sponsor_name : '', 'submit' => 'submit', 'leg' => $_POST['leg'], 'epin' => $epin_no, 'paypal_id' => 'binary' . $z . '@gmail.com');
        }
        //'epin'=>!empty($epin_no)?$epin_no:'',
        //echo "<pre>"; print_r($_SERVER); echo "</pre>";
    }
    /* ===========================================================Close Auto Insert. */
    //most outer if condition
    if (isset($_POST['submit'])) {
        $firstname = sanitize_text_field($_POST['firstname']);
        $lastname = sanitize_text_field($_POST['lastname']);
        $username = sanitize_text_field($_POST['username']);
        $epin = sanitize_text_field(isset($_POST['epin']) ? $_POST['epin'] : '');
        $sponsor = sanitize_text_field($_POST['sponsor']);
        $password = sanitize_text_field($_POST['password']);
        $confirm_pass = sanitize_text_field($_POST['confirm_password']);
        $email = sanitize_text_field($_POST['email']);
        $confirm_email = sanitize_text_field($_POST['confirm_email']);
        $invalid_usernames = array('admin');
        $username = sanitize_user($username);
        if (!validate_username($username) || in_array($username, $invalid_usernames)) {
            $error .= "\n Username is invalid.";
        }
        if (username_exists($username)) {
            $error .= "\n Username already exists.";
        }
        if (empty($sponsor)) {
            $sponsor = $wpdb->get_var("select `username` FROM {$table_prefix}mlm_users order by id asc limit 1");
        }
        if (!empty($epin) && epin_exists($epin)) {
            $error .= "\n ePin already issued or wrong ePin.";
        }
        if (!empty($mlm_general_settings['sol_payment']) && empty($epin)) {
            $error .= "\n Please enter your ePin.";
        } else {
            if (empty($_POST['epin_value']) && empty($epin)) {
                $error .= "\n Please either enter the ePin or select the Product.";
            }
        }
        if (checkInputField($password)) {
            $error .= "\n Please enter your password.";
        }
        if (confirmPassword($password, $confirm_pass)) {
            $error .= "\n Please confirm your password.";
        }
        if (checkInputField($sponsor)) {
            $error .= "\n Please enter your sponsor name.";
        }
        if (checkInputField($firstname)) {
            $error .= "\n Please enter your first name.";
        }
        if (checkInputField($lastname)) {
            $error .= "\n Please enter your last name.";
        }
        if (!is_email($email)) {
            $error .= "\n E-mail address is invalid.";
        }
        if (email_exists($email)) {
            $error .= "\n E-mail address is already in use.";
        }
        if (confirmEmail($email, $confirm_email)) {
            $error .= "\n Please confirm your email address.";
        }
        include_once ABSPATH . '/wp-admin/includes/plugin.php';
        if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
            $paypalId = sanitize_text_field($_POST['paypal_id']);
            if (checkInputField($paypalId)) {
                $error .= "\n Please enter your Paypal id.";
            }
        }
        $sql = "SELECT COUNT(*) num, `user_key` FROM {$table_prefix}mlm_users WHERE `username` = '" . $sponsor . "'";
        $intro = $wpdb->get_row($sql);
        if (isset($_GET['l']) && $_GET['l'] != '') {
            $leg = $_GET['l'];
        } else {
            @($leg = $_POST['leg']);
        }
        if (isset($leg) && $leg != '0') {
            if ($leg != '1') {
                $error .= "\n You have enter a wrong placement.";
            }
        }
        //generate random numeric key for new user registration
        $user_key = generateKey();
        //if generated key is already exist in the DB then again re-generate key
        do {
            $check = $wpdb->get_var("SELECT COUNT(*) ck FROM {$table_prefix}mlm_users WHERE `user_key` = '" . $user_key . "'");
            $flag = 1;
            if ($check == 1) {
                $user_key = generateKey();
                $flag = 0;
            }
        } while ($flag == 0);
        //check parent key exist or not
        if (isset($_GET['k']) && $_GET['k'] != '') {
            if (!checkKey($_GET['k'])) {
                $error .= "\n Parent key does't exist.";
            }
            // check if the user can be added at the current position
            $checkallow = checkallowed($_GET['k'], $leg);
            if ($checkallow >= 1) {
                $error .= "\n You have enter a wrong placement.";
            }
        }
        if (!isset($leg)) {
            $key = $wpdb->get_var("SELECT user_key FROM {$table_prefix}mlm_users WHERE user_id = '{$user_id}'");
            $l = totalLeftLegUsers($key);
            $r = totalRightLegUsers($key);
            if ($l < $r) {
                $leg = '0';
            } else {
                $leg = '1';
            }
        }
        // outer if condition
        if (empty($error)) {
            // inner if condition
            if ($intro->num == 1) {
                $sponsor = $intro->user_key;
                $sponsor1 = $sponsor;
                //find parent key
                if (isset($_GET['k']) && $_GET['k'] != '') {
                    $parent_key = $_GET['k'];
                } else {
                    $readonly_sponsor = '';
                    do {
                        $sql = "SELECT `user_key` FROM {$table_prefix}mlm_users WHERE parent_key = '" . $sponsor1 . "' AND \n\t\t\t\tleg = '" . $leg . "' AND banned = '0'";
                        $spon = $wpdb->get_var($sql);
                        $num = $wpdb->num_rows;
                        if ($num) {
                            $sponsor1 = $spon;
                        }
                    } while ($num == 1);
                    $parent_key = $sponsor1;
                }
                $user = array('user_login' => $username, 'user_pass' => $password, 'first_name' => $firstname, 'last_name' => $lastname, 'user_email' => $email, 'user_registered' => current_time('mysql'), 'role' => 'mlm_user');
                // return the wp_users table inserted user's ID
                $user_id = wp_insert_user($user);
                /* Send e-mail to admin and new user  */
                wp_new_user_notification($user_id, $password);
                $pc = isset($mlm_general_settings['product_price']) ? $mlm_general_settings['product_price'] : '0';
                //insert the data into fa_user table
                if (!empty($epin)) {
                    $pointResult = $wpdb->get_row("select p_id,point_status from {$table_prefix}mlm_epins where epin_no = '{$epin}'");
                    $pointStatus = $pointResult->point_status;
                    $productPrice = $wpdb->get_var("SELECT product_price FROM {$table_prefix}mlm_product_price WHERE p_id = '" . $pointResult->p_id . "'");
                    // to epin point status 1
                    if ($pointStatus[0] == '1') {
                        $paymentStatus = '1';
                        $payment_date = current_time('mysql');
                    } else {
                        if ($pointStatus[0] == '0') {
                            $paymentStatus = '2';
                            $payment_date = current_time('mysql');
                        }
                    }
                } else {
                    if (!empty($_POST['epin_value'])) {
                        $productPrice = $wpdb->get_var("SELECT product_price FROM {$table_prefix}mlm_product_price WHERE p_id = '" . $_POST['epin_value'] . "'");
                        $paymentStatus = '0';
                        $payment_date = '0000-00-00 00:00:00';
                    } else {
                        // to non epin
                        $paymentStatus = '0';
                        $payment_date = '0000-00-00 00:00:00';
                    }
                }
                $insert = "INSERT INTO {$table_prefix}mlm_users\n\t\t\t\t\t\t   (\n\t\t\t\t\t\t\t\tuser_id, username, user_key, parent_key, sponsor_key, leg,payment_date,payment_status,product_price\n\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t'" . $user_id . "','" . $username . "', '" . $user_key . "', '" . $parent_key . "', '" . $sponsor . "', '" . $leg . "','" . $payment_date . "','" . $paymentStatus . "','" . $productPrice . "'\n\t\t\t\t\t\t\t)";
                // if all data successfully inserted
                if ($wpdb->query($insert)) {
                    //begin most inner if condition
                    //entry on Left and Right Leg tables
                    if ($leg == 0) {
                        $insert = "INSERT INTO {$table_prefix}mlm_leftleg set  pkey='" . $parent_key . "',ukey='" . $user_key . "'";
                        $insert = $wpdb->query($insert);
                        if ($u = get_option('network_mail', true) == 1) {
                        }
                    } else {
                        if ($leg == 1) {
                            $insert = "INSERT INTO {$table_prefix}mlm_rightleg set pkey='" . $parent_key . "',ukey='" . $user_key . "'";
                            $insert = $wpdb->query($insert);
                            if ($u = get_option('network_mail', true) == 1) {
                            }
                        }
                    }
                    SendMailToAll($user_key, $parent_key, $sponsor);
                    //begin while loop
                    while ($parent_key != '0') {
                        $query = "SELECT COUNT(*) num, parent_key, leg \n\t\t\t\t\t\t\t\t  FROM {$table_prefix}mlm_users \n\t\t\t\t\t\t\t\t  WHERE user_key = '" . $parent_key . "'\n\t\t\t\t\t\t\t\t  AND banned = '0'";
                        $result = $wpdb->get_row($query);
                        if ($result->num == 1) {
                            if ($result->parent_key != '0') {
                                if ($result->leg == 1) {
                                    $tbright = "INSERT INTO {$table_prefix}mlm_rightleg set pkey='" . $result->parent_key . "',ukey='" . $user_key . "' ";
                                    $tbright = $wpdb->query($tbright);
                                    if ($u = get_option('network_mail', true) == 1) {
                                    }
                                } else {
                                    $tbleft = "INSERT INTO {$table_prefix}mlm_leftleg set pkey='" . $result->parent_key . "',ukey='" . $user_key . "' ";
                                    $tbleft = $wpdb->query($tbleft);
                                    if ($u = get_option('network_mail', true) == 1) {
                                    }
                                }
                            }
                            $parent_key = $result->parent_key;
                        } else {
                            $parent_key = '0';
                        }
                    }
                    //end while loop
                    if (isset($epin) && !empty($epin)) {
                        $sql = "update {$table_prefix}mlm_epins set user_key='{$user_key}', date_used='" . current_time('mysql') . "', status=1 where epin_no ='{$epin}' ";
                        $wpdb->query($sql);
                    }
                    if ($paymentStatus == 1) {
                        insert_refferal_commision($user_id);
                    }
                    if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
                        update_user_meta($user_id, 'mlm_user_paypalid', $paypalId, FALSE);
                    }
                    $chk = '';
                    $msg = "<span style='color:green;'>Congratulations! You have successfully registered in the system.</span>";
                }
                //end most inner if condition
            } else {
                $error = "\n Sponsor does not exist in the system.";
            }
        }
        //end outer if condition
    }
    //end most outer if condition
    //if any error occoured
    if (!empty($error)) {
        $error = nl2br($error);
    }
    if ($chk != '') {
        include 'js-validation-file.html';
        ?>

        <?php 
        $user_roles = $current_user->roles;
        $user_role = array_shift($user_roles);
        $general_setting = get_option('wp_mlm_general_settings');
        if (is_user_logged_in()) {
            if (!empty($general_setting['wp_reg']) && !empty($general_setting['reg_url']) && $user_role != 'mlm_user') {
                echo "<script>window.location ='" . site_url() . '/' . $general_setting['reg_url'] . "'</script>";
            }
        } else {
            if (!empty($general_setting['wp_reg']) && !empty($general_setting['reg_url'])) {
                echo "<script>window.location ='" . site_url() . '/' . $general_setting['reg_url'] . "'</script>";
            }
        }
        ?>

        <span style='color:red;'><?php 
        echo $error;
        ?>
</span>
        <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <form name="frm" method="post" action="" onSubmit="return formValidation();">
                <tr>
                    <td><?php 
        _e('Create Username', 'binary-mlm-pro');
        ?>
<span style="color:red;">*</span> :</td>
                    <td><input type="text" name="username" id="username" value="<?php 
        if (!empty($_POST['username'])) {
            _e(htmlentities($_POST['username']));
        }
        ?>
" maxlength="20" size="37" onBlur="checkUserNameAvailability(this.value);"><br /><div id="check_user"></div></td>
                </tr>
                <?php 
        $mlm_general_settings = get_option('wp_mlm_general_settings');
        if (!empty($mlm_general_settings['ePin_activate']) && !empty($mlm_general_settings['sol_payment'])) {
            ?>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td><?php 
            _e('Enter ePin', 'binary-mlm-pro');
            ?>
<span style="color:red;">*</span> :</td>
                        <td><input type="text" name="epin" id="epin" value="<?php 
            if (!empty($_POST['epin'])) {
                _e(htmlentities($_POST['epin']));
            }
            ?>
" maxlength="20" size="37" onBlur="checkePinAvailability(this.value);"><br /><div id="check_epin"></div></td>
                    </tr>
                <?php 
        } else {
            if (!empty($mlm_general_settings['ePin_activate'])) {
                ?>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td><?php 
                _e('Enter ePin', 'binary-mlm-pro');
                ?>
 :</td>
                        <td><input type="text" name="epin" id="epin" value="<?php 
                if (!empty($_POST['epin'])) {
                    _e(htmlentities($_POST['epin']));
                }
                ?>
" maxlength="20" size="37" onBlur="checkePinAvailability(this.value);"><br /><div id="check_epin"></div></td>
                    </tr>
                    <?php 
            }
        }
        if (empty($mlm_general_settings['sol_payment'])) {
            ?>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td><?php 
            _e('Product', 'binary-mlm-pro');
            ?>
 :</td>
                        <td> <?php 
            $pro_price_settings = $wpdb->get_results("select * from {$table_prefix}mlm_product_price where p_id!='1'");
            ?>

                            <select name="epin_value" id="epin_value" >
                                <option value="">Select Product</option>
                                <?php 
            foreach ($pro_price_settings as $pricedetail) {
                ?>
       
                                    <option value="<?php 
                echo $pricedetail->p_id;
                ?>
" <?php 
                echo $epin_value == $pricedetail->p_id ? 'selected="selected"' : '';
                ?>
><?php 
                echo $pricedetail->product_name;
                ?>
</option>
                                <?php 
            }
            ?>
                            </select></td>
                    </tr>
                <?php 
        }
        ?>
                <tr><td colspan="2">&nbsp;</td></tr>
                <tr>
                    <td><?php 
        _e('Create Password', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <td>	<input type="password" name="password" id="password" maxlength="20" size="37" >
                        <br /><span style="font-size:12px; font-style:italic; color:#006633"><?php 
        _e('Password length atleast 6 character', 'binary-mlm-pro');
        ?>
</span>
                    </td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr>

                <tr>
                    <td><?php 
        _e('Confirm Password', 'binary-mlm-pro');
        ?>
  <span style="color:red;">*</span> :</td>
                    <td><input type="password" name="confirm_password" id="confirm_password" maxlength="20" size="37" ></td>
                </tr>
                <tr><td colspan="2">&nbsp;</td></tr>
                <tr>
                    <td><?php 
        _e('Email Address', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <td><input type="text" name="email" id="email" value="<?php 
        if (!empty($_POST['email'])) {
            _e(htmlentities($_POST['email']));
        }
        ?>
"  size="37" ></td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr><tr>

                <tr>
                    <td><?php 
        _e('Confirm Email Address', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <td><input type="text" name="confirm_email" id="confirm_email" value="<?php 
        if (!empty($_POST['confirm_email'])) {
            _e(htmlentities($_POST['confirm_email']));
        }
        ?>
" size="37" ></td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr>
                <?php 
        if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
            ?>
                    <tr>
                        <td><?php 
            _e('Paypal ID', 'binary-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="paypal_id" id="paypal_id" value="<?php 
            if (!empty($_POST['paypal_id'])) {
                _e(htmlentities($_POST['paypal_id']));
            }
            ?>
" size="37" ></td>
                    </tr>

                    <tr><td colspan="2">&nbsp;</td></tr>
                <?php 
        }
        ?>
	
                <tr>
                    <td><?php 
        _e('First Name', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <td><input type="text" name="firstname" id="firstname" value="<?php 
        if (!empty($_POST['firstname'])) {
            _e(htmlentities($_POST['firstname']));
        }
        ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'firstname');" ></td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr>

                <tr>
                    <td><?php 
        _e('Last Name', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <td><input type="text" name="lastname" id="lastname" value="<?php 
        if (!empty($_POST['lastname'])) {
            _e(htmlentities($_POST['lastname']));
        }
        ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'lastname');"></td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr>

                <tr>
                    <?php 
        if (isset($sponsor_name) && $sponsor_name != '') {
            $spon = $sponsor_name;
        } else {
            if (isset($sp_name)) {
                $spon = $sp_name;
            } else {
                if (isset($_POST['sponsor'])) {
                    $spon = htmlentities($_POST['sponsor']);
                }
            }
        }
        ?>
                    <td><?php 
        _e('Sponsor Name', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <td>
                        <input type="text" name="sponsor" id="sponsor" value="<?php 
        if (!empty($spon)) {
            _e($spon);
        }
        ?>
" maxlength="20" size="37" onBlur="checkReferrerAvailability(this.value);" <?php 
        echo $readonly_sponsor;
        ?>
>
                        <br /><div id="check_referrer"></div>
                    </td>
                </tr>

                <tr><td colspan="2">&nbsp;</td></tr>

                <tr>
                    <td><?php 
        _e('Placement', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span> :</td>
                    <?php 
        if (isset($_POST['leg']) && $_POST['leg'] == '0') {
            $checked = 'checked';
        } else {
            if (isset($_GET['l']) && $_GET['l'] == '0') {
                $checked = 'checked';
                $disable_leg = 'disabled';
            } else {
                $checked = '';
            }
        }
        if (isset($_POST['leg']) && $_POST['leg'] == '1') {
            $checked1 = 'checked';
        } else {
            if (isset($_GET['l']) && $_GET['l'] == '1') {
                $checked1 = 'checked';
                $disable_leg = 'disabled';
            } else {
                $checked1 = '';
            }
        }
        ?>

                    <td><?php 
        echo __('Left', 'binary-mlm-pro');
        ?>
 <input id="left" type="radio" name="leg" value="0" <?php 
        echo $checked;
        ?>
 <?php 
        if (!empty($disable_leg)) {
            _e($disable_leg);
        }
        ?>
/>
                        <?php 
        echo __('Right', 'binary-mlm-pro');
        ?>
<input id="right" type="radio" name="leg" value="1" <?php 
        echo $checked1;
        ?>
 <?php 
        if (!empty($disable_leg)) {
            _e($disable_leg);
        }
        ?>
/>



                    </td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="submit" id="submit" value="<?php 
        _e('Submit', 'binary-mlm-pro');
        ?>
" /></td>
                </tr>
            </form>
        </table>
        <?php 
    } else {
        _e($msg);
    }
}
function viewUnilevelNetworkPage()
{
    $table_prefix = mlm_core_get_table_prefix();
    //$obj = new UnilevelTree();
    global $current_user, $wpdb;
    get_currentuserinfo();
    $username1 = $current_user->user_login;
    //get no. of level
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    $res = mysql_fetch_array(mysql_query("SELECT user_key FROM {$table_prefix}mlm_users WHERE username = '******'"));
    $total = mysql_fetch_array(mysql_query("SELECT count(*) as num FROM {$table_prefix}mlm_hierarchy WHERE pid = '" . $res['user_key'] . "'"));
    $total = $total['num'];
    $member_page_id = $wpdb->get_var("SELECT id FROM {$table_prefix}posts  WHERE `post_content` LIKE '%mlm-view-child-level-member%'\tAND `post_type` != 'revision'");
    /*	$level[0]=countLevelMember($res['user_key']);
    	$user[0]=returnMemberUserkey($res['user_key']);
    
    $total=$level[0];
    
    for($i=1;$i<$mlm_no_of_level;$i++) {
    
    $user[$i]=returnMemberUserkey($user[$i-1]);
    $level[$i]=countLevelMember($user[$i-1]);
    
    
    if($level[$i]==0 || $level[$i]=='') {
    $level[$i]="No Any Members";
    }
    else {
    $total=$level[$i]+$total;
    }
    
    }*/
    //print_r($level);
    ?>
	<style type="text/css">
		span.owner
		{
			color:#339966; 
			font-style:italic;
		}
		span.paid
		{
			color: #669966!important; 
			/*background-color:#770000; */
			font-style:normal;
		}
		span.leg
		{
			color:red; 
			font-style:italic;
		}
	</style>

<script type="text/javascript" language="javascript">
	function searchUser()
	{
		var user = document.getElementById("username").value;
		if(user=="")
		{
			alert("Please enter username then searched.");
			document.getElementById("username").focus();
			return false;
		}
	}
</script>
 		<table border="0" cellspacing="0" cellpadding="0" >
			<tr>

			<td align="center">
				<form name="usersearch" id="usersearch" action="" method="post" onSubmit="return searchUser();">
					<input type="text" name="username" id="username"> <input type="submit" name="search" value="Search">
				</form>
			</td>
		</tr>               
		</table>
		
		<?php 
    if (isset($_POST['search'])) {
        $Search = $_POST['username'];
        $qry = mysql_query("SELECT user_key,h.level as level FROM {$table_prefix}mlm_hierarchy as h INNER JOIN {$table_prefix}mlm_users as u ON u.user_key=h.cid WHERE h.pid = '" . $res['user_key'] . "' AND u.username LIKE ('%" . $Search . "%')");
        $num = mysql_num_rows($qry);
        if ($num > 0) {
            while ($result = mysql_fetch_array($qry)) {
                $user = array();
                $usr_dtls = mysql_fetch_array(mysql_query("SELECT user_id,username,sponsor_key,payment_status FROM {$table_prefix}mlm_users WHERE user_key='" . $result['user_key'] . "'"));
                $user['username'] = $usr_dtls['username'];
                $user['first_name'] = get_user_meta($usr_dtls['user_id'], 'first_name', true);
                $user['last_name'] = get_user_meta($usr_dtls['user_id'], 'last_name', true);
                $sponser_id = $usr_dtls['sponsor_key'];
                $user['sponsor'] = getusernamebykey($sponser_id);
                $email = $wpdb->get_var("SELECT user_email FROM {$table_prefix}users WHERE ID='" . $usr_dtls['user_id'] . "'");
                $user['email'] = $email;
                $user['level'] = $result['level'];
                if ($usr_dtls['payment_status'] == 1) {
                    $user['status'] = "Paid";
                } else {
                    $user['status'] = "Not Paid";
                }
                $user_data[] = $user;
            }
            $level_data = $user_data;
            //print_r($level_data);
            ?>
		

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
var visualization;
var data;
var options = {'showRowNumber': true};
function drawVisualization() {
  // Create and populate the data table.
  var dataAsJson =
  {cols:[
	{id:'A',label:'<?php 
            echo _e("Username", "unilevel-mlm-pro");
            ?>
',type:'string'},
	{id:'B',label:'<?php 
            echo _e("First Name", "unilevel-mlm-pro");
            ?>
',type:'string'},
	{id:'C',label:'<?php 
            echo _e("Last Name", "unilevel-mlm-pro");
            ?>
',type:'string'},
    {id:'D',label:'<?php 
            echo _e("Sponsor", "unilevel-mlm-pro");
            ?>
',type:'string'},
    {id:'E',label:'<?php 
            echo _e("Email", "unilevel-mlm-pro");
            ?>
',type:'string'},
	{id:'F',label:'<?php 
            echo _e("Level", "unilevel-mlm-pro");
            ?>
',type:'string'},
    {id:'G',label:'<?php 
            echo _e("Status", "unilevel-mlm-pro");
            ?>
',type:'string'}],	
  rows:[
  <?php 
            for ($i = 0; $i < count($level_data); $i++) {
                ?>
                        {c:[{v:'<?php 
                echo $level_data[$i]['username'];
                ?>
'},
                        {v:'<?php 
                echo $level_data[$i]['first_name'];
                ?>
'},
                        {v:'<?php 
                echo $level_data[$i]['last_name'];
                ?>
'},
                        {v:'<?php 
                echo $level_data[$i]['sponsor'];
                ?>
'},
                        {v:'<?php 
                echo $level_data[$i]['email'];
                ?>
'},
						{v:'<?php 
                echo $level_data[$i]['level'];
                ?>
'},
                         {v:'<?php 
                echo $level_data[$i]['status'];
                ?>
'}
                        ]},
  <?php 
            }
            ?>
  ]};
  data = new google.visualization.DataTable(dataAsJson);
  // Set paging configuration options
  // Note: these options are changed by the UI controls in the example.
  options['page'] = 'enable';
  options['pageSize'] = 10;
  options['pagingSymbols'] = {prev: 'prev', next: 'next'};
  options['pagingButtonsConfiguration'] = 'auto';
  //options['allowHtml'] = true;
  //data.sort({column:1, desc: false});
  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  draw();
}
function draw() {
  visualization.draw(data, options);
}
google.setOnLoadCallback(drawVisualization);
// sets the number of pages according to the user selection.
function setNumberOfPages(value) {
  if (value) {
	options['pageSize'] = parseInt(value, 10);
	options['page'] = 'enable';
  } else {
	options['pageSize'] = null;
	options['page'] = null;  
  }
  draw();
}
// Sets custom paging symbols "Prev"/"Next"
function setCustomPagingButtons(toSet) {
  options['pagingSymbols'] = toSet ? {next: 'next', prev: 'prev'} : null;
  draw();  
}
function setPagingButtonsConfiguration(value) {
  options['pagingButtonsConfiguration'] = value;
  draw();
}
</script>
<!--va-matter-->
    <div class="va-matter">
    	<!--va-matterbox-->
    	<div class="va-matterbox">
        	<!--va-headname-->
        	<div class="va-headname"><strong><?php 
            _e('Search Results for:' . $Search, 'unilevel-mlm-pro');
            ?>
</strong></div>
            <!--/va-headname-->
			<div class="va-admin-leg-details">
            	<!--va-admin-mid-->
				<div class="paging">
				<?php 
            if (count($level_data) > 0) {
                ?>
				  <form action="">
					<div class="left-side" style="width:30%;float:left;">
						<?php 
                _e('Display Number of Rows', 'unilevel-mlm-pro');
                ?>
 : &nbsp; 
					</div>
					<div class="right-side">
						<select style="font-size: 12px" onchange="setNumberOfPages(this.value)">
						  <option value="5">5</option>
						  <option selected="selected" value="10">10</option>
						  <option value="20">20</option>
						  <option  value="50">50</option>
						  <option value="100">100</option>
						  <option value="500">500</option>
						   <option value="">All</option>
						</select>
					</div>	
					</form>
					<?php 
            }
            ?>
					<div class="right-members">
					<?php 
            _e('Total Records', 'unilevel-mlm-pro');
            ?>
: <strong><?php 
            echo count($level_data);
            ?>
</strong>
					</div>
					<div class="va-clear"></div>
				  </div>
				<div id="table"></div>
				<div class="va-clear"></div>
			</div>		
		</div>
	</div>
<?php 
        } else {
            ?>


<p> No Search Result Found!</p>



	
<?php 
        }
    } else {
        ?>
		<table border="0" cellspacing="0" cellpadding="0" >
			<TR>
			<TD align="center" ><strong><?php 
        _e('Levels', 'unilevel-mlm-pro');
        ?>
</strong></TD>
			<TD align="center" > <strong><?php 
        _e('No. of Members', 'unilevel-mlm-pro');
        ?>
</strong></TD>
			</TR>
		<?php 
        for ($j = 1; $j <= $mlm_no_of_level; $j++) {
            if (returncountLevelMember($res['user_key'], $j) == 0) {
                $num = "Level " . $j;
            } else {
                $num = "<a href='?page_id=" . $member_page_id . "&lvl=" . $j . "'> Level " . $j . "</a>";
            }
            ?>
		<TR>
			<TD align="center" ><strong><?php 
            _e($num, 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="center" > <?php 
            _e(returncountLevelMember($res['user_key'], $j), 'unilevel-mlm-pro');
            ?>
</TD>
			</TR>
		    
			<?php 
        }
        ?>
 
        <TR>
			<TD align="center" ><strong><?php 
        _e('Total', 'unilevel-mlm-pro');
        ?>
</strong></TD>
			<TD align="center" > <?php 
        _e($total, 'unilevel-mlm-pro');
        ?>
</TD>
			</TR>			
		</table>
		
		<?php 
    }
    ?>
		
		<div style="margin:0 auto;padding:0px;clear:both; width:100%!important;" align="center">

</div>
<?php 
}
    function widget($args, $instance)
    {
        extract($args);
        $table_prefix = mlm_core_get_table_prefix();
        global $wpdb;
        $title = apply_filters('widget_title', $instance['title']);
        $textarea = $instance['textarea'];
        $ckemail = get_option('ckemail');
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        if ($textarea) {
            echo '<p>' . $textarea . '</p>';
        }
        if (!empty($_GET['sp_name'])) {
            $sp_name = $_GET['sp_name'];
        } else {
            if (!empty($_GET['sp'])) {
                $sp_name = getusernamebykey($_GET['sp']);
            } else {
                if (!empty($_COOKIE["sp_name"])) {
                    $sp_name = $_COOKIE["sp_name"];
                }
            }
        }
        //$sp_name = empty($_COOKIE["sp_name"])?'':$_COOKIE["sp_name"];
        if (is_user_logged_in()) {
            $current_user = wp_get_current_user();
            $cuserid = $current_user->ID;
            $cusername = $current_user->user_firstname . ' ' . $current_user->user_lastname;
            $cemail = $current_user->user_email;
            $all_meta_for_user = get_user_meta($cuserid);
            ?>
  
            <div class="join_box">
                <div class="join_box_left" style="width:90px;float:left;">
                    <?php 
            echo get_avatar($cuserid, 80);
            ?>
                </div>
                <div class="join_box_right">
                    <?php 
            echo '<span class="swname">' . ucwords(empty($cusername) ? '' : $cusername) . '</span><br/>';
            if (!empty($ckemail)) {
                ?>
                        <span class='swemail'><?php 
                echo empty($cemail) ? '' : $cemail;
                ?>
</span><br/><br/>
                        <?php 
            } else {
                echo '<br/>';
            }
            ?>
                    <input type="button" value="Join Now" class="primary button" onclick="window.location = '<?php 
            echo get_post_id_or_postname('mlm_registration_page', 'binary-mlm-pro');
            ?>
'" />
                </div>
            </div>
            <?php 
        } else {
            if (!empty($sp_name)) {
                $userid = $wpdb->get_var("SELECT user_id FROM {$table_prefix}mlm_users WHERE username = '******'");
                if (!empty($userid)) {
                    $all_meta_for_user = get_user_meta($userid);
                    $fname = $all_meta_for_user['first_name'][0];
                    $lname = $all_meta_for_user['last_name'][0];
                    $fullname = $fname . ' ' . $lname;
                    $user_info = get_userdata($userid);
                    $email = $user_info->user_email;
                    $permalink = get_permalink(empty($_GET['page_id']) ? '' : $_GET['page_id']);
                    $postidparamalink = strstr($permalink, 'page_id');
                    $concat = $postidparamalink ? '&' : '/?';
                }
                ?>
                <div class="join_box">
                    <div class="join_box_left" style="width:90px;float:left;">
                        <?php 
                echo get_avatar($userid, 80);
                ?>
                    </div>
                    <div class="join_box_right">
                        <?php 
                echo '<span class="swname">' . ucwords(empty($fullname) ? '' : $fullname) . '</span><br/>';
                if (!empty($ckemail)) {
                    ?>
                            <span class='swemail'><?php 
                    echo empty($email) ? '' : $email;
                    ?>
</span><br/><br/>
                            <?php 
                } else {
                    echo '<br/>';
                }
                ?>
                        <input type="button" value="Join Now" class="primary button" onclick="window.location = '<?php 
                echo get_post_id_or_postname('mlm_registration_page', 'binary-mlm-pro');
                echo empty($concat) ? '/?' : $concat;
                ?>
sp_name=<?php 
                echo $sp_name;
                ?>
'" />
                    </div>
                </div>
                <?php 
            }
        }
        echo $after_widget;
    }
function mlmRegularBonus()
{
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //get no. of level
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    //most outer if condition
    if (isset($_POST['mlm_regular_bonus_settings'])) {
        $per_ref = count(array_filter($_POST['per_ref']));
        $pay_value = count(array_filter($_POST['pay_value']));
        if ($per_ref == 0) {
            $error .= "\n Please Specify No. of Personal Referral.";
        }
        if ($pay_value == 0) {
            $error .= "\n Please Specify Payout Value.";
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_regular_bonus_settings', $_POST);
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=royalty_bonus";
            _e("<script>window.location='{$url}'</script>");
            $msg = _e("<span style='color:green;'>Your bonus has been successfully updated.</span>", 'unilevel-mlm-pro');
        }
    }
    // end outer if condition
    if ($chk != '') {
        $mlm_settings = get_option('wp_mlm_regular_bonus_settings');
        ?>
<div class='wrap1'>
	<h2><?php 
        _e('Regular Bonus Settings', 'unilevel-mlm-pro');
        ?>
  </h2>
	<div class="notibar msginfo">
		<a class="close"></a>
		<p><?php 
        _e('Regular bonus is a one time payment made to a member in the network based on the number of personal referrers. To add a new bonus slab click the Add Row Button. To delete a particular bonus slab, select the checkbox against the slab and click the Delete Row Button.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('No. of Personal Referrers', 'unilevel-mlm-pro');
        ?>
 - </strong><?php 
        _e('This is the value of the personal referrers  which would trigger a bonus distribution in the network. If the first slab has a value of 5 personal referrers while the next slab has 10 personal referrers, this implies that the member has to sponsor 5 members to get the bonus of Slab1 and a total of 15 members (10 more members) in the network in order to get the bonus for the
Slab2.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Payout Value', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('This is the fixed payout   amount paid to the member on achieving the milestone.', 'unilevel-mlm-pro');
        ?>
</p>

	</div>
	
	<?php 
        if ($error) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p> <strong><?php 
            _e('Please Correct the following Error', 'unilevel-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	<?php 
        if (!empty($msg)) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p><?php 
            _e($msg);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	

<?php 
        if (empty($mlm_settings)) {
            ?>
<form name="admin_bonus_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		
		
		<tr>

			<td>
				<INPUT type="button" value="<?php 
            _e('Add Row', 'unilevel-mlm-pro');
            ?>
" onclick="addRow('dataTable')" class='button-primary' />
    			<INPUT type="button" value="<?php 
            _e('Delete Row', 'unilevel-mlm-pro');
            ?>
" onclick="deleteRow('dataTable')" class='button-primary' />
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
            _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450">
		<TR>
			<TD align="left" width="12%"><strong><?php 
            _e('Select', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="left" width="44%"> <strong><?php 
            _e('No. of Personal Referrals', 'unilevel-mlm-pro');
            ?>
</strong></TD>
			
			<TD align="left" width="44%"> <strong><?php 
            _e('Payout Value', 'unilevel-mlm-pro');
            ?>
</strong></TD>
		</TR>
	</TABLE>
	<br\>
	<TABLE id="dataTable"  cellspacing="0" cellpadding="0" border="0" width="450">
		<TR>
			<TD align="left" width="12%"><INPUT type="checkbox" name="chk[]"/></TD>
			<TD align="left" width="44%"> <INPUT type="text" name="per_ref[]" size="15" /> </TD>
			
			<TD align="left" width="44%"> <INPUT type="text" name="pay_value[]" size="15" /> </TD>
			
		</TR>
	</TABLE>
	
	<table border="0" width="100%">	
		<tr>
			<td>
		<p class="submit">
	<input type="submit" name="mlm_regular_bonus_settings" id="mlm_regular_bonus_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
			</td>
		<tr>
	</table>
</form>
</div>
<script language="JavaScript">
  populateArrays();
</script>
<?php 
        } else {
            if (!empty($mlm_settings)) {
                ?>
		
			<form name="admin_bouns_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		<tr>
			<td>
				<INPUT type="button" value="<?php 
                _e('Add Row', 'unilevel-mlm-pro');
                ?>
" onclick="addRow('dataTable')" class='button-primary'/>
    			<INPUT type="button" value="<?php 
                _e('Delete Row', 'unilevel-mlm-pro');
                ?>
" onclick="deleteRow('dataTable')" class='button-primary'/>
				<div class="toggle-visibility" id="admin-mlm-bonus-slab"><?php 
                _e('Add or remove bonus slab.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
	</table>
	<TABLE id="dataTableheading" cellspacing="5" cellpadding="5"  border="0" width="450" >
		<TR>
			<TD align="left" width="12%"><strong><?php 
                _e('Select', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="44%"> <strong><?php 
                _e('No. of Personal Referrals', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			<TD align="left" width="44%"> <strong><?php 
                _e('Payout Value', 'unilevel-mlm-pro');
                ?>
</strong></TD>
			
		</TR>
	</TABLE>
	<br\>
		<TABLE id="dataTable"   cellspacing="5" cellpadding="5" border="0" width="450">
		<?php 
                $i = 0;
                while ($i < count($mlm_settings['per_ref'])) {
                    ?>
        	<TR>
           		<TD align="left" width="12%"><INPUT type="checkbox" name="chk[]"/></TD>
				<TD align="left" width="44%"> <INPUT type="text" name="per_ref[]" size="15" value="<?php 
                    echo $mlm_settings['per_ref'][$i];
                    ?>
"/> </TD>
				
				<TD align="left" width="44%"> <INPUT type="text" name="pay_value[]" size="15" value="<?php 
                    echo $mlm_settings['pay_value'][$i];
                    ?>
"/> </TD>
				
				
				
        	</TR>    	
		<?php 
                    $i++;
                }
                ?>
		</TABLE>
	
	<p class="submit">
	<input type="submit" name="mlm_regular_bonus_settings" id="mlm_regular_bonus_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
</form>
</div>
<script language="JavaScript">
  populateArrays();
</script>
			<?php 
            }
        }
    } else {
        _e($msg);
    }
}
function adminMLMSettings()
{
    global $pagenow, $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    $mlm_settings = get_option('wp_mlm_general_settings');
    $sql = "SELECT COUNT(*) AS num FROM {$table_prefix}mlm_users";
    $num = $wpdb->get_var($sql);
    if ($num == 0) {
        $tabs = array('createuser' => __('Create First User', 'binary-mlm-pro'), 'general' => __('General', 'binary-mlm-pro'), 'eligibility' => __('Eligibility', 'binary-mlm-pro'), 'payout' => __('Payout', 'binary-mlm-pro'), 'bonus' => __('Bonus', 'binary-mlm-pro'), 'email' => __('Email Settings', 'binary-mlm-pro'));
        if (isset($mlm_settings['ePin_activate']) && $mlm_settings['ePin_activate'] == '1') {
            $tabs['epin_settings'] = __('ePins', 'binary-mlm-pro');
            $tabs['product_price'] = __('Manage Products', 'binary-mlm-pro');
        }
        /**
         * Detect plugin. For use in Admin area only.
         */
        include_once ABSPATH . '/wp-admin/includes/plugin.php';
        if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
            //plugin is activated
            $tabs['paypal_detail'] = __('Paypal Details', 'binary-mlm-pro');
        }
        $tabs['reset_all_data'] = __('Reset All MLM Data', 'binary-mlm-pro');
        $tabval = 'createuser';
        $tabfun = 'register_first_user';
    } else {
        $tabs = array('general' => __('General', 'binary-mlm-pro'), 'eligibility' => __('Eligibility', 'binary-mlm-pro'), 'payout' => __('Payout', 'binary-mlm-pro'), 'bonus' => __('Bonus', 'binary-mlm-pro'), 'email' => __('Email Settings', 'binary-mlm-pro'));
        if (isset($mlm_settings['ePin_activate']) && $mlm_settings['ePin_activate'] == '1') {
            $tabs['epin_settings'] = __('ePins', 'binary-mlm-pro');
            $tabs['product_price'] = __('Manage Products', 'binary-mlm-pro');
        }
        if (is_plugin_active('mlm-paypal-mass-pay/load-data.php')) {
            //plugin is activated
            $tabs['paypal_detail'] = __('Paypal Details', 'binary-mlm-pro');
        }
        $tabs['reset_all_data'] = __('Reset All MLM Data', 'binary-mlm-pro');
        $tabval = 'general';
        $tabfun = 'mlmGeneral';
    }
    if (!empty($_GET['tab'])) {
        if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'createuser') {
            $current = 'createuser';
        } else {
            if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'general') {
                $current = 'general';
            } else {
                if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'eligibility') {
                    $current = 'eligibility';
                } else {
                    if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'payout') {
                        $current = 'payout';
                    } else {
                        if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'bonus') {
                            $current = 'bonus';
                        } else {
                            if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'email') {
                                $current = 'email';
                            } else {
                                if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'epin_settings') {
                                    $current = 'epin_settings';
                                } else {
                                    if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'product_price') {
                                        $current = 'product_price';
                                    } else {
                                        if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'paypal_detail') {
                                            $current = 'paypal_detail';
                                        } else {
                                            if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'reset_all_data') {
                                                $current = 'reset_all_data';
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        $current = $tabval;
    }
    $links = array();
    _e('<div id="icon-themes" class="icon32"><br></div>');
    _e("<h1>MLM Settings</h1>", "binary-mlm-pro");
    _e('<h2 class="nav-tab-wrapper">');
    foreach ($tabs as $tab => $name) {
        $class = $tab == $current ? ' nav-tab-active' : '';
        _e("<a class='nav-tab{$class}' href='?page=admin-settings&tab={$tab}'>{$name}</a>");
    }
    _e('</h2>');
    if (!empty($_GET['tab'])) {
        if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'createuser') {
            register_first_user();
        } else {
            if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'general') {
                mlmGeneral();
            } else {
                if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'eligibility') {
                    mlmEligibility();
                } else {
                    if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'payout') {
                        mlmPayout();
                    } else {
                        if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'bonus') {
                            mlmBonus();
                        } else {
                            if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'email') {
                                mlmEmailTemplates();
                            } else {
                                if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'epin_settings') {
                                    epin_tab();
                                } else {
                                    if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'product_price') {
                                        mlmProductPrice();
                                    } else {
                                        if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'paypal_detail') {
                                            $current = Paypal_Detail();
                                        } else {
                                            if ($pagenow == 'admin.php' && $_GET['page'] == 'admin-settings' && $_GET['tab'] == 'reset_all_data') {
                                                adminMlmReserAllData();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        $tabfun();
    }
}
<?php

require_once '../../../wp-config.php';
global $wpdb;
$table_prefix = mlm_core_get_table_prefix();
extract($_REQUEST);
$user_key = getuserkeybyid($user_id);
if (!empty($epin)) {
    $sql = "SELECT * FROM {$table_prefix}mlm_epins WHERE epin_no='" . $epin . "' AND status=1";
    $results = $wpdb->get_results($sql);
    if ($wpdb->num_rows != 1) {
        $sql = "update {$table_prefix}mlm_epins set user_key='{$user_key}', date_used=now(), status=1 where epin_no ='{$epin}' ";
        $epinUpdate = $wpdb->query($sql);
        if (!empty($epinUpdate)) {
            $userUpdate = mlmUserUpdateePin($user_id, $epin);
            $status = $wpdb->get_var("SELECT payment_status \n\t\t\t\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\t\t\t\tWHERE `user_id` = '" . $user_id . "'");
            if ($status == '1') {
                insert_refferal_commision($user_id);
            }
        }
    }
    if ($epinUpdate && $userUpdate) {
        _e("<span class='error' style='color:green'>Congratulations! Your account is now set to Active.</span>");
    } else {
        _e("<span class='error' style='color:red'>Sorry. You have entered an invalid ePin.</span>");
    }
}
function mlmGeneral()
{
    global $wpdb;
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //most outer if condition
    if (isset($_POST['mlm_general_settings'])) {
        $currency = sanitize_text_field($_POST['currency']);
        $levels = sanitize_text_field($_POST['mlm-level']);
        //$single_sale = sanitize_text_field( $_POST['single-sale'] );
        if (checkInputField($currency)) {
            $error .= "\n Please Select your currency type.";
        }
        if (checkInputField($levels)) {
            $error .= "\n Please specify No. of Levels.";
        }
        //if ( checkInputField($single_sale) )
        //		$error .= "\n Please specify value of single sale.";
        $wp_check = $_POST['wp_reg'];
        $reg_url = sanitize_text_field($_POST['reg_url']);
        if ($wp_check == '1') {
            if (checkInputField($reg_url)) {
                $error .= "\n Please Fill The URL.";
            }
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_general_settings', $_POST);
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=eligibility";
            _e("<script>window.location='{$url}'</script>");
            $msg = "<span style='color:green;'>Your general settings has been successfully updated.</span>";
        }
    }
    // end outer if condition
    ?>

	<script type="text/javascript">

	jQuery(document).ready(function () {

		jQuery("input[name='ePin_activate']").change(function () {
			var value = jQuery(this).val();
			if (value == '1') {
				jQuery(".sole_id").show();
			   
			} else if (value == '0') {

			   jQuery(".sole_id").hide();
			}
		});
		
		});
	</script>	
   <script language="javascript">
        jQuery(document).ready(function(){
            jQuery("#reg_url").click(function(){
                jQuery("#reg_url").removeAttr("readonly");
            });
             
        });
        function CheckBoxChanged(checkbox)
        {
            if (checkbox.checked == true) {
                //document.getElementById('reg_url').disabled = false;
                jQuery("#reg_url").removeAttr("readonly");
            }
            else
            {
                jQuery("#reg_url").attr("readonly","readonly");
                //document.getElementById('reg_url').focus();
            }
        }
        function show1()
        {
            if (document.getElementById('reg_url').value == '')
            {
                alert('Please Fill The URL');
                document.getElementById('reg_url').focus();
                return true;
            }
        }


    </script>
<?php 
    if ($chk != '') {
        $mlm_settings = get_option('wp_mlm_general_settings');
        $URL = empty($mlm_settings['affiliate_url']) ? '' : $mlm_settings['affiliate_url'] . '/';
        ?>
		
<div class='wrap1'>
	<h2><?php 
        _e('Currency Setting', 'unilevel-mlm-pro');
        ?>
 </h2>
	    
		<div class="updated fade">
		<p><?php 
        _e("In order to enable SEO Friendly Affiliate URLs please add the following line of code in your .htaccess file at the top of the file BEFORE the #Begin Wordpress line of code<br/><br/> <strong> RedirectMatch 301 u/(.*)  " . site_url() . "/" . $URL . "?sp_name=\$1 </strong> <br/><br/>Please note that your Permalink setting in WordPress should be anything other than Default setting.", 'unilevel-mlm-pro');
        ?>
 </p> </div> <br/>
		
		<div class="notibar msginfo">
		<a class="close"></a>	
		<p><strong><?php 
        _e('Currency', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('Please select the base currency of your MLM Network. This option is very important as all calculations will be performed in this base currency. Once this currency is chosen and saved, it CANNOT be changed later. The entire network will need to be reset if you decide to change the currency at a later date.', 'unilevel-mlm-pro');
        ?>
 </p>
		<p><strong><?php 
        _e('No. of Levels', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('This defines the levels upto which the payment will be distributed for a successful sale in the network. As with currency, once defined, this value cannot be changed.', 'unilevel-mlm-pro');
        ?>
</p>
		
		<p><strong><?php 
        _e('Use WP registration page', 'unilevel-mlm-pro');
        ?>
 - </strong> <?php 
        _e(' Select this option in case you want to use the default WP registration page or a custom registration page on your site. ', 'unilevel-mlm-pro');
        ?>
</p>
		<p><strong><?php 
        _e('URL of registration page', 'unilevel-mlm-pro');
        ?>
 - </strong> <?php 
        _e(' In case you selected the Use WP registration page option specify the URL of your registration page. This would enable us to setup the correct redirect for the registration page included in our plugin. ', 'unilevel-mlm-pro');
        ?>
</p>
		<p><strong><?php 
        _e('Redirect Affiliate URL', 'unilevel-mlm-pro');
        ?>
 - </strong> <?php 
        _e(' By default the affiliate URL for your members is setup to redirect to the registration page included in our plugin. In case you would like the affiliate URL to redirect to a different page, please specify the desired URL in this field. ', 'unilevel-mlm-pro');
        ?>
</p>

		<p><strong><?php 
        _e('Activate ePin', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('In case you would like to Activate ePin functionality on your website, set this value to Yes.', 'unilevel-mlm-pro');
        ?>
 </p>
	    <p><strong><?php 
        _e('Sole Payment Method', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('In case members can only register on your site via ePin, set this to Yes. This would make the ePin field mandatory on the user registration form and a visitor would need a valid unused ePin to complete his registration. If this value is set to No, a visitor will be able to register on the site even without specifying a valid ePin. In this case you would need to manually mark the member as Paid / Unpaid under Users -> All Users. ', 'unilevel-mlm-pro');
        ?>
 </p>
	    <p><strong><?php 
        _e('ePin Length', 'unilevel-mlm-pro');
        ?>
 -</strong> <?php 
        _e('The length of the generated ePins.', 'unilevel-mlm-pro');
        ?>
 </p>
	
	</div>
	<?php 
        if ($error) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p> <strong><?php 
            _e('Please Correct the following Error', 'unilevel-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	
	<?php 
        if (empty($mlm_settings)) {
            ?>
	<form name="admin_general_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="60%" class="form-table">
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onClick="toggleVisibility('admin-mlm-currency');"><?php 
            _e('Currency', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
			<?php 
            $sql = "SELECT iso3, currency \n\t\t\t\t\t\t\t\t\t\t\tFROM {$table_prefix}mlm_currency \n\t\t\t\t\t\t\t\t\t\t\tORDER BY iso3";
            $results = $wpdb->get_results($sql);
            ?>
				<select name="currency" id="currency" >
					<option value=""><?php 
            _e('Select Currency', 'unilevel-mlm-pro');
            ?>
</option>
				<?php 
            foreach ($results as $row) {
                if ($_POST['currency'] == $row->iso3) {
                    $selected = 'selected';
                } else {
                    $selected = '';
                }
                ?>
						<option value="<?php 
                echo $row->iso3;
                ?>
" <?php 
                echo $selected;
                ?>
><?php 
                echo $row->iso3 . " - " . $row->currency;
                ?>
</option>
				<?php 
            }
            ?>
				</select>
				<div class="toggle-visibility" id="admin-mlm-currency"><?php 
            _e('Select your currency which will you use.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onClick="toggleVisibility('admin-mlm-level');"><?php 
            _e('No. of Levels', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-level" id="mlm-level" size="10" value="<?php 
            if (!empty($_POST['mlm-level'])) {
                _e(htmlentities($_POST['mlm-level']));
            }
            ?>
">
				<div class="toggle-visibility" id="admin-mlm-level"><?php 
            _e('Please specify no. of level.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
		
		<!--<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onClick="toggleVisibility('admin-mlm-single-sale');"><?php 
            _e('Value of Single Sale', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="single-sale" id="single-sale" size="10" value="<?php 
            //if(!empty($_POST['single-sale'])) _e(htmlentities($_POST['single-sale']));
            ?>
">
				<div class="toggle-visibility" id="admin-mlm-single-sale"><?php 
            //_e('Please specify value of single sale.','unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>-->
		
		
                        <tr>

                            <th scope="row" class="admin-setting" >
                                <strong><?php 
            _e('Use WP registration page', 'unilevel-mlm-pro');
            ?>
</strong>
                            </th>
                            <td>
                                <input type="checkbox" name="wp_reg" id="wp_reg" value="1" <?php 
            echo $_POST['wp_reg'] == 1 ? ' checked="checked"' : '';
            ?>
 onclick="CheckBoxChanged(this);" onblur="show1();" />
                            </td> 
                        </tr>
                        <tr>

                            <th scope="row" class="admin-setting" >
                                <strong><?php 
            _e('URL of registration page', 'unilevel-mlm-pro');
            ?>
:<span style="color:red;"></span>:</strong>
                            </th>
                            <td>
                                <?php 
            echo site_url() . '/';
            ?>
<input type="text" name="reg_url" id="reg_url" value="<?php 
            echo empty($_POST['reg_url']) ? '' : $_POST['reg_url'];
            ?>
" readonly="true"/>
                            </td>

                        </tr>
		
	                      <tr>

                            <th scope="row" class="admin-setting" >
                                <strong><?php 
            _e('Redirect Affiliate URL', 'unilevel-mlm-pro');
            ?>
:</strong>
                            </th>
                            <td>
                                <?php 
            echo site_url() . '/';
            ?>
<input type="text" name="affiliate_url" id="affiliate_url" value="<?php 
            echo empty($_POST['affiliate_url']) ? '' : $_POST['affiliate_url'];
            ?>
" />
                            </td>

                        </tr>
						
			 <tr><td colspan="2" style="padding: 0px;">
		
		<table>
                <tr>
			<th scope="row" class="admin-settings">
				<strong><?php 
            _e('Activate ePin', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>:</strong>
			</th>
			<td>
			<?php 
            if ($mlm_settings['ePin_activate'] == '0') {
                ?>
		<script>	jQuery(document).ready(function () { jQuery(".sole_id").hide(); });</script>
		<?php 
            }
            ?>
		
		
			<input class="radio" type="radio" name="ePin_activate" value="1" <?php 
            if (isset($_POST['ePin_activate']) && $_POST['ePin_activate'] == '1') {
                echo 'checked';
            }
            ?>
/> <?php 
            _e('Yes', 'unilevel-mlm-pro');
            ?>
			<?php 
            $sql = "SELECT COUNT( * ) AS ps FROM  {$table_prefix}mlm_users WHERE  `payment_status` =  '2'";
            $ps = $wpdb->get_var($sql);
            $sql1 = "SELECT COUNT( * ) AS es FROM  {$table_prefix}mlm_epins WHERE  `status` =  '1'";
            $es = $wpdb->get_var($sql1);
            if ($ps > 0 || $es > 0) {
                echo "<br>" . __('Cannot be disabled as 1 or more ePins have been used for registration.', 'unilevel-mlm-pro');
            } else {
                ?>
			<input class="radio" type="radio" name="ePin_activate" value="0" <?php 
                if (isset($_POST['ePin_activate']) && $_POST['ePin_activate'] != '1') {
                    echo 'checked';
                } else {
                    echo 'checked';
                }
                ?>
/> <?php 
                _e('No', 'unilevel-mlm-pro');
                ?>
			<?php 
            }
            ?>
			</td>
		</tr>
		<tr class="sole_id" >
			<th scope="row" class="admin-settings">
				<strong><?php 
            _e('Sole Payment Method', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>:</strong>
			</th>
			<td>
			<input class="radio" type="radio" name="sol_payment" value="1" <?php 
            if (isset($_POST['sol_payment']) && $_POST['sol_payment'] == '1') {
                echo 'checked';
            }
            ?>
/> <?php 
            _e('Yes', 'unilevel-mlm-pro');
            ?>
			<input class="radio" type="radio" name="sol_payment" value="0" <?php 
            if (isset($_POST['sol_payment']) && $_POST['sol_payment'] != '1') {
                echo 'checked';
            } else {
                echo 'checked';
            }
            ?>
/> <?php 
            _e('No', 'unilevel-mlm-pro');
            ?>
			</td>
		</tr>
		<tr class="sole_id">
				<th><strong><?php 
            _e('ePin Length', 'unilevel-mlm-pro');
            ?>
:</strong></th>
				
				<td>
				<?php 
            $epin_length = $_POST['epin_length'];
            ?>
				<select name="epin_length" id="epin_length">
				<?php 
            // or whatever you want
            $epin_array = array(8 => '8', 9 => '9', 10 => '10', 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15');
            foreach ($epin_array as $key => $val) {
                ?>
						<option value="<?php 
                echo $key;
                ?>
"<?php 
                if ($key == $epin_length) {
                    echo ' selected="selected"';
                }
                ?>
>
						<?php 
                echo $val;
                ?>
						</option>
						<?php 
            }
            ?>
				
				</select>
				</td>
				
			</tr></table>
			
			
                          </td></tr>	
		
	</table>
	<p class="submit">
	<input type="submit" name="mlm_general_settings" id="mlm_general_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onClick="needToConfirm = false;">
	</p>
	</form>
	</div>
	<script language="JavaScript">
  populateArrays();
</script>
<?php 
        } else {
            if (!empty($mlm_settings)) {
                ?>
		
		
		<?php 
                if (isset($mlm_settings['recur_payment']) && $mlm_settings['recur_payment'] == '0') {
                    ?>
		<script>	jQuery(document).ready(function () { jQuery(".recur_id").hide(); });</script>
		<?php 
                }
                ?>
		 
			<form name="admin_general_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onClick="toggleVisibility('admin-mlm-currency');"><?php 
                _e('Currency', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
			<?php 
                $sql = "SELECT iso3, currency \n\t\t\t\t\t\tFROM {$table_prefix}mlm_currency\n\t\t\t\t\t\tWHERE iso3 = '" . $mlm_settings['currency'] . "'\n\t\t\t\t\t\tORDER BY iso3";
                //$sql = mysql_fetch_array(mysql_query($sql));
                ?>
				<input type="text" name="currency" id="currency" value="<?php 
                echo $mlm_settings['currency'];
                ?>
" readonly />
				<div class="toggle-visibility" id="admin-mlm-currency"><?php 
                _e('You can not change the currency.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onClick="toggleVisibility('admin-mlm-level');"><?php 
                _e('No. of Levels', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-level" id="mlm-level" size="10" value="<?php 
                if (!empty($mlm_settings['mlm-level'])) {
                    _e($mlm_settings['mlm-level']);
                }
                ?>
" readonly>
				<div class="toggle-visibility" id="admin-mlm-level"><?php 
                _e('You can not change the level.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
		
		<!--<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onClick="toggleVisibility('admin-mlm-single-sale');"><?php 
                _e('Value of Single Sale', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="single-sale" id="single-sale" size="10" value="<?php 
                //if(!empty($mlm_settings['single-sale'])) _e($mlm_settings['single-sale']);
                ?>
">
				<div class="toggle-visibility" id="admin-mlm-single-sale"><?php 
                //_e('Please specify value of single sale.','unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>-->
		

                    <tr>

                        <th scope="row" class="admin-setting" >
                            <strong><?php 
                _e('Use WP registration page', 'unilevel-mlm-pro');
                ?>
</strong>
                        </th>
                        <td>
                            <input type="checkbox" name="wp_reg" id="wp_reg" value="1" <?php 
                echo $mlm_settings['wp_reg'] == 1 ? ' checked="checked"' : '';
                ?>
  onclick="CheckBoxChanged(this);"/>
                        </td> 



                    </tr>
                    <tr>

                        <th scope="row" class="admin-setting" >
                            <strong><?php 
                _e('URL of registration page', 'unilevel-mlm-pro');
                ?>
<span style="color:red;"></span>:</strong>
                        </th>
                        <td>
                            <?php 
                echo site_url() . '/';
                ?>
<input type="text" name="reg_url" id="reg_url" value="<?php 
                echo empty($mlm_settings['reg_url']) ? '' : $mlm_settings['reg_url'];
                ?>
" onblur="show1()" readonly="true" />
                        </td>

                    </tr>

					
						                      <tr>

                            <th scope="row" class="admin-setting" >
                                <strong><?php 
                _e('Redirect Affiliate URL', 'unilevel-mlm-pro');
                ?>
:</strong>
                            </th>
                            <td>
                                <?php 
                echo site_url() . '/';
                ?>
<input type="text" name="affiliate_url" id="affiliate_url" value="<?php 
                echo empty($mlm_settings['affiliate_url']) ? '' : $mlm_settings['affiliate_url'];
                ?>
" />
                            </td>

                        </tr>

		
		
		<tr><td colspan="2" style="padding: 0px;">
		<table>
                <tr>
			<th scope="row" class="admin-settings">
				<strong><?php 
                _e('Activate ePin', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>:</strong>
			</th>
			<td>
			<?php 
                if ($mlm_settings['ePin_activate'] == '0') {
                    ?>
		<script>	jQuery(document).ready(function () { jQuery(".sole_id").hide(); });</script>
		<?php 
                }
                ?>
		
		
			<input class="radio" type="radio" name="ePin_activate" value="1" <?php 
                if (isset($mlm_settings['ePin_activate']) && $mlm_settings['ePin_activate'] == '1') {
                    echo 'checked';
                }
                ?>
/> <?php 
                _e('Yes', 'unilevel-mlm-pro');
                ?>
			<?php 
                $sql = "SELECT COUNT( * ) AS ps FROM  {$table_prefix}mlm_users WHERE  `payment_status` =  '2'";
                $ps = $wpdb->get_var($sql);
                $sql1 = "SELECT COUNT( * ) AS es FROM  {$table_prefix}mlm_epins WHERE  `status` =  '1'";
                $es = $wpdb->get_var($sql1);
                if ($ps > 0 || $es > 0) {
                    echo "<br>" . __('Cannot be disabled as 1 or more ePins have been used for registration.', 'unilevel-mlm-pro');
                } else {
                    ?>
			<input class="radio" type="radio" name="ePin_activate" value="0" <?php 
                    if (isset($mlm_settings['ePin_activate']) && $mlm_settings['ePin_activate'] == '0') {
                        echo 'checked';
                    }
                    ?>
/> <?php 
                    _e('No', 'unilevel-mlm-pro');
                    ?>
			<?php 
                }
                ?>
			</td>
		</tr>
		<tr class="sole_id" >
			<th scope="row" class="admin-settings">
				<strong><?php 
                _e('Sole Payment Method', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>:</strong>
			</th>
			<td>
			<input class="radio" type="radio" name="sol_payment" value="1" <?php 
                if (isset($mlm_settings['sol_payment']) && $mlm_settings['sol_payment'] == '1') {
                    echo 'checked';
                }
                ?>
/> <?php 
                _e('Yes', 'unilevel-mlm-pro');
                ?>
			<input class="radio" type="radio" name="sol_payment" value="0" <?php 
                if (isset($mlm_settings['sol_payment']) && $mlm_settings['sol_payment'] == '0') {
                    echo 'checked';
                }
                ?>
/> <?php 
                _e('No', 'unilevel-mlm-pro');
                ?>
			</td>
		</tr>
		<tr class="sole_id">
				<th><strong><?php 
                _e('ePin Length', 'unilevel-mlm-pro');
                ?>
</strong></th>
				
				<td>
				<?php 
                $epin_length = $mlm_settings['epin_length'];
                ?>
				<select name="epin_length" id="epin_length">
				<?php 
                // or whatever you want
                $epin_array = array(8 => '8', 9 => '9', 10 => '10', 11 => '11', 12 => '12', 13 => '13', 14 => '14', 15 => '15');
                foreach ($epin_array as $key => $val) {
                    ?>
						<option value="<?php 
                    echo $key;
                    ?>
"<?php 
                    if ($key == $epin_length) {
                        echo ' selected="selected"';
                    }
                    ?>
>
						<?php 
                    echo $val;
                    ?>
						</option>
						<?php 
                }
                ?>
				
				</select>
				</td>
				
			</tr></table>
                    </td></tr>
		</table>
		<p class="submit">
	<input type="submit" name="mlm_general_settings" id="mlm_general_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onClick="needToConfirm = false;">
	</p>
	</form>
	</div>
		<?php 
            }
        }
    } else {
        _e($msg);
    }
}
function mlmGeneral()
{
    global $wpdb;
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //most outer if condition
    if (isset($_POST['mlm_general_settings'])) {
        $currency = sanitize_text_field($_POST['currency']);
        if (checkInputField($currency)) {
            $error .= "\n Please Select your currency type.";
        }
        $reg_url = sanitize_text_field($_POST['reg_url']);
        if (isset($_POST['wp_reg'])) {
            $error .= "\n Please Fill The URL.";
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_general_settings', $_POST);
            /*             * ********code to save the product price that have payment status 1 and product price 0 ********* */
            $mlm_general_settings = get_option('wp_mlm_general_settings');
            if (!empty($mlm_general_settings['product_price'])) {
                $product_price = $mlm_general_settings['product_price'];
                $sql = "SELECT id \n\t\t\t\t\t\tFROM {$table_prefix}mlm_users\n\t\t\t\t\t\tWHERE payment_status='1' AND product_price='0'";
                $ids = $wpdb->get_results($sql);
                foreach ($ids as $id) {
                    $sql = "update {$table_prefix}mlm_users set product_price='{$product_price}' where id ='{$id->id}' ";
                    $wpdb->query($sql);
                }
            }
            /*             * ********code to save the product price that have payment status 1 and product price 0 ********* */
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=eligibility";
            _e("<script>window.location='{$url}'</script>");
            $msg = "<span style='color:green;'>Your general settings has been successfully updated.</span>";
        }
    }
    // end outer if condition
    ?>
    <script>
        jQuery(document).ready(function() {

            jQuery("input[name='ePin_activate']").change(function() {
                var value = jQuery(this).val();
                if (value == '1')
                    jQuery("#sole_id").show();
                else if (value == '0')
                    jQuery("#sole_id").hide();
            });
            jQuery("#rp1").click(function() {
                var value = jQuery('#rp1').val();
                if (value == 'yes')
                    jQuery("#frequency").removeAttr("disabled");
            });
            jQuery("#rp2").click(function() {
                var value = jQuery('#rp2').val();
                if (value == 'no')
                    jQuery("#frequency").attr("disabled", "disabled");
            });
        });



        function isNumberKey(evt)
        {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 46 || charCode > 57 || charCode == 47))
                return false;

            return true;
        }
    </script>	

    <script language="javascript">
        jQuery(document).ready(function() {
            jQuery("#reg_url").click(function() {
                jQuery("#reg_url").removeAttr("readonly");
            });

        });
        function CheckBoxChanged(checkbox)
        {
            if (checkbox.checked == true) {
                //document.getElementById('reg_url').disabled = false;
                jQuery("#reg_url").removeAttr("readonly");
            }
            else
            {
                jQuery("#reg_url").attr("readonly", "readonly");
                //document.getElementById('reg_url').focus();
            }
        }
        function show1()
        {
            if (document.getElementById('reg_url').value == '')
            {
                alert('Please Fill The URL');
                document.getElementById('reg_url').focus();
                return false;
            }
        }


    </script>
    <?php 
    if ($chk != '') {
        $mlm_settings = get_option('wp_mlm_general_settings');
        $URL = empty($mlm_settings['affiliate_url']) ? '' : $mlm_settings['affiliate_url'] . '/';
        include 'js-validation-file.html';
        ?>

        <div class='wrap1'>
            <h2><?php 
        _e('Currency Setting', 'binary-mlm-pro');
        ?>
 </h2>
            <div class="updated fade">
                <p><?php 
        _e("In order to enable SEO Friendly Affiliate URLs please add the following line of code in your .htaccess file at the top of the file BEFORE the #Begin Wordpress line of code<br/><br/> <strong> RedirectMatch 301 u/(.*)  " . site_url() . "/" . $URL . "?sp_name=\$1 </strong> <br/><br/>Please note that your Permalink setting in WordPress should be anything other than Default setting.", 'binary-mlm-pro');
        ?>
 </p> </div> <br/>
            <div class="notibar msginfo">
                <a class="close"></a>

                <p><?php 
        _e('Please select the base currency of your MLM Network. This option is very important as all calculations will be performed in this base currency. Once this currency is chosen and saved, it CANNOT be changed later. The entire network will need to be reset if you decide to change the currency at a later date.', 'binary-mlm-pro');
        ?>
 </p>

                <p><strong><?php 
        _e('Use WP registration page', 'binary-mlm-pro');
        ?>
 - </strong><?php 
        _e('In case you would like to Check this functionality on your website, you need to put redirect link of registration page.', 'binary-mlm-pro');
        ?>
</p>
                <p><strong><?php 
        _e('URL of registration page', 'binary-mlm-pro');
        ?>
 - </strong><?php 
        _e('Registration page url for redirect your website to specefic location .', 'binary-mlm-pro');
        ?>
</p>

                <p><strong><?php 
        _e('Redirect Affiliate URL', 'unilevel-mlm-pro');
        ?>
 - </strong> <?php 
        _e(' By default the affiliate URL for your members is setup to redirect to the registration page included in our plugin. In case you would like the affiliate URL to redirect to a different page, please specify the desired URL in this field. ', 'unilevel-mlm-pro');
        ?>
</p> 
                <p><strong><?php 
        _e('Activate ePin', 'binary-mlm-pro');
        ?>
 - </strong><?php 
        _e('In case you would like to Activate ePin functionality on your website, set this value to Yes.', 'binary-mlm-pro');
        ?>
</p>  
                <p><strong><?php 
        _e('Sole Payment Method', 'binary-mlm-pro');
        ?>
 - </strong><?php 
        _e('In case members can only register on your site via ePin, set this to Yes. This would make the ePin field mandatory on the user registration form and a visitor would need a valid unused ePin to complete his registration. If this value is set to No, a visitor will be able to register on the site even without specifying a valid ePin. In this case you would need to manually mark the member as Paid / Unpaid under Users -> All Users.', 'binary-mlm-pro');
        ?>
</p>             
                <p><strong><?php 
        _e('ePin Length', 'binary-mlm-pro');
        ?>
 - </strong><?php 
        _e('The length of the generated ePins.', 'binary-mlm-pro');
        ?>
</p>
                <p><strong><?php 
        _e('Process Withdrawals', 'binary-mlm-pro');
        ?>
 - </strong><?php 
        _e('In case you would like to Check this functionality on your website than  withdrawal amount by specific process. defaul process is manually', 'binary-mlm-pro');
        ?>
</p>


            </div>
            <?php 
        if ($error) {
            ?>
                <div class="notibar msgerror">
                    <a class="close"></a>
                    <p> <strong><?php 
            _e('Please Correct the following Error', 'binary-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>

                </div>
            <?php 
        }
        ?>

            <?php 
        $currency = isset($_POST['currency']) ? $_POST['currency'] : (isset($mlm_settings['currency']) ? $mlm_settings['currency'] : '');
        $wp_reg = isset($_POST['wp_reg']) ? $_POST['wp_reg'] : (isset($mlm_settings['wp_reg']) ? $mlm_settings['wp_reg'] : '');
        $reg_url = isset($_POST['reg_url']) ? $_POST['reg_url'] : (isset($mlm_settings['reg_url']) ? $mlm_settings['reg_url'] : '');
        $affiliate_url = isset($_POST['affiliate_url']) ? $_POST['affiliate_url'] : (isset($mlm_settings['affiliate_url']) ? $mlm_settings['affiliate_url'] : '');
        $product_price = isset($_POST['product_price']) ? $_POST['product_price'] : (isset($mlm_settings['product_price']) ? $mlm_settings['product_price'] : '');
        $process_withdrawal = isset($_POST['process_withdrawal']) ? $_POST['process_withdrawal'] : (isset($mlm_settings['process_withdrawal']) ? $mlm_settings['process_withdrawal'] : '');
        if (empty($process_withdrawal)) {
            $_POST['process_withdrawal'] = 'Manually';
        }
        ?>
            <form name="admin_general_settings" method="post" action="" id="admin_general_settings">
                <table border="0" cellpadding="0" cellspacing="0" width="60%" class="form-table">
                    <tr>
                        <th scope="row" class="admin-settings">
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-currency');"><?php 
        _e('Currency', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>: </a>
                        </th>
                        <td>
                            <?php 
        $sql = "SELECT iso3, currency FROM {$table_prefix}mlm_currency ORDER BY iso3";
        $results = $wpdb->get_results($sql);
        ?>
                            <select name="currency" id="currency" >
                                <option value=""><?php 
        _e('Select Currency', 'binary-mlm-pro');
        ?>
</option>
                                <?php 
        foreach ($results as $row) {
            if ($currency == $row->iso3) {
                $selected = 'selected';
            } else {
                $selected = '';
            }
            ?>
                                    <option value="<?php 
            echo $row->iso3;
            ?>
" <?php 
            echo $selected;
            ?>
><?php 
            echo $row->iso3 . " - " . $row->currency;
            ?>
</option>
                                    <?php 
        }
        ?>
                            </select>
                            <div class="toggle-visibility" id="admin-mlm-currency"><?php 
        _e('Select your currency which will you use.', 'binary-mlm-pro');
        ?>
</div>
                        </td>

                    </tr>
                    <tr>

                        <th scope="row" class="admin-setting" >
                            <strong><?php 
        _e('Use WP registration page');
        ?>
</strong>
                        </th>
                        <td>
                            <input type="checkbox" name="wp_reg" id="wp_reg" value="1" <?php 
        echo $wp_reg == 1 ? ' checked="checked"' : '';
        ?>
 onclick="CheckBoxChanged(this);" onblur="show1();" />
                        </td> 
                    </tr>
                    <tr>

                        <th scope="row" class="admin-setting" >
                            <strong><?php 
        _e('URL of registration page', 'binary-mlm-pro');
        ?>
<span style="color:red;"></span>:</strong>
                        </th>
                        <td>
                            <?php 
        echo site_url() . '/';
        ?>
<input type="text" name="reg_url" id="reg_url" value="<?php 
        echo $reg_url;
        ?>
" readonly="true"/>
                        </td>

                    </tr>
                    <tr>

                        <th scope="row" class="admin-setting" >
                            <strong><?php 
        _e('Redirect Affiliate URL', 'binary-mlm-pro');
        ?>
:</strong>
                        </th>
                        <td>
                            <?php 
        echo site_url() . '/';
        ?>
<input type="text" name="affiliate_url" id="affiliate_url" value="<?php 
        echo $affiliate_url;
        ?>
" />
                        </td>

                    </tr>
                    <?php 
        general_settings_epin();
        ?>


                    <tr>

                        <th scope="row" class="admin-settings">
                            <strong><?php 
        _e('Process Withdrawals', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>:</strong> 
                        </th>

                        <td>
                            <input type="radio" name="process_withdrawal" id="process_withdrawal" value="Automatically" <?php 
        echo $process_withdrawal == 'Automatically' ? ' checked="checked"' : '';
        ?>
 />Automatically
                            <input type="radio" name="process_withdrawal" id="process_withdrawal" value="Manually" <?php 
        echo $process_withdrawal == 'Manually' ? ' checked="checked"' : '';
        ?>
 />Manually

                        </td>	

                    </tr>
                </table>
                <p class="submit">
                    <input type="submit" name="mlm_general_settings" id="mlm_general_settings" value="<?php 
        _e('Update Options', 'binary-mlm-pro');
        ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
                </p>
            </form>
        </div>

        <script language="JavaScript">
            populateArrays();
        </script>
        <?php 
    } else {
        _e($msg);
    }
}
function PayoutGeneratedMail($userId, $total, $payoutMasterId)
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    $deduction = get_option('wp_mlm_withdrawal_method_settings');
    $amount = $total;
    $payId = $payoutMasterId;
    $comment = $_my_post['wcomment'];
    $admin_mail = get_option('admin_email');
    $res = $wpdb->get_var("\n\t\t\t\t\t\t\tSELECT user_id \n\t\t\t\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\t\t\t\tWHERE `id` = '" . $userId . "'\n\t\t\t\t");
    $user_info = get_userdata($res);
    $username = $user_info->user_login;
    $first_name = $user_info->first_name;
    $last_name = $user_info->last_name;
    $name = $first_name . " " . $last_name;
    if (empty($first_name) && empty($first_name)) {
        $name = $username;
    }
    $to = $admin_mail;
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: Admin <' . $admin_mail . '>' . "\r\n";
    $subject = get_option('runpayout_email_subject', true);
    $message = nl2br(htmlspecialchars(get_option('runpayout_email_message', true)));
    $message = str_replace('[firstname]', $first_name, $message);
    $message = str_replace('[lastname]', $last_name, $message);
    $message = str_replace('[email]', $email, $message);
    $message = str_replace('[username]', $username, $message);
    $message = str_replace('[amount]', $amount, $message);
    $message = str_replace('[payoutid]', $payId, $message);
    $message = str_replace('[sitename]', $siteownwer, $message);
    wp_mail($to, $subject, $message, $headers);
}
function adminViewUnilevelNetwork($id)
{
    $table_prefix = mlm_core_get_table_prefix();
    //$obj = new UnilevelTree();
    global $wpdb;
    get_currentuserinfo();
    //get no. of level
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    $res = mysql_fetch_array(mysql_query("SELECT user_key FROM {$table_prefix}mlm_users WHERE user_id = '" . $id . "'"));
    $total = mysql_fetch_array(mysql_query("SELECT count(*) as num FROM {$table_prefix}mlm_hierarchy WHERE pid = '" . $res['user_key'] . "'"));
    $total = $total['num'];
    $member_page_id = $wpdb->get_var("SELECT id FROM {$table_prefix}posts  WHERE `post_content` LIKE '%mlm-view-child-level-member%'\tAND `post_type` != 'revision'");
    if (!empty($_GET['lvl']) && $_GET['lvl'] != '') {
        $level = $_GET['lvl'];
        $level_data = getLevelInfo($res['user_key'], $level);
        ?>
	 
	
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
  google.load('visualization', '1', {packages: ['table']});
</script>
<script type="text/javascript">
var visualization;
var data;
var options = {'showRowNumber': true};
function drawVisualization() {
  // Create and populate the data table.
  var dataAsJson =
  {cols:[
	{id:'A',label:'<?php 
        echo _e("Username", "unilevel-mlm-pro");
        ?>
',type:'string'},
	{id:'B',label:'<?php 
        echo _e("First Name", "unilevel-mlm-pro");
        ?>
',type:'string'},
	{id:'C',label:'<?php 
        echo _e("Last Name", "unilevel-mlm-pro");
        ?>
',type:'string'},
    {id:'D',label:'<?php 
        echo _e("Sponsor", "unilevel-mlm-pro");
        ?>
',type:'string'},
	{id:'E',label:'<?php 
        echo _e("Email", "unilevel-mlm-pro");
        ?>
',type:'string'},
    {id:'F',label:'<?php 
        echo _e("Status", "unilevel-mlm-pro");
        ?>
',type:'string'}],
  rows:[
  <?php 
        for ($i = 0; $i < count($level_data); $i++) {
            ?>
                        {c:[{v:'<?php 
            echo $level_data[$i]['username'];
            ?>
'},
                        {v:'<?php 
            echo $level_data[$i]['first_name'];
            ?>
'},
                        {v:'<?php 
            echo $level_data[$i]['last_name'];
            ?>
'},
                        {v:'<?php 
            echo $level_data[$i]['sponsor'];
            ?>
'},
						{v:'<?php 
            echo $level_data[$i]['email'];
            ?>
'},
                        {v:'<?php 
            echo $level_data[$i]['status'];
            ?>
'}]},
  <?php 
        }
        ?>
  ]};
  data = new google.visualization.DataTable(dataAsJson);
  // Set paging configuration options
  // Note: these options are changed by the UI controls in the example.
  options['page'] = 'enable';
  options['pageSize'] = 10;
  options['pagingSymbols'] = {prev: 'prev', next: 'next'};
  options['pagingButtonsConfiguration'] = 'auto';
  //options['allowHtml'] = true;
  //data.sort({column:1, desc: false});
  // Create and draw the visualization.
  visualization = new google.visualization.Table(document.getElementById('table'));
  draw();
}
function draw() {
  visualization.draw(data, options);
}
google.setOnLoadCallback(drawVisualization);
// sets the number of pages according to the user selection.
function setNumberOfPages(value) {
  if (value) {
	options['pageSize'] = parseInt(value, 10);
	options['page'] = 'enable';
  } else {
	options['pageSize'] = null;
	options['page'] = null;  
  }
  draw();
}
// Sets custom paging symbols "Prev"/"Next"
function setCustomPagingButtons(toSet) {
  options['pagingSymbols'] = toSet ? {next: 'next', prev: 'prev'} : null;
  draw();  
}
function setPagingButtonsConfiguration(value) {
  options['pagingButtonsConfiguration'] = value;
  draw();
}
</script>
<!--va-matter-->
    <div class="va-matter">
    	<!--va-matterbox-->
    	<div class="va-matterbox">
        	<!--va-headname-->
        	<div class="va-headname"><strong><?php 
        _e('Level ' . $level . ' Members', 'unilevel-mlm-pro');
        ?>
</strong></div>
            <!--/va-headname-->
			<div class="va-admin-leg-details">
            	<!--va-admin-mid-->
				<div class="paging">
				  <form action="">
					<div class="left-side" style="width:30%;float:left;">
						<?php 
        _e('Display Number of Rows', 'unilevel-mlm-pro');
        ?>
 : &nbsp; 
					</div>
					<div class="right-side">
						<select style="font-size: 12px" onchange="setNumberOfPages(this.value)">
						  <option value="5">5</option>
						  <option selected="selected" value="10">10</option>
						  <option value="20">20</option>
						  <option  value="50">50</option>
						  <option value="100">100</option>
						  <option value="500">500</option>
						   <option value="">All</option>
						</select>
					</div>	
					</form>
					<div class="right-members">
					<?php 
        _e('Total Records', 'unilevel-mlm-pro');
        ?>
: <strong><?php 
        echo count($level_data);
        ?>
</strong>
					</div>
					<div class="va-clear"></div>
				  </div>
				<div id="table"></div>
				<div class="va-clear"></div>
			</div>		
		</div>
	</div>	
	
	 
	 
<?php 
    } else {
        ?>

 		<table border="0" cellspacing="5" cellpadding="5" width="50%">
			<TR>
			<TD align="center" ><strong><?php 
        _e('Levels', 'unilevel-mlm-pro');
        ?>
</strong></TD>
			<TD align="center" > <strong><?php 
        _e('No. of Members', 'unilevel-mlm-pro');
        ?>
</strong></TD>
			</TR>
		<?php 
        for ($j = 1; $j <= $mlm_no_of_level; $j++) {
            if (returncountLevelMember($res['user_key'], $j) == 0) {
                $num = "Level " . $j;
            } else {
                $num = "<a href='?page=mlm-user-account&ac=network&lvl=" . $j . "'> Level " . $j . "</a>";
            }
            ?>
		<TR>
			<TD align="center" ><strong><?php 
            _e($num, 'unilevel-mlm-pro');
            ?>
</strong></TD>
			<TD align="center" > <?php 
            _e(returncountLevelMember($res['user_key'], $j), 'unilevel-mlm-pro');
            ?>
</TD>
			</TR>
		    
			<?php 
        }
        ?>
 
        <TR>
			<TD align="center" ><strong><?php 
        _e('Total', 'unilevel-mlm-pro');
        ?>
</strong></TD>
			<TD align="center" > <?php 
        _e($total, 'unilevel-mlm-pro');
        ?>
</TD>
			</TR>			
		</table>
		
<?php 
    }
}
function mlm_payment_settings()
{
    global $wpdb;
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    $pageurl = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-mlm-payment-settings";
    // save Payment Method here
    if (isset($_POST['updateoption'])) {
        update_option('wp_mlm_payment_method', $_POST);
    }
    //Update Paypal settings
    if (isset($_POST['updatepaypaloption'])) {
        update_option('wp_mlm_paypal_settings', $_POST);
    }
    if (isset($_POST['fieldupdate'])) {
        update_option('wp_mlm_paypal_field_settings', $_POST);
    }
    //most outer if condition
    if (isset($_POST['mlm_payment_settings'])) {
        $site_address = sanitize_text_field($_POST['mlm-site-address']);
        $shared_key = sanitize_text_field($_POST['mlm-pre-shared-key']);
        $merchant_id = sanitize_text_field($_POST['mlm-merchant-id']);
        $password = sanitize_text_field($_POST['mlm-merchant-password']);
        if (checkInputField($site_address)) {
            $error .= "\n Please Select your website address.";
        }
        if (checkInputField($shared_key)) {
            $error .= "\n Please specify Pre Shared Key.";
        }
        if (checkInputField($merchant_id)) {
            $error .= "\n Please specify Merchant ID.";
        }
        if (checkInputField($password)) {
            $error .= "\n Please specify Password.";
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_payment_settings', $_POST);
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-mlm-payment-settings";
            _e("<script>window.location='{$url}'</script>");
            $msg = "<span style='color:green;'>Your Payment settings has been successfully updated.</span>";
        }
    }
    // end outer if condition
    if ($chk != '') {
        $mlm_settings = get_option('wp_mlm_payment_settings');
        $mlm_paypal_settings = get_option('wp_mlm_paypal_payment_settings');
        $mlm_method = get_option('wp_mlm_payment_method');
        $paypal_settings = get_option('wp_mlm_paypal_settings');
        $paypal_field_settings = get_option('wp_mlm_paypal_field_settings');
        $paypalform = $paypal_field_settings['paypal_form'];
        ?>
 
		
<div class='wrap1'>
	<h2><?php 
        _e('Payment Setting', 'unilevel-mlm-pro');
        ?>
 </h2>
<table id="wpsc-payment-gateway-settings" class="wpsc-edit-module-options">
				<tbody><tr>
					<td width="50%" valign="top">
						<div class="postbox">
							<h3 class="hndle">Select Payment Gateways</h3>
							<div class="inside">
								<p>Activate the payment gateways that you want to make available to your customers by selecting them below.</p>
								<br>

<form name="admin_payment_settings" method="post" action="">

<div class="wpsc-select-gateway">
<div class="wpsc-gateway-actions">
<span class="edit">
<a class="edit-payment-module" data-gateway-id="paypal" title="Edit this Payment Gateway's Settings" href="<?php 
        echo $pageurl;
        ?>
&amp;payment_gateway_id=paypal">Edit</a></span></div>

<p><input type="radio" name="mlm_payment_method" value="paypal" id="mlm_paypal_method" <?php 
        if ($mlm_method['mlm_payment_method'] == 'paypal') {
            echo "checked='checked'";
        }
        ?>
>
<label for="mlm_paypal_method">Paypal</label></p></div>
					
<div class="wpsc-select-gateway">
<div class="wpsc-gateway-actions">
<span class="edit">
<a class="edit-payment-module" data-gateway-id="cardsave" title="Edit this Payment Gateway's Settings" href="<?php 
        echo $pageurl;
        ?>
&amp;payment_gateway_id=cardsave">Edit</a></span></div>
<p>
<input type="radio" name="mlm_payment_method" value="cardsave" id="mlm_worldpay_id" <?php 
        if ($mlm_method['mlm_payment_method'] == 'cardsave') {
            echo "checked='checked'";
        }
        ?>
>
<label for="mlm_worldpay_id">cardsave</label></p></div>


<div class="submit gateway_settings">
<input type="submit" value="Update" name="updateoption" class="button-primary">
</div>
</form>
</div>
</div>

</td>

<td id="wpsc-payment-gateway-settings-panel" class="wpsc-module-settings" rowspan="2">
									
									
									
	<?php 
        if ($error) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p> <strong><?php 
            _e('Please Correct the following Error', 'unilevel-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	
	<?php 
        if (empty($mlm_settings) && isset($_GET['payment_gateway_id']) && $_GET['payment_gateway_id'] == 'cardsave') {
            ?>
<div class="postbox">
<h3 class="hndle">Cardsave</h3>
<div class="inside">
	<form name="admin_payout_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="60%" class="form-table">
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-site-address');"><?php 
            _e('Website Address', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-site-address" id="mlm-site-address" size="30" value="<?php 
            if (!empty($mlm_settings['mlm-site-address'])) {
                _e($mlm_settings['mlm-site-address']);
            }
            ?>
">
				<div class="toggle-visibility" id="admin-mlm-site-address"><?php 
            _e('Please specify Website Address.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
		      <tr>
                          <th scope="row" class="admin-settings"><a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-item_name');"><?php 
            _e('Product Name:', 'unilevel-mlm-pro');
            ?>
</a>
      </th>
      <td>
      <input type="text" size="30" value="<?php 
            if (!empty($mlm_settings['item_name'])) {
                _e($mlm_settings['item_name'], 'unilevel-mlm-pro');
            }
            ?>
" name="item_name">
      <div class="toggle-visibility" id="admin-mlm-item_name"><?php 
            _e('Please specify Product Name.', 'unilevel-mlm-pro');
            ?>
</div>
      </td>
      </tr>
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-pre-shared-key');"><?php 
            _e('Pre Shared Key', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-pre-shared-key" id="mlm-pre-shared-key" size="30" value="<?php 
            if (!empty($mlm_settings['mlm-pre-shared-key'])) {
                _e($mlm_settings['mlm-pre-shared-key']);
            }
            ?>
">
				<div class="toggle-visibility" id="admin-mlm-pre-shared-key"><?php 
            _e('Please specify value of Pre Shared Key.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
		
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-merchant-id');"><?php 
            _e('Merchant ID', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-merchant-id" id="mlm-merchant-id" size="30" value="<?php 
            if (!empty($mlm_settings['mlm-merchant-id'])) {
                _e($mlm_settings['mlm-merchant-id']);
            }
            ?>
">
				<div class="toggle-visibility" id="admin-mlm-merchant-id"><?php 
            _e('Please specify value of Merchant ID.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
		
		
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-merchant-password');"><?php 
            _e('Password', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="password" name="mlm-merchant-password" id="mlm-merchant-password" size="30" value="<?php 
            if (!empty($mlm_settings['mlm-merchant-password'])) {
                _e($mlm_settings['mlm-merchant-password']);
            }
            ?>
">
				<div class="toggle-visibility" id="admin-mlm-merchant-password"><?php 
            _e('Please specify value of merchant Password.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
		
		
		
	</table>
	<p class="submit">
	<input type="submit" name="mlm_payment_settings" id="mlm_payment_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
	</form>
	</div>
	
	</div></div>
	<script language="JavaScript">
  populateArrays();
</script>
<?php 
        } else {
            if (!empty($mlm_settings) && isset($_GET['payment_gateway_id']) && $_GET['payment_gateway_id'] == 'cardsave') {
                ?>
		<div class="postbox">
<h3 class="hndle">Cardsave</h3>
<div class="inside">

			<form name="admin_payout_settings" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="60%" class="form-table">
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-site-address');"><?php 
                _e('Website Address', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-site-address" id="mlm-site-address" size="30" value="<?php 
                if (!empty($mlm_settings['mlm-site-address'])) {
                    _e($mlm_settings['mlm-site-address']);
                }
                ?>
">
				<div class="toggle-visibility" id="admin-mlm-site-address"><?php 
                _e('Please specify Website Address.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
  <tr>
                          <th scope="row" class="admin-settings"><a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-item_name');"><?php 
                _e('Product Name:', 'unilevel-mlm-pro');
                ?>
</a>
      </th>
      <td>
      <input type="text" size="30" value="<?php 
                if (!empty($mlm_settings['item_name'])) {
                    _e($mlm_settings['item_name'], 'unilevel-mlm-pro');
                }
                ?>
" name="item_name">
      <div class="toggle-visibility" id="admin-mlm-item_name"><?php 
                _e('Please specify Product Name.', 'unilevel-mlm-pro');
                ?>
</div>
      </td>
      </tr>
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-pre-shared-key');"><?php 
                _e('Pre Shared Key', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-pre-shared-key" id="mlm-pre-shared-key" size="30" value="<?php 
                if (!empty($mlm_settings['mlm-pre-shared-key'])) {
                    _e($mlm_settings['mlm-pre-shared-key']);
                }
                ?>
">
				<div class="toggle-visibility" id="admin-mlm-pre-shared-key"><?php 
                _e('Please specify value of Pre Shared Key.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
		
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-merchant-id');"><?php 
                _e('Merchant ID', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="text" name="mlm-merchant-id" id="mlm-merchant-id" size="30" value="<?php 
                if (!empty($mlm_settings['mlm-merchant-id'])) {
                    _e($mlm_settings['mlm-merchant-id']);
                }
                ?>
">
				<div class="toggle-visibility" id="admin-mlm-merchant-id"><?php 
                _e('Please specify value of Merchant ID.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
		
		
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('admin-mlm-merchant-password');"><?php 
                _e('Password', 'unilevel-mlm-pro');
                ?>
 <span style="color:red;">*</span>: </a>
			</th>
			<td>
		<input type="password" name="mlm-merchant-password" id="mlm-merchant-password" size="30" value="<?php 
                if (!empty($mlm_settings['mlm-merchant-password'])) {
                    _e($mlm_settings['mlm-merchant-password']);
                }
                ?>
">
				<div class="toggle-visibility" id="admin-mlm-merchant-password"><?php 
                _e('Please specify value of merchant Password.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
		
		
		
	</table>
	<p class="submit">
	<input type="submit" name="mlm_payment_settings" id="mlm_payment_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
	</form>
	</div>
	
	
	</div></div>
		<?php 
            }
        }
        if (empty($paypal_settings) && isset($_GET['payment_gateway_id']) && $_GET['payment_gateway_id'] == 'paypal' || empty($paypal_settings) && !isset($_GET['payment_gateway_id'])) {
            ?>
	<div class="postbox">
<h3 class="hndle"><?php 
            _e('Paypal', 'unilevel-mlm-pro');
            ?>
</h3>


<div class="inside">

<form action="" method="post" name="admin_paypal_settings" >								
<table class="form-table">
<tbody>								
<tr>
					<td><?php 
            _e('Display Name', 'unilevel-mlm-pro');
            ?>
</td>
					<td>
						<input type="text" name="user_defined_name" value=""><br>
						<small><?php 
            _e('The text that people see when making a purchase.', 'unilevel-mlm-pro');
            ?>
</small>
					</td>
				</tr>
  <tr>
      <td><?php 
            _e('Product Name:', 'unilevel-mlm-pro');
            ?>
      </td>
      <td>
      <input type="text" size="40" value="" name="item_name">
      </td>
  </tr>
  <tr>
  	<td></td>
  	<td colspan="1">
  	<span class="description">
  	<?php 
            _e('This will be shown Product Name at PayPal Gateway.', 'unilevel-mlm-pro');
            ?>
  	</span>
  	</td>
  </tr>

                                
                                
  <tr>
      <td><?php 
            _e('Username:'******'unilevel-mlm-pro');
            ?>
      </td>
      <td>
      <input type="text" size="40" value="" name="paypal_business">
      </td>
  </tr>
  <tr>
  	<td></td>
  	<td colspan="1">
  	<span class="description">
  	<?php 
            _e('This is your PayPal email address.', 'unilevel-mlm-pro');
            ?>
  	</span>
  	</td>
  </tr>

  <tr>
      <td><?php 
            _e('Account Type:', 'unilevel-mlm-pro');
            ?>
      </td>
      <td>
		<select name="paypal_multiple_url"><option value="https://www.paypal.com/cgi-bin/webscr" selected="selected"><?php 
            _e('Live Account', 'unilevel-mlm-pro');
            ?>
</option><option value="https://www.sandbox.paypal.com/cgi-bin/webscr"><?php 
            _e('Sandbox Account', 'unilevel-mlm-pro');
            ?>
</option></select>
	   </td>
  </tr>
  <tr>
	 <td colspan="1">
	 </td>
	 <td>
		<span class="description">
  			<?php 
            _e('If you have a PayPal developers Sandbox account please use Sandbox mode, if you just have a standard PayPal account then you will want to use Live mode.', 'unilevel-mlm-pro');
            ?>
  		</span>
  	  </td>
  </tr>
   <tr>
     <td><?php 
            _e('IPN :', 'unilevel-mlm-pro');
            ?>
     </td>
     <td>
       <input type="radio" value="1" name="paypal_ipn" id="paypal_ipn1"> <label for="paypal_ipn1"><?php 
            _e('Yes', 'unilevel-mlm-pro');
            ?>
</label> &nbsp;
       <input type="radio" value="0" name="paypal_ipn" id="paypal_ipn2"> <label for="paypal_ipn2"><?php 
            _e('No', 'unilevel-mlm-pro');
            ?>
</label>
     </td>
  </tr>
  <tr>
  	<td colspan="2">
  	<span class="description">
  	<?php 
            _e('IPN (instant payment notification ) will automatically update your sales logs to \'Accepted payment\' when a customers payment is successful. For IPN to work you also need to have IPN turned on in your Paypal settings. If it is not turned on, the sales sill remain as \'Order Pending\' status until manually changed. It is highly recommend using IPN, especially if you are selling digital products.', 'unilevel-mlm-pro');
            ?>
  	</span>
  	</td>
  </tr>
   <tr class="update_gateway">
		<td colspan="2">
			<div class="submit">
			<input type="submit" value="Update" name="updatepaypaloption">
		</div>
		</td>
	</tr>
</tbody></table>
</form>


 </div>
		


</div>	
	<?php 
        } else {
            if (!empty($paypal_settings) && isset($_GET['payment_gateway_id']) && $_GET['payment_gateway_id'] == 'paypal' || !empty($paypal_settings) && !isset($_GET['payment_gateway_id'])) {
                ?>
	<div class="postbox">
<h3 class="hndle"><?php 
                _e('Paypal', 'unilevel-mlm-pro');
                ?>
</h3>



<div class="inside">

<form action="" method="post" name="admin_paypal_settings" >								
<table class="form-table">
<tbody>
<tr>
					<td><?php 
                _e('Display Name', 'unilevel-mlm-pro');
                ?>
</td>
					<td>
						<input type="text" name="user_defined_name" value="<?php 
                if (!empty($paypal_settings['user_defined_name'])) {
                    _e($paypal_settings['user_defined_name'], 'unilevel-mlm-pro');
                }
                ?>
"><br>
						<small><?php 
                _e('The text that people see when making a purchase.', 'unilevel-mlm-pro');
                ?>
</small>
					</td>
				</tr>

     <tr>
      <td><?php 
                _e('Product Name:', 'unilevel-mlm-pro');
                ?>
      </td>
      <td>
      <input type="text" size="40" value="<?php 
                if (!empty($paypal_settings['item_name'])) {
                    _e($paypal_settings['item_name'], 'unilevel-mlm-pro');
                }
                ?>
" name="item_name">
      </td>
  </tr>
  <tr>
  	<td></td>
  	<td colspan="1">
  	<span class="description">
  	<?php 
                _e('This will be shown Product Name at PayPal Gateway.', 'unilevel-mlm-pro');
                ?>
  	</span>
  	</td>
  </tr>                             
                                
  <tr>
      <td><?php 
                _e('Username:'******'unilevel-mlm-pro');
                ?>
      </td>
      <td>
      <input type="text" size="40" value="<?php 
                if (!empty($paypal_settings['paypal_business'])) {
                    _e($paypal_settings['paypal_business'], 'unilevel-mlm-pro');
                }
                ?>
" name="paypal_business">
      </td>
  </tr>
  <tr>
  	<td></td>
  	<td colspan="1">
  	<span class="description">
  	<?php 
                _e('This is your PayPal email address.', 'unilevel-mlm-pro');
                ?>
  	</span>
  	</td>
  </tr>

  <tr>
      <td><?php 
                _e('Account Type:', 'unilevel-mlm-pro');
                ?>
      </td>
      <td>
		<select name="paypal_multiple_url">
		<option value="https://www.paypal.com/cgi-bin/webscr" <?php 
                if (!empty($paypal_settings['paypal_multiple_url']) && $paypal_settings['paypal_multiple_url'] == 'https://www.paypal.com/cgi-bin/webscr') {
                    ?>
 selected="selected" <?php 
                }
                ?>
 ><?php 
                _e('Live Account', 'unilevel-mlm-pro');
                ?>
</option>
		<option value="https://www.sandbox.paypal.com/cgi-bin/webscr" <?php 
                if (!empty($paypal_settings['paypal_multiple_url']) && $paypal_settings['paypal_multiple_url'] == 'https://www.sandbox.paypal.com/cgi-bin/webscr') {
                    ?>
 selected="selected" <?php 
                }
                ?>
><?php 
                _e('Sandbox Account', 'unilevel-mlm-pro');
                ?>
</option></select>
	   </td>
  </tr>
  <tr>
	 <td colspan="1">
	 </td>
	 <td>
		<span class="description">
  			<?php 
                _e('If you have a PayPal developers Sandbox account please use Sandbox mode, if you just have a standard PayPal account then you will want to use Live mode.', 'unilevel-mlm-pro');
                ?>
  		</span>
  	  </td>
  </tr>
   <tr>
     <td><?php 
                _e('IPN :', 'unilevel-mlm-pro');
                ?>
     </td>
     <td>
       <input type="radio" value="1" name="paypal_ipn" id="paypal_ipn1" <?php 
                if ($paypal_settings['paypal_ipn'] != '' && $paypal_settings['paypal_ipn'] == '1') {
                    ?>
 checked="checked" <?php 
                }
                ?>
> <label for="paypal_ipn1"><?php 
                _e('Yes', 'unilevel-mlm-pro');
                ?>
</label> &nbsp;
       <input type="radio" value="0" name="paypal_ipn" id="paypal_ipn2" <?php 
                if ($paypal_settings['paypal_ipn'] != '' && $paypal_settings['paypal_ipn'] == '0') {
                    ?>
 checked="checked" <?php 
                }
                ?>
> <label for="paypal_ipn2"><?php 
                _e('No', 'unilevel-mlm-pro');
                ?>
</label>
     </td>
  </tr>
  <tr>
  	<td colspan="2">
  	<span class="description">
  	<?php 
                _e('IPN (instant payment notification ) will automatically update your sales logs to \'Accepted payment\' when a customers payment is successful. For IPN to work you also need to have IPN turned on in your Paypal settings. If it is not turned on, the sales sill remain as \'Order Pending\' status until manually changed. It is highly recommend using IPN, especially if you are selling digital products.', 'unilevel-mlm-pro');
                ?>
  	</span>
  	</td>
  </tr>

   <tr class="update_gateway">
		<td colspan="2">
			<div class="submit">
			<input type="submit" value="Update" name="updatepaypaloption">
		</div>
		</td>
	</tr>


</tbody></table>
</form>
 </div>
		


</div>	
		
<?php 
            }
        }
        ?>
		
		</td>
						</tr>
			</tbody></table>
		<?php 
    } else {
        _e($msg);
    }
}
function mlmNetworkDetailsPage()
{
    //get loged user's key
    $key = get_current_user_key();
    //Total my personal sales
    $personalSales = totalMyPersonalSales($key);
    //Total my personal sales active users
    $activePersonalSales = activeUsersOnPersonalSales($key);
    //show five users on personal sales
    $fivePersonalUsers = myFivePersonalUsers($key);
    //get logged in user info
    global $current_user, $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    get_currentuserinfo();
    $username = $current_user->ID;
    $user_info = get_userdata($current_user->ID);
    $_SESSION['ajax'] = 'ajax_check';
    $add_page_id = get_post_id('mlm_registration_page');
    $sponsor_name = $current_user->user_login;
    /**********Affiliate URL CODE***********************/
    $affiliateURLold = site_url() . '?page_id=' . $add_page_id . '&sp=' . $key;
    $affiliateURLnew = site_url() . '/u/' . $sponsor_name;
    $permalink = get_permalink(empty($_GET['page_id']) ? '' : $_GET['page_id']);
    $postidparamalink = strstr($permalink, 'page_id');
    $affiliateURL = $postidparamalink ? $affiliateURLold : $affiliateURLnew;
    /*********E O F Affiliate URL Code************************/
    $view_memberpage_id = $wpdb->get_var("SELECT id FROM {$table_prefix}posts  WHERE `post_content` LIKE '%mlm-view-child-level-member%'\tAND `post_type` != 'revision'");
    // Check Payment Method
    $mlm_method = get_option('wp_mlm_payment_method');
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    $mlm_pay_settings = get_option('wp_mlm_payment_settings');
    //Check If USER is Not PAid then will show option for Payment
    $check_paid = $wpdb->get_var("SELECT payment_status FROM {$table_prefix}mlm_users WHERE user_id = '" . $username . "'");
    if ($check_paid == 0) {
        PayNowOptions($username, 'dashboard');
    }
    ?>
	     <?php 
    if (function_exists('Update_Paypal_Notification')) {
        Update_Paypal_Notification();
    }
    ?>
	
<p class="affiliate_url"><strong>Affiliate URL :</strong> <?php 
    echo $affiliateURL;
    ?>
 </p><br /> 
		<table width="100%" border="0" cellspacing="10" cellpadding="1">
		  <tr>
			<td width="40%" valign="top">
				<table width="100%" border="0" cellspacing="10" cellpadding="1">
				  <tr>
					<td colspan="2"><strong><?php 
    _e('Personal Information', 'unilevel-mlm-pro');
    ?>
</strong></td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('Title', 'unilevel-mlm-pro');
    ?>
</td>
					<td><?php 
    _e('Details', 'unilevel-mlm-pro');
    ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('Name', 'unilevel-mlm-pro');
    ?>
</td>
					<td><?php 
    echo $user_info->first_name . ' ' . $user_info->last_name;
    ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('Address', 'unilevel-mlm-pro');
    ?>
</td>
					<td style="white-space:normal;"><?php 
    echo $user_info->user_address1 . "<br>" . $user_info->user_address2;
    ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('City', 'unilevel-mlm-pro');
    ?>
</td>
					<td><?php 
    echo $user_info->user_city;
    ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('Contact No', 'unilevel-mlm-pro');
    ?>
.</td>
					<td><?php 
    echo $user_info->user_telephone;
    ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('DOB', 'unilevel-mlm-pro');
    ?>
</td>
					<td><?php 
    echo $user_info->user_dob;
    ?>
</td>
				  </tr>
				  
				  
				  
				  <tr>
		<td><a href="<?php 
    echo get_post_id_or_postname('mlm_update_profile_page', 'unilevel-mlm-pro');
    ?>
" style="text-decoration: none"><?php 
    _e('Edit', 'unilevel-mlm-pro');
    ?>
</a></td>
		<td><a href="<?php 
    echo get_post_id_or_postname('mlm_network_genealogy_page', 'unilevel-mlm-pro');
    ?>
" style="text-decoration: none"><?php 
    _e('View Genealogy', 'unilevel-mlm-pro');
    ?>
</a></td>
		</tr>
				</table> 
					<table width="100%" border="0" cellspacing="10" cellpadding="1">
				  <tr>
					<td colspan="2"><strong><?php 
    _e('My Payouts', 'unilevel-mlm-pro');
    ?>
</strong></td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
    _e('Date', 'unilevel-mlm-pro');
    ?>
</td>
					<td><?php 
    _e('Amount', 'unilevel-mlm-pro');
    ?>
</td>
       <td><?php 
    _e('Action', 'unilevel-mlm-pro');
    ?>
</td>
				  </tr>
<?php 
    $detailsArr = my_payout_function();
    //_e("<pre>");print_r($detailsArr); exit;
    //$page_id = get_post_id('mlm_my_payout_details_page');
    if (count($detailsArr) > 0) {
        $mlm_settings = get_option('wp_mlm_general_settings');
        ?>
			<?php 
        foreach ($detailsArr as $row) {
            $amount = $row->commission_amount + $row->bonus_amount;
            ?>
		<tr>
			<td><?php 
            echo $row->payoutDate;
            ?>
</td>
			<td><?php 
            echo $mlm_settings['currency'] . ' ' . $amount;
            ?>
</td>
			<td><a href="<?php 
            echo get_post_id_or_postname_for_payout('mlm_my_payout_details_page', $row->payout_id);
            ?>
">View</a></td>
			
		</tr>
		
		<?php 
        }
        ?>
	<?php 
    } else {
        ?>
	<div class="no-payout"><?php 
        _e('You have not earned any commisssions yet.', 'unilevel-mlm-pro');
        ?>
 </div>
	
	<?php 
    }
    ?>
				</table>
			</td>
			<td width="40%">
				<table width="100%" border="0" cellspacing="10" cellpadding="1">
				  <tr>
					<td><strong><?php 
    _e('Network Details', 'unilevel-mlm-pro');
    ?>
</strong></td>
				  </tr>
				  
				  

				 	<tr>
					<td>
						<table width="100%" border="0" cellspacing="10" cellpadding="1">
							<tr>
								<td colspan="2"><strong><?php 
    _e('Personal Sales', 'unilevel-mlm-pro');
    ?>
</strong></td>
							</tr>
							
							<tr>
								<td><?php 
    _e('My Personal Sales', 'unilevel-mlm-pro');
    ?>
: <?php 
    echo $personalSales;
    ?>
</td>
			<td><?php 
    _e('Active', 'unilevel-mlm-pro');
    ?>
: <?php 
    echo $activePersonalSales;
    ?>
</td>
							</tr>
							<?php 
    foreach ($fivePersonalUsers as $key => $value) {
        _e("<tr>");
        foreach ($value as $k => $val) {
            _e("<td>" . $val . "</td>");
        }
        _e("</tr>");
    }
    ?>
							<tr>
		<td colspan="2"><a href="?page_id=<?php 
    echo $view_memberpage_id;
    ?>
&lvl=1" style="text-decoration: none"><?php 
    _e('View All', 'unilevel-mlm-pro');
    ?>
</a></td>
		</tr>
							
						</table>
					</td>
				  </tr> 
				  
				</table>
			</td>
		  </tr>
		</table>

<?php 
}
function mlmPayout()
{
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //get no. of level
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    $mlm_product_value = $mlm_general_settings['single-sale'];
    //most outer if condition
    if (isset($_POST['mlm_payout_settings'])) {
        //echo "<pre>"; print_r($_POST);
        $company_commission = sanitize_text_field($_POST['company_commission_amount']);
        $referral_commission = sanitize_text_field($_POST['referral_commission_amount']);
        if (checkInputField($company_commission)) {
            $error .= "\n Please specify your company commission.";
        }
        if (checkInputField($referral_commission)) {
            $error .= "\n Please specify your referral commission.";
        }
        for ($k = 1; $k <= $mlm_no_of_level; $k++) {
            if (checkInputField(sanitize_text_field($_POST['level' . $k . '_commission']))) {
                $error .= "\n Please specify your Level {$k} Commission.";
            }
        }
        //if any error occoured
        if (!empty($error)) {
            $error = nl2br($error);
        } else {
            $chk = '';
            update_option('wp_mlm_payout_settings', $_POST);
            $url = get_bloginfo('url') . "/wp-admin/admin.php?page=admin-settings&tab=regular_bonus";
            _e("<script>window.location='{$url}'</script>");
            $msg = "<span style='color:green;'>Your payout settings has been successfully updated.</span>";
        }
    }
    // end outer if condition
    if ($chk != '') {
        $mlm_settings = get_option('wp_mlm_payout_settings');
        ?>


<div class='wrap1'>
	<h2><?php 
        _e('Payout Settings', 'unilevel-mlm-pro');
        ?>
  </h2>
	<div class="notibar msginfo">
		<a class="close"></a>
		<p><?php 
        _e('These settings define the commissions that would be distributed in the network for a single sale in the network.', 'unilevel-mlm-pro');
        ?>
</p>
		<p><strong><?php 
        _e('Commission Type', 'unilevel-mlm-pro');
        ?>
 - </strong><?php 
        _e('Select whether the commission amounts specified are absolute numbers or percentage figures.', 'unilevel-mlm-pro');
        ?>
</p>
		<p><strong><?php 
        _e('Company Share', 'unilevel-mlm-pro');
        ?>
 - </strong><?php 
        _e('This is a fixed amount that is payable to the company (First User in the network) for every sale in the network.', 'unilevel-mlm-pro');
        ?>
</p>
		<p><strong><?php 
        _e('Referral Commission', 'unilevel-mlm-pro');
        ?>
</strong> - <?php 
        _e('This is a referral commission that is paid to the sponsor for sponsoring a new member to the network.  This is over and above his regular Level based commissions. You can set this to zero in case you do not want to distribute any referral commission as typically this would be covered
under Level 1 Commissions.', 'unilevel-mlm-pro');
        ?>
</p>
		<p><strong><?php 
        _e('Level Commissions', 'unilevel-mlm-pro');
        ?>
 - </strong><?php 
        _e('These are the amounts payable at various levels in the upline depending on the No. of Levels setting defined under the General Tab.', 'unilevel-mlm-pro');
        ?>
</p>
<p><strong><?php 
        _e('Note :', 'unilevel-mlm-pro');
        ?>
  </strong><?php 
        _e('The sum of all the commissions mentioned above should always be less than or equal to the
Product Value as defined in the General Tab.', 'unilevel-mlm-pro');
        ?>
</p>		
	</div>
	<?php 
        if ($error) {
            ?>
	<div class="notibar msgerror">
		<a class="close"></a>
		<p> <strong><?php 
            _e('Please Correct the following Error', 'unilevel-mlm-pro');
            ?>
 :</strong> <?php 
            _e($error);
            ?>
</p>
	</div>
	<?php 
        }
        ?>
	<script>
	 function check_total_amount(num) 
{ 
    
var commission_type = document.getElementById('commission_type').value;

var direct_cpy=parseFloat(document.getElementById('company_commission_amount').value);
var direct_reff=parseFloat(document.getElementById('referral_commission_amount').value);

if(commission_type=='percent') {
var level_comm=0;
var total=100;
for(var i=1;i<=num;i++)
{
var x='level'+i+'_commission';
level_comm += parseFloat(document.getElementById(x).value);

}
var result=direct_cpy+direct_reff+level_comm;

if(result!=total)
 { 
alert('Commissions in percent should always be equal to 100.Please Correct this.');
document.getElementById('company_commission_amount').focus()
return false;

}

}
}
</script>
<?php 
        if (empty($mlm_settings)) {
            ?>
		<form name="admin_payout_settings" method="post" action="" onsubmit="return check_total_amount('<?php 
            echo $mlm_no_of_level;
            ?>
');">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">

    <tr>
	<th scope="row" class="admin-settings"><?php 
            _e('Commission Type', 'unilevel-mlm-pro');
            ?>
 :</th>
	<td>
	<select name="commission_type" id="commission_type" >
    <option value="fixed" <?php 
            if ($_POST['commission_type'] == 'fixed') {
                echo 'selected';
            }
            ?>
 >Fixed </option>
	<option value="percent" <?php 
            if ($_POST['commission_type'] == 'percent') {
                echo 'selected';
            }
            ?>
>Percent </option>
	</select>
	</td></tr>	


	
		<tr>
	<th scope="row" class="admin-settings">
				<a style="cursor:pointer;"title="Click for Help!" onclick="toggleVisibility('admin-mlm-company_commission_amount');">
				<?php 
            _e('Company Share', 'unilevel-mlm-pro');
            ?>
 :</a>
			</th>
			<td>
			<input type="text" name="company_commission_amount" id="company_commission_amount" size="10" value="<?php 
            if (isset($_POST['company_commission_amount'])) {
                _e(htmlentities($_POST['company_commission_amount']));
            }
            ?>
"><?php 
            if ($_POST['commission_type'] == 'percent') {
                echo '%';
            }
            ?>
				<div class="toggle-visibility" id="admin-mlm-company_commission_amount"><?php 
            _e('Please specify Company commission.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		<tr>
	<th scope="row" class="admin-settings">
				<a style="cursor:pointer;"title="Click for Help!" onclick="toggleVisibility('admin-mlm-referral_commission_amount');">
				<?php 
            _e('Referral Commission', 'unilevel-mlm-pro');
            ?>
 :</a>
			</th>
			<td>
			<input type="text" name="referral_commission_amount" id="referral_commission_amount" size="10" value="<?php 
            if (isset($_POST['referral_commission_amount'])) {
                _e(htmlentities($_POST['referral_commission_amount']));
            }
            ?>
"><?php 
            if ($_POST['commission_type'] == 'percent') {
                echo '%';
            }
            ?>
				<div class="toggle-visibility" id="admin-mlm-referral_commission_amount"><?php 
            _e('Please specify referral commission.', 'unilevel-mlm-pro');
            ?>
</div>
			</td>
		</tr>
		
    
<?php 
            for ($j = 1; $j <= $mlm_no_of_level; $j++) {
                ?>
		  

<th scope="row" class="admin-settings">
				<a style="cursor:pointer;"title="Click for Help!" onclick="toggleVisibility('admin-mlm-level<?php 
                echo $j;
                ?>
-commission');">
				<?php 
                _e('Level ' . $j . ' Commission', 'unilevel-mlm-pro');
                ?>
 :</a>
			</th>
			<td>
			<input type="text" name="level<?php 
                echo $j;
                ?>
_commission" id="level<?php 
                echo $j;
                ?>
_commission" size="10" value="<?php 
                if (isset($_POST['level' . $j . '_commission'])) {
                    _e(htmlentities($_POST['level' . $j . '_commission']));
                }
                ?>
"><?php 
                if ($_POST['commission_type'] == 'percent') {
                    echo '%';
                }
                ?>
				<div class="toggle-visibility" id="admin-mlm-level<?php 
                echo $j;
                ?>
-commission"><?php 
                _e('Please specify Level ' . $j . ' Commission.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>


<?php 
            }
            ?>

	
		</table>
		<p class="submit">
	<input type="submit" name="mlm_payout_settings" id="mlm_payout_settings" value="<?php 
            _e('Update Options', 'unilevel-mlm-pro');
            ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
	</form>

	<?php 
        } else {
            if (!empty($mlm_settings)) {
                ?>
			<form name="admin_payout_settings" method="post" action="" onsubmit="return check_total_amount('<?php 
                echo $mlm_no_of_level;
                ?>
');">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
	

    <tr>
	<th scope="row" class="admin-settings"><?php 
                _e('Commission Type', 'unilevel-mlm-pro');
                ?>
 :</th>
	<td>
	<select name="commission_type" id="commission_type" >
    <option value="fixed" <?php 
                if ($mlm_settings['commission_type'] == 'fixed') {
                    echo 'selected';
                }
                ?>
 >Fixed </option>
	<option value="percent" <?php 
                if ($mlm_settings['commission_type'] == 'percent') {
                    echo 'selected';
                }
                ?>
>Percent </option>
	</select>
	</td></tr>	
		
		<tr>
	<th scope="row" class="admin-settings">
				<a style="cursor:pointer;"title="Click for Help!" onclick="toggleVisibility('admin-mlm-company_commission_amount');">
				<?php 
                _e('Company Share', 'unilevel-mlm-pro');
                ?>
 :</a>
			</th>
			<td>
			<input type="text" name="company_commission_amount" id="company_commission_amount" size="10" value="<?php 
                if (isset($mlm_settings['company_commission_amount'])) {
                    _e($mlm_settings['company_commission_amount'], 'unilevel-mlm-pro');
                }
                ?>
"><?php 
                if ($mlm_settings['commission_type'] == 'percent') {
                    echo '%';
                }
                ?>
				<div class="toggle-visibility" id="admin-mlm-company_commission_amount"><?php 
                _e('Please specify Company commission.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		<tr>
	<th scope="row" class="admin-settings">
				<a style="cursor:pointer;"title="Click for Help!" onclick="toggleVisibility('admin-mlm-referral_commission_amount');">
				<?php 
                _e('Referral Commission', 'unilevel-mlm-pro');
                ?>
 :</a>
			</th>
			<td>
			<input type="text" name="referral_commission_amount" id="referral_commission_amount" size="10" value="<?php 
                if (isset($mlm_settings['referral_commission_amount'])) {
                    _e($mlm_settings['referral_commission_amount'], 'unilevel-mlm-pro');
                }
                ?>
"><?php 
                if ($mlm_settings['commission_type'] == 'percent') {
                    echo '%';
                }
                ?>
				<div class="toggle-visibility" id="admin-mlm-referral_commission_amount"><?php 
                _e('Please specify referral commission.', 'unilevel-mlm-pro');
                ?>
</div>
			</td>
		</tr>
		
<?php 
                for ($j = 1; $j <= $mlm_no_of_level; $j++) {
                    ?>
		  

<th scope="row" class="admin-settings">
				<a style="cursor:pointer;"title="Click for Help!" onclick="toggleVisibility('admin-mlm-level<?php 
                    echo $j;
                    ?>
-commission');">
				<?php 
                    _e('Level ' . $j . ' Commission', 'unilevel-mlm-pro');
                    ?>
 :</a>
			</th>
			<td>
			<input type="text" name="level<?php 
                    echo $j;
                    ?>
_commission" id="level<?php 
                    echo $j;
                    ?>
_commission" size="10" value="<?php 
                    if (isset($mlm_settings['level' . $j . '_commission'])) {
                        _e($mlm_settings['level' . $j . '_commission']);
                    }
                    ?>
"><?php 
                    if ($mlm_settings['commission_type'] == 'percent') {
                        echo '%';
                    }
                    ?>
				<div class="toggle-visibility" id="admin-mlm-level<?php 
                    echo $j;
                    ?>
-commission"><?php 
                    _e('Please specify Level ' . $j . ' Commission.', 'unilevel-mlm-pro');
                    ?>
</div>
			</td>
		</tr>


<?php 
                }
                ?>
		  
		</table>
		<p class="submit">
	<input type="submit" name="mlm_payout_settings" id="mlm_payout_settings" value="<?php 
                _e('Update Options', 'unilevel-mlm-pro');
                ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
	</form>

	<script language="JavaScript">
  populateArrays();
</script>
<?php 
            }
        }
    } else {
        _e($msg);
    }
}
function register_first_user()
{
    global $wpdb;
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    //most outer if condition
    if (isset($_POST['submit'])) {
        $username = sanitize_text_field($_POST['username']);
        $password = sanitize_text_field($_POST['password']);
        $confirm_pass = sanitize_text_field($_POST['confirm_password']);
        $email = sanitize_text_field($_POST['email']);
        $confirm_email = sanitize_text_field($_POST['confirm_email']);
        $firstname = sanitize_text_field($_POST['first_name']);
        $lastname = sanitize_text_field($_POST['last_name']);
        //Add usernames we don't want used
        $invalid_usernames = array('admin');
        //Do username validation
        $username = sanitize_user($username);
        if (!validate_username($username) || in_array($username, $invalid_usernames)) {
            $error .= "\n Username is invalid.";
        }
        if (username_exists($username)) {
            $error .= "\n Username already exists.";
        }
        if (checkInputField($username)) {
            $error .= "\n Please enter your username.";
        }
        if (checkInputField($password)) {
            $error .= "\n Please enter your password.";
        }
        if (confirmPassword($password, $confirm_pass)) {
            $error .= "\n Please confirm your password.";
        }
        //Do e-mail address validation
        if (!is_email($email)) {
            $error .= "\n E-mail address is invalid.";
        }
        if (email_exists($email)) {
            $error .= "\n E-mail address is already in use.";
        }
        if (confirmEmail($email, $confirm_email)) {
            $error .= "\n Please confirm your email address.";
        }
        //generate random numeric key for new user registration
        $user_key = generateKey();
        // outer if condition
        if (empty($error)) {
            $user = array('user_login' => $username, 'user_pass' => $password, 'user_email' => $email, 'first_name' => $firstname, 'last_name' => $lastname, 'role' => 'mlm_user');
            // return the wp_users table inserted user's ID
            $user_id = wp_insert_user($user);
            /* Send e-mail to admin and new user - 
               You could create your own e-mail instead of using this function */
            wp_new_user_notification($user_id, $password);
            //insert the data into fa_user table
            $insert = "INSERT INTO {$table_prefix}mlm_users\n\t\t\t\t\t\t   \t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_id, username, user_key, parent_key, sponsor_key, leg, payment_status\n\t\t\t\t\t\t\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $user_id . "','" . $username . "', '" . $user_key . "', '0', '0', '0','1'\n\t\t\t\t\t\t\t\t\t\t\t\t\t)";
            // if all data successfully inserted
            if ($wpdb->query($insert)) {
                $chk = '';
                //$msg = "<span style='color:green;'>Congratulations! You have successfully registered in the system.</span>";
            }
        }
        //end outer if condition
    }
    //end most outer if condition
    //if any error occoured
    if (!empty($error)) {
        $error = nl2br($error);
    }
    if ($chk != '') {
        include 'js-validation-file.html';
        ?>
        <div class='wrap'>
            <h2><?php 
        _e('Create First User in Network', 'binary-mlm-pro');
        ?>
</h2>
            <div class="notibar msginfo">
                <a class="close"></a>
                <p><?php 
        _e('In order to begin building your network you would need to register the First User of the network. All other users would be registered under this First User.', 'binary-mlm-pro');
        ?>
</p>
            </div>
            <?php 
        if ($error) {
            ?>
                <div class="notibar msgerror">
                    <a class="close"></a>
                    <p> <strong><?php 
            _e('Please Correct the following Error(s)', 'binary-mlm-pro');
            ?>
:</strong> <?php 
            _e($error);
            ?>
</p>
                </div>
            <?php 
        }
        ?>

            <p>&nbsp;</p>
            <form name="frm" method="post" action="" onSubmit="return adminFormValidation();">
                <table border="0" cellpadding="0" cellspacing="0" width="100%"  class="form-table">

                    <tr>
                        <th scope="row" class="admin-settings">
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('create-first-user');">
                                <?php 
        _e('Create Username', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>: </a>
                        </th>
                        <td>
                            <input type="text" name="username" id="username" value="<?php 
        if (!empty($_POST['username'])) {
            _e(htmlentities($_POST['username']));
        }
        ?>
" maxlength="20" size="37">
                            <div class="toggle-visibility" id="create-first-user"><?php 
        _e('Please create the first user of the your network.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>

                    <tr>
                        <th scope="row" class="admin-settings">
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('create-password');"></a>
                            <?php 
        _e('Create Password', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>: </a>
                        </th>
                        <td><input type="password" name="password" id="password" maxlength="20" size="37" >
                            <div class="toggle-visibility" id="create-password"><?php 
        _e('Password length is atleast 6 char.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>

                    <tr>
                        <th scope="row" class="admin-settings">
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('confirm-password');">
                                <?php 
        _e('Confirm Password', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>: </a>
                        </th>
                        <td>
                            <input type="password" name="confirm_password" id="confirm_password" maxlength="20" size="37" >
                            <div class="toggle-visibility" id="confirm-password"><?php 
        _e('Please confirm your password.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>

                    <tr>
                        <th scope="row" class="admin-settings">
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('email-address');">
                                <?php 
        _e('Email Address', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>: </a>
                        </th>
                        <td>
                            <input type="text" name="email" id="email" value="<?php 
        if (!empty($_POST['email'])) {
            _e(htmlentities($_POST['email']));
        }
        ?>
"  size="37" >
                            <div class="toggle-visibility" id="email-address"><?php 
        _e('Please specify your email address.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>

                    <tr>
                        <th>
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('confirm-address');">
                                <?php 
        _e('Confirm Email Address', 'binary-mlm-pro');
        ?>
 <span style="color:red;">*</span>: </a>
                        </th>
                        <td>
                            <input type="text" name="confirm_email" id="confirm_email" value="<?php 
        if (!empty($_POST['confirm_email'])) {
            _e(htmlentities($_POST['confirm_email']));
        }
        ?>
" size="37" >
                            <div class="toggle-visibility" id="confirm-address"><?php 
        _e('Please confirm your email address.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('first-name');">
                                <?php 
        _e('First Name', 'binary-mlm-pro');
        ?>
 
                        </th>
                        <td>
                            <input type="text" name="first_name" id="first_name" value="<?php 
        if (!empty($_POST['first_name'])) {
            _e(htmlentities($_POST['first_name']));
        }
        ?>
" size="37" >
                            <div class="toggle-visibility" id="first-name"><?php 
        _e('Please enter your first name.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('last-name');">
                                <?php 
        _e('Last Name', 'binary-mlm-pro');
        ?>
  </a>
                        </th>
                        <td>
                            <input type="text" name="last_name" id="last_name" value="<?php 
        if (!empty($_POST['last_name'])) {
            _e(htmlentities($_POST['last_name']));
        }
        ?>
" size="37" >
                            <div class="toggle-visibility" id="last-name"><?php 
        _e('Please confirm your last name.', 'binary-mlm-pro');
        ?>
</div>
                        </td>
                    </tr>
                </table>
                <p class="submit">
                    <input type="submit" name="submit" id="submit" value="<?php 
        _e('Submit', 'binary-mlm-pro');
        ?>
" class='button-primary' onclick="needToConfirm = false;"/>
                </p>
            </form>
        </div>	
        <script language="JavaScript">
            populateArrays();
        </script>
        <?php 
    } else {
        _e("<script>window.location='admin.php?page=admin-settings&tab=general&msg=s'</script>");
    }
}
Esempio n. 25
0
function mlm_core_drop_tables()
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    mlm_core_delete_users_data();
    $wpdb->query("DROP TABLE {$table_prefix}mlm_users");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_country");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_currency");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_commission");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_bonus");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_payout");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_payout_master");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_hierarchy");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_payment_status");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_transaction");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_withdrawal");
    $wpdb->query("DROP TABLE {$table_prefix}mlm_epins");
}
function adminMLMUserAccountInterface()
{
    //get database table prefix
    $table_prefix = mlm_core_get_table_prefix();
    global $wpdb;
    $msg = '';
    if (isset($_POST['mlm_user_account'])) {
        $search = $_POST['search_user'];
        $userId = $wpdb->get_var("SELECT ID FROM {$table_prefix}users WHERE user_login = '******' OR user_email = '{$search}'");
        if ($wpdb->num_rows > 0) {
            $_SESSION['search_user'] = $search;
            $_SESSION['session_set'] = 'sets';
            $_SESSION['userID'] = $userId;
        } else {
            $msg = __('You have entered a wrong username or email address', 'unilevel-mlm-pro');
            $_SESSION['search_user'] = $search;
            $_SESSION['session_set'] = '';
            $_SESSION['userID'] = '';
        }
    }
    ?>

<div class='wrap'>
	<div id="icon-users" class="icon32"></div><h1><?php 
    _e('User Report', 'unilevel-mlm-pro');
    ?>
</h1><br />

	<div class="notibar msginfo" style="margin:10px;">
		<a class="close"></a>
		<p><?php 
    _e("Input a member's username or email address in the input box below to get complete information about the member's account. No more switching back and forth into different member accounts to check their account details.", 'unilevel-mlm-pro');
    ?>
</p>
	</div>	

</div>

<div class="forms-ui">

<p><span style='color:red;'><?php 
    if (!empty($error)) {
        _e($error);
    }
    ?>
</span></p>

		<form name="open_user_account" method="post" action="">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" class="form-table">
		<tr>
			<th scope="row" class="admin-settings">
				<a style="cursor:pointer;" title="Click for Help!" onclick="toggleVisibility('search-user');"><?php 
    _e('Search By username or email address', 'unilevel-mlm-pro');
    ?>
 :</a>
			</th>
			<td>
				<input type="text" name="search_user" id="search_user" size="52" value="<?php 
    if (!empty($_SESSION['search_user'])) {
        _e(htmlentities($_SESSION['search_user']));
    }
    ?>
">
				<a href="?page=mlm-user-account" style="cursor:pointer;text-decoration:none; margin-left:90px;"><?php 
    _e('Back to User Dashboard', 'unilevel-mlm-pro');
    ?>
</a>
				<div class="toggle-visibility" id="search-user"><?php 
    _e('Please enter username or email address.', 'unilevel-mlm-pro');
    ?>
</div>
				<div style="color:red;"><?php 
    echo $msg;
    ?>
</div>
			</td>
		</tr>
		</table>
		<p class="submit">
	<input type="submit" name="mlm_user_account" id="mlm_user_account" value="<?php 
    _e('Search', 'unilevel-mlm-pro');
    ?>
 &raquo;" class='button-primary' onclick="needToConfirm = false;">
	</p>
	</form>

	<script language="JavaScript">
  populateArrays();
</script>
<!-----sdfgdf -->
<?php 
    if (!empty($_GET['ac'])) {
        if ($_GET['ac'] == 'edit' && $_GET['page'] == 'mlm-user-account') {
            mlm_update_profile($_SESSION['userID']);
        } else {
            if ($_GET['ac'] == 'personal' && $_GET['page'] == 'mlm-user-account') {
                myPersonalGroupDetails($_SESSION['userID']);
            } else {
                if ($_GET['ac'] == 'payout' && $_GET['page'] == 'mlm-user-account') {
                    mlm_my_payout_page($_SESSION['userID']);
                } else {
                    if ($_GET['ac'] == 'payout-details' && $_GET['page'] == 'mlm-user-account') {
                        mlm_my_payout_details_page($_SESSION['userID']);
                    } else {
                        if ($_GET['ac'] == 'network' && $_GET['page'] == 'mlm-user-account') {
                            adminViewUnilevelNetwork($_SESSION['userID']);
                        }
                    }
                }
            }
        }
    } else {
        if (!empty($_SESSION['session_set']) && $_SESSION['session_set'] == 'sets') {
            $key = $wpdb->get_var("SELECT user_key FROM {$table_prefix}mlm_users WHERE user_id = {$_SESSION['userID']}");
            //Total my personal sales
            $personalSales = totalMyPersonalSales($key);
            //Total my personal sales active users
            $activePersonalSales = activeUsersOnPersonalSales($key);
            //show five users on personal sales
            $fivePersonalUsers = myFivePersonalUsers($key);
            $user_info = get_userdata($_SESSION['userID']);
            $add_page_id = get_post_id('mlm_registration_page');
            $sponsor_name = $user_info->user_login;
            $affiliateURL = site_url() . '?page_id=' . $add_page_id . '&sponsor=' . $sponsor_name;
            ?>
	
		<table width="100%" border="0" cellspacing="10" cellpadding="1">
		  <tr>
			<td width="40%" valign="top">
				<table width="100%" border="0" cellspacing="10" cellpadding="1">
				  <tr>
					<td colspan="2"><strong><?php 
            _e('Personal Information', 'unilevel-mlm-pro');
            ?>
</strong></td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('Title', 'unilevel-mlm-pro');
            ?>
</td>
					<td><?php 
            _e('Details', 'unilevel-mlm-pro');
            ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('Name', 'unilevel-mlm-pro');
            ?>
</td>
					<td><?php 
            echo $user_info->first_name . ' ' . $user_info->last_name;
            ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('Address', 'unilevel-mlm-pro');
            ?>
</td>
					<td style="white-space:normal;"><?php 
            echo $user_info->user_address1 . "<br>" . $user_info->user_address2;
            ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('City', 'unilevel-mlm-pro');
            ?>
</td>
					<td><?php 
            echo $user_info->user_city;
            ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('Contact No', 'unilevel-mlm-pro');
            ?>
.</td>
					<td><?php 
            echo $user_info->user_telephone;
            ?>
</td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('DOB', 'unilevel-mlm-pro');
            ?>
</td>
					<td><?php 
            echo $user_info->user_dob;
            ?>
</td>
				  </tr>
				   
				  
				  <tr>
		<td><a href="?page=mlm-user-account&ac=edit" style="text-decoration: none"><?php 
            _e('Edit', 'unilevel-mlm-pro');
            ?>
</a></td>
		<td><a href="?page=mlm-user-account&ac=network" style="text-decoration: none"><?php 
            _e('View Genealogy', 'unilevel-mlm-pro');
            ?>
</a></td>
		</tr>
				</table>
					<table width="100%" border="0" cellspacing="10" cellpadding="1">
				  <tr>
					<td colspan="2"><strong><?php 
            _e('My Payouts', 'unilevel-mlm-pro');
            ?>
</strong></td>
				  </tr>
				  <tr>
					<td scope="row"><?php 
            _e('Date', 'unilevel-mlm-pro');
            ?>
</td>
					<td><?php 
            _e('Amount', 'unilevel-mlm-pro');
            ?>
</td>
       <td><?php 
            _e('Action', 'unilevel-mlm-pro');
            ?>
</td>
				  </tr>
<?php 
            $detailsArr = my_payout_function($_SESSION['userID']);
            //_e("<pre>");print_r($detailsArr); exit;
            //$page_id = get_post_id('mlm_my_payout_details_page');
            if (count($detailsArr) > 0) {
                $mlm_settings = get_option('wp_mlm_general_settings');
                ?>
			<?php 
                foreach ($detailsArr as $row) {
                    $amount = $row->commission_amount + $row->bonus_amount;
                    ?>
		<tr>
			<td><?php 
                    echo $row->payoutDate;
                    ?>
</td>
			<td><?php 
                    echo $mlm_settings['currency'] . ' ' . $amount;
                    ?>
</td>
			<td><a href="?page=mlm-user-account&ac=payout-details&pid=<?php 
                    echo $row->payout_id;
                    ?>
" style="text-decoration:none;"><?php 
                    _e('View', 'unilevel-mlm-pro');
                    ?>
</a></td>	
		</tr>
		<tr><td colspan="2"><a href="?page=mlm-user-account&ac=payout" style="text-decoration:none;"><?php 
                    _e('View All', 'unilevel-mlm-pro');
                    ?>
</a></td></tr>
		<?php 
                }
                ?>
	<?php 
            } else {
                ?>
	<div class="no-payout"> <?php 
                _e('You have not earned any commisssions yet.', 'unilevel-mlm-pro');
                ?>
 </div>
	
	<?php 
            }
            ?>
				</table>
			</td>
			<td width="40%">
				<table width="100%" border="0" cellspacing="10" cellpadding="1">
				  <tr>
					<td><strong><?php 
            _e('Network Details', 'unilevel-mlm-pro');
            ?>
</strong></td>
				  </tr>
				   

				 	<tr>
					<td>
						<table width="100%" border="0" cellspacing="10" cellpadding="1">
							<tr>
								<td colspan="2"><strong><?php 
            _e('Personal Sales', 'unilevel-mlm-pro');
            ?>
</strong></td>
							</tr>
							
							<tr>
								<td><?php 
            _e('My Personal Sales', 'unilevel-mlm-pro');
            ?>
: <?php 
            echo $personalSales;
            ?>
</td>
			<td>Active: <?php 
            echo $activePersonalSales;
            ?>
</td>
							</tr>
							<?php 
            foreach ($fivePersonalUsers as $key => $value) {
                _e("<tr>");
                foreach ($value as $k => $val) {
                    _e("<td>" . $val . "</td>");
                }
                _e("</tr>");
            }
            ?>
							<tr>
		<td colspan="2"><a href="?page=mlm-user-account&ac=personal" style="text-decoration: none"><?php 
            _e('View All', 'unilevel-mlm-pro');
            ?>
</a></td>
		</tr>
							
						</table>
					</td>
				  </tr> 
				  
				</table>
			</td>
		  </tr>
		</table>
		<?php 
        }
    }
    ?>
<!---sdfdsfsd ->


	</div>
<?php 
}
function mlm_update_profile($id = '')
{
    echo "<script>window.location='" . site_url() . "'</script>";
    // Echo count of items in menu
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    global $current_user;
    get_currentuserinfo();
    if ($id == '') {
        //$sponsor_name = $current_user->user_login;
        $userId = $current_user->ID;
        $class = '';
    } else {
        $userId = $id;
        $class = "class='button-primary'";
    }
    //most outer if condition
    if (isset($_POST['submit'])) {
        $firstname = sanitize_text_field($_POST['firstname']);
        $lastname = sanitize_text_field($_POST['lastname']);
        $address1 = sanitize_text_field($_POST['address1']);
        $address2 = sanitize_text_field($_POST['address2']);
        $city = sanitize_text_field($_POST['city']);
        $state = sanitize_text_field($_POST['state']);
        $postalcode = sanitize_text_field($_POST['postalcode']);
        $telephone = sanitize_text_field($_POST['telephone']);
        $dob = sanitize_text_field($_POST['dob']);
        if (checkInputField($firstname)) {
            $error .= "\n Please enter your first name.";
        }
        if (checkInputField($lastname)) {
            $error .= "\n Please enter your last name.";
        }
        if (checkInputField($address1)) {
            $error .= "\n Please enter your address.";
        }
        if (checkInputField($city)) {
            $error .= "\n Please enter your city.";
        }
        if (checkInputField($state)) {
            $error .= "\n Please enter your state.";
        }
        if (checkInputField($postalcode)) {
            $error .= "\n Please enter your postal code.";
        }
        if (checkInputField($telephone)) {
            $error .= "\n Please enter your contact number.";
        }
        if (checkInputField($dob)) {
            $error .= "\n Please enter your date of birth.";
        }
        // inner if condition
        if (empty($error)) {
            $user = array('ID' => $userId, 'first_name' => $firstname, 'last_name' => $lastname);
            // return the wp_users table inserted user's ID
            $user_id = wp_update_user($user);
            //get the selected country name from the country table
            $country = $_POST['country'];
            $sql = "SELECT name \n\t\t\t\t\t\tFROM {$table_prefix}mlm_country\n\t\t\t\t\t\tWHERE id = '" . $country . "'";
            $country1 = $wpdb->get_var($sql);
            //insert the registration form data into user_meta table
            update_user_meta($user_id, 'user_address1', $address1, FALSE);
            // I have replace FALSE to $unique
            update_user_meta($user_id, 'user_address2', $address2, FALSE);
            update_user_meta($user_id, 'user_city', $city, FALSE);
            update_user_meta($user_id, 'user_state', $state, FALSE);
            update_user_meta($user_id, 'user_country', $country1, FALSE);
            update_user_meta($user_id, 'user_postalcode', $postalcode, FALSE);
            update_user_meta($user_id, 'user_telephone', $telephone, FALSE);
            update_user_meta($user_id, 'user_dob', $dob, FALSE);
            $msg = "<span style='color:green;'>Congratulations! Profile has been successfully updated.</span>";
        }
        //end inner if condition
    }
    //end most outer if condition
    //if any error occoured
    if (!empty($error)) {
        $error = nl2br($error);
    }
    $user_info = get_userdata($userId);
    if (!empty($msg)) {
        _e($msg);
    }
    include 'js-validation-file.html';
    ?>

    <script type="text/javascript">
        var popup1, popup2, splofferpopup1;
        var bas_cal, dp_cal1, dp_cal2, ms_cal; // declare the calendars as global variables 
        window.onload = function() {
            dp_cal1 = new Epoch('dp_cal1', 'popup', document.getElementById('dob'));
        };
    </script>
    <span style='color:red;'><?php 
    echo $error;
    ?>
</span>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <form name="frm" method="post" action="" onSubmit="return updateFormValidation();">
            <tr>
                <td><?php 
    _e('First Name', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td><input type="text" name="firstname" id="firstname" value="<?php 
    echo $user_info->first_name;
    ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'firstname');" ></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('Last Name', 'binary-mlm-pro');
    ?>
<span style="color:red;">*</span> :</td>
                <td><input type="text" name="lastname" id="lastname" value="<?php 
    echo $user_info->last_name;
    ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'lastname');"></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('Address Line 1', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td><input type="text" name="address1" id="address1" value="<?php 
    echo $user_info->user_address1;
    ?>
"  size="37" onBlur="return allowspace(this.value, 'address1');"></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('Address Line 2', 'binary-mlm-pro');
    ?>
 :</td>
                <td><input type="text" name="address2" id="address2" value="<?php 
    echo $user_info->user_address2;
    ?>
"  size="37" onBlur="return allowspace(this.value, 'address2');"></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('City', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td><input type="text" name="city" id="city" value="<?php 
    echo $user_info->user_city;
    ?>
" maxlength="30" size="37" onBlur="return allowspace(this.value, 'city');"></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('State', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td><input type="text" name="state" id="state" value="<?php 
    echo $user_info->user_state;
    ?>
" maxlength="30" size="37" onBlur="return allowspace(this.value, 'state');"></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('Postal Code', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td><input type="text" name="postalcode" id="postalcode" value="<?php 
    echo $user_info->user_postalcode;
    ?>
" maxlength="20" size="37" onBlur="return numeric(this.value, 'postalcode');"></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('Country', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td>
                    <?php 
    $sql = "SELECT id, name\n\t\t\t\t\t\t\tFROM {$table_prefix}mlm_country\n\t\t\t\t\t\t\tORDER BY name";
    $rows = $wpdb->get_results($sql);
    ?>
                    <select name="country" id="country" >
                        <option value="">Select Country</option>
                        <?php 
    foreach ($rows as $row) {
        if ($user_info->user_country == $row->name) {
            $selected = 'selected';
        } else {
            $selected = '';
        }
        ?>
                            <option value="<?php 
        echo $row->id;
        ?>
" <?php 
        echo $selected;
        ?>
><?php 
        echo $row->name;
        ?>
</option>
                            <?php 
    }
    ?>
                    </select>
                </td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr><tr>

            <tr>
                <td><?php 
    _e('Contact No', 'binary-mlm-pro');
    ?>
. <span style="color:red;">*</span> :</td>
                <td><input type="text" name="telephone" id="telephone" value="<?php 
    echo $user_info->user_telephone;
    ?>
" maxlength="20" size="37" onBlur="return numeric(this.value, 'telephone');" ></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td><?php 
    _e('Date of Birth', 'binary-mlm-pro');
    ?>
 <span style="color:red;">*</span> :</td>
                <td><input type="text" name="dob" id="dob" value="<?php 
    echo $user_info->user_dob;
    ?>
" maxlength="20" size="22" ></td>
            </tr>

            <tr><td colspan="2">&nbsp;</td></tr>

            <tr>
                <td colspan="2"><input type="submit" name="submit" id="submit" value="Update" <?php 
    echo $class;
    ?>
 /></td>
            </tr>
        </form>
    </table>
    <?php 
}
Esempio n. 28
0
function join_network_page()
{
    global $wpdb, $current_user;
    $user_id = $current_user->ID;
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    global $current_user;
    get_currentuserinfo();
    if (!empty($_GET['sp_name'])) {
        $sp_name = $_GET['sp_name'];
        ?>
        <script>$.cookie('s_name', '<?php 
        echo $sp_name;
        ?>
', {path: '/'});</script>

        <?php 
        //setcookie("s_name", $sp_name);
    } else {
        if (!empty($_GET['sp'])) {
            $sp_name = getusernamebykey($_GET['sp']);
            ?>
        <script>$.cookie('s_name', '<?php 
            echo $sp_name;
            ?>
', {path: '/'});</script>

        <?php 
        } else {
            $sp_name = $_COOKIE["s_name"];
        }
    }
    /*     * ****date format ***** */
    $date_format = get_option('date_format');
    $time_format = get_option('time_format');
    /*     * ****** end******* */
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    $mlm_no_of_level = $mlm_general_settings['mlm-level'];
    $mlm_pay_settings = get_option('wp_mlm_payment_settings');
    $mlm_method = get_option('wp_mlm_payment_method');
    if (isset($_REQUEST['sp_name']) && $_REQUEST['sp_name'] != '') {
        //$sponsorName = getusernamebykey($_REQUEST['sp']);
        $sponsorName = $_REQUEST['sp_name'];
        if (isset($sponsorName) && $sponsorName != '') {
            $readonly_sponsor = 'readonly';
            $sponsor_name = $sponsorName;
        }
    } else {
        if (isset($_COOKIE["s_name"]) && $_COOKIE["s_name"] != '') {
            $readonly_sponsor = 'readonly';
            $sponsor_name = $_COOKIE["s_name"];
        } else {
            if (isset($_REQUEST['sp']) && $_REQUEST['sp'] != '') {
                //$sponsorName = getusernamebykey($_REQUEST['sp']);
                $sponsorName = getusernamebykey($_REQUEST['sp']);
                if (isset($sponsorName) && $sponsorName != '') {
                    $readonly_sponsor = 'readonly';
                    $sponsor_name = $sponsorName;
                }
            } else {
                $readonly_sponsor = '';
            }
        }
    }
    //most outer if condition
    if (isset($_POST['submit'])) {
        $sponsor = sanitize_text_field($_POST['sponsor']);
        if (empty($sponsor)) {
            $sponsor = $wpdb->get_var("select `username` FROM {$table_prefix}mlm_users order by id asc limit 1");
        }
        $firstname = sanitize_text_field($_POST['firstname']);
        $lastname = sanitize_text_field($_POST['lastname']);
        $email = sanitize_text_field($_POST['email']);
        /*         * ***** check for the epin field ***** */
        if (isset($_POST['epin']) && !empty($_POST['epin'])) {
            $epin = sanitize_text_field($_POST['epin']);
        } else {
            if (isset($_POST['epin']) && empty($_POST['epin'])) {
                $epin = '';
            }
        }
        /*         * ***** check for the epin field ***** */
        /* $address1 = sanitize_text_field( $_POST['address1'] );
                  $address2 = sanitize_text_field( $_POST['address2'] );
        
                  $city = sanitize_text_field( $_POST['city'] );
                  $state = sanitize_text_field( $_POST['state'] );
                  $postalcode = sanitize_text_field( $_POST['postalcode'] );
                  $telephone = sanitize_text_field( $_POST['telephone'] );
                  $dob = sanitize_text_field( $_POST['dob'] ); */
        //Add usernames we don't want used
        $invalid_usernames = array('admin');
        //Do username validation
        $sql = "SELECT COUNT(*) num, `user_key` \n\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\tWHERE `username` = '" . $sponsor . "'";
        //Case If User is not fill the Sponser field
        $intro = $wpdb->get_row($sql);
        if (checkInputField($firstname)) {
            $error .= "\n Please enter your first name.";
        }
        if (checkInputField($lastname)) {
            $error .= "\n Please enter your last name.";
        }
        if (checkInputField($email)) {
            $error .= "\n Please enter your email address.";
        }
        /*         * ***** check for the epin field ***** */
        if (isset($epin) && !empty($epin)) {
            if (epin_exists($epin)) {
                $error .= "\n ePin already issued or wrong ePin.";
            }
        }
        if ($mlm_general_settings['sol_payment'] == 1) {
            if (isset($_POST['epin']) && empty($_POST['epin'])) {
                $error .= "\n Please enter your ePin.";
            }
        }
        /*         * ***** check for the epin field ***** */
        /* if ( checkInputField($address1) ) 
                  $error .= "\n Please enter your address.";
        
                  if ( checkInputField($city) )
                  $error .= "\n Please enter your city.";
        
                  if ( checkInputField($state) )
                  $error .= "\n Please enter your state.";
        
                  if ( checkInputField($postalcode) )
                  $error .= "\n Please enter your postal code.";
        
                  if ( checkInputField($telephone) )
                  $error .= "\n Please enter your contact number.";
        
                  if ( checkInputField($dob) )
                  $error .= "\n Please enter your date of birth."; */
        //generate random numeric key for new user registration
        $user_key = generateKey();
        //if generated key is already exist in the DB then again re-generate key
        do {
            $check = $wpdb->get_var("SELECT COUNT(*) ck \n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `user_key` = '" . $user_key . "'");
            $flag = 1;
            if ($check == 1) {
                $user_key = generateKey();
                $flag = 0;
            }
        } while ($flag == 0);
        // outer if condition
        if (empty($error)) {
            // inner if condition
            if ($intro->num == 1) {
                $sponsor = $intro->user_key;
                $parent_key = $sponsor;
                // return the wp_users table inserted user's ID
                wp_update_user(array('ID' => $user_id, 'role' => 'mlm_user'));
                $username = $current_user->user_login;
                //get the selected country name from the country table
                $country = $_POST['country'];
                $sql = "SELECT name \n\t\t\t\t\t\tFROM {$table_prefix}mlm_country\n\t\t\t\t\t\tWHERE id = '" . $country . "'";
                $country1 = $wpdb->get_var($sql);
                //insert the registration form data into user_meta table
                $user = array('ID' => $user_id, 'first_name' => $firstname, 'last_name' => $lastname, 'user_email' => $email, 'role' => 'mlm_user');
                // return the wp_users table inserted user's ID
                $user_id = wp_update_user($user);
                /* add_user_meta( $user_id, 'user_address1', $address1, FALSE );  
                   add_user_meta( $user_id, 'user_address2', $address2, FALSE );
                   add_user_meta( $user_id, 'user_city', $city, FALSE );
                   add_user_meta( $user_id, 'user_state', $state, FALSE );
                   add_user_meta( $user_id, 'user_country', $country1, FALSE );
                   add_user_meta( $user_id, 'user_postalcode', $postalcode, FALSE );
                   add_user_meta( $user_id, 'user_telephone', $telephone, FALSE );
                   add_user_meta( $user_id, 'user_dob', $dob, FALSE); */
                //get the selected country name from the country table
                if (!empty($epin)) {
                    $pointResult = mysql_query("select point_status from {$table_prefix}mlm_epins where epin_no = '{$epin}'");
                    $pointStatus = mysql_fetch_row($pointResult);
                    // to epin point status 1
                    if ($pointStatus[0] == '1') {
                        $paymentStatus = '1';
                    } else {
                        if ($pointStatus[0] == '0') {
                            $paymentStatus = '2';
                        }
                    }
                } else {
                    // to non epin
                    $paymentStatus = '0';
                }
                //insert the data into fa_user table
                $insert = "INSERT INTO {$table_prefix}mlm_users\n\t\t\t\t\t\t   (\n\t\t\t\t\t\t\t\tuser_id, username, user_key, parent_key, sponsor_key, payment_status\n\t\t\t\t\t\t\t) \n\t\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t'" . $user_id . "','" . $username . "', '" . $user_key . "', '" . $parent_key . "', '" . $sponsor . "','" . $paymentStatus . "'\n\t\t\t\t\t\t\t)";
                $wpdb->query($insert);
                //hierarchy code for genology
                InsertHierarchy($user_key, $sponsor);
                if (isset($epin) && !empty($epin)) {
                    $sql = "update {$table_prefix}mlm_epins set user_key='{$user_key}', date_used=now(), status=1 where epin_no ='{$epin}' ";
                    // Update epin according user_key (19-07-2013)
                    mysql_query($sql);
                    if ($paymentStatus == 1) {
                        UserStatusUpdate($user_id);
                    }
                }
                $chk = '';
                $msg = "<span style='color:green;'>Congratulations! You have successfully Join MLM</span>";
                $check_paid = $wpdb->get_var("SELECT payment_status FROM {$table_prefix}mlm_users WHERE user_id = '" . $user_id . "'");
                if ($check_paid == '0') {
                    PayNowOptions($user_id, 'join_net');
                }
            } else {
                $error = "\n Sponsor does not exist in the system.";
            }
        }
        //end inner if condition
    }
    //end outer if condition
    // }
    //if any error occoured
    if (!empty($error)) {
        $error = nl2br($error);
    }
    if ($chk != '') {
        //include 'js-validation-file.html';
        ?>
        <script type="text/javascript">
            var popup1, popup2, splofferpopup1;
            var bas_cal, dp_cal1, dp_cal2, ms_cal; // declare the calendars as global variables 
            window.onload = function() {
                dp_cal1 = new Epoch('dp_cal1', 'popup', document.getElementById('dob'));
            };

            function checkReferrerAvailability(str)
            {
                if (isSpclChar(str, 'sponsor') == false)
                {
                    document.getElementById('sponsor').focus();
                    return false;
                }
                var xmlhttp;

                if (str != "") {

                    if (window.XMLHttpRequest)
                    {// code for IE7+, Firefox, Chrome, Opera, Safari
                        xmlhttp = new XMLHttpRequest();
                    }
                    else
                    {// code for IE6, IE5
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    xmlhttp.onreadystatechange = function()
                    {
                        if (xmlhttp.status == 200 && xmlhttp.readyState == 4)
                        {
                            document.getElementById("check_referrer").innerHTML = xmlhttp.responseText;
                        }
                    }
                    xmlhttp.open("GET", "<?php 
        echo MLM_PLUGIN_URL . 'ajax/check_username.php';
        ?>
" + "?action=sponsor&q=" + str, true);
                    xmlhttp.send();

                }
            }
        </script>		

        <?php 
        if ($current_user->roles[0] == 'mlm_user') {
            echo "Your are already a MLM user";
        } else {
            $fname = get_user_meta($user_id, 'first_name', true);
            $lname = get_user_meta($user_id, 'last_name', true);
            $u_email = $current_user->user_email;
            ?>
            <span style='color:red;'><?php 
            echo $error;
            ?>
</span>
            <?php 
            if (isset($msg) && $msg != "") {
                echo $msg;
            }
            ?>
	
            <form name="frm" method="post" action="" onSubmit="return JoinNetworkformValidation();">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">


                    <tr><td colspan="2">&nbsp;</td></tr>

                    <tr>
                        <td><?php 
            _e('First Name', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="firstname" id="firstname" value="<?php 
            if (!empty($fname)) {
                _e(htmlentities($fname));
            } elseif (!empty($_POST['firstname'])) {
                _e(htmlentities($_POST['firstname']));
            }
            ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'firstname');" ></td>
                    </tr>

                    <tr><td colspan="2">&nbsp;</td></tr>

                    <tr>
                        <td><?php 
            _e('Last Name', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="lastname" id="lastname" value="<?php 
            if (!empty($lname)) {
                _e(htmlentities($lname));
            } elseif (!empty($_POST['lastname'])) {
                _e(htmlentities($_POST['lastname']));
            }
            ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'lastname');"></td>
                    </tr>
                    <tr><td colspan="2">&nbsp;</td></tr>


                    <tr>
                        <td><?php 
            _e('Email', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="email" id="email" value="<?php 
            if (!empty($u_email)) {
                _e(htmlentities($u_email));
            } elseif (!empty($_POST['email'])) {
                _e(htmlentities($_POST['email']));
            }
            ?>
"  size="37" ></td>
                    </tr>

                    <tr><td colspan="2">&nbsp;</td></tr>

                    <tr>
            <?php 
            if (isset($sponsor_name) && $sponsor_name != '') {
                $spon = $sponsor_name;
            } else {
                if (isset($_POST['sponsor'])) {
                    $spon = htmlentities($_POST['sponsor']);
                }
            }
            ?>
                        <td><?php 
            _e('Sponsor Name', 'unilevel-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td>
                            <input type="text" name="sponsor" id="sponsor" value="<?php 
            if (!empty($spon)) {
                _e($spon);
            }
            ?>
" maxlength="20" size="37" onBlur="checkReferrerAvailability(this.value);" <?php 
            echo $readonly_sponsor;
            ?>
>
                            <br /><div id="check_referrer"></div>
                        </td>
                    </tr>
            <?php 
            if (isset($mlm_general_settings['ePin_activate']) && $mlm_general_settings['ePin_activate'] == '1' && isset($mlm_general_settings['sol_payment']) && $mlm_general_settings['sol_payment'] == '1') {
                ?>
                        <tr><td colspan="2">&nbsp;</td></tr>
                        <tr>
                            <td><?php 
                _e('Enter ePin', 'unilevel-mlm-pro');
                ?>
<span style="color:red;">*</span> :</td>
                            <td><input type="text" name="epin" id="epin" value="<?php 
                if (!empty($_POST['epin'])) {
                    _e(htmlentities($_POST['epin']));
                }
                ?>
" maxlength="20" size="37" onBlur="checkePinAvailability(this.value);"><br /><div id="check_epin"></div></td>
                        </tr>
            <?php 
            } else {
                if (isset($mlm_general_settings['ePin_activate']) && $mlm_general_settings['ePin_activate'] == '1') {
                    ?>
                        <tr><td colspan="2">&nbsp;</td></tr>
                        <tr>
                            <td><?php 
                    _e('Enter ePin', 'unilevel-mlm-pro');
                    ?>
 :</td>
                            <td><input type="text" name="epin" id="epin" value="<?php 
                    if (!empty($_POST['epin'])) {
                        _e(htmlentities($_POST['epin']));
                    }
                    ?>
" maxlength="20" size="37" onBlur="checkePinAvailability1(this.value);"><br /><div id="check_epin"></div></td>
                        </tr>
            <?php 
                }
            }
            ?>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submit" id="submit" value="<?php 
            _e('Submit', 'unilevel-mlm-pro');
            ?>
" /></td>
                    </tr>
                </table>
            </form>
            <?php 
        }
    } else {
        _e($msg);
    }
}
function mlm_epin_settings()
{
    global $wpdb;
    $table_prefix = mlm_core_get_table_prefix();
    $mlm_settings = get_option('wp_mlm_general_settings');
    $pro_price_settings = $wpdb->get_results("select * from {$table_prefix}mlm_product_price where p_id!='1'");
    if (isset($_POST['epin_save'])) {
        update_option('wp_mlm_epin_settings', $_POST);
        $epin_settings = get_option('wp_mlm_epin_settings');
        $epin_length = $mlm_settings['epin_length'];
        if ($_POST['epins_type'] == '1') {
            $type = 'regular';
        } else {
            $type = 'free';
        }
        $range = $epin_settings['number_of_epins'];
        $epins_type = $epin_settings['epins_type'];
        $epin_value = $epin_settings['epins_value'];
        for ($i = 0; $i <= $range - 1; $i++) {
            $epin_no = epin_genarate($epin_length);
            //if generated key is already exist in the DB then again re-generate key
            do {
                $check = $wpdb->get_var("SELECT COUNT(*) ck \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$table_prefix}mlm_epins \n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE `epin_no` = '" . $epin_no . "'");
                $flag = 1;
                if ($check == 1) {
                    $epin_no = epin_genarate($epin_length);
                    $flag = 0;
                }
            } while ($flag == 0);
            if ($type == 'regular') {
                $p_id = $_POST['epins_value'];
            } else {
                $p_id = 1;
            }
            $query = "insert into {$table_prefix}mlm_epins set epin_no='{$epin_no}',point_status='{$epins_type}',p_id='" . $p_id . "', date_generated=now();";
            mysql_query($query) or die(mysql_error());
            if ($i == $range - 1) {
                $message = 1;
            } else {
                $message = 0;
            }
        }
    } else {
        $epin_settings = get_option('wp_mlm_epin_settings');
    }
    ?>
    <script>

        function epinValidation()
        {
            var number_of_epins = document.getElementById("number_of_epins").value;
            if (number_of_epins == "")
            {
                alert('<?php 
    _e("The Number of ePins can not be empty. please Specify the ePins Number.", "unilevel-mlm-pro");
    ?>
');
                document.getElementById('number_of_epins').focus();
                return false;
            }
        }
        
       function epinType(val){
     
        if(val=='0')
        {
         document.getElementById("epins_value").disabled = true;  
        }
        else {
         document.getElementById("epins_value").disabled = false;   
        }
        
        }
        
    </script>
    <div class="wrap1">
        <h2><?php 
    _e("ePin Settings", "unilevel-mlm-pro");
    ?>
</h2>
        <div class="notibar msginfo">
            <a class="close"></a>
            <p><?php 
    _e('Use this tab to generate the ePins in your network which would be used for registering new members on the site. All ePins generated will be unique and the length shall be as specified in the General Tab.', 'unilevel-mlm-pro');
    ?>
</p>
            
            <p><strong><?php 
    _e('Type - Regular', 'unilevel-mlm-pro');
    ?>
</strong> - <?php 
    _e('A member registering with a Regular ePin shall be treated as a regular Paid member of the system. The commission for the member will be distributed amongst his upline and he will also earn commissions and bonuses from his downline.', 'unilevel-mlm-pro');
    ?>
</p>	

            <p><strong><?php 
    _e('Type - Free', 'unilevel-mlm-pro');
    ?>
</strong> - <?php 
    _e('A member registering with a Free ePin shall be treated as a Special Paid member of the system. The commission for the member will NOT be distributed amongst his upline (since he has not paid himself). However, he will earn commissions and bonuses from his downline (for regular paid members).', 'unilevel-mlm-pro');
    ?>
</p>	

<p><strong><?php 
    _e('ePin Value/Product', 'unilevel-mlm-pro');
    ?>
</strong> - <?php 
    _e('Select the Product with which this ePin will be mapped. A new user registering on the frontend will be deemed to have bought this product if he registers with an ePin generated in this lot. The commissions will also be distributed according to the value of the product.', 'unilevel-mlm-pro');
    ?>
</p>

<p><strong><?php 
    _e('No. of ePins', 'unilevel-mlm-pro');
    ?>
</strong> - <?php 
    _e('Specify the number of ePins to generate.', 'unilevel-mlm-pro');
    ?>
</p>

        </div>


        <div><?php 
    if (isset($message) && $message == 1) {
        ?>
<span style="color:#4F8A10;font-weight:bold;">
                    <?php 
        echo $epin_settings['number_of_epins'];
        ?>
 
                    <?php 
        _e('ePins of type ', 'unilevel-mlm-pro');
        ?>
                    <?php 
        if (isset($epin_settings['epins_type']) && $epin_settings['epins_type'] == '1') {
            echo 'Regular';
        } else {
            echo 'Free';
        }
        ?>
                <?php 
        _e(' have been generated successfully.', 'unilevel-mlm-pro');
        ?>

                    <br>
        <?php 
        _e('Click', 'unilevel-mlm-pro');
        ?>
&nbsp;<a href="<?php 
        echo admin_url() . "admin.php?page=admin-reports&tab=epinreports";
        ?>
"><?php 
        _e('<strong>Here</strong>', 'unilevel-mlm-pro');
        ?>
</a>&nbsp;
        <?php 
        _e('to go to the ePin Report to see the listing of generated ePins.', 'unilevel-mlm-pro');
        ?>
                </span>
    <?php 
    } else {
        if (isset($message) && $message == 0) {
            ?>
                <span style="color:#D8000C;"><?php 
            _e('There was an error in generating the ePins. Please try again.', 'unilevel-mlm-pro');
            ?>
</span><?php 
        }
    }
    ?>
</div>
        <div class="fileedit-sub">
            <div class="alignleft">
                <form method="post" action="#" id="form" onSubmit="return epinValidation();">
                    <table width="100%" border="0" cellspacing="4" cellpadding="4">



                        <tr>
                            <td><strong><?php 
    _e('Type', 'unilevel-mlm-pro');
    ?>
</strong></td>
                            <td>:&nbsp;</td>
                            <td>
    <?php 
    $selected = 'selected="selected"';
    ?>
                                <select name="epins_type" id="epins_type" onchange="epinType(this.value);">
                                    <option value="1" <?php 
    if (isset($_POST['epins_type']) && $_POST['epins_type'] == '1') {
        echo $selected;
    } else {
        echo '';
    }
    ?>
><?php 
    _e("Regular", "unilevel-mlm-pro");
    ?>
</option>
                                    <option value="0" <?php 
    if (isset($_POST['epins_type']) && $_POST['epins_type'] == '0') {
        echo $selected;
    } else {
        echo '';
    }
    ?>
><?php 
    _e("Free", "unilevel-mlm-pro");
    ?>
</option>
                                </select>
                            </td>
                            <td>&nbsp;</td>
                        </tr>

                        <tr>
                            <td><strong><?php 
    _e('ePin Value/Product', 'unilevel-mlm-pro');
    ?>
</strong></td>
                            <td>:&nbsp;</td>
                            <td><select name="epins_value" id="epins_value">
<?php 
    foreach ($pro_price_settings as $pricedetail) {
        ?>
       
<option value="<?php 
        echo $pricedetail->p_id;
        ?>
"><?php 
        echo $pricedetail->product_name . ' (' . $mlm_settings['currency'] . ' ' . $pricedetail->product_price . ')';
        ?>
</option>
<?php 
    }
    ?>
</select>
                            </td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td><strong><?php 
    _e('No. of ePins', 'unilevel-mlm-pro');
    ?>
</strong></td>
                            <td>:&nbsp;</td>
                            <td><input type="text" name="number_of_epins" id="number_of_epins" /></td>
                            <td>&nbsp;</td>
                        </tr>
                    </table>
                    <p class="submit">
                        <input type="submit" name="epin_save" value="<?php 
    _e('Generate ePins', 'unilevel-mlm-pro');
    ?>
"  class="button-primary" /></p>
                </form>
            </div>
        </div>
    </div>
    <?php 
}
function join_network()
{
    global $wpdb, $current_user;
    $user_id = $current_user->ID;
    $table_prefix = mlm_core_get_table_prefix();
    $error = '';
    $chk = 'error';
    if (!empty($_GET['sp_name'])) {
        $sp_name = $wpdb->get_var("select username from {$table_prefix}mlm_users where username='******'sp_name'] . "'");
        if ($sp_name) {
            ?>
            <script type='text/javascript'>
                $.cookie('sp_name', '<?php 
            echo $sp_name;
            ?>
', {path: '/'});
            </script>
            <?php 
        }
    } else {
        if (!empty($_REQUEST['sp'])) {
            $sp_name = $wpdb->get_var("select username from {$table_prefix}mlm_users where user_key='" . $_REQUEST['sp'] . "'");
            if ($sp_name) {
                ?>
            <script type='text/javascript'>
                $.cookie('sp_name', '<?php 
                echo $sp_name;
                ?>
', {path: '/'});
            </script>
            <?php 
            }
        } else {
            $sp_name = empty($_COOKIE["sp_name"]) ? '' : $_COOKIE["sp_name"];
        }
    }
    /*     * ****date format ***** */
    $date_format = get_option('date_format');
    $time_format = get_option('time_format');
    /*     * ****** end******* */
    global $current_user;
    get_currentuserinfo();
    $mlm_general_settings = get_option('wp_mlm_general_settings');
    if (isset($_REQUEST['sp']) && $_REQUEST['sp'] != '') {
        $sponsorName = getusernamebykey($_REQUEST['sp']);
        if (isset($sponsorName) && $sponsorName != '') {
            $readonly_sponsor = 'readonly';
            $sponsor_name = $sponsorName;
        } else {
            redirectPage(home_url(), array());
            exit;
        }
    } else {
        if (!empty($_REQUEST['sp_name'])) {
            $sponsorName = $_REQUEST['sp_name'];
            if (!empty($sponsorName)) {
                $readonly_sponsor = 'readonly';
                $sponsor_name = $sponsorName;
            } else {
                redirectPage(home_url(), array());
                exit;
            }
        } else {
            $readonly_sponsor = '';
        }
    }
    //most outer if condition
    if (isset($_POST['submit'])) {
        $firstname = sanitize_text_field($_POST['firstname']);
        $lastname = sanitize_text_field($_POST['lastname']);
        $email = sanitize_text_field($_POST['email']);
        $sponsor = sanitize_text_field($_POST['sponsor']);
        if (empty($sponsor)) {
            $sponsor = $wpdb->get_var("select `username` FROM {$table_prefix}mlm_users order by id asc limit 1");
        }
        if (checkInputField($firstname)) {
            $error .= "\n Please enter your first name.";
        }
        if (checkInputField($lastname)) {
            $error .= "\n Please enter your last name.";
        }
        if (!is_email($email)) {
            $error .= "\n E-mail address is invalid.";
        }
        //Add usernames we don't want used
        $invalid_usernames = array('admin');
        //Do username validation
        $sql = "SELECT COUNT(*) num, `user_key` \n\t\t\t\tFROM {$table_prefix}mlm_users \n\t\t\t\tWHERE `username` = '" . $sponsor . "'";
        $intro = $wpdb->get_row($sql);
        if (isset($_GET['l']) && $_GET['l'] != '') {
            $leg = $_GET['l'];
        } else {
            $leg = $_POST['leg'];
        }
        if (isset($leg) && $leg != '0') {
            if ($leg != '1') {
                $error .= "\n You have enter a wrong placement.";
            }
        }
        if (!isset($leg)) {
            $key = $wpdb->get_var("SELECT user_key FROM {$table_prefix}mlm_users WHERE user_id = '{$user_id}'");
            $l = totalLeftLegUsers($key);
            $r = totalRightLegUsers($key);
            if ($l < $r) {
                $leg = '0';
            } else {
                $leg = '1';
            }
        }
        //generate random numeric key for new user registration
        $user_key = generateKey();
        //if generated key is already exist in the DB then again re-generate key
        do {
            $check = $wpdb->get_var("SELECT COUNT(*) ck FROM {$table_prefix}mlm_users \n                                     WHERE `user_key` = '" . $user_key . "'");
            $flag = 1;
            if ($check == 1) {
                $user_key = generateKey();
                $flag = 0;
            }
        } while ($flag == 0);
        //check parent key exist or not
        if (isset($_GET['k']) && $_GET['k'] != '') {
            if (!checkKey($_GET['k'])) {
                $error .= "\n Parent key does't exist.";
            }
            // check if the user can be added at the current position
            $checkallow = checkallowed($_GET['k'], $leg);
            if ($checkallow >= 1) {
                $error .= "\n You have enter a wrong placement.";
            }
        }
        // outer if condition
        if (empty($error)) {
            // inner if condition
            if ($intro->num == 1) {
                $sponsor = $intro->user_key;
                $sponsor1 = $sponsor;
                //find parent key
                if (isset($_GET['k']) && $_GET['k'] != '') {
                    $parent_key = $_GET['k'];
                } else {
                    $readonly_sponsor = '';
                    do {
                        $sql = "SELECT `user_key` FROM {$table_prefix}mlm_users \n                                WHERE parent_key = '" . $sponsor1 . "' AND \n                                leg = '" . $leg . "' AND banned = '0'";
                        $spon = $wpdb->get_var($sql);
                        $num = $wpdb->num_rows;
                        if ($num) {
                            $sponsor1 = $spon;
                        }
                    } while ($num == 1);
                    $parent_key = $sponsor1;
                }
                // return the wp_users table inserted user's ID
                $user = array('ID' => $user_id, 'first_name' => $firstname, 'last_name' => $lastname, 'user_email' => $email, 'role' => 'mlm_user');
                // return the wp_users table inserted user's ID
                $user_id = wp_update_user($user);
                $username = $current_user->user_login;
                //get the selected country name from the country table
                /* Send e-mail to admin and new user - 
                   You could create your own e-mail instead of using this function */
                /**                 * ****** product Price set *************** */
                if (!empty($mlm_general_settings['product_price'])) {
                    $pc = $mlm_general_settings['product_price'];
                } else {
                    $pc = '0';
                }
                //insert the data into fa_user table
                if (!empty($epin)) {
                    $pointStatus = $wpdb->get_row("select point_status from {$table_prefix}mlm_epins where epin_no = '{$epin}'", ARRAY_N);
                    // to epin point status 1
                    if ($pointStatus[0] == '1') {
                        $paymentStatus = '1';
                        $product_price = $pc;
                    } else {
                        if ($pointStatus[0] == '0') {
                            $paymentStatus = '2';
                            $product_price = '0';
                        }
                    }
                } else {
                    // to non epin
                    $paymentStatus = '0';
                    $product_price = '0';
                }
                $insert = "INSERT INTO {$table_prefix}mlm_users(\n\t\t\tuser_id, username, user_key, parent_key, sponsor_key, leg,payment_status,product_price) \n\t\t\tVALUES(\n\t\t\t'" . $user_id . "','" . $username . "', '" . $user_key . "', '" . $parent_key . "', '" . $sponsor . "', '" . $leg . "','" . $paymentStatus . "','" . $product_price . "')";
                // if all data successfully inserted
                if ($wpdb->query($insert)) {
                    //begin most inner if condition
                    //entry on Left and Right Leg tables
                    if ($leg == 0) {
                        $insert = "INSERT INTO {$table_prefix}mlm_leftleg  (pkey, ukey) \n\t\t\t\tVALUES ('" . $parent_key . "','" . $user_key . "')";
                        $insert = $wpdb->query($insert);
                    } else {
                        if ($leg == 1) {
                            $insert = "INSERT INTO {$table_prefix}mlm_rightleg(pkey, ukey) \n\t\t\t\tVALUES('" . $parent_key . "','" . $user_key . "')";
                            $insert = $wpdb->query($insert);
                        }
                    }
                    //begin while loop
                    while ($parent_key != '0') {
                        $query = "SELECT COUNT(*) num, parent_key, leg \n                                FROM {$table_prefix}mlm_users \n                                WHERE user_key = '" . $parent_key . "'\n                                AND banned = '0'";
                        $result = $wpdb->get_row($query);
                        if ($result->num == 1) {
                            if ($result->parent_key != '0') {
                                if ($result->leg == 1) {
                                    $tbright = "INSERT INTO {$table_prefix}mlm_rightleg (pkey,ukey) \n\t\t\t\t\t\tVALUES('" . $result->parent_key . "','" . $user_key . "')";
                                    $tbright = $wpdb->query($tbright);
                                } else {
                                    $tbleft = "INSERT INTO {$table_prefix}mlm_leftleg (pkey, ukey) \n\t\t\t\t\t\tVALUES('" . $result->parent_key . "','" . $user_key . "')";
                                    $tbleft = $wpdb->query($tbleft);
                                }
                            }
                            $parent_key = $result->parent_key;
                        } else {
                            $parent_key = '0';
                        }
                    }
                    //end while loop
                    if (isset($epin) && !empty($epin)) {
                        $sql = "update {$table_prefix}mlm_epins set user_key='{$user_key}', date_used=now(), status=1 where epin_no ='{$epin}' ";
                        // Update epin according user_key (19-07-2013)
                        $wpdb->query($sql);
                        if ($paymentStatus == 1) {
                            insert_refferal_commision($user_id, $sponsor, $user_key);
                        }
                    }
                    $chk = '';
                    $msg = "<span style='color:green;'>Congratulations! You have successfully Join MLM</span>";
                }
                //end most inner if condition
            } else {
                $error = "\n Sponsor does not exist in the system.";
            }
        }
        //end outer if condition
    }
    //end most outer if condition
    //if any error occoured
    if (!empty($error)) {
        $error = nl2br($error);
    }
    if ($chk != '') {
        include 'js-validation-file.html';
        ?>
        <?php 
        if ($current_user->roles[0] == 'mlm_user') {
            echo "Your are MLM user";
        } else {
            $_POST['firstname'] = get_user_meta($user_id, 'first_name', true);
            $_POST['lastname'] = get_user_meta($user_id, 'last_name', true);
            $_POST['email'] = $current_user->user_email;
            ?>
            <script>
                function checkspname() {
                    var spname = document.getElementById('sponsor').value;
                    if (spname == '') {
                        if (!confirm('Are you sure you do not know your Sponsor\'s username? Proceed without a Sponsor?')) {
                            return false;
                        }
                    }
                }
            </script>
            <span style='color:red;'><?php 
            echo $error;
            ?>
</span>
            <?php 
            if (isset($msg) && $msg != "") {
                echo $msg;
            }
            ?>
            <form name="frm" method="post" action="" onSubmit="checkspname()">			
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr><td colspan="2">&nbsp;</td></tr>

                    <tr>
                        <td><?php 
            _e('First Name', 'binary-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="firstname" id="firstname" value="<?php 
            if (!empty($_POST['firstname'])) {
                _e(htmlentities($_POST['firstname']));
            }
            ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'firstname');" ></td>
                    </tr>

                    <tr><td colspan="2">&nbsp;</td></tr>

                    <tr>
                        <td><?php 
            _e('Last Name', 'binary-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="lastname" id="lastname" value="<?php 
            if (!empty($_POST['lastname'])) {
                _e(htmlentities($_POST['lastname']));
            }
            ?>
" maxlength="20" size="37" onBlur="return checkname(this.value, 'lastname');"></td>
                    </tr>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td><?php 
            _e('Email Address', 'binary-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><input type="text" name="email" id="email" value="<?php 
            if (!empty($_POST['email'])) {
                _e(htmlentities($_POST['email']));
            }
            ?>
"  size="37" ></td>
                    </tr>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td><?php 
            _e('Sponsor Name', 'binary-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td>
                            <input type="text" name="sponsor" id="sponsor" value="<?php 
            if (!empty($_POST['sponsor'])) {
                _e(htmlentities($_POST['sponsor']));
            }
            ?>
" maxlength="20" size="37" onkeyup="checkReferrerAvailability12(this.value);">
                            <br /><div id="check_referrer"></div>
                        </td>
                    </tr>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td><?php 
            _e('Placement', 'binary-mlm-pro');
            ?>
 <span style="color:red;">*</span> :</td>
                        <td><?php 
            echo __('Left', 'binary-mlm-pro');
            ?>
 <input id="left" type="radio" name="leg" value="0" <?php 
            echo isset($led) && $leg == '0' ? 'checked="checked"' : '';
            ?>
 />
                            <?php 
            echo __('Right', 'binary-mlm-pro');
            ?>
<input id="right" type="radio" name="leg" value="1" <?php 
            echo isset($led) && $leg == '0' ? 'checked="checked"' : '';
            ?>
/>
                        </td>

                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submit" id="submit" value="<?php 
            _e('Submit', 'binary-mlm-pro');
            ?>
" /></td>
                    </tr>
                </table>
            </form>
            <?php 
        }
        ?>
	
        <?php 
    } else {
        _e($msg);
    }
}