getApplication()->getEventManager(); $sm = $e->getApplication()->getServiceManager(); // Process to save device Infos for all view see https://stackoverflow.com/questions/24524899/zf2-add-global-variable-to-view // can be call in view with $this.layout()->viewDeviceInfos $eventManager->attach(MvcEvent::EVENT_RENDER, function ($e) { $sm = $e->getApplication()->getServiceManager();// getServiceLocator(); // activation ou non de la partie mobile CWR $table = $sm->get('Reservation\Model\ConfigurationTable'); $config = $table->getConfig(1); $CWRActive = $config->CWRMobile ? $config->CWRMobile : false; $layoutViewModel = $e->getViewModel(); if($CWRActive) { // A voir pour un paramétrage de la versions mobile ou non $viewDeviceInfos = [ // Check if the "mobile" word exists in User-Agent 'isMob' => is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "mobile")), // Check if the "tablet" word exists in User-Agent 'isTab' => is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "tablet")), // Platform check 'isWin' => is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "windows")), 'isAndroid' => is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "android")), 'isIPhone' => is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "iphone")), 'isIPad' => is_numeric(strpos(strtolower($_SERVER["HTTP_USER_AGENT"]), "ipad")) ]; } else { $viewDeviceInfos = [ // Check if the "mobile" word exists in User-Agent 'isMob' =>false, // Check if the "tablet" word exists in User-Agent 'isTab' =>false, // Platform check 'isWin' =>false, 'isAndroid' =>false, 'isIPhone' =>false, 'isIPad' =>false ]; } $viewDeviceInfos['isIOS'] = $viewDeviceInfos['isIphone'] || $viewDeviceInfos['isIPad']; $layoutViewModel->viewDeviceInfos = $viewDeviceInfos; $isXMLHttpRequest = $e->getRequest()->isXmlHttpRequest(); if(!$isXMLHttpRequest) { $table = $sm->get('Application\Model\ConfigApiPushTable'); $config = $table->fetch(); $layoutViewModel->configApiPush = $config; } }); $this->initSession(array( // 'remember_me_seconds' => 180, 'use_cookies' => true, 'cookie_httponly' => true, )); // getUser $auth_service = $sm->get('zfcuser_auth_service'); $gestName = ''; $isBo = false; if ($auth_service && $auth_service->hasIdentity()) { $gestName = $auth_service->getIdentity()->getUsername(); $isBo = true; } if(!$isBo) { $this->checkPostRequestFromCurrentConnectedUser($e); // check if post request with locId is from current connected user (security) not for bo connection } date_default_timezone_set('Europe/Paris'); $langfile = "fr_FR"; $allLangues = array(); $routeCallback = function ($e) { // $table = new Tables('lang',$e->getApplication()->getServiceManager()->get('Zend\Db\Adapter\Adapter')); // $langTable = $table->getTable(); // $result = $langTable->select(array('active'=>'1')); $langTable = $e->getApplication()->getServiceManager()->get('Reservation\Model\LangueTable'); $result = $langTable->getAll(); $availableLanguages = array(); $defaultLanguage = 'fr_FR'; foreach ($result as $row) { $availableLanguages[] = $row->codeLang; if ($row->default == '1') { $defaultLanguage = $row->codeLang; } } //$availableLanguages = array ('fr_FR', 'en_US'); $language = ""; $fromRoute = false; //see if language could be find in url $lang_session = new Container('lang'); $lang = $lang_session->lang; //echo $lang; $langfile = $lang; $sess = new Container("loc"); $loc = $sess->loc; // var_dump("locCallBack",$loc); if ($loc) { if ($loc->langue == "UK") { $defaultLanguage = 'en_US'; } else { $defaultLanguage = 'fr_FR'; } } if ($lang) { $language = $lang; $fromRoute = true; //or use language from http accept } else { $headers = $e->getApplication()->getRequest()->getHeaders(); if ($headers->has('Accept-Language')) { $headerLocale = $headers->get('Accept-Language')->getPrioritized(); $language = substr($headerLocale[0]->getLanguage(), 0, 5); } } if (!in_array($language, $availableLanguages)) { $language = $defaultLanguage; } $e->getApplication()->getServiceManager()->get('translator')->setLocale($language); }; $eventManager->attach(MvcEvent::EVENT_ROUTE, $routeCallback); $sm = $e->getApplication()->getServiceManager(); $table = new Tables('lang', $sm->get('Zend\Db\Adapter\Adapter')); $result = $table->getTable()->select(array('active' => '1')); $langueBO = array(); foreach ($result as $row) { $allLangues[] = $row; if ($row->codeLang == "fr_FR") { $langueBO[] = $row; } } $router = $sm->get('router'); $request = $sm->get('request'); $matchedRoute = $router->match($request); $idCampagne = ""; $logoCampagne = ""; $params = $controller = $action = $route = null; if ($matchedRoute) { $params = $matchedRoute->getParams(); $controller = $params['controller']; $action = $params['action']; $route = $matchedRoute->getMatchedRouteName(); ## RECUP CAMPAGNE $urlAcces = !empty($params['acces']) ? $params['acces'] : ''; if ($urlAcces) { $tableCampagne = $e->getApplication()->getServiceManager()->get('Reservation\Model\CampagneTable'); $camps = $tableCampagne->getCampagnesByUrlAcces($urlAcces); $now = time(); foreach ($camps as $camp) { $dateDebutTS = strtotime($camp->dateDebut); $dateFinTS = strtotime($camp->dateFin); //vérification ouverture de la campagne if ($now >= $dateDebutTS && $now <= $dateFinTS) { $idCampagne = $camp->id; $logoCampagne = $camp->logo; } } } } $module_array = explode('\\', $controller); $module = array_pop($module_array); //roles $authorize = $sm->get('BjyAuthorize\Provider\Identity\ProviderInterface'); $roles = $authorize->getIdentityRoles(); $isAdmin = false; if (in_array('admin', $roles)) { $isAdmin = true; } // getUser $auth_service = $sm->get('zfcuser_auth_service'); $gestName = ''; if ($auth_service && $auth_service->hasIdentity()) { $gestName = $auth_service->getIdentity()->getUsername(); } $sess = new Container("locSess"); $loc = $sess->loc; // var_dump($_SESSION["loc"],$isAdmin, $gestName, $module, $controller, $action, $route, $params); //$allLangues = array(); if ($route) { $routesArr = explode('/', $route); if (in_array('zfcuser', $routesArr)) { $allLangues = $langueBO; } syslog(LOG_INFO, __FILE__.".".__FUNCTION__.".".__LINE__."_$_SERVER[REMOTE_ADDR] : route=".json_encode($routesArr)); } syslog(LOG_INFO, __FILE__.".".__FUNCTION__.".".__LINE__."_$_SERVER[REMOTE_ADDR] : controller=$controller action=$action route=$route module=$module isAdmin=$isAdmin($gestName) idCampagne=$idCampagne"); $e->getViewModel()->setVariables( array( 'CURRENT_MODULE_NAME' => $module, 'CURRENT_CONTROLLER_NAME' => $controller, 'CURRENT_ACTION_NAME' => $action, 'CURRENT_ROUTE_NAME' => $route, 'ALL_LANGUES' => $allLangues, 'IS_ADMIN' => $isAdmin, 'CURRENT_PARAMS' => $params, 'idCampagne' => $idCampagne, 'logoCampagne' => $logoCampagne, ) ); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); } public function initSession($config) { $sessionConfig = new SessionConfig(); $sessionConfig->setOptions($config); $sessionManager = new SessionManager($sessionConfig); $sessionManager->start(); Container::setDefaultManager($sessionManager); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function getServiceConfig() { return array( 'factories' => array( 'Application\Model\CodeTable' => function ($sm) { $tableGateway = $sm->get('CodeTableGateway'); $table = new CodeTable($tableGateway); return $table; }, 'CodeTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Code()); return new TableGateway('codes', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\PaysTable' => function ($sm) { $tableGateway = $sm->get('PaysTableGateway'); $table = new PaysTable($tableGateway); return $table; }, 'PaysTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Pays()); return new TableGateway('pays', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\LocataireTable' => function ($sm) { $tableGateway = $sm->get('LocataireTableGateway'); $table = new LocataireTable($tableGateway); return $table; }, 'LocataireTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Locataire()); return new TableGateway('locataires', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\TypelogementTable' => function ($sm) { $tableGateway = $sm->get('TypelogementTableGateway'); $table = new TypelogementTable($tableGateway); return $table; }, 'TypelogementTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Typelogement()); return new TableGateway('type_logement', $dbAdapter, null, $resultSetPrototype); }, /*attribution de la table*/ 'Application\Model\EchangeXmlSql' => function ($sm) { $tableGateway = $sm->get('EchangeXmlSqlTableGateway'); $table = new EchangeXmlSql($tableGateway); return $table; }, 'EchangeXmlSqlTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new EchangeXmlObject()); return new TableGateway('reservations', $dbAdapter, null, $resultSetPrototype); }, /*fin attribution*/ 'Application\Model\ComptesTable' => function ($sm) { $tableGateway = $sm->get('ComptesTableGateway'); $table = new ComptesTable($tableGateway); return $table; }, 'ComptesTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Comptes()); return new TableGateway('comptes', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\PileTable' => function ($sm) { $tableGateway = $sm->get('PileTableGateway'); $table = new PileTable($tableGateway); return $table; }, 'PileTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Pile()); return new TableGateway('pile', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\DocumentsTable' => function ($sm) { $tableGateway = $sm->get('DocumentsTableGateway'); $table = new DocumentsTable($tableGateway); return $table; }, 'DocumentsTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Documents()); return new TableGateway('documents', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\LocaTable' => function ($sm) { $tableGateway = $sm->get('LocaTableGateway'); $table = new LocaTable($tableGateway); return $table; }, 'LocaTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Loca()); return new TableGateway('locataires', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\SessionWLTable' => function ($sm) { $tableGateway = $sm->get('SessionWLTableGateway'); $table = new SessionWLTable($tableGateway); return $table; }, 'SessionWLTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new SessionWL()); return new TableGateway('session', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\UrlTokenTable' => function ($sm) { $tableGateway = $sm->get('UrlTokenTableGateway'); $table = new UrlTokenTable($tableGateway); return $table; }, 'UrlTokenTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new UrlToken()); return new TableGateway('urlToken', $dbAdapter, null, $resultSetPrototype); }, 'Application\Model\ConfigApiPushTable' => function ($sm) { //LOLODEV $tableGateway = $sm->get('ConfigApiPushTableGateway'); $table = new ConfigApiPushTable($tableGateway); return $table; }, 'ConfigApiPushTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new ConfigApiPush()); return new TableGateway('configApiPush', $dbAdapter, null, $resultSetPrototype); }, ), ); } public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } private function checkPostRequestFromCurrentConnectedUser(MvcEvent $e) { $request = $e->getApplication()->getServiceManager()->get('Request'); if ($request->isPost()) { if($request->getPost('locId', null) == null) { return true; } $locIdPost = $request->getPost('locId'); $locIdSession = $_SESSION['loc']['loc']->id; // $resa = $_SESSION['locSess']; // var_dump( $_SESSION['loc'], $locIdSession, array_keys($_SESSION) ); if ($locIdPost == $locIdSession) { return true; } die(); } } }