示例#1
0
function bulletin_pdf($tab_bull, $i, $tab_rel)
{
    //echo "DEBUG";
    global $gepi_cpe_suivi, $RneEtablissement, $gepiSchoolName, $gepiSchoolAdress1, $gepiSchoolAdress2, $gepiSchoolZipCode, $gepiSchoolCity, $gepiSchoolPays, $gepiSchoolTel, $gepiSchoolFax, $gepiSchoolEmail, $gepiYear, $logo_etab, $bull_intitule_app, $bull_formule_bas, $un_seul_bull_par_famille, $compteur_bulletins, $date_bulletin, $tab_modele_pdf, $use_cell_ajustee, $num_resp_bull, $nb_releve_par_page, $gepi_denom_mention, $signature_bull, $pdf;
    //=========================================
    if (isset($GLOBALS['multisite']) and $GLOBALS['multisite'] == 'y') {
        // On récupère le RNE de l'établissement
        $rep_photos = "../photos/" . $_COOKIE['RNE'] . "/eleves/";
    } else {
        $rep_photos = "../photos/eleves/";
    }
    //==============
    //Ajout J.Etheve
    // ***** flag pour l'affichage de la moyenne générale non coefficientée
    /*
    if ($coefficients_a_1!="oui") {
    	$affiche_deux_moy_gen=1;
    }
    else {
    	$affiche_deux_moy_gen==0;
    }
    */
    $affiche_deux_moy_gen = $tab_bull['affiche_moyenne_general_coef_1'];
    // *****
    $affiche_numero_responsable = $tab_bull['affiche_numero_responsable'];
    //=====================================
    /*
    // NE PAS SUPPRIMER CETTE SECTION... c'est pour le debug
    
    // Règles en rouge:
    // Selon ce que l'on souhaite débugger, décommenter une des deux règles
    $pdf->SetDrawColor(255,0,0);
    //=====================================
    // Règle 1: horizontale
    $tmp_marge_gauche=5;
    $tmp_marge_haut=5;
    $x=$tmp_marge_gauche;
    $y=$tmp_marge_haut;
    
    $pdf->SetXY($x,$y);
    $pdf->Cell(200,1,'','T',0,'C',0);
    
    for($loop=0;$loop<19;$loop++) {
    	$x=$tmp_marge_gauche+$loop*10;
    	$pdf->SetXY($x,$y);
    	$pdf->Cell(5,20,''.$loop,'',0,'L',0);
    	$pdf->SetXY($x,$y);
    	$pdf->Cell(10,270,'','L',0,'C',0);
    
    	for($loop2=0;$loop2<10;$loop2++) {
    		$pdf->SetXY($x+$loop2,$y);
    		$pdf->Cell(10,5,'','L',0,'C',0);
    	}
    }
    //=====================================
    // Règle 2: verticale
    $tmp_marge_gauche=1;
    $tmp_marge_haut=0;
    $x=$tmp_marge_gauche;
    $y=$tmp_marge_haut;
    
    $pdf->SetFont('DejaVu','',5);
    
    // Ligne verticale
    $pdf->SetXY($x,$y);
    $pdf->Cell(1,280,'','L',0,'C',0);
    
    for($loop=1;$loop<29;$loop++) {
    	// Repère numérique en cm
    	$y=$tmp_marge_haut+$loop*10-3;
    	$pdf->SetXY($x,$y);
    	$pdf->Cell(10,5,''.$loop,'',0,'L',0);
    
    	// Ligne tous les centimètres
    	$y=$tmp_marge_haut+$loop*10;
    	$pdf->SetXY($x,$y);
    	$pdf->Cell(200,10,'','T',0,'C',0);
    
    	// Les millimètres
    	for($loop2=0;$loop2<10;$loop2++) {
    		$pdf->SetXY($x,$y-10+$loop2);
    		$pdf->Cell(2,10,'','T',0,'C',0);
    	}
    }
    //=====================================
    // Retour au noir pour les tracés qui suivent:
    $pdf->SetDrawColor(0,0,0);
    */
    //=====================================
    if ($nb_releve_par_page != 1 || $nb_releve_par_page != 2) {
        // Actuellement, on n'a qu'un bulletin par page/recto donc qu'un relevé de notes par verso, mais sait-on jamais un jour...
        $nb_releve_par_page = 1;
    }
    // Préparation des lignes d'adresse
    //echo "\$i=$i et \$nb_bulletins=$nb_bulletins<br />";
    // Initialisation:
    for ($loop = 0; $loop <= 1; $loop++) {
        $tab_adr_ligne1[$loop] = "";
        $tab_adr_ligne2[$loop] = "";
        $tab_adr_ligne3[$loop] = "";
        $tab_adr_ligne4[$loop] = "";
        $tab_adr_ligne5[$loop] = "";
        $tab_adr_ligne6[$loop] = "";
        $tab_adr_ligne7[$loop] = "";
    }
    // ON N'UTILISE PAS LE CHAMP adr4 DE L'ADRESSE DANS resp_adr
    // IL FAUDRA VOIR COMMENT LE RECUPERER
    if (!isset($tab_bull['eleve'][$i]['resp'][0])) {
        //$tab_adr_ligne1[0]="<font color='red'><b>ADRESSE MANQUANTE</b></font>";
        $tab_adr_ligne1[0] = "ADRESSE MANQUANTE";
        $tab_adr_ligne2[0] = "";
        $tab_adr_ligne3[0] = "";
        $tab_adr_ligne4[0] = "";
        $tab_adr_ligne5[0] = "";
        $tab_adr_ligne6[0] = "";
        $tab_adr_ligne7[0] = "";
        // Initialisation parce qu'on a des blagues s'il n'y a pas de resp:
        $nb_bulletins = 1;
    } else {
        if (isset($tab_bull['eleve'][$i]['resp'][1])) {
            if (isset($tab_bull['eleve'][$i]['resp'][1]['adr1']) && isset($tab_bull['eleve'][$i]['resp'][1]['adr2']) && isset($tab_bull['eleve'][$i]['resp'][1]['adr3']) && isset($tab_bull['eleve'][$i]['resp'][1]['adr4']) && isset($tab_bull['eleve'][$i]['resp'][1]['cp']) && isset($tab_bull['eleve'][$i]['resp'][1]['commune'])) {
                // Le deuxième responsable existe et est renseigné
                if ($tab_bull['eleve'][$i]['resp'][0]['adr_id'] == $tab_bull['eleve'][$i]['resp'][1]['adr_id'] or my_strtolower($tab_bull['eleve'][$i]['resp'][0]['adr1']) == my_strtolower($tab_bull['eleve'][$i]['resp'][1]['adr1']) && my_strtolower($tab_bull['eleve'][$i]['resp'][0]['adr2']) == my_strtolower($tab_bull['eleve'][$i]['resp'][1]['adr2']) && my_strtolower($tab_bull['eleve'][$i]['resp'][0]['adr3']) == my_strtolower($tab_bull['eleve'][$i]['resp'][1]['adr3']) && my_strtolower($tab_bull['eleve'][$i]['resp'][0]['adr4']) == my_strtolower($tab_bull['eleve'][$i]['resp'][1]['adr4']) && $tab_bull['eleve'][$i]['resp'][0]['cp'] == $tab_bull['eleve'][$i]['resp'][1]['cp'] && my_strtolower($tab_bull['eleve'][$i]['resp'][0]['commune']) == my_strtolower($tab_bull['eleve'][$i]['resp'][1]['commune'])) {
                    // Les adresses sont identiques
                    $nb_bulletins = 1;
                    $tab_adr_lignes[0] = "";
                    if ($tab_bull['eleve'][$i]['resp'][0]['nom'] != $tab_bull['eleve'][$i]['resp'][1]['nom'] && $tab_bull['eleve'][$i]['resp'][1]['nom'] != "") {
                        // Les noms des responsables sont différents
                        $tab_adr_ligne1[0] = $tab_bull['eleve'][$i]['resp'][0]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][0]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][0]['prenom'] . " et " . $tab_bull['eleve'][$i]['resp'][1]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][1]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][1]['prenom'];
                    } else {
                        if ($tab_bull['eleve'][$i]['resp'][0]['civilite'] != "" && $tab_bull['eleve'][$i]['resp'][1]['civilite'] != "") {
                            $tab_adr_ligne1[0] = $tab_bull['eleve'][$i]['resp'][0]['civilite'] . " et " . $tab_bull['eleve'][$i]['resp'][1]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][0]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][0]['prenom'];
                        } else {
                            $tab_adr_ligne1[0] = "M. et Mme " . $tab_bull['eleve'][$i]['resp'][0]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][0]['prenom'];
                        }
                    }
                    $tab_adr_lignes[0] = "<b>" . $tab_adr_ligne1[0] . "</b>";
                    $tab_adr_ligne2[0] = "";
                    if ($tab_bull['eleve'][$i]['resp'][0]['adr1'] != '') {
                        $tab_adr_ligne2[0] = $tab_bull['eleve'][$i]['resp'][0]['adr1'];
                        $tab_adr_lignes[0] .= "\n";
                        $tab_adr_lignes[0] .= $tab_adr_ligne2[0];
                    }
                    if ($tab_bull['eleve'][$i]['resp'][0]['adr2'] != "") {
                        $tab_adr_ligne3[0] = $tab_bull['eleve'][$i]['resp'][0]['adr2'];
                        $tab_adr_lignes[0] .= "\n";
                        $tab_adr_lignes[0] .= $tab_adr_ligne3[0];
                    }
                    if ($tab_bull['eleve'][$i]['resp'][0]['adr3'] != "") {
                        $tab_adr_ligne4[0] = $tab_bull['eleve'][$i]['resp'][0]['adr3'];
                        $tab_adr_lignes[0] .= "\n";
                        $tab_adr_lignes[0] .= $tab_adr_ligne4[0];
                    }
                    if ($tab_bull['eleve'][$i]['resp'][0]['adr4'] != "") {
                        $tab_adr_ligne5[0] = $tab_bull['eleve'][$i]['resp'][0]['adr4'];
                        $tab_adr_lignes[0] .= "\n";
                        $tab_adr_lignes[0] .= $tab_adr_ligne5[0];
                    }
                    $tab_adr_ligne6[0] = $tab_bull['eleve'][$i]['resp'][0]['cp'] . " " . $tab_bull['eleve'][$i]['resp'][0]['commune'];
                    $tab_adr_lignes[0] .= "\n";
                    $tab_adr_lignes[0] .= $tab_adr_ligne6[0];
                    if ($tab_bull['eleve'][$i]['resp'][0]['pays'] != "" && my_strtolower($tab_bull['eleve'][$i]['resp'][0]['pays']) != my_strtolower($gepiSchoolPays)) {
                        $tab_adr_ligne7[0] = $tab_bull['eleve'][$i]['resp'][0]['pays'];
                        $tab_adr_lignes[0] .= "\n";
                        $tab_adr_lignes[0] .= $tab_adr_ligne7[0];
                    }
                } else {
                    // Les adresses sont différentes
                    //if ($un_seul_bull_par_famille!="oui") {
                    // On teste en plus si la deuxième adresse est valide
                    if ($un_seul_bull_par_famille != "oui" && $tab_bull['eleve'][$i]['resp'][1]['adr1'] != "" && $tab_bull['eleve'][$i]['resp'][1]['commune'] != "") {
                        $nb_bulletins = 2;
                    } else {
                        $nb_bulletins = 1;
                    }
                    for ($cpt = 0; $cpt < $nb_bulletins; $cpt++) {
                        $tab_adr_lignes[$cpt] = "";
                        if ($tab_bull['eleve'][$i]['resp'][$cpt]['civilite'] != "") {
                            $tab_adr_ligne1[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['prenom'];
                        } else {
                            $tab_adr_ligne1[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['prenom'];
                        }
                        $tab_adr_lignes[$cpt] .= "<b>" . $tab_adr_ligne1[$cpt] . "</b>";
                        $tab_adr_ligne2[$cpt] = "";
                        if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr1'] != '') {
                            $tab_adr_ligne2[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr1'];
                            $tab_adr_lignes[$cpt] .= "\n";
                            $tab_adr_lignes[$cpt] .= $tab_adr_ligne2[$cpt];
                        }
                        if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr2'] != "") {
                            $tab_adr_ligne3[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr2'];
                            $tab_adr_lignes[$cpt] .= "\n";
                            $tab_adr_lignes[$cpt] .= $tab_adr_ligne3[$cpt];
                        }
                        if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr3'] != "") {
                            $tab_adr_ligne4[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr3'];
                            $tab_adr_lignes[$cpt] .= "\n";
                            $tab_adr_lignes[$cpt] .= $tab_adr_ligne4[$cpt];
                        }
                        if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr4'] != "") {
                            $tab_adr_ligne5[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr4'];
                            $tab_adr_lignes[$cpt] .= "\n";
                            $tab_adr_lignes[$cpt] .= $tab_adr_ligne5[$cpt];
                        }
                        $tab_adr_ligne6[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['cp'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['commune'];
                        $tab_adr_lignes[$cpt] .= "\n";
                        $tab_adr_lignes[$cpt] .= $tab_adr_ligne6[$cpt];
                        if ($tab_bull['eleve'][$i]['resp'][$cpt]['pays'] != "" && my_strtolower($tab_bull['eleve'][$i]['resp'][$cpt]['pays']) != my_strtolower($gepiSchoolPays)) {
                            $tab_adr_ligne7[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['pays'];
                            $tab_adr_lignes[$cpt] .= "\n";
                            $tab_adr_lignes[$cpt] .= $tab_adr_ligne7[$cpt];
                        }
                    }
                }
            } else {
                // Il n'y a pas de deuxième adresse, mais il y aurait un deuxième responsable???
                // CA NE DEVRAIT PAS ARRIVER ETANT DONNé LA REQUETE EFFECTUEE QUI JOINT resp_pers ET resp_adr...
                if ($un_seul_bull_par_famille != "oui") {
                    $nb_bulletins = 2;
                } else {
                    $nb_bulletins = 1;
                }
                for ($cpt = 0; $cpt < $nb_bulletins; $cpt++) {
                    $tab_adr_lignes[$cpt] = "";
                    if ($tab_bull['eleve'][$i]['resp'][$cpt]['civilite'] != "") {
                        $tab_adr_ligne1[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['prenom'];
                    } else {
                        $tab_adr_ligne1[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['prenom'];
                    }
                    $tab_adr_lignes[$cpt] .= "<b>" . $tab_adr_ligne1[$cpt] . "</b>";
                    $tab_adr_ligne2[$cpt] = "";
                    if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr1'] != '') {
                        $tab_adr_ligne2[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr1'];
                        $tab_adr_lignes[$cpt] .= "\n";
                        $tab_adr_lignes[$cpt] .= $tab_adr_ligne2[$cpt];
                    }
                    if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr2'] != "") {
                        $tab_adr_ligne3[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr2'];
                        $tab_adr_lignes[$cpt] .= "\n";
                        $tab_adr_lignes[$cpt] .= $tab_adr_ligne3[$cpt];
                    }
                    if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr3'] != "") {
                        $tab_adr_ligne4[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr3'];
                        $tab_adr_lignes[$cpt] .= "\n";
                        $tab_adr_lignes[$cpt] .= $tab_adr_ligne4[$cpt];
                    }
                    if ($tab_bull['eleve'][$i]['resp'][$cpt]['adr4'] != "") {
                        $tab_adr_ligne5[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['adr4'];
                        $tab_adr_lignes[$cpt] .= "\n";
                        $tab_adr_lignes[$cpt] .= $tab_adr_ligne5[$cpt];
                    }
                    $tab_adr_ligne6[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['cp'] . " " . $tab_bull['eleve'][$i]['resp'][$cpt]['commune'];
                    $tab_adr_lignes[$cpt] .= "\n";
                    $tab_adr_lignes[$cpt] .= $tab_adr_ligne6[$cpt];
                    if ($tab_bull['eleve'][$i]['resp'][$cpt]['pays'] != "" && my_strtolower($tab_bull['eleve'][$i]['resp'][$cpt]['pays']) != my_strtolower($gepiSchoolPays)) {
                        $tab_adr_ligne7[$cpt] = $tab_bull['eleve'][$i]['resp'][$cpt]['pays'];
                        $tab_adr_lignes[$cpt] .= "\n";
                        $tab_adr_lignes[$cpt] .= $tab_adr_ligne7[$cpt];
                    }
                }
            }
        } else {
            // Il n'y a pas de deuxième responsable
            $nb_bulletins = 1;
            $tab_adr_lignes[0] = "";
            if ($tab_bull['eleve'][$i]['resp'][0]['civilite'] != "") {
                $tab_adr_ligne1[0] = $tab_bull['eleve'][$i]['resp'][0]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][0]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][0]['prenom'];
            } else {
                $tab_adr_ligne1[0] = $tab_bull['eleve'][$i]['resp'][0]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][0]['prenom'];
            }
            $tab_adr_lignes[0] .= "<b>" . $tab_adr_ligne1[0] . "</b>";
            $tab_adr_ligne2[0] = "";
            if ($tab_bull['eleve'][$i]['resp'][0]['adr1'] != '') {
                $tab_adr_ligne2[0] = $tab_bull['eleve'][$i]['resp'][0]['adr1'];
                $tab_adr_lignes[0] .= "\n";
                $tab_adr_lignes[0] .= $tab_adr_ligne2[0];
            }
            if ($tab_bull['eleve'][$i]['resp'][0]['adr2'] != "") {
                $tab_adr_ligne3[0] = $tab_bull['eleve'][$i]['resp'][0]['adr2'];
                $tab_adr_lignes[0] .= "\n";
                $tab_adr_lignes[0] .= $tab_adr_ligne3[0];
            }
            if ($tab_bull['eleve'][$i]['resp'][0]['adr3'] != "") {
                $tab_adr_ligne4[0] = $tab_bull['eleve'][$i]['resp'][0]['adr3'];
                $tab_adr_lignes[0] .= "\n";
                $tab_adr_lignes[0] .= $tab_adr_ligne4[0];
            }
            if ($tab_bull['eleve'][$i]['resp'][0]['adr4'] != "") {
                $tab_adr_ligne5[0] = $tab_bull['eleve'][$i]['resp'][0]['adr4'];
                $tab_adr_lignes[0] .= "\n";
                $tab_adr_lignes[0] .= $tab_adr_ligne5[0];
            }
            $tab_adr_ligne6[0] = $tab_bull['eleve'][$i]['resp'][0]['cp'] . " " . $tab_bull['eleve'][$i]['resp'][0]['commune'];
            $tab_adr_lignes[0] .= "\n";
            $tab_adr_lignes[0] .= $tab_adr_ligne6[0];
            if ($tab_bull['eleve'][$i]['resp'][0]['pays'] != "" && my_strtolower($tab_bull['eleve'][$i]['resp'][0]['pays']) != my_strtolower($gepiSchoolPays)) {
                $tab_adr_ligne7[0] = $tab_bull['eleve'][$i]['resp'][0]['pays'];
                $tab_adr_lignes[0] .= "\n";
                $tab_adr_lignes[0] .= $tab_adr_ligne7[0];
            }
        }
    }
    // Envoi du bulletin à des resp_legal=0
    if (isset($tab_bull['eleve'][$i]['resp'][2])) {
        //$indice_tab_adr=count($tab_adr_ligne1);
        foreach ($tab_bull['eleve'][$i]['resp'] as $key => $value) {
            if ($key >= 2) {
                $tab_adr_lignes[$nb_bulletins] = "";
                if ($tab_bull['eleve'][$i]['resp'][$key]['civilite'] != "") {
                    $tab_adr_ligne1[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['civilite'] . " " . $tab_bull['eleve'][$i]['resp'][$key]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][$key]['prenom'];
                } else {
                    $tab_adr_ligne1[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['nom'] . " " . $tab_bull['eleve'][$i]['resp'][$key]['prenom'];
                }
                $tab_adr_lignes[$nb_bulletins] .= "<b>" . $tab_adr_ligne1[0] . "</b>";
                $tab_adr_ligne2[$nb_bulletins] = "";
                if ($tab_bull['eleve'][$i]['resp'][$key]['adr1'] != '') {
                    $tab_adr_ligne2[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['adr1'];
                    $tab_adr_lignes[$nb_bulletins] .= "\n";
                    $tab_adr_lignes[$nb_bulletins] .= $tab_adr_ligne2[0];
                }
                if ($tab_bull['eleve'][$i]['resp'][$key]['adr2'] != "") {
                    $tab_adr_ligne3[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['adr2'];
                    $tab_adr_lignes[$nb_bulletins] .= "\n";
                    $tab_adr_lignes[$nb_bulletins] .= $tab_adr_ligne3[0];
                }
                if ($tab_bull['eleve'][$i]['resp'][$key]['adr3'] != "") {
                    $tab_adr_ligne4[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['adr3'];
                    $tab_adr_lignes[$nb_bulletins] .= "\n";
                    $tab_adr_lignes[$nb_bulletins] .= $tab_adr_ligne4[0];
                }
                if ($tab_bull['eleve'][$i]['resp'][$key]['adr4'] != "") {
                    $tab_adr_ligne5[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['adr4'];
                    $tab_adr_lignes[$nb_bulletins] .= "\n";
                    $tab_adr_lignes[$nb_bulletins] .= $tab_adr_ligne5[0];
                }
                $tab_adr_ligne6[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['cp'] . " " . $tab_bull['eleve'][$i]['resp'][$key]['commune'];
                $tab_adr_lignes[$nb_bulletins] .= "\n";
                $tab_adr_lignes[$nb_bulletins] .= $tab_adr_ligne6[0];
                if ($tab_bull['eleve'][$i]['resp'][$key]['pays'] != "" && my_strtolower($tab_bull['eleve'][$i]['resp'][$key]['pays']) != my_strtolower($gepiSchoolPays)) {
                    $tab_adr_ligne7[$nb_bulletins] = $tab_bull['eleve'][$i]['resp'][$key]['pays'];
                    $tab_adr_lignes[$nb_bulletins] .= "\n";
                    $tab_adr_lignes[$nb_bulletins] .= $tab_adr_ligne7[0];
                }
                $nb_bulletins++;
            }
        }
    }
    //=========================================
    //echo "\$i=$i et \$nb_bulletins=$nb_bulletins<br />";
    //+++++++++++++++++++++++++++++++++++++++++++
    // A FAIRE
    // Mettre ici une boucle pour $nb_bulletins
    // Et tenir compte par la suite de la demande d'intercaler le relevé de notes ou non
    //+++++++++++++++++++++++++++++++++++++++++++
    for ($num_resp_bull = 0; $num_resp_bull < $nb_bulletins; $num_resp_bull++) {
        $pdf->AddPage();
        //ajout d'une page au document
        $pdf->SetFont('DejaVu');
        //================================
        // On insère le footer dès que la page est créée:
        //Positionnement à 1 cm du bas et 0,5cm + 0,5cm du coté gauche
        $pdf->SetXY(5, -10);
        //Police DejaVu Gras 6
        $pdf->SetFont('DejaVu', 'B', 8);
        // $fomule = 'Bulletin à conserver précieusement. Aucun duplicata ne sera délivré. - GEPI : solution libre de gestion et de suivi des résultats scolaires.'
        $pdf->Cell(0, 4.5, $bull_formule_bas, 0, 0, 'C');
        //================================
        // A VERIFIER: CETTE VARIABLE NE DOIT PAS ETRE UTILE
        // SI LES VALEURS AFFICHEES PROVIENNENT DE L'EXTRACTION HORS DE LA FONCTION
        $total_coef_en_calcul = 0;
        // quand on change d'élève on vide les variables suivantes
        $categorie_passe = '';
        $total_moyenne_classe_en_calcul = 0;
        $total_moyenne_min_en_calcul = 0;
        $total_moyenne_max_en_calcul = 0;
        $total_coef_en_calcul = 0;
        // ...
        $hauteur_pris = 0;
        //=========================================
        // Récupération de l'identifiant de la classe:
        $classe_id = $tab_bull['eleve'][$i]['id_classe'];
        //=========================================
        // 20120713
        if ($tab_bull['verouiller'] == "N") {
            $pdf->SetFont('DejaVu', 'B', 40);
            $pdf->SetTextColor(255, 192, 203);
            //$pdf->TextWithRotation(40,190,$texte_filigrame[$classe_id],45);
            $pdf->TextWithRotation(40, 210, "ATTENTION : Période non close", 45);
            $pdf->SetTextColor(0, 0, 0);
        } elseif ($tab_modele_pdf["affiche_filigrame"][$classe_id] === '1') {
            $pdf->SetFont('DejaVu', 'B', 50);
            $pdf->SetTextColor(255, 192, 203);
            //$pdf->TextWithRotation(40,190,$texte_filigrame[$classe_id],45);
            $pdf->TextWithRotation(40, 190, $tab_modele_pdf["texte_filigrame"][$classe_id], 45);
            $pdf->SetTextColor(0, 0, 0);
        }
        //=========================================
        // ============= DEBUT BLOC ETABLISSEMENT ==========================
        // Bloc identification etablissement
        $logo = '../images/' . getSettingValue('logo_etab');
        $format_du_logo = my_strtolower(str_replace('.', '', strstr(getSettingValue('logo_etab'), '.')));
        // Logo
        //if($tab_modele_pdf["affiche_logo_etab"][$classe_id]==='1' and file_exists($logo) and getSettingValue('logo_etab') != '' and ($format_du_logo==='jpg' or $format_du_logo==='png'))
        if ($tab_modele_pdf["affiche_logo_etab"][$classe_id] === '1' and file_exists($logo) and getSettingValue('logo_etab') != '' and ($format_du_logo === 'jpg' or $format_du_logo === 'png')) {
            $valeur = redimensionne_image($logo, $tab_modele_pdf["L_max_logo"][$classe_id], $tab_modele_pdf["H_max_logo"][$classe_id]);
            $X_logo = 5;
            $Y_logo = 5;
            $L_logo = $valeur[0];
            $H_logo = $valeur[1];
            $X_etab = $X_logo + $L_logo + 1;
            $Y_etab = $Y_logo;
            if (!isset($tab_modele_pdf["centrage_logo"][$classe_id]) or empty($tab_modele_pdf["centrage_logo"][$classe_id])) {
                $tab_modele_pdf["centrage_logo"][$classe_id] = '0';
            }
            if ($tab_modele_pdf["centrage_logo"][$classe_id] === '1') {
                // centrage du logo
                $centre_du_logo = $H_logo / 2;
                $Y_logo = $tab_modele_pdf["Y_centre_logo"][$classe_id] - $centre_du_logo;
            }
            //logo
            $tmp_dim_photo = getimagesize($logo);
            if (isset($tmp_dim_photo[2]) && $tmp_dim_photo[2] == 2) {
                $pdf->Image($logo, $X_logo, $Y_logo, $L_logo, $H_logo);
            }
        }
        //=========================================
        // Adresse établissement
        if (!isset($X_etab) or empty($X_etab)) {
            $X_etab = '5';
            $Y_etab = '5';
        }
        $pdf->SetXY($X_etab, $Y_etab);
        $pdf->SetFont('DejaVu', '', 14);
        //=========================
        // AJOUT: boireaus 20081224
        //        Ajout du test $tab_modele_pdf["affiche_nom_etab"][$classe_id] et $tab_modele_pdf["affiche_adresse_etab"][$classe_id]
        //=========================
        //$tab_modele_pdf["affiche_nom_etab"][$classe_id]=0;
        if (isset($tab_modele_pdf["affiche_nom_etab"][$classe_id]) && $tab_modele_pdf["affiche_nom_etab"][$classe_id] != "0" || !isset($tab_modele_pdf["affiche_nom_etab"][$classe_id])) {
            // mettre en gras le nom de l'établissement si $nom_etab_gras = 1
            if ($tab_modele_pdf["nom_etab_gras"][$classe_id] === '1') {
                $pdf->SetFont('DejaVu', 'B', 14);
            }
            $pdf->Cell(90, 7, $gepiSchoolName, 0, 2, '');
        }
        //$tab_modele_pdf["affiche_adresse_etab"][$classe_id]=0;
        if (isset($tab_modele_pdf["affiche_adresse_etab"][$classe_id]) && $tab_modele_pdf["affiche_adresse_etab"][$classe_id] != "0" || !isset($tab_modele_pdf["affiche_adresse_etab"][$classe_id])) {
            $pdf->SetFont('DejaVu', '', 10);
            if ($gepiSchoolAdress1 != '') {
                $pdf->Cell(90, 5, $gepiSchoolAdress1, 0, 2, '');
            }
            if ($gepiSchoolAdress2 != '') {
                $pdf->Cell(90, 5, $gepiSchoolAdress2, 0, 2, '');
            }
            $pdf->Cell(90, 5, $gepiSchoolZipCode . " " . $gepiSchoolCity, 0, 2, '');
        }
        $passealaligne = '0';
        // entête téléphone
        // emplacement du cadre télécom
        $x_telecom = $pdf->GetX();
        $y_telecom = $pdf->GetY();
        // Affichage du tel de l'établissement
        if ($tab_modele_pdf["entente_tel"][$classe_id] === '1') {
            $grandeur = '';
            $text_tel = '';
            if ($tab_modele_pdf["tel_image"][$classe_id] != '') {
                $a = $pdf->GetX();
                $b = $pdf->GetY();
                $ima = '../images/imabulle/' . $tab_modele_pdf["tel_image"][$classe_id] . '.jpg';
                $valeurima = redimensionne_image($ima, 15, 15);
                $pdf->Image($ima, $a, $b, $valeurima[0], $valeurima[1]);
                $text_tel = '      ' . $gepiSchoolTel;
                $grandeur = $pdf->GetStringWidth($text_tel);
                $grandeur = $grandeur + 2;
            } else {
                if ($tab_modele_pdf["tel_texte"][$classe_id] != '') {
                    $text_tel = $tab_modele_pdf["tel_texte"][$classe_id];
                }
                $text_tel .= $gepiSchoolTel;
                $grandeur = $pdf->GetStringWidth($text_tel);
            }
            /*
            if ( $tab_modele_pdf["tel_texte"][$classe_id] != '' and $tab_modele_pdf["tel_image"][$classe_id] === '' ) {
            	$text_tel = $tab_modele_pdf["tel_texte"][$classe_id].''.$gepiSchoolTel;
            	$grandeur = $pdf->GetStringWidth($text_tel);
            }
            */
            $pdf->Cell($grandeur, 5, $text_tel, 0, $passealaligne, '');
        }
        $passealaligne = '2';
        // entête fax
        if ($tab_modele_pdf["entente_fax"][$classe_id] === '1') {
            $text_fax = '';
            if ($tab_modele_pdf["fax_image"][$classe_id] != '') {
                $a = $pdf->GetX();
                $b = $pdf->GetY();
                $ima = '../images/imabulle/' . $tab_modele_pdf["fax_image"][$classe_id] . '.jpg';
                $valeurima = redimensionne_image($ima, 15, 15);
                $pdf->Image($ima, $a, $b, $valeurima[0], $valeurima[1]);
                $text_fax = '      ' . $gepiSchoolFax;
            } else {
                if ($tab_modele_pdf["fax_texte"][$classe_id] != '') {
                    $text_fax = $tab_modele_pdf["fax_texte"][$classe_id];
                }
                $text_fax .= $gepiSchoolFax;
            }
            /*
            if ( $tab_modele_pdf["fax_texte"][$classe_id] != '' and $tab_modele_pdf["fax_image"][$classe_id] === '' ) {
            	$text_fax = $tab_modele_pdf["fax_texte"][$classe_id].''.$gepiSchoolFax;
            }
            */
            if ($tab_modele_pdf["entente_tel"][$classe_id] === '1') {
                $text_fax = " " . $text_fax;
            }
            $pdf->Cell(90, 5, $text_fax, 0, $passealaligne, '');
        }
        if ($tab_modele_pdf["entente_mel"][$classe_id] === '1') {
            $text_mel = '';
            $y_telecom = $y_telecom + 5;
            $pdf->SetXY($x_telecom, $y_telecom);
            //$text_mel = $gepiSchoolEmail;
            if ($tab_modele_pdf["courrier_image"][$classe_id] != '') {
                $a = $pdf->GetX();
                $b = $pdf->GetY();
                $ima = '../images/imabulle/' . $tab_modele_pdf["courrier_image"][$classe_id] . '.jpg';
                $valeurima = redimensionne_image($ima, 15, 15);
                $pdf->Image($ima, $a, $b, $valeurima[0], $valeurima[1]);
                $text_mel = '      ' . $gepiSchoolEmail;
            } else {
                if ($tab_modele_pdf["courrier_texte"][$classe_id] != '') {
                    $text_mel = $tab_modele_pdf["courrier_texte"][$classe_id];
                }
                $text_mel .= $gepiSchoolEmail;
            }
            /*
            if ( $tab_modele_pdf["courrier_texte"][$classe_id] != '' and $tab_modele_pdf["courrier_image"][$classe_id] === '' ) {
            	$text_mel = $tab_modele_pdf["courrier_texte"][$classe_id].' '.$gepiSchoolEmail;
            }
            */
            $pdf->Cell(90, 5, $text_mel, 0, 2, '');
        }
        // Lignes supplémentaires à prendre en compte...
        if ($tab_modele_pdf["entete_info_etab_suppl"][$classe_id] == 'y' && ($tab_modele_pdf["entete_info_etab_suppl_texte"][$classe_id] != '' || $tab_modele_pdf["entete_info_etab_suppl_valeur"][$classe_id] != '')) {
            $y_telecom = $y_telecom + 5;
            $pdf->SetXY($x_telecom, $y_telecom);
            $texte = $tab_modele_pdf["entete_info_etab_suppl_texte"][$classe_id] . " : " . $tab_modele_pdf["entete_info_etab_suppl_valeur"][$classe_id];
            $pdf->Cell(90, 5, $texte, 0, 2, '');
        }
        // ============= FIN BLOC ETABLISSEMENT ==========================
        //=========================================
        // A VOIR: REMPLACER LE $i PAR AUTRE CHOSE POUR EVITER LA COLLISION AVEC L'INDICE $i passé à la fonction
        //$i = $nb_eleve_aff;
        //$id_periode = $periode_classe[$id_classe_selection][$cpt_info_periode];
        $id_periode = $tab_bull['num_periode'];
        // AJOUT ERIC
        //$classe_id=$id_classe_selection;
        $pdf->SetFont('DejaVu', 'B', 12);
        // gestion des styles
        $pdf->SetStyle2("b", "DejaVu", "B", 8, "0,0,0");
        $pdf->SetStyle2("i", "DejaVu", "I", 8, "0,0,0");
        $pdf->SetStyle2("u", "DejaVu", "U", 8, "0,0,0");
        // style pour la case appréciation générale
        // identité du professeur principal
        if ($tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id] != '' and $tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id] < '15') {
            $taille = $tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id];
        } else {
            $taille = '10';
        }
        $pdf->SetStyle2("bppc", "DejaVu", "B", $taille, "0,0,0");
        $pdf->SetStyle2("ippc", "DejaVu", "I", $taille, "0,0,0");
        // ============= DEBUT BLOC ADRESSE PARENTS ==========================
        // bloc affichage de l'adresse des parents
        if ($tab_modele_pdf["active_bloc_adresse_parent"][$classe_id] === '1') {
            $pdf->SetXY($tab_modele_pdf["X_parent"][$classe_id], $tab_modele_pdf["Y_parent"][$classe_id]);
            // définition des Largeur - hauteur
            if ($tab_modele_pdf["largeur_bloc_adresse"][$classe_id] != '' and $tab_modele_pdf["largeur_bloc_adresse"][$classe_id] != '0') {
                $longeur_cadre_adresse = $tab_modele_pdf["largeur_bloc_adresse"][$classe_id];
            } else {
                $longeur_cadre_adresse = '90';
            }
            if ($tab_modele_pdf["hauteur_bloc_adresse"][$classe_id] != '' and $tab_modele_pdf["hauteur_bloc_adresse"][$classe_id] != '0') {
                $hauteur_cadre_adresse = $tab_modele_pdf["hauteur_bloc_adresse"][$classe_id];
            } else {
                $hauteur_cadre_adresse = '1';
            }
            //=========================
            // Pour le moment, on fait une croix sur cell_ajustee() si la hauteur du cadre n'est pas saisie
            if ($hauteur_cadre_adresse == 1 || $use_cell_ajustee == "n") {
                $texte_1_responsable = trim($tab_adr_ligne1[$num_resp_bull]);
                //$hauteur_caractere=12;
                //$hauteur_caractere=$tab_modele_pdf["adresse_resp_fontsize_ligne_1"][$classe_id];
                $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                $pdf->SetFont('DejaVu', 'B', $hauteur_caractere);
                $val = $pdf->GetStringWidth($texte_1_responsable);
                $taille_texte = $longeur_cadre_adresse;
                $grandeur_texte = 'test';
                while ($grandeur_texte != 'ok') {
                    if ($taille_texte < $val) {
                        $hauteur_caractere = $hauteur_caractere - 0.3;
                        $pdf->SetFont('DejaVu', 'B', $hauteur_caractere);
                        $val = $pdf->GetStringWidth($texte_1_responsable);
                    } else {
                        $grandeur_texte = 'ok';
                    }
                }
                $pdf->Cell(90, 7, $texte_1_responsable, 0, 2, '');
                // ERIC
                if ($tab_modele_pdf["affiche_numero_responsable"][$classe_id] == '1') {
                    //Ajout Eric le 13-11-2010 Num du Resp légal sur le bulletin
                    $pdf->SetXY($tab_modele_pdf["X_parent"][$classe_id] + 90 - 8, $tab_modele_pdf["Y_parent"][$classe_id] - 3);
                    $pdf->SetFont('DejaVu', '', 6);
                    //6==> hauteur de caractère
                    $num = $num_resp_bull + 1;
                    // on se base sur le nombre de bulletin à imprimer
                    $num_legal = "(Resp " . $num . ")";
                    $pdf->Cell(90, 7, $num_legal, 0, 2, '');
                    // On remet le curseur à la bonne position pour la suite de l'adresse
                    $pdf->SetXY($tab_modele_pdf["X_parent"][$classe_id], $tab_modele_pdf["Y_parent"][$classe_id] + 7);
                    // Fin modif Eric
                }
                $texte_1_responsable = $tab_adr_ligne2[$num_resp_bull];
                if ($texte_1_responsable != "") {
                    //$hauteur_caractere=10;
                    $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $val = $pdf->GetStringWidth($texte_1_responsable);
                    $taille_texte = $longeur_cadre_adresse;
                    $grandeur_texte = 'test';
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_caractere = $hauteur_caractere - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                            $val = $pdf->GetStringWidth($texte_1_responsable);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $pdf->Cell(90, 5, $texte_1_responsable, 0, 2, '');
                }
                $texte_1_responsable = $tab_adr_ligne3[$num_resp_bull];
                if ($texte_1_responsable != "") {
                    //$hauteur_caractere=10;
                    $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $val = $pdf->GetStringWidth($texte_1_responsable);
                    $taille_texte = $longeur_cadre_adresse;
                    $grandeur_texte = 'test';
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_caractere = $hauteur_caractere - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                            $val = $pdf->GetStringWidth($texte_1_responsable);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $pdf->Cell(90, 5, $texte_1_responsable, 0, 2, '');
                }
                // Suppression du saut de ligne pour mettre la ligne 3 de l'adresse
                //$pdf->Cell(90,5, '',0,2,'');
                $texte_1_responsable = $tab_adr_ligne4[$num_resp_bull];
                if ($texte_1_responsable != "") {
                    //$hauteur_caractere=10;
                    $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $val = $pdf->GetStringWidth($texte_1_responsable);
                    $taille_texte = $longeur_cadre_adresse;
                    $grandeur_texte = 'test';
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_caractere = $hauteur_caractere - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                            $val = $pdf->GetStringWidth($texte_1_responsable);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $pdf->Cell(90, 5, $texte_1_responsable, 0, 2, '');
                }
                $texte_1_responsable = $tab_adr_ligne5[$num_resp_bull];
                if ($texte_1_responsable != "") {
                    //$hauteur_caractere=10;
                    $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $val = $pdf->GetStringWidth($texte_1_responsable);
                    $taille_texte = $longeur_cadre_adresse;
                    $grandeur_texte = 'test';
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_caractere = $hauteur_caractere - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                            $val = $pdf->GetStringWidth($texte_1_responsable);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $pdf->Cell(90, 5, $texte_1_responsable, 0, 2, '');
                }
                //$texte_1_responsable = $cp_parents[$ident_eleve_aff][$responsable_place]." ".$ville_parents[$ident_eleve_aff][$responsable_place];
                $texte_1_responsable = $tab_adr_ligne6[$num_resp_bull];
                if ($texte_1_responsable != "") {
                    //$hauteur_caractere=10;
                    $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $val = $pdf->GetStringWidth($texte_1_responsable);
                    $taille_texte = $longeur_cadre_adresse;
                    $grandeur_texte = 'test';
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_caractere = $hauteur_caractere - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                            $val = $pdf->GetStringWidth($texte_1_responsable);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $pdf->Cell(90, 5, $texte_1_responsable, 0, 2, '');
                }
                //============================
                //if((my_strtolower($gepiSchoolPays)!=my_strtolower($pays_parents[$ident_eleve_aff][$responsable_place]))&&($pays_parents[$ident_eleve_aff][$responsable_place]!="")) {
                if (isset($tab_adr_ligne7[$num_resp_bull])) {
                    $texte_1_responsable = $tab_adr_ligne7[$num_resp_bull];
                    if ($texte_1_responsable != "") {
                        //$hauteur_caractere=10;
                        $hauteur_caractere = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                        $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                        $val = $pdf->GetStringWidth($texte_1_responsable);
                        $taille_texte = $longeur_cadre_adresse;
                        $grandeur_texte = 'test';
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $val) {
                                $hauteur_caractere = $hauteur_caractere - 0.3;
                                $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                                $val = $pdf->GetStringWidth($texte_1_responsable);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        $pdf->Cell(90, 5, $texte_1_responsable, 0, 2, '');
                    }
                }
                //============================
                $texte_1_responsable = '';
                if ($tab_modele_pdf["cadre_adresse"][$classe_id] != 0) {
                    if ($hauteur_cadre_adresse == '1') {
                        // Patch tout pourri... pour faire un encadrement à peu près correct, même si la hauteur du cadre adresse parent n'a pas été saisie dans le modèle
                        $h_tmp = $pdf->GetY() - $tab_modele_pdf["Y_parent"][$classe_id] - 2;
                        $pdf->Rect($tab_modele_pdf["X_parent"][$classe_id], $tab_modele_pdf["Y_parent"][$classe_id], $longeur_cadre_adresse, $h_tmp, 'D');
                    } else {
                        $pdf->Rect($tab_modele_pdf["X_parent"][$classe_id], $tab_modele_pdf["Y_parent"][$classe_id], $longeur_cadre_adresse, $hauteur_cadre_adresse, 'D');
                    }
                    // Remarque: L'encadrement réalisé ne tient pas compte du texte saisi.
                    //           Si on met des valeurs trop réduites, ça ne diminue pas la taille du texte de l'adresse
                    //           On ne fait ici que mettre une déco qui ne va pas nécessairement coïncider
                    //           A REVOIR...
                }
            } else {
                $texte = $tab_adr_lignes[$num_resp_bull];
                //$taille_max_police=10;
                $taille_max_police = $tab_modele_pdf["adresse_resp_fontsize"][$classe_id];
                $taille_min_police = ceil($taille_max_police / 3);
                $largeur_dispo = $longeur_cadre_adresse;
                $h_cell = $hauteur_cadre_adresse;
                if ($tab_modele_pdf["cadre_adresse"][$classe_id] != 0) {
                    $bordure_cadre_adresse_resp = 'LRBT';
                } else {
                    $bordure_cadre_adresse_resp = '';
                }
                cell_ajustee($texte, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, $bordure_cadre_adresse_resp, 'C', 'L', 0.3, 1);
            }
        }
        // ============= FIN BLOC ADRESSE PARENTS ==========================
        //=========================================
        // ============= DEBUT BLOC ELEVE ==========================
        // Bloc affichage information sur l'élève
        if ($tab_modele_pdf["active_bloc_eleve"][$classe_id] === '1') {
            $pdf->SetXY($tab_modele_pdf["X_eleve"][$classe_id], $tab_modele_pdf["Y_eleve"][$classe_id]);
            // définition des Lageur - hauteur
            if ($tab_modele_pdf["largeur_bloc_eleve"][$classe_id] != '' and $tab_modele_pdf["largeur_bloc_eleve"][$classe_id] != '0') {
                $longeur_cadre_eleve = $tab_modele_pdf["largeur_bloc_eleve"][$classe_id];
            } else {
                $longeur_cadre_eleve = $pdf->GetStringWidth($tab_bull['eleve'][$i]['nom'] . " " . $tab_bull['eleve'][$i]['prenom']);
                $rajout_cadre_eleve = 100 - $longeur_cadre_eleve;
                $longeur_cadre_eleve = $longeur_cadre_eleve + $rajout_cadre_eleve;
            }
            if ($tab_modele_pdf["hauteur_bloc_eleve"][$classe_id] != '' and $tab_modele_pdf["hauteur_bloc_eleve"][$classe_id] != '0') {
                $hauteur_cadre_eleve = $tab_modele_pdf["hauteur_bloc_eleve"][$classe_id];
            } else {
                $nb_ligne = 5;
                $hauteur_ligne = 6;
                $hauteur_cadre_eleve = $nb_ligne * $hauteur_ligne;
            }
            $pdf->SetFont('DejaVu', 'B', 14);
            if ($tab_modele_pdf["cadre_eleve"][$classe_id] != 0) {
                $pdf->Rect($tab_modele_pdf["X_eleve"][$classe_id], $tab_modele_pdf["Y_eleve"][$classe_id], $longeur_cadre_eleve, $hauteur_cadre_eleve, 'D');
            }
            $X_eleve_2 = $tab_modele_pdf["X_eleve"][$classe_id];
            $Y_eleve_2 = $tab_modele_pdf["Y_eleve"][$classe_id];
            //photo de l'élève
            if (!isset($tab_modele_pdf["ajout_cadre_blanc_photo"][$classe_id]) or empty($tab_modele_pdf["ajout_cadre_blanc_photo"][$classe_id])) {
                $tab_modele_pdf["ajout_cadre_blanc_photo"][$classe_id] = '0';
            }
            if ($tab_modele_pdf["ajout_cadre_blanc_photo"][$classe_id] === '1') {
                $ajouter = '1';
            } else {
                $ajouter = '0';
            }
            $photo[$i] = nom_photo($tab_bull['eleve'][$i]['elenoet']);
            if ($tab_modele_pdf["active_photo"][$classe_id] === '1' and $photo[$i] != '' and file_exists($photo[$i])) {
                $L_photo_max = ($hauteur_cadre_eleve - $ajouter * 2) * 2.8;
                $H_photo_max = ($hauteur_cadre_eleve - $ajouter * 2) * 2.8;
                $valeur = redimensionne_image($photo[$i], $L_photo_max, $H_photo_max);
                $X_photo = $tab_modele_pdf["X_eleve"][$classe_id] + 0.2 + $ajouter;
                $Y_photo = $tab_modele_pdf["Y_eleve"][$classe_id] + 0.25 + $ajouter;
                $L_photo = $valeur[0];
                $H_photo = $valeur[1];
                $X_eleve_2 = $tab_modele_pdf["X_eleve"][$classe_id] + $L_photo + $ajouter + 1;
                $Y_eleve_2 = $Y_photo;
                // Seules les images JPEG ont l'air acceptées... et on ne peut pas se fier à l'extension...
                $tmp_dim_photo = getimagesize($photo[$i]);
                //if((!isset($tmp_dim_photo['mime']))||(preg_match("/jpeg/i",$tmp_dim_photo['mime']))) {
                if (isset($tmp_dim_photo[2]) && $tmp_dim_photo[2] == 2) {
                    $pdf->Image($photo[$i], $X_photo, $Y_photo, $L_photo, $H_photo);
                    $longeur_cadre_eleve = $longeur_cadre_eleve - ($valeur[0] + $ajouter);
                }
            }
            $pdf->SetXY($X_eleve_2, $Y_eleve_2);
            //$pdf->Cell(90,7, ($tab_bull['eleve'][$i]['nom']." ".$tab_bull['eleve'][$i]['prenom']),0,2,'');
            $nom_prenom = affiche_eleve($tab_bull['eleve'][$i]['nom'], $tab_bull['eleve'][$i]['prenom'], $tab_bull['id_classe']);
            $hauteur_caractere_nom_prenom = 14;
            $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_nom_prenom);
            $val = $pdf->GetStringWidth($nom_prenom);
            if ($tab_modele_pdf["active_photo"][$classe_id] === '1' and $photo[$i] != '' and file_exists($photo[$i])) {
                $taille_texte = 90 - $L_photo;
                // Espace max
            } else {
                $taille_texte = 90;
                // Espace max
            }
            if ($taille_texte < 10) {
                $taille_texte = 90;
            }
            // Sécurité pour ne pas risquer une boucle infinie
            $grandeur_texte = 'test';
            while ($grandeur_texte != 'ok') {
                if ($taille_texte < $val) {
                    $hauteur_caractere_nom_prenom = $hauteur_caractere_nom_prenom - 0.3;
                    $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_nom_prenom);
                    $val = $pdf->GetStringWidth($nom_prenom);
                } else {
                    $grandeur_texte = 'ok';
                }
            }
            $grandeur_texte = 'test';
            $pdf->Cell(90, 7, $nom_prenom, 0, 2, '');
            $pdf->SetFont('DejaVu', '', 10);
            if ($tab_modele_pdf["affiche_date_naissance"][$classe_id] === '1') {
                if ($tab_bull['eleve'][$i]['naissance'] != "") {
                    $info_naissance = "Né";
                    if ($tab_bull['eleve'][$i]['sexe'] == "F") {
                        $info_naissance .= "e";
                    }
                    $info_naissance .= " le " . $tab_bull['eleve'][$i]['naissance'];
                    if (getSettingValue('ele_lieu_naissance') == 'y' && $tab_modele_pdf["affiche_lieu_naissance"][$classe_id] === '1') {
                        $info_naissance .= " à " . $tab_bull['eleve'][$i]['lieu_naissance'];
                    }
                    $pdf->Cell(90, 5, $info_naissance, 0, 2, '');
                }
            }
            $rdbt = '';
            if ($tab_modele_pdf["affiche_dp"][$classe_id] === '1') {
                if ($tab_modele_pdf["affiche_doublement"][$classe_id] === '1') {
                    //if($tab_bull['eleve'][$i]['doublant']!="") {
                    if ($tab_bull['eleve'][$i]['doublant'] == "R") {
                        //$rdbt=" ; ".$doublement[$i];
                        //$rdbt=" ; redoublant";
                        $rdbt = "redoublant";
                        if ($tab_bull['eleve'][$i]['sexe'] == "F") {
                            $rdbt .= "e";
                        }
                    }
                    //if(isset($tab_bull['eleve'][$i]['regime'])) {
                    if (isset($tab_bull['eleve'][$i]['regime']) && $tab_bull['eleve'][$i]['regime'] != "") {
                        if ($rdbt == "") {
                            $pdf->Cell(90, 4, regime($tab_bull['eleve'][$i]['regime']), 0, 2, '');
                        } else {
                            $pdf->Cell(90, 4, regime($tab_bull['eleve'][$i]['regime']) . "; " . $rdbt, 0, 2, '');
                        }
                    } else {
                        $pdf->Cell(90, 4, $rdbt, 0, 2, '');
                    }
                }
            } else {
                if ($tab_modele_pdf["affiche_doublement"][$classe_id] === '1') {
                    //if($tab_bull['eleve'][$i]['doublant']!="") {
                    if ($tab_bull['eleve'][$i]['doublant'] == "R") {
                        //$pdf->Cell(90,4.5, $doublement[$i],0,2,'');
                        //$rdbt=" ; redoublant";
                        $rdbt = "redoublant";
                        if ($tab_bull['eleve'][$i]['sexe'] == "F") {
                            $rdbt .= "e";
                        }
                        $pdf->Cell(90, 4.5, $rdbt, 0, 2, '');
                    }
                }
            }
            // affiche le nom court de la classe
            if ($tab_modele_pdf["affiche_nom_court"][$classe_id] === '1') {
                if ($tab_bull['eleve'][$i]['classe'] != "") {
                    // si l'affichage du numéro INE est activé alors on ne passe pas
                    $passe_a_la_ligne = 0;
                    //if ( $tab_modele_pdf["affiche_ine"][$classe_id] != '1' or $tab_modele_pdf["INE_eleve"][$i] == '' )
                    if ($tab_modele_pdf["affiche_ine"][$classe_id] != '1' or $tab_bull['eleve'][$i]['no_gep'] == '') {
                        $passe_a_la_ligne = 1;
                    }
                    $pdf->Cell(45, 4.5, unhtmlentities($tab_bull['eleve'][$i]['classe']), 0, $passe_a_la_ligne, '');
                }
            }
            // affiche l'INE de l'élève
            if ($tab_modele_pdf["affiche_ine"][$classe_id] === '1') {
                if ($tab_bull['eleve'][$i]['no_gep'] != '') {
                    $pdf->Cell(45, 4.5, 'INE: ' . $tab_bull['eleve'][$i]['no_gep'], 0, 1, '');
                }
            }
            // Affichage du numéro d'impression
            $pdf->SetX($X_eleve_2);
            if ($tab_modele_pdf["affiche_effectif_classe"][$classe_id] === '1') {
                if ($tab_modele_pdf["affiche_numero_impression"][$classe_id] === '1') {
                    $pass_ligne = '0';
                } else {
                    $pass_ligne = '2';
                }
                if ($tab_bull['eff_classe'] != "") {
                    $pdf->Cell(45, 4.5, 'Effectif : ' . $tab_bull['eff_classe'] . ' élèves', 0, $pass_ligne, '');
                }
            }
            if ($tab_modele_pdf["affiche_numero_impression"][$classe_id] === '1') {
                //+++++++++++++++++++
                //+++++++++++++++++++
                // A VOIR... CE $i...
                // Si on n'imprime que certains bulletins, on récupère le numéro d'ordre (alphabétique) de l'élève dans la classe.
                //+++++++++++++++++++
                //+++++++++++++++++++
                //$num_ordre = $i;
                $num_ordre = $i + 1;
                $pdf->Cell(45, 4, 'Bulletin N° ' . $num_ordre, 0, 2, '');
            }
            // Affichage de l'établissement d'origine
            // On n'affiche pas l'établissement d'origine si c'est le même que l'établissement actuel: $RneEtablissement
            //if($tab_modele_pdf["affiche_etab_origine"][$classe_id]==='1' and !empty($etablissement_origine[$i]) ) {
            //if($tab_modele_pdf["affiche_etab_origine"][$classe_id]==='1' and isset($tab_bull['eleve'][$i]['etab_id']) and !empty($tab_bull['eleve'][$i]['etab_id']) ) {
            if ($tab_modele_pdf["affiche_etab_origine"][$classe_id] === '1' && isset($tab_bull['eleve'][$i]['etab_id']) && !empty($tab_bull['eleve'][$i]['etab_id']) && my_strtolower($tab_bull['eleve'][$i]['etab_id']) != my_strtolower($RneEtablissement)) {
                $pdf->SetX($X_eleve_2);
                $hauteur_caractere_etaborigine = '10';
                $pdf->SetFont('DejaVu', '', $hauteur_caractere_etaborigine);
                $chaine_etab_origine = 'Etab. Origine : ' . $tab_bull['eleve'][$i]['etab_niveau_nom'] . " " . $tab_bull['eleve'][$i]['etab_nom'] . " (" . $tab_bull['eleve'][$i]['etab_ville'] . ")";
                //$chaine_etab_origine='Etab. Origine : '.$tab_bull['eleve'][$i]['etab_niveau_nom']." ".$tab_bull['eleve'][$i]['etab_type'].." ".$tab_bull['eleve'][$i]['etab_nom']." (".$tab_bull['eleve'][$i]['etab_ville'].")";
                $val = $pdf->GetStringWidth($chaine_etab_origine);
                $taille_texte = $longeur_cadre_eleve - 3;
                $grandeur_texte = 'test';
                while ($grandeur_texte != 'ok') {
                    if ($taille_texte < $val) {
                        $hauteur_caractere_etaborigine = $hauteur_caractere_etaborigine - 0.3;
                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_etaborigine);
                        $val = $pdf->GetStringWidth($chaine_etab_origine);
                    } else {
                        $grandeur_texte = 'ok';
                    }
                }
                $grandeur_texte = 'test';
                $pdf->Cell(90, 4, $chaine_etab_origine, 0, 2);
                $pdf->SetFont('DejaVu', '', 10);
            }
        }
        // fin du bloc affichage information sur l'élèves
        // ============= FIN BLOC ELEVE ==========================
        //=========================================
        // ============= DEBUT BLOC CLASSE/PERIODE/DATATION ==========================
        // Bloc affichage datation du bulletin:
        // Classe, période,...
        if ($tab_modele_pdf["active_bloc_datation"][$classe_id] === '1') {
            $pdf->SetXY($tab_modele_pdf["X_datation_bul"][$classe_id], $tab_modele_pdf["Y_datation_bul"][$classe_id]);
            // définition des Largeur - hauteur
            if ($tab_modele_pdf["largeur_bloc_datation"][$classe_id] != '' and $tab_modele_pdf["largeur_bloc_datation"][$classe_id] != '0') {
                $longeur_cadre_datation_bul = $tab_modele_pdf["largeur_bloc_datation"][$classe_id];
            } else {
                $longeur_cadre_datation_bul = '95';
            }
            if ($tab_modele_pdf["hauteur_bloc_datation"][$classe_id] != '' and $tab_modele_pdf["hauteur_bloc_datation"][$classe_id] != '0') {
                $hauteur_cadre_datation_bul = $tab_modele_pdf["hauteur_bloc_datation"][$classe_id];
            } else {
                $nb_ligne_datation_bul = 3;
                $hauteur_ligne_datation_bul = 6;
                $hauteur_cadre_datation_bul = $nb_ligne_datation_bul * $hauteur_ligne_datation_bul;
            }
            if ($tab_modele_pdf["cadre_datation_bul"][$classe_id] != 0) {
                $pdf->Rect($tab_modele_pdf["X_datation_bul"][$classe_id], $tab_modele_pdf["Y_datation_bul"][$classe_id], $longeur_cadre_datation_bul, $hauteur_cadre_datation_bul, 'D');
            }
            $taille_texte = '14';
            $type_texte = 'B';
            if ($tab_modele_pdf["taille_texte_classe"][$classe_id] != '' and $tab_modele_pdf["taille_texte_classe"][$classe_id] != '0') {
                $taille_texte = $tab_modele_pdf["taille_texte_classe"][$classe_id];
            } else {
                $taille_texte = '14';
            }
            if ($tab_modele_pdf["type_texte_classe"][$classe_id] != '') {
                if ($tab_modele_pdf["type_texte_classe"][$classe_id] === 'N') {
                    $type_texte = '';
                } else {
                    $type_texte = $tab_modele_pdf["type_texte_classe"][$classe_id];
                }
            } else {
                $type_texte = 'B';
            }
            $pdf->SetFont('DejaVu', $type_texte, $taille_texte);
            $pdf->Cell(90, 7, "Classe de " . unhtmlentities($tab_bull['classe_nom_complet']), 0, 2, 'C');
            $taille_texte = '12';
            $type_texte = '';
            if ($tab_modele_pdf["taille_texte_annee"][$classe_id] != '' and $tab_modele_pdf["taille_texte_annee"][$classe_id] != '0') {
                $taille_texte = $tab_modele_pdf["taille_texte_annee"][$classe_id];
            } else {
                $taille_texte = '12';
            }
            if ($tab_modele_pdf["type_texte_annee"][$classe_id] != '') {
                if ($tab_modele_pdf["type_texte_annee"][$classe_id] === 'N') {
                    $type_texte = '';
                } else {
                    $type_texte = $tab_modele_pdf["type_texte_annee"][$classe_id];
                }
            } else {
                $type_texte = '';
            }
            $pdf->SetFont('DejaVu', $type_texte, $taille_texte);
            $annee_scolaire = $gepiYear;
            $pdf->Cell(90, 5, "Année scolaire " . $annee_scolaire, 0, 2, 'C');
            $taille_texte = '10';
            $type_texte = '';
            if ($tab_modele_pdf["taille_texte_periode"][$classe_id] != '' and $tab_modele_pdf["taille_texte_periode"][$classe_id] != '0') {
                $taille_texte = $tab_modele_pdf["taille_texte_periode"][$classe_id];
            } else {
                $taille_texte = '10';
            }
            if ($tab_modele_pdf["type_texte_periode"][$classe_id] != '') {
                if ($tab_modele_pdf["type_texte_periode"][$classe_id] === 'N') {
                    $type_texte = '';
                } else {
                    $type_texte = $tab_modele_pdf["type_texte_periode"][$classe_id];
                }
            } else {
                $type_texte = '';
            }
            $pdf->SetFont('DejaVu', $type_texte, $taille_texte);
            $pdf->Cell(90, 5, $tab_bull['bull_prefixe_periode'] . unhtmlentities($tab_bull['nom_periode']), 0, 2, 'C');
            $taille_texte = '8';
            $type_texte = '';
            if ($tab_modele_pdf["affiche_date_edition"][$classe_id] === '1') {
                if ($tab_modele_pdf["taille_texte_date_edition"][$classe_id] != '' and $tab_modele_pdf["taille_texte_date_edition"][$classe_id] != '0') {
                    $taille_texte = $tab_modele_pdf["taille_texte_date_edition"][$classe_id];
                } else {
                    $taille_texte = '8';
                }
                if ($tab_modele_pdf["type_texte_date_datation"][$classe_id] != '') {
                    if ($tab_modele_pdf["type_texte_date_datation"][$classe_id] === 'N') {
                        $type_texte = '';
                    } else {
                        $type_texte = $tab_modele_pdf["type_texte_date_datation"][$classe_id];
                    }
                } else {
                    $type_texte = '';
                }
                $pdf->SetFont('DejaVu', $type_texte, $taille_texte);
                $pdf->Cell(95, 7, $date_bulletin, 0, 2, 'R');
            }
            $pdf->SetFont('DejaVu', '', 10);
        }
        // ============= FIN BLOC CLASSE/PERIODE/DATATION ==========================
        //=========================================
        // ============= DEBUT BLOC NOTES ET APPRECIATIONS ==========================
        // Bloc notes et appréciations
        // 20130927
        if (!isset($tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id]) || !is_numeric($tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id]) || $tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id] <= 0) {
            $tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id] = 3;
        }
        //nombre de matieres à afficher
        //$nb_matiere = $info_bulletin[$ident_eleve_aff][$id_periode]['nb_matiere'];
        $nb_matiere = 0;
        //$fich=fopen("/tmp/infos_matieres_eleve.txt","a+");
        //fwrite($fich,"\$tab_bull['eleve'][$i]['nom']=".$tab_bull['eleve'][$i]['nom']."\n");
        for ($j = 0; $j < count($tab_bull['groupe']); $j++) {
            if (isset($tab_bull['note'][$j][$i])) {
                // Si l'élève suit l'option, sa note est affectée (éventuellement vide)
                //fwrite($fich,"\$tab_bull['groupe'][$j]['matiere']['matiere']=".$tab_bull['groupe'][$j]['matiere']['matiere']." ");
                //fwrite($fich,"\$tab_bull['note'][$j][$i]=".$tab_bull['note'][$j][$i]."\n");
                $nb_matiere++;
                // Si les catégories doivent être affichées, il faut réordonner les matières pour ne pas avoir:
                //     LIT
                //     SCI
                //     AUT
                //     LIT à nouveau
                // Sinon, les calculs de hauteur sont faussés et ça ne permet pas d'avoir des ordres très différents avec et sans catégories
                // Il vaudrait mieux refaire ce tri au départ, avant d'être dans les boucles élèves
            }
        }
        if (isset($tab_bull['eleve'][$i]['aid_b'])) {
            $nb_matiere += count($tab_bull['eleve'][$i]['aid_b']);
        }
        if (isset($tab_bull['eleve'][$i]['aid_e'])) {
            $nb_matiere += count($tab_bull['eleve'][$i]['aid_e']);
        }
        //fclose($fich);
        /*
        //++++++++++++++++
        // Pour debug:
        $pdf->SetXY(100, 25);
        $pdf->SetFont('DejaVu','',10);
        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], 8, "nb_matiere=$nb_matiere",1,0,'C');
        //++++++++++++++++
        */
        if ($tab_modele_pdf["active_bloc_note_appreciation"][$classe_id] === '1' and $nb_matiere != '0') {
            $pdf->Rect($tab_modele_pdf["X_note_app"][$classe_id], $tab_modele_pdf["Y_note_app"][$classe_id], $tab_modele_pdf["longeur_note_app"][$classe_id], $tab_modele_pdf["hauteur_note_app"][$classe_id], 'D');
            //entête du tableau des notes et app
            $nb_entete_moyenne = $tab_modele_pdf["active_moyenne_eleve"][$classe_id] + $tab_modele_pdf["active_moyenne_classe"][$classe_id] + $tab_modele_pdf["active_moyenne_min"][$classe_id] + $tab_modele_pdf["active_moyenne_max"][$classe_id];
            //min max classe eleve
            $hauteur_entete = 8;
            $hauteur_entete_pardeux = $hauteur_entete / 2;
            $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id], $tab_modele_pdf["Y_note_app"][$classe_id]);
            $pdf->SetFont('DejaVu', '', 10);
            $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $hauteur_entete, $tab_modele_pdf["titre_entete_matiere"][$classe_id], 1, 0, 'C');
            $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
            // coefficient matière
            if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id]);
                $pdf->SetFont('DejaVu', '', 8);
                $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $hauteur_entete, $tab_modele_pdf["titre_entete_coef"][$classe_id], 'LRB', 0, 'C');
                $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
            }
            // nombre de notes
            // 20081118
            //if($tab_modele_pdf["active_nombre_note_case"][$classe_id]==='1') {
            if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id]);
                $pdf->SetFont('DejaVu', '', 8);
                $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $hauteur_entete, $tab_modele_pdf["titre_entete_nbnote"][$classe_id], 'LRB', 0, 'C');
                $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
            }
            // Pour forcer la valeur à tester (lors de l'ajout d'un mode):
            //$tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id]='7';
            // eleve | min | classe | max | rang | niveau | appreciation |
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '1') {
                $ordre_moyenne[0] = 'eleve';
                $ordre_moyenne[1] = 'min';
                $ordre_moyenne[2] = 'classe';
                $ordre_moyenne[3] = 'max';
                $ordre_moyenne[4] = 'rang';
                $ordre_moyenne[5] = 'niveau';
                $ordre_moyenne[6] = 'appreciation';
            }
            // min | classe | max | eleve | niveau | rang | appreciation |
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '2') {
                $ordre_moyenne[0] = 'min';
                $ordre_moyenne[1] = 'classe';
                $ordre_moyenne[2] = 'max';
                $ordre_moyenne[3] = 'eleve';
                $ordre_moyenne[4] = 'niveau';
                $ordre_moyenne[5] = 'rang';
                $ordre_moyenne[6] = 'appreciation';
            }
            // eleve | niveau | rang | appreciation | min | classe | max
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '3') {
                $ordre_moyenne[0] = 'eleve';
                $ordre_moyenne[1] = 'niveau';
                $ordre_moyenne[2] = 'rang';
                $ordre_moyenne[3] = 'appreciation';
                $ordre_moyenne[4] = 'min';
                $ordre_moyenne[5] = 'classe';
                $ordre_moyenne[6] = 'max';
            }
            // eleve | classe | min | max | rang | niveau | appreciation |
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '4') {
                $ordre_moyenne[0] = 'eleve';
                $ordre_moyenne[1] = 'classe';
                $ordre_moyenne[2] = 'min';
                $ordre_moyenne[3] = 'max';
                $ordre_moyenne[4] = 'rang';
                $ordre_moyenne[5] = 'niveau';
                $ordre_moyenne[6] = 'appreciation';
            }
            // eleve | min | classe | max | niveau | rang | appreciation |
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '5') {
                $ordre_moyenne[0] = 'eleve';
                $ordre_moyenne[1] = 'min';
                $ordre_moyenne[2] = 'classe';
                $ordre_moyenne[3] = 'max';
                $ordre_moyenne[4] = 'niveau';
                $ordre_moyenne[5] = 'rang';
                $ordre_moyenne[6] = 'appreciation';
            }
            // min | classe | max | eleve | rang | niveau | appreciation |
            //if ( $ordre_entete_model_bulletin[$classe_id] === '6' ) {
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '6') {
                $ordre_moyenne[0] = 'min';
                $ordre_moyenne[1] = 'classe';
                $ordre_moyenne[2] = 'max';
                $ordre_moyenne[3] = 'eleve';
                $ordre_moyenne[4] = 'rang';
                $ordre_moyenne[5] = 'niveau';
                $ordre_moyenne[6] = 'appreciation';
            }
            // appreciation | eleve | rang | niveau | min | classe | max |
            //if ( $ordre_entete_model_bulletin[$classe_id] === '6' ) {
            if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '7') {
                $ordre_moyenne[0] = 'appreciation';
                $ordre_moyenne[1] = 'eleve';
                $ordre_moyenne[2] = 'niveau';
                $ordre_moyenne[3] = 'rang';
                $ordre_moyenne[4] = 'min';
                $ordre_moyenne[5] = 'classe';
                $ordre_moyenne[6] = 'max';
            }
            $cpt_ordre = 0;
            $chapeau_moyenne = 'non';
            while (!empty($ordre_moyenne[$cpt_ordre])) {
                // Je ne saisis pas pourquoi cette variable est initialisée à ce niveau???
                //$categorie_passe_count = 0;
                // le chapeau des moyennes
                $ajout_espace_au_dessus = 4;
                if ($tab_modele_pdf["entete_model_bulletin"][$classe_id] === '1' and $nb_entete_moyenne > 1 and ($ordre_moyenne[$cpt_ordre] === 'classe' or $ordre_moyenne[$cpt_ordre] === 'min' or $ordre_moyenne[$cpt_ordre] === 'max' or $ordre_moyenne[$cpt_ordre] === 'eleve') and $chapeau_moyenne === 'non' and $tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] != '3' and $tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] != '7') {
                    $largeur_moyenne = $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id] * $nb_entete_moyenne;
                    $text_entete_moyenne = 'Moyenne';
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id]);
                    $pdf->Cell($largeur_moyenne, $hauteur_entete_pardeux, $text_entete_moyenne, 1, 0, 'C');
                    $chapeau_moyenne = 'oui';
                }
                //if ( ($tab_modele_pdf["entete_model_bulletin"][$classe_id] === '2' and $nb_entete_moyenne > 1 and ( $ordre_moyenne[$cpt_ordre] === 'classe' or $ordre_moyenne[$cpt_ordre] === 'min' or $ordre_moyenne[$cpt_ordre] === 'max' ) and $chapeau_moyenne === 'non' ) or ( $tab_modele_pdf["entete_model_bulletin"][$classe_id] === '1' and $tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '3' and $chapeau_moyenne === 'non' and ( $ordre_moyenne[$cpt_ordre] === 'classe' or $ordre_moyenne[$cpt_ordre] === 'min' or $ordre_moyenne[$cpt_ordre] === 'max' )  ) )
                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["entete_model_bulletin"][$classe_id] === '2' and $nb_entete_moyenne > 1 and ($ordre_moyenne[$cpt_ordre] === 'classe' or $ordre_moyenne[$cpt_ordre] === 'min' or $ordre_moyenne[$cpt_ordre] === 'max') and $chapeau_moyenne === 'non' or $tab_modele_pdf["entete_model_bulletin"][$classe_id] === '1' and ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '3' or $tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] === '7') and $chapeau_moyenne === 'non' and ($ordre_moyenne[$cpt_ordre] === 'classe' or $ordre_moyenne[$cpt_ordre] === 'min' or $ordre_moyenne[$cpt_ordre] === 'max'))) {
                    $largeur_moyenne = $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id] * ($nb_entete_moyenne - 1);
                    $text_entete_moyenne = 'Pour la classe';
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id]);
                    $hauteur_caractere = 10;
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $val = $pdf->GetStringWidth($text_entete_moyenne);
                    $taille_texte = $largeur_moyenne;
                    $grandeur_texte = 'test';
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_caractere = $hauteur_caractere - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                            $val = $pdf->GetStringWidth($text_entete_moyenne);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $pdf->Cell($largeur_moyenne, $hauteur_entete_pardeux, $text_entete_moyenne, 1, 0, 'C');
                    $chapeau_moyenne = 'oui';
                }
                //eleve
                if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                    $ajout_espace_au_dessus = 4;
                    $hauteur_de_la_cellule = $hauteur_entete_pardeux;
                    if ($tab_modele_pdf["entete_model_bulletin"][$classe_id] === '2' and $tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $nb_entete_moyenne > 1) {
                        $hauteur_de_la_cellule = $hauteur_entete;
                        $ajout_espace_au_dessus = 0;
                    }
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id] + $ajout_espace_au_dessus);
                    $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $hauteur_de_la_cellule, "Elève", 1, 0, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                    $pdf->SetFillColor(0, 0, 0);
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                }
                //classe
                //if($tab_modele_pdf["active_moyenne_classe"][$classe_id]==='1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe' ) {
                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe')) {
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id] + 4);
                    $hauteur_caractere = '8.5';
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $text_moy_classe = 'Classe';
                    if ($tab_modele_pdf["entete_model_bulletin"][$classe_id] === '2') {
                        $text_moy_classe = 'Moy.';
                    }
                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $hauteur_entete_pardeux, $text_moy_classe, 1, 0, 'C');
                    $X_moyenne_classe = $tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise;
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                }
                //min
                //if($tab_modele_pdf["active_moyenne_min"][$classe_id]==='1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min' ) {
                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min')) {
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id] + 4);
                    $hauteur_caractere = '8.5';
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $hauteur_entete_pardeux, "Min.", 1, 0, 'C');
                    $X_min_classe = $tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise;
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                }
                //max
                //if($tab_modele_pdf["active_moyenne_max"][$classe_id]==='1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max' ) {
                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max')) {
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id] + 4);
                    $hauteur_caractere = '8.5';
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $hauteur_entete_pardeux, "Max.", 1, 0, 'C');
                    $X_max_classe = $tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise;
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                }
                $pdf->SetFont('DejaVu', '', 8);
                // rang de l'élève
                if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'rang') {
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id]);
                    $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $hauteur_entete, $tab_modele_pdf["titre_entete_rang"][$classe_id], 'LRB', 0, 'C');
                    //$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $hauteur_entete, $tab_modele_pdf["titre_entete_rang"][$classe_id],'LRB',0,'C');
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                }
                // graphique de niveau
                if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'niveau') {
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id]);
                    $hauteur_caractere = '10';
                    $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                    $pdf->Cell($tab_modele_pdf["largeur_niveau"][$classe_id], $hauteur_entete_pardeux, "Niveau", 'LR', 0, 'C');
                    $pdf->SetXY($tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise, $tab_modele_pdf["Y_note_app"][$classe_id] + 4);
                    $pdf->SetFont('DejaVu', '', 8);
                    $pdf->Cell($tab_modele_pdf["largeur_niveau"][$classe_id], $hauteur_entete_pardeux, "ABC+C-DE", 'LRB', 0, 'C');
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                }
                /*
                $f=fopen("/tmp/largeurs_bull.txt", "a+");
                fwrite($f, "\n");
                fclose($f);
                */
                //appreciation
                $hauteur_caractere = '10';
                $pdf->SetFont('DejaVu', '', $hauteur_caractere);
                if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'appreciation') {
                    $X_col_app = $tab_modele_pdf["X_note_app"][$classe_id] + $largeur_utilise;
                    $pdf->SetXY($X_col_app, $tab_modele_pdf["Y_note_app"][$classe_id]);
                    if (!empty($ordre_moyenne[$cpt_ordre + 1])) {
                        $cpt_ordre_sous = $cpt_ordre + 1;
                        $largeur_appret = 0;
                        while (!empty($ordre_moyenne[$cpt_ordre_sous])) {
                            if ($ordre_moyenne[$cpt_ordre_sous] === 'eleve') {
                                $largeur_appret = $largeur_appret + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre_sous] === 'rang') {
                                $largeur_appret = $largeur_appret + $tab_modele_pdf["largeur_rang"][$classe_id];
                            }
                            if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre_sous] === 'niveau') {
                                $largeur_appret = $largeur_appret + $tab_modele_pdf["largeur_niveau"][$classe_id];
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 and $tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre_sous] === 'min') {
                                $largeur_appret = $largeur_appret + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 and $tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre_sous] === 'classe') {
                                $largeur_appret = $largeur_appret + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 and $tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre_sous] === 'max') {
                                $largeur_appret = $largeur_appret + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            $cpt_ordre_sous = $cpt_ordre_sous + 1;
                        }
                        $largeur_appreciation = $tab_modele_pdf["longeur_note_app"][$classe_id] - $largeur_utilise - $largeur_appret;
                    } else {
                        $largeur_appreciation = $tab_modele_pdf["longeur_note_app"][$classe_id] - $largeur_utilise;
                    }
                    $pdf->SetFont('DejaVu', '', 10);
                    //$titre_entete_appreciation=$bull_intitule_app;
                    $titre_entete_appreciation = $tab_modele_pdf['titre_entete_appreciation'][$classe_id];
                    $pdf->Cell($largeur_appreciation, $hauteur_entete, $titre_entete_appreciation, 'LRB', 0, 'C');
                    $largeur_utilise = $largeur_utilise + $largeur_appreciation;
                }
                $cpt_ordre = $cpt_ordre + 1;
            }
            $largeur_utilise = 0;
            // fin de boucle d'ordre
            //===============================================
            //emplacement des blocs matière et note et appréciation
            //si catégorie activé il faut compter le nombre de catégories
            $nb_categories_select = 0;
            //$categorie_passe_for='';
            if ($tab_modele_pdf["active_regroupement_cote"][$classe_id] === '1' or $tab_modele_pdf["active_entete_regroupement"][$classe_id] === '1') {
                /* A CONVERTIR AVEC $tab_bull
                			for($x=0;$x<$nb_matiere;$x++) {
                				if($matiere[$ident_eleve_aff][$id_periode][$x]['categorie']!=$categorie_passe_for) {
                					$nb_categories_select=$nb_categories_select+1;
                				}
                				$categorie_passe_for=$matiere[$ident_eleve_aff][$id_periode][$x]['categorie'];
                			}
                			*/
                //$nb_categories_select=count($tab_bull['cat_id']);
                $nb_categories_select = count(array_count_values($tab_bull['cat_id']));
            }
            fich_debug_bull("======================\n");
            fich_debug_bull("Elève " . $tab_bull['eleve'][$i]['login'] . "\n");
            fich_debug_bull("\$nb_categories_select={$nb_categories_select}\n");
            //$nb_matiere=count($tab_bull['eleve'][$i][]);
            /*
            $nb_matiere=0;
            for($j=0;$j<count($tab_bull['groupe']);$j++) {
            	if(isset($tab_bull['note'][$j][$i])) {
            		// Si l'élève suit l'option, sa note est affectée (éventuellement vide)
            		$nb_matiere++;
            	}
            }
            */
            $X_bloc_matiere = $tab_modele_pdf["X_note_app"][$classe_id];
            $Y_bloc_matiere = $tab_modele_pdf["Y_note_app"][$classe_id] + $hauteur_entete;
            $longeur_bloc_matiere = $tab_modele_pdf["longeur_note_app"][$classe_id];
            // calcul de la hauteur totale que peut prendre le cadre matière dans sa globalité
            if ($tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne_general"][$classe_id] === '1') {
                // si les moyennes et la moyenne générale sont activées alors on les ajoute à ce qu'il faudra soustraire au cadre global matiere
                $hauteur_toute_entete = $hauteur_entete + $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id];
                if ($affiche_deux_moy_gen == 1) {
                    $hauteur_toute_entete += $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id];
                }
            } else {
                $hauteur_toute_entete = $hauteur_entete;
            }
            $hauteur_bloc_matiere = $tab_modele_pdf["hauteur_note_app"][$classe_id] - $hauteur_toute_entete;
            $X_note_moy_app = $tab_modele_pdf["X_note_app"][$classe_id];
            $Y_note_moy_app = $tab_modele_pdf["Y_note_app"][$classe_id] + $tab_modele_pdf["hauteur_note_app"][$classe_id] - $hauteur_entete;
            if ($tab_modele_pdf["active_entete_regroupement"][$classe_id] === '1') {
                $espace_entre_matier = ($hauteur_bloc_matiere - $nb_categories_select * 5) / $nb_matiere;
            } else {
                $espace_entre_matier = $hauteur_bloc_matiere / $nb_matiere;
            }
            fich_debug_bull("\$hauteur_bloc_matiere={$hauteur_bloc_matiere}\n");
            fich_debug_bull("\$nb_matiere={$nb_matiere}\n");
            fich_debug_bull("\$espace_entre_matier={$espace_entre_matier}\n");
            /*
            //++++++++++++++++
            // Pour debug:
            $pdf->SetXY(100, 30);
            $pdf->SetFont('DejaVu','',10);
            $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], 8, "espace_entre_matier=$espace_entre_matier",1,0,'C');
            //++++++++++++++++
            */
            $pdf->SetXY($X_bloc_matiere, $Y_bloc_matiere);
            $Y_decal = $Y_bloc_matiere;
            fich_debug_bull("Avant les AID_B: \$Y_decal={$Y_decal}\n");
            //======================================================
            // DEBUT DES AID AFFICHéS AVANT LES MATIERES
            if (isset($tab_bull['eleve'][$i]['aid_b'])) {
                //echo "count(\$tab_bull['eleve'][$i]['aid_b']=".count($tab_bull['eleve'][$i]['aid_b'])."<br />";
                for ($m = 0; $m < count($tab_bull['eleve'][$i]['aid_b']); $m++) {
                    $pdf->SetXY($X_bloc_matiere, $Y_decal);
                    // Si c'est une matière suivie par l'élève
                    //if(isset($tab_bull['eleve'][$i]['note'][$m][$i])) {
                    // calcul la taille du titre de la matière
                    $hauteur_caractere_matiere = 10;
                    if ($tab_modele_pdf["taille_texte_matiere"][$classe_id] != '' and $tab_modele_pdf["taille_texte_matiere"][$classe_id] != '0' and $tab_modele_pdf["taille_texte_matiere"][$classe_id] < '11') {
                        $hauteur_caractere_matiere = $tab_modele_pdf["taille_texte_matiere"][$classe_id];
                    }
                    $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_matiere);
                    // Pour parer au bug sur la suppression de matière alors que des groupes sont conservés:
                    if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['nom_complet'])) {
                        $info_nom_matiere = $tab_bull['eleve'][$i]['aid_b'][$m]['nom_complet'];
                    } else {
                        $info_nom_matiere = $tab_bull['eleve'][$i]['aid_b'][$m]['nom'];
                    }
                    // 20130927 : cell_ajustee() ou pas sur le nom de matière/enseignement
                    if (isset($tab_modele_pdf["cell_ajustee_texte_matiere"][$classe_id]) && $tab_modele_pdf["cell_ajustee_texte_matiere"][$classe_id] == 1) {
                        // Encadrement
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier, "", 'LRBT', 1, 'L');
                        // cell_ajustee() ne centre pas verticalement le texte.
                        // On met un décalage pour ne pas coller le texte à la bordure
                        $Y_decal_cell_ajustee = 1;
                        // On repositionne et on inscrit le nom de matière sur la moitié de la hauteur de la cellule
                        $pdf->SetXY($X_bloc_matiere, $Y_decal + $Y_decal_cell_ajustee);
                        $texte = $info_nom_matiere;
                        $taille_max_police = $hauteur_caractere_matiere;
                        $taille_min_police = ceil($taille_max_police / $tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id]);
                        $largeur_dispo = $tab_modele_pdf["largeur_matiere"][$classe_id] - 2;
                        $h_cell = $espace_entre_matier / 2 - $Y_decal_cell_ajustee;
                        cell_ajustee("<b>" . $texte . "</b>", $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
                    } else {
                        $val = $pdf->GetStringWidth($info_nom_matiere);
                        $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id] - 2;
                        $grandeur_texte = 'test';
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $val) {
                                $hauteur_caractere_matiere = $hauteur_caractere_matiere - 0.3;
                                $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_matiere);
                                $val = $pdf->GetStringWidth($info_nom_matiere);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        $grandeur_texte = 'test';
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier / 2, $info_nom_matiere, 'LR', 1, 'L');
                    }
                    // On note l'ordonnée pour le nom des professeurs
                    $Y_decal = $Y_decal + $espace_entre_matier / 2;
                    $pdf->SetXY($X_bloc_matiere, $Y_decal);
                    $pdf->SetFont('DejaVu', '', 8);
                    fich_debug_bull("\$info_nom_matiere={$info_nom_matiere}\n");
                    fich_debug_bull("\$Y_decal={$Y_decal}\n");
                    // nom des professeurs
                    if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['aid_prof_resp_login'][0])) {
                        $nb_prof_matiere = count($tab_bull['eleve'][$i]['aid_b'][$m]['aid_prof_resp_login']);
                        $espace_matiere_prof = $espace_entre_matier / 2;
                        if ($nb_prof_matiere > 0) {
                            $espace_matiere_prof = $espace_matiere_prof / $nb_prof_matiere;
                        }
                        $nb_pass_count = '0';
                        $text_prof = '';
                        while ($nb_prof_matiere > $nb_pass_count) {
                            $tmp_login_prof = $tab_bull['eleve'][$i]['aid_b'][$m]['aid_prof_resp_login'][$nb_pass_count];
                            $text_prof = affiche_utilisateur($tmp_login_prof, $tab_bull['eleve'][$i]['id_classe']);
                            if ($nb_prof_matiere <= 2) {
                                $hauteur_caractere_prof = 8;
                            } elseif ($nb_prof_matiere == 3) {
                                $hauteur_caractere_prof = 5;
                            } elseif ($nb_prof_matiere > 3) {
                                $hauteur_caractere_prof = 2;
                            }
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                            $val = $pdf->GetStringWidth($text_prof);
                            $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id];
                            $grandeur_texte = 'test';
                            while ($grandeur_texte != 'ok') {
                                if ($taille_texte < $val) {
                                    $hauteur_caractere_prof = $hauteur_caractere_prof - 0.3;
                                    $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                                    $val = $pdf->GetStringWidth($text_prof);
                                } else {
                                    $grandeur_texte = 'ok';
                                }
                            }
                            $grandeur_texte = 'test';
                            $pdf->SetX($X_bloc_matiere);
                            if (empty($tab_bull['eleve'][$i]['aid_b'][$m]['aid_prof_resp_login'][$nb_pass_count + 1])) {
                                $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LRB', 1, 'L');
                            }
                            if (!empty($tab_bull['eleve'][$i]['aid_b'][$m]['aid_prof_resp_login'][$nb_pass_count + 1])) {
                                $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LR', 1, 'L');
                            }
                            $nb_pass_count = $nb_pass_count + 1;
                        }
                    }
                    $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
                    // coefficient matière
                    if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                        $pdf->SetFont('DejaVu', '', 10);
                        //$pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $espace_entre_matier, $tab_bull['eleve'][$i]['coef_eleve'][$i][$m],1,0,'C');
                        $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $espace_entre_matier, '', 1, 0, 'C');
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                    }
                    //permet le calcul total des coefficients
                    // if(empty($moyenne_min[$id_classe][$id_periode])) {
                    //$total_coef_en_calcul=$total_coef_en_calcul+$tab_bull['eleve'][$i]['coef_eleve'][$i][$m];
                    //}
                    // nombre de note
                    // 20081118
                    //if($tab_modele_pdf["active_nombre_note_case"][$classe_id]==='1') {
                    if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                        $pdf->SetFont('DejaVu', '', 10);
                        //$valeur = $tab_bull['eleve'][$i]['nbct'][$m][$i] . "/" . $tab_bull['eleve'][$i]['groupe'][$m]['nbct'];
                        $valeur = '';
                        $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $espace_entre_matier, $valeur, 1, 0, 'C');
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
                    }
                    // les moyennes eleve, classe, min, max
                    $cpt_ordre = 0;
                    while (!empty($ordre_moyenne[$cpt_ordre])) {
                        //eleve
                        if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', 'B', 10);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                            // calcul nombre de sous affichage
                            $nb_sousaffichage = '1';
                            //20090908 if(empty($active_coef_sousmoyene)) { $active_coef_sousmoyene = ''; }
                            //if($active_coef_sousmoyene==='1') { $nb_sousaffichage = $nb_sousaffichage + 1; }
                            if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                $nb_sousaffichage = $nb_sousaffichage + 1;
                            }
                            if ($tab_modele_pdf["active_nombre_note"][$classe_id] === '1') {
                                $nb_sousaffichage = $nb_sousaffichage + 1;
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                            }
                            // On filtre si la moyenne est vide, on affiche seulement un tiret
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note'] == "-") {
                                $valeur = "-";
                            } elseif ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_statut'] != "") {
                                if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_statut'] == "other") {
                                    $valeur = "-";
                                } else {
                                    $valeur = $tab_bull['eleve'][$i]['aid_b'][$m]['aid_statut'];
                                }
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, $valeur, 1, 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                            $valeur = "";
                            if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                $pdf->SetFont('DejaVu', 'I', 7);
                                //$pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier/$nb_sousaffichage, 'coef. '.$tab_bull['eleve'][$i]['coef_eleve'][$i][$m],'LR',2,'C',$tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, '', 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                // On affiche toutes les moyennes dans la même colonne
                                $pdf->SetFont('DejaVu', 'I', 7);
                                if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1') {
                                    //if ($tab_bull['eleve'][$i]['moy_classe_grp'][$m]=="-") {
                                    if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_moyenne'] == "-" || $tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_moyenne'] == "") {
                                        $valeur = "-";
                                    } else {
                                        $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_moyenne'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'cla.' . $valeur, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                                if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1') {
                                    //if ($tab_bull['eleve'][$i]['moy_min_classe_grp'][$m]=="-") {
                                    if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_min'] == "-" || $tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_min'] == "") {
                                        $valeur = "-";
                                    } else {
                                        $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_min'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'min.' . $valeur, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                                if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1') {
                                    //if ($tab_bull['eleve'][$i]['moy_max_classe_grp'][$m]=="-") {
                                    if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_max'] == "-" || $tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_max'] == "") {
                                        $valeur = "-";
                                    } else {
                                        $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_max'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'max.' . $valeur, 'LRD', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    $valeur = '';
                                    // on remet à vide.
                                }
                            }
                            if ($tab_modele_pdf["active_nombre_note"][$classe_id] === '1') {
                                $pdf->SetFont('DejaVu', 'I', 7);
                                $espace_pour_nb_note = $espace_entre_matier / $nb_sousaffichage;
                                $espace_pour_nb_note = $espace_pour_nb_note / 2;
                                $valeur1 = '';
                                $valeur2 = '';
                                /*
                                if ($tab_bull['eleve'][$i]['nbct'][$m][$i]!= 0 ) {
                                	$valeur1 = $tab_bull['eleve'][$i]['nbct'][$m][$i].' note';
                                	if($tab_bull['eleve'][$i]['nbct'][$m][$i]>1){$valeur1.='s';}
                                	$valeur2 = 'sur '.$tab_bull['eleve'][$i]['groupe'][$m]['nbct'];
                                }
                                */
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_pour_nb_note, $valeur1, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_pour_nb_note, $valeur2, 'LRB', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $valeur1 = '';
                                $valeur2 = '';
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->SetFillColor(0, 0, 0);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        // Fin affichage élève
                        //classe
                        //if( $tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe' ) {
                        if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe')) {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            //if ($tab_bull['eleve'][$i]['moy_classe_grp'][$m]=="-") {
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_moyenne'] == "-" || $tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_moyenne'] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_moyenne'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //min
                        //if( $tab_modele_pdf["active_moyenne_min"][$classe_id]==='1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min' ) {
                        if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min')) {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 8);
                            //if ($tab_bull['eleve'][$i]['moy_min_classe_grp'][$m]=="-") {
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_min'] == "-" || $tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_min'] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_min'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //max
                        //if( $tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max' ) {
                        if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max')) {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            //if ($tab_bull['eleve'][$i]['moy_max_classe_grp'][$m]== "-") {
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_max'] == "-" || $tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_max'] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note_max'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //$largeur_utilise = $largeur_utilise+$largeur_moyenne;
                        // rang de l'élève
                        if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'rang') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 8);
                            // A REVOIR: J'AI l'EFFECTIF DU GROUPE, mais faut-il compter les élèves ABS, DISP,...?
                            //if((isset($tab_bull['eleve'][$i]['rang'][$i][$m]))&&(isset($tab_bull['eleve'][$i]['groupe'][$m]['effectif']))) {
                            //$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, $tab_bull['eleve'][$i]['rang'][$i][$m].'/'.$tab_bull['eleve'][$i]['groupe'][$m]['effectif'],1,0,'C');
                            //if((isset($tab_bull['eleve'][$i]['rang'][$m][$i]))&&(isset($tab_bull['eleve'][$i]['groupe'][$m]['effectif']))) {
                            //	$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, $tab_bull['eleve'][$i]['rang'][$m][$i].'/'.$tab_bull['eleve'][$i]['groupe'][$m]['effectif_avec_note'],1,0,'C');
                            //}
                            //else {
                            $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, '', 1, 0, 'C');
                            //}
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                        }
                        // graphique de niveau
                        if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'niveau') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 10);
                            //$id_groupe_graph = $tab_bull['eleve'][$i]['groupe'][$m]['id'];
                            // placement de l'élève dans le graphique de niveau
                            // AJOUT: La variable n'était pas initialisée dans le bulletin_pdf_avec_modele...
                            $place_eleve = '';
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['aid_note'] != "") {
                                /*
                                if ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<5) { $place_eleve=5;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=5) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<8))  { $place_eleve=4;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=8) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<10)) { $place_eleve=3;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=10) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<12)) {$place_eleve=2;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=12) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<15)) { $place_eleve=1;}
                                if ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=15) { $place_eleve=0;}
                                */
                                if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['place_eleve'])) {
                                    //$place_eleve=$tab_bull['eleve'][$i]['aid_b'][$m]['place_eleve'];
                                    $place_eleve = $tab_bull['eleve'][$i]['aid_b'][$m]['place_eleve'] - 1;
                                }
                            }
                            $data_grap = array();
                            if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['quartile1_classe'])) {
                                $data_grap[0] = $tab_bull['eleve'][$i]['aid_b'][$m]['quartile1_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['quartile2_classe'])) {
                                $data_grap[1] = $tab_bull['eleve'][$i]['aid_b'][$m]['quartile2_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['quartile3_classe'])) {
                                $data_grap[2] = $tab_bull['eleve'][$i]['aid_b'][$m]['quartile3_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['quartile4_classe'])) {
                                $data_grap[3] = $tab_bull['eleve'][$i]['aid_b'][$m]['quartile4_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['quartile5_classe'])) {
                                $data_grap[4] = $tab_bull['eleve'][$i]['aid_b'][$m]['quartile5_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_b'][$m]['quartile6_classe'])) {
                                $data_grap[5] = $tab_bull['eleve'][$i]['aid_b'][$m]['quartile6_classe'];
                            }
                            //if (array_sum($data_grap[$id_periode][$id_groupe_graph]) != 0) {
                            if (array_sum($data_grap) != 0) {
                                //$pdf->DiagBarre($X_note_moy_app+$largeur_utilise, $Y_decal-($espace_entre_matier/2), $tab_modele_pdf["largeur_niveau"][$classe_id], $espace_entre_matier, $data_grap[$id_periode][$id_groupe_graph], $place_eleve);
                                $pdf->DiagBarre($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2, $tab_modele_pdf["largeur_niveau"][$classe_id], $espace_entre_matier, $data_grap, $place_eleve);
                            }
                            $place_eleve = '';
                            // on vide la variable
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                        }
                        //appréciation
                        if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'appreciation') {
                            // si on autorise l'affichage des sous matière et s'il y en a alors on les affiche
                            //$id_groupe_select = $tab_bull['eleve'][$i]['groupe'][$m]['id'];
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $X_sous_matiere = 0;
                            $largeur_sous_matiere = 0;
                            /*
                            if($tab_modele_pdf["autorise_sous_matiere"][$classe_id]==='1' and !empty($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'])) {
                            	$X_sous_matiere = $X_note_moy_app+$largeur_utilise;
                            	$Y_sous_matiere = $Y_decal-($espace_entre_matier/2);
                            	$n=0;
                            	$largeur_texte_sousmatiere=0; $largeur_sous_matiere=0;
                            	while( !empty($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n]) )
                            	{
                            		$pdf->SetFont('DejaVu','',8);
                            		$largeur_texte_sousmatiere = $pdf->GetStringWidth($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n].': '.$tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_note'][$n]);
                            		if($largeur_sous_matiere<$largeur_texte_sousmatiere) { $largeur_sous_matiere=$largeur_texte_sousmatiere; }
                            		$n = $n + 1;
                            	}
                            	if($largeur_sous_matiere!='0') { $largeur_sous_matiere = $largeur_sous_matiere + 2; }
                            	$n=0;
                            	while( !empty($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n]) )
                            	{
                            		$pdf->SetXY($X_sous_matiere, $Y_sous_matiere);
                            		$pdf->SetFont('DejaVu','',8);
                            		$pdf->Cell($largeur_sous_matiere, $espace_entre_matier/count($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom']), ($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n].': '.$tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_note'][$n]),1,0,'L');
                            		$Y_sous_matiere = $Y_sous_matiere+$espace_entre_matier/count($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom']);
                            		$n = $n + 1;
                            	}
                            	$largeur_utilise = $largeur_utilise+$largeur_sous_matiere;
                            }
                            */
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            // calcul de la taille du texte des appréciation
                            $hauteur_caractere_appreciation = 9;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere_appreciation);
                            //suppression des espace en début et en fin
                            //$app_aff = trim($tab_bull['eleve'][$i]['aid_b'][$m]['aid_appreciation']);
                            $app_aff = "";
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['message'] != '') {
                                $app_aff .= $tab_bull['eleve'][$i]['aid_b'][$m]['message'];
                            }
                            //if($app_aff!='') {$app_aff.=" ";}
                            if ($tab_bull['eleve'][$i]['aid_b'][$m]['display_nom'] == 'y' && $tab_bull['eleve'][$i]['aid_b'][$m]['aid_nom'] != '') {
                                if ($app_aff != '') {
                                    $app_aff .= " ";
                                }
                                $app_aff .= $tab_bull['eleve'][$i]['aid_b'][$m]['aid_nom'];
                            }
                            if ($app_aff != '') {
                                $app_aff .= "\n";
                            }
                            $app_aff .= trim($tab_bull['eleve'][$i]['aid_b'][$m]['aid_appreciation']);
                            fich_debug_bull("__________________________________________\n");
                            fich_debug_bull("{$app_aff}\n");
                            fich_debug_bull("__________________________________________\n");
                            // DEBUT AJUSTEMENT TAILLE APPRECIATION
                            $taille_texte_total = $pdf->GetStringWidth($app_aff);
                            $largeur_appreciation2 = $largeur_appreciation - $largeur_sous_matiere;
                            if ($use_cell_ajustee == "n") {
                                //$taille_texte = (($espace_entre_matier/3)*$largeur_appreciation2);
                                $nb_ligne_app = '2.8';
                                //$nb_ligne_app = '3.8';
                                //$nb_ligne_app = '4.8';
                                $taille_texte_max = $nb_ligne_app * ($largeur_appreciation2 - 4);
                                //$taille_texte_max = $nb_ligne_app * ($largeur_appreciation2);
                                $grandeur_texte = 'test';
                                fich_debug_bull("\$taille_texte_total={$taille_texte_total}\n");
                                fich_debug_bull("\$largeur_appreciation2={$largeur_appreciation2}\n");
                                fich_debug_bull("\$nb_ligne_app={$nb_ligne_app}\n");
                                //fich_debug_bull("\$taille_texte_max = \$nb_ligne_app * (\$largeur_appreciation2-4)=$nb_ligne_app * ($largeur_appreciation2-4)=$taille_texte_max\n");
                                fich_debug_bull("\$taille_texte_max = \$nb_ligne_app * (\$largeur_appreciation2)={$nb_ligne_app} * ({$largeur_appreciation2})={$taille_texte_max}\n");
                                while ($grandeur_texte != 'ok') {
                                    if ($taille_texte_max < $taille_texte_total) {
                                        $hauteur_caractere_appreciation = $hauteur_caractere_appreciation - 0.3;
                                        //$hauteur_caractere_appreciation = $hauteur_caractere_appreciation-0.1;
                                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_appreciation);
                                        $taille_texte_total = $pdf->GetStringWidth($app_aff);
                                    } else {
                                        $grandeur_texte = 'ok';
                                    }
                                }
                                $grandeur_texte = 'test';
                                $pdf->drawTextBox($app_aff, $largeur_appreciation2, $espace_entre_matier, 'J', 'M', 1);
                            } else {
                                //$texte="Bla bla\nbli ".$app_aff;
                                $texte = $app_aff;
                                $taille_max_police = $hauteur_caractere_appreciation;
                                $taille_min_police = ceil($taille_max_police / 3);
                                $largeur_dispo = $largeur_appreciation2;
                                $h_cell = $espace_entre_matier;
                                if (getSettingValue('suppr_balises_app_prof') == 'y') {
                                    $texte = preg_replace('/<(.*)>/U', '', $texte);
                                }
                                cell_ajustee($texte, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, 'LRBT');
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            $largeur_utilise = $largeur_utilise + $largeur_appreciation2;
                            //$largeur_utilise = 0;
                        }
                        $cpt_ordre = $cpt_ordre + 1;
                    }
                    $largeur_utilise = 0;
                    // fin de boucle d'ordre
                    $Y_decal = $Y_decal + $espace_entre_matier / 2;
                    //}
                }
            }
            // FIN DES AID AFFICHéS AVANT LES MATIERES
            //======================================================
            fich_debug_bull("Apres les AID_B: \$Y_decal={$Y_decal}\n");
            // Compteur du nombre de matières dans la catégorie
            $categorie_passe_count = 0;
            //for($m=0; $m<$nb_matiere; $m++)
            for ($m = 0; $m < count($tab_bull['groupe']); $m++) {
                $pdf->SetXY($X_bloc_matiere, $Y_decal);
                fich_debug_bull("\n");
                fich_debug_bull("Catégorie précédente: \$categorie_passe={$categorie_passe}\n");
                //fich_debug_bull("Catégorie courante :  \$tab_bull['nom_cat_complet'][$m]=".$tab_bull['nom_cat_complet'][$m]."\n");
                if (isset($tab_bull['nom_cat_complet'][$m])) {
                    fich_debug_bull("Catégorie courante :  \$tab_bull['nom_cat_complet'][{$m}]=" . $tab_bull['nom_cat_complet'][$m] . "\n");
                } else {
                    fich_debug_bull("Catégorie courante :  \$tab_bull['nom_cat_complet'][{$m}] non affectée.\n");
                }
                fich_debug_bull("\$tab_bull['groupe'][{$m}]['matiere']['matiere']=" . $tab_bull['groupe'][$m]['matiere']['matiere'] . "\n");
                fich_debug_bull("\$X_bloc_matiere={$X_bloc_matiere}\n");
                fich_debug_bull("\$Y_decal={$Y_decal}\n");
                // si on affiche les catégories
                if ($tab_modele_pdf["active_entete_regroupement"][$classe_id] === '1') {
                    //si on affiche les moyennes des catégories
                    //if($matiere[$ident_eleve_aff][$id_periode][$m]['categorie']!=$categorie_passe)
                    //if($tab_bull['cat_id'][$m]!=$categorie_passe)
                    // Si on change de catégorie
                    // 20141122 : A FAIRE : Il faudrait faire un premier tour des catégories avant pour voir celles qui concernent l'élève
                    if ($tab_bull['nom_cat_complet'][$m] != $categorie_passe) {
                        // Nom de la catégorie dans la première cellule (à l'horizontale)
                        $hauteur_caractere_catego = '10';
                        if ($tab_modele_pdf["taille_texte_categorie"][$classe_id] != '' and $tab_modele_pdf["taille_texte_categorie"][$classe_id] != '0') {
                            $hauteur_caractere_catego = $tab_modele_pdf["taille_texte_categorie"][$classe_id];
                        } else {
                            $hauteur_caractere_catego = '10';
                        }
                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_catego);
                        $tt_catego = unhtmlentities($tab_bull['nom_cat_complet'][$m]);
                        $val = $pdf->GetStringWidth($tt_catego);
                        $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id];
                        $grandeur_texte = 'test';
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $val) {
                                $hauteur_caractere_catego = $hauteur_caractere_catego - 0.3;
                                $pdf->SetFont('DejaVu', '', $hauteur_caractere_catego);
                                $val = $pdf->GetStringWidth($tt_catego);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        $grandeur_texte = 'test';
                        $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                        fich_debug_bull("On écrit {$tt_catego} à \$Y_decal={$Y_decal}\n");
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], unhtmlentities($tt_catego), 'TLB', 0, 'L', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                        $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
                        // coefficient matière (affiché sans bordure gauche/droite)
                        if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal);
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                        }
                        // nombre de notes (affiché sans bordure gauche/droite)
                        if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal);
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
                        }
                        $pdf->SetFillColor(0, 0, 0);
                        if ($tab_modele_pdf["ordre_entete_model_bulletin"][$classe_id] == '7') {
                            $largeur_utilise += $largeur_appreciation;
                        }
                        // les moyennes eleve, classe, min, max par catégorie
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal);
                        $cpt_ordre = 0;
                        $chapeau_moyenne = 'non';
                        while (!empty($ordre_moyenne[$cpt_ordre])) {
                            // Moyenne de l'élève dans la catégorie
                            if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                                $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal);
                                if ($tab_modele_pdf["active_moyenne_regroupement"][$classe_id] === '1') {
                                    //$categorie_passage=$matiere[$ident_eleve_aff][$id_periode][$m]['categorie'];
                                    $categorie_passage = $tab_bull['nom_cat_complet'][$m];
                                    //if($matiere[$ident_eleve_aff][$id_periode][$m]['affiche_moyenne']==='1')
                                    if (isset($tab_bull['moy_cat_eleve'][$i][$tab_bull['cat_id'][$m]])) {
                                        // On va afficher la moyenne de l'élève pour la catégorie
                                        if ($tab_bull['moy_cat_eleve'][$i][$tab_bull['cat_id'][$m]] == "" || $tab_bull['moy_cat_eleve'][$i][$tab_bull['cat_id'][$m]] == "-") {
                                            $valeur = "-";
                                        } else {
                                            //$calcule_moyenne_eleve_categorie[$categorie_passage]=$matiere[$ident_eleve_aff][$id_periode][$categorie_passage]['moy_eleve']/$matiere[$ident_eleve_aff][$id_periode][$categorie_passage]['coef_tt_catego'];
                                            $valeur = present_nombre(preg_replace("/,/", ".", $tab_bull['moy_cat_eleve'][$i][$tab_bull['cat_id'][$m]]), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                            //$valeur =$tab_bull['moy_cat_eleve'][$i][$tab_bull['cat_id'][$m]];
                                        }
                                        $pdf->SetFont('DejaVu', 'B', 8);
                                        $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], $valeur, 1, 0, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                        $pdf->SetFillColor(0, 0, 0);
                                        $valeur = "";
                                    } else {
                                        $pdf->SetFillColor(255, 255, 255);
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'TL', 0, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    }
                                } else {
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C');
                                }
                                $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            // Moyenne de la classe dans la catégorie
                            //if($tab_modele_pdf["active_moyenne_classe"][$classe_id]==='1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe' ) {
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe')) {
                                $pdf->SetXY($X_moyenne_classe, $Y_decal);
                                $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                                if ($tab_modele_pdf["active_moyenne_regroupement"][$classe_id] === '1') {
                                    //$categorie_passage=$matiere[$ident_eleve_aff][$id_periode][$m]['categorie'];
                                    $categorie_passage = $tab_bull['nom_cat_complet'][$m];
                                    //if($matiere[$ident_eleve_aff][$id_periode][$m]['affiche_moyenne']==='1')
                                    if (isset($tab_bull['moy_cat_classe'][$i][$tab_bull['cat_id'][$m]])) {
                                        // On va afficher la moyenne de la classe pour la catégorie
                                        $pdf->SetFont('DejaVu', '', 8);
                                        // 20141122
                                        if ($tab_bull['moy_cat_classe'][$i][$tab_bull['cat_id'][$m]] == "" || $tab_bull['moy_cat_classe'][$i][$tab_bull['cat_id'][$m]] == "-") {
                                            $valeur = "-";
                                        } else {
                                            $valeur = present_nombre($tab_bull['moy_cat_classe'][$i][$tab_bull['cat_id'][$m]], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                        }
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], $valeur, 'TLR', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                    } else {
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                    }
                                } else {
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                }
                                $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            // Moyenne minimale de la classe dans la catégorie
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min')) {
                                $pdf->SetXY($X_min_classe, $Y_decal);
                                $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                                if ($tab_modele_pdf["active_moyenne_regroupement"][$classe_id] === '1') {
                                    $categorie_passage = $tab_bull['nom_cat_complet'][$m];
                                    if (isset($tab_bull['moy_cat_min'][$i][$tab_bull['cat_id'][$m]])) {
                                        // On va afficher la moyenne min de la classe pour la catégorie
                                        $pdf->SetFont('DejaVu', '', 8);
                                        if ($tab_bull['moy_cat_min'][$i][$tab_bull['cat_id'][$m]] == "" || $tab_bull['moy_cat_min'][$i][$tab_bull['cat_id'][$m]] == "-") {
                                            $valeur = "-";
                                        } else {
                                            $calcule_moyenne_classe_categorie[$categorie_passage] = preg_replace("/,/", ".", $tab_bull['moy_cat_min'][$i][$tab_bull['cat_id'][$m]]);
                                            $valeur = present_nombre($calcule_moyenne_classe_categorie[$categorie_passage], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                        }
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], $valeur, 'TLR', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                    } else {
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                    }
                                } else {
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                }
                                $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            // Moyenne maximale de la classe dans la catégorie
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max')) {
                                $pdf->SetXY($X_max_classe, $Y_decal);
                                $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                                if ($tab_modele_pdf["active_moyenne_regroupement"][$classe_id] === '1') {
                                    $categorie_passage = $tab_bull['nom_cat_complet'][$m];
                                    if (isset($tab_bull['moy_cat_max'][$i][$tab_bull['cat_id'][$m]])) {
                                        // On va afficher la moyenne max de la classe pour la catégorie
                                        $pdf->SetFont('DejaVu', '', 8);
                                        if ($tab_bull['moy_cat_max'][$i][$tab_bull['cat_id'][$m]] == "" || $tab_bull['moy_cat_max'][$i][$tab_bull['cat_id'][$m]] == "-") {
                                            $valeur = "-";
                                        } else {
                                            $calcule_moyenne_classe_categorie[$categorie_passage] = preg_replace("/,/", ".", $tab_bull['moy_cat_max'][$i][$tab_bull['cat_id'][$m]]);
                                            $valeur = present_nombre($calcule_moyenne_classe_categorie[$categorie_passage], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                        }
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], $valeur, 'TLR', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                    } else {
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                    }
                                } else {
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                                }
                                $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                            }
                            $cpt_ordre = $cpt_ordre + 1;
                        }
                        //$largeur_utilise = 0;
                        // fin de boucle d'ordre
                        // Rang de l'élève
                        if ($tab_modele_pdf["active_rang"][$classe_id] === '1') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal);
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                            //$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '','T',0,'C');
                            $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                        }
                        // Graphique de niveau
                        if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                            //$pdf->Cell($tab_modele_pdf["largeur_niveau"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '','T',0,'C');
                            $pdf->Cell($tab_modele_pdf["largeur_niveau"][$classe_id], $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'T', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                        }
                        // Appreciation
                        if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1') {
                            // Problème de coordonnées si on met l'appréciation en première position...
                            //$pdf->SetXY($X_note_moy_app+$largeur_utilise, $Y_decal);
                            $pdf->SetXY($X_col_app, $Y_decal);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_entete1"][$classe_id], $tab_modele_pdf["couleur_categorie_entete2"][$classe_id], $tab_modele_pdf["couleur_categorie_entete3"][$classe_id]);
                            $pdf->Cell($largeur_appreciation, $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '', 'TB', 0, 'C', $tab_modele_pdf["couleur_categorie_entete"][$classe_id]);
                            //$pdf->Cell($largeur_appreciation, $tab_modele_pdf["hauteur_info_categorie"][$classe_id], '','TB',0,'C');
                            $largeur_utilise = 0;
                        }
                        $Y_decal = $Y_decal + 5;
                        $pdf->SetFillColor(0, 0, 0);
                    }
                }
                fich_debug_bull("Après les catégories en entête\n");
                fich_debug_bull("\$Y_decal={$Y_decal}\n");
                fich_debug_bull("\$categorie_passe_count={$categorie_passe_count}\n");
                //============================
                // Modif: boireaus 20070828
                if ($tab_modele_pdf["active_regroupement_cote"][$classe_id] === '1' or $tab_modele_pdf["active_entete_regroupement"][$classe_id] === '1') {
                    //if($matiere[$ident_eleve_aff][$id_periode][$m]['categorie']===$categorie_passe) {
                    /*
                    if(isset($tab_bull['note'][$m][$i])) {
                    	if($tab_bull['nom_cat_complet'][$m]===$categorie_passe) {
                    		$categorie_passe_count=$categorie_passe_count+1;
                    	}
                    	else {
                    		$categorie_passe_count=0;
                    	}
                    
                    	//if($matiere[$ident_eleve_aff][$id_periode][$m]['categorie']!=$categorie_passe) {
                    	if($tab_bull['nom_cat_complet'][$m]!=$categorie_passe) {
                    		$categorie_passe_count=$categorie_passe_count+1;
                    	}
                    }
                    */
                    fich_debug_bull("\n");
                    fich_debug_bull("\$tab_bull['nom_cat_complet'][{$m}]=" . $tab_bull['nom_cat_complet'][$m] . "\n");
                    fich_debug_bull("\$categorie_passe={$categorie_passe}\n");
                    if ($tab_bull['nom_cat_complet'][$m] != $categorie_passe) {
                        $categorie_passe_count = 0;
                        $Y_categ_cote = $Y_decal;
                    }
                    /*
                    else {
                    	$categorie_passe_count++;
                    }
                    if(!isset($tab_bull['note'][$m][$i])) {
                    	$categorie_passe_count--;
                    }
                    */
                    if (isset($tab_bull['note'][$m][$i])) {
                        $categorie_passe_count++;
                    }
                    // fin des moyen par catégorie
                }
                fich_debug_bull("Après un test sur le changement de catégorie\n");
                fich_debug_bull("\$categorie_passe_count={$categorie_passe_count}\n");
                //============================
                // si on affiche les catégories sur le côté
                if (!isset($tab_bull['nom_cat_complet'][$m + 1])) {
                    //$matiere[$ident_eleve_aff][$id_periode][$m+1]['categorie']='';
                    $tab_bull['nom_cat_complet'][$m + 1] = '';
                }
                if ($tab_modele_pdf["active_regroupement_cote"][$classe_id] === '1') {
                    // On dessine/écrit la catégorie sur le côté quand la catégorie suivante change
                    if ($tab_bull['nom_cat_complet'][$m] != $tab_bull['nom_cat_complet'][$m + 1] and $categorie_passe != '') {
                        //hauteur du regroupement hauteur des matier * nombre de matier de la catégorie
                        //$hauteur_regroupement=$espace_entre_matier*($categorie_passe_count+1);
                        $hauteur_regroupement = $espace_entre_matier * $categorie_passe_count;
                        fich_debug_bull("\$espace_entre_matier={$espace_entre_matier}\n");
                        fich_debug_bull("\$categorie_passe_count={$categorie_passe_count}\n");
                        fich_debug_bull("\$hauteur_regroupement={$hauteur_regroupement}\n");
                        //placement du cadre
                        //if($nb_eleve_aff===0) { $enplus = 5; }
                        //if($nb_eleve_aff!=0) { $enplus = 0; }
                        //if($compteur_bulletins===0) { $enplus = 5; }
                        //if($compteur_bulletins!=0) { $enplus = 0; }
                        fich_debug_bull("Position du cadre {$categorie_passe}\n");
                        $tmp_val = $Y_decal - $hauteur_regroupement + $espace_entre_matier;
                        fich_debug_bull("\$Y_decal-\$hauteur_regroupement+\$espace_entre_matier=" . $Y_decal . "-" . $hauteur_regroupement . "+" . $espace_entre_matier . "=" . $tmp_val . "\n");
                        //$pdf->SetXY($X_bloc_matiere-5,$Y_decal-$hauteur_regroupement+$espace_entre_matier);
                        $pdf->SetXY($X_bloc_matiere - 5, $Y_categ_cote);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_categorie_cote1"][$classe_id], $tab_modele_pdf["couleur_categorie_cote2"][$classe_id], $tab_modele_pdf["couleur_categorie_cote3"][$classe_id]);
                        if ($tab_modele_pdf["couleur_categorie_cote"][$classe_id] === '1') {
                            $mode_choix_c = '2';
                        } else {
                            $mode_choix_c = '1';
                        }
                        $pdf->drawTextBox("", 5, $hauteur_regroupement, 'C', 'T', $mode_choix_c);
                        //texte à afficher
                        $hauteur_caractere_vertical = '8';
                        if ($tab_modele_pdf["taille_texte_categorie_cote"][$classe_id] != '' and $tab_modele_pdf["taille_texte_categorie_cote"][$classe_id] != '0') {
                            $hauteur_caractere_vertical = $tab_modele_pdf["taille_texte_categorie_cote"][$classe_id];
                        } else {
                            $hauteur_caractere_vertical = '8';
                        }
                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_vertical);
                        $text_s = unhtmlentities($tab_bull['nom_cat_complet'][$m]);
                        //$text_s = $tab_bull['nom_cat_complet'][$m];
                        $longeur_test_s = $pdf->GetStringWidth($text_s);
                        // gestion de la taille du texte vertical
                        $taille_texte = $hauteur_regroupement;
                        $grandeur_texte = 'test';
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $longeur_test_s) {
                                $hauteur_caractere_vertical = $hauteur_caractere_vertical - 0.3;
                                $pdf->SetFont('DejaVu', '', $hauteur_caractere_vertical);
                                $longeur_test_s = $pdf->GetStringWidth($text_s);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        //décalage pour centrer le texte
                        $deca = ($hauteur_regroupement - $longeur_test_s) / 2;
                        //place le texte dans le cadre
                        //$placement = $Y_decal+$espace_entre_matier-$deca;
                        $placement = $Y_categ_cote + $hauteur_regroupement - $deca;
                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_vertical);
                        //$pdf->TextWithDirection($X_bloc_matiere-1,$placement,(unhtmlentities($text_s)),'U');
                        $pdf->TextWithDirection($X_bloc_matiere - 1, $placement, $text_s, 'U');
                        $pdf->SetFont('DejaVu', '', 10);
                        $pdf->SetFillColor(0, 0, 0);
                    }
                }
                fich_debug_bull("Après les catégories sur le côté\n");
                fich_debug_bull("\$Y_decal={$Y_decal}\n");
                if ($tab_modele_pdf["active_regroupement_cote"][$classe_id] === '1' or $tab_modele_pdf["active_entete_regroupement"][$classe_id] === '1') {
                    // fin d'affichage catégorie sur le coté
                    $categorie_passe = $tab_bull['nom_cat_complet'][$m];
                    // fin de gestion de catégorie
                }
                //============================
                // Lignes de Matière, Note, Rang,... Appréciation
                fich_debug_bull("Avant isset(\$tab_bull['note'][{$m}][{$i}]: \$Y_decal={$Y_decal}\n");
                $pdf->SetXY($X_bloc_matiere, $Y_decal);
                // Si c'est une matière suivie par l'élève
                if (isset($tab_bull['note'][$m][$i])) {
                    //echo "\$tab_bull['eleve'][$i]['nom']=".$tab_bull['eleve'][$i]['nom']."<br />\n";
                    // calcul la taille du titre de la matière
                    $hauteur_caractere_matiere = 10;
                    if ($tab_modele_pdf["taille_texte_matiere"][$classe_id] != '' and $tab_modele_pdf["taille_texte_matiere"][$classe_id] != '0' and $tab_modele_pdf["taille_texte_matiere"][$classe_id] < '11') {
                        $hauteur_caractere_matiere = $tab_modele_pdf["taille_texte_matiere"][$classe_id];
                    }
                    $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_matiere);
                    if (getSettingValue('bul_rel_nom_matieres') == 'nom_groupe') {
                        $info_nom_matiere = $tab_bull['groupe'][$m]['name'];
                    } elseif (getSettingValue('bul_rel_nom_matieres') == 'description_groupe') {
                        $info_nom_matiere = $tab_bull['groupe'][$m]['description'];
                    } else {
                        // Pour parer au bug sur la suppression de matière alors que des groupes sont conservés:
                        if (isset($tab_bull['groupe'][$m]['matiere']['nom_complet'])) {
                            $info_nom_matiere = $tab_bull['groupe'][$m]['matiere']['nom_complet'];
                        } else {
                            $info_nom_matiere = $tab_bull['groupe'][$m]['name'] . " (" . $tab_bull['groupe'][$m]['id'] . ")";
                        }
                    }
                    // 20130927 : cell_ajustee() ou pas sur le nom de matière/enseignement
                    if (isset($tab_modele_pdf["cell_ajustee_texte_matiere"][$classe_id]) && $tab_modele_pdf["cell_ajustee_texte_matiere"][$classe_id] == 1) {
                        // Encadrement
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier, "", 'LRBT', 1, 'L');
                        // cell_ajustee() ne centre pas verticalement le texte.
                        // On met un décalage pour ne pas coller le texte à la bordure
                        $Y_decal_cell_ajustee = 1;
                        // On repositionne et on inscrit le nom de matière sur la moitié de la hauteur de la cellule
                        $pdf->SetXY($X_bloc_matiere, $Y_decal + $Y_decal_cell_ajustee);
                        $texte = $info_nom_matiere;
                        $taille_max_police = $hauteur_caractere_matiere;
                        $taille_min_police = ceil($taille_max_police / $tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id]);
                        $largeur_dispo = $tab_modele_pdf["largeur_matiere"][$classe_id] - 2;
                        $h_cell = $espace_entre_matier / 2 - $Y_decal_cell_ajustee;
                        cell_ajustee("<b>" . $texte . "</b>", $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
                    } else {
                        $val = $pdf->GetStringWidth($info_nom_matiere);
                        $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id] - 2;
                        $grandeur_texte = 'test';
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $val) {
                                $hauteur_caractere_matiere = $hauteur_caractere_matiere - 0.3;
                                $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_matiere);
                                $val = $pdf->GetStringWidth($info_nom_matiere);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        $grandeur_texte = 'test';
                        // Encadrement
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier, "", 'LRBT', 1, 'L');
                        // On repositionne et on inscrit le nom de matière sur la moitié de la hauteur de la cellule
                        $pdf->SetXY($X_bloc_matiere, $Y_decal);
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier / 2, $info_nom_matiere, 'LR', 1, 'L');
                    }
                    // On note l'ordonnée pour le nom des professeurs
                    $Y_decal = $Y_decal + $espace_entre_matier / 2;
                    $pdf->SetXY($X_bloc_matiere, $Y_decal);
                    $pdf->SetFont('DejaVu', '', 8);
                    fich_debug_bull("\$info_nom_matiere={$info_nom_matiere}\n");
                    fich_debug_bull("Le nom de matière est écrit; on est à mi-hauteur de la cellule pour écrire le nom du prof:\n");
                    fich_debug_bull("\$Y_decal={$Y_decal}\n");
                    // nom des professeurs
                    if (isset($tab_bull['groupe'][$m]["profs"]["list"])) {
                        if ($tab_modele_pdf["presentation_proflist"][$classe_id] != "2") {
                            // Présentation en colonne des profs
                            $nb_prof_matiere = count($tab_bull['groupe'][$m]["profs"]["list"]);
                            $espace_matiere_prof = $espace_entre_matier / 2;
                            if ($nb_prof_matiere > 0) {
                                $espace_matiere_prof = $espace_matiere_prof / $nb_prof_matiere;
                            }
                            $nb_pass_count = '0';
                            $text_prof = '';
                            while ($nb_prof_matiere > $nb_pass_count) {
                                //$text_prof="";
                                //for($loop_prof_grp=0;$loop_prof_grp<$nb_prof_par_ligne;$loop_prof_grp++) {
                                // calcul de la hauteur du caractère du prof
                                //$tmp_login_prof=$tab_bull['groupe'][$m]["profs"]["list"][$nb_pass_count+$loop_prof_grp];
                                $tmp_login_prof = $tab_bull['groupe'][$m]["profs"]["list"][$nb_pass_count];
                                /*
                                $text_prof=$tab_bull['groupe'][$m]["profs"]["users"]["$tmp_login_prof"]["civilite"];
                                $text_prof.=" ".$tab_bull['groupe'][$m]["profs"]["users"]["$tmp_login_prof"]["nom"];
                                $text_prof.=" ".mb_substr($tab_bull['groupe'][$m]["profs"]["users"]["$tmp_login_prof"]["prenom"],0,1);
                                */
                                //if($loop_prof_grp>0) {$text_prof.=", ";}
                                $text_prof = affiche_utilisateur($tmp_login_prof, $tab_bull['eleve'][$i]['id_classe']);
                                //}
                                if ($nb_prof_matiere <= 2) {
                                    $hauteur_caractere_prof = 8;
                                } elseif ($nb_prof_matiere == 3) {
                                    $hauteur_caractere_prof = 5;
                                } elseif ($nb_prof_matiere > 3) {
                                    $hauteur_caractere_prof = 2;
                                }
                                $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                                $val = $pdf->GetStringWidth($text_prof);
                                $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id];
                                $grandeur_texte = 'test';
                                while ($grandeur_texte != 'ok') {
                                    if ($taille_texte < $val) {
                                        $hauteur_caractere_prof = $hauteur_caractere_prof - 0.3;
                                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                                        $val = $pdf->GetStringWidth($text_prof);
                                    } else {
                                        $grandeur_texte = 'ok';
                                    }
                                }
                                $grandeur_texte = 'test';
                                $pdf->SetX($X_bloc_matiere);
                                if (empty($tab_bull['groupe'][$m]["profs"]["list"][$nb_pass_count + 1])) {
                                    $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LRB', 1, 'L');
                                }
                                if (!empty($tab_bull['groupe'][$m]["profs"]["list"][$nb_pass_count + 1])) {
                                    $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LR', 1, 'L');
                                }
                                $nb_pass_count = $nb_pass_count + 1;
                            }
                        } else {
                            // Présentation en ligne des profs
                            // On n'a pas forcément le formatage choisi pour la classe...
                            //$text_prof=$tab_bull['groupe'][$m]["profs"]["proflist_string"]."  ";
                            $text_prof = "";
                            for ($loop_prof_grp = 0; $loop_prof_grp < count($tab_bull['groupe'][$m]["profs"]["list"]); $loop_prof_grp++) {
                                $tmp_login_prof = $tab_bull['groupe'][$m]["profs"]["list"][$loop_prof_grp];
                                if ($loop_prof_grp > 0) {
                                    $text_prof .= ", ";
                                }
                                $text_prof .= affiche_utilisateur($tmp_login_prof, $tab_bull['eleve'][$i]['id_classe']);
                            }
                            if ($text_prof != "") {
                                $espace_matiere_prof = $espace_entre_matier / 2;
                                $hauteur_caractere_prof = 8;
                                if ($use_cell_ajustee == "n") {
                                    $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                                    $val = $pdf->GetStringWidth($text_prof);
                                    $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id];
                                    $grandeur_texte = 'test';
                                    while ($grandeur_texte != 'ok') {
                                        if ($taille_texte < $val) {
                                            $hauteur_caractere_prof = $hauteur_caractere_prof - 0.3;
                                            $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                                            $val = $pdf->GetStringWidth($text_prof);
                                        } else {
                                            $grandeur_texte = 'ok';
                                        }
                                    }
                                    $grandeur_texte = 'test';
                                    $pdf->SetX($X_bloc_matiere);
                                    $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LR', 1, 'L');
                                } else {
                                    $texte = $text_prof;
                                    $taille_max_police = $hauteur_caractere_prof;
                                    $taille_min_police = ceil($hauteur_caractere_prof / 3);
                                    $largeur_dispo = $tab_modele_pdf["largeur_matiere"][$classe_id];
                                    $h_cell = $espace_matiere_prof;
                                    $pdf->SetX($X_bloc_matiere);
                                    cell_ajustee($texte, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
                                }
                            }
                        }
                    }
                    $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
                    // coefficient matière
                    if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                        $pdf->SetFont('DejaVu', '', 10);
                        $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $espace_entre_matier, $tab_bull['coef_eleve'][$i][$m], 1, 0, 'C');
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                    }
                    //permet le calcul total des coefficients
                    // if(empty($moyenne_min[$id_classe][$id_periode])) {
                    $total_coef_en_calcul = $total_coef_en_calcul + $tab_bull['coef_eleve'][$i][$m];
                    //}
                    // nombre de note
                    // 20081118
                    //if($tab_modele_pdf["active_nombre_note_case"][$classe_id]==='1') {
                    if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                        $pdf->SetFont('DejaVu', '', 10);
                        $valeur = $tab_bull['nbct'][$m][$i] . "/" . $tab_bull['groupe'][$m]['nbct'];
                        $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $espace_entre_matier, $valeur, 1, 0, 'C');
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
                    }
                    // les moyennes eleve, classe, min, max
                    $cpt_ordre = 0;
                    while (!empty($ordre_moyenne[$cpt_ordre])) {
                        //eleve
                        if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                            // calcul nombre de sous affichage
                            $nb_sousaffichage = '1';
                            if ($tab_modele_pdf["moyennes_periodes_precedentes"][$classe_id] == 'y' && isset($tab_bull['login_prec'])) {
                                $nb_sousaffichage += count($tab_bull['login_prec']);
                                // Il faut récupérer le nombre de périodes...
                            }
                            // 20130520
                            if (isset($tab_modele_pdf["moyennes_annee"][$classe_id]) && $tab_modele_pdf["moyennes_annee"][$classe_id] == 'y') {
                                $nb_sousaffichage = $nb_sousaffichage + 1;
                            }
                            if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                $nb_sousaffichage = $nb_sousaffichage + 1;
                            }
                            //20100615
                            //if((!isset($moyennes_periodes_precedentes))||($moyennes_periodes_precedentes!="y")) {
                            if ($tab_modele_pdf["moyennes_periodes_precedentes"][$classe_id] != 'y') {
                                // On n'affiche pas tout ce qui suit en plus, si on affiche les moyennes de toutes les périodes déjà
                                if ($tab_modele_pdf["active_nombre_note"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                    if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1') {
                                        $nb_sousaffichage = $nb_sousaffichage + 1;
                                    }
                                }
                                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                    if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1') {
                                        $nb_sousaffichage = $nb_sousaffichage + 1;
                                    }
                                }
                                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                    if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1') {
                                        $nb_sousaffichage = $nb_sousaffichage + 1;
                                    }
                                }
                            }
                            if ($tab_modele_pdf["moyennes_periodes_precedentes"][$classe_id] != 'y' && $tab_modele_pdf["moyennes_annee"][$classe_id] != 'y') {
                                // On ne va pas afficher les moyennes des périodes précédentes dans la même cellule
                                if ($tab_modele_pdf["evolution_moyenne_periode_precedente"][$classe_id] == 'y') {
                                    $pdf->SetFont('DejaVu', 'B', 8);
                                } else {
                                    $pdf->SetFont('DejaVu', 'B', 10);
                                }
                                $fleche_evolution = "";
                                // On filtre si la moyenne est vide, on affiche seulement un tiret
                                if ($tab_bull['note'][$m][$i] == "-") {
                                    $valeur = "-";
                                } elseif ($tab_bull['statut'][$m][$i] != "") {
                                    $valeur = $tab_bull['statut'][$m][$i];
                                } else {
                                    $valeur = present_nombre($tab_bull['note'][$m][$i], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    //if((isset($evolution_moyenne_periode_precedente))&&($evolution_moyenne_periode_precedente=="y")) {
                                    if ($tab_modele_pdf["evolution_moyenne_periode_precedente"][$classe_id] == 'y' && isset($tab_bull['login_prec'])) {
                                        //$fleche_evolution="";
                                        foreach ($tab_bull['login_prec'] as $key => $value) {
                                            // Il faut récupérer l'id_groupe et l'indice de l'élève... dans les tableaux récupérés de calcul_moy_gen.inc.php
                                            // Tableaux d'indices [$j][$i] (groupe, élève)
                                            $indice_eleve = -1;
                                            for ($loop_l = 0; $loop_l < count($tab_bull['login_prec'][$key]); $loop_l++) {
                                                //echo "\$tab_bull['login_prec'][$key][$loop_l]=".$tab_bull['login_prec'][$key][$loop_l]." et \$tab_bull['eleve'][$i]['login']="******"<br />\n";
                                                if ($tab_bull['login_prec'][$key][$loop_l] == $tab_bull['eleve'][$i]['login']) {
                                                    $indice_eleve = $loop_l;
                                                    break;
                                                }
                                            }
                                            //echo "\$indice_eleve=$indice_eleve<br />\n";
                                            if ($indice_eleve != -1) {
                                                // Recherche du groupe
                                                $indice_grp = -1;
                                                for ($loop_l = 0; $loop_l < count($tab_bull['group_prec'][$key]); $loop_l++) {
                                                    //echo "\$tab_bull['group_prec'][$key][$loop_l]['id']=".$tab_bull['group_prec'][$key][$loop_l]['id']." et \$tab_bull['groupe'][$m]['id']=".$tab_bull['groupe'][$m]['id']."<br />\n";
                                                    if ($tab_bull['group_prec'][$key][$loop_l]['id'] == $tab_bull['groupe'][$m]['id']) {
                                                        $indice_grp = $loop_l;
                                                        break;
                                                    }
                                                }
                                                //echo "\$indice_grp=$indice_grp<br />\n";
                                                if ($indice_grp != -1) {
                                                    if (isset($tab_bull['statut_prec'][$key][$indice_grp][$indice_eleve])) {
                                                        if ($tab_bull['statut_prec'][$key][$indice_grp][$indice_eleve] == "") {
                                                            //echo "\$tab_bull['note'][$m][$i]=".$tab_bull['note'][$m][$i]."<br />\n";
                                                            //echo "\$tab_bull['note_prec'][$key][$indice_grp][$indice_eleve]=".$tab_bull['note_prec'][$key][$indice_grp][$indice_eleve]."<br />\n";
                                                            if ($tab_bull['note'][$m][$i] > $tab_bull['note_prec'][$key][$indice_grp][$indice_eleve]) {
                                                                $fleche_evolution = "+";
                                                            } elseif ($tab_bull['note'][$m][$i] < $tab_bull['note_prec'][$key][$indice_grp][$indice_eleve]) {
                                                                $fleche_evolution = "-";
                                                            } else {
                                                                $fleche_evolution = "";
                                                            }
                                                            //echo "\$fleche_evolution=".$fleche_evolution."<br />\n";
                                                            //$valeur = present_nombre($tab_bull['note_prec'][$key][$indice_grp][$indice_eleve], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if ($fleche_evolution != "") {
                                    $fleche_evolution = " " . $fleche_evolution;
                                }
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, $valeur . $fleche_evolution, 1, 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $valeur = "";
                                if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                    $pdf->SetFont('DejaVu', 'I', 7);
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'coef. ' . $tab_bull['coef_eleve'][$i][$m], 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                                if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                    // On affiche toutes les moyennes dans la même colonne
                                    $pdf->SetFont('DejaVu', 'I', 7);
                                    if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1') {
                                        //if ($tab_bull['moy_classe_grp'][$m]=="-") {
                                        if ($tab_bull['moy_classe_grp'][$m] == "-" || $tab_bull['moy_classe_grp'][$m] == "") {
                                            $valeur = "-";
                                        } else {
                                            $valeur = present_nombre($tab_bull['moy_classe_grp'][$m], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                        }
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'cla.' . $valeur, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    }
                                    if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1') {
                                        //if ($tab_bull['moy_min_classe_grp'][$m]=="-") {
                                        if ($tab_bull['moy_min_classe_grp'][$m] == "-" || $tab_bull['moy_min_classe_grp'][$m] == "") {
                                            $valeur = "-";
                                        } else {
                                            $valeur = present_nombre($tab_bull['moy_min_classe_grp'][$m], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                        }
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'min.' . $valeur, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    }
                                    if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1') {
                                        //if ($tab_bull['moy_max_classe_grp'][$m]=="-") {
                                        if ($tab_bull['moy_max_classe_grp'][$m] == "-" || $tab_bull['moy_max_classe_grp'][$m] == "") {
                                            $valeur = "-";
                                        } else {
                                            $valeur = present_nombre($tab_bull['moy_max_classe_grp'][$m], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                        }
                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'max.' . $valeur, 'LRD', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                        $valeur = '';
                                        // on remet à vide.
                                    }
                                }
                                if ($tab_modele_pdf["active_nombre_note"][$classe_id] === '1') {
                                    $pdf->SetFont('DejaVu', 'I', 7);
                                    $espace_pour_nb_note = $espace_entre_matier / $nb_sousaffichage;
                                    $espace_pour_nb_note = $espace_pour_nb_note / 2;
                                    $valeur1 = '';
                                    $valeur2 = '';
                                    if ($tab_bull['nbct'][$m][$i] != 0) {
                                        $valeur1 = $tab_bull['nbct'][$m][$i] . ' note';
                                        if ($tab_bull['nbct'][$m][$i] > 1) {
                                            $valeur1 .= 's';
                                        }
                                        $valeur2 = 'sur ' . $tab_bull['groupe'][$m]['nbct'];
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_pour_nb_note, $valeur1, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_pour_nb_note, $valeur2, 'LRB', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    $valeur1 = '';
                                    $valeur2 = '';
                                }
                            } else {
                                // On affiche les moyennes de l'élève pour les autres périodes dans la même colonne
                                // Il faut récupérer l'indice de l'élève... dans les tableaux récupérés de calcul_moy_gen.inc.php
                                $pdf->SetFont('DejaVu', 'I', 6);
                                if ($tab_modele_pdf["moyennes_periodes_precedentes"][$classe_id] == 'y') {
                                    if (isset($tab_bull['login_prec'])) {
                                        //for($loop_p=1;$loop_p<count($tab_bull['login_prec']);$loop_p++) {
                                        foreach ($tab_bull['login_prec'] as $key => $value) {
                                            // Il faut récupérer l'id_groupe et l'indice de l'élève... dans les tableaux récupérés de calcul_moy_gen.inc.php
                                            // Tableaux d'indices [$j][$i] (groupe, élève)
                                            //		$tab_bull['note_prec'][$loop_p]=$current_eleve_note;
                                            //		$tab_bull['statut_prec'][$loop_p]=$current_eleve_statut;
                                            $indice_eleve = -1;
                                            //for($loop_l=0;$loop_l<count($tab_bull['login_prec'][$loop_p]);$loop_l++) {
                                            for ($loop_l = 0; $loop_l < count($tab_bull['login_prec'][$key]); $loop_l++) {
                                                //echo "\$tab_bull['login_prec'][$key][$loop_l]=".$tab_bull['login_prec'][$key][$loop_l]." et \$tab_bull['eleve'][$i]['login']="******"<br />\n";
                                                if ($tab_bull['login_prec'][$key][$loop_l] == $tab_bull['eleve'][$i]['login']) {
                                                    $indice_eleve = $loop_l;
                                                    break;
                                                }
                                            }
                                            //echo "\$indice_eleve=$indice_eleve<br />\n";
                                            if ($indice_eleve != -1) {
                                                // Recherche du groupe
                                                $indice_grp = -1;
                                                for ($loop_l = 0; $loop_l < count($tab_bull['group_prec'][$key]); $loop_l++) {
                                                    //echo "\$tab_bull['group_prec'][$key][$loop_l]['id']=".$tab_bull['group_prec'][$key][$loop_l]['id']." et \$tab_bull['groupe'][$m]['id']=".$tab_bull['groupe'][$m]['id']."<br />\n";
                                                    if ($tab_bull['group_prec'][$key][$loop_l]['id'] == $tab_bull['groupe'][$m]['id']) {
                                                        $indice_grp = $loop_l;
                                                        break;
                                                    }
                                                }
                                                //echo "\$indice_grp=$indice_grp<br />\n";
                                                if ($indice_grp != -1) {
                                                    if (isset($tab_bull['statut_prec'][$key][$indice_grp][$indice_eleve])) {
                                                        if ($tab_bull['statut_prec'][$key][$indice_grp][$indice_eleve] != "") {
                                                            $valeur = $tab_bull['statut_prec'][$key][$indice_grp][$indice_eleve];
                                                        } else {
                                                            $valeur = present_nombre($tab_bull['note_prec'][$key][$indice_grp][$indice_eleve], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                                        }
                                                        if ($key == 1) {
                                                            $bordure_top = 'T';
                                                        } else {
                                                            $bordure_top = '';
                                                        }
                                                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'P' . $key . ': ' . $valeur, 'LR' . $bordure_top, 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                $pdf->SetFont('DejaVu', 'B', 10);
                                // On filtre si la moyenne est vide, on affiche seulement un tiret
                                if ($tab_bull['note'][$m][$i] == "-") {
                                    $valeur = "-";
                                } elseif ($tab_bull['statut'][$m][$i] != "") {
                                    $valeur = $tab_bull['statut'][$m][$i];
                                } else {
                                    $valeur = present_nombre($tab_bull['note'][$m][$i], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                }
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, $valeur, 1, 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                // Réinitialisation
                                $valeur = "";
                                // 20130520
                                //echo "\$tab_modele_pdf[\"moyennes_annee\"][$classe_id]=".$tab_modele_pdf["moyennes_annee"][$classe_id]."<br />\n";
                                //echo "\$tab_bull['moy_annee'][$m][$i]=".$tab_bull['moy_annee'][$m][$i]."<br />\n";
                                if (isset($tab_modele_pdf["moyennes_annee"][$classe_id]) && $tab_modele_pdf["moyennes_annee"][$classe_id] == 'y' && isset($tab_bull['moy_annee'][$m][$i])) {
                                    $pdf->SetFont('DejaVu', 'I', 6);
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, "An: " . $tab_bull['moy_annee'][$m][$i], 1, 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                                // On affiche éventuellement le coef
                                if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                    $pdf->SetFont('DejaVu', 'I', 6);
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'coef. ' . $tab_bull['coef_eleve'][$i][$m], 'LRB', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->SetFillColor(0, 0, 0);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        // Fin affichage élève
                        //classe
                        //if( $tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe' ) {
                        if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe')) {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            //if ($tab_bull['moy_classe_grp'][$m]=="-") {
                            if ($tab_bull['moy_classe_grp'][$m] == "-" || $tab_bull['moy_classe_grp'][$m] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['moy_classe_grp'][$m], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //min
                        //if( $tab_modele_pdf["active_moyenne_min"][$classe_id]==='1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min' ) {
                        if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min')) {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 8);
                            //if ($tab_bull['moy_min_classe_grp'][$m]=="-") {
                            if ($tab_bull['moy_min_classe_grp'][$m] == "-" || $tab_bull['moy_min_classe_grp'][$m] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['moy_min_classe_grp'][$m], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //max
                        //if( $tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max' ) {
                        if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max')) {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            //if ($tab_bull['moy_max_classe_grp'][$m]== "-") {
                            if ($tab_bull['moy_max_classe_grp'][$m] == "-" || $tab_bull['moy_max_classe_grp'][$m] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['moy_max_classe_grp'][$m], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //$largeur_utilise = $largeur_utilise+$largeur_moyenne;
                        // rang de l'élève
                        if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'rang') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 8);
                            // A REVOIR: J'AI l'EFFECTIF DU GROUPE, mais faut-il compter les élèves ABS, DISP,...?
                            //if((isset($tab_bull['rang'][$i][$m]))&&(isset($tab_bull['groupe'][$m]['effectif']))) {
                            //$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, $tab_bull['rang'][$i][$m].'/'.$tab_bull['groupe'][$m]['effectif'],1,0,'C');
                            if (isset($tab_bull['groupe'][$m]['effectif_avec_note']) && $tab_bull['groupe'][$m]['effectif_avec_note'] == 0) {
                                $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, "-", 1, 0, 'C');
                            } elseif (isset($tab_bull['rang'][$m][$i]) && isset($tab_bull['groupe'][$m]['effectif_avec_note'])) {
                                $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, $tab_bull['rang'][$m][$i] . '/' . $tab_bull['groupe'][$m]['effectif_avec_note'], 1, 0, 'C');
                            } else {
                                $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, '', 1, 0, 'C');
                            }
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                        }
                        // graphique de niveau
                        if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'niveau') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 10);
                            $id_groupe_graph = $tab_bull['groupe'][$m]['id'];
                            // placement de l'élève dans le graphique de niveau
                            // AJOUT: La variable n'était pas initialisée dans le bulletin_pdf_avec_modele...
                            $place_eleve = '';
                            if ($tab_bull['note'][$m][$i] != "") {
                                /*
                                if ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<5) { $place_eleve=5;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=5) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<8))  { $place_eleve=4;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=8) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<10)) { $place_eleve=3;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=10) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<12)) {$place_eleve=2;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=12) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<15)) { $place_eleve=1;}
                                if ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=15) { $place_eleve=0;}
                                */
                                if (isset($tab_bull['place_eleve'][$m][$i])) {
                                    //$place_eleve=$tab_bull['place_eleve'][$m][$i];
                                    $place_eleve = $tab_bull['place_eleve'][$m][$i] - 1;
                                }
                            }
                            $data_grap[0] = $tab_bull['quartile1_grp'][$m];
                            $data_grap[1] = $tab_bull['quartile2_grp'][$m];
                            $data_grap[2] = $tab_bull['quartile3_grp'][$m];
                            $data_grap[3] = $tab_bull['quartile4_grp'][$m];
                            $data_grap[4] = $tab_bull['quartile5_grp'][$m];
                            $data_grap[5] = $tab_bull['quartile6_grp'][$m];
                            //if (array_sum($data_grap[$id_periode][$id_groupe_graph]) != 0) {
                            if (array_sum($data_grap) != 0) {
                                //$pdf->DiagBarre($X_note_moy_app+$largeur_utilise, $Y_decal-($espace_entre_matier/2), $tab_modele_pdf["largeur_niveau"][$classe_id], $espace_entre_matier, $data_grap[$id_periode][$id_groupe_graph], $place_eleve);
                                $pdf->DiagBarre($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2, $tab_modele_pdf["largeur_niveau"][$classe_id], $espace_entre_matier, $data_grap, $place_eleve);
                            }
                            $place_eleve = '';
                            // on vide la variable
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                        }
                        //appréciation
                        if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'appreciation') {
                            // si on autorise l'affichage des sous matière et s'il y en a alors on les affiche
                            $id_groupe_select = $tab_bull['groupe'][$m]['id'];
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $X_sous_matiere = 0;
                            $largeur_sous_matiere = 0;
                            if ($tab_modele_pdf["autorise_sous_matiere"][$classe_id] === '1' and !empty($tab_bull['groupe'][$m][$i]['cn_nom'])) {
                                $X_sous_matiere = $X_note_moy_app + $largeur_utilise;
                                $Y_sous_matiere = $Y_decal - $espace_entre_matier / 2;
                                $n = 0;
                                $largeur_texte_sousmatiere = 0;
                                $largeur_sous_matiere = 0;
                                while (!empty($tab_bull['groupe'][$m][$i]['cn_nom'][$n])) {
                                    $pdf->SetFont('DejaVu', '', 8);
                                    $largeur_texte_sousmatiere = $pdf->GetStringWidth($tab_bull['groupe'][$m][$i]['cn_nom'][$n] . ': ' . $tab_bull['groupe'][$m][$i]['cn_note'][$n]);
                                    if ($largeur_sous_matiere < $largeur_texte_sousmatiere) {
                                        $largeur_sous_matiere = $largeur_texte_sousmatiere;
                                    }
                                    $n = $n + 1;
                                }
                                if ($largeur_sous_matiere != '0') {
                                    $largeur_sous_matiere = $largeur_sous_matiere + 2;
                                }
                                $n = 0;
                                while (!empty($tab_bull['groupe'][$m][$i]['cn_nom'][$n])) {
                                    $pdf->SetXY($X_sous_matiere, $Y_sous_matiere);
                                    $pdf->SetFont('DejaVu', '', 8);
                                    $pdf->Cell($largeur_sous_matiere, $espace_entre_matier / count($tab_bull['groupe'][$m][$i]['cn_nom']), $tab_bull['groupe'][$m][$i]['cn_nom'][$n] . ': ' . $tab_bull['groupe'][$m][$i]['cn_note'][$n], 1, 0, 'L');
                                    $Y_sous_matiere = $Y_sous_matiere + $espace_entre_matier / count($tab_bull['groupe'][$m][$i]['cn_nom']);
                                    $n = $n + 1;
                                }
                                $largeur_utilise = $largeur_utilise + $largeur_sous_matiere;
                            }
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            // calcul de la taille du texte des appréciation
                            $hauteur_caractere_appreciation = 9;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere_appreciation);
                            //suppression des espace en début et en fin
                            $app_aff = trim($tab_bull['app'][$m][$i]);
                            fich_debug_bull("__________________________________________\n");
                            fich_debug_bull("{$app_aff}\n");
                            fich_debug_bull("__________________________________________\n");
                            // DEBUT AJUSTEMENT TAILLE APPRECIATION
                            $taille_texte_total = $pdf->GetStringWidth($app_aff);
                            $largeur_appreciation2 = $largeur_appreciation - $largeur_sous_matiere;
                            if ($use_cell_ajustee == "n") {
                                //$taille_texte = (($espace_entre_matier/3)*$largeur_appreciation2);
                                $nb_ligne_app = '2.8';
                                //$nb_ligne_app = '3.8';
                                //$nb_ligne_app = '4.8';
                                $taille_texte_max = $nb_ligne_app * ($largeur_appreciation2 - 4);
                                //$taille_texte_max = $nb_ligne_app * ($largeur_appreciation2);
                                $grandeur_texte = 'test';
                                fich_debug_bull("\$taille_texte_total={$taille_texte_total}\n");
                                fich_debug_bull("\$largeur_appreciation2={$largeur_appreciation2}\n");
                                fich_debug_bull("\$nb_ligne_app={$nb_ligne_app}\n");
                                //fich_debug_bull("\$taille_texte_max = \$nb_ligne_app * (\$largeur_appreciation2-4)=$nb_ligne_app * ($largeur_appreciation2-4)=$taille_texte_max\n");
                                fich_debug_bull("\$taille_texte_max = \$nb_ligne_app * (\$largeur_appreciation2)={$nb_ligne_app} * ({$largeur_appreciation2})={$taille_texte_max}\n");
                                while ($grandeur_texte != 'ok') {
                                    if ($taille_texte_max < $taille_texte_total) {
                                        $hauteur_caractere_appreciation = $hauteur_caractere_appreciation - 0.3;
                                        //$hauteur_caractere_appreciation = $hauteur_caractere_appreciation-0.1;
                                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_appreciation);
                                        $taille_texte_total = $pdf->GetStringWidth($app_aff);
                                    } else {
                                        $grandeur_texte = 'ok';
                                    }
                                }
                                $grandeur_texte = 'test';
                                $pdf->drawTextBox($app_aff, $largeur_appreciation2, $espace_entre_matier, 'J', 'M', 1);
                            } else {
                                $texte = $app_aff;
                                //$texte="Bla bla\nbli ".$app_aff;
                                $taille_max_police = $hauteur_caractere_appreciation;
                                $taille_min_police = ceil($taille_max_police / 3);
                                $largeur_dispo = $largeur_appreciation2;
                                $h_cell = $espace_entre_matier;
                                if (getSettingValue('suppr_balises_app_prof') == 'y') {
                                    $texte = preg_replace('/<(.*)>/U', '', $texte);
                                }
                                cell_ajustee($texte, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, 'LRBT');
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            $largeur_utilise = $largeur_utilise + $largeur_appreciation2;
                            //$largeur_utilise = 0;
                        }
                        $cpt_ordre = $cpt_ordre + 1;
                    }
                    $largeur_utilise = 0;
                    // fin de boucle d'ordre
                    $Y_decal = $Y_decal + $espace_entre_matier / 2;
                    fich_debug_bull("Apres affichage de l'appreciation: \$Y_decal={$Y_decal}\n");
                }
            }
            fich_debug_bull("Avant les AID_E: \$Y_decal={$Y_decal}\n");
            //======================================================
            // DEBUT DES AID AFFICHéS APRES LES MATIERES
            if (isset($tab_bull['eleve'][$i]['aid_e'])) {
                //echo "count(\$tab_bull['eleve'][$i]['aid_e']=".count($tab_bull['eleve'][$i]['aid_e'])."<br />";
                for ($m = 0; $m < count($tab_bull['eleve'][$i]['aid_e']); $m++) {
                    $pdf->SetXY($X_bloc_matiere, $Y_decal);
                    // Si c'est une matière suivie par l'élève
                    //if(isset($tab_bull['eleve'][$i]['note'][$m][$i])) {
                    // calcul la taille du titre de la matière
                    $hauteur_caractere_matiere = 10;
                    if ($tab_modele_pdf["taille_texte_matiere"][$classe_id] != '' and $tab_modele_pdf["taille_texte_matiere"][$classe_id] != '0' and $tab_modele_pdf["taille_texte_matiere"][$classe_id] < '11') {
                        $hauteur_caractere_matiere = $tab_modele_pdf["taille_texte_matiere"][$classe_id];
                    }
                    $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_matiere);
                    // Pour parer au bug sur la suppression de matière alors que des groupes sont conservés:
                    if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['nom_complet'])) {
                        $info_nom_matiere = $tab_bull['eleve'][$i]['aid_e'][$m]['nom_complet'];
                    } else {
                        $info_nom_matiere = $tab_bull['eleve'][$i]['aid_e'][$m]['nom'];
                    }
                    // 20130927 : cell_ajustee() ou pas sur le nom de matière/enseignement
                    if (isset($tab_modele_pdf["cell_ajustee_texte_matiere"][$classe_id]) && $tab_modele_pdf["cell_ajustee_texte_matiere"][$classe_id] == 1) {
                        // Encadrement
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier, "", 'LRBT', 1, 'L');
                        // cell_ajustee() ne centre pas verticalement le texte.
                        // On met un décalage pour ne pas coller le texte à la bordure
                        $Y_decal_cell_ajustee = 1;
                        // On repositionne et on inscrit le nom de matière sur la moitié de la hauteur de la cellule
                        $pdf->SetXY($X_bloc_matiere, $Y_decal + $Y_decal_cell_ajustee);
                        $texte = $info_nom_matiere;
                        $taille_max_police = $hauteur_caractere_matiere;
                        $taille_min_police = ceil($taille_max_police / $tab_modele_pdf["cell_ajustee_texte_matiere_ratio_min_max"][$classe_id]);
                        $largeur_dispo = $tab_modele_pdf["largeur_matiere"][$classe_id] - 2;
                        $h_cell = $espace_entre_matier / 2 - $Y_decal_cell_ajustee;
                        cell_ajustee("<b>" . $texte . "</b>", $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
                    } else {
                        $val = $pdf->GetStringWidth($info_nom_matiere);
                        $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id] - 2;
                        $grandeur_texte = 'test';
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $val) {
                                $hauteur_caractere_matiere = $hauteur_caractere_matiere - 0.3;
                                $pdf->SetFont('DejaVu', 'B', $hauteur_caractere_matiere);
                                $val = $pdf->GetStringWidth($info_nom_matiere);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        $grandeur_texte = 'test';
                        $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_entre_matier / 2, $info_nom_matiere, 'LR', 1, 'L');
                    }
                    $Y_decal = $Y_decal + $espace_entre_matier / 2;
                    $pdf->SetXY($X_bloc_matiere, $Y_decal);
                    $pdf->SetFont('DejaVu', '', 8);
                    fich_debug_bull("\$info_nom_matiere={$info_nom_matiere}\n");
                    fich_debug_bull("\$Y_decal={$Y_decal}\n");
                    // nom des professeurs
                    if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['aid_prof_resp_login'][0])) {
                        $nb_prof_matiere = count($tab_bull['eleve'][$i]['aid_e'][$m]['aid_prof_resp_login']);
                        $espace_matiere_prof = $espace_entre_matier / 2;
                        if ($nb_prof_matiere > 0) {
                            $espace_matiere_prof = $espace_matiere_prof / $nb_prof_matiere;
                        }
                        $nb_pass_count = '0';
                        $text_prof = '';
                        while ($nb_prof_matiere > $nb_pass_count) {
                            $tmp_login_prof = $tab_bull['eleve'][$i]['aid_e'][$m]['aid_prof_resp_login'][$nb_pass_count];
                            $text_prof = affiche_utilisateur($tmp_login_prof, $tab_bull['eleve'][$i]['id_classe']);
                            if ($nb_prof_matiere <= 2) {
                                $hauteur_caractere_prof = 8;
                            } elseif ($nb_prof_matiere == 3) {
                                $hauteur_caractere_prof = 5;
                            } elseif ($nb_prof_matiere > 3) {
                                $hauteur_caractere_prof = 2;
                            }
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                            $val = $pdf->GetStringWidth($text_prof);
                            $taille_texte = $tab_modele_pdf["largeur_matiere"][$classe_id];
                            $grandeur_texte = 'test';
                            while ($grandeur_texte != 'ok') {
                                if ($taille_texte < $val) {
                                    $hauteur_caractere_prof = $hauteur_caractere_prof - 0.3;
                                    $pdf->SetFont('DejaVu', '', $hauteur_caractere_prof);
                                    $val = $pdf->GetStringWidth($text_prof);
                                } else {
                                    $grandeur_texte = 'ok';
                                }
                            }
                            $grandeur_texte = 'test';
                            $pdf->SetX($X_bloc_matiere);
                            if (empty($tab_bull['eleve'][$i]['aid_e'][$m]['aid_prof_resp_login'][$nb_pass_count + 1])) {
                                $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LRB', 1, 'L');
                            }
                            if (!empty($tab_bull['eleve'][$i]['aid_e'][$m]['aid_prof_resp_login'][$nb_pass_count + 1])) {
                                $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $espace_matiere_prof, $text_prof, 'LR', 1, 'L');
                            }
                            $nb_pass_count = $nb_pass_count + 1;
                        }
                    }
                    $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
                    // coefficient matière
                    if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                        $pdf->SetFont('DejaVu', '', 10);
                        //$pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $espace_entre_matier, $tab_bull['eleve'][$i]['coef_eleve'][$i][$m],1,0,'C');
                        $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $espace_entre_matier, '', 1, 0, 'C');
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                    }
                    //permet le calcul total des coefficients
                    // if(empty($moyenne_min[$id_classe][$id_periode])) {
                    //$total_coef_en_calcul=$total_coef_en_calcul+$tab_bull['eleve'][$i]['coef_eleve'][$i][$m];
                    //}
                    // nombre de note
                    // 20081118
                    //if($tab_modele_pdf["active_nombre_note_case"][$classe_id]==='1') {
                    if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                        $pdf->SetFont('DejaVu', '', 10);
                        //$valeur = $tab_bull['eleve'][$i]['nbct'][$m][$i] . "/" . $tab_bull['eleve'][$i]['groupe'][$m]['nbct'];
                        $valeur = '';
                        $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $espace_entre_matier, $valeur, 1, 0, 'C');
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
                    }
                    // les moyennes eleve, classe, min, max
                    $cpt_ordre = 0;
                    while (!empty($ordre_moyenne[$cpt_ordre])) {
                        //eleve
                        if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', 'B', 10);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                            // calcul nombre de sous affichage
                            $nb_sousaffichage = '1';
                            //20090908 if(empty($active_coef_sousmoyene)) { $active_coef_sousmoyene = ''; }
                            if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                $nb_sousaffichage = $nb_sousaffichage + 1;
                            }
                            if ($tab_modele_pdf["active_nombre_note"][$classe_id] === '1') {
                                $nb_sousaffichage = $nb_sousaffichage + 1;
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1') {
                                    $nb_sousaffichage = $nb_sousaffichage + 1;
                                }
                            }
                            // On filtre si la moyenne est vide, on affiche seulement un tiret
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note'] == "-") {
                                $valeur = "-";
                            } elseif ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_statut'] != "") {
                                if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_statut'] == "other") {
                                    $valeur = "-";
                                } else {
                                    $valeur = $tab_bull['eleve'][$i]['aid_e'][$m]['aid_statut'];
                                }
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, $valeur, 1, 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                            $valeur = "";
                            if ($tab_modele_pdf["active_coef_sousmoyene"][$classe_id] === '1') {
                                $pdf->SetFont('DejaVu', 'I', 7);
                                //$pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier/$nb_sousaffichage, 'coef. '.$tab_bull['eleve'][$i]['coef_eleve'][$i][$m],'LR',2,'C',$tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, '', 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                            }
                            if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] === '1') {
                                // On affiche toutes les moyennes dans la même colonne
                                $pdf->SetFont('DejaVu', 'I', 7);
                                if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1') {
                                    //if ($tab_bull['eleve'][$i]['moy_classe_grp'][$m]=="-") {
                                    if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_moyenne'] == "-" || $tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_moyenne'] == "") {
                                        $valeur = "-";
                                    } else {
                                        $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_moyenne'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'cla.' . $valeur, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                                if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1') {
                                    //if ($tab_bull['eleve'][$i]['moy_min_classe_grp'][$m]=="-") {
                                    if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_min'] == "-" || $tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_min'] == "") {
                                        $valeur = "-";
                                    } else {
                                        $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_min'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'min.' . $valeur, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                }
                                if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1') {
                                    //if ($tab_bull['eleve'][$i]['moy_max_classe_grp'][$m]=="-") {
                                    if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_max'] == "-" || $tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_max'] == "") {
                                        $valeur = "-";
                                    } else {
                                        $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_max'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                    }
                                    $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier / $nb_sousaffichage, 'max.' . $valeur, 'LRD', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                    $valeur = '';
                                    // on remet à vide.
                                }
                            }
                            if ($tab_modele_pdf["active_nombre_note"][$classe_id] === '1') {
                                $pdf->SetFont('DejaVu', 'I', 7);
                                $espace_pour_nb_note = $espace_entre_matier / $nb_sousaffichage;
                                $espace_pour_nb_note = $espace_pour_nb_note / 2;
                                $valeur1 = '';
                                $valeur2 = '';
                                /*
                                if ($tab_bull['eleve'][$i]['nbct'][$m][$i]!= 0 ) {
                                	$valeur1 = $tab_bull['eleve'][$i]['nbct'][$m][$i].' note';
                                	if($tab_bull['eleve'][$i]['nbct'][$m][$i]>1){$valeur1.='s';}
                                	$valeur2 = 'sur '.$tab_bull['eleve'][$i]['groupe'][$m]['nbct'];
                                }
                                */
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_pour_nb_note, $valeur1, 'LR', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_pour_nb_note, $valeur2, 'LRB', 2, 'C', $tab_modele_pdf["active_reperage_eleve"][$classe_id]);
                                $valeur1 = '';
                                $valeur2 = '';
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->SetFillColor(0, 0, 0);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        // Fin affichage élève
                        //classe
                        if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            //if ($tab_bull['eleve'][$i]['moy_classe_grp'][$m]=="-") {
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_moyenne'] == "-" || $tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_moyenne'] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_moyenne'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //min
                        if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 8);
                            //if ($tab_bull['eleve'][$i]['moy_min_classe_grp'][$m]=="-") {
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_min'] == "-" || $tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_min'] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_min'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //max
                        if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            //if ($tab_bull['eleve'][$i]['moy_max_classe_grp'][$m]== "-") {
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_max'] == "-" || $tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_max'] == "") {
                                $valeur = "-";
                            } else {
                                $valeur = present_nombre($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note_max'], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $espace_entre_matier, $valeur, 'TLRB', 0, 'C');
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //$largeur_utilise = $largeur_utilise+$largeur_moyenne;
                        // rang de l'élève
                        if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'rang') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 8);
                            // A REVOIR: J'AI l'EFFECTIF DU GROUPE, mais faut-il compter les élèves ABS, DISP,...?
                            //if((isset($tab_bull['eleve'][$i]['rang'][$i][$m]))&&(isset($tab_bull['eleve'][$i]['groupe'][$m]['effectif']))) {
                            //$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, $tab_bull['eleve'][$i]['rang'][$i][$m].'/'.$tab_bull['eleve'][$i]['groupe'][$m]['effectif'],1,0,'C');
                            //if((isset($tab_bull['eleve'][$i]['rang'][$m][$i]))&&(isset($tab_bull['eleve'][$i]['groupe'][$m]['effectif']))) {
                            //	$pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, $tab_bull['eleve'][$i]['rang'][$m][$i].'/'.$tab_bull['eleve'][$i]['groupe'][$m]['effectif_avec_note'],1,0,'C');
                            //}
                            //else {
                            $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $espace_entre_matier, '', 1, 0, 'C');
                            //}
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                        }
                        // graphique de niveau
                        if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'niveau') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $pdf->SetFont('DejaVu', '', 10);
                            //$id_groupe_graph = $tab_bull['eleve'][$i]['groupe'][$m]['id'];
                            // placement de l'élève dans le graphique de niveau
                            // AJOUT: La variable n'était pas initialisée dans le bulletin_pdf_avec_modele...
                            $place_eleve = '';
                            //if ($tab_bull['eleve'][$i]['note'][$m][$i]!="") {
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['aid_note'] != "") {
                                /*
                                if ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<5) { $place_eleve=5;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=5) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<8))  { $place_eleve=4;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=8) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<10)) { $place_eleve=3;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=10) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<12)) {$place_eleve=2;}
                                if (($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=12) and ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']<15)) { $place_eleve=1;}
                                if ($matiere[$ident_eleve_aff][$id_periode][$m]['moy_eleve']>=15) { $place_eleve=0;}
                                */
                                if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['place_eleve'])) {
                                    //$place_eleve=$tab_bull['eleve'][$i]['aid_e'][$m]['place_eleve'];
                                    $place_eleve = $tab_bull['eleve'][$i]['aid_e'][$m]['place_eleve'] - 1;
                                }
                            }
                            $data_grap = array();
                            if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['quartile1_classe'])) {
                                $data_grap[0] = $tab_bull['eleve'][$i]['aid_e'][$m]['quartile1_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['quartile2_classe'])) {
                                $data_grap[1] = $tab_bull['eleve'][$i]['aid_e'][$m]['quartile2_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['quartile3_classe'])) {
                                $data_grap[2] = $tab_bull['eleve'][$i]['aid_e'][$m]['quartile3_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['quartile4_classe'])) {
                                $data_grap[3] = $tab_bull['eleve'][$i]['aid_e'][$m]['quartile4_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['quartile5_classe'])) {
                                $data_grap[4] = $tab_bull['eleve'][$i]['aid_e'][$m]['quartile5_classe'];
                            }
                            if (isset($tab_bull['eleve'][$i]['aid_e'][$m]['quartile6_classe'])) {
                                $data_grap[5] = $tab_bull['eleve'][$i]['aid_e'][$m]['quartile6_classe'];
                            }
                            //if (array_sum($data_grap[$id_periode][$id_groupe_graph]) != 0) {
                            if (array_sum($data_grap) != 0) {
                                //$pdf->DiagBarre($X_note_moy_app+$largeur_utilise, $Y_decal-($espace_entre_matier/2), $tab_modele_pdf["largeur_niveau"][$classe_id], $espace_entre_matier, $data_grap[$id_periode][$id_groupe_graph], $place_eleve);
                                $pdf->DiagBarre($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2, $tab_modele_pdf["largeur_niveau"][$classe_id], $espace_entre_matier, $data_grap, $place_eleve);
                            }
                            $place_eleve = '';
                            // on vide la variable
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                        }
                        //appréciation
                        if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'appreciation') {
                            // si on autorise l'affichage des sous matière et s'il y en a alors on les affiche
                            //$id_groupe_select = $tab_bull['eleve'][$i]['groupe'][$m]['id'];
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            $X_sous_matiere = 0;
                            $largeur_sous_matiere = 0;
                            /*
                            if($tab_modele_pdf["autorise_sous_matiere"][$classe_id]==='1' and !empty($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'])) {
                            	$X_sous_matiere = $X_note_moy_app+$largeur_utilise;
                            	$Y_sous_matiere = $Y_decal-($espace_entre_matier/2);
                            	$n=0;
                            	$largeur_texte_sousmatiere=0; $largeur_sous_matiere=0;
                            	while( !empty($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n]) )
                            	{
                            		$pdf->SetFont('DejaVu','',8);
                            		$largeur_texte_sousmatiere = $pdf->GetStringWidth($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n].': '.$tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_note'][$n]);
                            		if($largeur_sous_matiere<$largeur_texte_sousmatiere) { $largeur_sous_matiere=$largeur_texte_sousmatiere; }
                            		$n = $n + 1;
                            	}
                            	if($largeur_sous_matiere!='0') { $largeur_sous_matiere = $largeur_sous_matiere + 2; }
                            	$n=0;
                            	while( !empty($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n]) )
                            	{
                            		$pdf->SetXY($X_sous_matiere, $Y_sous_matiere);
                            		$pdf->SetFont('DejaVu','',8);
                            		$pdf->Cell($largeur_sous_matiere, $espace_entre_matier/count($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom']), ($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom'][$n].': '.$tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_note'][$n]),1,0,'L');
                            		$Y_sous_matiere = $Y_sous_matiere+$espace_entre_matier/count($tab_bull['eleve'][$i]['groupe'][$m][$i]['cn_nom']);
                            		$n = $n + 1;
                            	}
                            	$largeur_utilise = $largeur_utilise+$largeur_sous_matiere;
                            }
                            */
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_decal - $espace_entre_matier / 2);
                            // calcul de la taille du texte des appréciation
                            $hauteur_caractere_appreciation = 9;
                            $pdf->SetFont('DejaVu', '', $hauteur_caractere_appreciation);
                            //suppression des espace en début et en fin
                            //$app_aff = trim($tab_bull['eleve'][$i]['aid_e'][$m]['aid_appreciation']);
                            $app_aff = "";
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['message'] != '') {
                                $app_aff .= $tab_bull['eleve'][$i]['aid_e'][$m]['message'];
                            }
                            //if($app_aff!='') {$app_aff.=" ";}
                            //if($tab_bull['eleve'][$i]['aid_e'][$m]['aid_nom']!='') {
                            if ($tab_bull['eleve'][$i]['aid_e'][$m]['display_nom'] == 'y' && $tab_bull['eleve'][$i]['aid_e'][$m]['aid_nom'] != '') {
                                if ($app_aff != '') {
                                    $app_aff .= " ";
                                }
                                $app_aff .= $tab_bull['eleve'][$i]['aid_e'][$m]['aid_nom'];
                            }
                            if ($app_aff != '') {
                                $app_aff .= "\n";
                            }
                            $app_aff .= trim($tab_bull['eleve'][$i]['aid_e'][$m]['aid_appreciation']);
                            fich_debug_bull("__________________________________________\n");
                            fich_debug_bull("{$app_aff}\n");
                            fich_debug_bull("__________________________________________\n");
                            // DEBUT AJUSTEMENT TAILLE APPRECIATION
                            $taille_texte_total = $pdf->GetStringWidth($app_aff);
                            $largeur_appreciation2 = $largeur_appreciation - $largeur_sous_matiere;
                            if ($use_cell_ajustee == "n") {
                                //$taille_texte = (($espace_entre_matier/3)*$largeur_appreciation2);
                                $nb_ligne_app = '2.8';
                                //$nb_ligne_app = '3.8';
                                //$nb_ligne_app = '4.8';
                                $taille_texte_max = $nb_ligne_app * ($largeur_appreciation2 - 4);
                                //$taille_texte_max = $nb_ligne_app * ($largeur_appreciation2);
                                $grandeur_texte = 'test';
                                fich_debug_bull("\$taille_texte_total={$taille_texte_total}\n");
                                fich_debug_bull("\$largeur_appreciation2={$largeur_appreciation2}\n");
                                fich_debug_bull("\$nb_ligne_app={$nb_ligne_app}\n");
                                //fich_debug_bull("\$taille_texte_max = \$nb_ligne_app * (\$largeur_appreciation2-4)=$nb_ligne_app * ($largeur_appreciation2-4)=$taille_texte_max\n");
                                fich_debug_bull("\$taille_texte_max = \$nb_ligne_app * (\$largeur_appreciation2)={$nb_ligne_app} * ({$largeur_appreciation2})={$taille_texte_max}\n");
                                while ($grandeur_texte != 'ok') {
                                    if ($taille_texte_max < $taille_texte_total) {
                                        $hauteur_caractere_appreciation = $hauteur_caractere_appreciation - 0.3;
                                        //$hauteur_caractere_appreciation = $hauteur_caractere_appreciation-0.1;
                                        $pdf->SetFont('DejaVu', '', $hauteur_caractere_appreciation);
                                        $taille_texte_total = $pdf->GetStringWidth($app_aff);
                                    } else {
                                        $grandeur_texte = 'ok';
                                    }
                                }
                                $grandeur_texte = 'test';
                                $pdf->drawTextBox($app_aff, $largeur_appreciation2, $espace_entre_matier, 'J', 'M', 1);
                            } else {
                                $texte = $app_aff;
                                //$texte="Bla bla\nbli ".$app_aff;
                                $taille_max_police = $hauteur_caractere_appreciation;
                                $taille_min_police = ceil($taille_max_police / 3);
                                $largeur_dispo = $largeur_appreciation2;
                                $h_cell = $espace_entre_matier;
                                if (getSettingValue('suppr_balises_app_prof') == 'y') {
                                    $texte = preg_replace('/<(.*)>/U', '', $texte);
                                }
                                cell_ajustee($texte, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, 'LRBT');
                            }
                            $pdf->SetFont('DejaVu', '', 10);
                            $largeur_utilise = $largeur_utilise + $largeur_appreciation2;
                            //$largeur_utilise = 0;
                        }
                        $cpt_ordre = $cpt_ordre + 1;
                    }
                    $largeur_utilise = 0;
                    // fin de boucle d'ordre
                    $Y_decal = $Y_decal + $espace_entre_matier / 2;
                    //}
                }
            }
            // FIN DES AID AFFICHéS APRES LES MATIERES
            //======================================================
            fich_debug_bull("Apres les AID_E: \$Y_decal={$Y_decal}\n");
            //echo "\$tab_modele_pdf['active_moyenne'][$classe_id]=".$tab_modele_pdf["active_moyenne"][$classe_id]."<br />";
            // Ligne moyenne générale
            // bas du tableau des notes et app si les moyennes générales ne sont pas affichées, le bas du tableau ne sera pas affiché
            if ($tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne_general"][$classe_id] === '1') {
                $X_note_moy_app = $tab_modele_pdf["X_note_app"][$classe_id];
                $Y_note_moy_app = $tab_modele_pdf["Y_note_app"][$classe_id] + $tab_modele_pdf["hauteur_note_app"][$classe_id] - $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id];
                if ($affiche_deux_moy_gen == 1) {
                    // On a réservé une ligne de plus pour la moyenne générale avec coefficients 1
                    $Y_note_moy_app -= $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id];
                }
                $pdf->SetXY($X_note_moy_app, $Y_note_moy_app);
                $pdf->SetFont('DejaVu', '', 10);
                $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                //================
                // Ajout: J.Etheve
                if ($affiche_deux_moy_gen == 1) {
                    $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "Moy.gén.coef.", 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                } else {
                    $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "Moyenne générale", 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                }
                //================
                $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
                // coefficient matière
                //echo "\$tab_modele_pdf['active_coef_moyenne'][$classe_id]=".$tab_modele_pdf["active_coef_moyenne"][$classe_id]."<br />";
                if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                    $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                    $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                    //$pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "",1,0,'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                    $pdf->SetFont('DejaVu', '', 10);
                    //echo "\$tab_modele_pdf['affiche_totalpoints_sur_totalcoefs'][$classe_id]=".$tab_modele_pdf["affiche_totalpoints_sur_totalcoefs"][$classe_id]."<br />\n";
                    if ($tab_modele_pdf["affiche_totalpoints_sur_totalcoefs"][$classe_id] == '1') {
                        $info_tot_et_coef = $tab_bull['tot_points_eleve'][$i] . "/" . $tab_bull['total_coef_eleve'][$i];
                    } elseif ($tab_modele_pdf["affiche_totalpoints_sur_totalcoefs"][$classe_id] == '2') {
                        $info_tot_et_coef = $tab_bull['total_coef_eleve'][$i];
                    } else {
                        $info_tot_et_coef = '-';
                    }
                    $val = $pdf->GetStringWidth($info_tot_et_coef);
                    $taille_texte = $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                    $grandeur_texte = 'test';
                    $hauteur_tmp = 10;
                    while ($grandeur_texte != 'ok') {
                        if ($taille_texte < $val) {
                            $hauteur_tmp = $hauteur_tmp - 0.3;
                            $pdf->SetFont('DejaVu', '', $hauteur_tmp);
                            $val = $pdf->GetStringWidth($info_tot_et_coef);
                        } else {
                            $grandeur_texte = 'ok';
                        }
                    }
                    $grandeur_texte = 'test';
                    $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $info_tot_et_coef, 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                    $pdf->SetFont('DejaVu', '', 10);
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                }
                // nombre de notes
                if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                    $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                    $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                    $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "", 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                    $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
                }
                $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                $cpt_ordre = 0;
                while (!empty($ordre_moyenne[$cpt_ordre])) {
                    // eleve
                    if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFont('DejaVu', 'B', 10);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        // On a deux paramètres de couleur qui se croisent. On utilise une variable tierce.
                        $utilise_couleur = $tab_modele_pdf["couleur_moy_general"][$classe_id];
                        if ($tab_modele_pdf["active_reperage_eleve"][$classe_id] === '1') {
                            // Si on affiche une couleur spécifique pour les moyennes de l'élève,
                            // on utilise cette couleur ici aussi, quoi qu'il arrive
                            $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                            $utilise_couleur = 1;
                        }
                        if ($tab_bull['moy_gen_eleve'][$i] == "" || $tab_bull['moy_gen_eleve'][$i] == "-") {
                            $val_tmp = "-";
                        } else {
                            $val_tmp = present_nombre(preg_replace("/,/", '.', $tab_bull['moy_gen_eleve'][$i]), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                        }
                        $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $val_tmp, 1, 0, 'C', $utilise_couleur);
                        $pdf->SetFont('DejaVu', '', 10);
                        $pdf->SetFillColor(0, 0, 0);
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                    }
                    // classe
                    // 20141122
                    if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe')) {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFont('DejaVu', '', 8);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        /*
                        if( $total_coef_en_calcul != 0){
                        	$moyenne_classe = $total_moyenne_classe_en_calcul / $total_coef_en_calcul;
                        }
                        else{
                        	$moyenne_classe = '-';
                        }
                        */
                        if ($tab_bull['moy_generale_classe'] == "" || $tab_bull['moy_generale_classe'] == "-") {
                            $moyenne_classe = '-';
                        } else {
                            $moyenne_classe = present_nombre(preg_replace("/,/", '.', $tab_bull['moy_generale_classe']), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                        }
                        if ($moyenne_classe != '-') {
                            //$moyenne_classe=$tab_bull['moy_generale_classe'];
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $moyenne_classe, 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        } else {
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '-', 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        }
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                    }
                    // min
                    if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min')) {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFont('DejaVu', '', 8);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        /*
                        if($total_coef_en_calcul != 0 and $tab_modele_pdf["affiche_moyenne_mini_general"][$classe_id] === '1' ){
                        	$moyenne_min = $total_moyenne_min_en_calcul / $total_coef_en_calcul;
                        }
                        else{
                        	$moyenne_min = '-';
                        }
                        */
                        if ($tab_bull['moy_min_classe'] != '-') {
                            //$moyenne_min=$tab_moy_min_classe[$classe_id][$id_periode];
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], present_nombre(preg_replace("/,/", '.', $tab_bull['moy_min_classe']), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]), 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        } else {
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '-', 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        }
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                    }
                    // max
                    if ($tab_modele_pdf["toute_moyenne_meme_col"][$classe_id] != 1 && ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max')) {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFont('DejaVu', '', 8);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        /*
                        if($total_coef_en_calcul != 0 and $tab_modele_pdf["affiche_moyenne_maxi_general"][$classe_id] === '1' ){
                        	$moyenne_max = $total_moyenne_max_en_calcul / $total_coef_en_calcul;
                        } else {
                        	$moyenne_max = '-';
                        }
                        */
                        if ($tab_bull['moy_max_classe'] != '-') {
                            $moyenne_max = $tab_bull['moy_max_classe'];
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], present_nombre(preg_replace("/,/", '.', $tab_bull['moy_max_classe']), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]), 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        } else {
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '-', 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        }
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                    }
                    // rang de l'élève (pour la ligne Moyenne générale)
                    if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'rang') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFont('DejaVu', '', 8);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        if ($tab_bull['rang_classe'][$i] != 0) {
                            $rang_a_afficher = $tab_bull['rang_classe'][$i] . '/' . $tab_bull['eff_classe'];
                        } else {
                            $rang_a_afficher = "";
                        }
                        $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $rang_a_afficher, 'TLRB', 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                    }
                    // graphique de niveau
                    if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'niveau') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        // placement de l'élève dans le graphique de niveau
                        //if ($tab_bull['moy_gen_eleve'][$i]!="") {
                        if ($tab_bull['moy_gen_eleve'][$i] != "" && $tab_bull['moy_gen_eleve'][$i] != "-") {
                            /*
                            if ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<5) { $place_eleve=5;}
                            if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=5) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<8))  { $place_eleve=4;}
                            if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=8) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<10)) { $place_eleve=3;}
                            if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=10) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<12)) {$place_eleve=2;}
                            if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=12) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<15)) { $place_eleve=1;}
                            if ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=15) { $place_eleve=0;}
                            */
                            //$place_eleve=$tab_bull['place_eleve_classe'][$i];
                            $place_eleve = $tab_bull['place_eleve_classe'][$i] - 1;
                        }
                        $data_grap_classe[0] = $tab_bull['quartile1_classe_gen'];
                        $data_grap_classe[1] = $tab_bull['quartile2_classe_gen'];
                        $data_grap_classe[2] = $tab_bull['quartile3_classe_gen'];
                        $data_grap_classe[3] = $tab_bull['quartile4_classe_gen'];
                        $data_grap_classe[4] = $tab_bull['quartile5_classe_gen'];
                        $data_grap_classe[5] = $tab_bull['quartile6_classe_gen'];
                        if (array_sum($data_grap_classe) != 0) {
                            //$pdf->DiagBarre($X_note_moy_app+$largeur_utilise, $Y_note_moy_app, $tab_modele_pdf["largeur_niveau"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $data_grap_classe[$id_periode][$id_classe_selection], $place_eleve);
                            $pdf->DiagBarre($X_note_moy_app + $largeur_utilise, $Y_note_moy_app, $tab_modele_pdf["largeur_niveau"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $data_grap_classe, $place_eleve);
                        }
                        $place_eleve = '';
                        // on vide la variable
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                    }
                    //appréciation
                    if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'appreciation') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        $pdf->Cell($largeur_appreciation, $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '', 'TLRB', 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        $largeur_utilise = $largeur_utilise + $largeur_appreciation;
                    }
                    $cpt_ordre = $cpt_ordre + 1;
                }
                $largeur_utilise = 0;
                // fin de boucle d'ordre
                $pdf->SetFillColor(0, 0, 0);
            }
            //================
            // Ajout: J.Etheve
            // *****------------------------------------ ajout moyenne générale non coefficientée
            if ($affiche_deux_moy_gen == 1) {
                // Ligne moyenne générale coefficientée
                //bas du tableau des note et app si les affichage des moyennes ne sont pas affiché le bas du tableau ne seras pas affiché
                if ($tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne_general"][$classe_id] === '1') {
                    $X_note_moy_app = $tab_modele_pdf["X_note_app"][$classe_id];
                    $Y_note_moy_app = $tab_modele_pdf["Y_note_app"][$classe_id] + $tab_modele_pdf["hauteur_note_app"][$classe_id];
                    //-$tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id];
                    // On a remonté d'une ligne la moyenne générale classique
                    $Y_note_moy_app -= $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id];
                    $pdf->SetXY($X_note_moy_app, $Y_note_moy_app);
                    $pdf->SetFont('DejaVu', '', 10);
                    $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                    $pdf->Cell($tab_modele_pdf["largeur_matiere"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "Moy.gén.non coef.", 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                    $largeur_utilise = $tab_modele_pdf["largeur_matiere"][$classe_id];
                    // coefficient matière
                    if ($tab_modele_pdf["active_coef_moyenne"][$classe_id] === '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        //$pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "",1,0,'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        $pdf->SetFont('DejaVu', '', 10);
                        $info_tot_et_coef = $tab_bull['tot_points_eleve1'][$i] . "/" . $tab_bull['total_coef_eleve1'][$i];
                        $val = $pdf->GetStringWidth($info_tot_et_coef);
                        $taille_texte = $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                        $grandeur_texte = 'test';
                        $hauteur_tmp = 10;
                        while ($grandeur_texte != 'ok') {
                            if ($taille_texte < $val) {
                                $hauteur_tmp = $hauteur_tmp - 0.3;
                                $pdf->SetFont('DejaVu', '', $hauteur_tmp);
                                $val = $pdf->GetStringWidth($info_tot_et_coef);
                            } else {
                                $grandeur_texte = 'ok';
                            }
                        }
                        $grandeur_texte = 'test';
                        $pdf->Cell($tab_modele_pdf["largeur_coef_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $info_tot_et_coef, 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        $pdf->SetFont('DejaVu', '', 10);
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_coef_moyenne"][$classe_id];
                    }
                    // nombre de note
                    // 20081118
                    //if($tab_modele_pdf["active_nombre_note_case"][$classe_id]==='1') {
                    if ($tab_modele_pdf["active_nombre_note_case"][$classe_id] === '1' && $tab_modele_pdf["active_nombre_note"][$classe_id] != '1') {
                        $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                        $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                        $pdf->Cell($tab_modele_pdf["largeur_nombre_note"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], "", 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                        $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_nombre_note"][$classe_id];
                    }
                    $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                    $cpt_ordre = 0;
                    while (!empty($ordre_moyenne[$cpt_ordre])) {
                        //eleve
                        if ($tab_modele_pdf["active_moyenne_eleve"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'eleve') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFont('DejaVu', 'B', 10);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            // On a deux paramètres de couleur qui se croisent. On utilise une variable tierce.
                            $utilise_couleur = $tab_modele_pdf["couleur_moy_general"][$classe_id];
                            if ($tab_modele_pdf["active_reperage_eleve"][$classe_id] === '1') {
                                // Si on affiche une couleur spécifique pour les moyennes de l'élève,
                                // on utilise cette couleur ici aussi, quoi qu'il arrive
                                $pdf->SetFillColor($tab_modele_pdf["couleur_reperage_eleve1"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve2"][$classe_id], $tab_modele_pdf["couleur_reperage_eleve3"][$classe_id]);
                                $utilise_couleur = 1;
                            }
                            if ($tab_bull['moy_gen_eleve_noncoef'][$i] == "" || $tab_bull['moy_gen_eleve_noncoef'][$i] == "-") {
                                $val_tmp = "-";
                            } else {
                                //$val_tmp=present_nombre($tab_bull['moy_gen_eleve'][$i], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                //$val_tmp=$tab_bull['moy_gen_eleve'][$i];
                                $val_tmp = present_nombre(preg_replace("/,/", '.', $tab_bull['moy_gen_eleve_noncoef'][$i]), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                                /*
                                $tmp_fich=fopen("/tmp/test_moy_gen.txt","a+");
                                fwrite($tmp_fich,$tab_bull['eleve'][$i]['login']." present_nombre(\$tab_bull['moy_gen_eleve'][$i], \$tab_modele_pdf[\"arrondie_choix\"][$classe_id], \$tab_modele_pdf[\"nb_chiffre_virgule\"][$classe_id], \$tab_modele_pdf[\"chiffre_avec_zero\"][$classe_id])=present_nombre(".$tab_bull['moy_gen_eleve'][$i].", ".$tab_modele_pdf["arrondie_choix"][$classe_id].", ".$tab_modele_pdf["nb_chiffre_virgule"][$classe_id].",". $tab_modele_pdf["chiffre_avec_zero"][$classe_id].")=".present_nombre($tab_bull['moy_gen_eleve'][$i], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id])."\n");
                                	
                                fwrite($tmp_fich,$tab_bull['eleve'][$i]['login']." present_nombre(preg_replace("/,/",'.',\$tab_bull['moy_gen_eleve'][$i]), \$tab_modele_pdf[\"arrondie_choix\"][$classe_id], \$tab_modele_pdf[\"nb_chiffre_virgule\"][$classe_id], \$tab_modele_pdf[\"chiffre_avec_zero\"][$classe_id])=".present_nombre(preg_replace("/,/",'.',$tab_bull['moy_gen_eleve'][$i]), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id])."\n");
                                	
                                fclose($tmp_fich);
                                */
                            }
                            //$pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], present_nombre($tab_bull['moy_gen_eleve'][$i], $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]),1,0,'C',$utilise_couleur);
                            $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $val_tmp, 1, 0, 'C', $utilise_couleur);
                            $pdf->SetFont('DejaVu', '', 10);
                            $pdf->SetFillColor(0, 0, 0);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //classe
                        if ($tab_modele_pdf["active_moyenne_classe"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'classe') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFont('DejaVu', '', 8);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            /*
                            if( $total_coef_en_calcul != 0){
                            	$moyenne_classe = $total_moyenne_classe_en_calcul / $total_coef_en_calcul;
                            }
                            else{
                            	$moyenne_classe = '-';
                            }
                            */
                            if ($tab_bull['moy_generale_classe_noncoef'] == "" || $tab_bull['moy_generale_classe_noncoef'] == "-") {
                                $moyenne_classe = '-';
                            } else {
                                $moyenne_classe = present_nombre(preg_replace("/,/", '.', $tab_bull['moy_generale_classe_noncoef']), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]);
                            }
                            if ($moyenne_classe != '-') {
                                //$moyenne_classe=$tab_bull['moy_generale_classe'];
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $moyenne_classe, 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            } else {
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '-', 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            }
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //min
                        if ($tab_modele_pdf["active_moyenne_min"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'min') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFont('DejaVu', '', 8);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            /*
                            if($total_coef_en_calcul != 0 and $tab_modele_pdf["affiche_moyenne_mini_general"][$classe_id] === '1' ){
                            	$moyenne_min = $total_moyenne_min_en_calcul / $total_coef_en_calcul;
                            }
                            else{
                            	$moyenne_min = '-';
                            }
                            */
                            if ($tab_bull['moy_min_classe'] != '-') {
                                //$moyenne_min=$tab_moy_min_classe[$classe_id][$id_periode];
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], present_nombre(preg_replace("/,/", '.', $tab_bull['moy_min_classe_noncoef']), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]), 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            } else {
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '-', 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            }
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        //max
                        if ($tab_modele_pdf["active_moyenne_max"][$classe_id] === '1' and $tab_modele_pdf["active_moyenne"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'max') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFont('DejaVu', '', 8);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            /*
                            if($total_coef_en_calcul != 0 and $tab_modele_pdf["affiche_moyenne_maxi_general"][$classe_id] === '1' ){
                            	$moyenne_max = $total_moyenne_max_en_calcul / $total_coef_en_calcul;
                            } else {
                            	$moyenne_max = '-';
                            }
                            */
                            if ($tab_bull['moy_max_classe_noncoef'] != '-') {
                                $moyenne_max = $tab_bull['moy_max_classe_noncoef'];
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], present_nombre(preg_replace("/,/", '.', $tab_bull['moy_max_classe_noncoef']), $tab_modele_pdf["arrondie_choix"][$classe_id], $tab_modele_pdf["nb_chiffre_virgule"][$classe_id], $tab_modele_pdf["chiffre_avec_zero"][$classe_id]), 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            } else {
                                $pdf->Cell($tab_modele_pdf["largeur_d_une_moyenne"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '-', 1, 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            }
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_d_une_moyenne"][$classe_id];
                        }
                        // rang de l'élève
                        if ($tab_modele_pdf["active_rang"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'rang') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFont('DejaVu', '', 8);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            if ($tab_bull['rang_classe'][$i] != 0) {
                                $rang_a_afficher = $tab_bull['rang_classe'][$i] . '/' . $tab_bull['eff_classe'];
                            } else {
                                $rang_a_afficher = "";
                            }
                            $pdf->Cell($tab_modele_pdf["largeur_rang"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $rang_a_afficher, 'TLRB', 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_rang"][$classe_id];
                        }
                        // graphique de niveau
                        if ($tab_modele_pdf["active_graphique_niveau"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'niveau') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            // placement de l'élève dans le graphique de niveau
                            //if ($tab_bull['moy_gen_eleve'][$i]!="") {
                            if ($tab_bull['moy_gen_eleve'][$i] != "" && $tab_bull['moy_gen_eleve'][$i] != "-") {
                                /*
                                if ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<5) { $place_eleve=5;}
                                if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=5) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<8))  { $place_eleve=4;}
                                if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=8) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<10)) { $place_eleve=3;}
                                if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=10) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<12)) {$place_eleve=2;}
                                if (($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=12) and ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']<15)) { $place_eleve=1;}
                                if ($info_bulletin[$ident_eleve_aff][$id_periode]['moy_general_eleve']>=15) { $place_eleve=0;}
                                */
                                //$place_eleve=$tab_bull['place_eleve_classe'][$i];
                                $place_eleve = $tab_bull['place_eleve_classe'][$i] - 1;
                            }
                            $data_grap_classe[0] = $tab_bull['quartile1_classe_gen'];
                            $data_grap_classe[1] = $tab_bull['quartile2_classe_gen'];
                            $data_grap_classe[2] = $tab_bull['quartile3_classe_gen'];
                            $data_grap_classe[3] = $tab_bull['quartile4_classe_gen'];
                            $data_grap_classe[4] = $tab_bull['quartile5_classe_gen'];
                            $data_grap_classe[5] = $tab_bull['quartile6_classe_gen'];
                            if (array_sum($data_grap_classe) != 0) {
                                //$pdf->DiagBarre($X_note_moy_app+$largeur_utilise, $Y_note_moy_app, $tab_modele_pdf["largeur_niveau"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $data_grap_classe[$id_periode][$id_classe_selection], $place_eleve);
                                $pdf->DiagBarre($X_note_moy_app + $largeur_utilise, $Y_note_moy_app, $tab_modele_pdf["largeur_niveau"][$classe_id], $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], $data_grap_classe, $place_eleve);
                            }
                            $place_eleve = '';
                            // on vide la variable
                            $largeur_utilise = $largeur_utilise + $tab_modele_pdf["largeur_niveau"][$classe_id];
                        }
                        //appréciation
                        if ($tab_modele_pdf["active_appreciation"][$classe_id] === '1' and $ordre_moyenne[$cpt_ordre] === 'appreciation') {
                            $pdf->SetXY($X_note_moy_app + $largeur_utilise, $Y_note_moy_app);
                            $pdf->SetFillColor($tab_modele_pdf["couleur_moy_general1"][$classe_id], $tab_modele_pdf["couleur_moy_general2"][$classe_id], $tab_modele_pdf["couleur_moy_general3"][$classe_id]);
                            $pdf->Cell($largeur_appreciation, $tab_modele_pdf["hauteur_entete_moyenne_general"][$classe_id], '', 'TLRB', 0, 'C', $tab_modele_pdf["couleur_moy_general"][$classe_id]);
                            $largeur_utilise = $largeur_utilise + $largeur_appreciation;
                        }
                        $cpt_ordre = $cpt_ordre + 1;
                    }
                    $largeur_utilise = 0;
                    // fin de boucle d'ordre
                    $pdf->SetFillColor(0, 0, 0);
                }
            }
            // *****-------------------------------------fin moyenne générale non coefficientée ---
            //================
        }
        // =============== bloc absence ==================
        if ($tab_modele_pdf["active_bloc_absence"][$classe_id] === '1') {
            $pdf->SetXY($tab_modele_pdf["X_absence"][$classe_id], $tab_modele_pdf["Y_absence"][$classe_id]);
            $origine_Y_absence = $tab_modele_pdf["Y_absence"][$classe_id];
            $pdf->SetFont('DejaVu', 'I', 8);
            $info_absence = '';
            // 20130215
            /*
            if(($tab_modele_pdf["afficher_abs_tot"][$classe_id]==='1')||
            ($tab_modele_pdf["afficher_abs_nj"][$classe_id]==='1')) {
            */
            if ($tab_modele_pdf["afficher_abs_tot"][$classe_id] == '1') {
                if ($tab_bull['eleve'][$i]['eleve_absences'] != '?') {
                    if ($tab_bull['eleve'][$i]['eleve_absences'] == '0') {
                        $info_absence = "<i>Aucune demi-journée d'absence</i>.";
                    } else {
                        $info_absence = "<i>Nombre de demi-journées d'absence ";
                        if ($tab_modele_pdf["afficher_abs_nj"][$classe_id] == '1') {
                            if ($tab_bull['eleve'][$i]['eleve_nj'] == '0' or $tab_bull['eleve'][$i]['eleve_nj'] == '?') {
                                $info_absence = $info_absence . "justifiées ";
                            }
                            $info_absence = $info_absence . ": </i><b>" . $tab_bull['eleve'][$i]['eleve_absences'] . "</b>";
                            if ($tab_bull['eleve'][$i]['eleve_nj'] != '0' and $tab_bull['eleve'][$i]['eleve_nj'] != '?') {
                                $info_absence = $info_absence . " (dont <b>" . $tab_bull['eleve'][$i]['eleve_nj'] . "</b> non justifiée";
                                if ($tab_bull['eleve'][$i]['eleve_nj'] != '1') {
                                    $info_absence = $info_absence . "s";
                                }
                                $info_absence = $info_absence . ")";
                            }
                        } else {
                            $info_absence = $info_absence . ": </i><b>" . $tab_bull['eleve'][$i]['eleve_absences'] . "</b>";
                        }
                        $info_absence = $info_absence . ".";
                    }
                }
            } elseif ($tab_modele_pdf["afficher_abs_nj"][$classe_id] == '1') {
                if ($tab_bull['eleve'][$i]['eleve_nj'] == '0') {
                    $info_absence = "<i>Aucune absence non justifiée</i>.";
                } else {
                    $info_absence = "<i>Nombre de demi-journées d'absence non justifiées ";
                    $info_absence .= ": </i><b>" . $tab_bull['eleve'][$i]['eleve_nj'] . ".</b>";
                }
            }
            if ($tab_modele_pdf["afficher_abs_ret"][$classe_id] == '1') {
                if ($tab_bull['eleve'][$i]['eleve_retards'] != '0' and $tab_bull['eleve'][$i]['eleve_retards'] != '?') {
                    $info_absence = $info_absence . "<i> Nombre de retards : </i><b>" . $tab_bull['eleve'][$i]['eleve_retards'] . ".</b>";
                }
            }
            if ($tab_modele_pdf["afficher_abs_cpe"][$classe_id] == '1' && isset($tab_bull['eleve'][$i]['cperesp_civilite']) && isset($tab_bull['eleve'][$i]['cperesp_login'])) {
                $pdf->SetFont('DejaVu', '', 8);
                // C.P.E.
                $info_absence = $info_absence . " (" . ucfirst($gepi_cpe_suivi) . " chargé";
                if ($tab_bull['eleve'][$i]['cperesp_civilite'] != "M.") {
                    $info_absence = $info_absence . "e";
                }
                /*
                $sql="SELECT civilite FROM utilisateurs WHERE login='******'";
                $res_civi=mysql_query($sql);
                if(mysql_num_rows($res_civi)>0){
                	$lig_civi=mysql_fetch_object($res_civi);
                	if($lig_civi->civilite!="M."){
                		$info_absence = $info_absence."e";
                	}
                }
                */
                $info_absence = $info_absence . " du suivi : <i>" . affiche_utilisateur($tab_bull['eleve'][$i]['cperesp_login'], $tab_bull['id_classe']) . "</i>)";
            }
            //$pdf->MultiCellTag($tab_modele_pdf["largeur_cadre_absences"][$classe_id], 5, ($info_absence), '', 'J', '');
            //$pdf->ext_MultiCellTag($tab_modele_pdf["largeur_cadre_absences"][$classe_id], 5, $info_absence, '', 'J', '');
            $taille_max_police = 8;
            $taille_min_police = ceil($taille_max_police / 3);
            $largeur_dispo = $tab_modele_pdf["largeur_cadre_absences"][$classe_id];
            $h_cell = 5;
            cell_ajustee($info_absence, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
            //=========================
            // MODIF: boireaus 20081220
            // Désactivation de ce qui provoquait un décalage progressif du bloc Avis du conseil,...
            //if ( isset($Y_avis_cons_init) ) { $tab_modele_pdf["Y_avis_cons"][$classe_id] = $Y_avis_cons_init; }
            //if ( isset($Y_sign_chef_init) ) { $tab_modele_pdf["Y_sign_chef"][$classe_id] = $Y_sign_chef_init; }
            //=========================
            // Il y a une ligne pour les absences, retards,... donc on compte une ligne (+0.5) de décalage pour le bloc Avis du conseil et celui de la signature du chefetab
            //if ( !isset($Y_avis_cons_init) ) { $Y_avis_cons_init = $tab_modele_pdf["Y_avis_cons"][$classe_id] + 0.5; }
            //if ( !isset($Y_sign_chef_init) ) { $Y_sign_chef_init = $tab_modele_pdf["Y_sign_chef"][$classe_id] + 0.5; }
            $Y_avis_cons_init = $tab_modele_pdf["Y_avis_cons"][$classe_id] + 0.5;
            $Y_sign_chef_init = $tab_modele_pdf["Y_sign_chef"][$classe_id] + 0.5;
            //=========================
            // MODIF: boireaus 20081220
            // Désactivation de ce qui provoquait une réduction progressive de la hauteur du bloc Avis du conseil,...
            //if ( isset($hauteur_avis_cons_init) ) { $tab_modele_pdf["hauteur_avis_cons"][$classe_id] = $hauteur_avis_cons_init; }
            //if ( isset($hauteur_sign_chef_init) ) { $tab_modele_pdf["hauteur_sign_chef"][$classe_id] = $hauteur_sign_chef_init; }
            //=========================
            //if ( !isset($hauteur_avis_cons_init) ) { $hauteur_avis_cons_init = $tab_modele_pdf["hauteur_avis_cons"][$classe_id] - 0.5; }
            //if ( !isset($hauteur_sign_chef_init) ) { $hauteur_sign_chef_init = $tab_modele_pdf["hauteur_sign_chef"][$classe_id] - 0.5; }
            $hauteur_avis_cons_init = $tab_modele_pdf["hauteur_avis_cons"][$classe_id] - 0.5;
            $hauteur_sign_chef_init = $tab_modele_pdf["hauteur_sign_chef"][$classe_id] - 0.5;
            $hauteur_pris_app_abs = 0;
            if ($tab_bull['eleve'][$i]['appreciation_absences'] != "") {
                // supprimer les espaces
                $text_absences_appreciation = trim(str_replace(array("\r\n", "\r", "\n"), ' ', unhtmlentities($tab_bull['eleve'][$i]['appreciation_absences'])));
                $info_absence_appreciation = "<i>Avis " . ucfirst($gepi_cpe_suivi) . " :</i> <b>" . $text_absences_appreciation . "</b>";
                $text_absences_appreciation = '';
                $pdf->SetXY($tab_modele_pdf["X_absence"][$classe_id], $tab_modele_pdf["Y_absence"][$classe_id] + 4);
                $pdf->SetFont('DejaVu', '', 8);
                //$pdf->MultiCellTag(200, 3, ($info_absence_appreciation), '', 'J', '');
                //$pdf->MultiCellTag($tab_modele_pdf["largeur_cadre_absences"][$classe_id], 3, ($info_absence_appreciation), '', 'J', '');
                //$pdf->ext_MultiCellTag($tab_modele_pdf["largeur_cadre_absences"][$classe_id], 3, ($info_absence_appreciation), '', 'J', '');
                $val = $pdf->GetStringWidth($info_absence_appreciation);
                // nombre de lignes que prend la remarque cpe
                //Arrondi à l'entier supérieur : ceil()
                $nb_ligne = 1;
                $nb_ligne = ceil($val / 200);
                $hauteur_pris = $nb_ligne * 3;
                $taille_max_police = 8;
                $taille_min_police = ceil($taille_max_police / 3);
                $largeur_dispo = $tab_modele_pdf["largeur_cadre_absences"][$classe_id];
                $h_cell = $hauteur_pris;
                cell_ajustee($info_absence_appreciation, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
                $hauteur_pris_app_abs = $hauteur_pris;
                //$tab_modele_pdf["Y_avis_cons"][$classe_id] = $tab_modele_pdf["Y_avis_cons"][$classe_id] + $hauteur_pris;
                $Y_avis_cons_init = $Y_avis_cons_init + $hauteur_pris;
                //$tab_modele_pdf["hauteur_avis_cons"][$classe_id] = $tab_modele_pdf["hauteur_avis_cons"][$classe_id] - ( $hauteur_pris + 0.5 );
                $hauteur_avis_cons_init = $hauteur_avis_cons_init - ($hauteur_pris + 0.5);
                //$tab_modele_pdf["Y_sign_chef"][$classe_id] = $tab_modele_pdf["Y_sign_chef"][$classe_id] + $hauteur_pris;
                $Y_sign_chef_init = $Y_sign_chef_init + $hauteur_pris;
                //$tab_modele_pdf["hauteur_sign_chef"][$classe_id] = $tab_modele_pdf["hauteur_sign_chef"][$classe_id] - ( $hauteur_pris + 0.5 );
                $hauteur_sign_chef_init = $hauteur_sign_chef_init - ($hauteur_pris + 0.5);
                $hauteur_pris = 0;
            } else {
                if ($Y_avis_cons_init != $tab_modele_pdf["Y_avis_cons"][$classe_id]) {
                    //$tab_modele_pdf["Y_avis_cons"][$classe_id] = $tab_modele_pdf["Y_avis_cons"][$classe_id] - $hauteur_pris;
                    $Y_avis_cons_init = $Y_avis_cons_init - $hauteur_pris;
                    //$tab_modele_pdf["hauteur_avis_cons"][$classe_id] = $tab_modele_pdf["hauteur_avis_cons"][$classe_id] + $hauteur_pris;
                    $hauteur_avis_cons_init = $hauteur_avis_cons_init + $hauteur_pris;
                    //$tab_modele_pdf["Y_sign_chef"][$classe_id] = $tab_modele_pdf["Y_sign_chef"][$classe_id] - $hauteur_pris;
                    $Y_sign_chef_init = $Y_sign_chef_init - $hauteur_pris;
                    //$tab_modele_pdf["hauteur_sign_chef"][$classe_id] = $tab_modele_pdf["hauteur_sign_chef"][$classe_id] + $hauteur_pris;
                    $hauteur_sign_chef_init = $hauteur_sign_chef_init + $hauteur_pris;
                    $hauteur_pris = 0;
                }
            }
            $info_absence = '';
            $info_absence_appreciation = '';
            $pdf->SetFont('DejaVu', '', 10);
        }
        // sinon, si le bloc absence n'est pas activé
        if ($tab_modele_pdf["active_bloc_absence"][$classe_id] != '1') {
            //=========================
            // MODIF: boireaus 20081220
            // Désactivation de ce qui provoquait un décalage progressif du bloc Avis du conseil,...
            //if ( isset($Y_avis_cons_init) ) { $tab_modele_pdf["Y_avis_cons"][$classe_id] = $Y_avis_cons_init; }
            //if ( isset($Y_sign_chef_init) ) { $tab_modele_pdf["Y_sign_chef"][$classe_id] = $Y_sign_chef_init; }
            //=========================
            //if ( !isset($Y_avis_cons_init) ) { $Y_avis_cons_init = $tab_modele_pdf["Y_avis_cons"][$classe_id]; }
            //if ( !isset($Y_sign_chef_init) ) { $Y_sign_chef_init = $tab_modele_pdf["Y_sign_chef"][$classe_id]; }
            $Y_avis_cons_init = $tab_modele_pdf["Y_avis_cons"][$classe_id];
            $Y_sign_chef_init = $tab_modele_pdf["Y_sign_chef"][$classe_id];
            $hauteur_avis_cons_init = $tab_modele_pdf["hauteur_avis_cons"][$classe_id] - 0.5;
            $hauteur_sign_chef_init = $tab_modele_pdf["hauteur_sign_chef"][$classe_id] - 0.5;
        }
        // fin
        //=========================
        // MODIF: boireaus 20081220
        /*
        if($Y_avis_cons_init!=$tab_modele_pdf["Y_avis_cons"][$classe_id]) {
        	$Y_avis_cons[$classe_id] = $tab_modele_pdf["Y_avis_cons"][$classe_id] + 0.5;
        	$Y_sign_chef[$classe_id] = $tab_modele_pdf["Y_sign_chef"][$classe_id] + 0.5;
        }
        */
        //=========================
        // ================ bloc avis du conseil de classe =================
        if ($tab_modele_pdf["active_bloc_avis_conseil"][$classe_id] === '1') {
            if ($tab_modele_pdf["cadre_avis_cons"][$classe_id] != 0) {
                //$pdf->Rect($tab_modele_pdf["X_avis_cons"][$classe_id], $tab_modele_pdf["Y_avis_cons"][$classe_id], $tab_modele_pdf["longeur_avis_cons"][$classe_id], $tab_modele_pdf["hauteur_avis_cons"][$classe_id], 'D');
                $pdf->Rect($tab_modele_pdf["X_avis_cons"][$classe_id], $Y_avis_cons_init, $tab_modele_pdf["longeur_avis_cons"][$classe_id], $hauteur_avis_cons_init, 'D');
            }
            //$pdf->SetXY($tab_modele_pdf["X_avis_cons"][$classe_id],$tab_modele_pdf["Y_avis_cons"][$classe_id]);
            $pdf->SetXY($tab_modele_pdf["X_avis_cons"][$classe_id], $Y_avis_cons_init);
            if ($tab_modele_pdf["taille_titre_bloc_avis_conseil"][$classe_id] != '' and $tab_modele_pdf["taille_titre_bloc_avis_conseil"][$classe_id] < '15') {
                $taille = $tab_modele_pdf["taille_titre_bloc_avis_conseil"][$classe_id];
            } else {
                $taille = '10';
            }
            $pdf->SetFont('DejaVu', 'I', $taille);
            if ($tab_modele_pdf["titre_bloc_avis_conseil"][$classe_id] != '') {
                $tt_avis = $tab_modele_pdf["titre_bloc_avis_conseil"][$classe_id];
            } else {
                $tt_avis = 'Avis du Conseil de classe :';
            }
            $pdf->Cell($tab_modele_pdf["longeur_avis_cons"][$classe_id], 5, $tt_avis, 0, 2, '');
            //$pdf->SetXY($tab_modele_pdf["X_avis_cons"][$classe_id]+2.5,$tab_modele_pdf["Y_avis_cons"][$classe_id]+5);
            $pdf->SetXY($tab_modele_pdf["X_avis_cons"][$classe_id] + 2.5, $Y_avis_cons_init + 5);
            $pdf->SetFont('DejaVu', '', 10);
            $texteavis = $tab_bull['avis'][$i];
            // ***** AJOUT POUR LES MENTIONS *****
            //$textmention = $tab_bull['id_mention'][$i];
            if (!isset($tableau_des_mentions_sur_le_bulletin) || !is_array($tableau_des_mentions_sur_le_bulletin) || count($tableau_des_mentions_sur_le_bulletin) == 0) {
                $tableau_des_mentions_sur_le_bulletin = get_mentions($classe_id);
            }
            if (isset($tableau_des_mentions_sur_le_bulletin[$tab_bull['id_mention'][$i]])) {
                $textmention = $tableau_des_mentions_sur_le_bulletin[$tab_bull['id_mention'][$i]];
            } else {
                $textmention = "-";
            }
            // ***** FIN DE L'AJOUT POUR LES MENTIONS *****
            //$avec_coches_mentions="y";
            //if($avec_coches_mentions=="y") {
            if ($tab_modele_pdf["affich_coches_mentions"][$classe_id] != "n") {
                //$marge_droite_avis_cons=40;
                if (count($tableau_des_mentions_sur_le_bulletin) > 0) {
                    $marge_droite_avis_cons = 40;
                } else {
                    $marge_droite_avis_cons = 5;
                }
            } else {
                $marge_droite_avis_cons = 5;
                //if(($textmention!="")&&($textmention!="-")) {
                if ($tab_modele_pdf["affich_mentions"][$classe_id] != "n" && $textmention != "" && $textmention != "-") {
                    //$texteavis.="\n".traduction_mention($textmention);
                    if ($use_cell_ajustee == "n") {
                        if ($tab_modele_pdf["affich_intitule_mentions"][$classe_id] != "n") {
                            $texteavis .= "\n" . ucfirst($gepi_denom_mention) . " : ";
                        }
                        $texteavis .= $textmention;
                    } else {
                        if ($tab_modele_pdf["affich_intitule_mentions"][$classe_id] != "n") {
                            $texteavis .= "\n" . "<b>" . ucfirst($gepi_denom_mention) . " :</b> ";
                        }
                        $texteavis .= $textmention;
                    }
                }
            }
            if ($use_cell_ajustee == "n") {
                $pdf->drawTextBox($texteavis, $tab_modele_pdf["longeur_avis_cons"][$classe_id] - $marge_droite_avis_cons, $hauteur_avis_cons_init - 10, 'J', 'M', 0);
            } else {
                $texte = $texteavis;
                $taille_max_police = 10;
                $taille_min_police = ceil($taille_max_police / 3);
                $largeur_dispo = $tab_modele_pdf["longeur_avis_cons"][$classe_id] - $marge_droite_avis_cons;
                $h_cell = $hauteur_avis_cons_init - 10;
                cell_ajustee($texte, $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
            }
            $X_pp_aff = $tab_modele_pdf["X_avis_cons"][$classe_id];
            //$Y_pp_aff=$tab_modele_pdf["Y_avis_cons"][$classe_id]+$tab_modele_pdf["hauteur_avis_cons"][$classe_id]-5;
            $Y_pp_aff = $Y_avis_cons_init + $hauteur_avis_cons_init - 5;
            $pdf->SetXY($X_pp_aff, $Y_pp_aff);
            if ($tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id] != '' and is_numeric($tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id]) and $tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id] > 0 and $tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id] < '15') {
                $taille = $tab_modele_pdf["taille_profprincipal_bloc_avis_conseil"][$classe_id];
            } else {
                $taille = '10';
            }
            $pdf->SetFont('DejaVu', 'I', $taille);
            // Le nom du professeur principal
            $pp_classe[$i] = "";
            //if(isset($tab_bull['eleve'][$i]['pp']['login'])) {
            if ($tab_modele_pdf["afficher_tous_profprincipaux"][$classe_id] == 1) {
                $index_pp = 'pp_classe';
            } else {
                $index_pp = 'pp';
            }
            if (isset($tab_bull['eleve'][$i][$index_pp][0]['login'])) {
                $pp_classe[$i] = "<b>" . ucfirst($tab_bull['gepi_prof_suivi']) . "</b> : ";
                $pp_classe[$i] .= "<i>" . affiche_utilisateur($tab_bull['eleve'][$i][$index_pp][0]['login'], $tab_bull['eleve'][$i]['id_classe']) . "</i>";
                for ($i_pp = 1; $i_pp < count($tab_bull['eleve'][$i][$index_pp]); $i_pp++) {
                    $pp_classe[$i] .= ", ";
                    $pp_classe[$i] .= "<i>" . affiche_utilisateur($tab_bull['eleve'][$i][$index_pp][$i_pp]['login'], $tab_bull['eleve'][$i]['id_classe']) . "</i>";
                }
            } else {
                $pp_classe[$i] = "";
            }
            //$pdf->MultiCellTag(200, 5, ($pp_classe[$i]), '', 'J', '');
            //$pdf->ext_MultiCellTag(200, 5, ($pp_classe[$i]), '', 'J', '');
            $taille_max_police = $taille;
            $taille_min_police = ceil($taille_max_police / 3);
            //$largeur_dispo=200;
            $largeur_dispo = $tab_modele_pdf["longeur_avis_cons"][$classe_id];
            $h_cell = 5;
            cell_ajustee($pp_classe[$i], $pdf->GetX(), $pdf->GetY(), $largeur_dispo, $h_cell, $taille_max_police, $taille_min_police, '');
        }
        //if($avec_coches_mentions=="y") {
        if ($tab_modele_pdf["affich_coches_mentions"][$classe_id] != "n") {
            // ***** AJOUT POUR LES MENTIONS *****
            // Essai pour ajouter un bloc renseignant les mentions du CC
            // A COMPLETER...
            $pdf->SetFont('DejaVu', '', 9);
            $X_pp_aff = $tab_modele_pdf["X_avis_cons"][$classe_id] + $tab_modele_pdf["longeur_avis_cons"][$classe_id] - 35;
            $Y_pp_aff = $tab_modele_pdf["Y_avis_cons"][$classe_id] + 5;
            $pdf->SetXY($X_pp_aff, $Y_pp_aff);
            /*
            $pdf->Cell(35,4, 'Félicitations      ',0,2,'R');
            $pdf->Cell(35,4, 'Mention honorable      ',0,2,'R');
            $pdf->Cell(35,4, 'Encouragements      ',0,2,'R');
            */
            if (!isset($tableau_des_mentions_sur_le_bulletin) || !is_array($tableau_des_mentions_sur_le_bulletin) || count($tableau_des_mentions_sur_le_bulletin) == 0) {
                $tableau_des_mentions_sur_le_bulletin = get_mentions($classe_id);
            }
            //for($loop_mention=0;$loop_mention<count($tableau_des_mentions_sur_le_bulletin);$loop_mention++) {
            $loop_mention = 0;
            foreach ($tableau_des_mentions_sur_le_bulletin as $key_mention => $value_mention) {
                //$pdf->Cell(35,4, $value_mention,0,2,'R');
                $pdf->Cell(35, 4, $value_mention, 0, 2, 'L');
                $loop_mention++;
            }
            /*
            $pdf->Rect($X_pp_aff+30, $Y_pp_aff+0.3, 2.4, 3);
            $pdf->Rect($X_pp_aff+30, $Y_pp_aff+4.3, 2.4, 3);
            $pdf->Rect($X_pp_aff+30, $Y_pp_aff+8.3, 2.4, 3);
            $pdf->Rect($X_pp_aff, $Y_pp_aff+0.1, 0.01, 12);
            */
            //for($loop_mention=0;$loop_mention<count($tableau_des_mentions_sur_le_bulletin);$loop_mention++) {
            $loop_mention = 0;
            foreach ($tableau_des_mentions_sur_le_bulletin as $key_mention => $value_mention) {
                $pdf->Rect($X_pp_aff + 30, $Y_pp_aff + 4 * $loop_mention + 0.3, 2.4, 3);
                if ($key_mention == $tab_bull['id_mention'][$i]) {
                    $pdf->SetXY($X_pp_aff - 1.73, $Y_pp_aff + $loop_mention * 4);
                    $pdf->Cell(35, 4, 'X', 0, 2, 'R');
                }
                $loop_mention++;
            }
            $pdf->Rect($X_pp_aff, $Y_pp_aff + 0.1, 0.01, $loop_mention * 4);
            /*
            // Si félicitations (à modifier...)
            if($textmention=="F") {
            	$pdf->SetXY($X_pp_aff-1.73,$Y_pp_aff);
            	$pdf->Cell(35,4, 'X',0,2,'R');
            }
            // Si mention honorable (à modifier...)
            if($textmention=="M") {
            	$pdf->SetXY($X_pp_aff-1.73,$Y_pp_aff+4);
            	$pdf->Cell(35,4, 'X',0,2,'R');
            }
            // Si encouragements (à modifier...)
            if($textmention=="E") {
            	$pdf->SetXY($X_pp_aff-1.73,$Y_pp_aff+8);
            	$pdf->Cell(35,4, 'X',0,2,'R');
            }
            */
            // Fin de l'essai
            // ***** FIN DE L'AJOUT POUR LES MENTIONS *****
        }
        // ======================= bloc du président du conseil de classe ================
        if ($tab_modele_pdf["active_bloc_chef"][$classe_id] === '1') {
            if ($tab_modele_pdf["cadre_sign_chef"][$classe_id] != 0) {
                //$pdf->Rect($tab_modele_pdf["X_sign_chef"][$classe_id], $tab_modele_pdf["Y_sign_chef"][$classe_id], $tab_modele_pdf["longeur_sign_chef"][$classe_id], $tab_modele_pdf["hauteur_sign_chef"][$classe_id], 'D');
                $pdf->Rect($tab_modele_pdf["X_sign_chef"][$classe_id], $Y_sign_chef_init, $tab_modele_pdf["longeur_sign_chef"][$classe_id], $hauteur_sign_chef_init, 'D');
            }
            //$pdf->SetXY($tab_modele_pdf["X_sign_chef"][$classe_id],$tab_modele_pdf["Y_sign_chef"][$classe_id]);
            $pdf->SetXY($tab_modele_pdf["X_sign_chef"][$classe_id], $Y_sign_chef_init);
            /*
            // 20120715
            // Si une image de signature doit être insérée...
            $tmp_fich=getSettingValue('fichier_signature');
            $fich_sign = '../backup/'.getSettingValue('backup_directory').'/'.$tmp_fich;
            //echo "\$fich_sign=$fich_sign<br />\n";
            if($tab_modele_pdf["signature_img"][$classe_id]==='1' and ($tmp_fich!='') and file_exists($fich_sign))
            {
            	$sql="SELECT 1=1 FROM droits_acces_fichiers WHERE fichier='signature_img' AND ((identite='".$_SESSION['statut']."' AND type='statut') OR (identite='".$_SESSION['login']."' AND type='individu'))";
            	$test=mysql_query($sql);
            	if(mysql_num_rows($test)>0) {
            */
            // 20130719
            if (isset($signature_bull[$tab_bull['id_classe']]) && $signature_bull[$tab_bull['id_classe']] != "" && file_exists($signature_bull[$tab_bull['id_classe']])) {
                $fich_sign = $signature_bull[$tab_bull['id_classe']];
                $X_sign = $tab_modele_pdf["X_sign_chef"][$classe_id];
                $Y_sign = $Y_sign_chef_init;
                $largeur_dispo = $tab_modele_pdf["longeur_sign_chef"][$classe_id] - 10;
                $hauteur_dispo = $hauteur_sign_chef_init - 10;
                /*
                echo "\$tab_modele_pdf[\"longeur_sign_chef\"][$classe_id]=".$tab_modele_pdf["longeur_sign_chef"][$classe_id]."<br />\n";
                echo "\$hauteur_sign_chef_init=".$hauteur_sign_chef_init."<br />\n";
                
                $valeur=redimensionne_image($fich_sign, $largeur_dispo, );
                $L_sign = $valeur[0];
                $H_sign = $valeur[1];
                */
                $tmp_dim_photo = getimagesize($fich_sign);
                $ratio_l = $tmp_dim_photo[0] / $largeur_dispo;
                $ratio_h = $tmp_dim_photo[1] / $hauteur_dispo;
                if ($ratio_l > $ratio_h) {
                    $L_sign = $largeur_dispo;
                    $H_sign = $largeur_dispo * $tmp_dim_photo[1] / $tmp_dim_photo[0];
                } else {
                    $H_sign = $hauteur_dispo;
                    $L_sign = $hauteur_dispo * $tmp_dim_photo[0] / $tmp_dim_photo[1];
                }
                /*
                echo "\$X_sign=$X_sign<br />\n";
                echo "\$Y_sign=$Y_sign<br />\n";
                echo "\$L_sign=$L_sign<br />\n";
                echo "\$H_sign=$H_sign<br />\n";
                */
                $X_sign += ($tab_modele_pdf["longeur_sign_chef"][$classe_id] - $L_sign) / 2;
                $Y_sign += ($hauteur_sign_chef_init - $H_sign) / 2;
                $tmp_dim_photo = getimagesize($fich_sign);
                if (isset($tmp_dim_photo[2]) && $tmp_dim_photo[2] == 2) {
                    //$pdf->Image($fich_sign, $X_sign, $Y_sign, $L_sign, $H_sign);
                    $pdf->Image($fich_sign, round($X_sign), round($Y_sign), round($L_sign), round($H_sign));
                }
                //}
            }
            $pdf->SetFont('DejaVu', '', 10);
            if ($tab_modele_pdf["affichage_haut_responsable"][$classe_id] === '1') {
                if ($tab_modele_pdf["affiche_fonction_chef"][$classe_id] === '1') {
                    if ($tab_modele_pdf["taille_texte_fonction_chef"][$classe_id] != '' and $tab_modele_pdf["taille_texte_fonction_chef"][$classe_id] != '0' and $tab_modele_pdf["taille_texte_fonction_chef"][$classe_id] < '15') {
                        $taille = $tab_modele_pdf["taille_texte_fonction_chef"][$classe_id];
                    } else {
                        $taille = '10';
                    }
                    $pdf->SetFont('DejaVu', 'B', $taille);
                    $pdf->MultiCell($tab_modele_pdf["longeur_sign_chef"][$classe_id], 5, $tab_bull['formule'], 0, 2, '');
                    $pdf->SetX($tab_modele_pdf["X_sign_chef"][$classe_id]);
                }
                if ($tab_modele_pdf["taille_texte_identitee_chef"][$classe_id] != '' and $tab_modele_pdf["taille_texte_identitee_chef"][$classe_id] != '0' and $tab_modele_pdf["taille_texte_identitee_chef"][$classe_id] < '15') {
                    $taille = $tab_modele_pdf["taille_texte_identitee_chef"][$classe_id];
                } else {
                    $taille_avis = '8';
                }
                $pdf->SetFont('DejaVu', 'I', $taille);
                $pdf->MultiCell($tab_modele_pdf["longeur_sign_chef"][$classe_id], 5, $tab_bull['suivi_par'], 0, 2, '');
            } else {
                //$pdf->MultiCell($longeur_sign_chef[$classe_id],5, "Visa du Chef d'établissement\nou de son délégué",0,2,'');
                $pdf->MultiCell($tab_modele_pdf["longeur_sign_chef"][$classe_id], 5, "Visa du Chef d'établissement\nou de son délégué", 0, 2, '');
                //$pdf->ext_MultiCell($tab_modele_pdf["longeur_sign_chef"][$classe_id],5, ("Visa du Chef d'établissement\nou de son délégué"),0,2,'');
            }
        }
        //		}
        // Insertion du relevé de notes si réclamé:
        /*
        if(count($tab_rel)!=0) {
        	releve_pdf($tab_rel,$i);
        }
        */
        if (count($tab_rel) != 0) {
            $temoin_releve_trouve = 'n';
            if (isset($tab_rel['eleve'])) {
                //echo "\$tab_bull['eleve'][$i]['login']="******"<br />";
                //for($k=0;$k<count($tab_rel['eleve']);$k++) {
                //for($k=0;$k<$tab_bull['eff_total_classe'];$k++) {
                for ($k = 0; $k < count($tab_rel['eleve']); $k++) {
                    //echo "\$tab_rel['eleve'][$k]['login']="******"<br />";
                    if (isset($tab_rel['eleve'][$k]['login'])) {
                        if ($tab_rel['eleve'][$k]['login'] == $tab_bull['eleve'][$i]['login']) {
                            releve_pdf($tab_rel, $k);
                            $temoin_releve_trouve = 'y';
                            break;
                        }
                    }
                }
            }
            /*
            else {
            	echo "<p style='color:red;'>Il semble que le tableau des relevés de notes soit vide.</p>\n";
            }
            */
            if ($temoin_releve_trouve == 'n') {
                $pdf->AddPage("P");
                $pdf->SetFontSize(10);
                $pdf->SetXY(20, 20);
                $pdf->SetFont('DejaVu', 'B', 14);
                $pdf->Cell(90, 7, "Relevé de notes non trouvé pour " . my_strtoupper($tab_bull['eleve'][$i]['nom']) . " " . casse_mot($tab_bull['eleve'][$i]['prenom'], 'majf2'), 0, 2, '');
            }
        }
    }
}
示例#2
0
			$temoin_avis_present="n";
			if(mysqli_num_rows($res_avis)>0) {
				$titre_bulle="Avis du Conseil de classe";

				$texte_bulle="<table class='boireaus boireaus_alt' style='margin:2px;' width='99%' summary='Avis'>\n";
				while($lig_avis=mysqli_fetch_object($res_avis)) {
					//==========================================================
					// AJOUT: boireaus 20080218
					//        Dispositif de restriction des accès aux appréciations pour les comptes responsables/eleves
					//if($tab_acces_app[$lig_avis->periode]=="y") {
					if(($tab_acces_app[$lig_avis->periode]=="y")&&($lig_avis->avis!="")) {
					//==========================================================
						$texte_bulle.="<tr><td style='font-weight:bold;'>$lig_avis->periode</td><td style='text-align:center;'>".htmlspecialchars($lig_avis->avis);

						if((!isset($tableau_des_mentions_sur_le_bulletin))||(!is_array($tableau_des_mentions_sur_le_bulletin))||(count($tableau_des_mentions_sur_le_bulletin)==0)) {
							$tableau_des_mentions_sur_le_bulletin=get_mentions();
						}

						if(isset($tableau_des_mentions_sur_le_bulletin[$lig_avis->id_mention])) {
							$texte_bulle.="<br />\n";
							$texte_bulle.="<b>".ucfirst($gepi_denom_mention)."</b> : ";
							$texte_bulle.=$tableau_des_mentions_sur_le_bulletin[$lig_avis->id_mention]."\n";
						}

						$texte_bulle.="</td></tr>\n";
						//==========================================================
						// AJOUT: boireaus 20080218
						//        Dispositif de restriction des accès aux appréciations pour les comptes responsables/eleves
						$temoin_avis_present="y";
					}
					//==========================================================
示例#3
0
function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0)
{
    $a = get_app();
    if (!$item['parent']) {
        return;
    }
    if ($item['deleted']) {
        return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n";
    }
    if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
        $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid);
    } else {
        $body = $item['body'];
    }
    $o = "\r\n\r\n<entry>\r\n";
    if (is_array($author)) {
        $o .= atom_author('author', $author['name'], $author['url'], 80, 80, $author['thumb'], $item['coord']);
    } else {
        $o .= atom_author('author', $item['author-name'] ? $item['author-name'] : $item['name'], $item['author-link'] ? $item['author-link'] : $item['url'], 80, 80, $item['author-avatar'] ? $item['author-avatar'] : $item['thumb'], $item['coord']);
    }
    if (strlen($item['owner-name'])) {
        $o .= atom_author('dfrn:owner', $item['owner-name'], $item['owner-link'], 80, 80, $item['owner-avatar'], $item['coord']);
    }
    if ($item['parent'] != $item['id'] || $item['parent-uri'] !== $item['uri'] || $item['thr-parent'] !== '' && $item['thr-parent'] !== $item['uri']) {
        $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
        $parent_item = $item['thr-parent'] ? $item['thr-parent'] : $item['parent-uri'];
        $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $parent[0]['guid']) . '" />' . "\r\n";
    }
    $htmlbody = $body;
    if ($item['title'] != "") {
        $htmlbody = "[b]" . $item['title'] . "[/b]\n\n" . $htmlbody;
    }
    $htmlbody = bbcode($htmlbody, false, false, 7);
    $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
    $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
    $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n";
    $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n";
    $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
    $o .= '<content type="' . $type . '" >' . xmlify($type === 'html' ? $htmlbody : $body) . '</content>' . "\r\n";
    $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $item['guid']) . '" />' . "\r\n";
    $o .= '<status_net notice_id="' . $item['id'] . '"></status_net>' . "\r\n";
    if ($comment) {
        $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
    }
    if ($item['location']) {
        $o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n";
        $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
    }
    if ($item['coord']) {
        $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
    }
    if ($item['private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
        $o .= '<dfrn:private>' . ($item['private'] ? $item['private'] : 1) . '</dfrn:private>' . "\r\n";
    }
    if ($item['extid']) {
        $o .= '<dfrn:extid>' . xmlify($item['extid']) . '</dfrn:extid>' . "\r\n";
    }
    if ($item['bookmark']) {
        $o .= '<dfrn:bookmark>true</dfrn:bookmark>' . "\r\n";
    }
    if ($item['app']) {
        $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n";
    }
    if ($item['guid']) {
        $o .= '<dfrn:diaspora_guid>' . $item['guid'] . '</dfrn:diaspora_guid>' . "\r\n";
    }
    if ($item['signed_text']) {
        $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'], 'signature' => $item['signature'], 'signer' => $item['signer'])));
        $o .= '<dfrn:diaspora_signature>' . xmlify($sign) . '</dfrn:diaspora_signature>' . "\r\n";
    }
    $verb = construct_verb($item);
    $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
    $actobj = construct_activity_object($item);
    if (strlen($actobj)) {
        $o .= $actobj;
    }
    $actarg = construct_activity_target($item);
    if (strlen($actarg)) {
        $o .= $actarg;
    }
    $tags = item_getfeedtags($item);
    if (count($tags)) {
        foreach ($tags as $t) {
            if ($type != 'html' or $t[0] != "@") {
                $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
            }
        }
    }
    // To-Do:
    // To support these elements, the API needs to be enhanced
    //$o .= '<link rel="ostatus:conversation" href="'.xmlify($a->get_baseurl().'/display/'.$owner['nickname'].'/'.$item['parent']).'"/>'."\r\n";
    //$o .= "\t".'<link rel="self" type="application/atom+xml" href="'.xmlify($a->get_baseurl().'/api/statuses/show/'.$item['id'].'.atom').'"/>'."\r\n";
    //$o .= "\t".'<link rel="edit" type="application/atom+xml" href="'.xmlify($a->get_baseurl().'/api/statuses/show/'.$item['id'].'.atom').'"/>'."\r\n";
    // Deactivated since it was meant only for OStatus
    //$o .= item_get_attachment($item);
    $o .= item_getfeedattach($item);
    $mentioned = get_mentions($item);
    if ($mentioned) {
        $o .= $mentioned;
    }
    call_hooks('atom_entry', $o);
    $o .= '</entry>' . "\r\n";
    return $o;
}
示例#4
0
function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0)
{
    $a = get_app();
    if (!$item['parent']) {
        return;
    }
    if ($item['deleted']) {
        return '<at:deleted-entry ref="' . xmlify($item['uri']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n";
    }
    if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
        $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid);
    } else {
        $body = $item['body'];
    }
    $o = "\r\n\r\n<entry>\r\n";
    if (is_array($author)) {
        $o .= atom_author('author', $author['name'], $author['url'], 80, 80, $author['thumb']);
    } else {
        $o .= atom_author('author', $item['author-name'] ? $item['author-name'] : $item['name'], $item['author-link'] ? $item['author-link'] : $item['url'], 80, 80, $item['author-avatar'] ? $item['author-avatar'] : $item['thumb']);
    }
    if (strlen($item['owner-name'])) {
        $o .= atom_author('dfrn:owner', $item['owner-name'], $item['owner-link'], 80, 80, $item['owner-avatar']);
    }
    if ($item['parent'] != $item['id'] || $item['parent-uri'] !== $item['uri']) {
        $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['parent']) . '" />' . "\r\n";
    }
    $o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
    $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
    $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n";
    $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n";
    $o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
    $o .= '<content type="' . $type . '" >' . xmlify($type === 'html' ? bbcode($body) : $body) . '</content>' . "\r\n";
    $o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
    if ($comment) {
        $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
    }
    if ($item['location']) {
        $o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n";
        $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
    }
    if ($item['coord']) {
        $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
    }
    if ($item['private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
        $o .= '<dfrn:private>1</dfrn:private>' . "\r\n";
    }
    if ($item['extid']) {
        $o .= '<dfrn:extid>' . xmlify($item['extid']) . '</dfrn:extid>' . "\r\n";
    }
    if ($item['bookmark']) {
        $o .= '<dfrn:bookmark>true</dfrn:bookmark>' . "\r\n";
    }
    if ($item['app']) {
        $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n";
    }
    if ($item['guid']) {
        $o .= '<dfrn:diaspora_guid>' . $item['guid'] . '</dfrn:diaspora_guid>' . "\r\n";
    }
    if ($item['signed_text']) {
        $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'], 'signature' => $item['signature'], 'signer' => $item['signer'])));
        $o .= '<dfrn:diaspora_signature>' . xmlify($sign) . '</dfrn:diaspora_signature>' . "\r\n";
    }
    $verb = construct_verb($item);
    $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
    $actobj = construct_activity_object($item);
    if (strlen($actobj)) {
        $o .= $actobj;
    }
    $actarg = construct_activity_target($item);
    if (strlen($actarg)) {
        $o .= $actarg;
    }
    $tags = item_getfeedtags($item);
    if (count($tags)) {
        foreach ($tags as $t) {
            $o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
        }
    }
    $o .= item_getfeedattach($item);
    $mentioned = get_mentions($item);
    if ($mentioned) {
        $o .= $mentioned;
    }
    call_hooks('atom_entry', $o);
    $o .= '</entry>' . "\r\n";
    return $o;
}
示例#5
0
文件: avis_pdf.php 项目: rhertzog/lcs
        $nb_periodes = $lig_max->max_per;
        unset($_SESSION['id_liste_periodes']);
        for ($i = 1; $i <= $nb_periodes; $i++) {
            $_SESSION['id_liste_periodes'][] = $i;
        }
        $id_liste_periodes = $_SESSION['id_liste_periodes'];
        $id_periode = $id_liste_periodes[0];
    }
} else {
    unset($_SESSION['id_liste_periodes']);
    $_SESSION['id_liste_periodes'][0] = $id_periode;
    $nb_periodes = 1;
}
//echo " ".$nb_pages;
//$nb_pages=$nb_pages*$nb_periodes;
$tab_mentions = get_mentions();
$affiche = 'n';
if ($affiche == 'y') {
    echo "<pre>";
    print_r($tab_mentions);
    echo "</pre>";
    //die();
}
if (getSettingAOui('active_mod_discipline')) {
    $tab_type_avertissement_fin_periode = get_tab_type_avertissement();
    /*
    // Récupérer les avertissements des élèves de la classe pour la période en cours.
    if(count($tab_type_avertissement_fin_periode)>0) {
    	//get_tab_avertissement_classe();
    	//liste_avertissements_fin_periode_classe()
    
示例#6
0
/**
 * Renvoie une balise <select> avec les mentions de bulletin
 *
 * @param string $nom_champ_select valeur des attribut name et id du select
 * @param int $id_classe Id de la classe
 * @param string $id_mention_selected Id de la mention à sélectionner par défaut
 * @return string La balise
 */
function champ_select_mention($nom_champ_select, $id_classe, $id_mention_selected = '')
{
    $tab_mentions = get_mentions($id_classe);
    $retour = "<select name='{$nom_champ_select}' id='{$nom_champ_select}'>\n";
    $retour .= "<option value=''";
    if ($id_mention_selected == "" || !array_key_exists($id_mention_selected, $tab_mentions)) {
        $retour .= " selected='selected'";
    }
    $retour .= " title=\"Aucune mention\"> --- </option>\n";
    foreach ($tab_mentions as $key => $value) {
        $retour .= "<option value='{$key}'";
        if ($id_mention_selected == $key) {
            $retour .= " selected='selected'";
        }
        //$retour.=">".$value." ".$key."</option>\n";
        $retour .= ">" . $value . "</option>\n";
    }
    $retour .= "</select>\n";
    return $retour;
}
示例#7
0
function bulletin($tab_moy, $current_eleve_login, $compteur, $total, $periode1, $periode2, $nom_periode, $gepiYear, $id_classe, $affiche_rang, $test_coef, $affiche_categories, $couleur_lignes = NULL)
{
    //global $nb_notes,$nombre_eleves,$type_etablissement,$type_etablissement2;
    global $nb_notes, $type_etablissement, $type_etablissement2;
    global $display_moy_gen;
    global $affiche_coef;
    global $bull_intitule_app;
    global $affiche_deux_moy_gen;
    global $affiche_colonne_moy_classe;
    //$affiche_colonne_moy_classe="n";
    global $gepi_denom_mention;
    if ($gepi_denom_mention == '') {
        $gepi_denom_mention = "mention";
    }
    //=========================
    global $utilisation_tablekit;
    if ($periode1 != $periode2) {
        //unset($utilisation_tablekit);
        $utilisation_tablekit = "no";
    }
    //=========================
    // Pour éviter dans bulletin() d'afficher le lien vers saisie_avis2.php depuis la page saisie_avis2.php
    global $temoin_page_courante;
    global $bull_simp_larg_tab, $bull_simp_larg_col1, $bull_simp_larg_col2, $bull_simp_larg_col3, $bull_simp_larg_col4;
    global $themessage;
    if (!isset($themessage) || $themessage == "") {
        $themessage = "Des saisies n\\'ont pas été enregistrées. Voulez-vous vraiment quitter sans enregistrer ?";
    }
    $alt = 1;
    // Initialisation des tableaux
    // $tab_afficher_liens_modif_app[$id_groupe][$num_per]
    // $tab_afficher_liens_valider_modif_app[$loop_per]
    //$tab_afficher_liens_modif_app=array();
    //$tab_afficher_liens_valider_modif_app=array();
    $tmp_tab = afficher_liens_modif_app($id_classe, $periode1, $periode2);
    $tab_afficher_liens_modif_app = $tmp_tab[0];
    $tab_afficher_liens_valider_modif_app = $tmp_tab[1];
    $afficher_proposition_correction = "n";
    if (count($tab_afficher_liens_modif_app) > 0) {
        $afficher_proposition_correction = "y";
    }
    /*
    echo "<pre>";
    print_r($tab_afficher_liens_modif_app);
    echo "</pre>";
    */
    $tab_statuts_signalement_faute_autorise = array('administrateur', 'professeur', 'cpe', 'scolarite');
    $afficher_signalement_faute = "n";
    if (in_array($_SESSION['statut'], $tab_statuts_signalement_faute_autorise)) {
        if ($_SESSION['statut'] == 'professeur' && mb_substr(getSettingValue('autoriser_signalement_faute_app_prof'), 0, 1) == 'y') {
            $afficher_signalement_faute = "y";
        } elseif ($_SESSION['statut'] == 'professeur' && mb_substr(getSettingValue('autoriser_signalement_faute_app_pp'), 0, 1) == 'y') {
            // Tester si le prof est pp de la classe
            if (is_pp($_SESSION['login'], $id_classe)) {
                $afficher_signalement_faute = "y";
            }
        } elseif ($_SESSION['statut'] == 'scolarite' && mb_substr(getSettingValue('autoriser_signalement_faute_app_scol'), 0, 1) == 'y') {
            $afficher_signalement_faute = "y";
        } elseif ($_SESSION['statut'] == 'cpe' && mb_substr(getSettingValue('autoriser_signalement_faute_app_cpe'), 0, 1) == 'y') {
            $afficher_signalement_faute = "y";
        }
    }
    if ($afficher_signalement_faute == 'y' || $afficher_proposition_correction == "y") {
        // A N'INSERER QUE POUR LES COMPTES DE PERSONNELS... de façon à éviter de donner les mails des profs à des élèves
        if (!isset($necessaire_signalement_fautes_insere) || $necessaire_signalement_fautes_insere == "n") {
            lib_signalement_fautes();
        }
        global $signalement_id_groupe;
        $envoi_mail_actif = getSettingValue('envoi_mail_actif');
    }
    global $mysqli;
    $tab_modif_app_proposees = array();
    $tab_mes_groupes = array();
    if ($_SESSION['statut'] == 'professeur') {
        //$tab_mes_groupes=array();
        $sql = "SELECT jgp.id_groupe FROM j_groupes_professeurs jgp WHERE login = '******'login'] . "';";
        //echo "$sql<br />";
        $res = mysqli_query($GLOBALS["mysqli"], $sql);
        if (mysqli_num_rows($res) > 0) {
            while ($lig = mysqli_fetch_object($res)) {
                $tab_mes_groupes[] = $lig->id_groupe;
                $sql = "SELECT * FROM matieres_app_corrections WHERE id_groupe='{$lig->id_groupe}';";
                $res_mad = mysqli_query($mysqli, $sql);
                if ($res_mad->num_rows > 0) {
                    while ($lig_mad = $res_mad->fetch_object()) {
                        $tab_modif_app_proposees[$lig_mad->id_groupe][$lig_mad->periode][$lig_mad->login] = $lig_mad->appreciation;
                    }
                }
            }
        }
        if (getSettingAOui('visuCorrectionsAppProposeesProfs')) {
            $sql = "SELECT DISTINCT ma.* FROM matieres_app_corrections ma,j_groupes_classes jgc WHERE jgc.id_groupe=ma.id_groupe AND jgc.id_classe='{$id_classe}';";
            //echo "$sql<br />";
            $res_mad = mysqli_query($mysqli, $sql);
            if ($res_mad->num_rows > 0) {
                while ($lig_mad = $res_mad->fetch_object()) {
                    $tab_modif_app_proposees[$lig_mad->id_groupe][$lig_mad->periode][$lig_mad->login] = $lig_mad->appreciation;
                }
            }
        }
        if (!isset($necessaire_corriger_appreciation_insere) || $necessaire_corriger_appreciation_insere == "n") {
            lib_corriger_appreciation();
        }
        global $corriger_app_id_groupe;
        //global $tab_mes_groupes;
        /*
        echo "tab_mes_groupes:<pre>";
        print_r($tab_mes_groupes);
        echo "</pre>";
        */
    } elseif ($_SESSION['statut'] == 'scolarite') {
        $sql = "SELECT DISTINCT ma.* FROM matieres_app_corrections ma,j_groupes_classes jgc WHERE jgc.id_groupe=ma.id_groupe AND jgc.id_classe='{$id_classe}';";
        //echo "$sql<br />";
        $res_mad = mysqli_query($mysqli, $sql);
        if ($res_mad->num_rows > 0) {
            while ($lig_mad = $res_mad->fetch_object()) {
                $tab_modif_app_proposees[$lig_mad->id_groupe][$lig_mad->periode][$lig_mad->login] = $lig_mad->appreciation;
            }
        }
        if (getSettingAOui('AccesModifAppreciationScol')) {
            if (!isset($necessaire_corriger_appreciation_insere) || $necessaire_corriger_appreciation_insere == "n") {
                lib_corriger_appreciation();
            }
        }
    }
    // données requise :
    //- le login de l'élève    : $current_eleve_login
    //- $compteur : compteur
    //- $total : nombre total d'élèves
    //- $periode1 : numéro de la première période à afficher
    //- $periode2 : numéro de la dernière période à afficher
    //- $nom_periode : tableau des noms de période
    //- $gepiYear : année
    //- $id_classe : identifiant de la classe.
    //==========================================================
    // AJOUT: boireaus 20080218
    //        Dispositif de restriction des accès aux appréciations pour les comptes responsables/eleves
    //echo "\$_SESSION['statut']=".$_SESSION['statut']."<br />";
    //echo "\$periode1=$periode1<br />";
    //echo "\$periode2=$periode2<br />";
    unset($tab_acces_app);
    $tab_acces_app = array();
    $tab_acces_app = acces_appreciations($periode1, $periode2, $id_classe);
    //==========================================================
    $nb_periodes = $periode2 - $periode1 + 1;
    $on_continue = "yes";
    if ($nb_periodes == 1) {
        // S'il n'est demandé qu'une seule période:
        // Test pour savoir si l'élève appartient à la classe pour la période considérée
        $test_eleve_app = sql_query1("select count(login) from j_eleves_classes where login='******' and id_classe='" . $id_classe . "' and periode='" . $periode1 . "'");
        if ($test_eleve_app == 0) {
            $on_continue = "no";
        }
    }
    if ($on_continue == 'yes') {
        // Mis hors de la fonction
        //$affiche_coef=sql_query1("SELECT display_coef FROM classes WHERE id='".$id_classe."'");
        //echo "\$affiche_categories=$affiche_categories<br />";
        $data_eleve = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM eleves WHERE login='******'");
        // Récupération du champ auto_increment
        $current_id_eleve = old_mysql_result($data_eleve, 0, "id_eleve");
        $current_eleve_nom = old_mysql_result($data_eleve, 0, "nom");
        $current_eleve_prenom = old_mysql_result($data_eleve, 0, "prenom");
        $current_eleve_sexe = old_mysql_result($data_eleve, 0, "sexe");
        $current_eleve_naissance = old_mysql_result($data_eleve, 0, "naissance");
        $current_eleve_naissance = affiche_date_naissance($current_eleve_naissance);
        $current_eleve_elenoet = old_mysql_result($data_eleve, 0, "elenoet");
        $data_profsuivi = mysqli_query($GLOBALS["mysqli"], "SELECT u.login FROM utilisateurs u, j_eleves_professeurs j WHERE (j.login='******' AND j.professeur = u.login AND j.id_classe='{$id_classe}') ");
        $current_eleve_profsuivi_login = @old_mysql_result($data_profsuivi, 0, "login");
        echo "<input type='hidden' name='nom_prenom_eleve[{$current_id_eleve}]' id='nom_prenom_eleve_{$current_id_eleve}' value=\"{$current_eleve_nom} {$current_eleve_prenom}\" />\n";
        $data_etab = mysqli_query($GLOBALS["mysqli"], "SELECT e.* FROM etablissements e, j_eleves_etablissements j WHERE (j.id_eleve ='{$current_eleve_elenoet}' AND e.id = j.id_etablissement) ");
        $current_eleve_etab_id = @old_mysql_result($data_etab, 0, "id");
        $current_eleve_etab_nom = @old_mysql_result($data_etab, 0, "nom");
        $current_eleve_etab_niveau = @old_mysql_result($data_etab, 0, "niveau");
        $current_eleve_etab_type = @old_mysql_result($data_etab, 0, "type");
        $current_eleve_etab_cp = @old_mysql_result($data_etab, 0, "cp");
        $current_eleve_etab_ville = @old_mysql_result($data_etab, 0, "ville");
        if ($current_eleve_etab_niveau != '') {
            foreach ($type_etablissement as $type_etab => $nom_etablissement) {
                if ($current_eleve_etab_niveau == $type_etab) {
                    $current_eleve_etab_niveau_nom = $nom_etablissement;
                }
            }
            if ($current_eleve_etab_cp == 0) {
                $current_eleve_etab_cp = '';
            }
            if ($current_eleve_etab_type == 'aucun') {
                $current_eleve_etab_type = '';
            } else {
                $current_eleve_etab_type = $type_etablissement2[$current_eleve_etab_type][$current_eleve_etab_niveau];
            }
        }
        $classe_eleve = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM classes WHERE id='{$id_classe}'");
        $current_eleve_classe = old_mysql_result($classe_eleve, 0, "classe");
        $id_classe = old_mysql_result($classe_eleve, 0, "id");
        $regime_doublant_eleve = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM j_eleves_regime WHERE login = '******'");
        $current_eleve_regime = old_mysql_result($regime_doublant_eleve, 0, "regime");
        $current_eleve_doublant = old_mysql_result($regime_doublant_eleve, 0, "doublant");
        //-------------------------------
        // On affiche l'en-tête : Les données de l'élève
        //-------------------------------
        echo "<span class='bull_simpl'><span class='bold'>{$current_eleve_nom} {$current_eleve_prenom}</span>";
        if ($current_eleve_sexe == "M") {
            echo ", né le {$current_eleve_naissance}";
        } else {
            echo ", née le {$current_eleve_naissance}";
        }
        if ($current_eleve_regime == "d/p") {
            echo ",&nbsp;demi-pensionnaire";
        }
        if ($current_eleve_regime == "ext.") {
            echo ",&nbsp;externe";
        }
        if ($current_eleve_regime == "int.") {
            echo ",&nbsp;interne";
        }
        if ($current_eleve_regime == "i-e") {
            if ($current_eleve_sexe == "M") {
                echo ",&nbsp;interne&nbsp;externé";
            } else {
                echo ",&nbsp;interne&nbsp;externée";
            }
        }
        if ($current_eleve_doublant == 'R') {
            if ($current_eleve_sexe == "M") {
                echo ", <b>redoublant</b>";
            } else {
                echo ", <b>redoublante</b>";
            }
        }
        echo "&nbsp;&nbsp;-&nbsp;&nbsp;Classe de {$current_eleve_classe}, année scolaire {$gepiYear}<br />\n";
        if ($current_eleve_etab_nom != '') {
            echo "Etablissement d'origine : ";
            if ($current_eleve_etab_id != '990') {
                echo "{$current_eleve_etab_niveau_nom} {$current_eleve_etab_type} {$current_eleve_etab_nom} ({$current_eleve_etab_cp} {$current_eleve_etab_ville})<br />\n";
            } else {
                echo "hors de France<br />\n";
            }
        }
        if ($periode1 < $periode2) {
            echo "Résultats de : ";
            $nb = $periode1;
            while ($nb < $periode2 + 1) {
                echo $nom_periode[$nb];
                if ($nb < $periode2) {
                    echo " - ";
                }
                $nb++;
            }
            echo ".</span>";
        } else {
            $temp = my_strtolower($nom_periode[$periode1]);
            echo "Résultats du {$temp}.</span>";
        }
        //
        //-------------------------------
        // Fin de l'en-tête
        // Initialisation de variable pour le cas où un élève n'est dans aucun enseignement sur une période
        $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black; border-bottom: 1px dashed black;";
        // On initialise le tableau :
        $bull_simp_larg_tab_defaut = 680;
        $bull_simp_larg_col1_defaut = 120;
        $bull_simp_larg_col2_defaut = 38;
        $bull_simp_larg_col3_defaut = 38;
        $bull_simp_larg_col4_defaut = 20;
        $larg_tab = $bull_simp_larg_tab_defaut;
        $larg_col1 = $bull_simp_larg_col1_defaut;
        $larg_col2 = $bull_simp_larg_col3_defaut;
        $larg_col3 = $bull_simp_larg_col3_defaut;
        $larg_col4 = $bull_simp_larg_col4_defaut;
        if (preg_match("/^[0-9]{1,}\$/", $bull_simp_larg_tab)) {
            $larg_tab = $bull_simp_larg_tab;
        }
        if (preg_match("/^[0-9]{1,}\$/", $bull_simp_larg_col1)) {
            $larg_col1 = $bull_simp_larg_col1;
        }
        if (preg_match("/^[0-9]{1,}\$/", $bull_simp_larg_col2)) {
            $larg_col2 = $bull_simp_larg_col2;
        }
        if (preg_match("/^[0-9]{1,}\$/", $bull_simp_larg_col3)) {
            $larg_col3 = $bull_simp_larg_col3;
        }
        if (preg_match("/^[0-9]{1,}\$/", $bull_simp_larg_col4)) {
            $larg_col4 = $bull_simp_larg_col4;
        }
        if ($bull_simp_larg_tab < $bull_simp_larg_col1 + $bull_simp_larg_col2 + $bull_simp_larg_col3 + $bull_simp_larg_col4) {
            $larg_tab = $bull_simp_larg_tab_defaut;
            $larg_col1 = $bull_simp_larg_col1_defaut;
            $larg_col2 = $bull_simp_larg_col2_defaut;
            $larg_col3 = $bull_simp_larg_col3_defaut;
            $larg_col4 = $bull_simp_larg_col4_defaut;
        }
        $larg_col5 = $larg_tab - $larg_col1 - $larg_col2 - $larg_col3 - $larg_col4;
        //=========================
        // MODIF: boireaus 20080315
        //echo "<table width=$larg_tab border=1 cellspacing=1 cellpadding=1>\n";
        echo "<table width={$larg_tab} class='boireaus";
        if ($utilisation_tablekit == "ok") {
            echo " sortable resizable";
        }
        echo "' cellspacing='1' cellpadding='1' summary='Matières/Notes/Appréciations'>\n";
        //=========================
        echo "<thead>\n";
        echo "<tr><td width=\"{$larg_col1}\" class='bull_simpl text'>{$compteur}";
        if ($total != '') {
            echo "/{$total}";
        }
        echo "</td>\n";
        //====================
        // Modif: boireaus 20070626
        if ($affiche_coef == 'y') {
            if ($test_coef != 0) {
                echo "<td width=\"{$larg_col2}\" align=\"center\" class='number'><p class='bull_simpl'>Coef.</p></td>\n";
            }
        }
        //====================
        if ($affiche_colonne_moy_classe != 'n') {
            echo "<td width=\"{$larg_col2}\" align=\"center\" class='bull_simpl text'>Classe</td>\n";
        }
        echo "<td width=\"{$larg_col3}\" align=\"center\" class='bull_simpl number'>&Eacute;lève</td>\n";
        if ($affiche_rang == 'y') {
            echo "<td width={$larg_col4} align=\"center\" class='bull_simpl number'><i>Rang</i></td>\n";
        }
        echo "<td width=\"{$larg_col5}\" class='bull_simpl nosort'>{$bull_intitule_app}</td>\n";
        if ($afficher_signalement_faute == 'y') {
            // A N'INSERER QUE POUR LES COMPTES DE PERSONNELS... de façon à éviter de donner les mails des profs à des élèves
            echo "<td class='bull_simpl noprint'>Signaler</td>\n";
        }
        echo "</tr>\n";
        echo "</thead>\n";
        echo "<tbody>\n";
        //echo "</table>";
        // On attaque maintenant l'affichage des appréciations des Activités Interdisciplinaires devant apparaître en tête des bulletins :
        $call_data = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM aid_config WHERE order_display1 = 'b' ORDER BY order_display2");
        $nb_aid = mysqli_num_rows($call_data);
        $z = 0;
        while ($z < $nb_aid) {
            $display_begin = old_mysql_result($call_data, $z, "display_begin");
            $display_end = old_mysql_result($call_data, $z, "display_end");
            if ($periode1 >= $display_begin and $periode2 <= $display_end) {
                $indice_aid = @old_mysql_result($call_data, $z, "indice_aid");
                $aid_query = mysqli_query($GLOBALS["mysqli"], "SELECT id_aid FROM j_aid_eleves WHERE (login='******' and indice_aid='{$indice_aid}')");
                $aid_id = @old_mysql_result($aid_query, 0, "id_aid");
                if ($aid_id != '') {
                    affiche_aid_simple($affiche_rang, $test_coef, $indice_aid, $aid_id, $current_eleve_login, $periode1, $periode2, $id_classe, 'bull_simpl', $affiche_coef);
                }
            }
            $z++;
        }
        //------------------------------
        // Boucle 'groupes'
        //------------------------------
        // Récupération des noms de categories
        $get_cat = mysqli_query($GLOBALS["mysqli"], "SELECT id FROM matieres_categories");
        $categories = array();
        while ($row = mysqli_fetch_array($get_cat, MYSQLI_ASSOC)) {
            $categories[] = $row["id"];
        }
        $cat_names = array();
        foreach ($categories as $cat_id) {
            $cat_names[$cat_id] = old_mysql_result(mysqli_query($GLOBALS["mysqli"], "SELECT nom_complet FROM matieres_categories WHERE id = '" . $cat_id . "'"), 0);
        }
        // Nombre de groupes sur la classe
        $nombre_groupes = count($tab_moy['current_group']);
        // Récupération des indices de l'élève $current_eleve_login dans $tab_moy
        unset($tab_login_indice);
        $nb = $periode1;
        while ($nb < $periode2 + 1) {
            //$tab_login_indice[$nb]=$tab_moy['periodes'][$nb]['tab_login_indice'][$current_eleve_login];
            // Un élève qui arrive ou part en cours d'année ne sera pas dans la classe ni dans les groupes sur certaines périodes
            //if(isset($tab_moy['periodes'][$nb]['tab_login_indice'][$current_eleve_login])) {
            if (isset($tab_moy['periodes'][$nb]['tab_login_indice'][my_strtoupper($current_eleve_login)])) {
                //$tab_login_indice[$nb]=$tab_moy['periodes'][$nb]['tab_login_indice'][$current_eleve_login];
                $tab_login_indice[$nb] = $tab_moy['periodes'][$nb]['tab_login_indice'][my_strtoupper($current_eleve_login)];
                //echo "\$tab_login_indice[$nb]=$tab_login_indice[$nb]<br />";
            }
            /*
            else {
            	echo "\$tab_moy['periodes'][$nb]['tab_login_indice'][$current_eleve_login] n'est pas affecté.<br />";
            }
            */
            $nb++;
        }
        //$j = 0;
        $prev_cat_id = null;
        //while ($j < $nombre_groupes) {
        for ($j = 0; $j < $nombre_groupes; $j++) {
            //echo "<table width=$larg_tab border=1 cellspacing=0 cellpadding=1 style='margin-bottom: 0px; border-bottom: 1px solid black; border-top: none;'>";
            $inser_ligne = 'no';
            //$group_id = old_mysql_result($appel_liste_groupes, $j, "id_groupe");
            //$current_group = get_group($group_id);
            // On récupère le groupe depuis $tab_moy
            $current_group = $tab_moy['current_group'][$j];
            //echo "<p>Groupe n°$j: ".$current_group['name']."<br />\n";
            // Coefficient pour le groupe
            $current_coef = $current_group["classes"]["classes"][$id_classe]["coef"];
            // Pour les enseignements à bonus,...
            $mode_moy = $current_group["classes"]["classes"][$id_classe]["mode_moy"];
            $current_matiere_professeur_login = $current_group["profs"]["list"];
            //$current_matiere_nom_complet = $current_group["matiere"]["nom_complet"];
            if (getSettingValue('bul_rel_nom_matieres') == 'nom_groupe') {
                $current_matiere_nom_complet = $current_group["name"];
            } elseif (getSettingValue('bul_rel_nom_matieres') == 'description_groupe') {
                $current_matiere_nom_complet = $current_group["description"];
            } else {
                $current_matiere_nom_complet = $current_group["matiere"]["nom_complet"];
            }
            $nb = $periode1;
            while ($nb < $periode2 + 1) {
                $current_classe_matiere_moyenne[$nb] = $tab_moy['periodes'][$nb]['current_classe_matiere_moyenne'][$j];
                // On teste si des notes de une ou plusieurs boites du carnet de notes doivent être affichée
                $test_cn = mysqli_query($GLOBALS["mysqli"], "select c.nom_court, c.id from cn_cahier_notes cn, cn_conteneurs c\n\t\t\twhere (cn.periode = '{$nb}' and cn.id_groupe='" . $current_group["id"] . "' and cn.id_cahier_notes = c.id_racine and c.id_racine!=c.id and c.display_bulletin = 1) ");
                $nb_ligne_cn[$nb] = mysqli_num_rows($test_cn);
                $n = 0;
                while ($n < $nb_ligne_cn[$nb]) {
                    $cn_id[$nb][$n] = old_mysql_result($test_cn, $n, 'id');
                    $cn_nom[$nb][$n] = old_mysql_result($test_cn, $n, 'nom_court');
                    $n++;
                }
                $nb++;
            }
            // Maintenant on regarde si l'élève suit bien cette matière ou pas
            //-----------------------------
            $nb = $periode1;
            while ($nb < $periode2 + 1) {
                // Test supplémentaire pour savoir si l'élève appartient à la classe pour la période considérée
                $test_eleve_app = sql_query1("select count(login) from j_eleves_classes where login='******' and id_classe='" . $id_classe . "' and periode='" . $nb . "'");
                if ((in_array($current_eleve_login, $current_group["eleves"][$nb]["list"]) or in_array(my_strtolower($current_eleve_login), $current_group["eleves"][$nb]["list"]) or in_array(my_strtoupper($current_eleve_login), $current_group["eleves"][$nb]["list"])) and $test_eleve_app != 0) {
                    $inser_ligne = 'yes';
                    $current_eleve_note[$nb] = $tab_moy['periodes'][$nb]['current_eleve_note'][$j][$tab_login_indice[$nb]];
                    $current_eleve_statut[$nb] = $tab_moy['periodes'][$nb]['current_eleve_statut'][$j][$tab_login_indice[$nb]];
                    $current_eleve_appreciation_query = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM matieres_appreciations ma, j_eleves_classes jec WHERE (ma.login='******' AND ma.id_groupe='" . $current_group["id"] . "' AND ma.periode='{$nb}' and jec.periode='{$nb}' and jec.login='******' and jec.id_classe='{$id_classe}')");
                    $current_eleve_appreciation[$nb] = @old_mysql_result($current_eleve_appreciation_query, 0, "appreciation");
                    $coef_eleve = $tab_moy['periodes'][$nb]['current_coef_eleve'][$tab_login_indice[$nb]][$j];
                    //echo "\$coef_eleve=\$tab_moy['periodes'][$nb]['current_coef_eleve'][".$tab_login_indice[$nb]."][$j]=".$coef_eleve."<br />\n";
                } else {
                    $current_eleve_note[$nb] = '';
                    $current_eleve_statut[$nb] = 'Non suivie';
                    $current_eleve_appreciation[$nb] = '';
                }
                //++++++++++++++++++++++++
                // Modif d'après F.Boisson
                // notes dans appreciation
                $sql = "SELECT cnd.note, cd.note_sur FROM cn_notes_devoirs cnd, cn_devoirs cd, cn_cahier_notes ccn WHERE cnd.login='******' AND cnd.id_devoir=cd.id AND cd.id_racine=ccn.id_cahier_notes AND ccn.id_groupe='" . $current_group["id"] . "' AND ccn.periode='{$nb}' AND cnd.statut='';";
                $result_nbct = mysqli_query($GLOBALS["mysqli"], $sql);
                $string_notes = '';
                if ($result_nbct) {
                    while ($snnote = mysqli_fetch_assoc($result_nbct)) {
                        if ($string_notes != '') {
                            $string_notes .= ", ";
                        }
                        $string_notes .= $snnote['note'];
                        if (getSettingValue("note_autre_que_sur_referentiel") == "V" || $snnote['note_sur'] != getSettingValue("referentiel_note")) {
                            $string_notes .= "/" . $snnote['note_sur'];
                        }
                    }
                }
                $current_eleve_appreciation[$nb] = str_replace('@@Notes', $string_notes, $current_eleve_appreciation[$nb]);
                //++++++++++++++++++++++++
                $nb++;
            }
            if ($inser_ligne == 'yes') {
                if ($affiche_categories) {
                    // On regarde si on change de catégorie de matière
                    if ($current_group["classes"]["classes"][$id_classe]["categorie_id"] != $prev_cat_id) {
                        $prev_cat_id = $current_group["classes"]["classes"][$id_classe]["categorie_id"];
                        // On est dans une nouvelle catégorie
                        // On récupère les infos nécessaires, et on affiche une ligne
                        // On détermine le nombre de colonnes pour le colspan
                        if ($affiche_colonne_moy_classe == 'n') {
                            $nb_total_cols = 3;
                        } else {
                            $nb_total_cols = 4;
                        }
                        //====================
                        // Modif: boireaus 20070626
                        if ($affiche_coef == 'y') {
                            if ($test_coef != 0) {
                                $nb_total_cols++;
                            }
                        }
                        //====================
                        if ($affiche_rang == 'y') {
                            $nb_total_cols++;
                        }
                        // On regarde s'il faut afficher la moyenne de l'élève pour cette catégorie
                        $affiche_cat_moyenne_query = mysqli_query($GLOBALS["mysqli"], "SELECT affiche_moyenne FROM j_matieres_categories_classes WHERE (classe_id = '" . $id_classe . "' and categorie_id = '" . $prev_cat_id . "')");
                        if (mysqli_num_rows($affiche_cat_moyenne_query) == "0") {
                            $affiche_cat_moyenne = false;
                        } else {
                            $affiche_cat_moyenne = old_mysql_result($affiche_cat_moyenne_query, 0);
                        }
                        // On a toutes les infos. On affiche !
                        echo "<tr>\n";
                        echo "<td colspan='" . $nb_total_cols . "'>\n";
                        echo "<p style='padding: 0; margin:0; font-size: 10px; text-align:left;'>" . $cat_names[$prev_cat_id] . "</p></td>\n";
                        if ($afficher_signalement_faute == 'y') {
                            // A N'INSERER QUE POUR LES COMPTES DE PERSONNELS... de façon à éviter de donner les mails des profs à des élèves
                            echo "<td class='bull_simpl noprint'>-</td>\n";
                        }
                        echo "</tr>\n";
                    }
                }
                if ($couleur_lignes == 'y') {
                    $alt = $alt * -1;
                    echo "<tr class='lig{$alt}'>\n";
                    $alt2 = $alt;
                } else {
                    echo "<tr>\n";
                }
                echo "<td ";
                if ($nb_periodes > 1) {
                    echo " rowspan= " . $nb_periodes;
                }
                //echo" width=\"$larg_col1\" class='bull_simpl'><b>$current_matiere_nom_complet</b>";
                echo " width=\"{$larg_col1}\" class='bull_simpl'><b>" . htmlspecialchars($current_matiere_nom_complet) . "</b>";
                $k = 0;
                //echo "(".$current_group['id'].")";
                $liste_email_profs_du_groupe = "";
                $liste_profs_du_groupe = "";
                while ($k < count($current_matiere_professeur_login)) {
                    echo "<br /><i>" . affiche_utilisateur($current_matiere_professeur_login[$k], $id_classe) . "</i>";
                    if ($k > 0) {
                        $liste_profs_du_groupe .= "|";
                    }
                    $liste_profs_du_groupe .= $current_matiere_professeur_login[$k];
                    $tmp_mail = retourne_email($current_matiere_professeur_login[$k]);
                    if ($tmp_mail != '') {
                        if ($liste_email_profs_du_groupe != '') {
                            $liste_email_profs_du_groupe .= ", ";
                        }
                        $liste_email_profs_du_groupe .= $tmp_mail;
                    }
                    $k++;
                }
                if (!isset($signalement_id_groupe[$current_group['id']])) {
                    echo "<input type='hidden' name='signalement_id_groupe[" . $current_group['id'] . "]' id='signalement_id_groupe_" . $current_group['id'] . "' value=\"" . $current_group['name'] . " (" . $current_group['name'] . " en " . $current_group['classlist_string'] . ")\" />\n";
                }
                echo "</td>\n";
                //====================
                // Modif: boireaus 20070626
                if ($affiche_coef == 'y') {
                    if ($test_coef != 0) {
                        //if ($current_coef > 0) $print_coef= $current_coef ; else $print_coef='-';
                        //if ($coef_eleve > 0) $print_coef= $coef_eleve; else $print_coef='-';
                        if ($coef_eleve > 0) {
                            $print_coef = number_format($coef_eleve, 1, ',', ' ');
                        } else {
                            $print_coef = '-';
                        }
                        echo "<td width=\"{$larg_col2}\"";
                        if ($nb_periodes > 1) {
                            echo " rowspan= " . $nb_periodes;
                        }
                        echo " align=\"center\"><p class='bull_simpl'>" . $print_coef . "</p></td>\n";
                    }
                }
                //====================
                $nb = $periode1;
                $print_tr = 'no';
                while ($nb < $periode2 + 1) {
                    if ($print_tr == 'yes') {
                        //echo "<tr style='border-width: 5px;'>\n";
                        if ($couleur_lignes == 'y') {
                            $alt2 = $alt2 * -1;
                            echo "<tr class='lig{$alt2}' style='border-width: 5px;'>\n";
                        } else {
                            echo "<tr>\n";
                        }
                    }
                    //=========================
                    // MODIF: boireaus 20080315
                    //echo "<td width=\"$larg_col2\" align=\"center\" class='bull_simpl'>\n";
                    //if($nb>$periode1) {$style_bordure_cell="border: 1px dashed black;";} else {$style_bordure_cell="";}
                    //$style_bordure_cell="border: 1px dashed black;";
                    if ($nb == $periode1) {
                        if ($nb == $periode2) {
                            $style_bordure_cell = "border: 1px solid black";
                        } else {
                            $style_bordure_cell = "border: 1px solid black; border-bottom: 1px dashed black";
                        }
                    } elseif ($nb == $periode2) {
                        $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black;";
                    } else {
                        $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black; border-bottom: 1px dashed black;";
                    }
                    if ($affiche_colonne_moy_classe != 'n') {
                        echo "<td width=\"{$larg_col2}\" align=\"center\" class='bull_simpl' style='{$style_bordure_cell}'>\n";
                        //=========================
                        //echo "\$nb=$nb<br />";
                        $note = number_format($current_classe_matiere_moyenne[$nb], 1, ',', ' ');
                        if ($note != "0,0") {
                            echo $note;
                        } else {
                            echo "-";
                        }
                        echo "</td>\n";
                    }
                    echo "<td width=\"{$larg_col3}\" align=\"center\" class='bull_simpl' style='{$style_bordure_cell}'>\n<b>";
                    $flag_moy[$nb] = 'no';
                    if ($current_eleve_note[$nb] != '') {
                        if ($current_eleve_statut[$nb] != '') {
                            echo $current_eleve_statut[$nb];
                        } else {
                            //$note=number_format($current_eleve_note[$nb],1, ',', ' ');
                            $note = nf($current_eleve_note[$nb]);
                            echo "{$note}";
                            $flag_moy[$nb] = 'yes';
                        }
                    } else {
                        echo '-';
                    }
                    echo "</b></td>\n";
                    //Affichage des cellules rang le cas échéant
                    if ($affiche_rang == 'y') {
                        /*
                        $rang = sql_query1("select rang from matieres_notes where (
                        periode = '".$nb."' and
                        id_groupe = '".$current_group["id"]."' and
                        login = '******' )
                        ");
                        if (($rang == 0) or ($rang == -1)){
                        	$rang = "-";
                        }
                        else{
                        	//$rang.="/".$nb_notes[$current_group["id"]][$nb];
                        	//if(isset($nb_notes[$current_group["id"]][$nb])){
                        		$rang.="/".$nb_notes[$current_group["id"]][$nb];
                        	//}
                        	//$rang.="<br />\$nb_notes[".$current_group["id"]."][$nb]";
                        }
                        */
                        $rang = "-";
                        if (isset($tab_login_indice[$nb])) {
                            if (isset($tab_moy['periodes'][$nb]['current_eleve_rang'][$j][$tab_login_indice[$nb]])) {
                                // Si l'élève n'est dans le groupe que sur une période (cas des IDD), son rang n'existera pas sur certaines périodes
                                //echo "\$tab_moy['periodes'][$nb]['current_eleve_rang'][$j][".$tab_login_indice[$nb]."]=";
                                $rang = $tab_moy['periodes'][$nb]['current_eleve_rang'][$j][$tab_login_indice[$nb]];
                                //echo "$rang<br />";
                            }
                        }
                        $eff_grp_avec_note = $tab_moy['periodes'][$nb]['current_group_effectif_avec_note'][$j];
                        if ($rang != 0 && $rang != -1 && $rang != '' && $rang != '-') {
                            $rang .= "/{$eff_grp_avec_note}";
                        }
                        echo "<td width=\"{$larg_col4}\" align=\"center\" class='bull_simpl' style='{$style_bordure_cell}'><i>" . $rang . "</i></td>\n";
                    }
                    // Affichage des cases appréciations
                    echo "<td width=\"{$larg_col5}\" class='bull_simpl' style='{$style_bordure_cell}; text-align:left;'>\n";
                    // Affichage des moyennes secondaires
                    if ($nb_ligne_cn[$nb] != 0) {
                        $tiret = 'no';
                        for ($cn = 0; $cn < $nb_ligne_cn[$nb]; $cn++) {
                            $appel_cn = mysqli_query($GLOBALS["mysqli"], "select note, statut from cn_notes_conteneurs where (login='******' and id_conteneur='" . $cn_id[$nb][$cn] . "')");
                            $cn_statut = @old_mysql_result($appel_cn, 0, 'statut');
                            if ($cn_statut == 'y') {
                                $cn_note = @old_mysql_result($appel_cn, 0, 'note');
                                if ($tiret == 'yes') {
                                    echo " - ";
                                }
                                echo $cn_nom[$nb][$cn] . "&nbsp;:&nbsp;" . $cn_note;
                                $tiret = 'yes';
                            }
                        }
                        echo "<br />\n";
                    }
                    //==========================================================
                    // MODIF: boireaus 20080218
                    //        Dispositif de restriction des accès aux appréciations pour les comptes responsables/eleves
                    //if ($current_eleve_appreciation[$nb]) {
                    if ($current_eleve_appreciation[$nb] && $tab_acces_app[$nb] == "y") {
                        //==========================================================
                        //======================================
                        // MODIF: boireaus
                        //echo $current_eleve_appreciation[$nb];
                        if ($current_eleve_appreciation[$nb] == "-1") {
                            // 20120409
                            echo "<div id='app_" . $current_id_eleve . "_" . $current_group['id'] . "_{$nb}'>";
                            echo "<span class='noprint'>-</span>\n";
                            echo "</div>\n";
                        } else {
                            // 20120409
                            echo "<div id='app_" . $current_id_eleve . "_" . $current_group['id'] . "_{$nb}'>";
                            if (strstr($current_eleve_appreciation[$nb], ">") || strstr($current_eleve_appreciation[$nb], "<")) {
                                echo "{$current_eleve_appreciation[$nb]}";
                            } else {
                                echo nl2br($current_eleve_appreciation[$nb]);
                            }
                            echo "</div>\n";
                            // 20131207
                            echo "<div id='proposition_app_" . $current_id_eleve . "_" . $current_group['id'] . "_{$nb}' class='noprint'>";
                            if (isset($tab_modif_app_proposees[$current_group['id']][$nb][$current_eleve_login])) {
                                echo "<div style='border:1px solid red; color: green'><strong>Proposition de correction en attente&nbsp;:</strong><br />" . $tab_modif_app_proposees[$current_group['id']][$nb][$current_eleve_login] . "</div>";
                            }
                            echo "</div>";
                            echo "<textarea name='appreciation_" . $current_id_eleve . "_" . $current_group['id'] . "[{$nb}]' id='appreciation_" . $current_id_eleve . "_" . $current_group['id'] . "_{$nb}' style='display:none;'>" . $current_eleve_appreciation[$nb] . "</textarea>\n";
                        }
                        //======================================
                    } else {
                        // 20120409
                        echo "<div id='app_" . $current_id_eleve . "_" . $current_group['id'] . "_{$nb}'>";
                        echo "<span class='noprint'>-</span>\n";
                        echo "</div>\n";
                    }
                    echo "</td>\n";
                    if ($afficher_signalement_faute == 'y' || $afficher_proposition_correction == 'y') {
                        // A N'INSERER QUE POUR LES COMPTES DE PERSONNELS... de façon à éviter de donner les mails des profs à des élèves
                        echo "<td class='bull_simpl noprint'>";
                        if ($current_group["classe"]["ver_periode"][$id_classe][$nb] == 'O') {
                            echo "-";
                        } else {
                            // 20120409
                            echo affiche_lien_proposition_ou_correction_appreciation($current_eleve_login, $current_id_eleve, $current_eleve_prenom, $current_eleve_nom, $current_group, $id_classe, $nb, $liste_profs_du_groupe, $tab_mes_groupes, $tab_afficher_liens_modif_app);
                            /*
                            if(($_SESSION['statut']=='professeur')&&(in_array($current_group['id'],$tab_mes_groupes))) {
                            	if($current_group["classe"]["ver_periode"][$id_classe][$nb]=='N') {
                            		echo "<a href='#' onclick=\"modifier_une_appreciation('$current_eleve_login', '$current_id_eleve', '".$current_group['id']."', '$liste_profs_du_groupe', '$nb', 'corriger') ;return false;\" title=\"Modifier l'appréciation en période $nb pour $current_eleve_prenom $current_eleve_nom.
                            Si vous vous apercevez que vous avez fait une faute de frappe, ou si vous souhaitez modifier votre appréciation, ce lien est là pour ça.\" class='noprint'><img src='../images/edit16.png' width='16' height='16' /></a> ";
                            	}
                            	elseif(isset($tab_afficher_liens_modif_app[$current_group['id']][$nb])) {
                            		if($tab_afficher_liens_modif_app[$current_group['id']][$nb]=='y') {
                            			echo "<a href='#' onclick=\"modifier_une_appreciation('$current_eleve_login', '$current_id_eleve', '".$current_group['id']."', '$liste_profs_du_groupe', '$nb', 'proposer') ;return false;\" title=\"Proposer une correction de l'appréciation en période $nb pour $current_eleve_prenom $current_eleve_nom.
                            Si vous vous apercevez que vous avez fait une faute de frappe, ou si vous souhaitez simplement modifier votre appréciation, ce lien est là pour ça.\" class='noprint'><img src='../images/edit16.png' width='16' height='16' /></a> ";
                            		}
                            		elseif($tab_afficher_liens_modif_app[$current_group['id']][$nb]=='yy') {
                            			echo "<a href='#' onclick=\"modifier_une_appreciation('$current_eleve_login', '$current_id_eleve', '".$current_group['id']."', '$liste_profs_du_groupe', '$nb', 'corriger') ;return false;\" title=\"Modifier l'appréciation en période $nb pour $current_eleve_prenom $current_eleve_nom.
                            Si vous vous apercevez que vous avez fait une faute de frappe, ou si vous souhaitez modifier votre appréciation, ce lien est là pour ça.\" class='noprint'><img src='../images/edit16.png' width='16' height='16' /></a> ";
                            		}
                            		//echo "plop";
                            	}
                            }
                            */
                            // Tester si l'adresse mail du/des profs de l'enseignement est renseignée et si l'envoi de mail est actif.
                            // Sinon, on pourrait enregistrer le signalement dans une table actions_signalements pour affichage comme le Panneau d'affichage
                            if ($afficher_signalement_faute == 'y') {
                                echo "<a href=\"mailto:{$liste_email_profs_du_groupe}?Subject=[Gepi]: Signaler un problème/faute&body=Bonjour,Je pense que vous avez commis une faute de frappe pour {$current_eleve_login} dans l enseignement n°" . $current_group['id'] . ".Cordialement.-- " . casse_mot($_SESSION['prenom'], 'majf2') . " " . $_SESSION['nom'] . "\"";
                                if ($envoi_mail_actif != 'n') {
                                    //echo " onclick=\"alert('plop');return false;\"";
                                    echo " onclick=\"signaler_une_faute('{$current_eleve_login}', '{$current_id_eleve}', '" . $current_group['id'] . "', '{$liste_profs_du_groupe}', '{$nb}') ;return false;\"";
                                }
                                echo " title=\"Signaler une faute de frappe, d'orthographe ou autre...\nSi vous vous apercevez que ce collègue a fait une erreur,\nvous pouvez lui envoyer un mail pour l'alerter.\nCe lien est là pour ça.\" target='_blank'><img src='../images/icons/mail.png' width='16' height='16' alt='Signaler un problème/faute par mail' /></a>";
                                echo "<span id='signalement_effectue_" . $current_id_eleve . "_" . $current_group['id'] . "_{$nb}'></span>";
                            }
                        }
                        echo "</td>\n";
                    }
                    echo "</tr>\n";
                    $print_tr = 'yes';
                    $nb++;
                }
                /*
                // On calcule les moyennes générales de l'élève et de la classe :
                if ($test_coef != 0) {
                	$nb=$periode1;
                	while ($nb < $periode2+1) {
                		if ($flag_moy[$nb] == 'yes') {
                		
                			//===========================
                			// MODIF: boireaus 20070627
                			//$total_coef[$nb] += $current_coef;
                			//$total_points_classe[$nb] += $current_coef*$current_classe_matiere_moyenne[$nb];
                			//$total_points_eleve[$nb] += $current_coef*$current_eleve_note[$nb];
                		
                			if($mode_moy=='-') {
                				$total_coef_eleve[$nb] += $coef_eleve;
                				$total_points_eleve[$nb] += $coef_eleve*$current_eleve_note[$nb];
                		
                				$total_coef_classe[$nb] += $current_coef;
                				$total_points_classe[$nb] += $current_coef*$current_classe_matiere_moyenne[$nb];
                			}
                			elseif($mode_moy=='sup10') {
                				if($current_eleve_note[$nb]>10) {
                					$total_points_eleve[$nb] += $coef_eleve*($current_eleve_note[$nb]-10);
                				}
                		
                				if($current_classe_matiere_moyenne[$nb]>0) {
                					$total_points_classe[$nb] += $current_coef*($current_classe_matiere_moyenne[$nb]-10);
                				}
                			}
                			else {
                				echo "<p>ANOMALIE&nbsp;: \$mode_moy='$mode_moy' mode inconnu pour ".$current_group['name']."</p>\n";
                			}
                		
                			//===========================
                		
                			//if($affiche_categories=='1'){
                			if(($affiche_categories=='1')||($affiche_categories==true)){
                				$total_cat_classe[$nb][$prev_cat_id] += $current_coef*$current_classe_matiere_moyenne[$nb];
                		
                				//===========================
                				// MODIF: boireaus 20070627
                				//$total_cat_eleve[$nb][$prev_cat_id] += $current_coef*$current_eleve_note[$nb];
                				$total_cat_eleve[$nb][$prev_cat_id] += $coef_eleve*$current_eleve_note[$nb];
                				//$total_cat_coef[$nb][$prev_cat_id] += $current_coef;
                				$total_cat_coef_eleve[$nb][$prev_cat_id] += $coef_eleve;
                				$total_cat_coef_classe[$nb][$prev_cat_id] += $current_coef;
                				//===========================
                			}
                		}
                		$nb++;
                	}
                }
                */
            }
            //$j++;
            //  echo "</table>";
        }
        //echo "<table width=$larg_tab border=1 cellspacing=1 cellpadding=1>";
        // On attaque maintenant l'affichage des appréciations des Activités Interdisciplinaires devant apparaître en fin de bulletin :
        $call_data = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM aid_config WHERE order_display1 = 'e' ORDER BY order_display2");
        $nb_aid = mysqli_num_rows($call_data);
        $z = 0;
        while ($z < $nb_aid) {
            $display_begin = old_mysql_result($call_data, $z, "display_begin");
            $display_end = old_mysql_result($call_data, $z, "display_end");
            if ($periode1 >= $display_begin and $periode2 <= $display_end) {
                $indice_aid = @old_mysql_result($call_data, $z, "indice_aid");
                $aid_query = mysqli_query($GLOBALS["mysqli"], "SELECT id_aid FROM j_aid_eleves WHERE (login='******' and indice_aid='{$indice_aid}')");
                $aid_id = @old_mysql_result($aid_query, 0, "id_aid");
                if ($aid_id != '') {
                    affiche_aid_simple($affiche_rang, $test_coef, $indice_aid, $aid_id, $current_eleve_login, $periode1, $periode2, $id_classe, 'bull_simpl', $affiche_coef);
                }
            }
            $z++;
        }
        //echo "</table>";
        //echo "<table width=$larg_tab border=1 cellspacing=1 cellpadding=1>";
        //====================================================================
        //====================================================================
        //====================================================================
        echo "</tbody>\n";
        // Affichage des moyennes générales
        echo "<tfoot>\n";
        if ($display_moy_gen == "y") {
            if ($test_coef != 0) {
                echo "<tr>\n<td";
                if ($nb_periodes > 1) {
                    echo " rowspan=" . $nb_periodes;
                }
                echo ">\n<p class='bull_simpl'><b>Moyenne générale</b></p>\n</td>\n";
                //====================
                // Modif: boireaus 20070626
                if ($affiche_coef == 'y') {
                    echo "<td";
                    if ($nb_periodes > 1) {
                        echo " rowspan=" . $nb_periodes;
                    }
                    echo " align=\"center\" style='{$style_bordure_cell}'>-</td>\n";
                }
                //====================
                $nb = $periode1;
                $print_tr = 'no';
                while ($nb < $periode2 + 1) {
                    //=============================
                    //if($nb==$periode1){echo "<tr>\n";}
                    if ($print_tr == 'yes') {
                        echo "<tr style='border-width: 5px;'>\n";
                    }
                    //=============================
                    //=========================
                    // AJOUT: boireaus 20080315
                    if ($nb == $periode1) {
                        if ($nb == $periode2) {
                            $style_bordure_cell = "border: 1px solid black";
                        } else {
                            $style_bordure_cell = "border: 1px solid black; border-bottom: 1px dashed black";
                        }
                    } elseif ($nb == $periode2) {
                        $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black;";
                    } else {
                        $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black; border-bottom: 1px dashed black;";
                    }
                    //=========================
                    if ($affiche_colonne_moy_classe != 'n') {
                        echo "<td class='bull_simpl' align=\"center\" style='{$style_bordure_cell}'>\n";
                        /*
                        //echo "\$total_points_classe[$nb]=$total_points_classe[$nb]<br />\n";
                        //echo "\$tab_moy_gen[$nb]=$tab_moy_gen[$nb]<br />\n";
                        //if ($total_points_classe[$nb] != 0) {
                        if(($total_points_classe[$nb]!=0)||(isset($tab_moy_gen[$nb]))) {
                        	//$moy_classe=number_format($total_points_classe[$nb]/$total_coef[$nb],1, ',', ' ');
                        	
                        	//=========================
                        	// MODIF: boireaus 20080316
                        	//$moy_classe=number_format($total_points_classe[$nb]/$total_coef_classe[$nb],1, ',', ' ');
                        	//$moy_classe=number_format($tab_moy_gen[$nb],1, ',', ' ');
                        	$moy_classe=$tab_moy_gen[$nb];
                        	//=========================
                        } else {
                        	$moy_classe = '-';
                        }
                        //echo "$moy_classe";
                        echo nf($moy_classe);
                        */
                        echo nf($tab_moy['periodes'][$nb]['moy_generale_classe'], 2);
                        if ($affiche_deux_moy_gen == 1) {
                            echo "<br />\n";
                            $moy_classe1 = $tab_moy['periodes'][$nb]['moy_generale_classe1'];
                            echo "<i>" . nf($moy_classe1, 2) . "</i>\n";
                        }
                        echo "</td>\n";
                    }
                    echo "<td class='bull_simpl' align=\"center\" style='{$style_bordure_cell}'>\n";
                    /*
                    if ($total_points_eleve[$nb] != '0') {
                    	//$moy_eleve=number_format($total_points_eleve[$nb]/$total_coef[$nb],1, ',', ' ');
                    	$moy_eleve=number_format($total_points_eleve[$nb]/$total_coef_eleve[$nb],1, ',', ' ');
                    } else {
                    	$moy_eleve = '-';
                    }
                    */
                    if (isset($tab_login_indice[$nb])) {
                        $moy_eleve = $tab_moy['periodes'][$nb]['moy_gen_eleve'][$tab_login_indice[$nb]];
                        echo "<b>" . nf($moy_eleve, 2) . "</b>\n";
                        if ($affiche_deux_moy_gen == 1) {
                            echo "<br />\n";
                            $moy_eleve1 = $tab_moy['periodes'][$nb]['moy_gen_eleve1'][$tab_login_indice[$nb]];
                            echo "<i><b>" . nf($moy_eleve1, 2) . "</b></i>\n";
                        }
                    } else {
                        echo "-\n";
                    }
                    echo "</td>\n";
                    if ($affiche_rang == 'y') {
                        $rang = sql_query1("select rang from j_eleves_classes where (\n\t\t\t\t\tperiode = '" . $nb . "' and\n\t\t\t\t\tid_classe = '" . $id_classe . "' and\n\t\t\t\t\tlogin = '******' )\n\t\t\t\t\t");
                        $nombre_eleves = count($tab_moy['periodes'][$nb]['current_eleve_login']);
                        if ($rang == 0 or $rang == -1) {
                            $rang = "-";
                        } else {
                            $rang .= "/" . $nombre_eleves;
                        }
                        echo "<td class='bull_simpl' align=\"center\" style='{$style_bordure_cell}'>" . $rang . "</td>\n";
                    }
                    if ($affiche_categories) {
                        echo "<td class='bull_simpl' style='{$style_bordure_cell}; text-align:left;'>\n";
                        foreach ($categories as $cat_id) {
                            // MODIF: boireaus 20070627 ajout du test et utilisation de $total_cat_coef_eleve, $total_cat_coef_classe
                            // Tester si cette catégorie doit avoir sa moyenne affichée
                            $affiche_cat_moyenne_query = mysqli_query($GLOBALS["mysqli"], "SELECT affiche_moyenne FROM j_matieres_categories_classes WHERE (classe_id = '" . $id_classe . "' and categorie_id = '" . $cat_id . "')");
                            if (mysqli_num_rows($affiche_cat_moyenne_query) == "0") {
                                $affiche_cat_moyenne = false;
                            } else {
                                $affiche_cat_moyenne = old_mysql_result($affiche_cat_moyenne_query, 0);
                            }
                            if ($affiche_cat_moyenne) {
                                /*
                                //if ($total_cat_coef[$nb][$cat_id] != "0") {
                                if ($total_cat_coef_eleve[$nb][$cat_id] != "0") {
                                	//$moy_eleve=number_format($total_cat_eleve[$nb][$cat_id]/$total_cat_coef[$nb][$cat_id],1, ',', ' ');
                                	//$moy_classe=number_format($total_cat_classe[$nb][$cat_id]/$total_cat_coef[$nb][$cat_id],1, ',', ' ');
                                	$moy_eleve=number_format($total_cat_eleve[$nb][$cat_id]/$total_cat_coef_eleve[$nb][$cat_id],1, ',', ' ');
                                	
                                	if ($total_cat_coef_classe[$nb][$cat_id] != "0") {
                                		$moy_classe=number_format($total_cat_classe[$nb][$cat_id]/$total_cat_coef_classe[$nb][$cat_id],1, ',', ' ');
                                	}
                                	else{
                                		$moy_classe="-";
                                	}
                                	
                                	echo $cat_names[$cat_id] . " - <b>".$moy_eleve."</b> (classe : " . $moy_classe . ")<br/>\n";
                                }
                                */
                                // Si l'élève est bien dans la classe sur la période $nb
                                if (isset($tab_login_indice[$nb])) {
                                    $moy_eleve = $tab_moy['periodes'][$nb]['moy_cat_eleve'][$tab_login_indice[$nb]][$cat_id];
                                    $moy_classe = $tab_moy['periodes'][$nb]['moy_cat_classe'][$tab_login_indice[$nb]][$cat_id];
                                    echo $cat_names[$cat_id] . " - <b>" . nf($moy_eleve, 2) . "</b> (classe : " . nf($moy_classe, 2) . ")<br/>\n";
                                }
                            }
                        }
                        echo "</td>\n</tr>\n";
                    } else {
                        echo "<td class='bull_simpl' style='text-align:left; {$style_bordure_cell}'>-</td>\n</tr>\n";
                    }
                    $nb++;
                    $print_tr = 'yes';
                }
            }
        }
        echo "</tfoot>\n";
        echo "</table>\n";
        // Les absences
        // On ne les affiche que si dans le bulletin HTML, on affiche les absences
        if (getSettingAOui('bull_affiche_absences')) {
            echo "<span class='bull_simpl'><b>Absences et retards:</b></span>\n";
            //echo "<table width=$larg_tab border=1 cellspacing=1 cellpadding=1>\n";
            echo "<table width='{$larg_tab}' class='boireaus' cellspacing='1' cellpadding='1' summary='Absences et retards'>\n";
            $nb = $periode1;
            while ($nb < $periode2 + 1) {
                //On vérifie si le module est activé
                if (getSettingValue("active_module_absence") != '2' || getSettingValue("abs2_import_manuel_bulletin") == 'y') {
                    $current_eleve_absences_query = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM absences WHERE (login='******' AND periode='{$nb}')");
                    $eleve_abs[$nb] = @old_mysql_result($current_eleve_absences_query, 0, "nb_absences");
                    $eleve_abs_nj[$nb] = @old_mysql_result($current_eleve_absences_query, 0, "non_justifie");
                    $eleve_retards[$nb] = @old_mysql_result($current_eleve_absences_query, 0, "nb_retards");
                    $current_eleve_appreciation_absences = @old_mysql_result($current_eleve_absences_query, 0, "appreciation");
                    $eleve_app_abs[$nb] = @old_mysql_result($current_eleve_absences_query, 0, "appreciation");
                } else {
                    // Initialisations files
                    require_once "../lib/initialisationsPropel.inc.php";
                    $eleve = EleveQuery::create()->findOneByLogin($current_eleve_login);
                    if ($eleve != null) {
                        $current_eleve_absences_query = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM absences WHERE (login='******' AND periode='{$nb}')");
                        $eleve_abs[$nb] = $eleve->getDemiJourneesAbsenceParPeriode($nb)->count();
                        $eleve_abs_nj[$nb] = $eleve->getDemiJourneesNonJustifieesAbsenceParPeriode($nb)->count();
                        $eleve_retards[$nb] = $eleve->getRetardsParPeriode($nb)->count();
                        $current_eleve_appreciation_absences = @old_mysql_result($current_eleve_absences_query, 0, "appreciation");
                        $eleve_app_abs[$nb] = @old_mysql_result($current_eleve_absences_query, 0, "appreciation");
                    }
                }
                if ($eleve_abs[$nb] !== '' and $eleve_abs_nj[$nb] !== '') {
                    $eleve_abs_j[$nb] = $eleve_abs[$nb] - $eleve_abs_nj[$nb];
                } else {
                    $eleve_abs_j[$nb] = "?";
                }
                if ($eleve_abs_nj[$nb] === '') {
                    $eleve_abs_nj[$nb] = "?";
                }
                if ($eleve_retards[$nb] === '') {
                    $eleve_retards[$nb] = "?";
                }
                //====================================
                // AJOUT: boireaus 20080317
                if ($nb == $periode1) {
                    if ($nb == $periode2) {
                        $style_bordure_cell = "border: 1px solid black";
                    } else {
                        $style_bordure_cell = "border: 1px solid black; border-bottom: 1px dashed black";
                    }
                } elseif ($nb == $periode2) {
                    $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black;";
                } else {
                    $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black; border-bottom: 1px dashed black;";
                }
                //====================================
                $nb_colspan_abs = 0;
                if (getSettingValue('bull_affiche_abs_tot') == 'y') {
                    $nb_colspan_abs++;
                }
                if (getSettingValue('bull_affiche_abs_nj') == 'y') {
                    $nb_colspan_abs++;
                }
                if (getSettingValue('bull_affiche_abs_ret') == 'y') {
                    $nb_colspan_abs++;
                }
                echo "<tr>\n<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>{$nom_periode[$nb]}</td>\n";
                // Test pour savoir si l'élève appartient à la classe pour la période considérée
                $test_eleve_app = sql_query1("select count(login) from j_eleves_classes where login='******' and id_classe='" . $id_classe . "' and periode='" . $nb . "'");
                if (getSettingValue('bull_affiche_abs_tot') == 'y' || getSettingValue('bull_affiche_abs_nj') == 'y' || getSettingValue('bull_affiche_abs_ret') == 'y') {
                    if ($test_eleve_app != 0) {
                        // 20130215
                        if (getSettingValue('bull_affiche_abs_tot') == 'y') {
                            if (getSettingValue('bull_affiche_abs_nj') == 'y') {
                                echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>\n";
                                if ($eleve_abs_j[$nb] == "1") {
                                    echo "Absences justifiées : une demi-journée";
                                } else {
                                    if ($eleve_abs_j[$nb] != "0") {
                                        echo "Absences justifiées : {$eleve_abs_j[$nb]} demi-journées";
                                    } else {
                                        echo "Aucune absence justifiée";
                                    }
                                }
                                echo "</td>\n";
                                echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>\n";
                                if ($eleve_abs_nj[$nb] == '1') {
                                    echo "Absences non justifiées : une demi-journée";
                                } else {
                                    if ($eleve_abs_nj[$nb] != '0') {
                                        echo "Absences non justifiées : {$eleve_abs_nj[$nb]} demi-journées";
                                    } else {
                                        echo "Aucune absence non justifiée";
                                    }
                                }
                                echo "</td>\n";
                            } else {
                                echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>\n";
                                if ($eleve_abs[$nb] > 0) {
                                    echo "Nombre de demi-journées : " . $eleve_abs[$nb];
                                } else {
                                    echo "Aucune absence";
                                }
                                echo "</td>\n";
                            }
                        } elseif (getSettingValue('bull_affiche_abs_nj') == 'y') {
                            echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>\n";
                            if ($eleve_abs_nj[$nb] == "1") {
                                echo "Absences non-justifiées : une demi-journée";
                            } else {
                                if ($eleve_abs_nj[$nb] != "0") {
                                    echo "Absences non-justifiées : {$eleve_abs_nj[$nb]} demi-journées";
                                } else {
                                    echo "Aucune absence non-justifiée";
                                }
                            }
                            echo "</td>\n";
                        }
                        if (getSettingValue('bull_affiche_abs_ret') == 'y') {
                            echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>Nb. de retards : {$eleve_retards[$nb]}</td>\n";
                        }
                        echo "</tr>\n";
                    } else {
                        if (getSettingValue('bull_affiche_abs_tot') == 'y') {
                            echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>-</td>\n";
                        }
                        if (getSettingValue('bull_affiche_abs_nj') == 'y') {
                            echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>-</td>\n";
                        }
                        if (getSettingValue('bull_affiche_abs_ret') == 'y') {
                            echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>-</td>\n";
                        }
                        echo "</tr>\n";
                    }
                } else {
                    if ($nb_colspan_abs > 0) {
                        echo "<td colspan='{$nb_colspan_abs}' valign=top class='bull_simpl' style='{$style_bordure_cell}'>-</td>\n";
                    } else {
                        echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>-</td>\n";
                    }
                    echo "</tr>\n";
                }
                //Ajout Eric
                if ($current_eleve_appreciation_absences != "") {
                    if ($test_eleve_app != 0) {
                        echo "<tr>\n";
                        echo "<td valign=top class='bull_simpl' style='{$style_bordure_cell}'>&nbsp;</td>\n";
                        if ($nb_colspan_abs > 0) {
                            echo "<td valign=top class='bull_simpl' colspan=\"{$nb_colspan_abs}\" style='text-align:left; {$style_bordure_cell}'>";
                        } else {
                            echo "<td valign=top class='bull_simpl' style='text-align:left; {$style_bordure_cell}'>";
                        }
                        echo " Observation(s) : {$current_eleve_appreciation_absences}</td>\n</tr>\n";
                    } else {
                        echo "<tr><td valign=top class='bull_simpl' style='{$style_bordure_cell}'>&nbsp;</td><td valign=top class='bull_simpl' colspan=\"3\" style='{$style_bordure_cell}'>-</td>\n</tr>\n";
                    }
                }
                $nb++;
            }
            echo "</table>\n";
        }
        $tab_classe_periode = get_infos_classe_periode($id_classe);
        // Maintenant, on met l'avis du conseil de classe :
        echo "<span class='bull_simpl'><b>Avis du conseil de classe </b> ";
        if ($current_eleve_profsuivi_login) {
            $gepi_prof_suivi = ucfirst(retourne_denomination_pp($id_classe));
            echo "<b>(" . ucfirst($gepi_prof_suivi) . " : <i>" . affiche_utilisateur($current_eleve_profsuivi_login, $id_classe) . "</i>)</b>";
        }
        echo " :</span>\n";
        $larg_col1b = $larg_tab - $larg_col1;
        echo "<table width=\"{$larg_tab}\" class='boireaus' cellspacing='1' cellpadding='1' summary='Avis du conseil de classe'>\n";
        $nb = $periode1;
        while ($nb < $periode2 + 1) {
            //=========================
            if ($nb == $periode1) {
                if ($nb == $periode2) {
                    $style_bordure_cell = "border: 1px solid black";
                } else {
                    $style_bordure_cell = "border: 1px solid black; border-bottom: 1px dashed black";
                }
            } elseif ($nb == $periode2) {
                $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black;";
            } else {
                $style_bordure_cell = "border: 1px solid black; border-top: 1px dashed black; border-bottom: 1px dashed black;";
            }
            //=========================
            $current_eleve_avis_query = mysqli_query($GLOBALS["mysqli"], "SELECT * FROM avis_conseil_classe WHERE (login='******' AND periode='{$nb}')");
            $current_eleve_avis[$nb] = @old_mysql_result($current_eleve_avis_query, 0, "avis");
            // **** AJOUT POUR LA MENTION ****
            $current_eleve_mention[$nb] = @old_mysql_result($current_eleve_avis_query, 0, "id_mention");
            // **** FIN D'AJOUT POUR LA MENTION ****
            // Test pour savoir si l'élève appartient à la classe pour la période considérée
            $test_eleve_app = sql_query1("select count(login) from j_eleves_classes where login='******' and id_classe='" . $id_classe . "' and periode='" . $nb . "'");
            if ($current_eleve_avis[$nb] == '' or $tab_acces_app[$nb] != "y" or $test_eleve_app == 0) {
                $current_eleve_avis[$nb] = ' -';
            }
            echo "<tr>\n<td valign=\"top\" width =\"{$larg_col1}\" class='bull_simpl' style='text-align:left; {$style_bordure_cell}'>{$nom_periode[$nb]}</td>\n";
            echo "<td valign=\"top\"  width = \"{$larg_col1b}\" class='bull_simpl' style='text-align:left; {$style_bordure_cell}' title=\"Avis du conseil de classe en période n°{$nb} pour " . $current_eleve_prenom . " " . $current_eleve_nom . "\">";
            if ($temoin_page_courante != "saisie_avis2" && $tab_classe_periode[$nb]['verouiller'] != "O") {
                if ($_SESSION['statut'] == 'scolarite' || $_SESSION['statut'] == 'professeur' && is_pp($_SESSION['login'], $id_classe)) {
                    echo "<div style='float:right; width:16px;' title=\"Saisir/Modifier l'avis du conseil de classe.\" class='noprint'><a href = '../saisie/saisie_avis2.php?periode_num={$nb}&amp;id_classe={$id_classe}&amp;fiche=y&amp;current_eleve_login={$current_eleve_login}#app' onclick=\"return confirm_abandon (this, change, '{$themessage}')\"><img src='../images/edit16.png' class='icone16' alt='Editer' /></a></div>";
                    //&amp;ind_eleve_login_suiv=$ind_eleve_login_suiv
                }
            }
            echo $current_eleve_avis[$nb];
            // Ajouter par la suite une option pour faire apparaître les mentions même si c'est "-"
            //if(($current_eleve_mention[$nb]=="F")||($current_eleve_mention[$nb]=="M")||($current_eleve_mention[$nb]=="E")) {
            $afficher_les_mentions = "y";
            if ($_SESSION['statut'] == 'eleve' || $_SESSION['statut'] == 'responsable') {
                if ($tab_acces_app[$nb] != "y") {
                    $afficher_les_mentions = "n";
                }
            }
            if ($afficher_les_mentions == "y") {
                if (!isset($tableau_des_mentions_sur_le_bulletin) || !is_array($tableau_des_mentions_sur_le_bulletin) || count($tableau_des_mentions_sur_le_bulletin) == 0) {
                    $tableau_des_mentions_sur_le_bulletin = get_mentions();
                }
                if (isset($tableau_des_mentions_sur_le_bulletin[$current_eleve_mention[$nb]])) {
                    echo "<br />\n";
                    echo "<br />\n";
                    echo "<b>" . $gepi_denom_mention . " : </b>";
                    echo $tableau_des_mentions_sur_le_bulletin[$current_eleve_mention[$nb]];
                    //else {echo "-";}
                }
            }
            echo "</td>\n";
            echo "</tr>\n";
            $nb++;
        }
        echo "</table>\n";
    }
    // fin de la condition if ($on_continue == 'yes')
}
示例#8
0
/**
 * Add user id in cb_user_mentions table so that in case
 * user updates profile we can update feeds too
 * 
 * @param STRING $messag
 * @param ARRAY $feed_id
 */
function add_users_mentioned($message, $fid = NULL, $cid = NULL)
{
    global $cbfeeds, $userquery;
    if ($message && ($fid || $cid)) {
        if ($fid) {
            $object = $cbfeeds->get_feed_object($fid);
        }
        if ($cid && $fid) {
            $object = get_comment_object($cid);
        }
        $mentions = get_mentions($message);
        if ($mentions) {
            foreach ($mentions as $mention) {
                db_insert(tbl('user_mentions'), array('userid' => userid(), 'who_id' => $mention['id'], 'who_type' => $mention['type'], 'feed_id' => $fid, 'comment_id' => $cid, 'time' => time(), 'date_added' => now()));
                if (!$cid && $fid) {
                    //Adding subscriptions..
                    $cbfeeds->addSubscription(array('id' => $fid, 'type' => 'feed_mention', 'userid' => $mention['id']));
                }
                $notification_action = 'feed_mention';
                if ($cid) {
                    $notification_action = 'comment_mention';
                }
                $cbfeeds->addNotification(array('action' => $notification_action, 'feed_id' => $fid, 'comment_id' => $cid, 'object_id' => $object['object_id'], 'object_type' => $object['object_type'], 'object' => $object['object'], 'actor_id' => userid(), 'userid' => $mention['id'], 'actor' => get_content('user', $userquery->udetails)));
            }
            return true;
        }
    }
    return false;
}