<?php

/**
* @package Admin
*/
class Admin_menu extends NE_MenuHook
{
    function Admin_menu($action, &$user, &$customer)
    {
        parent::NE_MenuHook($action, $user, $customer);

        $this->modulesViews['Support']  = array(
                                            array('admin', 'ViewSettings&amp;group=support'),
                                            array('admin', 'ViewSettings'),
                                            array('support', 'ViewTicketTypes'),
                                            array('support', 'AddEditTicketType'),
                                            array('support', 'ViewEmailRoutings'),
                                            array('support', 'AddEditEmailRouting'),
                                            array('support', 'ViewEscalations'),
                                            array('support', 'AddEditEscalation'),
                                            array('support', 'ViewAutoresponderTemplates'),
                                            array('support', 'ViewDepartments'),
                                            array('support', 'KB_manageArticlesView'),
                                            array('support', 'AddEditDepartment'),
                                          );

        $this->modulesViews['Billing'] = array(
                                            array('admin', 'ViewSettings&amp;group=invoicing'),
                                            array('admin', 'ViewSettings'),
                                            array('admin', 'ListCoupons'),
                                            array('admin', 'ArchivedCoupons'),
                                            array('admin', 'AddCoupon'),
                                            array('admin', 'EditCoupon'),
                                            array('admin', 'ShowCurrencyOverview'),
                                            array('admin', 'ShowAddCurrency'),
                                            array('admin', 'ShowEditCurrency'),
                                            array('admin', 'ShowTaxOverview'),
                                            array('admin', 'ShowAddTaxRules'),
                                            array('admin', 'RecurringSettings'),
                                            array('admin', 'RunningRecurringActions'),
                                            array('admin', 'CompletedRunningRecurringActions'),
                                            array('admin', 'ThirdPartyBilling'),
                                            array('billing', 'ShowBillingTypes'),
                                            array('billing', 'AddBillingType'),
                                        );
        $this->modulesViews['System setup'] = array(
                                                array('admin', 'ViewAdminList'),
                                                array('admin', 'AccountSettings'),
                                                array('admin', 'ShowAddAdmin'),
                                                array('admin', 'EditAddAdminAccount'),
                                                array('admin', 'ViewGeneralGroups'),
                                                array('admin', 'AddEditGeneralGroup'),
                                                array('admin', 'ViewCustomerGroups'),
                                                array('admin', 'AddEditCustomerGroup'),
                                                array('admin', 'DisplayPassphraseInfo'),
                                                array('admin', 'DisplayEncryptDomainPasswords'),
                                                array('admin', 'ViewServers'),
                                                array('admin', 'ShowAddNewServer'),
                                                array('admin', 'PlanSettings'),
                                                array('admin', 'EditPackage'),
                                                array('admin', 'AddPlan'),
                                                array('admin', 'ShowCustomFields'),
                                                array('admin', 'ShowTldOverview'),
                                                array('admin', 'ViewSettings&amp;group=passwords_strength'),
                                                array('admin', 'ViewSettings'),
                                                array('admin', 'Fraud'),
                                                array('admin', 'Services'),
                                                array('admin', 'Affiliates'),
                                                array('admin', 'PhoneVerification'),
                                                array('admin', 'Registrars'),
                                              );
    }

    function getMenuArr()
    {
	$menus=array();
	if (isset($this->configuration['modules']['support']['installedVersion'])) {
		$menus['Support'] = array(
                                        'modulesViews'  => $this->modulesViews['Support'],
                                        'menuArr'       => $this->_getSupportOptionsMenu(),
                                    );	
	}
	$menus['Billing'] = array(
                                        'modulesViews'  => $this->modulesViews['Billing'],
                                        'menuArr'       => $this->_getBillingOptionsMenu(),
                                    );
	$menus['System setup']      = array(
                                        'modulesViews'  => $this->modulesViews['System setup'],
                                        'menuArr'       => $this->_getSystemSetupMenu(),
                                    );
        return $menus;
    }

