<?php
	require_once('dbconfig.php');
	require_once('function.php');
	

if(isset($_SESSION['SESS_TOKEN']))
	{
$rows = sql($DBH, "SELECT * FROM tbl_user where hash = ?", array($SESS_HASH_USER), "rows");
	foreach($rows as $row)
	{
	$name		=	$row['name'];
	$surname	=	$row['surname'];
	$profile_pic	=	$row['profile_pic'];
	$email		=	$row['email'];
	$bank_name	=	$row['bank_name'];
	$account_name	=	$row['account_name'];
	$account_number	=	$row['account_number'];
	$phone		=	$row['phone'];
	$phone_two	=	$row['phone_ii'];
	$country	=	$row['country'];
	$location	=	$row['location'];
	$dob		=	$row['dob'];
	$gender		=	$row['gender'];
	}
	if($profile_pic == "default.jpg"){
		$user_true 			 = "<a class='navbar-brand' href='index.php' style='font-weight: bold; color: green'><small> $name $surname</small></a>";
		$user_pic	="<img class='user one' src='profile_pic/profile.jpg' width='200px'>";
		}
		else
		{
		
		$user_true 			 = "<a class='navbar-brand' href='index.php' style='font-weight: bold; color: gold'> $name $surname</a>";
		$user_pic	="<img class='user one' src='profile_pic/$profile_pic' width='200px'>";
		}
}

