How to enable access to helpdesk only if user have special product

From aMember Pro Documentation
Revision as of 07:03, 3 July 2012 by Alexander (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Create /amember/application/configs/site.php with this code:

<?php
        function helpdeskEnabled(){
            $user = Am_Di::getInstance()->auth->getUser();
            if(!$user) return false;
            foreach($user->getActiveProducts() as $p){
                $data = $p->getBillingPlanData();
                if($data['helpdesk_enabled']) return true;
            }
            return false;
        }
 
 
        Am_Di::getInstance()->billingPlanTable->customFields()
            ->add(new Am_CustomFieldSelect('helpdesk_enabled', "Enable access to helpdesk", '', '', array('options' => array(0=>'No', 1=>'Yes'))));
 
        Am_Di::getInstance()->hook->add('userMenu', 'onUserMenu');
        function onUserMenu($event){
            $menu = $event->getMenu();
            if(!helpdeskEnabled()) $menu->removePage($menu->findOneBy('id', 'helpdesk'));  
        }
 
        Am_Di::getInstance()->hook->add(Am_Event::INIT_CONTROLLER_PAGES, 'onControllerPages');
        function onControllerPages($event){
            $c = $event->getController();
            if(!is_a($c, 'Helpdesk_IndexController')) return;
            if(!helpdeskEnabled()) throw new Am_Exception_InputError('Access denied!');
 
        }
?>

By default access to helpdesk will be disabled for all users. You can enable it for selected products only(aMember CP -> Manage Products -> Edit Product -> Enable access to helpdesk)