<?php

/**
* @package Billing
*/
class Billing_menu extends NE_MenuHook
{
    var $modulesViews = array(
        array('billing', 'ActiveInvoices'),
        array('billing', 'ViewArchivedInvoices'),
        array('billing', 'ViewUnInvoicedWork'),
        array('billing', 'CreateInvoiceEntry'),
        array('billing', 'ViewInvoiceEntryDetail'),
        array('billing', 'RecurringOverview'),
        array('billing', 'Billing_ViewEventLog'),
        array('billing', 'EditRecurringInvoice'),
    );
    function getMenuArr()
    {
        $tArray = array();
        $tSubArray = array();
        $navlinks = array();
        $options = false;
        
        if(!$this->user->isAnonymous()){
            if ($this->action == "ActiveInvoices"){
                $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ActiveInvoices\" class='sel'>"
                    .strtolower($this->user->lang("Active Invoices"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }else{
                 $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ActiveInvoices\" >"
                    .strtolower($this->user->lang("Active Invoices"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
            $options = true;
        }

        //drop down menu additions
        if ($this->customer && !$this->customer->isGuest()) {
            if ($this->user->hasPermission('billing_archived_invoices') && !$this->user->isAnonymous()) {
                if ($this->action == "ViewArchivedInvoices"){
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ViewArchivedInvoices\" class='sel'>"
                        .strtolower($this->user->lang("Archived Invoices"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }else{
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ViewArchivedInvoices\">"
                        .strtolower($this->user->lang("Archived Invoices"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            if ($this->user->hasPermission('billing_uninvoiced_work')) {
                if ($this->action == "ViewUnInvoicedWork"){
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ViewUnInvoicedWork\" class='sel'>"
                        .strtolower($this->user->lang("Uninvoiced Work"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }else{
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ViewUnInvoicedWork\">"
                        .strtolower($this->user->lang("Uninvoiced Work"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            if ($this->user->hasPermission('billing_create')) {
                if ($this->action == "CreateInvoiceEntry"){
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=CreateInvoiceEntry\" class='sel'>"
                        .strtolower($this->user->lang("create invoice"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }else{
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=CreateInvoiceEntry\">"
                        .strtolower($this->user->lang("create invoice"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            if ($this->user->hasPermission('billing_recurring_overview') && !$this->user->isAnonymous()) {
                if ($this->action == "RecurringOverview"){
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=RecurringOverview\" class='sel'>"
                        .strtolower($this->user->lang("Recurring"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }else{
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=RecurringOverview\">"
                        .strtolower($this->user->lang("Recurring"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            if ($this->user->hasPermission('billing_view_eventlog') && !$this->user->isAnonymous()) {
                if ($this->action == "Billing_ViewEventLog"){
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=Billing_ViewEventLog\" class='sel'>"
                        .strtolower($this->user->lang("Billing event log"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }else{
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=Billing_ViewEventLog\">"
                        .strtolower($this->user->lang("Billing event log"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }
        }

        if ($this->customer && !$this->customer->isGuest()) {
            //Am I viewing main invoice
            if ($this->action == "ActiveInvoices" || $this->action == "") {
                 $tSubArray[0] = strtolower($this->user->lang("viewing active invoices"));
                 $tSubArray[1] = 1;
                 $tSubArray[2] = 1;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];
                 $options = true;
            } elseif(!$this->user->isAnonymous()) {
                $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ActiveInvoices\" >"
                    .strtolower($this->user->lang("Active Invoices"))."</a>";
                $tSubArray[1] = 1;
                $tSubArray[2] = 0;
                $tArray[] = $tSubArray;
                $options = true;
            }

            //Check to see if archived invoices exist
            if ($this->user->hasPermission('billing_archived_invoices') && !$this->user->isAnonymous()) {
                if ($this->action == "ViewArchivedInvoices") {
                    $tSubArray[0] = strtolower($this->user->lang("viewing archived invoices"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ViewArchivedInvoices\">"
                        .strtolower($this->user->lang("Archived Invoices"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            //Check to see if user is are admin
            if ($this->user->isAdmin()) {
                if ($this->user->hasPermission('billing_uninvoiced_work')) {
                    if ($this->action == "ViewUnInvoicedWork") {
                        $tSubArray[0] = strtolower($this->user->lang("viewing uninvoiced work"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=ViewUnInvoicedWork\">"
                            .strtolower($this->user->lang("Uninvoiced Work"))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }
                    $options = true;
                }

                if ($this->user->hasPermission('billing_create')) {
                    if ($this->action == "CreateInvoiceEntry") {
                        $tSubArray[0] = strtolower($this->user->lang("creating invoice entry"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=CreateInvoiceEntry\">"
                            .strtolower($this->user->lang("create invoice entry"))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 0;
                        $tArray[] = $tSubArray;
                    }
                    $options = true;
                }

                if ($this->action == "EditRecurringInvoice") {
                    $tSubArray[0] = strtolower($this->user->lang("editing recurring invoice"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                    $options = true;
                }
                
                if ($this->action == "ViewInvoiceEntryDetail") {
                    $tSubArray[0] = strtolower($this->user->lang("editing entry"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                    $options = true;
                }                                
                
            }

            //Check to see if you are viewing invoice entry
            if ($this->user->hasPermission('billing_recurring_overview') && !$this->user->isAnonymous()) {
                if ($this->action == "RecurringOverview") {
                    $tSubArray[0] = strtolower($this->user->lang("recurring overview"));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=RecurringOverview\">"
                        .strtolower($this->user->lang("recurring overview"))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            //Check to see if you are viewing invoice entry
            if ($this->action == "ViewInvoiceEntry") {
                $tSubArray[0] = strtolower($this->user->lang("View Entry"));
                $tSubArray[1] = 1;
                $tSubArray[2] = 1;
                $tArray[] = $tSubArray;
                $navlinks[] = $tSubArray[0];
                $options = true;
            }

            //Check to see if you are viewing invoice entry
            if ($this->user->hasPermission('billing_view_eventlog') && !$this->user->isAnonymous()) {
                if ($this->action == "Billing_ViewEventLog") {
                    $tSubArray[0] = strtolower($this->user->lang('Billing event log'));
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 1;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=billing&amp;view=Billing_ViewEventLog\">"
                        .strtolower($this->user->lang('Billing event log'))."</a>";
                    $tSubArray[1] = 1;
                    $tSubArray[2] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }
        } else {  // a client is not selected
            $tSubArray[0] = strtolower($this->user->lang("active invoices"));
            $tSubArray[1] = 1;
            $tSubArray[2] = 1;
            $tArray[] = $tSubArray;
            $options = true;
        }

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