<?php
// fichier asynchone pour les pages
$page=new yamlReadwriter();
$page_url=$_POST['source']; 
$page->loadYaml(getTemplate("structure_page.yaml"));// charger le contenu de page
$page->loadContentFromYaml(CONTENTS."pages/".$page_url);
$page->setType("page"); // important
$page->setSnippetFolder(APP."form_parts/");

switch($_POST['action']){        
    case "gethtml":
        $menu_edit=array("edit","viewmode");
        include(APP."snippets/menu-viewer.php");
        // charge le snippet unique ici
        $snippet=getSnippetFile("display_page.php");
        include($snippet);
        break;

    case "loadform":
        $menu_edit=array("viewmode");
        include(APP."snippets/menu-viewer.php");
        
        $page->addHidden("action","submitform");
        $page->addHidden("endaction","yc_reloadpage");  
        
        if(!$page_url){
            $page->form_title="Créer une page";
            $page->form_submit="Créer";

        } else {
            $page->form_title="Modifier un page";
            $page->form_submit="Modifier";
            $page->form_delete=true;
        }
        echo "<div class='generic-viewercontent'>";
        $page->writeForm();
        echo "</div>";
        break;

    case "submitform":
        $page->setDestinationFolder(CONTENTS."pages/");
        $page->processPost(true);
        $snippet=getSnippetFile("menu-pages.php");
        include($snippet);
        break;
        
    case "deleteelem":
        $page->setDestinationFolder(CONTENTS."pages/");
        $page->deleteyaml();
        $snippet=getSnippetFile("menu-pages.php");
        include($snippet);       
        break;

}    