<?php
require 'core/config.php';
require 'core/classes/user.php';
require 'core/classes/RCCServiceSoap.php';
$RCCServiceSoap = new RCCServiceSoap($soapcfg["ip"],$soapcfg["port"],$soapcfg["url"]);

class PartyStarter {
 function bootstrap() {
  echo '<link rel="stylesheet" href="css/bootstrap.min.css">
		<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js" integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD" crossorigin="anonymous"></script>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">';
 }
 function header() {
  // to not confuse you i renamed it from loggedoutheader to header since qzip made it both lol
  require 'core/config.php';
  $grubloxlogotohome = '<a class="navbar-brand text-dark" href="/"><span class="grufont fs-3">G </span><span class="gotham">GRUBLOX</span></a>';
  $showhome = '';
   $adminTab = " ";
  if (isset($_SESSION['user'])) {
   $showhome = '        <li class="nav-item text-dark" style="color: #FFFFFF;">
          <a class="nav-link text-dark nav-animated" href="/home"><i class="bi bi-house"></i> Home
            <span class="visually-hidden">(current)</span>
          </a>
        </li>';
		
	$query = $con->prepare('SELECT COUNT(id) FROM users WHERE id=:id');
	$query->bindParam(':id', $_SESSION['user'], PDO::PARAM_INT);
    $query->execute();
	$userExists = $query->fetchColumn();
	if($userExists <= 1) {
	// php me when
	} else {
	unset($_SESSION["user"]);	
	}

	$query = $con->prepare('SELECT * FROM friends WHERE user=:id AND state="pending"');
	$query->bindParam(':id', $_SESSION['user'], PDO::PARAM_INT);
    $query->execute();
	
    if($query->fetchColumn() >= 1) {
     $friendnotif = '<span class="position-absolute bottom-0 start-0 badge border border-light rounded-circle bg-danger p-2"><span class="visually-hidden">friend request</span></span>';
    } else {
	 $friendnotif = null;
	}
	echo $query->fetchColumn();
	
	$query = $con->prepare('SELECT * FROM users WHERE id=:id');
	$query->bindParam(':id', $_SESSION['user'], PDO::PARAM_INT);
    $query->execute();
	   // if admin
   if($query->fetch(PDO::FETCH_ASSOC)["admin"] >= 1) {
   $adminTab = '        <li class="nav-item nav-animated">
          <a class="nav-link text-dark" href="/admin"><i class="bi bi-wrench-adjustable-circle"></i> Admin</a>
        </li>';
   } else {
   $adminTab = " ";
   }	
	
   $grubloxlogotohome = '<a class="navbar-brand text-dark" href="/home"><span class="grufont fs-3">G </span><span class="gotham">GRUBLOX</span></a>';
   $user = new User($con, $_SESSION['user']);
   $money = $user->getMoney(false);
   
      $time = time();
   if($user->getLastPaid() !== NULL) {
   $dateToCheck = $user->getLastPaid();
   $dateToCheck += 86400;
   if($time >= $dateToCheck) {
   $q = $con->prepare("UPDATE users SET lastPaid=:lastPaid, money=money+:price WHERE id=:id");
   $q->bindParam(':id',$_SESSION['user'],PDO::PARAM_INT);
   $q->bindParam(':price',$pay,PDO::PARAM_INT);
   $q->bindParam(':lastPaid',$time,PDO::PARAM_INT);
   $q->execute();
   }
   } else {
   $q = $con->prepare("UPDATE users SET lastPaid=:date WHERE id=:id");
   $q->bindParam(':id',$_SESSION['user'],PDO::PARAM_INT);
   $q->bindParam(':date',$time,PDO::PARAM_INT);
   $q->execute();
   $q = $con->prepare("UPDATE users SET money=money+:price WHERE id=:id");
   $q->bindParam(':id',$_SESSION['user'],PDO::PARAM_INT);
   $q->bindParam(':price',$pay,PDO::PARAM_INT);
   $q->execute();
   }

   if ($money < 1000000) {
    // Anything less than a million
    $money = number_format($money);
   }
   else if ($money < 1000000000) {
    // Anything less than a billion
    $money = number_format($money / 1000000, 1) . 'M';
   }
   else {
    // At least a billion
    $money = number_format($money / 1000000000, 1) . 'B';

   }
   
   // messy shit sorry mario1 fix it urself :trol:
   $rightside = '
        <li class="nav-item">
          <a class="nav-link text-dark" style="font-size: 1.1rem"><span class="grufont" style="font-size: 1.25rem">@ </span>'.$money.'</a>
        </li>
        <li class="nav-item dropdown">
          <button class="nav-link border-0 text-dark dropdown-toggle bg-transparent" data-bs-toggle="dropdown" aria-expanded="false">
            <img height=32 width=32 class="rounded-5 position-relative" src="/assets/renders/user/headshot?userId='.(int)htmlspecialchars($_SESSION['user']).'"> 
			'.$friendnotif.'
			</img>
          </button>
          <ul class="dropdown-menu dropdown-menu-lg-end anim-dropdown" style="z-index: 3;">
            <li><a class="nav-link ms-2" href="/user"><span class="bi bi-person-circle"></span> Profile</a></li>
            <li><a class="nav-link ms-2" href="/settings"><span class="bi bi-gear"></span> Settings</a></li>
            <li><a class="nav-link ms-2" href="/friends"><span class="bi bi-person"></span> Friend requests</a></li>
            <li><a class="nav-link ms-2" href="/logout"><span class="bi bi-box-arrow-right"></span> Logout</a></li>
          </ul>
        </li>';
  } else {
   $rightside = '
        <li class="nav-item nav-animated">
          <a class="nav-link text-dark" href="/register">Register</a>
        </li>
        <li class="nav-item nav-animated">
          <a class="nav-link text-dark" href="/login">Login</a>
        </li>';
  }

  echo '<script
			  src="https://code.jquery.com/jquery-3.6.3.min.js"
			  integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU="
			  crossorigin="anonymous"></script>
        <link rel="stylesheet" href="/css/bootstrap.min.css"><link rel="stylesheet" href="/css/global.css">
		<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js" integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD" crossorigin="anonymous"></script>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css">
<nav class="navbar navbar-expand-lg navbar-light sticky-top py-0" style="background-color: #ff7700;">
  <div class="container-fluid">
    ' . $grubloxlogotohome . '
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor03" aria-controls="navbarColor03" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarColor03">
      <ul class="navbar-nav me-auto ml-auto" style="color: #FFFFFF;">
        ' . $showhome . '
        <li class="nav-item nav-animated">
          <a class="nav-link text-dark" href="/games"><i class="bi bi-controller"></i> Games</a>
        </li>
        <li class="nav-item nav-animated">
          <a class="nav-link text-dark" href="/catalog"><i class="bi bi-shop"></i> Catalog</a>
        </li>
        <li class="nav-item nav-animated">
          <a class="nav-link text-dark" href="/about"><i class="bi bi-question-circle"></i> About</a>
        </li>
		'.$adminTab.'
      </ul>
	  <ul class="navbar-nav">
' . $rightside . '
      </ul>
    </div>
  </div>
</nav>';
 }

}
?>
