<?php
session_start();
$key = md5(date("Y-m-d").":".$_SERVER['REMOTE_ADDR']);
if (isset($_SESSION['aW1iZXN0cmEuY29tLm15']) <> $key) {
    header("location:".$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME']); // cara baru !
} else {
    include "_headerg.php";
    include "_navtop.php";
    include "_navside.php";
    include "_functions.php";
    require "conn.php";   
    
?>
        <div id="page-wrapper" >
            <div id="page-inner">
                <div class="row">
                    <div class="col-md-12" style="vertical-align: middle;">
                        <div class="col-md-6" style="display: inline-block; vertical-align: middle;">
                            <h2>Genealogy</h2> 
                        </div>
                                <? if ($_SESSION['username'] == "admin") { ?>
<br/>
                                <div class="col-md-6 "  style="display: inline-block; vertical-align: middle;">
                                     <form role="form" method="post">
                                        <div class="input-group">
                                            <input type="text" name="u" class="form-control" placeholder="username" />
                                            <span class="form-group input-group-btn">
                                                <button class="btn btn-default" type="submit" name="<?= sha1($_SERVER['REMOTE_ADDR']) ?>"> Search </button>
                                            </span>
                                        </div>
                                     </form>
                                </div>                            


<? } ?>

                    </div>
                    
                </div>
            <hr />




			<div class="row">
                <div class="col-md-12">
                    <!-- Form Elements -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
<?
if (isset($_POST[sha1($_SERVER['REMOTE_ADDR'])])) {
    $uuu = mysqli_real_escape_string($con, $_POST['u']);

    $sql = "SELECT id FROM ahli WHERE username = '".$uuu."' LIMIT 1";
    $count = mysqli_num_rows(mysqli_query($con, $sql));

    if ($count == 1) {
        $uuid = mysqli_fetch_array(mysqli_query($con, $sql));

        $usr = $uuu;
        $sid = $uuid[0];

    } else {
        $usr = "Result";
        $blank = "&nbsp;&nbsp;<code>Username not found !</code>";
    } 

} else {

    $usr = $_SESSION['username'];
    $sid = $_SESSION['aidi'];
    $blank = "";

}
?>                            
                            <?= $usr ?>
                        </div>
                        <div class="panel-body" style="margin-left:-30px;">
                            <div class="col-md-12">
                            <div class="tree-container">
<?= $blank ?>                                
<ul id="treemenu1" class="treeview"  >
<?php

$ssql = "select * from ahli where penaja='".$sid."' order by id";
$result = mysqli_query($con, $ssql);
$num = mysqli_num_rows($result);
$i = 0;
while ($i < $num) {



    //if (mysqli_result($result, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
    //$strText = "<h3>LEVEL 1 </h3><b>" . mysqli_result($result, $i, "nama") . "</b> 
    $strText = "<span style='display: block;'>" . mysqli_result($result, $i, "nama") . "</span>
                <span style='display: block;'>Members: <code>" . mysqli_result($result, $i, "username") . "</code></span>
                <span style='display: block;'>Join on: <code>" . mysqli_result($result, $i, "tarikh")."</code></span>";
    echo "<li>
        <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>

                <div class='col-md-12'>
                    <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                        <img class='img-thumbnail img-circle'src='assets/img/level1.png'/>
                        <h6><code> Level 1 </code></h6>
                    </div>
                    <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                </div>
          
        </div>";
   

//2nd level
    $ssql = "select * from ahli where penaja='" . mysqli_result($result, $i, "id") . "' order by id";
    $result2 = mysqli_query($con, $ssql);
    $num2 = mysqli_num_rows($result2);
    if ($num2 > 0) {
        echo "<ul class='treeview'>";
    }
    $j = 0;
    while ($j < $num2) {
        //if (mysqli_result($result2, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
        //$strText = "[2] <b>" . mysqli_result($result2, $j, "nama") . "</b> - <code>" . mysqli_result($result2, $j, "username") . "</code> - " . mysqli_result($result2, $j, "tarikh");
        $strText = "<span style='display: block;'>" . mysqli_result($result2, $j, "nama") . "</span>
                    <span style='display: block;'>Members: <code>" . mysqli_result($result2, $j, "username") . "</code></span>
                    <span style='display: block;'>Join on: <code>" . mysqli_result($result2, $j, "tarikh")."</code></span>";
        echo "<li> 
            <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>
    
                    <div class=' col-md-12'>
                        <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                            <img class='img-thumbnail  img-circle' src='assets/img/level2.png'/>
                            <h6><code> Level 2 </code></h6>
                        </div>
                        <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                    </div>
              
            </div>";
        

//3rd level
        $ssql = "select * from ahli where penaja='" . mysqli_result($result2, $j, "id") . "' order by id";
        $result3 = mysqli_query($con, $ssql);
        $num3 = mysqli_num_rows($result3);
        $k = 0;
        if ($num3 > 0) {
            echo "<ul class='treeview'>";
        }
        while ($k < $num3) {
            //if (mysqli_result($result3, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
            //$strText = "[3] <b>" . mysqli_result($result3, $k, "nama") . "</b> - <code>" . mysqli_result($result3, $k, "username") . "</code> - " . mysqli_result($result3, $k, "tarikh");
            $strText = "<span style='display: block;'>" . mysqli_result($result3, $k, "nama") . "</span>
                        <span style='display: block;'>Members: <code>" . mysqli_result($result3, $k, "username") . "</code></span>
                        <span style='display: block;'>Join on: <code>" . mysqli_result($result3, $k, "tarikh")."</code></span>";
            echo "<li> 
                <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>
        
                        <div class=' col-md-12'>
                            <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                                <img class='img-thumbnail img-circle' src='assets/img/level3.png'/>
                                <h6><code> Level 3 </code></h6>
                            </div>
                            <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                        </div>
                  
                </div>";
        




//4th level
            $ssql = "select * from ahli where penaja='" . mysqli_result($result3, $k, "id") . "' order by id";
            $result4 = mysqli_query($con, $ssql);
            $num4 = mysqli_num_rows($result4);
            $l = 0;
            if ($num4 > 0) {
                echo "<ul class='treeview'>";
            }
            while ($l < $num4) {
                //if (mysqli_result($result4, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
                //$strText = "[4] <b>" . mysqli_result($result4, $l, "nama") . "</b> - <code>" . mysqli_result($result4, $l, "username") . "</code> - " . mysqli_result($result4, $l, "tarikh");
                $strText = "<span style='display: block;'>" . mysqli_result($result4, $l, "nama") . "</span>
                            <span style='display: block;'>Members: <code>" . mysqli_result($result4, $l, "username") . "</code></span>
                            <span style='display: block;'>Join on: <code>" . mysqli_result($result4, $l, "tarikh")."</code></span>";
                echo "<li> 
                    <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>
            
                            <div class=' col-md-12'>
                                <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                                    <img class='img-thumbnail img-circle' src='assets/img/level4.png'/>
                                    <h6><code> Level 4 </code></h6>
                                </div>
                                <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                            </div>
                      
                    </div>";



//5th level
                $ssql = "select * from ahli where penaja='" . mysqli_result($result4, $l, "id") . "' order by id";
                $result5 = mysqli_query($con, $ssql);
                $num5 = mysqli_num_rows($result5);
                $m = 0;
                if ($num5 > 0) {
                    echo "<ul class='treeview'>";
                }
                while ($m < $num5) {
                    //if (mysqli_result($result5, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
                    //$strText = "[5] <b>" . mysqli_result($result5, $m, "nama") . "</b> - <code>" . mysqli_result($result5, $m, "username") . "</code> - " . mysqli_result($result5, $m, "tarikh");
                    $strText = "<span style='display: block;'>" . mysqli_result($result5, $m, "nama") . "</span>
                                <span style='display: block;'>Members: <code>" . mysqli_result($result5, $m, "username") . "</code></span>
                                <span style='display: block;'>Join on: <code>" . mysqli_result($result5, $m, "tarikh")."</code></span>";
                    echo "<li> 
                        <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>
                
                                <div class=' col-md-12'>
                                    <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                                        <img class='img-thumbnail img-circle' src='assets/img/level5.png'/>
                                        <h6><code> Level 5 </code></h6>
                                    </div>
                                    <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                                </div>
                          
                        </div>";

        




                
//6th level
                    $ssql = "select * from ahli where penaja='" . mysqli_result($result5, $m, "id") . "' order by id";
                    $result6 = mysqli_query($con, $ssql);
                    $num6= mysqli_num_rows($result6);
                    $n = 0;
                    if ($num6 > 0) {
                        echo "<ul class='treeview'>";
                    }
                    while ($n < $num6) {
                        //if (mysqli_result($result6, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
                        //$strText = "[6] <b>" . mysqli_result($result6, $n, "nama") . "</b> - <code>" . mysqli_result($result6, $n, "username") . "</code> - " . mysqli_result($result6, $n, "tarikh");
                         $strText = "<span style='display: block;'>" . mysqli_result($result6, $n, "nama") . "</span>
                                    <span style='display: block;'>Members: <code>" . mysqli_result($result6, $n, "username") . "</code></span>
                                    <span style='display: block;'>Join on: <code>" . mysqli_result($result6, $n, "tarikh")."</code></span>";
                        echo "<li> 
                            <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>
                    
                                    <div class=' col-md-12'>
                                        <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                                            <img class='img-thumbnail img-circle' src='assets/img/level6.png'/>
                                            <h6><code> Level 6 </code></h6>
                                        </div>
                                        <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                                    </div>
                              
                            </div>";

        




                
//7th level
                        $ssql = "select * from ahli where penaja='" . mysqli_result($result6, $n, "id") . "' order by id";
                        $result7 = mysqli_query($con, $ssql);
                        $num7= mysqli_num_rows($result7);
                        $o = 0;
                        if ($num7 > 0) {
                            echo "<ul class='treeview'>";
                        }
                        while ($o < $num7) {
                            //if (mysqli_result($result7, $i, "pakej") == 0) { $color = "#FF0000"; } else { $color = "#6B0000"; }
                            //$strText = "[7] <b>" . mysqli_result($result7, $o, "nama") . "</b> - <code>" . mysqli_result($result7, $o, "username") . "</code> - " . mysqli_result($result7, $o, "tarikh");
                            $strText = "<span style='display: block;'>" . mysqli_result($result7, $o, "nama") . "</span>
                                        <span style='display: block;'>Members: <code>" . mysqli_result($result7, $o, "username") . "</code></span>
                                        <span style='display: block;'>Join on: <code>" . mysqli_result($result7, $o, "tarikh")."</code></span>";
                            echo "<li> 
                                <div class='row ' style='margin-bottom: 15px; padding-top:10px; border-bottom: 1px solid rgba(0, 0, 0, 0.1);'>
                        
                                        <div class=' col-md-12'>
                                            <div class='text-middle text-center' style='display: block; vertical-align: middle;'>
                                                <img class='img-thumbnail img-circle' src='assets/img/level7.png'/>
                                                <h6><code> Level 7 </code></h6>
                                            </div>
                                            <div  style='display: inline-block; vertical-align: middle; ' >" . $strText."</div>
                                        </div>
                                  
                                </div>";





                
                            echo "</li>\n";
                            $o++;
                        }
                        if ($num7 > 0) {
                            echo "</ul>\n";
                        }
                        echo "</li>\n";
                        $n++;
                    }
                    if ($num6 > 0) {
                        echo "</ul>\n";
                    }
                    echo "</li>\n";
                    $m++;
                }
                if ($num5 > 0) {
                    echo "</ul>\n";
                }
                echo "</li>\n";
                $l++;
            }
            if ($num4 > 0) {
                echo "</ul>\n";
            }
            echo "</li>\n";
            $k++;
        }
        if ($num3 > 0) {
            echo "</ul>\n";
        }
        echo "</li>\n";
        $j++;
    }
    if ($num2 > 0) {
        echo "</ul>\n";
    }
    echo "</li>\n";
    $i++;
}
mysqli_close($con);
?>
                    </ul>

<script type="text/javascript">
ddtreemenu.createTree("treemenu1", true)
</script>                                <div class="col-md-12">



                                </div>                                
                            </div>
                            </div>
                            
                        </div>
                    </div>
                     <!-- End Form Elements -->
                </div>

			</div>



             <!-- /. PAGE INNER  -->
<? kaki: ?>			 
            </div>
         <!-- /. PAGE WRAPPER  -->
        </div>
<?
    include "_footer.php";
}
?>
