<?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('Admin_Profile_Events','ShowEmail','ViewUsers','Admin_Profile_Contact','Admin_Profile_Accounts','Admin_Profile_Password','Admin_Profile_Billing','Admin_Profile_RecurringCharges','Admin_Profile_Notes','Admin_Profile_Domains','Admin_Profile_Products','Admin_Profile_Invoices','Admin_Profile_UnInvoiced'));
            $menuItem->addPermissions('clients_view_customers');
            $this->addItem($menuItem);

            //Domain List items
            $menuItem = new NE_MenuItem($this->user->lang("Domains List"), "index.php?fuse=domains&amp;view=ViewDomainsList");
            $menuItem->addViews('ViewDomainsList');
            $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) {
                    $fuse = "clients";
                    $view = "Admin_Profile_Invoices";
                    $varname = "invoiceid";
                    if (!$this->user->isAdmin() ) {
                        $fuse = "clients";
                        $varname = "billdetailid";
                        $view = "Invoice_View";
                    }

                    $menuItem = new NE_MenuItem($this->user->lang('Invoice').' #'.$invoiceid, "index.php?fuse=".$fuse."&amp;view=".$view."&amp;".$varname."=".$invoiceid);

                    if (!$this->user->isAdmin() ) {
                        $this->addItem($menuItem);
                    } else {
                        $this->tpl->setKey('openitemname', $menuItem->getURL());
                        $this->tpl->parse('openitem_out', '.openitem');
                    }
                }
            }

            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);
            }

            

        }
    }
}


?>
