<?php
$mainnav = '';
$pageCats = getPageCatArray($con);
$progress = getCurrentProgress($con);

$query = 'SELECT p.*, pc.pgop FROM pages p LEFT JOIN page_cat pc ON (p.pgcat_id = pc.pgcat_id) WHERE p.display=1 ORDER BY p.dispOrder';  
$result = $con->query($query);
$num_rows = mysqli_num_rows($result);

if ($num_rows > 0) {
	// Define Nav Lists
	foreach ($pageCats as $key => $value) {
		$navName = $value['name'];
		$$navName = ''; 
	} 
	while ($row=$result->fetch_array(MYSQLI_ASSOC)) {
		foreach ($pageCats as $key => $value) {
			if ($row['pgcat_id'] == $key)
				$tableName = $value['name'];
		}
		$$tableName .= '<li><a href="?op='. $row['pgop'] .'&type='. $row['type'];
		$$tableName .= ((!empty($row['ptype'])) ? '&ptype='. $row['ptype'] : '');
		$$tableName .= '">'. $row['pageName'] .'</a></li>';
	}
	foreach ($pageCats as $key => $value) {
		$navName = $value['name'];
		$navIcon = (!empty($value['icon']) ? $value['icon'] : 'fa-wrench');
		$mainnav .= '<li>
						<a href="#"><i class="fa '. $navIcon .' fa-fw"></i> '. $navName .'<span class="fa arrow"></span></a>
                  		<ul class="nav nav-second-level">
                        	'. $$navName . '
                     	</ul>
                      	<!-- /.nav-second-level -->
                  	</li>'; 
	}
}

$content .= '
    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="margin-bottom: 0;">
    	<div class="navbar-header">
        	<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            	<span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
               	<span class="icon-bar"></span>
               	<span class="icon-bar"></span>
         	</button>
          	<a class="navbar-brand" href="index.php"><span class="logo">Como Creative</span> Billing</a>
       	</div>
       	<!-- /.navbar-header -->

		<ul class="nav navbar-top-links navbar-right">
			<li class="dropdown">
            	<a class="dropdown-toggle" data-toggle="dropdown" href="#">
                	<i class="fa fa-external-link"></i>  <i class="fa fa-caret-down"></i>
              	</a>
              	<ul class="dropdown-menu dropdown-quicklinks">
                	<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="client" data-adminact="new" data-editid=""><i class="fa fa-user-plus"></i> Add a NEW Client</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="loginfo" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Login Info</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="rate" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Client Rate</a></li>
					<li class="divider"></li>
                  	<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="project" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Project</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="task" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Task</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="expense" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Expense</a></li>
                  	<li class="divider"></li>
                  	<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="ongoing" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Ongoing Fee</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="service" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Service</a></li>
					<li class="divider"></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="todo" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW To Do</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="estimate" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Estimate</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="user" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW User</a></li>
					<li class="divider"></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="contact" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Contact</a></li>
					<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="campaign" data-adminact="new" data-editid=""><i class="fa fa-plus-square"></i> Add a NEW Campaign</a></li>
             	</ul>
             	<!-- /.dropdown-quicklinks -->
          	</li>
          	<!-- /.dropdown -->
          	
			<li class="dropdown">
            	<a class="dropdown-toggle" data-toggle="dropdown" href="#">
                 	<i class="fa fa-tasks fa-fw"></i>  <i class="fa fa-caret-down"></i>
             	</a>
            	'. $progress .'  	
          	</li>
          	<!-- /.dropdown -->
          	
			<li class="dropdown">
            	<a class="dropdown-toggle" data-toggle="dropdown" href="#">
                	<i class="fa fa-bell fa-fw"></i>  <i class="fa fa-caret-down"></i>
             	</a>
               	<ul class="dropdown-menu dropdown-alerts">
                	<li>
                    	<a href="#">
                        	<div>
                            	<i class="fa fa-comment fa-fw"></i> New Comment
                             	<span class="pull-right text-muted small">4 minutes ago</span>
                         	</div>
                    	</a>
                 	</li>
                  	<li class="divider"></li>
                  	<li>
                    	<a href="#">
                        	<div>
                            	<i class="fa fa-twitter fa-fw"></i> 3 New Followers
                              	<span class="pull-right text-muted small">12 minutes ago</span>
                         	</div>
                      	</a>
                  	</li>
                  	<li class="divider"></li>
                  	<li>
                    	<a href="#">
                        	<div>
                            	<i class="fa fa-envelope fa-fw"></i> Message Sent
                              	<span class="pull-right text-muted small">4 minutes ago</span>
                          	</div>
                      	</a>
                  	</li>
             	</ul>
             	<!-- /.dropdown-alerts -->
          	</li>
          	<!-- /.dropdown -->
            
			<li class="dropdown">
            	<a class="dropdown-toggle" data-toggle="dropdown" href="#">
                	<i class="fa fa-user fa-fw"></i>  <i class="fa fa-caret-down"></i>
              	</a>
                <ul class="dropdown-menu dropdown-user">
                	<li><a href="#"><i class="fa fa-user fa-fw"></i> User Profile</a></li>
                 	<li><a href="#" class="admin" data-toggle="modal" data-target="#adminModal" data-admintype="user" data-adminact="edit" data-editid="' . $_SESSION['userID'] . '" title="Edit Settings"><i class="fa fa-gear fa-fw"></i> Settings</a></li>
                 	<li class="divider"></li>
                  	<li><a href="'. $logoutLink .'"><i class="fa fa-sign-out fa-fw"></i> Logout</a></li>
             	</ul>
              	<!-- /.dropdown-user -->
         	</li>
          	<!-- /.dropdown -->
       	</ul>
     	<!-- /.navbar-top-links -->

     	<div class="navbar-default sidebar" role="navigation">
        	<div class="sidebar-nav navbar-collapse">
           		<ul class="nav" id="side-menu">
					<li class="sidebar-search">
                    	<div class="input-group custom-search-form">
                        	<input type="text" class="form-control" placeholder="Search...">
                          	<span class="input-group-btn">
								<button class="btn btn-default" type="button">
									<i class="fa fa-search"></i>
								</button>
                            </span>
               			</div>
                  	</li>
					<li>
                    	<a href="index.php"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
                 	</li>
					'. $mainnav .'
              	</ul>
          	</div>
          	<!-- /.sidebar-collapse -->
     	</div>
     	<!-- /.navbar-static-side -->
  	</nav>';

?>