| 1 | 
           www | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           declare(strict_types=1);
  | 
        
        
            | 
            | 
           3 | 
              | 
        
        
            | 
            | 
           4 | 
           namespace LeadersLinked;
  | 
        
        
            | 
            | 
           5 | 
              | 
        
        
            | 
            | 
           6 | 
           use Laminas\Db\Adapter\AdapterInterface;
  | 
        
        
            | 
            | 
           7 | 
           use Laminas\ModuleManager\ModuleEvent;
  | 
        
        
            | 
            | 
           8 | 
           use Laminas\ModuleManager\ModuleManager;
  | 
        
        
            | 
            | 
           9 | 
           use Laminas\Mvc\MvcEvent;
  | 
        
        
            | 
            | 
           10 | 
           use Laminas\Config\Reader\Ini;
  | 
        
        
            | 
            | 
           11 | 
           use Laminas\Permissions\Acl\Acl;
  | 
        
        
            | 
            | 
           12 | 
           use Laminas\Permissions\Acl\Role\GenericRole;
  | 
        
        
            | 
            | 
           13 | 
           use LeadersLinked\Plugin\CurrentUserPlugin;
  | 
        
        
            | 
            | 
           14 | 
           use LeadersLinked\Mapper\UserMapper;
  | 
        
        
            | 
            | 
           15 | 
           use LeadersLinked\Authentication\AuthTokenAdapter;
  | 
        
        
            | 
            | 
           16 | 
           use Laminas\Authentication\AuthenticationService;
  | 
        
        
            | 
            | 
           17 | 
           use Laminas\Permissions\Acl\Resource\GenericResource;
  | 
        
        
            | 
            | 
           18 | 
           use LeadersLinked\Model\UserType;
  | 
        
        
           | 3639 | 
           efrain | 
           19 | 
           use LeadersLinked\Plugin\CurrentNetworkPlugin;
  | 
        
        
            | 
            | 
           20 | 
           use LeadersLinked\Model\Network;
  | 
        
        
            | 
            | 
           21 | 
           use LeadersLinked\Model\User;
  | 
        
        
            | 
            | 
           22 | 
           use LeadersLinked\Mapper\CompanyUserMapper;
  | 
        
        
            | 
            | 
           23 | 
           use LeadersLinked\Model\CompanyUser;
  | 
        
        
            | 
            | 
           24 | 
           use LeadersLinked\Mapper\CompanyMapper;
  | 
        
        
           | 5205 | 
           efrain | 
           25 | 
           use LeadersLinked\Mapper\CompanyServiceMapper;
  | 
        
        
            | 
            | 
           26 | 
           use LeadersLinked\Model\Service;
  | 
        
        
           | 6849 | 
           efrain | 
           27 | 
              | 
        
        
           | 6749 | 
           efrain | 
           28 | 
           use LeadersLinked\Library\Functions;
  | 
        
        
           | 7122 | 
           efrain | 
           29 | 
           use LeadersLinked\Mapper\DailyPulseMapper;
  | 
        
        
            | 
            | 
           30 | 
           use LeadersLinked\Model\DailyPulse;
  | 
        
        
           | 7134 | 
           efrain | 
           31 | 
           use LeadersLinked\Mapper\OrganizationPositionMapper;
  | 
        
        
            | 
            | 
           32 | 
           use LeadersLinked\Mapper\KnowledgeAreaCategoryJobDescriptionMapper;
  | 
        
        
            | 
            | 
           33 | 
           use LeadersLinked\Mapper\MyCoachCategoryJobDescriptionMapper;
  | 
        
        
           | 7141 | 
           efrain | 
           34 | 
           use LeadersLinked\Mapper\KnowledgeAreaCategoryUserMapper;
  | 
        
        
            | 
            | 
           35 | 
           use LeadersLinked\Mapper\MyCoachCategoryUserMapper;
  | 
        
        
           | 1 | 
           www | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
           class Module
  | 
        
        
            | 
            | 
           38 | 
           {
  | 
        
        
            | 
            | 
           39 | 
               /**
  | 
        
        
            | 
            | 
           40 | 
                *
  | 
        
        
            | 
            | 
           41 | 
                * @var boolean
  | 
        
        
            | 
            | 
           42 | 
                */
  | 
        
        
            | 
            | 
           43 | 
               private $isJson;
  | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
               /**
  | 
        
        
            | 
            | 
           46 | 
                *
  | 
        
        
            | 
            | 
           47 | 
                * @var boolean
  | 
        
        
            | 
            | 
           48 | 
                */
  | 
        
        
            | 
            | 
           49 | 
               private $isHtml;
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
               /**
  | 
        
        
            | 
            | 
           52 | 
                *
  | 
        
        
            | 
            | 
           53 | 
                * @var Acl
  | 
        
        
            | 
            | 
           54 | 
                */
  | 
        
        
            | 
            | 
           55 | 
               private $acl;
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
               /**
  | 
        
        
            | 
            | 
           58 | 
                *
  | 
        
        
            | 
            | 
           59 | 
                * @var AdapterInterface
  | 
        
        
            | 
            | 
           60 | 
                */
  | 
        
        
            | 
            | 
           61 | 
               private $adapter;
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
               /**
  | 
        
        
            | 
            | 
           64 | 
                *
  | 
        
        
            | 
            | 
           65 | 
                * @var CurrentUserPlugin
  | 
        
        
            | 
            | 
           66 | 
                */
  | 
        
        
           | 3639 | 
           efrain | 
           67 | 
               private $currentUserPlugin;
  | 
        
        
           | 1 | 
           www | 
           68 | 
              | 
        
        
            | 
            | 
           69 | 
               /**
  | 
        
        
           | 3639 | 
           efrain | 
           70 | 
                *
  | 
        
        
            | 
            | 
           71 | 
                * @var CurrentNetworkPlugin
  | 
        
        
            | 
            | 
           72 | 
                */
  | 
        
        
            | 
            | 
           73 | 
               private $currentNetworkPlugin;
  | 
        
        
            | 
            | 
           74 | 
              | 
        
        
            | 
            | 
           75 | 
               /**
  | 
        
        
           | 1 | 
           www | 
           76 | 
                *
  | 
        
        
            | 
            | 
           77 | 
                * @var array
  | 
        
        
            | 
            | 
           78 | 
                */
  | 
        
        
            | 
            | 
           79 | 
               private $routesAuthorized = [];
  | 
        
        
            | 
            | 
           80 | 
              | 
        
        
            | 
            | 
           81 | 
               /**
  | 
        
        
            | 
            | 
           82 | 
                *
  | 
        
        
            | 
            | 
           83 | 
                * @var boolean
  | 
        
        
            | 
            | 
           84 | 
                */
  | 
        
        
            | 
            | 
           85 | 
               private $authByHeaders = false;
  | 
        
        
            | 
            | 
           86 | 
              | 
        
        
           | 7330 | 
           efrain | 
           87 | 
              | 
        
        
            | 
            | 
           88 | 
               /**
  | 
        
        
            | 
            | 
           89 | 
                *
  | 
        
        
            | 
            | 
           90 | 
                * @var array
  | 
        
        
            | 
            | 
           91 | 
                */
  | 
        
        
            | 
            | 
           92 | 
               private $config;
  | 
        
        
            | 
            | 
           93 | 
              | 
        
        
            | 
            | 
           94 | 
              | 
        
        
            | 
            | 
           95 | 
              | 
        
        
           | 1 | 
           www | 
           96 | 
               public function init(ModuleManager $moduleManager)
  | 
        
        
            | 
            | 
           97 | 
               {
  | 
        
        
            | 
            | 
           98 | 
                   $events = $moduleManager->getEventManager();
  | 
        
        
            | 
            | 
           99 | 
                   $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, array($this, 'onMergeConfig'));
  | 
        
        
            | 
            | 
           100 | 
               }
  | 
        
        
            | 
            | 
           101 | 
              | 
        
        
            | 
            | 
           102 | 
               public function onMergeConfig(ModuleEvent $event)
  | 
        
        
            | 
            | 
           103 | 
               {
  | 
        
        
            | 
            | 
           104 | 
                   $configListener = $event->getConfigListener();
  | 
        
        
           | 7330 | 
           efrain | 
           105 | 
                   $this->config   = $configListener->getMergedConfig(false);
  | 
        
        
           | 1 | 
           www | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
                   $reader = new Ini();
  | 
        
        
            | 
            | 
           108 | 
                   $data = $reader->fromFile('config/leaderslinked.ini');
  | 
        
        
            | 
            | 
           109 | 
              | 
        
        
            | 
            | 
           110 | 
                   $prefix = 'leaderslinked';
  | 
        
        
            | 
            | 
           111 | 
                   foreach($data as $section => $pairs)
  | 
        
        
            | 
            | 
           112 | 
                   {
  | 
        
        
            | 
            | 
           113 | 
                       foreach($pairs as $key => $value)
  | 
        
        
            | 
            | 
           114 | 
                       {
  | 
        
        
           | 7330 | 
           efrain | 
           115 | 
                           $this->config[$prefix . '.' . $section . '.' . $key] = $value;
  | 
        
        
           | 1 | 
           www | 
           116 | 
                       }
  | 
        
        
            | 
            | 
           117 | 
                   }
  | 
        
        
           | 7330 | 
           efrain | 
           118 | 
                   $configListener->setMergedConfig($this->config);
  | 
        
        
           | 1 | 
           www | 
           119 | 
               }
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
            | 
            | 
           121 | 
              | 
        
        
            | 
            | 
           122 | 
               public function getConfig() : array
  | 
        
        
            | 
            | 
           123 | 
               {
  | 
        
        
            | 
            | 
           124 | 
                   return include __DIR__ . '/../config/module.config.php';
  | 
        
        
            | 
            | 
           125 | 
               }
  | 
        
        
            | 
            | 
           126 | 
              | 
        
        
            | 
            | 
           127 | 
               public function onBootstrap(MvcEvent $event)
  | 
        
        
            | 
            | 
           128 | 
               {
  | 
        
        
            | 
            | 
           129 | 
                   $serviceManager = $event->getApplication()->getServiceManager();
  | 
        
        
            | 
            | 
           130 | 
                   $adapter = $serviceManager->get('leaders-linked-db');
  | 
        
        
            | 
            | 
           131 | 
                  // $logger          = $serviceManager->get('Zend\Log\Logger');
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
            | 
            | 
           133 | 
              | 
        
        
            | 
            | 
           134 | 
                   $session = $serviceManager->get('leaders-linked-session');
  | 
        
        
            | 
            | 
           135 | 
                   $session->start();
  | 
        
        
            | 
            | 
           136 | 
              | 
        
        
            | 
            | 
           137 | 
              | 
        
        
            | 
            | 
           138 | 
                   $translator = $serviceManager->get('MvcTranslator');
  | 
        
        
            | 
            | 
           139 | 
                   $translator->addTranslationFile(
  | 
        
        
            | 
            | 
           140 | 
                       'phpArray',
  | 
        
        
            | 
            | 
           141 | 
                       __DIR__ . '/i18n/validate.php',
  | 
        
        
            | 
            | 
           142 | 
                       'default'
  | 
        
        
            | 
            | 
           143 | 
                       );
  | 
        
        
            | 
            | 
           144 | 
              | 
        
        
            | 
            | 
           145 | 
                   $translator->addTranslationFile(
  | 
        
        
            | 
            | 
           146 | 
                       'phpArray',
  | 
        
        
            | 
            | 
           147 | 
                       __DIR__ . '/i18n/spanish.php',
  | 
        
        
            | 
            | 
           148 | 
                       'default'
  | 
        
        
            | 
            | 
           149 | 
                       );
  | 
        
        
            | 
            | 
           150 | 
              | 
        
        
            | 
            | 
           151 | 
                   \Laminas\Validator\AbstractValidator::setDefaultTranslator($translator);
  | 
        
        
            | 
            | 
           152 | 
              | 
        
        
            | 
            | 
           153 | 
              | 
        
        
            | 
            | 
           154 | 
                   $headers  = $event->getRequest()->getHeaders();
  | 
        
        
            | 
            | 
           155 | 
                   if($headers->has('Accept')) {
  | 
        
        
            | 
            | 
           156 | 
                       $accept = $headers->get('Accept');
  | 
        
        
            | 
            | 
           157 | 
                       $prioritized = $accept->getPrioritized();
  | 
        
        
            | 
            | 
           158 | 
              | 
        
        
            | 
            | 
           159 | 
                       foreach($prioritized as $key => $value) {
  | 
        
        
            | 
            | 
           160 | 
                           $raw = trim($value->getRaw());
  | 
        
        
            | 
            | 
           161 | 
              | 
        
        
            | 
            | 
           162 | 
                           if(!$this->isJson) {
  | 
        
        
            | 
            | 
           163 | 
                               $this->isJson = strpos($raw, 'json');
  | 
        
        
            | 
            | 
           164 | 
                           }
  | 
        
        
            | 
            | 
           165 | 
              | 
        
        
            | 
            | 
           166 | 
                       }
  | 
        
        
            | 
            | 
           167 | 
                   } else {
  | 
        
        
            | 
            | 
           168 | 
                       $accept = '';
  | 
        
        
            | 
            | 
           169 | 
                   }
  | 
        
        
            | 
            | 
           170 | 
                   if($headers->has('token')) {
  | 
        
        
           | 6749 | 
           efrain | 
           171 | 
                       $device_uuid = Functions::sanitizeFilterString($headers->get('token')->getFieldValue());
  | 
        
        
           | 1 | 
           www | 
           172 | 
                   } else {
  | 
        
        
            | 
            | 
           173 | 
                       $device_uuid = '';
  | 
        
        
            | 
            | 
           174 | 
                   }
  | 
        
        
            | 
            | 
           175 | 
                   if($headers->has('secret')) {
  | 
        
        
           | 6749 | 
           efrain | 
           176 | 
                       $password =  Functions::sanitizeFilterString($headers->get('secret')->getFieldValue());
  | 
        
        
           | 1 | 
           www | 
           177 | 
                   } else {
  | 
        
        
            | 
            | 
           178 | 
                       $password = '';
  | 
        
        
            | 
            | 
           179 | 
                   }
  | 
        
        
            | 
            | 
           180 | 
                   if($headers->has('rand')) {
  | 
        
        
           | 6749 | 
           efrain | 
           181 | 
                       $rand =  Functions::sanitizeFilterString($headers->get('rand')->getFieldValue());
  | 
        
        
           | 1 | 
           www | 
           182 | 
                   } else {
  | 
        
        
            | 
            | 
           183 | 
                       $rand = 0;
  | 
        
        
            | 
            | 
           184 | 
                   }
  | 
        
        
            | 
            | 
           185 | 
                   if($headers->has('created')) {
  | 
        
        
           | 6749 | 
           efrain | 
           186 | 
                       $timestamp =  Functions::sanitizeFilterString($headers->get('created')->getFieldValue());
  | 
        
        
           | 1 | 
           www | 
           187 | 
                   } else {
  | 
        
        
            | 
            | 
           188 | 
                       $timestamp = 0;
  | 
        
        
            | 
            | 
           189 | 
                   }
  | 
        
        
           | 7335 | 
           efrain | 
           190 | 
              | 
        
        
           | 1 | 
           www | 
           191 | 
              | 
        
        
            | 
            | 
           192 | 
              | 
        
        
           | 3639 | 
           efrain | 
           193 | 
                   $this->currentNetworkPlugin = new CurrentNetworkPlugin($adapter);
  | 
        
        
            | 
            | 
           194 | 
                   if(!$this->currentNetworkPlugin->hasNetwork()) {
  | 
        
        
           | 3790 | 
           efrain | 
           195 | 
                       $this->isJson = true;
  | 
        
        
            | 
            | 
           196 | 
                       $response = $event->getResponse();
  | 
        
        
            | 
            | 
           197 | 
                       $this->sendResponse($response, ['success' => false, 'data' => '401 Unauthorized - Private network - not found', 'fatal' => true]);
  | 
        
        
           | 3639 | 
           efrain | 
           198 | 
                   }
  | 
        
        
            | 
            | 
           199 | 
              | 
        
        
            | 
            | 
           200 | 
                   if($this->currentNetworkPlugin->getNetwork()->status == Network::STATUS_INACTIVE) {
  | 
        
        
           | 3790 | 
           efrain | 
           201 | 
                       $this->isJson = true;
  | 
        
        
            | 
            | 
           202 | 
                       $response = $event->getResponse();
  | 
        
        
            | 
            | 
           203 | 
                       $this->sendResponse($response, ['success' => false, 'data' => '401 Unauthorized - Private network - inactive', 'fatal' => true]);
  | 
        
        
            | 
            | 
           204 | 
              | 
        
        
           | 3639 | 
           efrain | 
           205 | 
                   }
  | 
        
        
            | 
            | 
           206 | 
              | 
        
        
            | 
            | 
           207 | 
              | 
        
        
           | 1 | 
           www | 
           208 | 
                   $this->authByHeaders = false;
  | 
        
        
            | 
            | 
           209 | 
                   if($device_uuid && $password && $rand && $timestamp) {
  | 
        
        
            | 
            | 
           210 | 
                       $this->authByHeaders = true;
  | 
        
        
            | 
            | 
           211 | 
              | 
        
        
            | 
            | 
           212 | 
              | 
        
        
            | 
            | 
           213 | 
                       $this->isJson = true;
  | 
        
        
            | 
            | 
           214 | 
              | 
        
        
            | 
            | 
           215 | 
                       $tokenAuthAdapter = new AuthTokenAdapter($adapter);
  | 
        
        
            | 
            | 
           216 | 
                       $tokenAuthAdapter->setData($device_uuid, $password, $timestamp, $rand);
  | 
        
        
            | 
            | 
           217 | 
              | 
        
        
            | 
            | 
           218 | 
                       $authService = new AuthenticationService();
  | 
        
        
            | 
            | 
           219 | 
                       $result = $authService->authenticate($tokenAuthAdapter);
  | 
        
        
            | 
            | 
           220 | 
                       if($result->getCode() != \Laminas\Authentication\Result::SUCCESS) {
  | 
        
        
            | 
            | 
           221 | 
                           $response = $event->getResponse();
  | 
        
        
            | 
            | 
           222 | 
              | 
        
        
            | 
            | 
           223 | 
                           $this->sendResponse($response, ['success' => false, 'data' => $result->getMessages()[0], 'fatal' => true]);
  | 
        
        
            | 
            | 
           224 | 
                       }
  | 
        
        
           | 210 | 
           efrain | 
           225 | 
              | 
        
        
            | 
            | 
           226 | 
              | 
        
        
            | 
            | 
           227 | 
              | 
        
        
            | 
            | 
           228 | 
              | 
        
        
            | 
            | 
           229 | 
              | 
        
        
           | 1 | 
           www | 
           230 | 
                   }
  | 
        
        
           | 3639 | 
           efrain | 
           231 | 
              | 
        
        
           | 1 | 
           www | 
           232 | 
              | 
        
        
           | 3639 | 
           efrain | 
           233 | 
              | 
        
        
            | 
            | 
           234 | 
                   if(empty($_SERVER['REDIRECT_URL'])) {
  | 
        
        
            | 
            | 
           235 | 
                       if(empty($_SERVER['REQUEST_URI'])) {
  | 
        
        
            | 
            | 
           236 | 
                           $routeName = '';
  | 
        
        
            | 
            | 
           237 | 
              | 
        
        
            | 
            | 
           238 | 
                       } else {
  | 
        
        
            | 
            | 
           239 | 
                           $routeName = $_SERVER['REQUEST_URI'];
  | 
        
        
            | 
            | 
           240 | 
                       }
  | 
        
        
            | 
            | 
           241 | 
              | 
        
        
            | 
            | 
           242 | 
                   } else {
  | 
        
        
            | 
            | 
           243 | 
                       $routeName = $_SERVER['REDIRECT_URL'];
  | 
        
        
            | 
            | 
           244 | 
              | 
        
        
            | 
            | 
           245 | 
                   }
  | 
        
        
            | 
            | 
           246 | 
              | 
        
        
           | 210 | 
           efrain | 
           247 | 
              | 
        
        
           | 3639 | 
           efrain | 
           248 | 
                   $routeName = strtolower(trim($routeName));
  | 
        
        
            | 
            | 
           249 | 
                   if(strlen($routeName) > 0 && substr($routeName, 0, 1) == '/') {
  | 
        
        
            | 
            | 
           250 | 
                       $routeName = substr($routeName, 1);
  | 
        
        
            | 
            | 
           251 | 
                   }
  | 
        
        
           | 1 | 
           www | 
           252 | 
              | 
        
        
           | 3639 | 
           efrain | 
           253 | 
                   $this->isHtml = $this->isJson ? false : true;
  | 
        
        
            | 
            | 
           254 | 
                   $this->currentUserPlugin = new CurrentUserPlugin($adapter);
  | 
        
        
           | 1 | 
           www | 
           255 | 
              | 
        
        
           | 210 | 
           efrain | 
           256 | 
              | 
        
        
           | 3639 | 
           efrain | 
           257 | 
                   if($this->authByHeaders && substr($routeName, 0, 8) == 'services') {
  | 
        
        
            | 
            | 
           258 | 
                       $checkUserForNetwork = false;
  | 
        
        
            | 
            | 
           259 | 
                   } else {
  | 
        
        
            | 
            | 
           260 | 
                       if($this->currentUserPlugin->hasIdentity()) {
  | 
        
        
            | 
            | 
           261 | 
              | 
        
        
            | 
            | 
           262 | 
                           $checkUserForNetwork = true;
  | 
        
        
            | 
            | 
           263 | 
                       } else {
  | 
        
        
            | 
            | 
           264 | 
                           $checkUserForNetwork = false;
  | 
        
        
            | 
            | 
           265 | 
                       }
  | 
        
        
            | 
            | 
           266 | 
                   }
  | 
        
        
            | 
            | 
           267 | 
              | 
        
        
            | 
            | 
           268 | 
                   if($checkUserForNetwork) {
  | 
        
        
            | 
            | 
           269 | 
                       if(!$routeName || in_array($routeName, ['signout', 'signin', 'home'])) {
  | 
        
        
            | 
            | 
           270 | 
                           $checkUserForNetwork = false;
  | 
        
        
            | 
            | 
           271 | 
                       }
  | 
        
        
            | 
            | 
           272 | 
                   }
  | 
        
        
            | 
            | 
           273 | 
              | 
        
        
            | 
            | 
           274 | 
                   if($checkUserForNetwork) {
  | 
        
        
            | 
            | 
           275 | 
              | 
        
        
            | 
            | 
           276 | 
              | 
        
        
            | 
            | 
           277 | 
              | 
        
        
            | 
            | 
           278 | 
                       if($this->currentUserPlugin->getUser()->network_id != $this->currentNetworkPlugin->getNetworkId()) {
  | 
        
        
           | 3790 | 
           efrain | 
           279 | 
              | 
        
        
            | 
            | 
           280 | 
                           $this->isJson = true;
  | 
        
        
            | 
            | 
           281 | 
                           $response = $event->getResponse();
  | 
        
        
            | 
            | 
           282 | 
                           $this->sendResponse($response, ['success' => false, 'data' => '401 Unauthorized - The user is not part of this private network', 'fatal' => true]);
  | 
        
        
            | 
            | 
           283 | 
              | 
        
        
           | 3639 | 
           efrain | 
           284 | 
                       }
  | 
        
        
            | 
            | 
           285 | 
                   }
  | 
        
        
            | 
            | 
           286 | 
              | 
        
        
           | 7335 | 
           efrain | 
           287 | 
                   /*
  | 
        
        
            | 
            | 
           288 | 
                   $application = $event->getApplication();
  | 
        
        
            | 
            | 
           289 | 
                   $templateMapResolver = $application->getServiceManager()->get(
  | 
        
        
            | 
            | 
           290 | 
                       'ViewTemplateMapResolver'
  | 
        
        
            | 
            | 
           291 | 
                       );
  | 
        
        
           | 3639 | 
           efrain | 
           292 | 
              | 
        
        
            | 
            | 
           293 | 
              | 
        
        
           | 7335 | 
           efrain | 
           294 | 
                   $listener = new LayoutListener($templateMapResolver);
  | 
        
        
            | 
            | 
           295 | 
                   $listener->attach($application->getEventManager());*/
  | 
        
        
            | 
            | 
           296 | 
              | 
        
        
            | 
            | 
           297 | 
              | 
        
        
            | 
            | 
           298 | 
              | 
        
        
           | 1 | 
           www | 
           299 | 
                   $this->initAcl($event);
  | 
        
        
            | 
            | 
           300 | 
                   $eventManager = $event->getApplication()->getEventManager();
  | 
        
        
           | 7343 | 
           efrain | 
           301 | 
                  // $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, [$this,'onDispatchError'], 0);
  | 
        
        
            | 
            | 
           302 | 
                  // $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, [$this,'onRenderError'], 0);
  | 
        
        
           | 1 | 
           www | 
           303 | 
              | 
        
        
            | 
            | 
           304 | 
                   $sharedManager = $eventManager->getSharedManager();
  | 
        
        
            | 
            | 
           305 | 
                   $sharedManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, [$this, 'authPreDispatch'], 100);
  | 
        
        
            | 
            | 
           306 | 
                   $sharedManager->attach(__NAMESPACE__, MvcEvent::EVENT_DISPATCH, [$this, 'authPosDispatch'], -100);
  | 
        
        
            | 
            | 
           307 | 
               }
  | 
        
        
            | 
            | 
           308 | 
              | 
        
        
            | 
            | 
           309 | 
               public function initAcl(MvcEvent $event)
  | 
        
        
            | 
            | 
           310 | 
               {
  | 
        
        
            | 
            | 
           311 | 
              | 
        
        
           | 3639 | 
           efrain | 
           312 | 
                   $serviceManager = $event->getApplication()->getServiceManager();
  | 
        
        
            | 
            | 
           313 | 
                   $adapter = $serviceManager->get('leaders-linked-db');
  | 
        
        
            | 
            | 
           314 | 
              | 
        
        
            | 
            | 
           315 | 
              | 
        
        
           | 1 | 
           www | 
           316 | 
                   require_once   (dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'acl.config.php');
  | 
        
        
            | 
            | 
           317 | 
              | 
        
        
            | 
            | 
           318 | 
              | 
        
        
            | 
            | 
           319 | 
                   $this->acl = new Acl();
  | 
        
        
            | 
            | 
           320 | 
                   $resources = getAclResources();
  | 
        
        
           | 1979 | 
           efrain | 
           321 | 
              | 
        
        
           | 1 | 
           www | 
           322 | 
                   foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           323 | 
                   {
  | 
        
        
            | 
            | 
           324 | 
                       $this->acl->addResource(new GenericResource($resourceName));
  | 
        
        
            | 
            | 
           325 | 
                   }
  | 
        
        
            | 
            | 
           326 | 
              | 
        
        
            | 
            | 
           327 | 
                   $usertypes = getAclUsertype();
  | 
        
        
            | 
            | 
           328 | 
                   foreach($usertypes as $usertype => $resources)
  | 
        
        
            | 
            | 
           329 | 
                   {
  | 
        
        
            | 
            | 
           330 | 
                       $this->acl->addRole(new GenericRole($usertype));
  | 
        
        
            | 
            | 
           331 | 
                       foreach ($resources as $resourceName)
  | 
        
        
            | 
            | 
           332 | 
                       {
  | 
        
        
            | 
            | 
           333 | 
                           $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           334 | 
                       }
  | 
        
        
            | 
            | 
           335 | 
                   }
  | 
        
        
           | 5205 | 
           efrain | 
           336 | 
              | 
        
        
           | 1 | 
           www | 
           337 | 
              | 
        
        
           | 3639 | 
           efrain | 
           338 | 
              | 
        
        
            | 
            | 
           339 | 
                   if($this->currentUserPlugin->hasIdentity() && $this->currentUserPlugin->getUser()->is_super_user == User::IS_SUPER_USER_YES) {
  | 
        
        
            | 
            | 
           340 | 
              | 
        
        
            | 
            | 
           341 | 
                       $resources =  getAclSuperAdmin();
  | 
        
        
            | 
            | 
           342 | 
                       foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           343 | 
                       {
  | 
        
        
            | 
            | 
           344 | 
                           $this->acl->allow(UserType::ADMIN, $resourceName);
  | 
        
        
            | 
            | 
           345 | 
                       }
  | 
        
        
            | 
            | 
           346 | 
                   }
  | 
        
        
            | 
            | 
           347 | 
              | 
        
        
            | 
            | 
           348 | 
              | 
        
        
           | 6388 | 
           efrain | 
           349 | 
              | 
        
        
            | 
            | 
           350 | 
                   $allowMyCoach = false;
  | 
        
        
           | 5951 | 
           efrain | 
           351 | 
                   $allowKnowledgeArea = false;
  | 
        
        
           | 5205 | 
           efrain | 
           352 | 
                   $allowDailyPulse = false;
  | 
        
        
            | 
            | 
           353 | 
              | 
        
        
           | 7122 | 
           efrain | 
           354 | 
              | 
        
        
            | 
            | 
           355 | 
              | 
        
        
           | 5205 | 
           efrain | 
           356 | 
                   $companyMapper = CompanyMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           357 | 
                   $company = $companyMapper->fetchDefaultForNetworkByNetworkId($this->currentNetworkPlugin->getNetwork()->id);
  | 
        
        
           | 7122 | 
           efrain | 
           358 | 
              | 
        
        
            | 
            | 
           359 | 
              | 
        
        
           | 5205 | 
           efrain | 
           360 | 
                   if($company) {
  | 
        
        
           | 7122 | 
           efrain | 
           361 | 
              | 
        
        
            | 
            | 
           362 | 
                       $companyServiceMapper = CompanyServiceMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           363 | 
                       $companyService = $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company->id, Service::DAILY_PULSE);
  | 
        
        
            | 
            | 
           364 | 
              | 
        
        
            | 
            | 
           365 | 
              | 
        
        
           | 5205 | 
           efrain | 
           366 | 
                       $companyUserMapper = CompanyUserMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           367 | 
                       $companyUser = $companyUserMapper->fetchOneAcceptedByCompanyIdAndUserId($company->id,  $this->currentUserPlugin->getUserId());
  | 
        
        
            | 
            | 
           368 | 
              | 
        
        
            | 
            | 
           369 | 
              | 
        
        
            | 
            | 
           370 | 
              | 
        
        
            | 
            | 
           371 | 
              | 
        
        
           | 7122 | 
           efrain | 
           372 | 
                       if($companyService) {
  | 
        
        
            | 
            | 
           373 | 
              | 
        
        
           | 7124 | 
           efrain | 
           374 | 
                           $dailyPulseMapper = DailyPulseMapper::getInstance($adapter);
  | 
        
        
           | 7122 | 
           efrain | 
           375 | 
                           $dailyPulse = $dailyPulseMapper->fetchOneByCompanyId($company->id);
  | 
        
        
            | 
            | 
           376 | 
              | 
        
        
            | 
            | 
           377 | 
                           if($dailyPulse) {
  | 
        
        
            | 
            | 
           378 | 
                               $privacy = $dailyPulse->privacy;
  | 
        
        
            | 
            | 
           379 | 
              | 
        
        
            | 
            | 
           380 | 
                           } else {
  | 
        
        
            | 
            | 
           381 | 
                               $privacy = DailyPulse::PRIVACY_COMPANY;
  | 
        
        
            | 
            | 
           382 | 
                           }
  | 
        
        
            | 
            | 
           383 | 
              | 
        
        
            | 
            | 
           384 | 
                           if($privacy ==  DailyPulse::PRIVACY_PUBLIC) {
  | 
        
        
            | 
            | 
           385 | 
                               $allowDailyPulse = true;
  | 
        
        
            | 
            | 
           386 | 
                           } else {
  | 
        
        
            | 
            | 
           387 | 
                               $allowDailyPulse = !empty($companyUser);
  | 
        
        
            | 
            | 
           388 | 
                           }
  | 
        
        
            | 
            | 
           389 | 
              | 
        
        
            | 
            | 
           390 | 
              | 
        
        
           | 5205 | 
           efrain | 
           391 | 
                       }
  | 
        
        
           | 7134 | 
           efrain | 
           392 | 
              | 
        
        
            | 
            | 
           393 | 
                       $job_description_ids = [];
  | 
        
        
            | 
            | 
           394 | 
              | 
        
        
            | 
            | 
           395 | 
                       $organizationPositionMapper = OrganizationPositionMapper::getInstance($adapter);
  | 
        
        
           | 7135 | 
           efrain | 
           396 | 
                       $records = $organizationPositionMapper->fetchAllByCompanyIdAndEmployeeId($company->id,  $this->currentUserPlugin->getUserId());
  | 
        
        
           | 7134 | 
           efrain | 
           397 | 
                       foreach($records as $record)
  | 
        
        
            | 
            | 
           398 | 
                       {
  | 
        
        
            | 
            | 
           399 | 
                           array_push($job_description_ids, $record->job_description_id);
  | 
        
        
            | 
            | 
           400 | 
                       }
  | 
        
        
           | 7122 | 
           efrain | 
           401 | 
              | 
        
        
           | 5951 | 
           efrain | 
           402 | 
              | 
        
        
            | 
            | 
           403 | 
                       $companyService = $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company->id, Service::KNOWLEDGE_AREA);
  | 
        
        
           | 7134 | 
           efrain | 
           404 | 
                       if($companyService) {
  | 
        
        
            | 
            | 
           405 | 
              | 
        
        
            | 
            | 
           406 | 
              | 
        
        
            | 
            | 
           407 | 
              | 
        
        
            | 
            | 
           408 | 
                           if($job_description_ids) {
  | 
        
        
            | 
            | 
           409 | 
              | 
        
        
            | 
            | 
           410 | 
              | 
        
        
            | 
            | 
           411 | 
                               $knowledgeAreaCategoryJobDescriptionMapper = KnowledgeAreaCategoryJobDescriptionMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           412 | 
                               $records = $knowledgeAreaCategoryJobDescriptionMapper->fetchAllByCompanyIdAndJobDescriptionIds($company->id, $job_description_ids);
  | 
        
        
            | 
            | 
           413 | 
              | 
        
        
            | 
            | 
           414 | 
                               if(!empty($records)) {
  | 
        
        
            | 
            | 
           415 | 
                                   $allowKnowledgeArea = true;
  | 
        
        
            | 
            | 
           416 | 
                               }
  | 
        
        
            | 
            | 
           417 | 
              | 
        
        
            | 
            | 
           418 | 
                           }
  | 
        
        
            | 
            | 
           419 | 
              | 
        
        
           | 7141 | 
           efrain | 
           420 | 
                           if($companyUser && !$allowKnowledgeArea) {
  | 
        
        
            | 
            | 
           421 | 
                               $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           422 | 
                               $records = $knowledgeAreaCategoryUserMapper->fetchAllByUserId($companyUser->user_id);
  | 
        
        
            | 
            | 
           423 | 
                               if(!empty($records)) {
  | 
        
        
            | 
            | 
           424 | 
                                   $allowKnowledgeArea = true;
  | 
        
        
            | 
            | 
           425 | 
                               }
  | 
        
        
           | 7134 | 
           efrain | 
           426 | 
                           }
  | 
        
        
           | 5951 | 
           efrain | 
           427 | 
                       }
  | 
        
        
            | 
            | 
           428 | 
              | 
        
        
           | 6388 | 
           efrain | 
           429 | 
                       $companyService = $companyServiceMapper->fetchOneActiveByCompanyIdAndServiceId($company->id, Service::MY_COACH);
  | 
        
        
           | 7134 | 
           efrain | 
           430 | 
                       if($companyService) {
  | 
        
        
            | 
            | 
           431 | 
              | 
        
        
            | 
            | 
           432 | 
              | 
        
        
            | 
            | 
           433 | 
                           if($job_description_ids) {
  | 
        
        
            | 
            | 
           434 | 
              | 
        
        
            | 
            | 
           435 | 
              | 
        
        
            | 
            | 
           436 | 
                               $myCoachCategoryJobDescriptionMapper = MyCoachCategoryJobDescriptionMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           437 | 
                               $records = $myCoachCategoryJobDescriptionMapper->fetchAllByCompanyIdAndJobDescriptionIds($company->id, $job_description_ids);
  | 
        
        
            | 
            | 
           438 | 
              | 
        
        
            | 
            | 
           439 | 
                               if(!empty($records)) {
  | 
        
        
            | 
            | 
           440 | 
                                   $allowKnowledgeArea = true;
  | 
        
        
            | 
            | 
           441 | 
                               }
  | 
        
        
            | 
            | 
           442 | 
              | 
        
        
            | 
            | 
           443 | 
                           }
  | 
        
        
            | 
            | 
           444 | 
              | 
        
        
           | 7141 | 
           efrain | 
           445 | 
                           if($companyUser && !$allowMyCoach) {
  | 
        
        
            | 
            | 
           446 | 
                               $myCoachCategoryUserMapper = MyCoachCategoryUserMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           447 | 
                               $records = $myCoachCategoryUserMapper->fetchAllByUserId($companyUser->user_id);
  | 
        
        
            | 
            | 
           448 | 
                               if(!empty($records)) {
  | 
        
        
            | 
            | 
           449 | 
                                   $allowMyCoach = true;
  | 
        
        
            | 
            | 
           450 | 
                               }
  | 
        
        
            | 
            | 
           451 | 
              | 
        
        
            | 
            | 
           452 | 
              | 
        
        
           | 7134 | 
           efrain | 
           453 | 
                           }
  | 
        
        
           | 6388 | 
           efrain | 
           454 | 
                       }
  | 
        
        
            | 
            | 
           455 | 
              | 
        
        
           | 5205 | 
           efrain | 
           456 | 
                   } else {
  | 
        
        
            | 
            | 
           457 | 
                       $companyUser = '';
  | 
        
        
            | 
            | 
           458 | 
                   }
  | 
        
        
            | 
            | 
           459 | 
              | 
        
        
           | 6388 | 
           efrain | 
           460 | 
              | 
        
        
            | 
            | 
           461 | 
                   $usertype = $this->currentUserPlugin->getUserTypeId();
  | 
        
        
           | 5205 | 
           efrain | 
           462 | 
                   if($allowDailyPulse) {
  | 
        
        
            | 
            | 
           463 | 
                       $resources = getAclDailyPulse();
  | 
        
        
            | 
            | 
           464 | 
                       foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           465 | 
                       {
  | 
        
        
            | 
            | 
           466 | 
                           $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           467 | 
                       }
  | 
        
        
            | 
            | 
           468 | 
                   }
  | 
        
        
            | 
            | 
           469 | 
              | 
        
        
           | 5951 | 
           efrain | 
           470 | 
                   if($allowKnowledgeArea) {
  | 
        
        
            | 
            | 
           471 | 
                       $resources = getAclKnowledgeArea();
  | 
        
        
            | 
            | 
           472 | 
                       foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           473 | 
                       {
  | 
        
        
            | 
            | 
           474 | 
                           $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           475 | 
                       }
  | 
        
        
            | 
            | 
           476 | 
                   }
  | 
        
        
           | 5205 | 
           efrain | 
           477 | 
              | 
        
        
           | 6388 | 
           efrain | 
           478 | 
                   if($allowMyCoach) {
  | 
        
        
            | 
            | 
           479 | 
                       $resources = getAclMyCoach();
  | 
        
        
           | 6481 | 
           efrain | 
           480 | 
              | 
        
        
           | 7141 | 
           efrain | 
           481 | 
              | 
        
        
           | 6481 | 
           efrain | 
           482 | 
              | 
        
        
           | 6388 | 
           efrain | 
           483 | 
                       foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           484 | 
                       {
  | 
        
        
            | 
            | 
           485 | 
                           $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           486 | 
                       }
  | 
        
        
            | 
            | 
           487 | 
              | 
        
        
            | 
            | 
           488 | 
                   }
  | 
        
        
           | 5951 | 
           efrain | 
           489 | 
              | 
        
        
            | 
            | 
           490 | 
              | 
        
        
           | 6388 | 
           efrain | 
           491 | 
              | 
        
        
           | 3639 | 
           efrain | 
           492 | 
                   if($this->currentNetworkPlugin->getNetwork()->default == Network::DEFAULT_YES) {
  | 
        
        
            | 
            | 
           493 | 
              | 
        
        
            | 
            | 
           494 | 
                       $usertypes = getAclUsertypeDefaultNetwork();
  | 
        
        
            | 
            | 
           495 | 
                       foreach($usertypes as $usertype => $resources)
  | 
        
        
            | 
            | 
           496 | 
                       {
  | 
        
        
           | 5205 | 
           efrain | 
           497 | 
              | 
        
        
           | 3639 | 
           efrain | 
           498 | 
              | 
        
        
           | 5205 | 
           efrain | 
           499 | 
              | 
        
        
           | 3639 | 
           efrain | 
           500 | 
                           foreach ($resources as $resourceName)
  | 
        
        
            | 
            | 
           501 | 
                           {
  | 
        
        
            | 
            | 
           502 | 
                               $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           503 | 
                           }
  | 
        
        
            | 
            | 
           504 | 
                       }
  | 
        
        
            | 
            | 
           505 | 
              | 
        
        
            | 
            | 
           506 | 
              | 
        
        
            | 
            | 
           507 | 
                   } else {
  | 
        
        
           | 3647 | 
           efrain | 
           508 | 
              | 
        
        
           | 3645 | 
           efrain | 
           509 | 
                       if($this->currentUserPlugin->hasIdentity()) {
  | 
        
        
           | 3639 | 
           efrain | 
           510 | 
              | 
        
        
           | 5205 | 
           efrain | 
           511 | 
              | 
        
        
           | 3645 | 
           efrain | 
           512 | 
                           if($company) {
  | 
        
        
           | 3639 | 
           efrain | 
           513 | 
              | 
        
        
           | 5205 | 
           efrain | 
           514 | 
              | 
        
        
           | 3645 | 
           efrain | 
           515 | 
                               if($companyUser) {
  | 
        
        
            | 
            | 
           516 | 
                                   $usertype = $this->currentUserPlugin->getUserTypeId();
  | 
        
        
           | 3639 | 
           efrain | 
           517 | 
              | 
        
        
           | 3645 | 
           efrain | 
           518 | 
                                   if($companyUser->creator == CompanyUser::CREATOR_YES) {
  | 
        
        
            | 
            | 
           519 | 
              | 
        
        
            | 
            | 
           520 | 
                                       $resources =  getAclUsertypeOtherNetworkCreator();
  | 
        
        
            | 
            | 
           521 | 
                                       foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           522 | 
                                       {
  | 
        
        
            | 
            | 
           523 | 
                                           $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           524 | 
                                       }
  | 
        
        
            | 
            | 
           525 | 
              | 
        
        
           | 3639 | 
           efrain | 
           526 | 
                                   }
  | 
        
        
           | 3645 | 
           efrain | 
           527 | 
                                   if($companyUser->creator == CompanyUser::CREATOR_NO) {
  | 
        
        
            | 
            | 
           528 | 
                                       $resources =  getAclUsertypeOtherNetworkNonCreator();
  | 
        
        
            | 
            | 
           529 | 
                                       foreach($resources as $resourceName)
  | 
        
        
            | 
            | 
           530 | 
                                       {
  | 
        
        
            | 
            | 
           531 | 
                                           $this->acl->allow($usertype, $resourceName);
  | 
        
        
            | 
            | 
           532 | 
                                       }
  | 
        
        
           | 3639 | 
           efrain | 
           533 | 
                                   }
  | 
        
        
            | 
            | 
           534 | 
                               }
  | 
        
        
            | 
            | 
           535 | 
                           }
  | 
        
        
           | 3647 | 
           efrain | 
           536 | 
                       }
  | 
        
        
           | 3639 | 
           efrain | 
           537 | 
                   }
  | 
        
        
            | 
            | 
           538 | 
              | 
        
        
            | 
            | 
           539 | 
              | 
        
        
           | 1 | 
           www | 
           540 | 
                   $event->getViewModel()->setVariable('acl', $this->acl);
  | 
        
        
            | 
            | 
           541 | 
              | 
        
        
            | 
            | 
           542 | 
               }
  | 
        
        
            | 
            | 
           543 | 
              | 
        
        
            | 
            | 
           544 | 
               public function onDispatchError(MvcEvent $event)
  | 
        
        
            | 
            | 
           545 | 
               {
  | 
        
        
            | 
            | 
           546 | 
                   $this->processError($event);
  | 
        
        
            | 
            | 
           547 | 
               }
  | 
        
        
            | 
            | 
           548 | 
              | 
        
        
            | 
            | 
           549 | 
               public function onRenderError(MvcEvent $event)
  | 
        
        
            | 
            | 
           550 | 
               {
  | 
        
        
            | 
            | 
           551 | 
                   $this->processError($event);
  | 
        
        
            | 
            | 
           552 | 
               }
  | 
        
        
            | 
            | 
           553 | 
              | 
        
        
            | 
            | 
           554 | 
               public function sendResponse(\Laminas\Http\Response $response, $data)
  | 
        
        
            | 
            | 
           555 | 
               {
  | 
        
        
           | 7343 | 
           efrain | 
           556 | 
                   /*
  | 
        
        
            | 
            | 
           557 | 
                   $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           558 | 
                   $headers->clearHeaders();
  | 
        
        
            | 
            | 
           559 | 
                   $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
  | 
        
        
           | 1 | 
           www | 
           560 | 
              | 
        
        
           | 7343 | 
           efrain | 
           561 | 
                   $response->setStatusCode(200);
  | 
        
        
            | 
            | 
           562 | 
                   $response->setContent(json_encode($data));
  | 
        
        
            | 
            | 
           563 | 
                   $response->send();
  | 
        
        
           | 1 | 
           www | 
           564 | 
              | 
        
        
           | 7343 | 
           efrain | 
           565 | 
                   /*
  | 
        
        
           | 1 | 
           www | 
           566 | 
                   if($this->isJson) {
  | 
        
        
            | 
            | 
           567 | 
                       $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           568 | 
                       $headers->clearHeaders();
  | 
        
        
            | 
            | 
           569 | 
                       $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
  | 
        
        
            | 
            | 
           570 | 
              | 
        
        
            | 
            | 
           571 | 
                       $response->setStatusCode(200);
  | 
        
        
            | 
            | 
           572 | 
                       $response->setContent(json_encode($data));
  | 
        
        
            | 
            | 
           573 | 
                       $response->send();
  | 
        
        
            | 
            | 
           574 | 
              | 
        
        
            | 
            | 
           575 | 
                   } else {
  | 
        
        
            | 
            | 
           576 | 
                       throw new \Exception($data['data']);
  | 
        
        
           | 7343 | 
           efrain | 
           577 | 
                   }*/
  | 
        
        
            | 
            | 
           578 | 
                   //exit;
  | 
        
        
           | 1 | 
           www | 
           579 | 
               }
  | 
        
        
            | 
            | 
           580 | 
              | 
        
        
            | 
            | 
           581 | 
               public function processError(MvcEvent $event)
  | 
        
        
            | 
            | 
           582 | 
               {
  | 
        
        
            | 
            | 
           583 | 
              | 
        
        
            | 
            | 
           584 | 
                   $request =  $event->getRequest();
  | 
        
        
           | 7361 | 
           efrain | 
           585 | 
              | 
        
        
            | 
            | 
           586 | 
                   $response = $event->getResponse();
  | 
        
        
            | 
            | 
           587 | 
                   $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           588 | 
                   $headers->clearHeaders();
  | 
        
        
            | 
            | 
           589 | 
              | 
        
        
            | 
            | 
           590 | 
                   $response->setStatusCode(404);
  | 
        
        
            | 
            | 
           591 | 
                   $response->send();
  | 
        
        
            | 
            | 
           592 | 
              | 
        
        
            | 
            | 
           593 | 
              | 
        
        
           | 7343 | 
           efrain | 
           594 | 
                   //if((method_exists($request, 'isXmlHttpRequest') && $request->isXmlHttpRequest()) || ($this->isJson && !$this->isHtml)) {
  | 
        
        
            | 
            | 
           595 | 
                       /*
  | 
        
        
           | 1 | 
           www | 
           596 | 
                       $error = $event->getError();
  | 
        
        
            | 
            | 
           597 | 
                       if (!$error) {
  | 
        
        
            | 
            | 
           598 | 
                           return;
  | 
        
        
            | 
            | 
           599 | 
                       }
  | 
        
        
            | 
            | 
           600 | 
              | 
        
        
            | 
            | 
           601 | 
                       $response = $event->getResponse();
  | 
        
        
            | 
            | 
           602 | 
              | 
        
        
            | 
            | 
           603 | 
                       if('error-exception' == $error) {
  | 
        
        
            | 
            | 
           604 | 
                           $exception = $event->getParam('exception');
  | 
        
        
            | 
            | 
           605 | 
                           error_log($exception->getCode() . ' ' . $exception->getMessage());
  | 
        
        
            | 
            | 
           606 | 
                           error_log($exception->getTraceAsString());
  | 
        
        
            | 
            | 
           607 | 
              | 
        
        
            | 
            | 
           608 | 
              | 
        
        
            | 
            | 
           609 | 
                           $data = [
  | 
        
        
            | 
            | 
           610 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           611 | 
                               'data' => 'An error occurred during execution; please try again later.'
  | 
        
        
            | 
            | 
           612 | 
                           ];
  | 
        
        
            | 
            | 
           613 | 
              | 
        
        
            | 
            | 
           614 | 
                       } else if('error-router-no-match' == $error) {
  | 
        
        
            | 
            | 
           615 | 
                           $data = [
  | 
        
        
            | 
            | 
           616 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           617 | 
                               'data' => 'Resource not found.'
  | 
        
        
            | 
            | 
           618 | 
              | 
        
        
            | 
            | 
           619 | 
                           ];
  | 
        
        
            | 
            | 
           620 | 
                       } else if(' error-controller-not-found' == $error) {
  | 
        
        
            | 
            | 
           621 | 
                           $data = [
  | 
        
        
            | 
            | 
           622 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           623 | 
                               'data' => 'Controller not found.'
  | 
        
        
            | 
            | 
           624 | 
              | 
        
        
            | 
            | 
           625 | 
                           ];
  | 
        
        
            | 
            | 
           626 | 
                       } else {
  | 
        
        
            | 
            | 
           627 | 
                           $data = [
  | 
        
        
            | 
            | 
           628 | 
                               'success' => false,
  | 
        
        
            | 
            | 
           629 | 
                               'data' => 'Unknow error.' , 'error' => $error
  | 
        
        
            | 
            | 
           630 | 
              | 
        
        
            | 
            | 
           631 | 
                           ];
  | 
        
        
            | 
            | 
           632 | 
                       }
  | 
        
        
            | 
            | 
           633 | 
              | 
        
        
           | 7343 | 
           efrain | 
           634 | 
                       $this->sendResponse($response, $data);*/
  | 
        
        
            | 
            | 
           635 | 
                   //}
  | 
        
        
           | 1 | 
           www | 
           636 | 
              | 
        
        
            | 
            | 
           637 | 
                   $this->initAcl($event);
  | 
        
        
           | 7343 | 
           efrain | 
           638 | 
                   $this->authPreDispatch($event);
  | 
        
        
           | 1 | 
           www | 
           639 | 
               }
  | 
        
        
            | 
            | 
           640 | 
              | 
        
        
            | 
            | 
           641 | 
              | 
        
        
            | 
            | 
           642 | 
               public function authPreDispatch(MvcEvent $event)
  | 
        
        
            | 
            | 
           643 | 
               {
  | 
        
        
           | 210 | 
           efrain | 
           644 | 
              | 
        
        
            | 
            | 
           645 | 
              | 
        
        
            | 
            | 
           646 | 
              | 
        
        
            | 
            | 
           647 | 
              | 
        
        
           | 1 | 
           www | 
           648 | 
                   $serviceManager = $event->getApplication()->getServiceManager();
  | 
        
        
            | 
            | 
           649 | 
                   $adapter = $serviceManager->get('leaders-linked-db');
  | 
        
        
            | 
            | 
           650 | 
              | 
        
        
           | 210 | 
           efrain | 
           651 | 
                   $routeName = $event->getRouteMatch()->getMatchedRouteName();
  | 
        
        
            | 
            | 
           652 | 
              | 
        
        
           | 1 | 
           www | 
           653 | 
              | 
        
        
           | 210 | 
           efrain | 
           654 | 
                   $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? trim(strtoupper($_SERVER['REQUEST_METHOD'])) : '';
  | 
        
        
            | 
            | 
           655 | 
              | 
        
        
            | 
            | 
           656 | 
                   if($requestMethod == 'POST' || $requestMethod == 'PUT' || $requestMethod == 'DELETE') {
  | 
        
        
            | 
            | 
           657 | 
              | 
        
        
           | 1979 | 
           efrain | 
           658 | 
              | 
        
        
           | 1323 | 
           efrain | 
           659 | 
                       if($this->authByHeaders && substr($routeName, 0, 8) == 'services') {
  | 
        
        
            | 
            | 
           660 | 
                           $exclude = true;
  | 
        
        
            | 
            | 
           661 | 
                       } else {
  | 
        
        
            | 
            | 
           662 | 
                           $exclude = false;
  | 
        
        
            | 
            | 
           663 | 
              | 
        
        
            | 
            | 
           664 | 
                           $usertypes = getAclUsertype();
  | 
        
        
            | 
            | 
           665 | 
              | 
        
        
            | 
            | 
           666 | 
              | 
        
        
            | 
            | 
           667 | 
                           foreach($usertypes[UserType::GUEST] as $resourceName)
  | 
        
        
            | 
            | 
           668 | 
                           {
  | 
        
        
            | 
            | 
           669 | 
                              if($routeName == $resourceName) {
  | 
        
        
            | 
            | 
           670 | 
                                 $exclude = true;
  | 
        
        
            | 
            | 
           671 | 
                                 break;
  | 
        
        
            | 
            | 
           672 | 
                               }
  | 
        
        
           | 210 | 
           efrain | 
           673 | 
                           }
  | 
        
        
            | 
            | 
           674 | 
                       }
  | 
        
        
           | 4131 | 
           efrain | 
           675 | 
              | 
        
        
           | 4808 | 
           efrain | 
           676 | 
                       $exclude = true;
  | 
        
        
           | 1979 | 
           efrain | 
           677 | 
              | 
        
        
           | 210 | 
           efrain | 
           678 | 
                       if(!$exclude) {
  | 
        
        
            | 
            | 
           679 | 
                           $httpToken = isset($_SERVER['HTTP_X_CSRF_TOKEN']) ? $_SERVER['HTTP_X_CSRF_TOKEN'] : '';
  | 
        
        
            | 
            | 
           680 | 
                           $sessionToken = isset($_SESSION['token']) ? $_SESSION['token'] : uniqid();
  | 
        
        
            | 
            | 
           681 | 
              | 
        
        
            | 
            | 
           682 | 
                           unset($_SESSION['token']);
  | 
        
        
            | 
            | 
           683 | 
                           if ( $httpToken != $sessionToken) {
  | 
        
        
            | 
            | 
           684 | 
                               header("HTTP/1.1 401 Unauthorized");
  | 
        
        
            | 
            | 
           685 | 
                               exit;
  | 
        
        
            | 
            | 
           686 | 
                           }
  | 
        
        
            | 
            | 
           687 | 
              | 
        
        
            | 
            | 
           688 | 
                       }
  | 
        
        
            | 
            | 
           689 | 
                   }
  | 
        
        
            | 
            | 
           690 | 
              | 
        
        
            | 
            | 
           691 | 
              | 
        
        
            | 
            | 
           692 | 
              | 
        
        
           | 3639 | 
           efrain | 
           693 | 
                   if($this->currentUserPlugin->hasIdentity())  {
  | 
        
        
            | 
            | 
           694 | 
                       $user = $this->currentUserPlugin->getUser();
  | 
        
        
           | 1 | 
           www | 
           695 | 
                       $userTypeId = $user->usertype_id;
  | 
        
        
            | 
            | 
           696 | 
              | 
        
        
            | 
            | 
           697 | 
              | 
        
        
            | 
            | 
           698 | 
                   }  else {
  | 
        
        
            | 
            | 
           699 | 
              | 
        
        
            | 
            | 
           700 | 
                       $userTypeId = UserType::GUEST;
  | 
        
        
            | 
            | 
           701 | 
                   }
  | 
        
        
            | 
            | 
           702 | 
              | 
        
        
           | 210 | 
           efrain | 
           703 | 
              | 
        
        
           | 1 | 
           www | 
           704 | 
                   if($this->acl->isAllowed($userTypeId, $routeName)) {
  | 
        
        
           | 3639 | 
           efrain | 
           705 | 
                       $user = $this->currentUserPlugin->getUser();
  | 
        
        
           | 210 | 
           efrain | 
           706 | 
              | 
        
        
           | 1 | 
           www | 
           707 | 
              | 
        
        
            | 
            | 
           708 | 
                       if($user) {
  | 
        
        
           | 3086 | 
           efrain | 
           709 | 
              | 
        
        
            | 
            | 
           710 | 
                           $updateLastActivity = true;
  | 
        
        
            | 
            | 
           711 | 
                           if ('chat' == substr($routeName, 0, 4)) {
  | 
        
        
            | 
            | 
           712 | 
                               $updateLastActivity = false;
  | 
        
        
            | 
            | 
           713 | 
                           }
  | 
        
        
            | 
            | 
           714 | 
                           if ('inmail' == substr($routeName, 0, 6)) {
  | 
        
        
            | 
            | 
           715 | 
                               $updateLastActivity = false;
  | 
        
        
            | 
            | 
           716 | 
                           }
  | 
        
        
            | 
            | 
           717 | 
                           if ('check-session' == $routeName) {
  | 
        
        
            | 
            | 
           718 | 
                               $updateLastActivity = false;
  | 
        
        
            | 
            | 
           719 | 
                           }
  | 
        
        
            | 
            | 
           720 | 
              | 
        
        
            | 
            | 
           721 | 
              | 
        
        
            | 
            | 
           722 | 
                           if($updateLastActivity) {
  | 
        
        
            | 
            | 
           723 | 
                               $userMapper = UserMapper::getInstance($adapter);
  | 
        
        
            | 
            | 
           724 | 
                               $userMapper->updateLastActivity($user->id);
  | 
        
        
            | 
            | 
           725 | 
                           }
  | 
        
        
           | 1 | 
           www | 
           726 | 
                       }
  | 
        
        
            | 
            | 
           727 | 
              | 
        
        
           | 7335 | 
           efrain | 
           728 | 
              | 
        
        
           | 7330 | 
           efrain | 
           729 | 
              | 
        
        
           | 1 | 
           www | 
           730 | 
                   } else {
  | 
        
        
           | 210 | 
           efrain | 
           731 | 
              | 
        
        
           | 7356 | 
           efrain | 
           732 | 
                       if($this->authByHeaders || $this->isJson) {
  | 
        
        
           | 1 | 
           www | 
           733 | 
                           $response = $event->getResponse();
  | 
        
        
            | 
            | 
           734 | 
                           $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           735 | 
                           $headers->clearHeaders();
  | 
        
        
            | 
            | 
           736 | 
                           $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
  | 
        
        
            | 
            | 
           737 | 
              | 
        
        
            | 
            | 
           738 | 
                           $response->setStatusCode(401);
  | 
        
        
            | 
            | 
           739 | 
                           $response->setContent(json_encode(['success' => false, 'data' => 'Unauthorized.', 'fatal' => true]));
  | 
        
        
            | 
            | 
           740 | 
                           $response->send();
  | 
        
        
            | 
            | 
           741 | 
                           exit;
  | 
        
        
            | 
            | 
           742 | 
              | 
        
        
           | 210 | 
           efrain | 
           743 | 
                       }
  | 
        
        
           | 1 | 
           www | 
           744 | 
              | 
        
        
           | 7361 | 
           efrain | 
           745 | 
                       $response = $event->getResponse();
  | 
        
        
            | 
            | 
           746 | 
                       $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           747 | 
                       $headers->clearHeaders();
  | 
        
        
           | 7357 | 
           efrain | 
           748 | 
              | 
        
        
           | 7361 | 
           efrain | 
           749 | 
                       $response->setStatusCode(401);
  | 
        
        
            | 
            | 
           750 | 
                       $response->send();
  | 
        
        
           | 7357 | 
           efrain | 
           751 | 
              | 
        
        
           | 7361 | 
           efrain | 
           752 | 
                       exit;
  | 
        
        
            | 
            | 
           753 | 
              | 
        
        
            | 
            | 
           754 | 
              | 
        
        
           | 1 | 
           www | 
           755 | 
                       //print_r($this->routesAuthorized);
  | 
        
        
            | 
            | 
           756 | 
                      // echo 'sin permiso'; exit;
  | 
        
        
           | 7356 | 
           efrain | 
           757 | 
                       /*
  | 
        
        
           | 1 | 
           www | 
           758 | 
              | 
        
        
           | 3639 | 
           efrain | 
           759 | 
                       $this->currentUserPlugin->clearIdentity();
  | 
        
        
           | 1 | 
           www | 
           760 | 
              | 
        
        
            | 
            | 
           761 | 
              | 
        
        
           | 7356 | 
           efrain | 
           762 | 
                      // if() {
  | 
        
        
           | 1 | 
           www | 
           763 | 
                           $response = $event->getResponse();
  | 
        
        
            | 
            | 
           764 | 
                           $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           765 | 
                           $headers->clearHeaders();
  | 
        
        
            | 
            | 
           766 | 
                           $headers->addHeaderLine('Content-type', 'application/json; charset=UTF-8');
  | 
        
        
            | 
            | 
           767 | 
              | 
        
        
            | 
            | 
           768 | 
                           $response->setStatusCode(200);
  | 
        
        
            | 
            | 
           769 | 
                           $response->setContent(json_encode(['success' => false, 'data' => 'Unauthorized.', 'fatal' => true]));
  | 
        
        
            | 
            | 
           770 | 
                           $response->send();
  | 
        
        
           | 7356 | 
           efrain | 
           771 | 
              | 
        
        
           | 1 | 
           www | 
           772 | 
                       } else {
  | 
        
        
            | 
            | 
           773 | 
                           $url = $event->getRouter()->assemble([], ['name' => 'signout']);
  | 
        
        
            | 
            | 
           774 | 
              | 
        
        
            | 
            | 
           775 | 
                           $response = $event->getResponse();
  | 
        
        
            | 
            | 
           776 | 
                           $headers = $response->getHeaders();
  | 
        
        
            | 
            | 
           777 | 
                           $headers->clearHeaders();
  | 
        
        
            | 
            | 
           778 | 
                           $headers->addHeaderLine('Location', $url);
  | 
        
        
            | 
            | 
           779 | 
              | 
        
        
            | 
            | 
           780 | 
                           $response->setStatusCode(302);
  | 
        
        
            | 
            | 
           781 | 
                           $response->send();
  | 
        
        
           | 7354 | 
           efrain | 
           782 | 
                       }*/
  | 
        
        
           | 7356 | 
           efrain | 
           783 | 
              | 
        
        
           | 1 | 
           www | 
           784 | 
                   }
  | 
        
        
            | 
            | 
           785 | 
              | 
        
        
            | 
            | 
           786 | 
              | 
        
        
            | 
            | 
           787 | 
               }
  | 
        
        
            | 
            | 
           788 | 
              | 
        
        
            | 
            | 
           789 | 
              | 
        
        
            | 
            | 
           790 | 
               public function authPosDispatch(MvcEvent $event)
  | 
        
        
            | 
            | 
           791 | 
               {
  | 
        
        
           | 7339 | 
           efrain | 
           792 | 
                  /// if($this->isHtml) {
  | 
        
        
           | 7352 | 
           efrain | 
           793 | 
                       /*if(empty($_SERVER['REDIRECT_URL'])) {
  | 
        
        
           | 7335 | 
           efrain | 
           794 | 
                           if(empty($_SERVER['REQUEST_URI'])) {
  | 
        
        
            | 
            | 
           795 | 
                               $routeName = '';
  | 
        
        
            | 
            | 
           796 | 
              | 
        
        
            | 
            | 
           797 | 
                           } else {
  | 
        
        
            | 
            | 
           798 | 
                               $routeName = $_SERVER['REQUEST_URI'];
  | 
        
        
            | 
            | 
           799 | 
                           }
  | 
        
        
            | 
            | 
           800 | 
              | 
        
        
            | 
            | 
           801 | 
                       } else {
  | 
        
        
            | 
            | 
           802 | 
                           $routeName = $_SERVER['REDIRECT_URL'];
  | 
        
        
            | 
            | 
           803 | 
              | 
        
        
            | 
            | 
           804 | 
                       }
  | 
        
        
            | 
            | 
           805 | 
              | 
        
        
            | 
            | 
           806 | 
              | 
        
        
            | 
            | 
           807 | 
                       $routeName = strtolower(trim($routeName));
  | 
        
        
            | 
            | 
           808 | 
                       if(strlen($routeName) > 0 && substr($routeName, 0, 1) == '/') {
  | 
        
        
            | 
            | 
           809 | 
                           $routeName = substr($routeName, 1);
  | 
        
        
            | 
            | 
           810 | 
                       }
  | 
        
        
            | 
            | 
           811 | 
              | 
        
        
            | 
            | 
           812 | 
              | 
        
        
            | 
            | 
           813 | 
                       $exclude = [
  | 
        
        
           | 7343 | 
           efrain | 
           814 | 
                           'home',
  | 
        
        
           | 7335 | 
           efrain | 
           815 | 
                           'oauth/facebook',
  | 
        
        
            | 
            | 
           816 | 
                           'oauth/facebook/cancel',
  | 
        
        
            | 
            | 
           817 | 
                           'oauth/facebook/delete',
  | 
        
        
            | 
            | 
           818 | 
                           'oauth/twitter',
  | 
        
        
            | 
            | 
           819 | 
                           'oauth/google',
  | 
        
        
            | 
            | 
           820 | 
                           'oauth/instagram',
  | 
        
        
            | 
            | 
           821 | 
                           'paypal',
  | 
        
        
            | 
            | 
           822 | 
                           'paypal/success',
  | 
        
        
            | 
            | 
           823 | 
                           'paypal/cancel',
  | 
        
        
            | 
            | 
           824 | 
                           'storage',
  | 
        
        
            | 
            | 
           825 | 
                           'storage-network',
  | 
        
        
            | 
            | 
           826 | 
                           'signout'
  | 
        
        
            | 
            | 
           827 | 
              | 
        
        
            | 
            | 
           828 | 
                       ];
  | 
        
        
            | 
            | 
           829 | 
              | 
        
        
            | 
            | 
           830 | 
                       if(!in_array($routeName, $exclude)) {
  | 
        
        
           | 7352 | 
           efrain | 
           831 | 
              | 
        
        
            | 
            | 
           832 | 
                           $event->getViewModel()->setVariables([
  | 
        
        
            | 
            | 
           833 | 
              | 
        
        
            | 
            | 
           834 | 
                           ]);
  | 
        
        
            | 
            | 
           835 | 
                       }*/
  | 
        
        
           | 7335 | 
           efrain | 
           836 | 
              | 
        
        
           | 7353 | 
           efrain | 
           837 | 
                       $event->getViewModel()->setTemplate('layout/layout');
  | 
        
        
           | 7352 | 
           efrain | 
           838 | 
              | 
        
        
           | 7339 | 
           efrain | 
           839 | 
                  /// }
  | 
        
        
           | 1 | 
           www | 
           840 | 
               }
  | 
        
        
           | 7330 | 
           efrain | 
           841 | 
              | 
        
        
           | 7335 | 
           efrain | 
           842 | 
              | 
        
        
           | 1 | 
           www | 
           843 | 
              | 
        
        
            | 
            | 
           844 | 
              | 
        
        
            | 
            | 
           845 | 
           }
  |