<?php
### Vérifie les droits d'accès de l'utilisateur
if(!current_user_can('administrator'))
	die('Access Denied');    

?>
<style>
th{
    text-align:left;
}
</style>
<div class="wrap">
    <h2>Bloc : Actus</h2>
    <?php
        home_display_warning_message('error');
        home_display_warning_message('notice');    
    ?>    
    <form method="post">
        <table>
            <tr>
                <td>Mode d'affichage des actualités :</td>
                <td>
                    <?php
                        $mode = get_mode_affichage();
                    ?>
                    <select name="type_affichage">
                        <option value="one" <?php echo ($mode == "one") ? ' selected="selected"' : ''; ?>>1 vidéo</option>
                        <option value="two_details" <?php echo ($mode == "two_details") ? ' selected="selected"' : ''; ?>>2 articles</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input class="button" type="submit" name="valider_mode_affichage_actu" value="<?php _e('Save'); ?>"></td>
            </tr>
        </table>
    </form>
    <?php
        switch(get_mode_affichage())
        {
            case 'one':
            case 'one_detail':
                $id_article = get_option('choix_video_actu');
                $id_article_ss = get_option('choix_video_actu_ss');
                $liste_document = home_getArticles();
                
                /* liste des médias */
                $args = array(
                    'post_type' => 'attachment',
                    'post_mime_type' =>'video',
                    'post_status' => 'inherit',
                    'posts_per_page' => -1,
                );
                $videos = get_posts( $args );
    ?>
    <form method="post">
        <table>
            <tr>
                <td>Vidéos disponibles :</td>
                <td>
                    <select name="choix_video_actu">
                        <option value=""></option>
                        <?php 
                            foreach($videos as $cle => $valeur)
                            {
                        ?>
                            <option value="<?php echo $valeur->ID?>" <?php echo ($id_article == $valeur->ID) ? ' selected="selected"' : ''; ?>><?php echo $valeur->post_title?></option>
                        <?php
                            }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>ou lien Youtube (prend la main sur le choix au dessus) :</td>
                <td>
                    <input type="text" name="actu_youtube" value="<?php echo get_option('actu_youtube') ?>" style="width: 350px;" />
                </td>
            </tr>
            <tr>
                <td>Version avec sous-titre :</td>
                <td>
                    <select name="choix_video_actu_ss">
                        <option value=""></option>
                        <?php 
                            foreach($videos as $cle => $valeur)
                            {
                        ?>
                            <option value="<?php echo $valeur->ID?>" <?php echo ($id_article_ss == $valeur->ID) ? ' selected="selected"' : ''; ?>><?php echo $valeur->post_title?></option>
                        <?php
                            }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>ou lien Youtube (prend la main sur le choix au dessus) :</td>
                <td>
                    <input type="text" name="actu_youtube_ss" value="<?php echo get_option('actu_youtube_ss') ?>" style="width: 350px;" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input class="button" type="submit" name="article_actu" value="<?php _e('Save'); ?>"></td>
            </tr>
        </table>
    </form>
    <?php
                break;
                
                
            case 'two_details':
                $id_article = get_option('home_actu_article');
                $liste_document = home_getArticles();
    ?>        
    <form method="post">
        <table>
            <tr>
                <td>Article 1</td>
                <td>
                    <select name="choix_article_actu[]">
                        <option value=""></option>
                        <?php
                            
                            foreach($liste_document as $cle => $valeur)
                            {
                            ?>
                            <option value="<?php echo $valeur->ID; ?>" <?php echo ($id_article[0] == $valeur->ID) ? ' selected="selected"' : ''; ?>><?php echo $valeur->post_title?></option>
                        <?php                
                            }
                        ?>                          
                    </select>
                </td>
            </tr>
            <tr>
                <td>Article 2</td>
                <td>
                    <select name="choix_article_actu[]">
                        <option value=""></option>
                        <?php 
                            foreach($liste_document as $cle => $valeur)
                            {
                        ?>
                            <option value="<?php echo $valeur->ID?>" <?php echo ($id_article[1] == $valeur->ID) ? ' selected="selected"' : ''; ?>><?php echo $valeur->post_title?></option>
                        <?php
                            }
                        ?>                          
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input class="button" type="submit" name="article_actu" value="<?php _e('Save'); ?>"></td>
            </tr>
        </table>
    </form> 
    <?php
                break;
        }
    ?>
</div>