<?php
// transformation d'image

switch($_POST['action']){
    case "gethtml":

        break;

    case "loadform":
        $menu_edit= array();
        include(APP."snippets/menu-viewer.php");
        include(APP."form_parts/image_edit.php");

        break;

    case "submitform":
        if($_FILES['modifiedImage']) {
            if(!$_POST['source']){
                echo "Erreur d'envoi";
                die();
            }
            $image=$_FILES['modifiedImage']['tmp_name'];
            $nomfichier=$_POST['source'];

            //$dest=IMPORTS.$nomfichier;
            $dest=getcompletefilepath($nomfichier);
            move_uploaded_file($image, $dest);

            // virer les vignettes de cette image
            supprimer_cache_images($nomfichier);

            if($_POST['item']){

                $item=new yamlReadwriter();
                $item_url=$_POST['item']; 
                $item->loadYaml(getTemplate("structure_item.yaml")); 
                $item->loadContentFromYaml(CONTENTS."items/".$item_url);

                ob_start(); // Start the output buffer
                $snippet=getSnippetFile("display_item_mosaique.php");
                include($snippet);
                $html=ob_get_contents();
                ob_end_clean();

                supprimer_cache();

                $retour= array( 0 => array(
                    'id' => $item->filename,
                    'html' => $html
                )
                              );
                echo json_encode($retour, JSON_HEX_QUOT | JSON_HEX_TAG);  
            }
        }

        break;
}

?>