FileSystem::supprimer_fichier(CHEMIN_DOSSIER_IMPORT.FileSystem::$file_saved_name);
    exit('Erreur : le fichier image ne semble pas valide !');
  }
  list($image_largeur, $image_hauteur, $image_type, $html_attributs) = $tab_infos;
  $tab_extension_types = array( IMAGETYPE_GIF=>'gif' , IMAGETYPE_JPEG=>'jpeg' , IMAGETYPE_PNG=>'png' ); // http://www.php.net/manual/fr/function.exif-imagetype.php#refsect1-function.exif-imagetype-constants
  // vérifier le type 
  if(!isset($tab_extension_types[$image_type]))
  {
    FileSystem::supprimer_fichier(CHEMIN_DOSSIER_IMPORT.FileSystem::$file_saved_name);
    exit('Erreur : le fichier transmis n\'est pas un fichier image (type '.$image_type.') !');
  }
  $image_format = $tab_extension_types[$image_type];
  // stocker l'image dans la base
  DB_STRUCTURE_IMAGE::DB_modifier_image( $user_id , 'signature' , base64_encode(file_get_contents(CHEMIN_DOSSIER_IMPORT.FileSystem::$file_saved_name)) , $image_format , $image_largeur , $image_hauteur );
  // Générer la balise html et afficher le retour
  list($width,$height) = dimensions_affichage_image( $image_largeur , $image_hauteur , 200 /*largeur_maxi*/ , 200 /*hauteur_maxi*/ );
  $user_texte = ($user_id) ? 'Signature '.$user_texte : $user_texte ;
  exit('<li id="sgn_'.$user_id.'">'.html($user_texte).' : <img src="'.URL_DIR_IMPORT.FileSystem::$file_saved_name.'" alt="'.html($user_texte).'" width="'.$width.'" height="'.$height.'" /><q class="supprimer" title="Supprimer cette image (aucune confirmation ne sera demandée)."></q></li>');
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Supprimer un fichier image (tampon de l'établissement ou signature)
// ////////////////////////////////////////////////////////////////////////////////////////////////////

if( ($action=='delete_signature') && ($user_id>=0) )
{
  DB_STRUCTURE_IMAGE::DB_supprimer_image( $user_id , 'signature' );
  exit('ok');
}

// ////////////////////////////////////////////////////////////////////////////////////////////////////
$options_horizontal_droite = str_replace('"' . $_SESSION['ENVELOPPE']['HORIZONTAL_DROITE'] . '"', '"' . $_SESSION['ENVELOPPE']['HORIZONTAL_DROITE'] . '" selected', fabriquer_chaine_option(15, 25));
$options_vertical_haut = str_replace('"' . $_SESSION['ENVELOPPE']['VERTICAL_HAUT'] . '"', '"' . $_SESSION['ENVELOPPE']['VERTICAL_HAUT'] . '" selected', fabriquer_chaine_option(40, 60));
$options_vertical_milieu = str_replace('"' . $_SESSION['ENVELOPPE']['VERTICAL_MILIEU'] . '"', '"' . $_SESSION['ENVELOPPE']['VERTICAL_MILIEU'] . '" selected', fabriquer_chaine_option(35, 55));
$options_vertical_bas = str_replace('"' . $_SESSION['ENVELOPPE']['VERTICAL_BAS'] . '"', '"' . $_SESSION['ENVELOPPE']['VERTICAL_BAS'] . '" selected', fabriquer_chaine_option(15, 25));
// Formulaire avec la liste des directeurs et professeurs
$select_user = HtmlForm::afficher_select(DB_STRUCTURE_COMMUN::DB_OPT_professeurs_directeurs_etabl(1), 'f_user', 'tampon_structure', FALSE, 'profs_directeurs');
// Récupérer les signatures existantes, dont le tampon de l'établissement.
$li_signatures = '';
$DB_TAB = DB_STRUCTURE_IMAGE::DB_lister_signatures_avec_identite();
foreach ($DB_TAB as $DB_ROW) {
    // Enregistrer temporairement le fichier sur le disque
    $texte = $DB_ROW['user_id'] ? 'Signature ' . $DB_ROW['user_nom'] . ' ' . $DB_ROW['user_prenom'] : 'Tampon de l\'établissement';
    $fichier_nom = 'signature_' . $_SESSION['BASE'] . '_' . $DB_ROW['user_id'] . '_' . fabriquer_fin_nom_fichier__date_et_alea() . '.' . $DB_ROW['image_format'];
    FileSystem::ecrire_fichier(CHEMIN_DOSSIER_EXPORT . $fichier_nom, base64_decode($DB_ROW['image_contenu']));
    // Générer la balise html pour afficher l'image
    list($width, $height) = dimensions_affichage_image($DB_ROW['image_largeur'], $DB_ROW['image_hauteur'], 200, 200);
    $li_signatures .= '<li id="sgn_' . $DB_ROW['user_id'] . '">' . html($texte) . ' : <img src="' . URL_DIR_EXPORT . $fichier_nom . '" alt="' . html($texte) . '" width="' . $width . '" height="' . $height . '" /><q class="supprimer" title="Supprimer cette image (aucune confirmation ne sera demandée)."></q></li>';
}
$li_signatures = $li_signatures ? $li_signatures : '<li id="sgn_none">Aucun fichier image trouvé !</li>';
?>

<div><span class="manuel"><a class="pop_up" href="<?php 
echo SERVEUR_DOCUMENTAIRE;
?>
?fichier=releves_bilans__reglages_syntheses_bilans#toggle_officiel_mise_en_page">DOC : Réglages synthèses &amp; bilans &rarr; Mise en page des bilans officiels</a></span></div>

<hr />

<form action="#" method="post" id="form_mise_en_page">
  <h2>En-tête du document</h2>
  <p>
        FileSystem::supprimer_fichier(CHEMIN_DOSSIER_IMPORT . FileSystem::$file_saved_name);
        exit('Erreur : le fichier image ne semble pas valide !');
    }
    list($image_largeur, $image_hauteur, $image_type, $html_attributs) = $tab_infos;
    $tab_extension_types = array(IMAGETYPE_GIF => 'gif', IMAGETYPE_JPEG => 'jpeg', IMAGETYPE_PNG => 'png');
    // http://www.php.net/manual/fr/function.exif-imagetype.php#refsect1-function.exif-imagetype-constants
    // vérifier le type
    if (!isset($tab_extension_types[$image_type])) {
        FileSystem::supprimer_fichier(CHEMIN_DOSSIER_IMPORT . FileSystem::$file_saved_name);
        exit('Erreur : le fichier transmis n\'est pas un fichier image (type ' . $image_type . ') !');
    }
    $image_format = $tab_extension_types[$image_type];
    // stocker l'image dans la base
    DB_STRUCTURE_IMAGE::DB_modifier_image(0, 'logo', base64_encode(file_get_contents(CHEMIN_DOSSIER_IMPORT . FileSystem::$file_saved_name)), $image_format, $image_largeur, $image_hauteur);
    // Générer la balise html et afficher le retour
    list($width, $height) = dimensions_affichage_image($image_largeur, $image_hauteur, 200, 200);
    exit('<li><img src="' . URL_DIR_IMPORT . FileSystem::$file_saved_name . '" alt="Logo établissement" width="' . $width . '" height="' . $height . '" /><q class="supprimer" title="Supprimer cette image (aucune confirmation ne sera demandée)."></q></li>');
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Supprimer un fichier image (logo de l'établissement)
// ////////////////////////////////////////////////////////////////////////////////////////////////////
if ($action == 'delete_logo') {
    DB_STRUCTURE_IMAGE::DB_supprimer_image(0, 'logo');
    exit('ok');
}
// ////////////////////////////////////////////////////////////////////////////////////////////////////
// Mettre à jour mois_bascule_annee_scolaire
// ////////////////////////////////////////////////////////////////////////////////////////////////////
if ($mois_bascule_annee_scolaire) {
    $tab_parametres = array();
    $tab_parametres['mois_bascule_annee_scolaire'] = $mois_bascule_annee_scolaire;
    $langue_pays_nom  = $tab_langue['langue']['nom'].' - '.$tab_langue['pays']['nom'];
    $selected = ($langue_pays_code==$_SESSION['ETABLISSEMENT']['LANGUE']) ? ' selected' : '' ;
    $options_langue .= '<option value="'.$langue_pays_code.'"'.$selected.'>'.$langue_pays_nom.' ['.$langue_pays_code.']</option>';
  }
}

