echo ' <span class="invalide">' . "\n";
                        }
                        echo '<span class="bold">' . get_string('liste_codes_competence', 'referentiel') . '</span>' . "\n";
                        echo referentiel_affiche_liste_codes_competence('/', $competences_activite, $ref_referentiel) . "\n";
                        echo '</span>' . "\n";
                        if ($CFG->referentiel_use_scale) {
                            require_once 'lib_bareme.php';
                            if ($rec_assoc = referentiel_get_assoc_bareme_occurrence($ref_referentiel)) {
                                if ($bareme = referentiel_get_bareme($rec_assoc->refscaleid)) {
                                    $competences_bareme = referentiel_get_competences_activite($activite_id, $bareme->id);
                                    if (empty($competences_bareme)) {
                                        // creer le bareme
                                        $competences_bareme = referentiel_creer_competences_activite($record_a, $bareme);
                                    }
                                    if ($competences_bareme) {
                                        echo '</span><br /><span class="bold">' . get_string('evaluation', 'referentiel') . '</span><br />' . referentiel_affiche_bareme_activite($competences_bareme, $bareme, true);
                                    }
                                }
                            }
                        }
                        echo '<br /><span class="bold">' . get_string('description', 'referentiel') . '</span><br /><span class="white">' . nl2br($description_activite) . '</span>
<br />
';
                        echo '<br /><span class="bold">' . get_string('commentaire', 'referentiel') . '</span>';
                        echo '<br /><textarea cols="80" rows="10" name="commentaire_activite">' . s($commentaire_activite) . '</textarea>
<br /><span class="bold">' . get_string('referent', 'referentiel') . '</span>' . s($teacher_info) . '
<br />' . "\n";
                        echo '<span class="bold">' . get_string('modification', 'referentiel') . '</span>' . "\n";
                        if (!empty($date_modif_info)) {
                            echo get_string('date_modif_by', 'referentiel') . '<i>' . $date_modif_info . '</i>';
                        }
