<?php

/**
* @package Clients
*/
class Clients_menu extends NE_MenuHook
{
    var $modulesViews = array(
        array('clients', 'ViewAllUsers'),
        array('clients', 'AddClient'),
        array('clients', 'ViewPendingUsers'),
        array('clients', 'ViewActiveUsers'),
        array('clients', 'ViewDeletedUsers'),
        array('clients', 'ViewInactiveUsers'),
        array('clients', 'ViewFraudUsers'),
        array('clients', 'ViewGuestUsers'),
        array('clients', 'AddDomain'),
        array('clients', 'ShowDomainData'),
        array('clients', 'ShowEmail'),
        array('clients', 'ViewInvoices'),        
        array('clients', 'AddInvoice'),
        array('clients', 'ViewUnInvoicedWork'),
        array('clients', 'ViewInvoiceEntry'),
        array('clients', 'DeleteClient'),
        array('clients', 'ShowCustomerData'),
        array('clients', 'SaveNewClient'),
        array('clients', 'Clients_ViewEventLog'),
        array('clients', 'ViewDomains'),
        array('clients', 'ViewManageDomain'),
    );

    var $menuDescription = /*T*/'Profile, packages and billing info'/*/T*/;

    function getMenuArr()
    {
        $tArray = array();
        $tSubArray = array();
        $navlinks = array();
        $options = false;

        if (NE_Lib::isPublicDir() && $this->user->isAdmin()) {
            return;
        }

		if ($this->user->isAdmin() && $this->user->hasPermission('clients_view_customers')) {
			if ($this->action == 'ViewAllUsers') {
				$tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ViewAllUsers\" class='sel'>".strtolower($this->user->lang("client list"))."</a>";
				$tSubArray[1] = 0;
				$tArray[] = $tSubArray;
			}else{
				$tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ViewAllUsers\" >".strtolower($this->user->lang("client list"))."</a>";
				$tSubArray[1] = 0;
				$tArray[] = $tSubArray;
			}
		}

		if ($this->user->isAdmin() && $this->user->hasPermission('clients_create_customers')) {
			//show active users			
			if ($this->action == 'AddClient') {				
				$tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=AddClient\" class='sel'>".strtolower($this->user->lang("Add Client"))."</a>";
				$tSubArray[1] = 0;
				$tArray[] = $tSubArray;				
			} else {
				$tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=AddClient\" >".strtolower($this->user->lang("Add Client"))."</a>";
				$tSubArray[1] = 0;
				$tArray[] = $tSubArray;
			}
		}



		//show seperater for active customer menu items if customer has been selected
		if ($this->customer && !$this->customer->isGuest() && ($this->user->isAdmin())) {
				$tSubArray[0] = "<div style='padding-top:2px;padding-bottom:2px;text-align:center;'>-----------------</div>";
				$tSubArray[1] = 0;
				$tArray[] = $tSubArray;
		}


        if ($this->customer && !$this->customer->isGuest()) {				
            if ($this->action== 'ShowCustomerData'){
                $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ShowCustomerData\"  class='sel'>".strtolower($this->user->lang('profile'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }else{
                $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ShowCustomerData\">".strtolower($this->user->lang('profile'))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
        }
        

        if($this->customer && !$this->customer->isGuest()) {
            
            //if we have 1 or more packages 
            if ($this->configuration['framework']['appName'] == 'ClientExec') {
                if ($this->user->hasPermission('clients_view_domains') && !$this->user->isAnonymous()) {
                    if ($this->action == 'ShowDomainData') {
                        $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ShowDomainData\"  class='sel'>".$this->user->lang("packages")."</a>";
                        $tSubArray[1] = 0;
                        $tArray[] = $tSubArray;
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowDomainData\" >".$this->user->lang("packages")."</a>";
                        $tSubArray[1] = 0;
                        $tArray[] = $tSubArray;
                    }
                }					
            }
            
//            if ($this->user->hasPermission('clients_create_customer_packages')) {
//                if ($this->action == 'AddDomain') {
//                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=AddDomain\"  class='sel'>".$this->user->lang("add package")."</a>";
//                    $tSubArray[1] = 0;
//                    $tArray[] = $tSubArray;
//                } else {
//                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=AddDomain\" >".$this->user->lang("add package")."</a>";
//                    $tSubArray[1] = 0;
//                    $tArray[] = $tSubArray;
//                }
//            }
            
            if($this->user->hasPermission('billing_view')){
                if ($this->action == 'ViewInvoices') {
                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ViewInvoices\"  class='sel'>".$this->user->lang("invoices")."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ViewInvoices\" >".$this->user->lang("invoices")."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
            }
            
            if (isset($this->configuration['modules']['domains']['installedVersion']) && $this->user->hasPermission('domains_view')){
                if ($this->action == 'ViewDomains' || $this->action == 'ViewManageDomain') {
                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ViewDomains\"  class='sel'>".$this->user->lang("domains")."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ViewDomains\" >".$this->user->lang("domains")."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
            }
            
//            if($this->user->hasPermission('billing_create_invoice')){
//                if ($this->action == 'AddInvoice') {
//                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=AddInvoice\"  class='sel'>".$this->user->lang("add invoice")."</a>";
//                    $tSubArray[1] = 0;
//                    $tArray[] = $tSubArray;
//                } else {
//                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=AddInvoice\" >".$this->user->lang("add invoice")."</a>";
//                    $tSubArray[1] = 0;
//                    $tArray[] = $tSubArray;
//                }
//            }
            
            if ($this->user->hasPermission('clients_email_customers')) {
                if ($this->action == 'ShowEmail') {
                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ShowEmail\"  class='sel'>".strtolower($this->user->lang("E-mail Client"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowEmail\" >".strtolower($this->user->lang("E-mail Client"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
            }
            
            if ($this->user->hasPermission('clients_view_eventlog')) {
                if ($this->action == 'Clients_ViewEventLog') {
                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=Clients_ViewEventLog\"  class='sel'>".strtolower($this->user->lang("event log"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=Clients_ViewEventLog\" >".strtolower($this->user->lang("event log"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
            }
        }

        //*******************************************************
        //SUBMENU ITEMS
        //*******************************************************
        
        //ClientList SubMenu
        if ($this->user->isAdmin()){
            if (($this->action== 'ViewPendingUsers')||
                    ($this->action== 'ViewDeletedUsers')||
                    ($this->action== 'ViewActiveUsers')||
                    ($this->action== 'ViewAllUsers')||
                    ($this->action== 'ViewFraudUsers')||
                    ($this->action== 'ViewGuestUsers')||
                    ($this->action== 'ViewInactiveUsers'))
            {
                $tSubArray[0] = strtolower($this->user->lang("client list"));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
            }
        }
        

        //*******************************************************
        // Selected Client Sub Menus
        //*******************************************************
        if (($this->action != 'ViewPendingUsers')&&
                ($this->action != 'ViewDeletedUsers')&&
                ($this->action != 'ViewActiveUsers')&&
                ($this->action != 'ViewAllUsers')&&
                ($this->action != 'ViewFraudUsers')&&
                ($this->action != 'ViewGuestUsers')&&
                ($this->action != 'ViewInactiveUsers'))
            { 
        
            //profile submenu item          
            $url = "<a href='index.php?fuse=clients&amp;view=ShowCustomerData'>".strtolower($this->user->lang("profile"))."</a>";
            if (in_array($this->action, array( 'AddClient',
                                               'ShowCustomerData')))
            {        
                //Active submenu item    
                $tSubArray[0] = $url;
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
            } else{
                //InActive submenu item
                $tSubArray[0] = $url;
                $tSubArray[1] = 1;
                $tSubArray[2] = 0;
                $tArray[] = $tSubArray;
            }
            
            //show package sub menu item
            if ($this->action != 'AddClient' && $this->action != 'ViewPendingUsers') {                
                if ($this->customer && !$this->customer->isGuest() && $this->action!= 'ViewActiveUsers') {
                    $url = "<a href='index.php?fuse=clients&amp;view=ShowDomainData'>".$this->user->lang("packages")."</a>";
                    if ($this->user->hasPermission('clients_view_domains'))
                    {
                        if (in_array($this->action, array( 'ShowDomainData',
                                            'AddDomain')))                          
                        {
                            //Active submenu item
                            $tSubArray[0] = $url;
                            $tSubArray[1] = 1;
                            $tSubArray[2] = 1;
                            $tArray[] = $tSubArray;
                            $navlinks[] = $tSubArray[0];
                        } else {
                            //InActive submenu item
                            $tSubArray[0] = $url;
                            $tSubArray[1] = 1;
                            $tSubArray[2] = 0;
                            $tArray[] = $tSubArray;
                        }
                    }
                }
                
                //show invoice sub menu item            
                if ($this->customer && $this->user->hasPermission('billing_view')){
                    $url = "<a href='index.php?fuse=clients&amp;view=ViewInvoices'>".$this->user->lang("invoices")."</a>";
                    if (in_array($this->action, array( 'ViewInvoices',
                                                       'ViewInvoiceEntry',
                                                       'ViewUnInvoicedWork')))  
                    {
                        //Active submenu item
                        $tSubArray[0] = $url;
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        //InActive submenu item
                        $tSubArray[0] = $url;
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }                         
                } 
                
                //show domain sub menu item            
                if ($this->customer && isset($this->configuration['modules']['domains']['installedVersion']) && $this->user->hasPermission('domains_view')){
                    $url = "<a href='index.php?fuse=clients&amp;view=ViewDomains'>".$this->user->lang("domains")."</a>";
                    if (in_array($this->action, array( 'ViewDomains',
                                                       'ViewManageDomain')))  
                    {
                        //Active submenu item
                        $tSubArray[0] = $url;
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        //InActive submenu item
                        $tSubArray[0] = $url;
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }                         
                } 
                
                if ($this->action != 'AddClient' && $this->action != 'ViewPendingUsers') {                    
                    if ($this->customer && $this->user->hasPermission('clients_email_customers')) {
                        $url = "<a href='index.php?fuse=clients&amp;view=ShowEmail'>".strtolower($this->user->lang("E-mail"))."</a>";
                        if (($this->action!= 'AddClient')) {
                            if ($this->action== 'ShowEmail') {
                                //Active submenu item
                                $tSubArray[0] = $url;
                                $tSubArray[1] = 1;
                                $tSubArray[2] = 1;
                                $tArray[] = $tSubArray;
                                $navlinks[] = $tSubArray[0];
                            } else {
                                //InActive submenu item
                                $tSubArray[0] = $url;
                                $tSubArray[1] = 1;
                                $tSubArray[2] = 0;
                                $tArray[] = $tSubArray;
                            }
                        }
                    }
                    
                    if ($this->user->hasPermission('clients_view_eventlog')) {
                        $url = "<a href='index.php?fuse=clients&amp;view=Clients_ViewEventLog'>".strtolower($this->user->lang("event log"))."</a>";
                        if ($this->action == 'Clients_ViewEventLog') {
                            //Active submenu item
                            $tSubArray[0] = $url;
                            $tSubArray[1] = 1;
                            $tSubArray[2] = 1;
                            $tArray[] = $tSubArray;
                            $navlinks[] = $tSubArray[0];
                        } else {
                            //InActive submenu item
                            $tSubArray[0] = $url;
                            $tSubArray[1] = 1;
                            $tSubArray[2] = 0;
                            $tArray[] = $tSubArray;
                        }
                    }
                }
            }//end check to see if pending user            
        }

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

    }
}


?>
