<?php	
	/*if(isset($_SESSION['app_id']) && $_SESSION['app_id']>0) {
		$appId =  $_SESSION['app_id'];
	}		
	if(isset($_REQUEST['page']) && $_REQUEST['page']!=''){
		$pageVal = trim($_REQUEST['page']);		
		if(isset($_SESSION['adminId']) && isset($_SESSION['adminId'])!=''){
			$accRs = mysqli_query($con, "SELECT access FROM tbl_admin WHERE admin_id = '".$_SESSION['adminId']."'");
			if(mysqli_num_rows($accRs)>0){
				$accRec = mysqli_fetch_array($accRs);
				$access = $accRec['access'];
				$showMenuArray = explode(',',$access);
			}
		}
	} else { $pageVal = '';  $showMenuArray=(1111); $page='home'; }  */
	
if(isset($_SESSION['adminId'])) {
	$accessPages = array('home','login','logout', 'change_pass','login_new');
	$accessMenus = array();
	$accessHead = array();	
	$accessString = 0;
	$rsAccess = mysqli_query($con, "SELECT access FROM tbl_admin WHERE admin_id = " . $_SESSION['adminId']);
	$resAccess = mysqli_fetch_array($rsAccess);
	$accessString = strlen($resAccess['access'])>0?$resAccess['access']:0;	
	
	$execAccessPages = mysqli_query($con, "SELECT parent,pages,page FROM tbl_access_control WHERE id IN(".$accessString.")"); 
	while($row = $execAccessPages->fetch_assoc()) {
		foreach(explode(',',$row['pages']) as $accessPages[]);
		$accessMenus[] = $row['page'];
		$accessHead[] = $row['parent'];
		
	}
	$accessHead = array_unique($accessHead);	
	if(!(in_array($page,$accessPages))) {
		echo "NO ACCESS TO THIS PAGE";
		exit();
	}
	
} else {
	echo "NO ACCESS TO THIS PAGE";
		exit();
}
	?>
<!DOCTYPE html>
<html lang="en">
<!-- BEGIN HEAD -->
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta name="description" content="Responsive Admin Template" />
    <meta name="author" content="SmartUniversity" />
    <title><?php echo $adminLabel; ?> Services Admin |</title>
    <!-- google font -->
    <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet" type="text/css" />
	<!-- icons -->
    <link href="assets/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
	<!--bootstrap -->
	<link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<link href="assets/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
	<link href="assets/plugins/summernote/summernote.css" rel="stylesheet">
    <!-- Material Design Lite CSS -->
	<link rel="stylesheet" href="assets/plugins/material/material.min.css">
	<link rel="stylesheet" href="assets/css/material_style.css">
	<!-- animation -->
	<link href="assets/css/pages/animate_page.css" rel="stylesheet">
	<!-- inbox style -->
    <link href="assets/css/pages/inbox.min.css" rel="stylesheet" type="text/css" />
	<!-- Theme Styles -->
    
    <link href="assets/css/plugins.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/style.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/responsive.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/theme-color.css" rel="stylesheet" type="text/css" />
    <!--custom styles-->
    <link href="css/custom.css" rel="stylesheet" type="text/css" />
	<!-- favicon -->
    <link rel="shortcut icon" href="assets/img/favicon.ico" /> 
    <script>
    //save menu toggle incookie
	function saveToggle() {		
		$.ajax({url:"./ajax/ajax.php?action=save_menu_toggle",success:function(result){			
			
		}});
	}
    </script>
    <script type="text/javascript">
	function loadNotifications() {				
				//$('#loading-image').show();
				$.ajax({url:"ajax/top_notify.php",success:function(result){
					//$('#loading-image').hide();
					$("#notify_ajax").html(result);								
				}});			
	}	
	setInterval(function() {
	  loadNotifications();
	}, 30000);
	</script>
 </head>
 <!-- END HEAD -->
 <?php
 if(isset($_REQUEST['page']) && $_REQUEST['page']!=''){
		$pageVal = trim($_REQUEST['page']);		
	} else {
		$pageVal = '';
		$page='home';
	}
	$debug = true;
	
	$showMenuArray = array(1,2,3,4,5,6,7,8,9);
	function getFormattedDateHeader($datetime) {
	$phpDate = strtotime($datetime);
	$FormattedPhpDate = date('d-m-Y', $phpDate);
	return $FormattedPhpDate;
	}
	function getUserNameHeader($id) {
		$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
		mysqli_select_db($con, DB_NAME) or die(mysql_error());
		if($id !='') {
			$res = mysqli_fetch_array(mysqli_query($con, "SELECT name FROM tbl_user WHERE id = '$id'"));
			return $res['name'];
		}
	}
	function getTechNameHeader($id) {
		$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
		mysqli_select_db($con, DB_NAME) or die(mysql_error());
		if($id !='') {
			$res = mysqli_fetch_array(mysqli_query($con, "SELECT name FROM tbl_technician WHERE id = '$id'"));
			return $res['name'];
		}
	}
	function getShopNameHeader($id) {
		$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
		mysqli_select_db($con, DB_NAME) or die(mysql_error());
		if($id !='') {
			$res = mysqli_fetch_array(mysqli_query($con, "SELECT building_name FROM tbl_purchase_partner WHERE id = '$id'"));
			return $res['building_name'];
		}
	}
