<?php

	include 'header.php';
	include 'navbar.php';

	
	require_once('includes/API_Config.php');
  
	$obj = new API_Config;
	$data = array();
	$data['refer_id'] = $_SESSION['refer_id'];
	$data['user_id'] = $_SESSION['user_id'];
	$response = json_decode($obj->call_API("API_dashboardDetails.php", $data));
	$profile = $response->data->personal_info[0];
	$packageInfo = $response->data->package_info;
	$joinees = $response->data->recently_joined;
	$sales  = $response->data->sales[0];
	$secure = $response->data->secure;
	$earnings = $response->data->pv_earnings;
	$sponsor_count = $response->data->sponsor_count;
	$rewardstatus = json_decode($obj->call_API("API_getRewardStatus.php", $data));
	
?>

					<!-- First Row Section Starts -->
					<div class="row">
						<div class="col-12 grid-margin">
						  <div class="card card-statistics">
							
							<div class="row">
								<!-- My Team Section Starts -->
								 <!--div class="card-col col-xl-3 col-lg-3 col-md-3 col-6">
									<div class="card-body">
										<div class="d-flex align-items-center justify-content-center flex-column flex-sm-row">
										  <i class="mdi mdi-account-multiple-outline text-primary mr-0 mr-sm-4 icon-lg"></i>
										  <div class="wrapper text-center text-sm-left">
											<p class="card-text mb-0">My Team</p>
											<div class="fluid-container">
											  <h3 class="card-title mb-0">65,650</h3>
											</div>
										  </div>
										</div>
									  </div>
								  </div-->
								  <!-- My Team Section Ends -->

								  <!-- Wallet Balance Section Starts -->
								  <div class="card-col col-xl-3 col-lg-3 col-md-3 col-6">
									<div class="card-body">
										<div class="d-flex align-items-center justify-content-center flex-column flex-sm-row">
										  <i class="mdi mdi-arrow-bottom-left text-primary mr-0 mr-sm-3 icon-lg"></i>
										  <div class="wrapper text-center text-sm-left">
											<p class="card-text mb-0">Total Left PV</p>
											<div class="fluid-container">
											  <h4 class="card-title mb-0">
											  <?php if(!empty($sales)) echo number_format($sales->left_member_pv, 0, ",", ","); else echo "0";?> PV 
											  </h4>
											</div>
										  </div>
										</div>
									  </div>
								  </div>
								  <!-- Wallet Balance Section Ends -->

								  <!-- Last RV Point Section Starts -->
								  <div class="card-col col-xl-3 col-lg-3 col-md-3 col-6">
									<div class="card-body">
										<div class="d-flex align-items-center justify-content-center flex-column flex-sm-row">
										  <i class="mdi mdi-arrow-bottom-right text-primary mr-0 mr-sm-3 icon-lg"></i>
										  <div class="wrapper text-center text-sm-left">
											<p class="card-text mb-0">Total Right PV</p>
											<div class="fluid-container">
											  <h4 class="card-title mb-0">
											   <?php if(!empty($sales)) echo number_format($sales->right_member_pv, 0, ",", ","); else echo "0";?>  PV 
											  </h4>
											</div>
										  </div>
										</div>
									  </div>
								  </div>
								  <!-- Last RV Point Section Ends -->

								  <!-- Last Payout Section Starts -->	
								 <div class="card-col col-xl-3 col-lg-3 col-md-3 col-6">
									<div class="card-body">
										<div class="d-flex align-items-center justify-content-center flex-column flex-sm-row">
										  <i class="mdi mdi-magnet-on text-primary mr-0 mr-sm-3 icon-lg"></i>
										  <div class="wrapper text-center text-sm-left">
											<p class="card-text mb-0">Total Direct</p>
											<div class="fluid-container">
											  <h4 class="card-title mb-0">
											   <?php if(!empty($sales)) echo number_format($sponsor_count, 0, ",", ","); else echo "0";?>  Members
											  </h4>
											</div>
										  </div>
										</div>
									  </div>
								  </div>
								  <!-- Last Payout Section Ends -->	


								  <!-- Last Payout Section Starts -->	
								  <div class="card-col col-xl-3 col-lg-3 col-md-3 col-6">
									<div class="card-body">
										<div class="d-flex align-items-center justify-content-center flex-column flex-sm-row">
										  <a href="add-new-member.php">			  
											<i class="mdi mdi-account-plus text-primary mr-0 mr-sm-3 icon-lg"></i>
										  </a>
										  <div class="wrapper text-center text-sm-left">
											<p class="card-text mb-0">Add New</p>
										  </div>
										</div>
									  </div>
								  </div>
								  <!-- Last Payout Section Ends -->	
							</div>
						  </div>
						</div>
					</div>
					<!-- First Row Section Ends -->

					<!-- Second Row Section Starts -->
					<div class="row">
						<!-- Profile Details Starts -->	
						<div class="col-md-4 col-sm-6 grid-margin stretch-card">
							<div class="card text-center">
								<div class="card-body">
									<img src="https://placehold.it/100x100" class="img-lg rounded-circle mb-2" alt="profile image"/>
									<h4><?php echo ucwords($profile->name . " " . $profile->last_name);?></h4>
									<p class="text-muted"><?php echo $profile->email_address;?></p>
									<p class="mt-4 card-text">
									</p>
									<a href="profile.php" class="btn btn-primary btn-sm mt-3 mb-4">Edit Profile</a>
									<div class="border-top pt-3">
										<div class="row">
											<div class="col-4">
												<h6><?php echo $profile->refer_id;?></h6>
												<p>Member ID</p>
											</div>
											<div class="col-4">
												<h6><?php echo $profile->sponsor_by;?></h6>
												<p>Sponsor ID</p>
											</div>
											<div class="col-4">
												<h6><?php echo $profile->sponsor_id;?></h6>
												<p>Placement ID</p>
											</div>
										</div>
									    <div class="row">
											<div class="col-4">
												<h6><?php echo $packageInfo->totalPurchase;?></h6>
												<p>Total Purchase</p>
											</div>
											<div class="col-4">
												<h6><?php echo $packageInfo->totalPV;?></h6>
												<p>Total PV</p>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- Profile Details Ends -->

						<!-- PV Details Starts -->	
						<div class="col-md-4 col-sm-6 grid-margin stretch-card">
						  <div class="card">
							<div class="card-body pb-0">									
								<h5 class="card-title">Rewards</h5>


								<div class="template-demo">
									<table class="table mb-0">
									  <thead>
										<tr>
										  <th class="pl-0">Reward Name</th>
										  <th class="text-right">Status</th>
										</tr>
									  </thead>
									  <tbody>


										 <?php
											 if(!empty($rewardstatus->data))
											  {
													$count = 1;
													foreach($rewardstatus->data as $row)
													{
														echo "<tr>";
														echo '<td class="pl-0">' . ucWords($row->rewardName) . '</td>';

														if($row->claimStatus !='')
														{
															echo '<td class="pr-1 text-right mt-3"><div class="badge badge-primary badge-pill">'. $row->claimStatus . '</div></td>';

															continue;

														}

														if(($row->rewardLeftVolume >= $row->leftLegTarget) && ($row->rewardRightVolume >= $row->rightLegTarget))
														{
															echo '<td class="pr-1 text-right mt-3"><a href="rewards.php"><div class="badge badge-primary badge-pill">Claim your reward</div></a></td>';
														}


														else
														{
															echo '<td class="pr-0 text-right"><a href="rewards.php"><div class="badge badge-warning badge-pill">Pending</div></a></td>';
														}

													}

											  }
																									
														
																									
														
										 ?>                     
								
									  </tbody>
									</table>
								 </div>




















							</div>
						  </div>
						</div>
						<!-- PV Details Ends -->

  						<!-- Update Details Starts -->	
						 <div class="col-md-4 grid-margin stretch-card">
							<div class="card">
								<div class="card-body">
									<h5 class="card-title">Top 5 Active Members</h5>
										<div class="table-responsive">
							  <table class="table center-aligned-table">
								<thead>
								  <tr class="bg-light">
									<th class="border-bottom-0">Member Name</th>
									<th class="border-bottom-0">Member ID</th>
								  </tr>
								</thead>
								<tbody>
								  <?php if(empty($joinees)) {?><h3>No Recent Joining with a product purchase</h3><?php }
								  
								  else 
								  {
									  foreach($joinees as $row)
									  {
										  echo "<tr>";
										  echo "<td>". $row->name . "</td>";
										  echo "<td>". $row->refer_id . "</td>";
										  echo "</tr>";			
									  }
									  
									  
									}
								  ?>
								</tbody>
							  </table>
							</div>
									
								</div>
							</div>
						</div>
						</div>
						<!-- Update Details Ends -->
					</div>
					<!-- Second Row Section Ends -->



					<!-- Third Row Section Starts -->
					
					<!-- Third Row Section Ends -->


				    <!-- Fourth Row Section Starts -->
					<div class="row">
						<div class="col-12 grid-margin">
						  <div class="card">
							<div class="card-body">
							  <h4 class="card-title">Promotional Referral Link</h4>
							  <p class="card-description">
								Copy and share your referral link
							  </p>
							  
							  <div class="row">
								<div class="col-md-6">
								  <h6 class="card-title">Left Referral Link</h6>
								  <div id="dragula-event-left" class="py-2">
									<div class="card rounded border mb-2">
									  <div class="card-body p-3">
										<div class="media">
										 <div class="media-body">
											<a href="#" id='copy_left_link'>http://localhost/MyBooster/register.php?refer_id=<?php echo $_SESSION['refer_id'];?>&leg=left</a>
											<p class="mb-0 text-muted">
											  Click to copy link
											</p>
											<p>
												<div class="sharethis-inline-share-buttons" data-url="http://localhost/MyBooster/register.php?refer_id=<?php echo $_SESSION['refer_id'];?>&leg=left" data-title="MyBooster" data-image="http://localhost/MyBooster/images/mybooster-logo.png" data-description="Evolve with purity">
												</div>
											</p>
										  </div>
										</div>
									  </div>
									</div>
								  </div>
								</div>

								<div class="col-md-6">
								  <h6 class="card-title">Right Referral Link</h6>
								  <div id="dragula-event-left" class="py-2">
									<div class="card rounded border mb-2">
									  <div class="card-body p-3">
										<div class="media">
										  <div class="media-body">
											<a href="#" id='copy_right_link'>http://localhost/MyBooster/register.php?refer_id=<?php echo $_SESSION['refer_id'];?>&leg=right</a>
											<p class="mb-0 text-muted">
											  Click to copy link
											</p>
											<p>
												<div class="sharethis-inline-share-buttons" data-url="http://localhost/MyBooster/register.php?refer_id=<?php echo $_SESSION['refer_id'];?>&leg=right" data-title="MyBooster" data-image="http://localhost/MyBooster/images/mybooster-logo.png" data-description="Evolve with purity">
												</div>
											</p>
										  </div>
										</div>
									  </div>
									</div>
								  </div>
								</div>
            				  </div>
							  
    						</div>
						 </div>
					 </div>
				   </div>
    			   <!-- Fourth Row Section Ends-->

			      <div class="modal fade" id="passwordModal" tabindex="-1" role="dialog" aria-labelledby="passwordModal" style="display: none;" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                      <div class="modal-content">
                        <div class="modal-header">
                          <h5 class="modal-title" id="passwordModalLabel-4">Secure Your Account</h5>
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">X</span>
                          </button>
                        </div>
                        <div class="modal-body">
                          <form id="frmPasswordModal" action="" method="POST">
							<h4><label class="col-form-label">Login Password:</label></h4>
							<div class="row">
								<div class="form-group col-md-6">
								  <input type="password" name="loginPassword" id="loginPassword" class="form-control" required aria-invalid="true" aria-describedby="loginPasswordHelp" placeholder="New Login Password">
								  <small id="loginPasswordHelp" class="form-text text-muted"></small>
								</div>
								<div class="form-group col-md-6">
								  <input type="password" name="loginPasswordConfirm" id="loginPasswordConfirm" class="form-control" required aria-invalid="true" aria-describedby="loginPasswordConfirmHelp" placeholder="Confirm Login Password">
								  <small id="loginPasswordConfirmHelp" class="form-text text-muted"></small>
								</div>
							</div>
														
							<h4><label class="col-form-label">Transaction Password:</label></h4>
							<div class="row">
								<div class="form-group col-md-6">
								  <input type="password" name="transPassword" id="transPassword" class="form-control" required aria-invalid="true" aria-describedby="transPasswordHelp" placeholder="New Transaction Password">
								  <small id="transPasswordHelp" class="form-text text-muted"></small>
								</div>
								<div class="form-group col-md-6">
								  <input type="password" name="transPasswordConfirm" id="transPasswordConfirm" class="form-control" required aria-invalid="true" aria-describedby="transPasswordConfirmHelp" placeholder="Confirm Transaction Password">
								  <small id="transPasswordConfirmHelp" class="form-text text-muted"></small>
								</div>
							</div>
									
    					    <h4><label for="motherName" class="col-form-label">Mother's Name:</label></h4>
							<div class="row">
								<div class="form-group col-md-6">
								  <input type="text" name="motherName" id="motherName" class="form-control" required aria-invalid="true" aria-describedby="motherNameHelp" placeholder="Mother's Name">
								  <small id="motherNameHelp" class="form-text text-muted"></small>
								</div>
							</div>

							<input type="text" name="referID" id="referID" class="form-control" hidden value=<?php echo $_SESSION['refer_id'];?>>
                          
						  </form>
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-primary" id="submitPasswordModal">Submit</button>
                          <button type="button" class="btn btn-light" id="closeModal" data-dismiss="modal">Close</button>
						  <div class="dot-opacity-loader" id="loaderModal">
							  <span></span>
							  <span></span>
							  <span></span>
						  </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  
				  <?php if($secure) { if($packageInfo->totalPV<3000){?><a href="#" id="show" class="btn btn-outline-danger" hidden></a><?php } }?>
                  <button type="button" class="btn btn-primary btn-sm" onclick="showToastPosition('bottom-left', 'LEFT')" id="leftClick" hidden></button>
                  <button type="button" class="btn btn-primary btn-sm" onclick="showToastPosition('bottom-right', 'RIGHT')" id="rightClick" hidden></button>
         
             	
						
		</div>
	</div>
</div>
 



<?php
	include 'footer.php';
?>


<script type="text/javascript">
   

      <?php if(!$secure) {?> $('#loaderModal').hide(); 
    $('#passwordModal').modal('show'); <?php }?> 


 
	$("#copy_left_link").click(function(){
		
		var $temp = $("<input>");
		$("body").append($temp);
		$temp.val($("#copy_left_link").text()).select();
		document.execCommand("copy");
		$("#leftClick").trigger('click');
		$temp.remove();
		$.notify("Link Copied","success");
		
	});

	 $("#copy_right_link").click(function(){
		//alert("hi");
		var $temp = $("<input>");
		$("body").append($temp);
		$temp.val($("#copy_right_link").text()).select();
		document.execCommand("copy");
		$("#rightClick").trigger('click');
		$temp.remove();
		$.notify("Link Copied","success");

	});
	

	



</script>





</body>

</html>
