<?php
// charger le fichier de settings général
$module=new yamlReadwriter();
 

switch($_POST['action']){ 
    case "modules_list":
        $menu_edit=array("viewmode");
        include(APP."snippets/menu-viewer.php");
        echo "<div class='generic-viewercontent'>";
        include(getSnippetFile("display_modules_list.php"));
        echo "</div>";
        break;

    case "modules_activation":
        // activer ou désactiver les modules
        $fulllist=glob(CHEMIN."modules/*",GLOB_ONLYDIR);
        @$activated=$_POST['modulename'];
        if(!$activated){ $activated=array(); }
            foreach($fulllist as $module){
                $nom_module=basename($module);
                $nom_strict=preg_replace("/^-/i","",$nom_module);
                if(in_array($module, $activated)){
                    rename($module,CHEMIN."modules/".$nom_strict);
                } else {
                    rename($module,CHEMIN."modules/-".$nom_strict);            
                }
            }
        
        $menu_edit=array("viewmode");
        include(APP."snippets/menu-viewer.php");
        echo "<div class='generic-viewercontent'>";
        include(getSnippetFile("display_modules_list.php"));
        echo "</div>";

        break;

    case "getphp":
        $module_url=$_POST['source'];
        $menu_edit=array("viewmode");
        include(APP."snippets/menu-viewer.php");
        echo "<div class='generic-viewercontent'>";
        include(CHEMIN.$_POST['source']);
        echo "</div>";

        break;
    case "getyaml":
        $module_url=$_POST['source'];
        $menu_edit=array("viewmode");
        include(APP."snippets/menu-viewer.php");
        $page=new yamlReadwriter();
        $page_url=$_POST['source']; 
        $page->loadYaml(getTemplate("structure_page.yaml"));// charger le contenu de page
        $page->loadContentFromYaml(CHEMIN.$_POST['source']);
        $page->setType("page"); // important
        $snippet=getSnippetFile("display_page.php");
        include($snippet);
        break;
}
