<?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', 'WelcomeEmail'),
        array('clients', 'AddDomain'),
        array('clients', 'ShowDomainData'),
        array('clients', 'ShowEmail'),
        array('clients', 'DeleteClient'),
        array('clients', 'ShowCustomerData'),
        array('clients', 'SaveNewClient'),
        array('clients', 'Clients_ViewEventLog'),
    );

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

        $tSelectedDomainTxt = "";
        if((isset($_REQUEST['selectedDomain']))&&($_REQUEST['selectedDomain']>0)) {
            $tSelectedDomainTxt = "selectedDomain=".$_REQUEST['selectedDomain']."&";
        }

        $txtProfile= $this->user->lang("Profile");
        if ($this->user->isAdmin()) {
            $txtProfile=$this->user->lang("client profile");
        }

        if (in_array($this->action, array( 'AddClient',
                                     'ViewPendingUsers',
                                     'ViewActiveUsers',
                                     'WelcomeEmail',
                                     'AddDomain',
                                     'ShowDomainData',
                                     'ShowEmail',
                                     'DeleteClient',
                                     'ShowCustomerData',
                                     'SaveNewClient',
                                     'Clients_ViewEventLog')))
        {
            if ($this->customer && !$this->customer->isGuest()) {
                if ($this->action== 'ShowCustomerData'){
                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ShowCustomerData\"  class='sel'>".strtolower($txtProfile)."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                }else{
                    $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ShowCustomerData\">".strtolower($txtProfile)."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                    $navlinks[] = $tSubArray[0];
                }
                $options = true;
            }

            if ($this->action != 'AddClient' && $this->action != 'ViewPendingUsers') {
                if ($this->action== 'ShowCustomerData'){
                     $tSubArray[0] = $this->user->lang("viewing profile");
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 1;
                     $tArray[] = $tSubArray;
                     $navlinks[] = $tSubArray[0];
                } elseif ($this->action!= 'ViewActiveUsers') {
                     $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowCustomerData\">".strtolower($this->user->lang("profile"))."</a>";
                     $tSubArray[1] = 1;
                     $tSubArray[2] = 0;
                     $tArray[] = $tSubArray;
                }

                if ($this->customer && !$this->customer->isGuest() && $this->action!= 'ViewActiveUsers') {
                    require_once 'classes/DomainGateway.php';
                    $domainGateway = new DomainGateway();

                   //show domain sub action
                   if ($this->user->hasPermission('clients_view_domains')
                       && $domainGateway->getDomainCount($this->customer->getId()) > 0)
                   {
                       if ($this->action== 'ShowDomainData'){
                           $tSubArray[0] = strtolower($this->user->lang("viewing packages"));
                           $tSubArray[1] = 1;
                           $tSubArray[2] = 1;
                           $tArray[] = $tSubArray;
                           $navlinks[] = $tSubArray[0];
                       } else {
                           $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowDomainData\">".$this->user->lang("view package")."</a>";
                           $tSubArray[1] = 1;
                           $tSubArray[2] = 0;
                           $tArray[] = $tSubArray;
                       }
                   }

                   //add domain subaction
                   if ($this->user->hasPermission('clients_create_customer_packages') && $this->customer && !$this->customer->isGuest()) {
                      if ($this->action == 'AddDomain') {
                          $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=clients&amp;view=AddDomain\">".strtolower($this->user->lang("Add Package"))."</a>";
                          $tSubArray[1] = 1;
                          $tSubArray[2] = 0;
                          $tArray[] = $tSubArray;
                      }
                   }
                   if ($this->customer && $this->user->hasPermission('clients_email_customers')) {
                      if (($this->action!= 'AddClient')) {
                          if ($this->action== 'ShowEmail') {
                              $tSubArray[0] = strtolower($this->user->lang("E-mail Client"));
                              $tSubArray[1] = 1;
                              $tSubArray[2] = 1;
                              $tArray[] = $tSubArray;
                              $navlinks[] = $tSubArray[0];
                          } else {
                              $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowEmail\">".strtolower($this->user->lang("E-mail Client"))."</a>";
                              $tSubArray[1] = 1;
                              $tSubArray[2] = 0;
                              $tArray[] = $tSubArray;
                          }
                      }
                   }

                   if ( $this->customer && !$this->customer->isGuest()
                        && $this->user->hasPermission('clients_view_domains')
                        && $domainGateway->getDomainCount($this->customer->getId()) > 0)
                    {
                       //welcome email sub action
                       if ($this->customer->GetStatus() == 1 || $this->customer->GetStatus() == -1) {
                           if ($this->action== 'WelcomeEmail') {
                               $tSubArray[0] = strtolower($this->user->lang("Welcome E-mail"));
                               $tSubArray[1] = 1;
                               $tSubArray[2] = 1;
                               $tArray[] = $tSubArray;
                               $navlinks[] = $tSubArray[0];
                           } else {
                               $tSubArray[0] = "<a href=\"index.php?fuse=clients&".$tSelectedDomainTxt."view=WelcomeEmail\">".strtolower($this->user->lang("Welcome E-mail"))."</a>";
                               $tSubArray[1] = 1;
                               $tSubArray[2] = 0;
                               $tArray[] = $tSubArray;
                           }
                       }
                   }

                   if ($this->user->hasPermission('clients_view_eventlog')) {
                        if ($this->action == 'Clients_ViewEventLog') {
                            $tSubArray[0] = strtolower($this->user->lang("Client event log"));
                            $tSubArray[1] = 1;
                            $tSubArray[2] = 1;
                            $tArray[] = $tSubArray;
                            $navlinks[] = $tSubArray[0];
                        } else {
                            $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=Clients_ViewEventLog\">".strtolower($this->user->lang("Client event log"))."</a>";
                            $tSubArray[1] = 1;
                            $tSubArray[2] = 0;
                            $tArray[] = $tSubArray;
                        }
                   }
                }
                $options = true;
            }//end check to see if pending user

        } elseif($this->customer && !$this->customer->isGuest() && !$this->user->isAnonymous()) {
            $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowCustomerData\" >".strtolower($txtProfile)."</a>";
            $tSubArray[1] = 0;
            $tArray[] = $tSubArray;
            $options = true;
        }

        if($this->customer && !$this->customer->isGuest()) {
            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("view packages")."</a>";
                   $tSubArray[1] = 0;
                   $tArray[] = $tSubArray;
                } else {
                    $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=ShowDomainData\" >".$this->user->lang("view packages")."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
                $options = true;
            }

            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;
                }
                $options = true;
            }
            
            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;
                }
                $options = true;
            }

           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("Client 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("Client event log"))."</a>";
                    $tSubArray[1] = 0;
                    $tArray[] = $tSubArray;
                }
           }
        }

        if ($this->user->isAdmin() && $this->user->hasPermission('clients_view_customers')) {

            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("Viewing Users"));
                 $tSubArray[1] = 1;
                 $tSubArray[2] = 1;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];
            }

            //show active users
            if ($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->hasPermission('clients_create_customers')) {
                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;
    
                    if ($this->action== 'AddClient') {
                        $tSubArray[0] = strtolower($this->user->lang("Adding Client"));
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 1;
                        $tArray[] = $tSubArray;
                        $navlinks[] = $tSubArray[0];
                    } else {
                        $tSubArray[0] = "<a href=\"index.php?fuse=clients&amp;view=AddClient\">".strtolower($this->user->lang("Add Client"))."</a>";
                        $tSubArray[1] = 1;
                        $tSubArray[2] = 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;
                }
            }
            $options = true;
        } else 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("Viewing Users"));
                 $tSubArray[1] = 1;
                 $tSubArray[2] = 1;
                 $tArray[] = $tSubArray;
                 $navlinks[] = $tSubArray[0];
            }

            //show active users
            if ($this->user->hasPermission('clients_view_customers')) {
                $tSubArray[0] ="<a href=\"index.php?fuse=clients&amp;view=ViewAllUsers\" >".strtolower($this->user->lang("Client List"))."</a>";
                $tSubArray[1] = 0;
                $tArray[] = $tSubArray;
            }
            $options = true;
        }
        if($options){
            return array('navlinks' => $navlinks, 'menus' => $tArray);
        }else{
            return;
        }
    }
}


?>
