/**
  * getModEnabled
  *
  * Retourne la liste des modules attachÈs ‡ un noeud, et en option, ceux dÈpendant du type d'utilisateur.
  *
  * @author FrÈdÈric Mossmann <*****@*****.**>
  * @param string  $node_type Type de noeud.
  * @param integer $node_id   Identifiant du noeud.
  * @param string  $user_type Type d'utilisateur (facultatif).
  * @param integer $user_id   Identifiant du noeud (facultatif).
  */
 public function getModEnabled($node_type, $node_id, $user_type = '', $user_id = 0, $full = 0, $notification = 0)
 {
     // echo "getModEnabled( $node_type, $node_id, $user_type, $user_id)";
     $carnetDeLiaison = CopixConfig::exists('kernel|carnetDeLiaison') && CopixConfig::get('kernel|carnetDeLiaison');
     $dao = _dao("kernel|kernel_mod_enabled");
     $modules = array();
     // Parent d'eleve...
     if (0 == strncmp($node_type, "USER_ELE", 8) && 0 == strncmp($user_type, "USER_RES", 8)) {
         $parents = Kernel::getNodeParents($node_type, $node_id);
         $parent = Kernel::filterNodeList($parents, 'BU_CLASSE');
         if (count($parent)) {
             if ($parent[0]['droit'] >= 30) {
                 $parent_modules = Kernel::getModEnabled($parent[0]['type'], $parent[0]['id'], $node_type, $node_id);
                 /*
                 echo '<li>$parent[0][] = '.$parent[0]['type']."/".$parent[0]['id']."</li>";
                 echo '<li>$node_* = '.$node_type."/".$node_id."</li>";
                 */
                 $perso = new stdClass();
                 foreach ($parent_modules as $parent_module) {
                     /*
                     $perso->node_type   = $parent[0]['type'];
                     $perso->node_id     = $parent[0]['id'];
                     */
                     $perso->node_type = $node_type;
                     $perso->node_id = $node_id;
                     $perso->module_type = $parent_module->module_type;
                     $perso->module_id = $parent_module->module_id;
                     $perso->module_nom = Kernel::Code2Name($parent_module->module_type);
                     $modules[] = clone $perso;
                 }
                 /*
                 $perso->node_type   = $parent[0]['type'];
                 $perso->node_id     = $parent[0]['id'];
                 */
                 $perso->node_type = $node_type;
                 $perso->node_id = $node_id;
                 $perso->module_type = 'MOD_CARNET';
                 $perso->module_id = 'ELEVE_' . $node_id;
                 $perso->module_nom = Kernel::Code2Name('MOD_CARNET');
                 if ($carnetDeLiaison) {
                     $modules[] = clone $perso;
                 }
             }
         }
         // _dump($modules);
         if ($notification) {
             Kernel::getModlistNotifications($modules);
         }
         reset($modules);
         return $modules;
     }
     $list = $dao->getByNode($node_type, $node_id);
     foreach ($list as $v) {
         if (!$full) {
             if ($v->module_type == 'MOD_MAGICMAIL') {
                 continue;
             }
         }
         $v->module_nom = Kernel::Code2Name($v->module_type);
         $modules[] = clone $v;
     }
     // _dump($modules);
     //print_r($modules);
     if ($user_type == "USER_ENS" && $node_type == "BU_CLASSE" && Kernel::getLevel($node_type, $node_id) >= 60) {
         $carnetcorresp = new CopixPPO();
         $carnetcorresp->node_type = $node_type;
         $carnetcorresp->node_id = $node_id;
         $carnetcorresp->module_type = 'MOD_CARNET';
         $carnetcorresp->module_id = 'CLASSE_' . $node_id;
         $carnetcorresp->module_nom = Kernel::Code2Name('MOD_CARNET');
         if ($carnetDeLiaison) {
             $modules[] = clone $carnetcorresp;
         }
     }
     //for KNE
     if (in_array($user_type, array('USER_ELE', 'USER_ENS', 'USER_DIR', 'USER_DID')) && $node_type == 'BU_CLASSE' && CopixClassesFactory::create('kne|kneService')->active) {
         $modKne = new stdClass();
         $modKne->node_type = $node_type;
         $modKne->node_id = $node_id;
         $modKne->module_type = 'MOD_KNE';
         $modKne->module_id = $node_id;
         $modKne->module_nom = kernel::Code2Name('MOD_KNE');
         $modules[] = $modKne;
     }
     //for Coreprim
     if (in_array($user_type, array('USER_ELE', 'USER_ENS', 'USER_DIR', 'USER_DID')) && $node_type == 'BU_CLASSE' && CopixConfig::exists('default|rssEtagereEnabled') && CopixConfig::get('default|rssEtagereEnabled')) {
         $modRssEtagere = new stdClass();
         $modRssEtagere->node_type = $node_type;
         $modRssEtagere->node_id = $node_id;
         $modRssEtagere->module_type = 'MOD_RSSETAGERE';
         $modRssEtagere->module_id = $node_type . "-" . $node_id;
         $modRssEtagere->module_nom = kernel::Code2Name('MOD_RSSETAGERE');
         $modules[] = $modRssEtagere;
     }
     if (CopixConfig::exists('|conf_ModTeleprocedures') && CopixConfig::get('|conf_ModTeleprocedures') == 0) {
         // Pas de module de tÈlÈprocÈdures...
     } else {
         if ($user_type == "USER_ENS" && $node_type == "BU_ECOLE" && Kernel::getLevel($node_type, $node_id) >= 60) {
             $teleprocedures = new CopixPPO();
             $teleprocedures->node_type = $node_type;
             $teleprocedures->node_id = $node_id;
             $teleprocedures->module_type = 'MOD_TELEPROCEDURES';
             $teleprocedures->module_id = 'ECOLE_' . $node_id;
             $teleprocedures->module_nom = Kernel::Code2Name('MOD_TELEPROCEDURES');
             $modules[] = clone $teleprocedures;
         } elseif (CopixConfig::exists('teleprocedures|USER_ADM_as_USER_ENS') && CopixConfig::get('teleprocedures|USER_ADM_as_USER_ENS') && $user_type == "USER_ADM" && $node_type == "BU_ECOLE" && Kernel::getLevel($node_type, $node_id) >= 30) {
             $teleprocedures = new CopixPPO();
             $teleprocedures->node_type = $node_type;
             $teleprocedures->node_id = $node_id;
             $teleprocedures->module_type = 'MOD_TELEPROCEDURES';
             $teleprocedures->module_id = 'ECOLE_' . $node_id;
             $teleprocedures->module_nom = Kernel::Code2Name('MOD_TELEPROCEDURES');
             $modules[] = clone $teleprocedures;
         }
     }
     // Cas particuliers : modules personnels sans numÈros
     if (0 == strncmp($node_type, "USER_", 5)) {
         $perso_list = array('MOD_ANNUAIRE', 'MOD_MINIMAIL', 'MOD_GROUPE', 'MOD_RESSOURCE');
         foreach ($perso_list as $perso_module) {
             $perso = new CopixPPO();
             $perso->node_type = $node_type;
             $perso->node_id = $node_id;
             $perso->module_id = NULL;
             $perso->module_type = $perso_module;
             $perso->module_nom = Kernel::Code2Name($perso_module);
             $modules[] = clone $perso;
             unset($perso);
         }
     }
     // Cas particulier : module d'administration
     if ($node_type == "ROOT" && Kernel::getLevel($node_type, $node_id) >= 60) {
         $sysutils = new CopixPPO();
         $sysutils->node_type = $node_type;
         $sysutils->node_id = $node_id;
         $sysutils->module_id = NULL;
         $sysutils->module_type = 'MOD_SYSUTILS';
         $sysutils->module_nom = Kernel::Code2Name('MOD_SYSUTILS');
         $modules[] = clone $sysutils;
         $charte = new CopixPPO();
         $charte->node_type = $node_type;
         $charte->node_id = $node_id;
         $charte->module_id = NULL;
         $charte->module_type = 'MOD_CHARTE';
         $charte->module_nom = Kernel::Code2Name('MOD_CHARTE');
         $modules[] = clone $charte;
     }
     // Cas ENS+VIL : SSO vers Gael si tout est configurÈ.
     $SsoGaelService =& CopixClassesFactory::Create('ssogael|ssogael');
     if (($user_type == "USER_ENS" && $node_type == "BU_ECOLE" || $user_type == "USER_VIL" && $node_type == "BU_VILLE") && method_exists($SsoGaelService, "canSsoGael") && $SsoGaelService->canSsoGael() && Kernel::getLevel($node_type, $node_id) >= 60) {
         $comptes = new stdClass();
         $comptes->node_type = $node_type;
         $comptes->node_id = $node_id;
         $comptes->module_type = 'MOD_SSOGAEL';
         $comptes->module_id = $node_type . '-' . $node_id;
         $comptes->module_nom = Kernel::Code2Name('MOD_SSO_GAEL');
         $comptes->module_popup = true;
         // Mode Popup !!!
         $modules[] = clone $comptes;
     }
     // Cas particulier : gestion des groupes de ville (AC/TICE)
     if ($node_type == "ROOT" && Kernel::getLevel($node_type, $node_id) >= 60) {
         $mod_grvilles = new stdClass();
         $mod_grvilles->node_type = $node_type;
         $mod_grvilles->node_id = $node_id;
         $mod_grvilles->module_type = 'MOD_REGROUPEMENTS';
         $mod_grvilles->module_id = $node_type . '-' . $node_id;
         $mod_grvilles->module_nom = Kernel::Code2Name('MOD_REGROUPEMENTS');
         $modules[] = clone $mod_grvilles;
     }
     // Cas particulier : Gestion autonome
     // if(    $user_type == "USER_EXT"
     //    && $node_type == "ROOT"
     //    && Kernel::getLevel( $node_type, $node_id ) >= 60 ) {
     if (CopixConfig::exists('kernel|gestionAutonomeEnabled') && CopixConfig::get('kernel|gestionAutonomeEnabled')) {
         if (($node_type == "ROOT" || $user_type == "USER_ENS" && $node_type == "BU_ECOLE" || $user_type == "USER_ENS" && $node_type == "BU_CLASSE" || $user_type == "USER_VIL" && $node_type == "BU_VILLE") && Kernel::getLevel($node_type, $node_id) >= 60) {
             $mod_grvilles = new CopixPPO();
             $mod_grvilles->node_type = $node_type;
             $mod_grvilles->node_id = $node_id;
             $mod_grvilles->module_type = 'MOD_GESTIONAUTONOME';
             $mod_grvilles->module_id = $node_type . '-' . $node_id;
             $mod_grvilles->module_nom = Kernel::Code2Name('MOD_GESTIONAUTONOME');
             $modules[] = clone $mod_grvilles;
         }
     } elseif (($node_type == "ROOT" || $user_type == "USER_ENS" && $node_type == "BU_ECOLE" || $user_type == "USER_ENS" && $node_type == "BU_CLASSE" || $user_type == "USER_VIL" && $node_type == "BU_VILLE") && Kernel::getLevel($node_type, $node_id) >= 60) {
         $comptes->node_type = $node_type;
         $comptes->node_id = $node_id;
         $comptes->module_type = 'MOD_COMPTES';
         $comptes->module_id = $node_type . '-' . $node_id;
         $comptes->module_nom = Kernel::Code2Name('MOD_COMPTES');
         $modules[] = clone $comptes;
     }
     if ($user_type == "USER_ENS" && ($node_type == "BU_ECOLE" && Kernel::getLevel($node_type, $node_id) >= 60 || $node_type == "BU_CLASSE") && CopixConfig::exists('default|conf_Ceriseprim_actif') && CopixConfig::get('default|conf_Ceriseprim_actif')) {
         $perso->node_type = $node_type;
         $perso->node_id = $node_id;
         $perso->module_type = 'MOD_CERISEPRIM';
         $perso->module_id = $node_type . "-" . $node_id;
         $perso->module_nom = Kernel::Code2Name('MOD_CERISEPRIM');
         $modules[] = clone $perso;
     }
     // _dump($modules);
     if ($notification) {
         Kernel::getModlistNotifications($modules);
     }
     reset($modules);
     return $modules;
 }