<?php
class Page {


function __construct($title = '', $breadcrum = ''){
 
    global $BASE_URL;
    global $BASE_URL_HTTPS;
    global $HOST_HTTPS;
    global $User;
    
        $this->BASE_URL = BASE_URL;
        $this->BASE_URL_HTTPS = BASE_URL_HTTPS;
        $this->DOMAIN = str_replace("https://", "", $this->BASE_URL_HTTPS);
        #$this->HOST_HTTPS = HOST_HTTPS;
        
        $this->PLATFORM_NAME = "BooCard";
        $this->COMPANY_NAME = "BooCard";
        
        
        $this->Title = $title;
        $this->SetActivePage = '';
        $this->AddToFooter = '';
        $this->AddToHead = '';
        $this->BodyElements = '';
        $this->Icon = '';
        
        $this->User = $User;
        $this->AssetsVersion = '0.9.8';
}


function SetIcon($icon){
    
        $this->Icon = "<i class='material-icons bg-gradient'>{$icon}</i> ";

}
function SetActivePage($value){
    
    $this->SetActivePage = $value;

}
function GetMeta(){



$timets = time();

if(PROGRESSIER_PWA_ID){
	$pwa_id = PROGRESSIER_PWA_ID;
	$pwa_script = <<<EOD
<link rel="manifest" href="https://progressier.app/{$pwa_id}/progressier.json"/><script defer src="https://progressier.app/{$pwa_id}/script.js"></script> 
EOD;
}

$HTML = <<<EOD
<!DOCTYPE html>
<html lang="it">
  <head> 
    <title>{$this->PLATFORM_NAME} > {$this->Title}</title>
    <meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!--favicon-->
	<link rel="icon" href="{$this->BASE_URL_HTTPS}/assets/images/favicon-32x32.png" type="image/png" />
	<!--plugins-->
	<link href="{$this->BASE_URL_HTTPS}/assets/plugins/simplebar/css/simplebar.css" rel="stylesheet" />
	<link href="{$this->BASE_URL_HTTPS}/assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css" rel="stylesheet" />
	<link href="{$this->BASE_URL_HTTPS}/assets/plugins/highcharts/css/highcharts.css" rel="stylesheet" />
	<link href="{$this->BASE_URL_HTTPS}/assets/plugins/vectormap/jquery-jvectormap-2.0.2.css" rel="stylesheet" />
	<link href="{$this->BASE_URL_HTTPS}/assets/plugins/metismenu/css/metisMenu.min.css" rel="stylesheet" />
	<!-- loader-->
	<link href="{$this->BASE_URL_HTTPS}/assets/css/pace.min.css" rel="stylesheet" />
	<script src="{$this->BASE_URL_HTTPS}/assets/js/pace.min.js"></script>
	<!-- Bootstrap CSS -->
	<link href="{$this->BASE_URL_HTTPS}/assets/css/bootstrap.min.css" rel="stylesheet">
	<link href="{$this->BASE_URL_HTTPS}/assets/css/bootstrap-extended.css" rel="stylesheet">
	<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet">
	<link href="{$this->BASE_URL_HTTPS}/assets/css/app.css" rel="stylesheet">
	<link href="{$this->BASE_URL_HTTPS}/assets/css/icons.css" rel="stylesheet">
	<!-- Theme Style CSS -->
	<link rel="stylesheet" href="{$this->BASE_URL_HTTPS}/assets/css/dark-theme.css" />
	<link rel="stylesheet" href="{$this->BASE_URL_HTTPS}/assets/css/semi-dark.css" />
	<link rel="stylesheet" href="{$this->BASE_URL_HTTPS}/assets/css/header-colors.css" />
    <link href="{$this->BASE_URL_HTTPS}/assets/css/custom.css?v={$this->AssetsVersion}&_={$timets}" rel="stylesheet">

    $pwa_script

  </head>
EOD;

return $HTML;

}



function GetNavigation(){
global $User;

	if($User->role == 'admin') {
		DEFINE('LICENSE_MOD_BROKER', true);

	}

	$dashboard      = menu_check_priv(LICENSE_MOD_BROKER, true, $this->BASE_URL.'/', 'bx-home-alt', 'Dashboard');
    $cards          = menu_check_priv(LICENSE_MOD_BROKER, true, "{$this->BASE_URL}/my-cards", 'bx-id-card', 'Cards');
    $targets        = menu_check_priv(LICENSE_MOD_BROKER, true, "{$this->BASE_URL}/my-targets", 'bx-link', 'Targets');

 switch($User->role) {

  case 'admin':{
  
    
  $HTML = <<<EOD
  
  
  <ul class="navbar-nav align-items-center flex-grow-1">
  $dashboard
  $cards
  $targets

</ul>
  
  
EOD;
  break;
  }
  
  }

return $HTML;
}

function GetHeader(){
$HTML = $this->GetMeta();
$Navigation = $this->GetNavigation();

if(is_backoffice()){

    $Embody = GenSuperAdminEmbody($this->User);

  
}

if($this->User->role == 'admin' ||  $this->User->role == 'backoffice' || $this->User->role == 'consulente' || $this->User->role == 'team_leader' || $this->User->role=='staff' || $this->User->role == 'manager'){


$TopRight_Menu = <<<EOD
 <div class="collapse navbar-collapse" id="navbarNav">
     <ul class="navbar-nav">
        
        
        $Embody

        
         <li class="nav-item">
             <a href="{$this->BASE_URL}/whatsapp/send" class="nav-link"><i class="material-icons">maps_ugc</i> WhatsApp</a>
         </li>
     

                                                              
      </ul>
  </div>
EOD;

$ModalQuickLink = <<<EOD
<li><div class="button" style="margin:0.5em" data-toggle="modal" data-target="#menuModal"> <i class="fa fa-grip fa-3x"></i> </div></li>
EOD;

$ProfileEdit = <<<EOD
<a class="dropdown-item" href="{$this->BASE_URL_HTTPS}/my-profile">Profilo</a>
EOD;

}

$HTML .=<<<EOD

<body {$this->BodyElements}>
<!--wrapper-->
	<div class="wrapper">
		<!--start header wrapper-->	
		<div class="header-wrapper">
			<!--start header -->
			<header>
				<div class="topbar d-flex align-items-center">
					<nav class="navbar navbar-expand gap-3">
						<div class="topbar-logo-header">
							<div class="">
								<!--img src="assets/images/logo-icon.png" class="logo-icon" alt="logo icon"-->
							</div>
							<div class="">
								<h4 class="logo-text">BooCard</h4>
							</div>
						</div>
						
						<div class="top-menu ms-auto">
						
						</div>
						<div class="user-box dropdown px-3">
							<a class="d-flex align-items-center nav-link dropdown-toggle dropdown-toggle-nocaret" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
								<img src="assets/images/avatars/profile.png" class="user-img" alt="user avatar">
								<div class="user-info ps-3">
									<p class="user-name mb-0">{$this->User->name}</p>
									<p class="designattion mb-0">{$this->User->email}</p>
								</div>
							</a>
							<ul class="dropdown-menu dropdown-menu-end">
								<li><a class="dropdown-item" href="{$this->BASE_URL_HTTPS}/my-profile"><i class="bx bx-user"></i><span>Profile</span></a>
								</li>
								<!--li><a class="dropdown-item" href="javascript:;"><i class="bx bx-cog"></i><span>Settings</span></a>
								</li-->
								<li><a class="dropdown-item" href="javascript:;"><i class='bx bx-dollar-circle'></i><span>Billings</span></a>
								</li>
							
								<li>
									<div class="dropdown-divider mb-0"></div>
								</li>
								<li><a class="dropdown-item" href="{$this->BASE_URL_HTTPS}/auth?logout=true"><i class='bx bx-log-out-circle'></i><span>Logout</span></a>
								</li>
							</ul>
						</div>
					</nav>
				</div>
			</header>
			<!--end header -->
			<!--navigation-->
			<div class="primary-menu">
				<nav class="navbar navbar-expand-lg align-items-center">
				   <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
					 <div class="offcanvas-header border-bottom">
						 <div class="d-flex align-items-center">
							 <div class="">
								 <img src="assets/images/logo-icon.png" class="logo-icon" alt="logo icon">
							 </div>
							 <div class="">
								 <h4 class="logo-text">Synadmin</h4>
							 </div>
						 </div>
					   <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
					 </div>
					 <div class="offcanvas-body">
                   
                   $Navigation
                   
                   </div>
				   </div>
			   </nav>
		 </div>
		 <!--end navigation-->
		   </div>
		   <!--end header wrapper-->
		<!--start page wrapper -->
		<div class="page-wrapper">

EOD;
return $HTML;
}

function GenerateBreadcrumbs($home = 'Dashboard') {
  global $page_title; //global varable that takes it's value from the page that breadcrubs will appear on. Can be deleted if you wish, but if you delete it, delete also the title tage inside the <li> tag inside the foreach loop.
    $breadcrumb  = '<ol class="breadcrumb slim-breadcrumb">';
    $root_domain = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'].'/';
    $breadcrumbs = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
    $breadcrumb .= '<li class="breadcrumb-item"><a href="' . $root_domain . '" title="Dashboard">' . $home . '</a></li>';
    foreach ($breadcrumbs as $crumb) {
        $link = ucwords(str_replace(array(".php","-","_"), array(""," "," "), $crumb));
        $root_domain .=  $crumb . '/';
        $breadcrumb .= '<li class="breadcrumb-item"><!--a href="'. $root_domain .'" title="'.$page_title.'"-->' . $link . '<!--/a--></li>';
    }
    $breadcrumb .= '</ol>';
    return $breadcrumb;
}



function GetFooter(){


    

$HTML = <<<EOD
</div>
<!--end page wrapper -->
<!--start overlay-->
<div class="overlay toggle-icon"></div>
<!--end overlay-->
<!--Start Back To Top Button--> <a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
<!--End Back To Top Button-->
<footer class="page-footer">
    <p class="mb-0">Copyright © 2024. All right reserved.</p>
</footer>
</div>
<!-- Bootstrap JS -->
	<script src="assets/js/bootstrap.bundle.min.js"></script>
	<!--plugins-->
	<script src="assets/js/jquery.min.js"></script>
	<script src="assets/plugins/simplebar/js/simplebar.min.js"></script>
	<script src="assets/plugins/metismenu/js/metisMenu.min.js"></script>
	<script src="assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
	<script src="assets/plugins/vectormap/jquery-jvectormap-2.0.2.min.js"></script>
	<script src="assets/plugins/vectormap/jquery-jvectormap-world-mill-en.js"></script>
	<script src="assets/plugins/highcharts/js/highcharts.js"></script>
	<script src="assets/plugins/highcharts/js/exporting.js"></script>
	<script src="assets/plugins/highcharts/js/variable-pie.js"></script>
	<script src="assets/plugins/highcharts/js/export-data.js"></script>
	<script src="assets/plugins/highcharts/js/accessibility.js"></script>
	<script src="assets/plugins/apexcharts-bundle/js/apexcharts.min.js"></script>
	<script src="assets/js/index2.js"></script>
	<!--app JS-->
	<script src="assets/js/app.js"></script>
	<script>
		new PerfectScrollbar('.customers-list');
		new PerfectScrollbar('.store-metrics');
		new PerfectScrollbar('.product-list');
	</script>
</body>

</html>
EOD;

return $HTML;


}

function Load($id){

    switch($id){
        case 'FullCalendar':

            return <<<EOD


<link href="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/core/main.min.css" rel="stylesheet">
<link href="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/daygrid/main.min.css" rel="stylesheet">
<link href="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/timegrid/main.min.css" rel="stylesheet">
<link href="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/list/main.min.css" rel="stylesheet">
<link href="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/bootstrap//main.min.css" rel="stylesheet">

<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/core/main.min.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/core/locales/it.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/list//main.min.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/interaction//main.min.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/daygrid/main.min.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/timegrid/main.min.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/bootstrap/main.min.js"></script>
<script src="{$Page->BASE_URL_HTTPS}/assets/plugins/fullcalendar/packages/google-calendar/main.min.js"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.43/moment-timezone-with-data.min.js"></script>

EOD;
        break;
    }



}


function NewCard($content, $class='', $title=false, $footer=false){

$HTML = <<<EOD
<div class="card {$class}">
    <div class="card-header plaincolor">
        {$title}
    </div>
    <div class="card-body">
        {$content}
    </div>
    <div class="card-footer text-muted">
        {$footer}
    </div>
</div>
EOD;

return $HTML;
}


function Output($Body){

$HTML = $this->GetHeader();
$HTML .= $Body;
$HTML .= $this->GetFooter();

return $HTML;
}

}