// Récupérer le logo, si présent.
$li_logo = '<li>Pas de logo actuellement enregistré.</li>';
$DB_ROW = DB_STRUCTURE_IMAGE::DB_recuperer_image( 0 /*user_id*/ , 'logo' );
if(!empty($DB_ROW))
{
  // Enregistrer temporairement le fichier sur le disque
  $fichier_nom = 'logo_'.$_SESSION['BASE'].'_'.fabriquer_fin_nom_fichier__date_et_alea().'.'.$DB_ROW['image_format'];
  FileSystem::ecrire_fichier( CHEMIN_DOSSIER_EXPORT.$fichier_nom , base64_decode($DB_ROW['image_contenu']) );
  // Générer la balise html pour afficher l'image
  list($width,$height) = dimensions_affichage_image( $DB_ROW['image_largeur'] , $DB_ROW['image_hauteur'] , 200 /*largeur_maxi*/ , 200 /*hauteur_maxi*/ );
  $li_logo = '<li><img src="'.URL_DIR_EXPORT.$fichier_nom.'" alt="Logo établissement" width="'.$width.'" height="'.$height.'" /><q class="supprimer" title="Supprimer cette image (aucune confirmation ne sera demandée)."></q></li>';
}

// Info contact du webmestre si multi-structures
if(HEBERGEUR_INSTALLATION=='multi-structures')
{
  $contact_class_zone = 'show';
  charger_parametres_mysql_supplementaires( 0 /*BASE*/ );
  $DB_ROW = DB_WEBMESTRE_ADMINISTRATEUR::DB_recuperer_contact_infos($_SESSION['BASE']);
  $contact_nom      = $DB_ROW['structure_contact_nom'];
  $contact_prenom   = $DB_ROW['structure_contact_prenom'];
  $contact_courriel = $DB_ROW['structure_contact_courriel'];
  $user_readonly = (CONTACT_MODIFICATION_USER!='non') ? '' : ' readonly' ;
  $mail_readonly = (CONTACT_MODIFICATION_MAIL!='non') ? '' : ' readonly' ;
  $user_title    = (CONTACT_MODIFICATION_USER=='oui') ? '' : ' <img alt="" src="./_img/bulle_aide.png" width="16" height="16" title="Valeur non modifiable directement.<br />Utiliser le lien ci-dessous." />' ;