<?php

require('../include/inc-connexion.php');
require('../include/inc-config.php');
require('../class/Image.php');
require('../class/imageManager.php');
require('menu.php');
require('../process/process-update-image.php');

$manager = new imageManager($db);
$images_data = $manager->readImagesData();

?>

<?php if(isset($message)) echo $message ?>

<h1><?php echo WEB_TITLE ?></h1>

<ul>
    <?php if(!empty($images_data)) : ?>
        <?php foreach($images_data as $image_data) : ?>
            <li>
                <img src="<?php echo THUMB_DIR_URL . $image_data['filename'] ?>">
                <form method="post" action="">
                    <p><label for="title">Titre :</label></p>
                    <p><input type="text" name="title_form" id="title" value="<?php echo $image_data['title'] ?>"></p>

                    <?php if(!empty($image_data['title'])) : ?>
                        <input type="hidden" name="update_form" value="1">
                    <?php endif ?>
            
                    <p><label for="descr">Description :</label></p>
                    <p><textarea name="descr_form" id="descr" cols="50" rows="5"><?php echo $image_data['descr'] ?></textarea></p>

                    <p><input type="hidden" name="filename_form" value="<?php echo $image_data['filename'] ?>"></p>
                
                    <p><input type="submit" name="submit_form" value="validez"></p>
                </form>
            </li>
        <?php endforeach ?>
    <?php endif ?>
</ul>