<?php
define('Admin_USER', true);
session_start();
if (!isset($_SESSION['adm1n']) || $_SESSION['adm1n']['Nbr'] == '') {

    header("Location: login.php");
    exit;

}
require_once "includes/php/defines.php";
require_once "includes/php/classes/mainClass.php";
require_once "includes/php/classes/navUtility.php";

$nav = new navigationUtility();
$categories = $nav->getOptionCategories();
$options = $nav->getCategoryOptions();
$cmp = $nav->getContentManagedPages();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title><?php echo COMPANY_NAME; ?> Admin Panel</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/jquery-2.min.js"></script>
<script src="js/popupwindow.js"></script>
<script type="text/javascript" src="js/search-type.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/refresh-timer.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/content_changer.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/form_processor.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/clear_form.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/process_ender.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/search_processor.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/delete_processor.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/popup_processor.js"></script>
<script type="text/javascript" src="includes/ajax/initiate-popup.js" async='async'></script>
<script type="text/javascript" src="includes/ajax/gallery_processor.js"></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@latest/js/froala_editor.pkgd.min.js'></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@latest/js/plugins/file.min.js'></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@latest/js/plugins/quick_insert.min.js'></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@latest/js/plugins/image.min.js'></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@latest/js/plugins/entities.min.js'></script>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/froala-editor@latest/js/plugins/word_paste.min.js'></script>
<link href='https://cdn.jsdelivr.net/npm/froala-editor@latest/css/froala_editor.pkgd.min.css' rel='stylesheet' type='text/css' />
<link href='https://cdn.jsdelivr.net/npm/froala-editor@latest/css/plugins/file.min.css' rel='stylesheet' type='text/css' />
<link href='https://cdn.jsdelivr.net/npm/froala-editor@latest/css/plugins/quick_insert.min.css' rel='stylesheet' type='text/css' />
<link href='https://cdn.jsdelivr.net/npm/froala-editor@latest/css/plugins/image.min.css' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="css/style-2.css" type="text/css">
<link rel="stylesheet" href="css/admin.css" type="text/css">
<link rel="stylesheet" href="css/file-upload.css" type="text/css">
<link rel="stylesheet" href="css/gallery.css" type="text/css">
<link rel="stylesheet" href="css/progress-animation.css" type="text/css">
<link rel="stylesheet" href="css/popupwindow.css">
<link rel="stylesheet" href="css/froala_editor.min.css">
<link rel="stylesheet" href="css/froala_style.css">
<link rel="stylesheet" href="css/font-awesome-4.7.0/css/font-awesome.min.css">
<link rel="shortcut icon" href="../assets/images/fav.png" type="image/png">
</head>
<body>
<header>
	<div class="i-menu-bar">
		<div class="container">
			<div class="col-md-12"  style="background-color:#fff;">
				<div class="col-md-3 logo">
					<a href="index.php"><img src="images/webduck-logo.png" alt="Logo" style="height:60px;"></a>
				</div>
				<div class="col-md-9 user-acc">
					<ul>
						<li><a href="javascript: contentChanger('administrative/manage-account.php');"><img src="images/my-account.png" alt=""> <span>my account</span></a></li>
						<li><a href="logout.php"><img src="images/logout.png" alt=""> <span>Logout</span></a></li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div class="container-fluid header">
		<div class="container">
			<!-- Main Navigation -->
			<nav id='cssmenu' class="nav">
				<div id="head-mobile"></div>
				<div class="button"></div>
				<ul class="main-nav">
                            <?php
for ($i = 0; $i < count($categories); $i++) {

    if ($categories[$i]['Nbr'] != '1') {

        echo '<li>';
        echo '<a href="';
        if($categories[$i]['Page'] != ''){

            echo 'javascript: contentChanger(\'' . $categories[$i]['Directory'] . '/' . $categories[$i]['Page'] . '\',\'' . $categories[$i]['Nbr'] . '\')';

        }else{

            echo '#';

        }
        echo '" title="' . $categories[$i]['Desc'] . '">';
        echo  $categories[$i]['Name'];
        if($categories[$i]['Page'] != ''){

            echo '</a>';

        }
        echo '<ul>';
        for ($k = 0; $k < count($options); $k++) {

            if ($options[$k]['Category'] == $categories[$i]['Nbr'] && $options[$k]['Visible'] == 1) {

                echo '<li><a href="javascript: contentChanger(\'' . $categories[$i]['Directory'] . '/' . $options[$k]['Page'] . '\');" title="' . $options[$k]['Desc'] . '">' . $options[$k]['Name'] . '</a></li>';

            }
        }
        if ($categories[$i]['Nbr'] == '21') {

            for ($x = 0; $x < count($cmp); $x++) {

                echo '<li><a href="javascript: contentChanger(\'' . $categories[$i]['Directory'] . '/edit-page.php\',\'' . $cmp[$x]['Nbr'] . '\');" title="' . $cmp[$x]['Name'] . '">' . $cmp[$x]['Name'] . '</a></li>';

            }

        }
        echo '</ul>';
        echo '</li>';

    } else {

        if ($_SESSION['adm1n']['Nbr'] == '3') {

            echo '<li><a href="javascript: contentChanger(\'' . $categories[$i]['Directory'] . '/' . $categories[$i]['Page'] . '\',\'' . $categories[$i]['Nbr'] . '\');" title="' . $categories[$i]['Desc'] . '">' . $categories[$i]['Name'] . '</a>';
            echo '<ul>';
            for ($k = 0; $k < count($options); $k++) {

                if ($options[$k]['Category'] == $categories[$i]['Nbr'] && $options[$k]['Visible'] == 1) {

                    echo '<li><a href="javascript: contentChanger(\'' . $categories[$i]['Directory'] . '/' . $options[$k]['Page'] . '\');" title="' . $options[$k]['Desc'] . '">' . $options[$k]['Name'] . '</a></li>';

                }
            }
            echo '</ul>';
            echo '</li>';

        }

    }

}
?>
				</ul>
			</nav>
		</div>
	</div>
</header>
<div id="PopUp" class="pop-up-display-content"></div>
<div id="Content_Area">
<!-- content area for admin panel functionality -->


<!-- end content area for admin panel functionality -->
</div>
<footer class="a-footer">
	<div class="container-fluid">
		Copyright <?php echo date("g:i m-d-Y", time()); ?>
	</div>
</footer>
<script type="text/javascript" src="js/custom.js"></script>
<script>
window.onload = function(){
<?php
if (isset($_GET['PageId'])) {

    $pageInfo = $nav->getPageInfo($_GET['PageId']);
    echo 'contentChanger(\'' . $pageInfo['Directory'] . '/' . $pageInfo['Page'] . '\')';

} else {

    echo 'contentChanger(\'misc/default.php\')';

}
?>
}
//check to see if the session variable timed out. If so kick back to login screen
var run = window.setInterval("sessionCheck()",1800000);
//var cmsUpdate = window.setInterval("autoUpdate()",120000);
window.addEventListener('popstate',() => {
    ctrlBckBtn();
});
</script>
</body>
</html>