?>
<body onload="loadNotifications()" class="page-header-fixed sidemenu-closed-hidelogo page-content-white page-md header-white dark-sidebar-color logo-dark <?php /*if(($page=='user_gods_view') || ($page=='technician_gods_view') || ($page=='shop_gods_view') || ($page=='task_gods_view')){?>sidemenu-closed<?php }*/ ?>">
    <div class="page-wrapper">
        <!-- start header -->
        <div class="page-header navbar navbar-fixed-top">
            <div class="page-header-inner ">
                <!-- logo start -->
                <div class="page-logo">
                    <a href="index.php?page=home">                    
                    <span class="logo-default" >
                    <?php if($footerSettingsRec['logo']!=''){?>
                    <img src="images/<?php echo $footerSettingsRec['logo']; ?>">
                    <?php } else { ?>
                    <img src="images/logo.png">
                    <?php } ?>
                    </span> </a>
                </div>
                <!-- logo end -->
				<ul class="nav navbar-nav navbar-left in">					
					<li><a href="#" onclick="saveToggle()" class="menu-toggler sidebar-toggler"><i class="icon-menu"></i></a></li>
				</ul>                 
                <!-- start mobile menu -->
                <a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse">
                    <span></span>
                </a>
               <!-- end mobile menu -->
                <!-- start header menu -->
                <div class="top-menu">
                    <ul class="nav navbar-nav pull-right">
                    	<!-- start language menu -->
                        
                        <!-- end language menu -->
                        <!-- start notification dropdown -->
                        <?php /*if($notifyCount>0){ ?>
                        <li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar">
                            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                <i class="fa fa-bell-o"></i>
                                <span class="badge headerBadgeColor1"> <?php echo $notifyCount; ?> </span>
                            </a>
                            <ul class="dropdown-menu animated swing">
                                <li class="external">
                                    <h3><span class="bold">Notifications</span></h3>
                                    <span class="notification-label purple-bgcolor">New <?php echo $notifyCount; ?></span>
                                </li>
                                <li>                                	
                                    <ul id="notify_ajax" class="dropdown-menu-list small-slimscroll-style" data-handle-color="#637283">
                                    	<!--Ajax content will be loaded here on page load and every 30 secs-->                                        
                                    </ul>
                                    
                                    <div class="dropdown-menu-footer">
                                        <!--<a href="javascript:void(0)"> All notifications </a>-->
                                    </div>
                                </li>
                            </ul>
                        </li>
                        <?php }*/ 
                        //print_r($_SESSION);?>
                        <!-- end notification dropdown -->
                        <!-- start message dropdown --> 						
                        <!-- end message dropdown -->
 						<!-- start manage user dropdown -->
 						<li class="dropdown dropdown-user">
                            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                <img alt="" class="img-circle " src="assets/img/dp.jpg" />
                                <span class="username username-hide-on-mobile"> <?php echo $_SESSION['adminusername'];?> </span>
                                <i class="fa fa-angle-down"></i>
                            </a>                            
                            <ul class="dropdown-menu dropdown-menu-default animated jello"> 
                                <li>
                                    <a href="index.php?page=change_pass">
                                        <i class="icon-settings"></i> Change Password
                                    </a>
                                </li>                                                               
                                <li>
                                    <a href="index.php?page=logout">
                                        <i class="icon-logout"></i> Log Out </a>
                                </li>
                            </ul>                            
                        </li>
                        <!-- end manage user dropdown -->
                        <!--<li class="dropdown dropdown-quick-sidebar-toggler">
                             <a id="headerSettingButton" class="mdl-button mdl-js-button mdl-button--icon pull-right" data-upgraded=",MaterialButton">
	                           <i class="material-icons">more_vert</i>
	                        </a>
                        </li>-->
                    </ul>
                </div>
            </div>
        </div>
        <!-- end header -->       
		<!-- start page container -->
        <div class="page-container">
 			<!-- start sidebar menu -->
 			<div class="sidebar-container">
 				<div class="sidemenu-container navbar-collapse collapse fixed-menu">
	                <div id="remove-scroll">
