<!doctype html>
<html lang="en">
<?php
require_once "config.php";
// require_once "creadational.php";
// require_once "function.php";

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
 $url = "https://";   
else  
 $url = "http://";   
    // Append the host(domain name, ip) to the URL.   
$url.= $_SERVER['HTTP_HOST'];   

    // Append the requested resource location to the URL   
$url.= $_SERVER['REQUEST_URI'];    
$link_array = explode('/',$url);
$page = end($link_array);

?>
<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

  <!-- Bootstrap CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="public/css/style.css" >
  <link rel="stylesheet" href="public/css/custom.css" >
  <script src="<?php echo getBaseUrl(); ?>public/js/jquery.min.js" ></script>
  <script src="<?php echo getBaseUrl(); ?>public/js/bootstrap.min.js"></script>
  <?php 
  if($page == '' || $page == 'index.php'){
    echo "<title>Stress Tracker | Home</title>";
  }else{
    echo "<title>Stress Tracker</title>";
  }
  ?>
  <!-- <link rel="shortcut icon" type="image/x-icon"/> -->
  <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon" href="/img/flavico.fw.ico">

    <!-- font awersom style -->
    <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
</head>
<body>
  <?php
  if (!isset($_SESSION)) {
    session_start();
  }
  require_once "config.php";
  // session_start();
  ini_set('display_errors', 0);
  ini_set('display_startup_errors', 0);
  // error_reporting(E_ALL);
  if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true)
  {

    $username = $_SESSION["username"];
    $sqlPendingUserAlerts= "SELECT PendingUserAlerts FROM users WHERE username='$username'";
    $PendingUserAlertsquery = mysqli_query($mysqli,$sqlPendingUserAlerts);
    $PendingUserAlertsGrab = mysqli_fetch_assoc($PendingUserAlertsquery);
    $PendingUserAlerts = $PendingUserAlertsGrab['PendingUserAlerts'];
    $PendingUserAlertsarr = str_replace("_"," ",$PendingUserAlerts);
    $PendingUserAlertsarr = trim($PendingUserAlertsarr);
    $PendingUserAlertsarr = explode(" ", $PendingUserAlertsarr);
    $NumberofAlerts = 0;
    $PendingUserAlertsToDisplayarr = [];
    if($PendingUserAlertsarr[0] != " " && $PendingUserAlertsarr[0] != "" && !empty($PendingUserAlertsarr[0]))
    {
      echo "<div class=dropdown1><img src=notificationbell.png alt=NoticationBell width=35px height=35px>";
    }

    for($i = 0; $i < count($PendingUserAlertsarr); $i++)
    {
      
      if($PendingUserAlertsarr[$i] != " " && $PendingUserAlertsarr[$i] != "" && !empty($PendingUserAlertsarr[$i]))
      {
       
        $PendingUserAlertsFirstColon = strpos($PendingUserAlertsarr[$i],":");
        $PendingUserAlertsFirstColon = $PendingUserAlertsFirstColon + 1;
        $PendingUserAlertsToDisplay = substr($PendingUserAlertsarr[$i],$PendingUserAlertsFirstColon);
        if(in_array($PendingUserAlertsToDisplay, $PendingUserAlertsToDisplayarr) == FALSE)
        {
          array_push($PendingUserAlertsToDisplayarr, $PendingUserAlertsToDisplay);
          $NumberofAlerts++;
          echo " <div class=dropdown-content1><div class=alerttext>Stress Alert: $PendingUserAlertsToDisplay<button class=dropbtn1><a href=ClearPendingAlert.php?PendingUserAlertToClear=_{$PendingUserAlertsarr[$i]}>Clear</a></button></div></div>";
        }
        
      }
    }
    echo "</div>";
    if($PendingUserAlertsarr[0] != " " && $PendingUserAlertsarr[0] != "" && !empty($PendingUserAlertsarr[0]))
    {
      echo "<span class=dot>$NumberofAlerts</span>";
    }

    
  }
  ?>
  <div class="wrapperLoader" style=" background-size: 5% !important;
  position: fixed;display: block;width: 100%; height: 100%;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(255,255,255)!important; cursor: pointer;z-index: 9999;background-repeat: no-repeat; background-size: 10%;  background-position: center;background: url('<?php echo getBaseUrl().'public/images/mini-logo.png';  ?>') center no-repeat;
  background-size:50%;">
  <div class="loader" style="position: fixed;display: block;width: 100%; height: 100%;top: 0;left: 0;right: 0;bottom: 0; cursor: pointer;z-index: 9999;background-image: url('<?php echo getBaseUrl().'public/images/loader.gif'; ?>');background-repeat: no-repeat; background-size: 12%;  background-position: center;"></div>
</div> 
<header class="lt-header">
  <div class="container-fluid">
    <nav class="navbar navbar-expand-lg navbar-light">
      <a class="navbar-brand" href=""> <img src="./public/images/Stress_Tracker_Logo.png" alt="LST LOGO"> </a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
      aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link"  href="<?php echo $baseurl; ?>">HOME</a>
        </li>
        <?php if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] == true) : ?>

          <?php
            $dissable_menu='';
            /*if($_SESSION["prosess_step_status"]==0)
            {
              $dissable_menu='dissable';
            }*/
          ?>
          <li class="nav-item">
            <a class="nav-link <?php echo $dissable_menu; ?>"  href="survey.php">TAKE DAILY SURVEY </a>
          </li>
          <li class="nav-item">
            <a class="nav-link <?php echo $dissable_menu; ?>"  href="#">MY GROUPS</a>
            <!-- <a class="nav-link"  href="groups.php" >GROUPS</a> -->
          </li>

              <!-- <li class="nav-item">
                <a class="nav-link"  href="#" >CREATE A GROUPS</a>
              </li> -->
              <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo $_SESSION['username']; ?></a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                  <a class="dropdown-item" href="#">PROFILE</a>
                  <a class="dropdown-item" href="logout.php">LOGOUT</a>
                </div>
              </li>
              
              <?php else : ?><!-- 
              <li class="nav-item">
                <a class="nav-link"  href="creategroup.php" >CREATE A GROUP</a>
              </li> -->
              <li class="nav-item">
                <a class="nav-link"  href="register.php" >JOIN</a>
              </li>
              
            <?php endif; ?>
          </ul>
        </div>
      </nav>
    </div>
  </header>