2018-12-18 09:44:39 +01:00
|
|
|
<?php
|
|
|
|
namespace Cadoles\CoreBundle\EventListener;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
use Symfony\Component\EventDispatcher\Event;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
|
|
|
|
|
|
|
class sessionListener {
|
|
|
|
protected $container;
|
|
|
|
protected $em;
|
|
|
|
|
|
|
|
public function __construct($container, EntityManager $em, TokenStorageInterface $token_storage)
|
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
$this->em = $em;
|
|
|
|
$this->token_storage = $token_storage;
|
|
|
|
}
|
|
|
|
|
2019-06-17 17:09:00 +02:00
|
|
|
public function haveRole($roles,$tohave,$route) {
|
|
|
|
$haverole=false;
|
2018-12-18 09:44:39 +01:00
|
|
|
if($roles=="") {
|
2019-06-17 17:09:00 +02:00
|
|
|
if(empty($tohave)) $haverole=true;
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($roles as $role) {
|
|
|
|
if(in_array($role,$tohave))
|
2019-06-17 17:09:00 +02:00
|
|
|
$haverole=true;
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-17 17:09:00 +02:00
|
|
|
if($route!=null) {
|
|
|
|
if($haverole&&in_array("ROLE_MODO",$roles)) {
|
|
|
|
$permmodo=$this->em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(["route"=>$route,"visible"=>true]);
|
|
|
|
if(!$permmodo) $haverole=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $haverole;
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function onDomainParse(Event $event) {
|
|
|
|
$session = new Session();
|
|
|
|
|
2019-04-16 09:49:49 +02:00
|
|
|
|
|
|
|
|
2019-03-12 14:50:57 +01:00
|
|
|
$configs = $this->em->getRepository("CadolesCoreBundle:Config")->findAll();
|
|
|
|
foreach($configs as $config) {
|
2019-07-10 17:22:44 +02:00
|
|
|
//dump($config->getId()." = ".strval($config->getValue()));
|
2019-04-16 09:49:49 +02:00
|
|
|
$session->set($config->getId(), strval($config->getValue()));
|
2019-03-12 14:50:57 +01:00
|
|
|
}
|
2019-07-10 17:22:44 +02:00
|
|
|
|
|
|
|
|
2018-12-18 09:44:39 +01:00
|
|
|
// Calcul des couleurs
|
|
|
|
$color = $this->container->get('cadoles.core.service.color');
|
|
|
|
$color->setColor();
|
|
|
|
|
|
|
|
// Utilisateur en cours
|
|
|
|
$curentuserid=0;
|
|
|
|
$token = $this->token_storage->getToken();
|
|
|
|
if(!$token) return;
|
|
|
|
$curentuser=$token->getUser();
|
|
|
|
|
|
|
|
// Roles actif
|
2019-06-17 17:09:00 +02:00
|
|
|
if($curentuser=="anon.") $roles=[];
|
2018-12-18 09:44:39 +01:00
|
|
|
else $roles=$curentuser->getRoles();
|
|
|
|
|
2019-06-25 15:53:10 +02:00
|
|
|
// Masteridentity
|
|
|
|
$masteridentity =$this->container->getParameter('masteridentity');
|
|
|
|
$session->set('masteridentity',$masteridentity);
|
|
|
|
|
|
|
|
// mode_auth
|
|
|
|
$mode_auth =$this->container->getParameter('mode_auth');
|
|
|
|
$session->set('mode_auth',$mode_auth);
|
|
|
|
|
2019-03-21 17:15:06 +01:00
|
|
|
// App activate
|
2019-06-04 15:05:41 +02:00
|
|
|
$app=[];
|
2019-11-28 10:37:12 +01:00
|
|
|
$app["importuser_activate"] =($masteridentity=="SQL");
|
|
|
|
|
|
|
|
$app["portal_activate"] =$this->container->getParameter('portal_activate');
|
|
|
|
$app["cron_activate"] =$this->container->getParameter('cron_activate');
|
|
|
|
$app["module_activate"] =$this->container->getParameter('module_activate');
|
|
|
|
$app["page_activate"] =$this->container->getParameter('page_activate');
|
|
|
|
$app["item_activate"] =$this->container->getParameter('item_activate');
|
|
|
|
$app["alert_activate"] =$this->container->getParameter('alert_activate');
|
|
|
|
$app["calendar_activate"] =$this->container->getParameter('calendar_activate');
|
|
|
|
$app["blog_activate"] =$this->container->getParameter('blog_activate');
|
|
|
|
$app["flux_activate"] =$this->container->getParameter('flux_activate');
|
|
|
|
$app["notice_activate"] =$this->container->getParameter('notice_activate');
|
|
|
|
$app["syncenvole_activate"] =$this->container->getParameter('syncenvole_activate');
|
|
|
|
$app["activate_widlimesurvey"] =$this->container->getParameter('activate_widlimesurvey');
|
|
|
|
$app["activate_widmoodle"] =$this->container->getParameter('activate_widmoodle');
|
|
|
|
$app["activate_widpiwik"] =$this->container->getParameter('activate_widpiwik');
|
|
|
|
$app["activate_widwordpress"] =$this->container->getParameter('activate_widwordpress');
|
|
|
|
|
|
|
|
$app["widbalado_activate_syncenvole"] =$this->container->getParameter('widbalado_activate_syncenvole');
|
|
|
|
$app["widgepi_activate_syncenvole"] =$this->container->getParameter('widgepi_activate_syncenvole');
|
|
|
|
$app["widnextcloud_activate_syncenvole"] =$this->container->getParameter('widnextcloud_activate_syncenvole');
|
|
|
|
$app["widpiwik_activate_syncenvole"] =$this->container->getParameter('widpiwik_activate_syncenvole');
|
|
|
|
$app["widsacoche_activate_syncenvole"] =$this->container->getParameter('widsacoche_activate_syncenvole');
|
2019-03-21 17:15:06 +01:00
|
|
|
|
2018-12-18 09:44:39 +01:00
|
|
|
// Chargement de la sidebar
|
|
|
|
$iconniveau01 =$this->container->getParameter('iconniveau01');
|
|
|
|
$labelsniveau01 =$this->container->getParameter('labelsniveau01');
|
|
|
|
$labelniveau01 =$this->container->getParameter('labelsniveau01');
|
|
|
|
$session->set('labelniveau01',$labelniveau01);
|
|
|
|
|
2019-03-12 14:50:57 +01:00
|
|
|
$viewniveau02 =$this->container->getParameter('viewniveau02');
|
2018-12-18 09:44:39 +01:00
|
|
|
$iconniveau02 =$this->container->getParameter('iconniveau02');
|
|
|
|
$labelsniveau02 =$this->container->getParameter('labelsniveau02');
|
2019-06-27 16:55:26 +02:00
|
|
|
$labelniveau02 =$this->container->getParameter('labelniveau02');
|
2019-06-13 13:15:55 +02:00
|
|
|
$session->set('viewniveau02',$viewniveau02);
|
2018-12-18 09:44:39 +01:00
|
|
|
$session->set('labelniveau02',$labelniveau02);
|
|
|
|
|
|
|
|
$moderegistration =$this->container->getParameter('moderegistration');
|
2019-03-12 14:50:57 +01:00
|
|
|
if($masteridentity!="SQL") $moderegistration="none";
|
2018-12-18 09:44:39 +01:00
|
|
|
|
2019-06-17 17:09:00 +02:00
|
|
|
|
|
|
|
if(in_array("ROLE_MODO",$roles)) {
|
|
|
|
$request = $event->getRequest();
|
|
|
|
$route = $request->attributes->get('_route');
|
|
|
|
if($route!="cadoles_core_config"&&stripos($route,"_config")!==false) {
|
|
|
|
if(stripos($route,"cadoles_core_config_logo")!==false) $route="cadoles_portal_config_page";
|
|
|
|
if(stripos($route,"cadoles_core_config_header")!==false) $route="cadoles_portal_config_page";
|
|
|
|
|
|
|
|
if(stripos($route,"cadoles_portal_config_panelwidget")!==false) $route="cadoles_portal_config_page";
|
|
|
|
if(stripos($route,"cadoles_portal_config_pagewidget")!==false) $route="cadoles_portal_config_page";
|
|
|
|
if(stripos($route,"cadoles_portal_config_bookmark")!==false) $route="cadoles_portal_config_page";
|
|
|
|
if(stripos($route,"cadoles_portal_config_slide")!==false) $route="cadoles_portal_config_page";
|
|
|
|
if(stripos($route,"cadoles_core_config_file")!==false) $route="cadoles_portal_config_page";
|
|
|
|
|
|
|
|
if(stripos($route,"cadoles_portal_config_itemcategory")!==false) $route="cadoles_portal_config_item";
|
|
|
|
if(stripos($route,"cadoles_portal_config_alertcategory")!==false) $route="cadoles_portal_config_alert";
|
|
|
|
if(stripos($route,"cadoles_portal_config_calendarevent")!==false) $route="cadoles_portal_config_calendar";
|
|
|
|
if(stripos($route,"cadoles_cron_config")!==false) $route="cadoles_cron_config";
|
|
|
|
|
|
|
|
$tbroute=explode("_",$route);
|
|
|
|
$route =(isset($tbroute[0])?$tbroute[0]:"");
|
|
|
|
$route.=(isset($tbroute[1])?"_".$tbroute[1]:"");
|
|
|
|
$route.=(isset($tbroute[2])?"_".$tbroute[2]:"");
|
|
|
|
$route.=(isset($tbroute[3])?"_".$tbroute[3]:"");
|
|
|
|
|
|
|
|
$permmodo = $this->em->getRepository("CadolesCoreBundle:PermModo")->findOneBy(['route'=> $route, "visible"=>true]);
|
|
|
|
if(!$permmodo) die('Permission denied');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-18 09:44:39 +01:00
|
|
|
$sidebar=array();
|
|
|
|
$nvs1 = $this->em->getRepository("CadolesCoreBundle:Sidebar")->findBy(array('parent'=> NULL), array('roworder' => 'ASC'));
|
|
|
|
foreach($nvs1 as $nv1) {
|
2019-06-17 17:09:00 +02:00
|
|
|
if($this->haveRole($roles,$nv1->getPermission(),$nv1->getPath())) {
|
2018-12-18 09:44:39 +01:00
|
|
|
$sidebar[$nv1->getRoworder()] = array(
|
|
|
|
"fonticon" => $nv1->getFonticon(),
|
|
|
|
"label" => $nv1->getLabel(),
|
|
|
|
"path" => $nv1->getPath(),
|
|
|
|
);
|
|
|
|
|
2019-06-04 15:05:41 +02:00
|
|
|
if($nv1->getAppactivate()!=""&&!$app[$nv1->getAppactivate()]) {
|
2019-03-21 17:15:06 +01:00
|
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-18 09:44:39 +01:00
|
|
|
if($nv1->getPath()=="cadoles_core_config_niveau01") {
|
|
|
|
$sidebar[$nv1->getRoworder()]["label"]=$labelsniveau01;
|
|
|
|
$sidebar[$nv1->getRoworder()]["fonticon"]=$iconniveau01;
|
|
|
|
}
|
|
|
|
if($nv1->getPath()=="cadoles_core_config_niveau02") {
|
2019-03-12 14:50:57 +01:00
|
|
|
if(!$viewniveau02)
|
|
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
|
|
else {
|
|
|
|
$sidebar[$nv1->getRoworder()]["label"]=$labelsniveau02;
|
|
|
|
$sidebar[$nv1->getRoworder()]["fonticon"]=$iconniveau02;
|
|
|
|
}
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
if($nv1->getPath()=="cadoles_core_config_whitelist") {
|
|
|
|
if($moderegistration=="none")
|
|
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($nv1->getChilds() as $nv2) {
|
2019-06-17 17:09:00 +02:00
|
|
|
|
|
|
|
if($this->haveRole($roles,$nv2->getPermission(),$nv2->getPath())) {
|
2018-12-18 09:44:39 +01:00
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()] = array (
|
|
|
|
"fonticon" => $nv2->getFonticon(),
|
|
|
|
"label" => $nv2->getLabel(),
|
|
|
|
"path" => $nv2->getPath(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if($nv2->getPath()=="cadoles_core_config_niveau01") {
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["label"]=$labelsniveau01;
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["fonticon"]=$iconniveau01;
|
|
|
|
}
|
2019-06-04 15:05:41 +02:00
|
|
|
|
|
|
|
|
2018-12-18 09:44:39 +01:00
|
|
|
if($nv2->getPath()=="cadoles_core_config_niveau02") {
|
2019-03-12 14:50:57 +01:00
|
|
|
if(!$viewniveau02)
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
|
|
else {
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["label"]=$labelsniveau02;
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["fonticon"]=$iconniveau02;
|
|
|
|
}
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
if($nv2->getPath()=="cadoles_core_config_whitelist") {
|
|
|
|
if($moderegistration=="none")
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
|
|
}
|
2019-03-21 17:15:06 +01:00
|
|
|
if($nv2->getPath()=="cadoles_core_config_registration") {
|
|
|
|
if($moderegistration=="none")
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
|
|
}
|
2018-12-18 09:44:39 +01:00
|
|
|
|
2019-06-04 15:05:41 +02:00
|
|
|
if($nv2->getAppactivate()!=""&&!$app[$nv2->getAppactivate()]) {
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]);
|
|
|
|
}
|
|
|
|
|
2018-12-18 09:44:39 +01:00
|
|
|
foreach($nv2->getChilds() as $nv3) {
|
2019-06-17 17:09:00 +02:00
|
|
|
if($this->haveRole($roles,$nv3->getPermission(),$nv3->getPath())) {
|
2018-12-18 09:44:39 +01:00
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()] = array (
|
|
|
|
"fonticon" => $nv3->getFonticon(),
|
|
|
|
"label" => $nv3->getLabel(),
|
|
|
|
"path" => $nv3->getPath(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if($nv3->getPath()=="cadoles_core_config_niveau01") {
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["label"]=$labelsniveau01;
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["fonticon"]=$iconniveau01;
|
|
|
|
}
|
|
|
|
if($nv3->getPath()=="cadoles_core_config_niveau02") {
|
2019-03-12 14:50:57 +01:00
|
|
|
if(!$viewniveau02)
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]);
|
|
|
|
else {
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["label"]=$labelsniveau02;
|
|
|
|
$sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]["fonticon"]=$iconniveau02;
|
|
|
|
}
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
if($nv3->getPath()=="cadoles_core_config_whitelist") {
|
|
|
|
if($moderegistration=="none"||$moderegistration=="byuser")
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($nv3->getPath()=="cadoles_core_config_registration") {
|
|
|
|
if($moderegistration=="none")
|
|
|
|
unset($sidebar[$nv1->getRoworder()]["childs"][$nv2->getRoworder()]["childs"][$nv3->getRoworder()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-17 17:09:00 +02:00
|
|
|
|
|
|
|
if(is_null($sidebar[$nv1->getRoworder()]["path"])&&!isset($sidebar[$nv1->getRoworder()]["childs"]))
|
|
|
|
unset($sidebar[$nv1->getRoworder()]);
|
|
|
|
}
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
$session->set('sidebar', $sidebar);
|
2019-05-07 13:49:42 +02:00
|
|
|
|
2019-06-04 15:05:41 +02:00
|
|
|
if($app["portal_activate"]) {
|
2019-05-07 13:49:42 +02:00
|
|
|
$session->set('cancreatepage',false);
|
|
|
|
$session->set('cancreatecalendar',false);
|
|
|
|
$session->set('cancreateblog',false);
|
2020-04-14 08:56:42 +02:00
|
|
|
$session->set('cancreateproject',false);
|
2019-06-13 13:15:55 +02:00
|
|
|
$session->remove("sublogo");
|
2019-05-07 13:49:42 +02:00
|
|
|
|
|
|
|
if($curentuser!="anon.") {
|
|
|
|
$groups=$curentuser->getGroups();
|
|
|
|
foreach($groups as $usergroup) {
|
|
|
|
$group=$usergroup->getGroup();
|
|
|
|
if($group->getFgcancreatepage()) $session->set('cancreatepage',true);
|
|
|
|
if($group->getFgcancreatecalendar()) $session->set('cancreatecalendar',true);
|
|
|
|
if($group->getFgcancreateblog()) $session->set('cancreateblog',true);
|
2020-04-14 08:56:42 +02:00
|
|
|
if($group->getFgcancreateproject()) $session->set('cancreateproject',true);
|
2019-05-07 13:49:42 +02:00
|
|
|
}
|
2019-06-13 13:15:55 +02:00
|
|
|
|
|
|
|
$niveau01=$curentuser->getNiveau01();
|
|
|
|
if($niveau01->getShowsubappname())
|
|
|
|
$session->set("subappname", $niveau01->getLabel());
|
|
|
|
|
|
|
|
if(!is_null($niveau01->getLogo()))
|
|
|
|
$session->set("sublogo", $niveau01->getLogo());
|
|
|
|
|
2019-05-07 13:49:42 +02:00
|
|
|
}
|
2020-06-09 09:53:25 +02:00
|
|
|
|
2019-05-07 13:49:42 +02:00
|
|
|
}
|
2020-06-09 09:53:25 +02:00
|
|
|
|
|
|
|
if($curentuser!="anon.") {
|
2020-06-09 17:28:47 +02:00
|
|
|
$visitedate=clone $curentuser->getVisitedate();
|
2020-06-09 11:24:07 +02:00
|
|
|
if($visitedate) $visitedate->add(new \DateInterval("PT1H"));
|
2020-06-09 09:53:25 +02:00
|
|
|
$now=new \DateTime();
|
|
|
|
if($visitedate<$now) {
|
|
|
|
$curentuser->setVisitedate($now);
|
|
|
|
$curentuser->setVisitecpt($curentuser->getVisitecpt()+1);
|
|
|
|
$this->em->persist($curentuser);
|
|
|
|
$this->em->flush();
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 09:44:39 +01:00
|
|
|
}
|
|
|
|
}
|