$header_web = "<header>
    <div id='wrapper'>

        <!-- Navigation -->
        <nav class='navbar navbar-default navbar-static-top' role='navigation' style='margin-bottom: 0'>
            <div class='navbar-header'>
                <button type='button' class='navbar-toggle' data-toggle='collapse' data-target='.navbar-collapse'>
                    <span class='sr-only'>Toggle navigation</span>
                    <span class='icon-bar'></span>
                    <span class='icon-bar'></span>
                    <span class='icon-bar'></span>
                </button>
                <a>$user_true</a>
            </div>
            <!-- /.navbar-header -->

            <ul class='nav navbar-top-links navbar-right'>
                <li class='dropdown'>
                    <a class='dropdown-toggle' data-toggle='dropdown' href='#'>
                        <i class='fa fa-envelope fa-fw'></i> <i class='fa fa-caret-down'></i>
                    </a>
                    <ul class='dropdown-menu dropdown-messages'>
                        <li>
                            <a href='#'>
                                <div>
                                    <strong>John Smith</strong>
                                    <span class='pull-right text-muted'>
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...</div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <strong>John Smith</strong>
                                    <span class='pull-right text-muted'>
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...</div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <strong>John Smith</strong>
                                    <span class='pull-right text-muted'>
                                        <em>Yesterday</em>
                                    </span>
                                </div>
                                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend...</div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a class='text-center' href='#'>
                                <strong>Read All Messages</strong>
                                <i class='fa fa-angle-right'></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-messages -->
                </li>
                <!-- /.dropdown -->
                <li class='dropdown'>
                    <a class='dropdown-toggle' data-toggle='dropdown' href='#'>
                        <i class='fa fa-tasks fa-fw'></i> <i class='fa fa-caret-down'></i>
                    </a>
                    <ul class='dropdown-menu dropdown-tasks'>
                        <li>
                            <a href='#'>
                                <div>
                                    <p>
                                        <strong>Task 1</strong>
                                        <span class='pull-right text-muted'>40% Complete</span>
                                    </p>
                                    <div class='progress progress-striped active'>
                                        <div class='progress-bar progress-bar-success' role='progressbar' aria-valuenow='40' aria-valuemin='0' aria-valuemax='100' style='width: 40%'>
                                            <span class='sr-only'>40% Complete (success)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <p>
                                        <strong>Task 2</strong>
                                        <span class='pull-right text-muted'>20% Complete</span>
                                    </p>
                                    <div class='progress progress-striped active'>
                                        <div class='progress-bar progress-bar-info' role='progressbar' aria-valuenow='20' aria-valuemin='0' aria-valuemax='100' style='width: 20%'>
                                            <span class='sr-only'>20% Complete</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <p>
                                        <strong>Task 3</strong>
                                        <span class='pull-right text-muted'>60% Complete</span>
                                    </p>
                                    <div class='progress progress-striped active'>
                                        <div class='progress-bar progress-bar-warning' role='progressbar' aria-valuenow='60' aria-valuemin='0' aria-valuemax='100' style='width: 60%'>
                                            <span class='sr-only'>60% Complete (warning)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <p>
                                        <strong>Task 4</strong>
                                        <span class='pull-right text-muted'>80% Complete</span>
                                    </p>
                                    <div class='progress progress-striped active'>
                                        <div class='progress-bar progress-bar-danger' role='progressbar' aria-valuenow='80' aria-valuemin='0' aria-valuemax='100' style='width: 80%'>
                                            <span class='sr-only'>80% Complete (danger)</span>
                                        </div>
                                    </div>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a class='text-center' href='#'>
                                <strong>See All Tasks</strong>
                                <i class='fa fa-angle-right'></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-tasks -->
                </li>
                <!-- /.dropdown -->
                <li class='dropdown'>
                    <a class='dropdown-toggle' data-toggle='dropdown' href='#'>
                        <i class='fa fa-bell fa-fw'></i> <i class='fa fa-caret-down'></i>
                    </a>
                    <ul class='dropdown-menu dropdown-alerts'>
                        <li>
                            <a href='#'>
                                <div>
                                    <i class='fa fa-comment fa-fw'></i> New Comment
                                    <span class='pull-right text-muted small'>4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <i class='fa fa-twitter fa-fw'></i> 3 New Followers
                                    <span class='pull-right text-muted small'>12 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <i class='fa fa-envelope fa-fw'></i> Message Sent
                                    <span class='pull-right text-muted small'>4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <i class='fa fa-tasks fa-fw'></i> New Task
                                    <span class='pull-right text-muted small'>4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a href='#'>
                                <div>
                                    <i class='fa fa-upload fa-fw'></i> Server Rebooted
                                    <span class='pull-right text-muted small'>4 minutes ago</span>
                                </div>
                            </a>
                        </li>
                        <li class='divider'></li>
                        <li>
                            <a class='text-center' href='#'>
                                <strong>See All Alerts</strong>
                                <i class='fa fa-angle-right'></i>
                            </a>
                        </li>
                    </ul>
                    <!-- /.dropdown-alerts -->
                </li>
                <!-- /.dropdown -->
                <li class='dropdown'>
                    <a class='dropdown-toggle' data-toggle='dropdown' href='#'>
                        <i class='fa fa-user fa-fw'></i> <i class='fa fa-caret-down'></i>
                    </a>
                    <ul class='dropdown-menu dropdown-user'>
                        <li><a href='#'><i class='fa fa-user fa-fw'></i> $user_true</a>
                        </li>
                        <li><a href='account.php'><i class='fa fa-gear fa-fw'></i> Settings</a>
                        </li>
                        <li class='divider'></li>
                        <li><a href='logout.php'><i class='fa fa-sign-out fa-fw'></i> Logout</a>
                        </li>
                    </ul>
                    <!-- /.dropdown-user -->
                </li>
                <!-- /.dropdown -->
            </ul>
            <!-- /.navbar-top-links -->

            <div class='navbar-default sidebar' role='navigation'>
                <div class='sidebar-nav navbar-collapse'>
                    <ul class='nav' id='side-menu'>
                        <li class='sidebar-search'>
                            <div class='input-group custom-search-form'>
                                <input type='text' class='form-control' placeholder='Search...'>
                                <span class='input-group-btn'>
                                <button class='btn btn-default' type='button'>
                                    <i class='fa fa-search'></i>
                                </button>
                            </span>
                            </div>
                            <!-- /input-group -->
                        </li>
                        <li>
                            <a href='index.php'><i class='fa fa-dashboard fa-spin'></i> DASHBOARD</a>
                        </li>
                        <li>
                            <a href='account.php'><i class='fa fa-user fa-spin'></i> ACCOUNT DETAILS</a>
                        </li>
                        <li>
                            <a href='multi_level_chain.php'><i class='fa fa-sitemap fa-fw'></i> MULT-LEVEL-CHAIN <span class='fa arrow'></span></a>
                            <ul class='nav nav-second-level'>
                                <li>
                                    <a href='classic.php'>CLASSIC LIST</a>
                                </li>
                                <li>
                                    <a href='manager.php'>MANAGER'S LIST</a>
                                </li>
                                <li>
                                    <a href='mentor.php'>MENTOR'S LIST</a>
                                </li>
                            </ul>
                            <!-- /.nav-second-level -->
                        </li>
                        <li>
                            <a href='courses.php'><i class='fa fa-book  fa-spin'></i>TAKE COURSES</a>
                        </li>
                        <li>
                            <a href='referrals.php'><i class='fa fa-book  fa-spin'></i>REFERRAL LINK</a>
                        </li>
                    </ul>
                </div>
                <!-- /.sidebar-collapse -->
            </div>
            <!-- /.navbar-static-side -->
        </nav>
        </header>";

			
			//delete any expired paired row and delete the user both after 3 days
			
			if(isset($_SESSION['SESS_TOKEN'])){
			
				$rows = sql($DBH, "SELECT * FROM tbl_payment_paired WHERE dt_stamp_end <= ? AND status = ?", 
				array(time(),"WAITING"), "rows");							
				foreach($rows as $row)
				{
					$payment_paired_id 	 			= $row['id'];
					$payment_paired_in_id 	 		= $row['payment_in_id'];
					$payment_paired_out_id 	 		= $row['payment_out_id'];
					$payment_paired_amount 	 		= $row['amount'];
					
					sql($DBH, "UPDATE tbl_payment_out SET STATUS = ?, amount = ? WHERE id = ?", 
					array("WAITING",$payment_paired_amount,$payment_paired_out_id), "rows");				
					
					sql($DBH, "UPDATE tbl_payment_in SET STATUS = ?, WHERE id = ?", 
					array("FAILED",$payment_paired_in_id), "rows");	
					
					$rows2 = sql($DBH, "SELECT * FROM tbl_payment_in WHERE id = ?",array($payment_paired_in_id), "rows");							
					foreach($rows2 as $row2)
					{
						$user_hash 	 			= $row2['user_hash'];
						sql($DBH, "UPDATE tbl_user SET status = ?  WHERE hash = ?", array("Inactive",$user_hash), "rows");	
					}
					
					sql($DBH, "DELETE FROM tbl_payment_paired  WHERE id = ?", array($payment_paired_id), "rows");
					sql($DBH, "DELETE FROM tbl_payment_in  WHERE STATUS = ?", array("FAILED"), "rows");
					
				}
				
				
			}
				
?>