/**
  * Renvoie l'entree de l'annuaire pour l'usager courant. Pour les parents, prends le home d'un des enfants. S'il n'y a pas d'enfant ou que le compte n'est rattache a rien, on l'envoie dans la 1e ville.
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2006/12/20
  * @return array Tableau avec [type] et [id] du noeud (BU_CLASSE, BU_ECOLE, BU_VILLE, BU_GVILLE)
  */
 public function getAnnuaireHome()
 {
     // Recuperation de ses blocs, comme dans le dashboard
     $nodes_all = Kernel::getNodeParents($this->user->type, $this->user->idEn);
     $nodes_all = Kernel::sortNodeList($nodes_all);
     //_dump($nodes_all);
     $home = null;
     foreach ($nodes_all as $node) {
         if ($node['type'] == 'BU_CLASSE' || $node['type'] == 'BU_ECOLE' || $node['type'] == 'BU_VILLE' || $node['type'] == 'BU_GVILLE') {
             $home = array('type' => $node['type'], 'id' => $node['id']);
             break;
         }
     }
     //_dump($home);
     if (!$home && Kernel::isParent()) {
         // Cas du parent d'�l�ve
         $enfants = Kernel::getNodeParents(_currentUser()->getExtra('type'), _currentUser()->getExtra('id'));
         while (list($k, $v) = each($enfants)) {
             if ($v["type"] != "USER_ELE") {
                 continue;
             }
             // Pour chaque enfant...
             //print_r($v);
             if (is_array($v['link']->classe) && ($id = array_shift(array_keys($v['link']->classe)))) {
                 $home = array('type' => 'BU_CLASSE', 'id' => $id);
             } elseif (is_array($v['link']->ecole) && ($id = array_shift(array_keys($v['link']->ecole)))) {
                 $home = array('type' => 'BU_ECOLE', 'id' => $id);
             } elseif (is_array($v['link']->ville) && ($id = array_shift(array_keys($v['link']->ville)))) {
                 $home = array('type' => 'BU_VILLE', 'id' => $id);
             }
             if ($home) {
                 break;
             }
         }
     }
     if (!$home || Kernel::isAdmin()) {
         // Si rattache a rien, on l'envoie dans la 1e ville
         $sql = "SELECT MIN(id_vi) AS ville FROM kernel_bu_ville LIMIT 1";
         $v = _doQuery($sql);
         $home = array('type' => 'BU_VILLE', 'id' => $v[0]->ville);
     }
     //print_r($home);
     return $home;
 }
 /**
  * getNode
  *
  * Affiche les informations d'un noeud et les utilisateurs qui y sont attachés.
  * @author	Frédéric Mossmann
  * @since	09.02.2006
  *
  */
 public function getNode()
 {
     if (CopixConfig::exists('kernel|gestionAutonomeEnabled') && CopixConfig::get('kernel|gestionAutonomeEnabled')) {
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('gestionautonome|default|showTree', array('type' => 'ROOT')));
     }
     $tpl = new CopixTpl();
     $tplGetNode = new CopixTpl();
     $pType = _request("type", 'ROOT');
     $pId = _request("id");
     $tpl->assign('TITLE_PAGE', CopixI18N::get('comptes.moduleDescription') . " &raquo; " . CopixI18N::get('comptes.title.getnode'));
     $petitpoucet = array();
     $droit = 0 + Kernel::getLevel($pType, $pId);
     switch ($pType) {
         case 'ROOT':
             $pId = 0;
             // ROOT
             $petitpoucet[] = array('txt' => 'Root');
             $childs = Kernel::getNodeChilds($pType, $pId);
             $childs = Kernel::filterNodeList($childs, 'USER_*');
             break;
         case 'BU_GRVILLE':
             $infos = Kernel::getNodeInfo($pType, $pId, false);
             // ROOT
             $petitpoucet[] = array('txt' => 'Root', 'url' => CopixUrl::get('comptes||getNode', array('type' => 'ROOT')));
             // BU_GRVILLE
             $petitpoucet[] = array('txt' => $infos['nom']);
             // Liste des "BU_VILLE"
             $childs = Kernel::getNodeChilds($pType, $pId);
             $childs = Kernel::filterNodeList($childs, 'USER_*');
             $droit = max($droit, Kernel::getLevel('ROOT', 0));
             break;
         case 'BU_VILLE':
             $infos = Kernel::getNodeInfo($pType, $pId, false);
             // Recherche des parents
             $parents = Kernel::getNodeParents($pType, $pId);
             $parent_grville = Kernel::filterNodeList($parents, 'BU_GRVILLE');
             // ROOT
             $petitpoucet[] = array('txt' => 'Root', 'url' => CopixUrl::get('comptes||getNode', array('type' => 'ROOT')));
             // BU_GRVILLE
             $petitpoucet[] = array('txt' => $parent_grville[0]['nom'], 'url' => CopixUrl::get('comptes||getNode', array('type' => $parent_grville[0]['type'], 'id' => $parent_grville[0]['id'])));
             // BU_VILLE
             $petitpoucet[] = array('txt' => $infos['nom']);
             // Liste des "BU_VILLE"
             $childs = Kernel::getNodeChilds($pType, $pId);
             $childs = Kernel::filterNodeList($childs, 'USER_*');
             $droit = max($droit, Kernel::getLevel('BU_GRVILLE', $parent_grville[0]["id"]));
             $droit = max($droit, Kernel::getLevel('ROOT', 0));
             break;
         case 'BU_ECOLE':
             $infos = Kernel::getNodeInfo($pType, $pId, false);
             // Recherche des parents
             $parents = Kernel::getNodeParents($pType, $pId);
             $parent_ville = Kernel::filterNodeList($parents, 'BU_VILLE');
             $parents = Kernel::getNodeParents($parent_ville[0]["type"], $parent_ville[0]["id"]);
             $parent_grville = Kernel::filterNodeList($parents, 'BU_GRVILLE');
             // ROOT
             $petitpoucet[] = array('txt' => 'Root', 'url' => CopixUrl::get('comptes||getNode', array('type' => 'ROOT')));
             // BU_GRVILLE
             $petitpoucet[] = array('txt' => $parent_grville[0]['nom'], 'url' => CopixUrl::get('comptes||getNode', array('type' => $parent_grville[0]['type'], 'id' => $parent_grville[0]['id'])));
             // BU_VILLE
             $petitpoucet[] = array('txt' => $parent_ville[0]['nom'], 'url' => CopixUrl::get('comptes||getNode', array('type' => $parent_ville[0]['type'], 'id' => $parent_ville[0]['id'])));
             // BU_ECOLE
             $petitpoucet[] = array('txt' => $infos['nom']);
             // Liste des "BU_VILLE"
             $childs = Kernel::getNodeChilds($pType, $pId);
             $childs = Kernel::filterNodeList($childs, 'USER_*');
             $droit = max($droit, Kernel::getLevel('BU_VILLE', $parent_ville[0]["id"]));
             $droit = max($droit, Kernel::getLevel('BU_GRVILLE', $parent_grville[0]["id"]));
             $droit = max($droit, Kernel::getLevel('ROOT', 0));
             break;
         case 'BU_CLASSE':
             $infos = Kernel::getNodeInfo($pType, $pId, false);
             // Recherche des parents
             $parents = Kernel::getNodeParents($pType, $pId);
             $parent_ecole = Kernel::filterNodeList($parents, 'BU_ECOLE');
             $parents = Kernel::getNodeParents($parent_ecole[0]["type"], $parent_ecole[0]["id"]);
             $parent_ville = Kernel::filterNodeList($parents, 'BU_VILLE');
             $parents = Kernel::getNodeParents($parent_ville[0]["type"], $parent_ville[0]["id"]);
             $parent_grville = Kernel::filterNodeList($parents, 'BU_GRVILLE');
             // ROOT
             $petitpoucet[] = array('txt' => 'Root', 'url' => CopixUrl::get('comptes||getNode', array('type' => 'ROOT')));
             // BU_GRVILLE
             $petitpoucet[] = array('txt' => $parent_grville[0]['nom'], 'url' => CopixUrl::get('comptes||getNode', array('type' => $parent_grville[0]['type'], 'id' => $parent_grville[0]['id'])));
             // BU_VILLE
             $petitpoucet[] = array('txt' => $parent_ville[0]['nom'], 'url' => CopixUrl::get('comptes||getNode', array('type' => $parent_ville[0]['type'], 'id' => $parent_ville[0]['id'])));
             // BU_ECOLE
             $petitpoucet[] = array('txt' => $parent_ecole[0]['nom'], 'url' => CopixUrl::get('comptes||getNode', array('type' => $parent_ecole[0]['type'], 'id' => $parent_ecole[0]['id'])));
             // BU_CLASSE
             $petitpoucet[] = array('txt' => $infos['nom']);
             // Liste des "BU_VILLE"
             $childs = Kernel::getNodeChilds($pType, $pId);
             //print_r($childs);
             $eleves = Kernel::filterNodeList($childs, 'USER_ELE');
             foreach ($eleves as $eleve) {
                 $parents = Kernel::getNodeChilds($eleve['type'], $eleve['id']);
                 $parents = Kernel::filterNodeList($parents, 'USER_RES');
                 foreach ($parents as $parent) {
                     $childs[] = $parent;
                 }
             }
             $childs = Kernel::filterNodeList($childs, 'USER_*');
             $droit = max($droit, Kernel::getLevel('BU_ECOLE', $parent_ecole[0]["id"]));
             $droit = max($droit, Kernel::getLevel('ROOT', 0));
             break;
         default:
             return CopixActionGroup::process('genericTools|Messages::getError', array('message' => CopixI18N::get('comptes.error.badnodetype'), 'back' => CopixUrl::get('||')));
             break;
     }
     // Tri par type de noeud
     // $childs = Kernel::sortNodeList( $childs, 'type', array('USER_VIL','USER_ENS','USER_ADM','USER_ELE','USER_RES','USER_EXT') );
     $childs = Kernel::sortNodeList($childs, 'comptes');
     $childs = Kernel::uniqNodeList($childs);
     // Ajoute le type d'utilisateur en toute lettres.
     foreach ($childs as $child_key => $child_val) {
         $childs[$child_key]['type_nom'] = Kernel::Code2Name($child_val['type']);
     }
     if (isset($petitpoucet)) {
         $tplGetNode->assign('PETITPOUCET', Kernel::PetitPoucet($petitpoucet, " &raquo; "));
     }
     $tplGetNode->assign('NAVIGATION', CopixZone::process('comptes|navigation'));
     if ($droit >= 70) {
         $tplGetNode->assign('MAIN', CopixZone::process('comptes|userlist', array('childs' => $childs, 'type' => $pType, 'id' => $pId)));
     } else {
         $tplGetNode->assign('MAIN', CopixI18N::get('comptes.error.badrights'));
     }
     $result = $tplGetNode->fetch("getnode.tpl");
     $menu = array();
     $session = _sessionGet('modules|comptes|doLoginCreate|success');
     if ($session && is_array($session) && sizeof($session)) {
         $menu[] = array('txt' => CopixI18N::get('comptes.strings.showloginresult', sizeof($session)), 'url' => CopixUrl::get('comptes||getLoginResult'), 'size' => 160);
     }
     /*if( Kernel::getLevel( 'ROOT', 0 ) >= PROFILE_CCV_ADMIN ) {
           $menu[] = array( 'txt' => CopixI18N::get('comptes.strings.getext'), 'url' => CopixUrl::get ('comptes||getUserExt'), 'size'=>160 );
           $menu[] = array( 'txt' => CopixI18N::get('comptes.strings.getanim'), 'url' => CopixUrl::get ('comptes|animateurs|list'), 'size'=>120 );
       }
       if( count($menu) ) $tpl->assign ('MENU', $menu );*/
     $tpl->assign('MENU', $this->menu);
     $tpl->assign('MAIN', $result);
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }
 public function processDefault()
 {
     $tpl = new CopixTpl();
     $tplModule = new CopixTpl();
     if (!$this->user->connected) {
         return new CopixActionReturn(COPIX_AR_REDIRECT, CopixUrl::get('welcome|default|'));
     }
     $tpl->assign('TITLE_PAGE', CopixI18N::get('kernel.title.accueilsimple'));
     $nodes_all = Kernel::getNodeParents($this->user->type, $this->user->idEn);
     $nodes_all = Kernel::sortNodeList($nodes_all);
     // _dump($nodes_all);
     $nodes = array();
     foreach ($nodes_all as $node) {
         if ($node['type'] == 'CLUB' && CopixConfig::exists('kernel|groupeAssistance') && ($groupeAssistance = CopixConfig::get('kernel|groupeAssistance')) && $node['id'] == $groupeAssistance) {
             continue;
         }
         if ($node['type'] == 'CLUB' && $node['droit'] < 20) {
             continue;
         }
         if (!isset($nodes[$node['type']])) {
             $nodes[$node['type']] = array();
         }
         //module not initialized : loaded into inconito
         if (!isset($nodes[$node['type']][$node['id']])) {
             $nodes[$node['type']][$node['id']] = $node;
             Kernel::createMissingModules($node['type'], $node['id']);
             $nodes[$node['type']][$node['id']]['modules'] = Kernel::getModEnabled($node['type'], $node['id'], $this->user->type, $this->user->idEn, 0, count($nodes_all) > $this->conf_notification_maxnodes ? 0 : 1);
             // Cas des groupes : on ajoute les membres et admin, selon les droits
             if ($node['type'] == 'CLUB') {
                 $addModule = new CopixPPO();
                 $addModule->node_type = $node['type'];
                 $addModule->node_id = $node['id'];
                 $addModule->module_type = 'MOD_ADMIN';
                 $addModule->module_id = 0;
                 $addModule->module_nom = CopixI18N::get('groupe|groupe.group.admin');
                 $nodes[$node['type']][$node['id']]['modules'][] = $addModule;
             }
             /*
              * ===== CONTENT GENERATION =====
              *
              */
             //cas parent élève
             if ($node['type'] == 'USER_ELE') {
                 $contentNode = Kernel::getNodeParents($node['type'], $node['id']);
                 $contentNode = Kernel::filterNodeList($contentNode, 'BU_CLASSE');
                 if (empty($contentNode)) {
                     continue;
                 }
                 $contentNode = $contentNode[0];
             } else {
                 $contentNode = $node;
             }
             //get content from db :
             $content = $this->db->query('SELECT * FROM module_admindash WHERE id_zone = ' . $contentNode['id'] . ' AND type_zone = "' . $contentNode['type'] . '"')->toArray1();
             // Get vocabulary catalog to use
             $nodeVocabularyCatalogDAO = _ioDAO('kernel|kernel_i18n_node_vocabularycatalog');
             $vocabularyCatalog = $nodeVocabularyCatalogDAO->getCatalogForNode($contentNode['type'], $contentNode['id']);
             //if no content : get default content
             if (empty($content['content'])) {
                 switch ($contentNode['type']) {
                     case 'BU_CLASSE':
                     case 'USER_ELE':
                         $content['content'] = CopixZone::process('kernel|dashboardClasse', array('idZone' => $contentNode['id'], 'catalog' => $vocabularyCatalog->id_vc));
                         break;
                     case 'BU_ECOLE':
                         $content['content'] = CopixZone::process('kernel|dashboardEcole', array('idZone' => $contentNode['id'], 'catalog' => $vocabularyCatalog->id_vc));
                         break;
                     case 'BU_VILLE':
                         $content['content'] = CopixZone::process('kernel|dashboardVille', array('idZone' => $contentNode['id'], 'catalog' => $vocabularyCatalog->id_vc));
                         break;
                     case 'CLUB':
                         $content['content'] = CopixZone::process('kernel|dashboardGrTravail', array('idZone' => $contentNode['id'], 'catalog' => $vocabularyCatalog->id_vc));
                         break;
                     case 'ROOT':
                         if ($contentNode['droit'] >= 60) {
                             $contentTpl = new CopixTpl();
                             $content['content'] = $contentTpl->fetch('zone.dashboard.root.tpl');
                         } else {
                             $contentTpl = new CopixTpl();
                             $content['content'] = $contentTpl->fetch('zone.dashboard.userext.tpl');
                         }
                         break;
                     default:
                         $content['content'] = '';
                         break;
                 }
             }
             //twitter integration
             $twitterSrc = '';
             if (!empty($content['social_stream'])) {
                 enic::to_load('social');
                 $twitter = new enicSocialTwitter();
                 $twitterSrc = $content['social_stream'];
             }
             //is admin :
             $is_admin = $contentNode['droit'] >= 60;
             //build html content
             $content_tpl = new CopixTpl();
             $content_tpl->assign('content', $content['content']);
             if (!empty($content['picture'])) {
                 $content_tpl->assign('picture', $content['picture']);
                 $content_tpl->assign('picturePath', $this->picturesPath);
             }
             $content_tpl->assign('twitter', $twitterSrc);
             $content_tpl->assign('is_admin', $is_admin);
             $content_tpl->assign('id', $contentNode['id']);
             $content_tpl->assign('type', $contentNode['type']);
             $content_tpl->assign('catalog', $vocabularyCatalog->id_vc);
             if ($contentNode['type'] == "BU_ECOLE") {
                 $content_tpl->assign('idZone', $contentNode['id']);
             }
             $content = $content_tpl->fetch('dashboard.nodes.tpl');
             //add css
             $this->addCss('styles/dashboard_zone.css');
             //free memory
             unset($content_tpl);
             /*
              *  ===== END CONTENT GENERATION =====
              */
             $nodes[$node['type']][$node['id']]['content'] = $content;
         } elseif ($nodes[$node['type']][$node['id']]['droit'] < $node['droit']) {
             $nodes[$node['type']][$node['id']] = $node;
         }
     }
     if (CopixConfig::exists('|use_class_validity') && CopixConfig::get('|use_class_validity')) {
         $tplModule->assign("use_class_validity", 1);
         if (isset($nodes['BU_CLASSE'])) {
             foreach ($nodes['BU_CLASSE'] as $classe_id => $classe_data) {
                 $validity_timestamp = Kernel::getValidityDateForClass($classe_data['id']);
                 if ($validity_timestamp) {
                     $nodes['BU_CLASSE'][$classe_id]['validity_timestamp'] = $validity_timestamp;
                     $nodes['BU_CLASSE'][$classe_id]['validity_date'] = date('d/m/Y', $validity_timestamp);
                     // Si l'école existe : mémoriser max validity
                     if (isset($nodes['BU_ECOLE'][$nodes['BU_CLASSE'][$classe_id]['ALL']->cla_ecole])) {
                         if (!isset($nodes['BU_ECOLE'][$nodes['BU_CLASSE'][$classe_id]['ALL']->cla_ecole]['validity_timestamp']) || $nodes['BU_ECOLE'][$nodes['BU_CLASSE'][$classe_id]['ALL']->cla_ecole]['validity_timestamp'] < $validity_timestamp) {
                             $nodes['BU_ECOLE'][$nodes['BU_CLASSE'][$classe_id]['ALL']->cla_ecole]['validity_timestamp'] = $validity_timestamp;
                             $nodes['BU_ECOLE'][$nodes['BU_CLASSE'][$classe_id]['ALL']->cla_ecole]['validity_date'] = date('d/m/Y', $validity_timestamp);
                         }
                     }
                 }
             }
         }
         $count_validity_ok = 0;
         $count_validity_bad = 0;
         foreach ($nodes as $node_type => $node_type_list) {
             foreach ($node_type_list as $node_id => $node) {
                 if (isset($nodes[$node_type][$node_id]['validity_timestamp'])) {
                     if ($nodes[$node_type][$node_id]['validity_timestamp'] < time()) {
                         unset($nodes[$node_type][$node_id]);
                         $count_validity_bad++;
                     } else {
                         $count_validity_ok++;
                     }
                 }
             }
         }
     } else {
         $tplModule->assign("use_class_validity", 0);
     }
     /* DRAFT WORKING */
     // _dump($nodes);
     /* $rClasse = Kernel::getNodeInfo ('BU_CLASSE', $nodes['BU_CLASSE'][1]['id'], false);
        CopixZone::process ('annuaire|infosclasse', array('rClasse'=>$rClasse)); */
     //echo $this->matrix->display();
     // _dump($nodes);
     $tplModule->assign("nodes", $nodes);
     if (count($nodes) == 0) {
         $result = $tplModule->fetch("dashboard-empty.tpl");
     } else {
         $result = $tplModule->fetch("dashboard.tpl");
     }
     $tpl->assign('MAIN', $result);
     return new CopixActionReturn(COPIX_AR_DISPLAY, $tpl);
 }