
<?php   
    //echo "Hello";
    //echo md5('admin');
    ini_set("display_errors", 0);
    //error_reporting(E_ALL);
    date_default_timezone_set('Africa/Lagos');
    session_start();

    include $_SERVER['DOCUMENT_ROOT'] . "/dbase/dbaseconnection.php";
    include $_SERVER['DOCUMENT_ROOT'] . "/functions/functions.php";
    include $_SERVER['DOCUMENT_ROOT'] . "/functions/mlmfunctions.php";
    include $_SERVER['DOCUMENT_ROOT'] . "/scripts/arraylist.php";

    if(!isset($_SESSION['logged'])){
        header('Location: /login.php?redirect=' . $_SERVER['PHP_SELF']);
    }else{
        $userid=$_SESSION['userid'];
        $username=$_SESSION['username'];
        $sql="SELECT * FROM mlmmembers WHERE userid=$userid";
        $result=mysql_query($sql) or die(mysql_error());
        if($result){
            $rows=mysql_fetch_array($result);
            $fullname=$rows['lastname'] . ", " . $rows['firstname'];
            $passport=$rows['passport'];
            $country=$rows['country'];
            //$status=$_SESSION['status']=$rows['status'];
            $emailaddress=$rows['emailaddress'];
            $phoneno=$rows['phoneno'];
            $profileid=$_SESSION['profileid']=$rows['profileid'];
            $userid=$_SESSION['userid']=$rows['userid'];
            $parentid=$_SESSION['parentid']=$rows['parentid'];
        }
    }
    //computematrixbonus($profileid); 
?>

<!DOCTYPE html>