/** Affiche une activite et les documents associés
 *
 *  input @param record_a  an object  activite
 *  detail true / false
 *  numero integer
 *  output null                                                     *
**/
function referentiel_print_activite_detail($bareme, $record_a, $context, $detail = true, $numero = 0)
{
    global $CFG;
    $s = '';
    $s0 = '';
    $s1 = '';
    $s2 = '';
    $nblignes = 4;
    // hauteur du tableau
    $nbressource = 0;
    if ($record_a) {
        $activite_id = $record_a->id;
        $type_activite = stripslashes($record_a->type_activite);
        $description_activite = stripslashes($record_a->description_activite);
        $competences_activite = $record_a->competences_activite;
        $commentaire_activite = stripslashes($record_a->commentaire_activite);
        $ref_instance = $record_a->ref_instance;
        $ref_referentiel = $record_a->ref_referentiel;
        $ref_course = $record_a->ref_course;
        $userid = $record_a->userid;
        $teacherid = $record_a->teacherid;
        $date_creation = $record_a->date_creation;
        $date_modif = $record_a->date_modif;
        $date_modif_student = $record_a->date_modif_student;
        $approved = $record_a->approved;
        $user_info = referentiel_get_user_info($userid);
        $teacher_info = referentiel_get_user_info($teacherid);
        if (empty($teacher_info)) {
            $teacher_info = get_string('inconnu', 'referentiel');
        }
        // dates
        $date_creation_info = userdate($date_creation);
        if ($date_modif != 0) {
            $date_modif_info = userdate($date_modif);
        } else {
            $date_modif_info = '';
        }
        if ($date_modif_student != 0) {
            $date_modif_student_info = userdate($date_modif_student);
        } else {
            $date_modif_student_info = '';
        }
        $ref_task = $record_a->ref_task;
        $stask = '';
        if ($ref_task) {
            // consignes associées à une tâche
            $titre_task = referentiel_get_theme_task($ref_task);
            $info_task = referentiel_get_content_task($ref_task);
            // $stask.='<br /><span class="light">'.get_string('task','referentiel').'</span>'."\n";
            if ($info_task != '') {
                // lien vers la tâche
                $stask .= ' ' . referentiel_affiche_overlib_texte($titre_task, $info_task) . "\n";
            }
            // documents associés à une tâche
            $stask .= referentiel_print_liste_documents_task($ref_task, referentiel_get_auteur_task($ref_task), $context);
        }
        $url_course = referentiel_get_course_link($ref_course);
        $url_instance = referentiel_get_instance_link($ref_instance);
        // preparation pour overlay
        if (empty($t_item_code) || empty($t_item_description_competence)) {
            referentiel_initialise_descriptions_items_referentiel($ref_referentiel);
        }
        $prioritaire = referentiel_activite_prioritaire($record_a);
        $s0 .= '
<a name="activite_' . $activite_id . '"></a>' . "\n";
        if (!empty($prioritaire)) {
            $s0 .= '<div class="ref_affprioritaire">' . "\n";
        } else {
            if (isset($approved) && $approved) {
                $s0 .= '<div class="ref_affvalide">' . "\n";
            } else {
                $s0 .= '<div class="ref_affinvalide">' . "\n";
            }
        }
        // entetete
        $s0 .= '<span class="bold">' . get_string('id_activite', 'referentiel', $activite_id) . '</span>';
        $s0 .= '<span class="light">' . get_string('type_activite', 'referentiel') . '</span> ' . $type_activite . "\n";
        $s0 .= $stask;
        $s0 .= '<span class="light">' . get_string('course') . '</span> ' . $url_course . "\n";
        $s0 .= '<span class="light">' . get_string('instance', 'referentiel') . '</span> ' . '<i>' . $url_instance . '</i>' . "\n";
        $s0 .= '</div>' . "\n";
        // details
        if ($detail) {
            if ($numero % 2 == 0) {
                $s1 .= '<div class="ref_affact1">';
            } else {
                $s1 .= '<div class="ref_affact2">';
            }
            $s1 .= '<span class="light">' . get_string('auteur', 'referentiel') . '</span> ' . $user_info;
            $liste_groupes = referentiel_liste_groupes_user($ref_course, $userid);
            if (!empty($liste_groupes)) {
                $s1 .= ' &nbsp; <i>' . $liste_groupes . '</i>' . "\n";
            }
            $s1 .= ' <span class="light">' . get_string('date_creation', 'referentiel') . '</span>
<span class="ital">' . $date_creation_info . '</span>' . "\n";
            if (!empty($date_modif_student_info) && $date_modif_student - $date_creation > 1000) {
                $s1 .= '<span class="light">' . get_string('date_modif_student', 'referentiel') . '</span>
<span class="ital">' . $date_modif_student_info . '</span>' . "\n";
            }
            if (!empty($date_modif_info)) {
                $s1 .= '<span class="light">' . get_string('date_modif', 'referentiel') . '</span>
<span class="ital">' . $date_modif_info . '</span>' . "\n";
            }
            $s1 .= '<br /><span class="light">' . get_string('referent', 'referentiel') . '</span> ' . $teacher_info . '
<span class="light">' . get_string('validation', 'referentiel') . '</span>' . "\n";
            if (isset($approved) && $approved) {
                $s1 .= get_string('approved', 'referentiel');
            } else {
                $s1 .= get_string('not_approved', 'referentiel');
            }
            if (isset($approved) && $approved) {
                $s1 .= ' <span class="valide">' . "\n";
            } else {
                $s1 .= ' <span class="invalide">' . "\n";
            }
            $s1 .= '<br /><span class="light">' . get_string('liste_codes_competence', 'referentiel') . '</span> <span class="bold">' . "\n";
            $s1 .= referentiel_affiche_liste_codes_competence('/', $competences_activite, $ref_referentiel) . "\n";
            $s1 .= '</span>' . "\n";
            /*
            			if ($CFG->referentiel_use_scale){
            				require_once('lib_bareme.php');
            				if ($rec_assoc=referentiel_get_assoc_bareme_occurrence($ref_referentiel)){
            					if ($bareme=referentiel_get_bareme($rec_assoc->refscaleid)){
            */
            if (!empty($bareme)) {
                $competences_bareme = referentiel_get_competences_activite($activite_id, $bareme->id);
                if (empty($competences_bareme)) {
                    // creer le bareme
                    $competences_bareme = referentiel_creer_competences_activite($record_a, $bareme);
                }
                if ($competences_bareme) {
                    if ($detail) {
                        $s1 .= '</span><br /><span class="light">' . get_string('evaluation', 'referentiel') . '</span><br /><span class="white">' . referentiel_affiche_bareme_activite($competences_bareme, $bareme, true) . '</span>' . "\n";
                    } else {
                        $s1 .= '</span><br /><span class="light">' . get_string('evaluation', 'referentiel') . '</span><br /><span class="white">' . referentiel_affiche_bareme_activite($competences_bareme, $bareme, false) . '</span>' . "\n";
                    }
                }
            }
            /*
            				}
            			}
            */
            $s1 .= '</span>' . "\n";
            //$s1.=$stask;
            $s1 .= '<br /><span class="light">' . get_string('description', 'referentiel') . '</span>' . "\n";
            $s1 .= '<div class="ref_aff0">' . nl2br($description_activite) . '</div>' . "\n";
            $s1 .= '<span class="light">' . get_string('commentaire', 'referentiel') . '</span>' . "\n";
            $s1 .= '<div class="ref_aff1">' . nl2br($commentaire_activite) . '</div>' . "\n";
            $s1 .= '</div>' . "\n";
        } else {
            // NO details
            if ($numero % 2 == 0) {
                $s1 .= '<div class="ref_affact1">';
            } else {
                $s1 .= '<div class="ref_affact2">';
            }
            $s1 .= $user_info;
            $liste_groupes = referentiel_liste_groupes_user($ref_course, $userid);
            if (!empty($liste_groupes)) {
                $s1 .= ' &nbsp; <i>' . $liste_groupes . '</i>' . "\n";
            }
            if (!empty($date_modif_student_info) && $date_modif_student - $date_creation > 1000) {
                $s1 .= ' &nbsp; <span class="ital">' . $date_modif_student_info . '</span>' . "\n";
            } else {
                $s1 .= ' &nbsp; <span class="ital">' . $date_creation_info . '</span>' . "\n";
            }
            $s1 .= ' &nbsp; <span class="light">' . get_string('referent', 'referentiel') . '</span> ' . $teacher_info;
            if (!empty($date_modif_info)) {
                $s1 .= ' &nbsp; <span class="ital">' . $date_modif_info . '</span>' . "\n";
            }
            if (isset($approved) && $approved) {
                $s1 .= ' &nbsp; ' . get_string('approved', 'referentiel');
            } else {
                $s1 .= ' &nbsp; ' . get_string('not_approved', 'referentiel');
            }
            if (isset($approved) && $approved) {
                $s1 .= ' <span class="valide">' . "\n";
            } else {
                $s1 .= ' <span class="invalide">' . "\n";
            }
            $s1 .= '<br /><span class="bold">' . "\n";
            $s1 .= referentiel_affiche_liste_codes_competence('/', $competences_activite, $ref_referentiel) . "\n";
            $s1 .= '</span>' . "\n";
            /*
            if ($CFG->referentiel_use_scale){
            	require_once('lib_bareme.php');
            	if ($rec_assoc=referentiel_get_assoc_bareme_occurrence($ref_referentiel)){
            		if ($bareme=referentiel_get_bareme($rec_assoc->refscaleid)){
            			$competences_bareme=referentiel_get_competences_activite($activite_id, $bareme->id);
            			if (empty($competences_bareme)){ // creer le bareme
            				$competences_bareme=referentiel_creer_competences_activite($record_a, $bareme);
            			}
            			if ($competences_bareme){
            				$s1.='</span><br /><span class="light">'.get_string('evaluation','referentiel').'</span><br /><span class="white">'.referentiel_affiche_bareme_activite($competences_bareme, $bareme, false).'</span>'."\n";
            			}
            		}
            	}
            }
            */
            $s1 .= '</span>' . "\n";
            //$s1.=$stask;
            $s1 .= '<div class="ref_aff0">' . nl2br($description_activite) . '</div>' . "\n";
            if (!empty($commentaire_activite)) {
                $s1 .= '<div class="ref_aff1">' . nl2br($commentaire_activite) . '</div>' . "\n";
            }
            $s1 .= '</div>' . "\n";
        }
        // charger les documents associes à l'activite courante
        if (isset($activite_id) && $activite_id > 0) {
            $ref_activite = $activite_id;
            // plus pratique
            // AFFICHER LA LISTE DES DOCUMENTS
            $compteur_document = 0;
            $records_document = referentiel_get_documents($ref_activite);
            if ($records_document) {
                // afficher
                $nbressource = count($records_document);
                $s2 .= '<!-- DOCUMENTS -->
<div class="ref_affdoc">' . "\n";
                if ($detail) {
                    if ($nbressource > 1) {
                        $s2 .= '<span class="bold">' . get_string('ressources_associees', 'referentiel', $nbressource) . '</span>' . "\n";
                    } else {
                        $s2 .= '<span class="bold">' . get_string('ressource_associee', 'referentiel', $nbressource) . '</span>' . "\n";
                    }
                    $s2 .= "\n";
                }
                foreach ($records_document as $record_d) {
                    $compteur_document++;
                    $document_id = $record_d->id;
                    $type_document = stripslashes($record_d->type_document);
                    $description_document = stripslashes($record_d->description_document);
                    $url_document = $record_d->url_document;
                    $ref_activite = $record_d->ref_activite;
                    if (isset($record_d->cible_document) && $record_d->cible_document == 1) {
                        $cible_document = '_blank';
                        // fenêtre cible
                    } else {
                        $cible_document = '';
                    }
                    if (isset($record_d->etiquette_document)) {
                        $etiquette_document = $record_d->etiquette_document;
                        // fenêtre cible
                    } else {
                        $etiquette_document = '';
                    }
                    if ($record_d->timestamp == 0) {
                        $date_creation = '';
                    } else {
                        $date_creation = userdate($record_d->timestamp);
                    }
                    // affichage de l'url
                    if (preg_match('/moddata\\/referentiel/', $url_document)) {
                        // l'URL doit être transformée
                        $data_r = new stdClass();
                        $data_r->id = $document_id;
                        $data_r->userid = $userid;
                        $data_r->author = $user_info;
                        $data_r->url = $url_document;
                        $data_r->filearea = 'document';
                        $url_document = referentiel_m19_to_m2_file($data_r, $context, false, true);
                    }
                    if ($detail) {
                        if ($date_modif < $record_d->timestamp) {
                            $s .= '<span class="prioritaire">';
                            $s .= '<br /><span class="light">' . get_string('num', 'referentiel') . '</span> <span class="ital">' . $document_id . '</i></span></span>
&nbsp;
<span class="light">' . get_string('date_creation', 'referentiel') . '</span> : <span class="ital">' . $date_creation . '</span>
&nbsp;
<span class="light">' . get_string('type', 'referentiel') . '</span> : ' . $type_document . '
&nbsp;
<span class="light">' . get_string('url', 'referentiel') . '</span>  :
';
                            $s .= referentiel_affiche_url($url_document, $etiquette_document, $cible_document);
                            $s .= '&nbsp; <span class="light">' . get_string('description', 'referentiel') . '</span> : ' . nl2br($description_document);
                            $s .= '</span>' . "\n";
                        } else {
                            $s .= '<br /><span class="light">' . get_string('num', 'referentiel') . '</span> <span class="ital">' . $document_id . '</span>
&nbsp;
<span class="light">' . get_string('date_creation', 'referentiel') . '</span> : <span class="ital">' . $date_creation . '</span>
&nbsp;
<span class="light">' . get_string('type', 'referentiel') . '</span> : ' . $type_document . '
&nbsp;
<span class="light">' . get_string('url', 'referentiel') . '</span>  :
';
                            $s .= referentiel_affiche_url($url_document, $etiquette_document, $cible_document);
                            $s .= '&nbsp; <span class="light">' . get_string('description', 'referentiel') . '</span> : ' . nl2br($description_document) . "\n";
                        }
                    } else {
                        if ($date_modif < $record_d->timestamp) {
                            $s .= '<span class="prioritaire">';
                        }
                        $s .= ' &nbsp; ' . referentiel_affiche_url($url_document, $etiquette_document, $cible_document);
                        if ($date_modif < $record_d->timestamp) {
                            $s .= '</span>' . "\n";
                        }
                    }
                }
            }
        }
        echo $s0 . $s1;
        if ($s2) {
            echo $s2;
            if ($s) {
                echo $s . "\n";
            }
            echo '</div>' . "\n";
        }
    }
}