<?php

/**
 * Clients Menu Hooks class
 * 
 * @package Clients
 */
class Clients_menu extends NE_MenuHook
{

    /**
     * function which display the client menus
     * 
     * @param object &$user     user reference
     * @param object &$customer customer reference
     * @param object &$tpl      tpl reference
     *
     * @return void
     */
    function Clients_menu(&$user, &$customer, &$tpl)
    {
        parent::NE_MenuHook($user, $customer, $tpl);

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

        if ($this->user->isAdmin() ) {
            //Client List
            $menuItem = new NE_MenuItem($this->user->lang("Client List"), "index.php?fuse=clients&amp;view=ViewUsers");
            $menuItem->addViews(array('ViewAdmin_Profile_Events','ShowEmail','ViewUsers','ViewAdmin_Profile_Contact','ViewAdmin_Profile_Accounts','ViewAdmin_Profile_Password','ViewAdmin_Profile_Billing','ViewAdmin_Profile_RecurringCharges','ViewAdmin_Profile_Notes','ViewAdmin_Profile_Domains','ViewAdmin_Profile_Products','ViewAdmin_Profile_Invoices','ViewAdmin_Profile_UnInvoiced','ViewMergeClient'));
            $menuItem->addPermissions('clients_view_customers');
            $this->addItem($menuItem);
            
            $menuItem = new NE_MenuItem($this->user->lang("Packages List"), "index.php?fuse=clients&amp;view=ViewPackagesList");
            $menuItem->addViews(array('ViewPackagesList','ViewDomainsList','ViewGeneralPackagesList'));
            $menuItem->addPermissions('clients_view_domains');
            $this->addItem($menuItem);
        }

        //if customer has been selected but we are not a guest(public) user
        if ($this->customer && !$this->customer->isGuest() ) {

            //Profile
            if (!$this->user->isAdmin() ) {
                $menuItem = new NE_MenuItem($this->user->lang("Profile"), "index.php?fuse=clients&amp;view=ShowCustomerData");
                $menuItem->addViews('ShowCustomerData');
                $this->addItem($menuItem);
            }

             //Show Orders if we have 1 or more packages
            if ($this->configuration['framework']['appName'] == 'ClientExec') {
                if (!$this->user->isAnonymous()&& !$this->user->isAdmin() ) {
                        $menuItem = new NE_MenuItem($this->user->lang("Packages"), "index.php?fuse=clients&amp;view=ShowDomainData");
                        $menuItem->addViews('ShowDomainData');
                        $menuItem->addPermissions('clients_view_domains');
                        $this->addItem($menuItem);
                }
            }

            //Invoices
            if (!$this->user->isAdmin() ) {
                $menuItem = new NE_MenuItem($this->user->lang("Invoices"), "index.php?fuse=clients&amp;view=ViewInvoices");
                $menuItem->addViews('ViewInvoices');
                $menuItem->addPermissions('billing_view');
                $this->addItem($menuItem);

                //only draw these if the customer is viewing otherwise we want to parse in the quicklinks
                if ($this->customer) {
                    $invoices = $this->customer->getUnpaidInvoices();
                    foreach ($invoices as $invoiceid) {
                        $menuItem = new NE_MenuItem($this->user->lang('Invoice').' #'.$invoiceid, "index.php?fuse=clients&amp;view=Invoice_View&amp;billdetailid=".$invoiceid);
                        $this->addItem($menuItem);
                    }
                }
            }


            if (isset($this->configuration['modules']['domains']['installedVersion']) && !$this->user->isAdmin()) {
                //Domains
                $menuItem = new NE_MenuItem($this->user->lang("Domains"), "index.php?fuse=clients&amp;view=ViewDomains");
                $menuItem->addViews(array('ViewDomains','ViewManageDomain'));
                $menuItem->addPermissions('domains_view');
                $this->addItem($menuItem);
            }

            

        }
    }
}


?>
