public function processDefault()
 {
     ini_set('max_execution_time', 0);
     $classeurservice =& CopixClassesFactory::Create('classeur|classeurservice');
     /* DEBUG
        if (!Admin::canAdmin())
            return CopixActionGroup::process ('genericTools|Messages::getError', array ('message'=>CopixI18N::get ('kernel|kernel.error.noRights'), 'back'=>CopixUrl::get ()));
        */
     $tpl = new CopixTpl();
     // $tpl->assign ('TITLE_PAGE', CopixI18N::get ('sysutils|admin.menu.cache'));
     // $tpl->assign ('MENU', Admin::getMenu('cache'));
     ///////////////
     //// ALBUM ////
     ///////////////
     $sql = "\n            SELECT\n                A.id AS album_id, A.nom AS album_nom, A.prefs AS album_prefs, A.date AS album_date, A.cle AS album_cle, A.public AS album_public\n            FROM module_album_albums A\n            ORDER BY A.id\n        ";
     $album_list = _doQuery($sql);
     $album_tree = array();
     foreach ($album_list as $album_item) {
         if (!isset($album_tree[$album_item->album_id])) {
             $album_tree[$album_item->album_id] = new CopixPPO();
             $album_tree[$album_item->album_id]->info = $album_item;
             $parent = Kernel::getModParent("MOD_ALBUM", $album_item->album_id);
             if (!$parent) {
                 unset($album_tree[$album_item->album_id]);
                 continue;
             }
             $album_tree[$album_item->album_id]->parent = $parent[0];
             $album_tree[$album_item->album_id]->dossier = array();
             $album_tree[$album_item->album_id]->photo = array();
         }
         $root = $this->albumScanFolder($album_item->album_id, 0);
         $album_tree[$album_item->album_id]->dossier = $root->dossier;
         $album_tree[$album_item->album_id]->photo = $root->photo;
     }
     // module_malle_malles : id 	titre 	date_creation 	cle
     // module_malle_folders : id malle parent nom nb_folders nb_files taille date_creation
     // module_malle_files : id 	malle 	folder 	nom 	fichier 	taille 	type 	cle 	date_upload
     ///////////////
     //// MALLE ////
     ///////////////
     $sql = "\n            SELECT\n                id, titre, date_creation, cle\n            FROM module_malle_malles\n            ORDER BY id\n        ";
     $malle_list = _doQuery($sql);
     $malle_tree = array();
     foreach ($malle_list as $malle_item) {
         if (!isset($malle_tree[$malle_item->id])) {
             $malle_tree[$malle_item->id] = new CopixPPO();
             $malle_tree[$malle_item->id]->info = $malle_item;
             $parent = Kernel::getModParent("MOD_MALLE", $malle_item->id);
             if (!$parent) {
                 unset($malle_tree[$malle_item->id]);
                 continue;
             }
             $malle_tree[$malle_item->id]->parent = $parent[0];
             $user_parents = Kernel::getNodeParents($parent[0]->node_type, $parent[0]->node_id);
             $malle_tree[$malle_item->id]->user_parents = $user_parents;
             $malle_tree[$malle_item->id]->dossier = array();
             $malle_tree[$malle_item->id]->docs = array();
         }
         $root = $this->malleScanFolder($malle_item->id, 0);
         $malle_tree[$malle_item->id]->dossier = $root->dossier;
         $malle_tree[$malle_item->id]->docs = $root->docs;
     }
     /////////////////////////////////////
     /////////////////////////////////////
     // kernel_mod_enabled : node_type 	node_id 	module_type 	module_id
     // module_classeur : id 	titre 	cle 	date_creation 	date_publication 	public
     // module_classeur_dossier : id 	module_classeur_id 	parent_id 	nom 	nb_dossiers 	nb_fichiers 	taille 	cle 	date_creation 	user_type 	user_id 	date_publication 	public
     // module_classeur_fichier : id 	module_classeur_id 	module_classeur_dossier_id 	titre 	commentaire 	fichier 	taille 	type 	cle 	date_upload 	user_type 	user_id
     // IMPORT ALBUMS
     if (1) {
         foreach ($album_tree as $album_item) {
             if (!isset($album_item->parent->node_type)) {
                 continue;
             }
             //// RECHERCHE D'UN CLASSEUR EXISTANT
             $sql = "\n                SELECT module_id\n                FROM kernel_mod_enabled\n                WHERE node_type=:node_type AND node_id=:node_id AND module_type=:module_type\n            ";
             $param = array('node_type' => $album_item->parent->node_type, 'node_id' => $album_item->parent->node_id, 'module_type' => 'MOD_CLASSEUR');
             $mod_classeur = _doQuery($sql, $param);
             if (!isset($mod_classeur[0])) {
                 $node_infos = $this->getNodeInfos($album_item->parent->node_type, $album_item->parent->node_id);
                 $file =& CopixSelectorFactory::create("classeur|classeur");
                 $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
                 $modservice =& CopixClassesFactory::Create('classeur|kernelclasseur');
                 if (method_exists($modservice, "create")) {
                     $modid = $modservice->create(array('title' => $node_infos->nom, 'subtitle' => '', 'node_type' => $album_item->parent->node_type, 'node_id' => $album_item->parent->node_id));
                     if ($modid != null) {
                         Kernel::registerModule('MOD_CLASSEUR', $modid, $album_item->parent->node_type, $album_item->parent->node_id);
                     }
                 }
                 $classeur_id = $modid;
             } else {
                 $classeur_id = $mod_classeur[0]->module_id;
             }
             $classeurDAO = _ioDAO('classeur|classeur');
             $classeur = $classeurDAO->get($classeur_id);
             $new_dir = realpath('./static/classeur') . '/' . $classeur->id . '-' . $classeur->cle . '/';
             if (!file_exists($new_dir)) {
                 mkdir($new_dir, 0755, true);
             }
             //// CREATION D'UN DOSSIER D'IMPORT
             $dossierDAO = _ioDAO('classeur|classeurdossier');
             $dossier = _record('classeur|classeurdossier');
             $dossier->classeur_id = $classeur_id;
             $dossier->parent_id = 0;
             $dossier->nom = "Import Album " . $album_item->info->album_id;
             $dossier->cle = $album_item->info->album_cle;
             $dossier->date_creation = $album_item->info->album_date;
             $dossier->user_type = "";
             $dossier->user_id = "";
             $dossier->nb_dossiers = 0;
             $dossier->nb_fichiers = 0;
             $dossier->taille = 0;
             $dossier->casier = 0;
             $dossierDAO->insert($dossier);
             // $dossier->id
             $this->albumImport($album_item, $dossier);
             $classeurservice->updateFolderInfosWithDescendants($dossier);
         }
     }
     // IMPORT MALLES
     if (1) {
         foreach ($malle_tree as $malle_item) {
             if (!isset($malle_item->parent->node_type)) {
                 continue;
             }
             //// RECHERCHE D'UN CLASSEUR EXISTANT
             $sql = "\n                SELECT module_id\n                FROM kernel_mod_enabled\n                WHERE node_type=:node_type AND node_id=:node_id AND module_type=:module_type\n            ";
             $param = array('node_type' => $malle_item->parent->node_type, 'node_id' => $malle_item->parent->node_id, 'module_type' => 'MOD_CLASSEUR');
             $mod_classeur = _doQuery($sql, $param);
             if (!isset($mod_classeur[0])) {
                 $node_infos = $this->getNodeInfos($malle_item->parent->node_type, $malle_item->parent->node_id);
                 $file =& CopixSelectorFactory::create("classeur|classeur");
                 $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
                 $modservice =& CopixClassesFactory::Create('classeur|kernelclasseur');
                 if (method_exists($modservice, "create")) {
                     $modid = $modservice->create(array('title' => $node_infos->nom, 'subtitle' => '', 'node_type' => $malle_item->parent->node_type, 'node_id' => $malle_item->parent->node_id));
                     if ($modid != null) {
                         Kernel::registerModule('MOD_CLASSEUR', $modid, $malle_item->parent->node_type, $malle_item->parent->node_id);
                     }
                 }
                 $classeur_id = $modid;
             } else {
                 $classeur_id = $mod_classeur[0]->module_id;
             }
             $classeurDAO = _ioDAO('classeur|classeur');
             $classeur = $classeurDAO->get($classeur_id);
             $new_dir = realpath('./static/classeur') . '/' . $classeur->id . '-' . $classeur->cle . '/';
             if (!file_exists($new_dir)) {
                 mkdir($new_dir, 0755, true);
             }
             //// CREATION D'UN DOSSIER D'IMPORT
             $dossierDAO = _ioDAO('classeur|classeurdossier');
             $dossier = _record('classeur|classeurdossier');
             $dossier->classeur_id = $classeur_id;
             $dossier->parent_id = 0;
             $dossier->nom = "Import documents " . $malle_item->info->id;
             $dossier->cle = $malle_item->info->cle;
             $dossier->date_creation = $malle_item->info->date_creation;
             $dossier->user_type = "";
             $dossier->user_id = "";
             $dossier->nb_dossiers = 0;
             $dossier->nb_fichiers = 0;
             $dossier->taille = 0;
             $dossierDAO->insert($dossier);
             // $dossier->id
             $this->malleImport($malle_item, $dossier);
             $classeurservice->updateFolderInfosWithDescendants($dossier);
         }
     }
     $sql = "\n            UPDATE kernel_mod_available\n            SET node = CONCAT(node, '_OFF')\n            WHERE module = 'MOD_MALLE' OR module = 'MOD_ALBUM'";
     _doQuery($sql);
     $sql = "\n            UPDATE kernel_mod_enabled\n            SET node_type = CONCAT(node_type, '_OFF')\n            WHERE module_type = 'MOD_MALLE' OR module_type = 'MOD_ALBUM' AND node_type != 'MOD_TELEPROCEDURES'";
     _doQuery($sql);
     echo "<h1>Fin</h1>";
     echo "<pre>";
     print_r($album_tree);
     print_r($malle_tree);
     die;
 }
 public function createMissingModules($node_type, $node_id)
 {
     $modavailable = Kernel::getModAvailable($node_type);
     $modenabled = Kernel::getModEnabled($node_type, $node_id, _currentUser()->getExtra('type'), _currentUser()->getExtra('id'), 1);
     $modinstalled = array();
     foreach ($modenabled as $module) {
         $modinstalled[] = strtolower($module->module_type);
     }
     //var_dump($modinstalled);
     $nodeInfo = Kernel::getNodeInfo($node_type, $node_id);
     if ($node_type == 'CLUB') {
         foreach ($modavailable as $module) {
             // echo "<li>".$module->module_type."</li>";
             if ($module->module_type == 'MOD_MAGICMAIL') {
                 $modname = 'magicmail';
                 // _dump($modinstalled);
                 // if( array_search("mod_magicmail", $modinstalled)===false ) echo "magicmail ";
                 // if( array_search("mod_blog", $modinstalled)!==false ) echo "blog ";
                 if (array_search("mod_magicmail", $modinstalled) === false && array_search("mod_blog", $modinstalled) !== false) {
                     $file =& CopixSelectorFactory::create($modname . "|" . $modname);
                     $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
                     //var_dump($filePath);
                     if (is_readable($filePath)) {
                         $modservice =& CopixClassesFactory::Create($modname . '|kernel' . $modname);
                         if (method_exists($modservice, "create")) {
                             $subtitle = $node_type == 'BU_ECOLE' && isset($nodeInfo['ALL']->eco_type) ? $nodeInfo['ALL']->eco_type : '';
                             $prenom = isset($nodeInfo['prenom']) ? $nodeInfo['prenom'] : '';
                             $modid = $modservice->create(array('title' => trim($prenom . ' ' . $nodeInfo['nom']), 'subtitle' => $subtitle, 'node_type' => $node_type, 'node_id' => $node_id));
                             if ($modid != null) {
                                 // _dump( array( $module->module_type, $modid, $node_type, $node_id ));
                                 Kernel::registerModule($module->module_type, $modid, $node_type, $node_id);
                             }
                         }
                     }
                 }
             }
         }
         return false;
     }
     foreach ($modavailable as $module) {
         //var_dump($module);
         if (preg_match("/^MOD_(.+)\$/", $module->module_type, $modinfo)) {
             $modname = strtolower($modinfo[1]);
             if (array_search("mod_" . $modname, $modinstalled) === false) {
                 $file =& CopixSelectorFactory::create($modname . "|" . $modname);
                 $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
                 //var_dump($filePath);
                 if (is_readable($filePath)) {
                     $modservice =& CopixClassesFactory::Create($modname . '|kernel' . $modname);
                     if (method_exists($modservice, "create")) {
                         $subtitle = $node_type == 'BU_ECOLE' && isset($nodeInfo['ALL']->eco_type) ? $nodeInfo['ALL']->eco_type : '';
                         $prenom = isset($nodeInfo['prenom']) ? $nodeInfo['prenom'] : '';
                         $modid = $modservice->create(array('title' => trim($prenom . ' ' . $nodeInfo['nom']), 'subtitle' => $subtitle, 'node_type' => $node_type, 'node_id' => $node_id));
                         if ($modid != null) {
                             Kernel::registerModule($module->module_type, $modid, $node_type, $node_id);
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * Verifie si le blog des teleprocedures d'une ville existe. Si non, le cree. Renvoie son id.
  *
  * @author Christophe Beyer <*****@*****.**>
  * @since 2009/01/23
  * @param object $rTelep Recordset de la teleprocedure
  * @return object Recordset du blog
  */
 public function checkIfBlogExists($rTelep)
 {
     $modEnabled = Kernel::getModEnabled('MOD_TELEPROCEDURES', $rTelep->id);
     $return = null;
     $exists = false;
     foreach ($modEnabled as $mod) {
         if ($mod->module_type == 'MOD_BLOG') {
             $exists = $mod->module_id;
         }
     }
     if (!$exists) {
         // Il faut creer le blog
         $modname = 'blog';
         $file =& CopixSelectorFactory::create($modname . "|" . $modname);
         $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
         if (is_readable($filePath)) {
             $modservice =& CopixClassesFactory::Create($modname . '|kernel' . $modname);
             if (method_exists($modservice, "create")) {
                 $title = $rTelep->titre . ' - ' . CopixI18N::get('teleprocedures|teleprocedures.moduleDescription');
                 $modid = $modservice->create(array('title' => $title, 'is_public' => 0));
                 if ($modid != null) {
                     Kernel::registerModule('MOD_BLOG', $modid, 'MOD_TELEPROCEDURES', $rTelep->id);
                     // Si le blog est cree, on cree aussi la malle et l'album
                     $modname = 'album';
                     $file =& CopixSelectorFactory::create($modname . "|" . $modname);
                     $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
                     if (is_readable($filePath)) {
                         $modservice =& CopixClassesFactory::Create($modname . '|kernel' . $modname);
                         if (method_exists($modservice, "create")) {
                             $title = $rTelep->titre . ' - ' . CopixI18N::get('teleprocedures|teleprocedures.moduleDescription');
                             $mod2id = $modservice->create(array('title' => $title));
                             if ($mod2id != null) {
                                 Kernel::registerModule('MOD_ALBUM', $mod2id, 'MOD_TELEPROCEDURES', $rTelep->id);
                             }
                         }
                     }
                     $modname = 'malle';
                     $file =& CopixSelectorFactory::create($modname . "|" . $modname);
                     $filePath = $file->getPath() . COPIX_CLASSES_DIR . "kernel" . strtolower($file->fileName) . '.class.php';
                     if (is_readable($filePath)) {
                         $modservice =& CopixClassesFactory::Create($modname . '|kernel' . $modname);
                         if (method_exists($modservice, "create")) {
                             $title = $rTelep->titre . ' - ' . CopixI18N::get('teleprocedures|teleprocedures.moduleDescription');
                             $mod2id = $modservice->create(array('title' => $title));
                             if ($mod2id != null) {
                                 Kernel::registerModule('MOD_MALLE', $mod2id, 'MOD_TELEPROCEDURES', $rTelep->id);
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $modid = $exists;
     }
     if ($modid) {
         $daoBlog =& _dao('blog|blog');
         $return = $daoBlog->get($modid);
     }
     return $return;
 }