    function _getSupportOptionsMenu()
    {
        $tArray = array();
        $tSubArray = array();
        $navlinks = array();

        if ($this->user->hasPermission('admin_edit_settings')) {
            if ($this->action== 'ViewSettings' && $_GET['group'] == 'support') {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=support\" class='sel'>".strtolower($this->user->lang('Support settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                $tSubArray[0] = strtolower($this->user->lang('Support settings'));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=support\">".strtolower($this->user->lang('Support settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('support_show_departments')) {
            if (in_array($this->action, array('ViewDepartments', 'AddEditDepartment'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewDepartments\" class='sel'>".strtolower($this->user->lang("Departments"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->action== 'ViewDepartments') {
                    $tSubArray[0] = strtolower($this->user->lang("Departments"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewDepartments\">".strtolower($this->user->lang('Departments'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->user->hasPermission('support_edit_departments')) {
                    if ($this->action == 'AddEditDepartment' && (!isset($_GET['department']) || $_GET['department'] == 0)) {
                        $tSubArray[0] = strtolower($this->user->lang('Adding Department'));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=AddEditDepartment\">".strtolower($this->user->lang('Add department'))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }

                    if ($this->action== 'AddEditDepartment' && isset($_GET['department']) && $_GET['department'] != 0) {
                        $tSubArray[0] = strtolower($this->user->lang("Editing department"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    }
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewDepartments\" >".strtolower($this->user->lang("Departments"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('support_show_escalations')) {
            if (in_array($this->action, array('ViewEscalations', 'AddEditEscalation'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewEscalations\" class='sel'>".strtolower($this->user->lang("Escalations"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->action== 'ViewEscalations') {
                    $tSubArray[0] = strtolower($this->user->lang("Escalation"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewEscalations\">".strtolower($this->user->lang('Escalation'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->user->hasPermission('support_edit_escalations')) {
                    if ($this->action == 'AddEditEscalation' && (!isset($_GET['escalationRule']) || $_GET['escalationRule'] == 0)) {
                        $tSubArray[0] = strtolower($this->user->lang('Adding Escalation Rule'));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=AddEditEscalation\">".strtolower($this->user->lang('Add Escalation Rule'))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }

                    if ($this->action== 'AddEditEscalation' && isset($_GET['escalationRule']) && $_GET['escalationRule'] != 0) {
                        $tSubArray[0] = strtolower($this->user->lang("Editing Escalation Rule"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    }
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewEscalations\" >".strtolower($this->user->lang("Escalation"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('support_show_emailroutings')) {
            if (in_array($this->action, array('ViewEmailRoutings', 'AddEditEmailRouting', 'ViewAutoresponderTemplates'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewEmailRoutings\" class='sel'>".strtolower($this->user->lang('Support routing'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->action== 'ViewEmailRoutings') {
                    $tSubArray[0] = strtolower($this->user->lang('Support routing'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewEmailRoutings\">".strtolower($this->user->lang('Support routing'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->user->hasPermission('support_edit_emailroutings')) {
                    if ($this->action == 'AddEditEmailRouting' && (!isset($_GET['routing']) || $_GET['routing'] == 0)) {
                        $tSubArray[0] = strtolower($this->user->lang('Adding support routing rule'));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=AddEditEmailRouting\">".strtolower($this->user->lang('Add support routing rule'))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }

                    if ($this->action== 'AddEditEmailRouting' && isset($_GET['routing']) && $_GET['routing'] != 0) {
                        $tSubArray[0] = strtolower($this->user->lang("Editing support routing rule"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    }
                }

                if ($this->user->hasPermission('admin_edit_autoresponders')) {
                    if ($this->action== 'ViewAutoresponderTemplates') {
                        $tSubArray[0] = strtolower($this->user->lang("Autoresponder templates"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewAutoresponderTemplates\">".strtolower($this->user->lang('Autoresponder templates'))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewEmailRoutings\" >".strtolower($this->user->lang("Support routing"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('support_show_tickettypes')) {
            if (in_array($this->action, array('ViewTicketTypes', 'AddEditTicketType'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewTicketTypes\" class='sel'>".strtolower($this->user->lang("Ticket types"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->action== 'ViewTicketTypes') {
                    $tSubArray[0] = strtolower($this->user->lang("Ticket types"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewTicketTypes\">".strtolower($this->user->lang('Ticket types'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->user->hasPermission('admin_edit_tickettypes')) {
                    if ($this->action == 'AddEditTicketType' && (!isset($_GET['ticketTypeId']) || $_GET['ticketTypeId'] == 0)) {
                        $tSubArray[0] = strtolower($this->user->lang('Adding ticket type'));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=AddEditTicketType\">".strtolower($this->user->lang('Add ticket type'))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }

                    if ($this->action== 'AddEditTicketType' && isset($_GET['ticketTypeId']) && $_GET['ticketTypeId'] != 0) {
                        $tSubArray[0] = strtolower($this->user->lang("Editing ticket type"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    }
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=support&amp;view=ViewTicketTypes\" >".strtolower($this->user->lang('Ticket types'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if (isset($this->configuration['modules']['knowledgebase']['installedVersion'])) {

            $tSubArray[0] = '<hr style="margin:5px 3px" />';
            $tSubArray[1] = 0;
            $tArray[] = $tSubArray;
                
            if ($this->user->hasPermission('admin_edit_settings')) {
                if ($this->action== 'ViewSettings' && $_GET['group'] == 'knowledgebase') {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=knowledgebase\" class='sel'>".strtolower($this->user->lang('KB settings'))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;

                    $tSubArray[0] = strtolower($this->user->lang('KB settings'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=knowledgebase\">".strtolower($this->user->lang('KB settings'))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
            }
        }

       return array('navlinks' => $navlinks, 'menus' => $tArray);
    }

    function _getBillingOptionsMenu()
    {
        $tArray = array();
        $tSubArray = array();
        $navlinks = array();

        if ($this->user->hasPermission('admin_edit_settings')) {
            if ($this->action== 'ViewSettings' && $_GET['group'] == 'invoicing') {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=invoicing\" class='sel'>".strtolower($this->user->lang('Billing settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                $tSubArray[0] = strtolower($this->user->lang('Billing settings'));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=invoicing\">".strtolower($this->user->lang('Billing settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_manage_plugins')) {
           if ($this->action== 'ThirdPartyBilling'){
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ThirdPartyBilling\" class='sel'>".strtolower($this->user->lang('Payment processors'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                $tSubArray[0] = strtolower($this->user->lang("Payment processors"));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
           } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ThirdPartyBilling\">".strtolower($this->user->lang('Payment processors'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
           }
        }

        if ($this->user->hasPermission('admin_view_coupons')) {
            if (in_array($this->action, array('ListCoupons', 'ArchivedCoupons','AddCoupon', 'EditCoupon'))) {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ListCoupons\" class='sel'>".strtolower($this->user->lang('coupons'))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;

                 $navlinks[] = $tSubArray[0];

                 // coupons list
                 if ($this->action== 'ListCoupons') {
                     $tSubArray[0] = strtolower($this->user->lang('Coupons list'));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ListCoupons\">".strtolower($this->user->lang('Coupons list'))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }
                 
                 if ($this->action== 'ArchivedCoupons') {
                     $tSubArray[0] = strtolower($this->user->lang('Archived Coupons'));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ArchivedCoupons\">".strtolower($this->user->lang('Archived Coupons'))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }

                 if ($this->user->hasPermission('admin_edit_coupons')) {
                     // add coupon
                     if ($this->action== 'AddCoupon') {
                         $tSubArray[0] = strtolower($this->user->lang('Add coupon'));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                     } else {
                         $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=AddCoupon\">".strtolower($this->user->lang('Add coupon'))."</a>";
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 0;
                         $tArray[] = $tSubArray;
                     }

                     // edit coupon
                     if ($this->action== 'EditCoupon') {
                         $tSubArray[0] = strtolower('edit coupon');
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                     }
                 }
            } else {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ListCoupons\" >".strtolower($this->user->lang('coupons'))."</a>" ;
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_show_currency_overview')) {
            if (in_array($this->action, array(  'ShowCurrencyOverview',
                                                'ShowAddCurrency',
                                                'ShowEditCurrency')))
        {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowCurrencyOverview\" class='sel'>".strtolower($this->user->lang("Currency"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];

                 //Currency Overview
                 if (($this->action== 'ShowCurrencyOverview')){
                     $tSubArray[0] = strtolower($this->user->lang("overview"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowCurrencyOverview\" >".strtolower($this->user->lang("overview"))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }

                 if ($this->user->hasPermission('admin_show_currency_overview')) {
                     //Currency Add
                     if ($this->action == 'ShowAddCurrency') {
                         $tSubArray[0] = strtolower($this->user->lang("Adding Currency"));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                     } else {
                         $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowAddCurrency\" >".strtolower($this->user->lang("Add Currency"))."</a>";
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 0;
                         $tArray[] = $tSubArray;
                     }
                     //Currency Edit
                     if ($this->action== 'ShowEditCurrency') {
                         $tSubArray[0] = strtolower($this->user->lang("Editing Currency"));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                     }
                 }
            } else {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowCurrencyOverview\" >".strtolower($this->user->lang("Currency"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_show_tax_overview')) {
            if (($this->action== 'ShowTaxOverview')||($this->action== 'ShowAddTaxRules')) {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowTaxOverview\" class='sel'>".strtolower($this->user->lang("Taxes"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];
                 if (($this->action== 'ShowTaxOverview')){
                     $tSubArray[0] = strtolower($this->user->lang("overview"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowTaxOverview\" >".strtolower($this->user->lang("overview"))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }

                 //tax rule addition screen
                 if ($this->action== 'ShowAddTaxRules') {
                     $tSubArray[0] = strtolower($this->user->lang("Add Tax Rule"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowAddTaxRules\" >".strtolower($this->user->lang("Add Tax Rule"))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }

            } else {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowTaxOverview\" >".strtolower($this->user->lang("Taxes"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('billing_show_billing_types')) {
            if (in_array($this->action, array("ShowBillingTypes", "AddBillingType"))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ShowBillingTypes\" class='sel' >"
                    .strtolower($this->user->lang("Billing types"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                if ($this->action == "ShowBillingTypes") {
                    $tSubArray[0] = strtolower($this->user->lang("Viewing Billing Types"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = strtolower($this->user->lang("Creating a new Billing Type"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ShowBillingTypes\" >"
                    .strtolower($this->user->lang("Billing types"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
            $options = true;
        }

        if ($this->user->hasPermission('billing_generate_invoices')) {
            if (in_array($this->action, array(  'CompletedRunningRecurringActions',
                                                'RecurringSettings',
                                                'RunningRecurringActions')))
            {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=RecurringSettings\" class='sel'>".strtolower($this->user->lang("Process invoices"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];

                 if (($this->action== 'RecurringSettings')||($this->action== 'CompletedRunningRecurringActions')){
                     $tSubArray[0] = strtolower($this->user->lang("Process invoices"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=RecurringSettings\" >".strtolower($this->user->lang("Process invoices"))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }
                 //only show when running actions
                 if ($this->action== 'RunningRecurringActions'){
                     $tSubArray[0] = strtolower($this->user->lang("Running Recurring Actions"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 }
            } else {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=RecurringSettings\" >".strtolower($this->user->lang("Process invoices"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
            }
        }

        return array('navlinks' => $navlinks, 'menus' => $tArray);
    }

    function _getSystemSetupMenu()
    {
        $tArray = array();
        $tSubArray = array();
        $navlinks = array();

        if ($this->user->getGroupId() == ROLE_SUPERADMIN) {
            if (in_array($this->action, array('ShowAddAdmin', 'ViewAdminList', 'EditAddAdminAccount', 'ViewGeneralGroups', 'AddEditGeneralGroup'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewAdminList\" class='sel'>".strtolower($this->user->lang("Staff management"))."</a>";
                $tSubArray[1] = 0;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->action== 'ViewAdminList') {
                    $tSubArray[0] = strtolower($this->user->lang("Viewing Staff"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewAdminList\" >".strtolower($this->user->lang('View Staff'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->action== 'ShowAddAdmin') {
                    $tSubArray[0] = strtolower($this->user->lang("Adding staff"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowAddAdmin\" >".strtolower($this->user->lang('Add staff'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->action== 'EditAddAdminAccount') {
                    $tSubArray[0] = strtolower($this->user->lang("Editing Staff"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                }

                if ($this->action=='ViewGeneralGroups') {
                    $tSubArray[0] = strtolower($this->user->lang("Access groups"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewGeneralGroups\" >".$this->user->lang("Access groups")."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->action=='AddEditGeneralGroup' && (!isset($_GET['group']) || $_GET['group'] == 0)) {
                    $tSubArray[0] = strtolower($this->user->lang("Adding access group"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=AddEditGeneralGroup\" >".$this->user->lang("Add access group")."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->action== 'AddEditGeneralGroup' && isset($_GET['group']) && $_GET['group'] != 0) {
                    $tSubArray[0] = strtolower($this->user->lang("Editing access group"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                }

            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewAdminList\" >".strtolower($this->user->lang("Staff management"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->isAdmin() && $this->action == 'AccountSettings') {
            if ($this->action== 'AccountSettings'){
               $tSubArray[0] = $this->user->lang("view my profile");
               $tSubArray[1] = 1;
               $tSubArray[2] = 1;
               $tArray[] = $tSubArray;
               $navlinks[] = $tSubArray[0];
            }
        }

        if ($this->user->hasPermission('admin_show_customergroups')) {
            if (in_array($this->action, array('ViewCustomerGroups', 'AddEditCustomerGroup'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewCustomerGroups\" class='sel'>".strtolower($this->user->lang("Customer groups"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->action == 'ViewCustomerGroups') {
                    $tSubArray[0] = strtolower($this->user->lang("Customer groups"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewCustomerGroups\">".strtolower($this->user->lang('Customer groups'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($this->user->hasPermission('admin_edit_customergroups')) {
                    if ($this->action == 'AddEditCustomerGroup' && (!isset($_GET['groupId']) || $_GET['groupId'] == 0)) {
                        $tSubArray[0] = strtolower($this->user->lang('Adding customer group'));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=AddEditCustomerGroup\">".strtolower($this->user->lang('Add customer group'))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }

                    if ($this->action== 'AddEditCustomerGroup' && isset($_GET['groupId']) && $_GET['groupId'] != 0) {
                        $tSubArray[0] = strtolower($this->user->lang("Editing customer group"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    }
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewCustomerGroups\" >".strtolower($this->user->lang("Customer groups"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_edit_servers')) {
            if (in_array($this->action, array('ViewServers', 'ShowAddNewServer'))) {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewServers\" class='sel'>".strtolower($this->user->lang('Servers'))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;

                 $navlinks[] = $tSubArray[0];

                 if ($this->action== 'ViewServers'){
                     $tSubArray[0] = strtolower($this->user->lang("Servers"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewServers\">".strtolower($this->user->lang('Servers'))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }

                 if ($this->action== 'ShowAddNewServer'){
                    $tSubArray[0] = strtolower($this->user->lang("Adding Server"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowAddNewServer\">".strtolower($this->user->lang('Add new server'))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }

            } else {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewServers\" >".strtolower($this->user->lang('Servers'))."</a>" ;
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_view_packagetypes')) {
            if (in_array($this->action, array(  'PlanSettings',
                                                'EditPackage',
                                                'AddPlan')))
            {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=PlanSettings\" class='sel'>".strtolower($this->user->lang("Package mgmt"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];

                 if ($this->action== 'PlanSettings') {
                    $tSubArray[0] = strtolower($this->user->lang("Viewing Package"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                 } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=PlanSettings\" >".strtolower($this->user->lang("View Package"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                 }

                if ($this->user->hasPermission('admin_edit_packagetypes')) {
                    if ($this->action== 'AddPlan') {
                         $tSubArray[0] = strtolower($this->user->lang("Create Package Type"));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                    } else {
                         $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=AddPlan\" >".strtolower($this->user->lang("Create Package Type"))."</a>";
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 0;
                         $tArray[] = $tSubArray;
                    }
                    if ($this->action== 'EditPackage' && isset($_GET['packageid']) && $_GET['packageid'] != 0) {
                         $tSubArray[0] = strtolower($this->user->lang("Edit Package"));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                    }
                    if ($this->action== 'EditPackage' && (!isset($_GET['packageid']) || $_GET['packageid'] == 0)) {
                         $tSubArray[0] = strtolower($this->user->lang("Add Package"));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                    }
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=PlanSettings\" >".strtolower($this->user->lang("Package mgmt"))."</a>" ;
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_show_custom_fields')) {
            if (($this->action== 'ShowCustomFields')) {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowCustomFields\" class='sel'>".strtolower($this->user->lang("Custom user fields"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];

                 if ($this->action=='ShowCustomFields') {
                     $tSubArray[0] = strtolower($this->user->lang("Modify Custom Fields"));
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                 } else {
                     $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowCustomFields\">".strtolower($this->user->lang("Modify Custom Fields"))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                 }
            } else {
                 $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowCustomFields\" >".strtolower($this->user->lang("Custom user fields"))."</a>";
                 $tSubArray[1] = 0;
                 $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_edit_settings')) {
            if ($this->action == 'ViewSettings' && isset($_GET['group']) && in_array($_GET['group'], array('general', 'signup', 'dashboard', 'style'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=general\" class='sel'>".strtolower($this->user->lang('General settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                if ($_GET['group'] == 'general') {
                    $tSubArray[0] = strtolower($this->user->lang('Global'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=general\">".strtolower($this->user->lang("Global"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'signup') {
                    $tSubArray[0] = strtolower($this->user->lang('Signup'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=signup\">".strtolower($this->user->lang("Signup"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'dashboard') {
                    $tSubArray[0] = strtolower($this->user->lang('Dashboard'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=dashboard\">".strtolower($this->user->lang("Dashboard"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'style') {
                    $tSubArray[0] = strtolower($this->user->lang('Style'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=style\">".strtolower($this->user->lang("Style"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=general\">".strtolower($this->user->lang('General settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_edit_passphrase')) {
            if (    in_array($this->action, array('DisplayPassphraseInfo', 'DisplayEncryptDomainPasswords', 'Fraud', 'PhoneVerification'))
                    || ($this->action == 'ViewSettings' && isset($_GET['group']) && $_GET['group'] == 'passwords_strength'))
            {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&group=passwords_strength\" class='sel' >".strtolower($this->user->lang("Security settings"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                if ($this->user->getGroupId() == ROLE_SUPERADMIN) {
                    if ($this->action == 'ViewSettings' && isset($_GET['group']) && $_GET['group'] == 'passwords_strength') {
                        $tSubArray[0] = strtolower($this->user->lang('Passwords strength'));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=passwords_strength\" >".$this->user->lang('Passwords strength')."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }
                }

                if ($this->user->hasPermission('admin_edit_passphrase')) {
                    if ($this->action=='DisplayPassphraseInfo') {
                        $tSubArray[0] = strtolower($this->user->lang("Passphrase Management"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=DisplayPassphraseInfo\" >".$this->user->lang("Passphrase Management")."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }
                }

                if ($this->user->getGroupId() == ROLE_SUPERADMIN) {
                    if ($this->action=='DisplayEncryptDomainPasswords') {
                        $tSubArray[0] = strtolower($this->user->lang("Domain encryption"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=DisplayEncryptDomainPasswords\" >".$this->user->lang("Domain encryption")."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }
                }

                if ($this->user->hasPermission('admin_manage_plugins')) {
                   if ($this->action== 'Fraud'){
                       $tSubArray[0] = strtolower($this->user->lang("Fraud - plugins"));
                       $tSubArray[1] = 1;
                       $tSubArray[2] = 1;
                       $tArray[] = $tSubArray;
                       $navlinks[] = $tSubArray[0];
                   } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=Fraud\">".strtolower($this->user->lang("Fraud - plugins"))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                   }

                   if ($this->action== 'PhoneVerification'){
                       $tSubArray[0] = strtolower($this->user->lang("Phone verification"));
                       $tSubArray[1] = 1;
                       $tSubArray[2] = 1;
                       $tArray[] = $tSubArray;
                       $navlinks[] = $tSubArray[0];
                   } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=PhoneVerification\">".strtolower($this->user->lang("Phone verification"))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                   }
                }

            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&group=passwords_strength\" >".strtolower($this->user->lang("Security settings"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }
    
        if ($this->user->hasPermission('admin_edit_settings')) {
            if ($this->action == 'ViewSettings'
                && isset($_GET['group']) && in_array($_GET['group'], array('mailsettings', 'emailtemplatesbilling', 'emailtemplatesdomains', 'emailtemplatessupport', 'emailtemplatesother')))
            {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=mailsettings\" class='sel'>".strtolower($this->user->lang('E-mail settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                if ($_GET['group'] == 'mailsettings') {
                    $tSubArray[0] = strtolower($this->user->lang('E-mail settings'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=mailsettings\">".strtolower($this->user->lang('E-mail settings'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'emailtemplatesbilling') {
                    $tSubArray[0] = strtolower($this->user->lang('Billing E-mail templates'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=emailtemplatesbilling\">".strtolower($this->user->lang('Billing E-mail templates'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'emailtemplatesdomains') {
                    $tSubArray[0] = strtolower($this->user->lang('Domain E-mail templates'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=emailtemplatesdomains\">".strtolower($this->user->lang('Domain E-mail templates'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'emailtemplatessupport') {
                    $tSubArray[0] = strtolower($this->user->lang('Support E-mail templates'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=emailtemplatessupport\">".strtolower($this->user->lang('Support E-mail templates'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }

                if ($_GET['group'] == 'emailtemplatesother') {
                    $tSubArray[0] = strtolower($this->user->lang('Other E-mail templates'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=emailtemplatesother\">".strtolower($this->user->lang('Other E-mail templates'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=mailsettings\" >".strtolower($this->user->lang('E-mail settings'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->hasPermission('admin_show_tld_overview') || $this->user->hasPermission('admin_manage_plugins')) {
            if (in_array($this->action, array('ShowTldOverview', 'Registrars'))) {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowTldOverview\" class='sel'>".strtolower($this->user->lang("Domain settings"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];

                if ($this->user->hasPermission('admin_show_tld_overview')) {
                     if (($this->action== 'ShowTldOverview')){
                         $tSubArray[0] = strtolower($this->user->lang("TLD Extensions"));
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 1;
                         $tArray[] = $tSubArray;
                         $navlinks[] = $tSubArray[0];
                     } else {
                         $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowTldOverview\" >".strtolower($this->user->lang("TLD Extensions"))."</a>";
                         $tSubArray[1] = 1;
                         $tSubArray[2] = 0;
                         $tArray[] = $tSubArray;
                     }
                }

                if ($this->user->hasPermission('admin_manage_plugins')) {
                   if ($this->action=='Registrars'){
                        $tSubArray[0] = strtolower($this->user->lang("Registrars - plugins"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                   } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=Registrars\">".strtolower($this->user->lang("Registrars - plugins"))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                   }
                }

            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ShowTldOverview\">".strtolower($this->user->lang("Domain settings"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }

        if ($this->user->isAdmin()) {
            $this->_addCustomModulesSettings($tArray, $navlinks);
        }

        if ($this->user->hasPermission('admin_manage_plugins')) {
           if ($this->action== 'Services') {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=Services\" class='sel'>".strtolower($this->user->lang('Automation services'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                $tSubArray[0] = strtolower($this->user->lang('Automation services'));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
           } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=Services\">".strtolower($this->user->lang('Automation services'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
           }

           if ($this->action== 'Affiliates') {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=Affiliates\" class='sel'>".strtolower($this->user->lang('Affiliates - plugins'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                $tSubArray[0] = strtolower($this->user->lang('Affiliates - plugins'));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
           } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=Affiliates\">".strtolower($this->user->lang('Affiliates - plugins'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
           }
        }

        return array('navlinks' => $navlinks, 'menus' => $tArray);
    }

    function _addCustomModulesSettings(&$tArray, &$navlinks)
    {
        // @TODO: have in each hook class a class var that determines where these should go
        $defaultSettings = array('general', 'dashboard', 'style', 'mailsettings', 'invoicing', 'knowledgebase', 'support', 'emailtemplatesother', 'emailtemplatesdomains', 'emailtemplatessupport', 'emailtemplatesbilling', 'signup', 'passwords_strength');

        foreach ($this->settings->getSettingHooks() as $hookClass => $hookConfig) {
            if (in_array($hookConfig['internalName'], $defaultSettings)) {
                continue;
            }

            if ($this->action== 'ViewSettings' && $_GET['group'] == $hookConfig['internalName']) {
                $tSubArray = array();
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=".$hookConfig['internalName']."\" class='sel'>".strtolower($hookConfig['tabLabel'])."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;

                $tSubArray[0] = strtolower(strtolower($hookConfig['tabLabel']));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
            } else {
                $tSubArray[0] = "<a href=\"index.php?fuse=admin&amp;view=ViewSettings&amp;group=".$hookConfig['internalName']."\">".strtolower($hookConfig['tabLabel'])."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }
    }
}

?>