<!--						sidemenu  page-header-fixed sidemenu-closed-->
	                    <ul class="sidemenu <?php if(isset($_COOKIE['menu_close']) && $_COOKIE['menu_close'] == 'yes'){ echo ' page-header-fixed sidemenu-closed';} elseif($page=='technician_gods_view'||$page=='user_gods_view'||$page=='shop_gods_view') {echo ' page-header-fixed sidemenu-closed';}  else { echo 'sidemenu  page-header-fixed'; } ?>" data-keep-expanded="false" data-auto-scroll="true" data-slide-speed="200" style="padding-top: 20px">
	                        <li class="sidebar-toggler-wrapper hide">
	                            <div class="sidebar-toggler">
	                                <span></span>
	                            </div>
	                        </li>
	                        <li class="sidebar-user-panel">
	                            <div class="user-panel">
	                                <!--<div class="pull-left image">
	                                    <img src="assets/img/dp.jpg" class="img-circle user-img-circle" alt="User Image" />
	                                </div>-->
	                                <div class="pull-left info">
	                                    <p> Admin User : <?php echo $_SESSION['adminusername'];?></p>
	                                    <!--<a href="#"><i class="fa fa-circle user-online"></i><span class="txtOnline"> Online</span></a>-->
	                                </div>
	                            </div>
	                        </li>
	                        <li class="nav-item start active">
	                            <a href="index.php?page=home" class="nav-link nav-toggle">
	                                <i class="material-icons">dashboard</i>
	                                <span class="title">Dashboard</span>                                	                          	
	                            </a>	                            
	                        </li>
	                        <?php 
							$execMainMenu = mysqli_query($con, "SELECT * FROM tbl_access_control WHERE menustatus ='Active' AND parent!='Shops' GROUP BY parent order by menu_order ASC");
							while($resMainMenu = mysqli_fetch_array($execMainMenu)) {	?>
				      		<?php if(in_array($resMainMenu['parent'],$accessHead)) { 
				      			//get pages inside the main menu. we have to open the div to show the current menu     
				      			$menuOpen = false; 			
								//echo "SELECT parent FROM tbl_access_control WHERE page = '".$pageVal."'";
				      			//$menuShowRs = mysqli_query($con, "SELECT parent FROM tbl_access_control WHERE page = '".$pageVal."'");
				      			$menuShowRs = mysqli_query($con, "SELECT parent FROM tbl_access_control WHERE FIND_IN_SET ('".$pageVal."', pages)");
				      			if(mysqli_num_rows($menuShowRs) >0){
				      				$menuShowRec = mysqli_fetch_array($menuShowRs);
									if($menuShowRec['parent']==$resMainMenu['parent']){
										$menuOpen = true;
									}
				      			} else {
				      				//the page may be added inside pages
				      				
				      			}							
				      			?>
				      			<li class="nav-item <?php if($menuOpen) { echo 'open'; } ?>">
						      	<a href="#" class="nav-link nav-toggle"> <i class="material-icons">grain</i>
						      		<span class="title"><?php echo $resMainMenu['parent'];   ?></span> <span class="arrow"></span>
						      	</a>
						        <ul class="sub-menu" <?php if($menuOpen) { echo 'style="display:block;"'; } ?> >		          
						            <?php 	$execSubMenu = mysqli_query($con, "SELECT * FROM tbl_access_control WHERE  parent= '".$resMainMenu['parent']."' AND menustatus ='Active' AND parent_sub = '' ORDER BY menu_order");
											while($resSubMenu = mysqli_fetch_array($execSubMenu)) {	?>
								            	<?php if(in_array($resSubMenu['page'],$accessMenus)) { ?>
									            	<?php 	$execSubMenu2 = mysqli_query($con, "SELECT * FROM tbl_access_control WHERE  parent_sub= '".$resSubMenu['menu']."' AND menustatus ='Active' ORDER BY menu_order");
												            if(mysqli_num_rows($execSubMenu2) >0){?>
												            <li class="nav-item <?php if($pageVal ==  $resSubMenu['page']){ echo 'class="active"'; }?>" >
												            	<a href="javascript:;"><?php echo $resSubMenu['menu']; ?></a>										        	
								            				</li>
								            				<?php } else { ?>		            		
								            				<li <?php if($pageVal ==  $resSubMenu['page']){ echo 'class="nav-item active"'; }?>>
								            					<a href="./index.php?page=<?php echo $resSubMenu['page'];   ?>"><?php echo $resSubMenu['menu'];  
																/*if($resSubMenu['page']=='manage_technician' && $unreadTechCount>0){
																	 echo ' <div class="menu_notify">'.$unreadTechCount.'</div>'; 
																} else if($resSubMenu['page']=='manage_user' && $unreadUserCount>0){
																	 echo ' <div class="menu_notify">'.$unreadUserCount.'</div>'; 
																} else if($resSubMenu['page']=='manage_purchase_partner' && $unreadShopCount>0){
																	 echo ' <div class="menu_notify">'.$unreadShopCount.'</div>'; 
																} else if($resSubMenu['page']=='manage_user_tasks' && $unreadTaskCount>0){
																	 echo ' <div class="menu_notify">'.$unreadTaskCount.'</div>'; 
																} else if($resSubMenu['page']=='manage_purchase_order' && $unreadOrderCount>0){
																	 echo ' <div class="menu_notify">'.$unreadOrderCount.'</div>'; 
																} else if($resSubMenu['page']=='tech_extra_tech_requests' && $unassignedExtraTechCount>0){
																	 echo ' <div class="menu_notify">'.$unassignedExtraTechCount.'</div>'; 
																} else if($resSubMenu['page']=='tech_disputes' && $notifyDisputeCount>0){
																	 echo ' <div class="menu_notify">'.$notifyDisputeCount.'</div>'; 
																} else if($resSubMenu['page']=='tech_leads' && $notifyLeadsCount>0){
																	 echo ' <div class="menu_notify">'.$notifyLeadsCount.'</div>'; 
																}*/ ?></a>
								            				</li>
								            				<?php } ?>
								            	<?php }	?>
								            <?php }	?>
						          </ul>						        
						      </li>
		      				<?php	}	?>
      						<?php }	?>
		      
	                        
	                    </ul>
	                </div>
                </div>
            </div>
<!-- end sidebar menu --> 