<?php
$controller_name = $controller->_get->toString('controller');
$action_name = $controller->_get->toString('action');

// Dashboard
$isScriptDashboard = in_array($controller_name, array('pjAdmin')) && in_array($action_name, array('pjActionIndex'));

// Bookings
$isScriptBookingsController = in_array($controller_name, array('pjAdminBookings'));
$isScriptBookingsList 			= $isScriptBookingsController && in_array($controller_name, array('pjActionIndex'));
// Export Bookings
$isScriptExportBookings 			= in_array($controller_name, array('pjActionExportBookings'));

// Parking Spaces
$isScriptSpaces 			= in_array($controller_name, array('pjAdminSpaces'));
$isScriptPrices 	= in_array($controller_name, array('pjAdminPrices'));
$isScriptVouchersController = in_array($controller_name, array('pjVouchers'));
$isScriptExtras 		= in_array($controller_name, array('pjAdminExtras'));

// Payments
$isScriptPaymentsController = in_array($controller_name, array('pjPayments'));

// Settings
$isScriptOptionsController = in_array($controller_name, array('pjAdminOptions')) && !in_array($action_name, array('pjActionPreview', 'pjActionInstall'));

$isScriptOptionsBooking         = $isScriptOptionsController && in_array($action_name, array('pjActionBooking'));
$isScriptOptionsBookingForm     = $isScriptOptionsController && in_array($action_name, array('pjActionBookingForm'));
$isScriptOptionsTerm            = $isScriptOptionsController && in_array($action_name, array('pjActionTerm'));
$isScriptOptionsNotifications   = $isScriptOptionsController && in_array($action_name, array('pjActionNotifications'));

// Reports
$isScriptReports     			= in_array($controller_name, array('pjAdminReports'));

// Permissions - Dashboard
$hasAccessScriptDashboard = pjAuth::factory('pjAdmin', 'pjActionIndex')->hasAccess();

// Permissions - Bookings
$hasAccessScriptBookings          = pjAuth::factory('pjAdminBookings')->hasAccess();

// Permissions - Bookings List
$hasAccessScriptBookingsList         	  = pjAuth::factory('pjAdminBookings', 'pjActionIndex')->hasAccess();

// Permissions - Export Bookings
$hasAccessScriptExportBookings          	  = pjAuth::factory('pjAdminBookings', 'pjActionExportBookings')->hasAccess();

// Permissions - Parking Spaces
$hasAccessScriptSpaces          	  = pjAuth::factory('pjAdminSpaces', 'pjActionIndex')->hasAccess();

// Permissions - Prices
$hasAccessScriptPrices            = pjAuth::factory('pjAdminPrices', 'pjActionIndex')->hasAccess();

// Permissions - Discounts
$hasAccessScriptDiscounts           = pjAuth::factory('pjAdminPrices', 'pjActionDiscount')->hasAccess();

// Permissions - Vouchers
$hasAccessScriptVouchers = pjAuth::factory('pjVouchers')->hasAccess();

// Permissions - Extras
$hasAccessScriptExtras          	  = pjAuth::factory('pjAdminExtras')->hasAccess();

// Permissions - Settings
$hasAccessScriptOptions                 = pjAuth::factory('pjAdminOptions')->hasAccess();
$hasAccessScriptOptionsBooking          = pjAuth::factory('pjAdminOptions', 'pjActionBooking')->hasAccess();
$hasAccessScriptOptionsBookingForm      = pjAuth::factory('pjAdminOptions', 'pjActionBookingForm')->hasAccess();
$hasAccessScriptOptionsTerm             = pjAuth::factory('pjAdminOptions', 'pjActionTerm')->hasAccess();
$hasAccessScriptOptionsNotifications    = pjAuth::factory('pjAdminOptions', 'pjActionNotifications')->hasAccess();

// Permissions - Payments
$hasAccessScriptPayments = pjAuth::factory('pjPayments', 'pjActionIndex')->hasAccess();

// Permissions - Reports
$hasAccessScriptReports            	= pjAuth::factory('pjAdminReports', 'pjActionIndex')->hasAccess();

?>

<?php if ($hasAccessScriptDashboard): ?>
    <li<?php echo $isScriptDashboard ? ' class="active"' : NULL; ?>>
        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdmin&amp;action=pjActionIndex"><i class="fa fa-th-large"></i> <span class="nav-label"><?php __('plugin_base_menu_dashboard');?></span></a>
    </li>
<?php endif; ?>

