<?php
// suppression d'items.
$items=new yamlReadwriter();
$items->setType("items_delete"); // important

switch($_POST['action']){
    case "loadform":
        $menu_edit= array();
        include(APP."snippets/menu-viewer.php");
        
        
        $items->addHidden("action","submitform");
        $items->addHidden("callback","yc_deleteGriditems");           
        $items->addHidden("endaction","yc_closeViewer");           

        $items->setSnippetFolder(APP."form_parts/");
        $items->form_title="Supprimer des items";
        $items->form_comment="Sélectionnez les items à supprimer dans la mosaïque.";
        $items->writeForm();

        break;

    case "submitform":
        $items->loadYaml(getTemplate("structure_item.yaml"));
        $items->setDestinationFolder(CONTENTS."items/");
        
        $retour=array();
        $files=$_POST['sources'];
        foreach($files as $item_url){
            $items->loadContentFromYaml(CONTENTS."items/".$item_url);
            $items->deleteyaml();
            $retour[] = array(
                'id' => $items->filename,
            );
        }
        echo json_encode($retour, JSON_HEX_QUOT | JSON_HEX_TAG);
        supprimer_cache();

        break;
}