<html lang="en">

    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <title>MLMPro | Multi-Level Marketing</title>
       
        <link href="/css/jquery.dataTables.css" rel="stylesheet" type="text/css"/>
        <link href="/jquery-ui/jquery-ui.min.css" rel="stylesheet" type="text/css"/>
        <link href="/icofont/css/icofont.css" rel="stylesheet" type="text/css"/>
        <!--<link rel="stylesheet" href="/css/bootstrap.min.css"/>-->
        <link rel="stylesheet" href="/css/jquery.jOrgChart.css"/>
        <!--<link rel="stylesheet" href="/css/custom.css"/>-->
        <link href="/css/styles.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            #chart_div table {width: 960px;}
      #chart_div img {width: 50px; height: auto;border-radius: 50%;}
      .google-visualization-orgchart-node {width: 130px;box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5) !important; background-color: #edf7ff !important; background: -webkit-gradient(linear, left top, left bottom, from(#edf7ff), to(#cde7ee)) !important; background: -moz-linear-gradient(top, #edf7ff, #cde7ee) !important;

        </style>           

    </head>

    <body id="home"> 
        <div id="bodycontainer" style="overflow-x: hidden; min-height: 100%;overflow-y: auto;position: relative;">
             <div id="mainmenu" style="display: block;">
               <h2>MLMPro</h2>
               <div id="leftprofilecontainer">
                    <div class="profileimage"><?php echo "<img src='/passports/$passport' alt=''>"?></div>
                    <div class="username"><?php echo $fullname;?></div> 
                </div><!--leftprofilecontainer-->
                <div id="leftmenu">
                    <div id="leftnavigation">
                        <?php include $_SERVER['DOCUMENT_ROOT'] . "/includes/membersmenu.inc.php";?>
                    </div>

                </div><!--leftmenu-->
            </div><!--mainmenu menu-->
            <div id="maincontent" style="/*width: 100%*/;">
                <div id="header">
                    <div style="float: left;margin-left: 10px;" id="toggleMenu"><span></span></div>
                    <ul id="profilenav">
                        <li class="profileimage"><?php echo "<img src='/passports/$passport' alt=''>"?></li>
                        <li class="username"><?php echo $fullname;?></li>
                    </ul>                
                </div>

                <div class="spacer"></div>
                <div id="innercontent" style='overflow: scroll;'>
                    <?php

                        $section=isset($_GET['section'])?$_GET['section']:'';
                        /*if($status==0){
                            # activation
                            //$section='';
                            echo "<h2>Profile Activation</h2>";
                            $activationErr='';
                            echo "<p>Your profile is not yet active. Please, check the email address/phone number you provided when registering for the activation code to activate your account.</p><!--<p>If you do not receive any activation code click <a href='/?section=resend'> resend activation code</a></p>-->";
                            if(isset($_POST['submit']) && $_POST['submit']=='Activate'){
                                //retrieve and validate variables
                                $activationcode=isset($_POST['activationcode'])?trim($_POST['activationcode']):'0';
                                $sql="SELECT * FROM mlmmembers WHERE username='" . $username . "' AND userid=" . $userid . " AND activationcode=" . $activationcode;
                                $result=mysql_query($sql) or die(mysql_error());
                                if(mysql_num_rows($result)>=1){
                                    mysql_query("UPDATE mlmmembers SET status=1 WHERE userid=$userid AND username='$username'");                                    header("Location: /index.php?section=dashboard");
                                }else{
                                    include $_SERVER['DOCUMENT_ROOT'] . "/includes/activationform.inc.php";
                                    echo "<p style='color:red;margin-left:140px;'>Invalid Activation code entered</p>";
                                }
                            }else{
                                include $_SERVER['DOCUMENT_ROOT'] . "/includes/activationform.inc.php";
                            }
                        }*/

                        if($section=='dashboard' || $section==''){
                            //dashboard

                            echo "<h2>Dashboard</h2>";
                            ?>
                                <section class="dashboard">
                                    <div class="item" style="border: 1px solid #ddd;text-align: center;margin-bottom: 24px;margin-left: 10px;">
                                        <div style="background: royalblue;"><?php echo "<img src='/passports/$passport' alt='' style='width: 100px;height: 100px;border-radius: 50%;padding:10px;margin-bottom:48px;'>"?></div>
                                        <div><p style="margin-bottom: 0;font-weight: bold;margin-top: 24px;"><?php echo $fullname;?></p></div>
                                        <div><p style="margin-bottom: 0;font-weight: bold;">Username: <span style="font-weight: normal;"><?php echo $username;?></span></p></div>
                                        <div><p style="margin-bottom: 0;font-weight: bold;">Country: <span style="font-weight: normal;"><?php echo $country;?></span></p></div>
                                        <div><p style="margin-bottom: 0;font-weight: bold;">eMail: <span style="font-weight: normal;"><?php echo $emailaddress;?></span></p></div>                                        
                                        <div><p style="margin-bottom: 0;font-weight: bold;">Phone: <span style="font-weight: normal;"><?php echo $phoneno;?></span></p></div>
                                        <div><p style="margin-bottom: 0;font-weight: bold;">Member ID: <span style="font-weight: normal;"><?php echo $profileid;?></span></p></div> 
                                    </div><!--myprofile-->
                                    <figure>
                                        <div class="item orange">
                                            <p class="value"><?php echo '$' . memberwallet($userid);?></p>
                                            <div class="caption"><a href="/?section=transactions"><p>e-Wallet Balance</p></a></div>
                                        </div>
                                    </figure>
                                    <figure>
                                        <div class="item emerland">
                                            <p class="value"><?php echo '$'. purchases($userid);?></p>
                                            <div class="caption"><p>Purchases</p></div>
                                        </div>
                                    </figure>
                                    <!--<figure>
                                        <div class="item pumpkin">
                                            <p>NA</p>
                                            <div class="caption"><p>Stage Completion Bonus</p></div>
                                        </div>
                                    </figure>-->
                                    <figure>
                                        <div class="item concrete">
                                            <p><span style="display:block;"></span><?php echo directmembers($profileid);?></p>
                                            <div class="caption"><a href="/?section=genealogy"><p>Direct Members</p></a></div>
                                        </div>
                                    </figure>
                                    <figure>
                                        <div class="item purple">
                                            <p><span style="display:block;"></span><?php echo countall($userid);?></p>
                                            <div class="caption"><p>Total Downlines</p></div>
                                        </div>
                                    </figure>
                                    <figure>
                                        <div class="item pomegranate">
                                            <p><?php echo getpinbalance($username);?></p>
                                            <div class="caption"><a href="/?section=viewepins"><p>Unused e-Pins</p></a></div>
                                        </div>
                                    </figure>
                                    <figure>
                                        <div class="item nightgale">
                                            <p><?php echo currentstage($userid);?></p>
                                            <div class="caption"><p>Current Stage</p></div>
                                        </div>
                                    </figure>
                                    <figure>
                                        <div class="item greensea">
                                            <p><?php echo gettickets($emailaddress);?></p>
                                            <div class="caption"><a href="/?section=listmail"><p>Messages/Tickets</p></a></div>
                                        </div>
                                    </figure>
                                </section>
                            <?php
                        }elseif ($section=='resend') {
                             echo "<h2>Profile Activation</h2><p>Kindly enter the email address provided during registration</p>";


                        }elseif($section=='personal' || $section=='changepassword' || $section=='bankinfo' || $section=='uploadprofilepix' || $section=='changetranspassword'){
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/personal.mod.php";
                        }elseif($section=='transactions' || $section=='ewalletdebit' || $section=='ewalletbalance' || $section=='withdrawalrequest' || $section=='fundaccount' || $section=='transferfund' || $section=='logintoewallet' || $section=='endsession' || $section=='withdrawalstatus' || $section=='managewallet'){
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/manageewallet.php";   
                        }elseif($section=='sendmail' || $section=='listmail' || $section=='sentitems' || $section=='read' || $section=='supportticket' ){
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/mailmanagement.php";
                        }elseif($section=='referralurl' || $section=='viewinvitations'){
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/referral.php";
                        }elseif ($section=='genealogy' || $section=='downline' || $section=='teamview') {
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/networkmanagement.php";
                        }elseif ($section=='generatepin' || $section=='viewepins') {
                            # code...
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/membersepins.php";
                        }elseif ($section=='addnewmember') {
                            # code...
                            include $_SERVER['DOCUMENT_ROOT'] . "/modules/membermanagement.php";
                        }
                        ?>
                    <div class="spacer"></div>

                </div><!--content-->
                <div class="spacer"></div>
            </div><!--maincontent-->
        </div>

        <script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="/jquery-ui/jquery-ui.min.js"></script>
        <script type="text/javascript" src="/js/jquery.dataTables.min.js"></script>
        <script type="text/javascript" src="/js/jquery.jOrgChart.js"></script>
        <script type="text/javascript" src='/js/mlm.js'> </script>
        
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript">
          google.charts.load('current', {packages:["orgchart"]});
          google.charts.setOnLoadCallback(drawChart);

          function drawChart() {
            $.ajax({
              type:"GET",
              url:"/modules/getdata.php",
              data:{},
              contentType:'application/json',
              dataType:"json",
              success:function(JSONObject){
                var data = new google.visualization.DataTable();
                data.addColumn('string', 'Name');
                data.addColumn('string', 'Parent');
                data.addColumn('string', 'ToolTip');

                for(var key in JSONObject){
                  var userid=JSONObject[key]['userid'].toString();
                  var username=JSONObject[key]['username'];
                  var parentid=JSONObject[key]['parentid'];
                  var passport=JSONObject[key]['passport'];
                  var stage=JSONObject[key]['currentstage'];
                  var profileid=JSONObject[key]['profileid'];
                  //console.write('username');
                  data.addRows([[{v:userid, f:username+'<div><img src="passports/'+passport+'"/><p><p>'+profileid+'</p>'+stage+'</div>'},parentid,userid]]);
                }
                $('.google-visualization-orgchart-table').css({'width':'960px'});
                var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
                var options = {'allowHtml':'true','allowCollapse':'true','title':'Genealogy Tree'};
                chart.draw(data, options);
                
                for (var i = 1; i < data.getNumberOfRows(); i++) {
                  //chart.collapse(i, true);
                }
              }
            });
          }

          $(".genealogy").on("click", function(){
            //alert("New Genealogy");
            drawchart();
          });
        </script>
    </body>
</html>