<?php
$booking_action = NULL;
if($hasAccessScriptBookingsList)
{
    $booking_action = 'pjActionIndex';
}else if($hasAccessScriptExportBookings){
    $booking_action = 'pjActionExportBookings';
}
?>
<?php if ($hasAccessScriptBookings && $booking_action != NULL): ?>
    <li<?php echo $isScriptBookingsController ? ' class="active"' : NULL; ?>>
        <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminBookings&amp;action=<?php echo $booking_action; ?>"><i class="fa fa-list"></i> <span class="nav-label"><?php __('menuBookings');?></span></a>
    </li>
<?php endif; ?>

<?php if ($hasAccessScriptSpaces || $hasAccessScriptPrices || $hasAccessScriptDiscounts || $hasAccessScriptExtras || $hasAccessScriptVouchers): ?>
	<li<?php echo ($isScriptSpaces || $isScriptPrices || $isScriptExtras || $isScriptVouchersController) ? ' class="active"' : NULL; ?>>
		<a href="#"><i class="fa fa-inbox"></i> <span class="nav-label"><?php __('menuSpaces');?></span><span class="fa arrow"></span></a>
		<ul class="nav nav-second-level collapse">
			<?php if ($hasAccessScriptSpaces): ?>
				<li<?php echo $isScriptSpaces ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminSpaces&amp;action=pjActionIndex"><?php __('menuSpaces');?></a></li>
			<?php endif; ?>
			<?php if ($hasAccessScriptPrices || $hasAccessScriptDiscounts): ?>
				<li<?php echo $isScriptPrices ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminPrices&amp;action=<?php echo $hasAccessScriptPrices ? 'pjActionIndex' : 'pjActionDiscount';?>"><?php __('menuPrices');?></a></li>
			<?php endif; ?>			
			<?php if (pjObject::getPlugin('pjVouchers') !== NULL): ?>
			    <?php if ($hasAccessScriptVouchers): ?>
			        <li<?php echo $isScriptVouchersController ? ' class="active"' : NULL; ?>>
			            <a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjVouchers&amp;action=pjActionIndex"><?php __('plugin_vouchers_menu_vouchers');?></a>
			        </li>
			    <?php endif; ?>
			<?php endif; ?>			
			<?php if ($hasAccessScriptExtras): ?>
                <li<?php echo $isScriptExtras ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminExtras&amp;action=pjActionIndex"><?php __('menuExtras');?></a></li>
            <?php endif; ?>
		</ul>
	</li>
<?php endif; ?>

<?php if ($hasAccessScriptReports): ?>
    <li<?php echo $isScriptReports ? ' class="active"' : NULL; ?>>
    	<a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminReports&amp;action=pjActionIndex"><i class="fa fa-files-o"></i> <span class="nav-label"><?php __('menuReports');?></span></a>
    </li>
<?php endif; ?>

<?php if ($hasAccessScriptOptionsBooking || $hasAccessScriptPayments || $hasAccessScriptOptionsBookingForm || $hasAccessScriptOptionsNotifications || $hasAccessScriptOptionsTerm): ?>
    <li<?php echo $isScriptOptionsController || $isScriptPaymentsController ? ' class="active"' : NULL; ?>>
        <a href="#"><i class="fa fa-cog"></i> <span class="nav-label"><?php __('menuSettings');?></span><span class="fa arrow"></span></a>
        <ul class="nav nav-second-level collapse">
            <?php if ($hasAccessScriptOptionsBooking): ?>
                <li<?php echo $isScriptOptionsBooking ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionBooking"><?php __('settingsTabBookings');?></a></li>
            <?php endif; ?>

            <?php if ($hasAccessScriptPayments): ?>
                <li<?php echo $isScriptPaymentsController ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjPayments&amp;action=pjActionIndex"><?php __('settingsTabPayments');?></a></li>
            <?php endif; ?>

            <?php if ($hasAccessScriptOptionsBookingForm): ?>
                <li<?php echo $isScriptOptionsBookingForm ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionBookingForm"><?php __('settingsTabBookingForm');?></a></li>
            <?php endif; ?>

            <?php if ($hasAccessScriptOptionsNotifications): ?>
                <li<?php echo $isScriptOptionsNotifications ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionNotifications"><?php __('settingsTabNotifications');?></a></li>
            <?php endif; ?>

            <?php if ($hasAccessScriptOptionsTerm): ?>
                <li<?php echo $isScriptOptionsTerm ? ' class="active"' : NULL; ?>><a href="<?php echo $_SERVER['PHP_SELF']; ?>?controller=pjAdminOptions&amp;action=pjActionTerm"><?php __('settingsTabTerms');?></a></li>
            <?php endif; ?>

        </ul>
    </li>
<?php endif; ?>