function referentiel_affiche_liste_codes_competence($separateur, $liste, $ref_referentiel)
{
    // supprime separateur
    global $t_item_code;
    global $t_item_description_competence;
    if (empty($t_item_code) || empty($t_item_description_competence)) {
        referentiel_initialise_descriptions_items_referentiel($ref_referentiel);
    }
    return referentiel_affiche_overlib_item($separateur, $liste);
}
function referentiel_evalue_global_liste_certificats($initiale, $userids, $mode, $referentiel_instance, $userid_filtre = 0, $gusers = NULL, $sql_f_where = '', $sql_f_order = '', $data_f, $select_acc = 0)
{
    // idem  que referentiel_print_evalue_liste_activite()
    // mais  specialise modification
    // form globale
    global $DB;
    global $CFG;
    global $USER;
    $protocole_link = '';
    //
    // contexte
    $cm = get_coursemodule_from_instance('referentiel', $referentiel_instance->id);
    $course = $DB->get_record('course', array('id' => $cm->course));
    if (empty($cm) or empty($course)) {
        print_print_error('REFERENTIEL_ERROR 5 :: print_lib_certificat.php :: You cannot call this script in that way');
    }
    $context = context_module::instance($cm->id);
    $roles = referentiel_roles_in_instance($referentiel_instance->id);
    $iseditor = $roles->is_editor;
    $isadmin = $roles->is_admin;
    $isteacher = $roles->is_teacher;
    $istutor = $roles->is_tutor;
    $isstudent = $roles->is_student;
    $isguest = $roles->is_guest;
    $records = array();
    if (isset($referentiel_instance->ref_referentiel) && $referentiel_instance->ref_referentiel > 0) {
        $referentiel_referentiel = referentiel_get_referentiel_referentiel($referentiel_instance->ref_referentiel);
        if (!$referentiel_referentiel) {
            if ($isadmin || $isteacher) {
                print_error(get_string('creer_referentiel', 'referentiel'), "edit.php?d={$referentiel_instance->id}&mode=editreferentiel&sesskey=" . sesskey());
            } else {
                print_error(get_string('creer_referentiel', 'referentiel'), "../../course/view.php?id={$course->id}&sesskey=" . sesskey());
            }
        }
        $isreferentielauteur = referentiel_is_author($USER->id, $referentiel_referentiel, !$isstudent);
        $seuil_certification = $referentiel_referentiel->seuil_certificat;
        $nb_items = referentiel_get_nb_items($referentiel_referentiel->id);
        if ($iseditor || $isadmin || $isreferentielauteur) {
            $protocole_link = "{$CFG->wwwroot}/mod/referentiel/edit_protocole.php?d={$referentiel_instance->id}&mode=protocole&sesskey=" . sesskey();
        } else {
            $protocole_link = "{$CFG->wwwroot}/mod/referentiel/protocole.php?d={$referentiel_instance->id}&mode=protocole&sesskey=" . sesskey();
        }
        // preparer les variables globales pour Overlib
        // referentiel_initialise_data_referentiel($referentiel_referentiel->id);
        // empreintes
        $liste_empreintes = referentiel_purge_dernier_separateur(referentiel_get_liste_empreintes_competence($referentiel_instance->id), '/');
        referentiel_initialise_descriptions_items_referentiel($referentiel_referentiel->id);
        // boite pour selectionner les utilisateurs ?
        if ($iseditor || $isteacher || $isadmin || $istutor) {
            if (!empty($select_acc)) {
                // eleves accompagnes
                $record_id_users = referentiel_get_accompagnements_teacher($referentiel_instance->id, $course->id, $USER->id);
            } else {
                // tous les users possibles (pour la boite de selection)
                // Get your userids the normal way
                $record_id_users = referentiel_get_students_course($course->id, 0, 0);
                //seulement les stagiaires
            }
            if ($gusers && $record_id_users) {
                // liste des utilisateurs du groupe courant
                // echo "<br />DEBUG :: print_lib_certificat.php :: 740 :: GUSERS<br />\n";
                // print_object($gusers);
                // echo "<br />\n";
                // exit;
                $record_users = array_intersect($gusers, array_keys($record_id_users));
                // echo "<br />DEBUG :: print_lib_certificat.php :: 745 :: RECORD_USERS<br />\n";
                // print_r($record_users  );
                // echo "<br />\n";
                // recopier
                $record_id_users = array();
                foreach ($record_users as $record_id) {
                    $a_obj = new stdClass();
                    $a_obj->userid = $record_id;
                    $record_id_users[] = $a_obj;
                }
            }
            // Ajouter l'utilisateur courant pour qu'il voit son certificat
            $a_obj = new stdClass();
            $a_obj->userid = $USER->id;
            $record_id_users[] = $a_obj;
            echo referentiel_select_users_accompagnes($CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance->id . '&amp;mode=' . $mode . '&amp;sesskey=' . sesskey(), $mode, $userid_filtre, $select_acc);
            // DEBUG
            // echo "<br />DEBUB :: print_lib_certificat.php :: 319<br />INITIALES: $initiale USERIDS: $userids\n";
            echo referentiel_select_users_certificat($record_id_users, $CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance->id . '&amp;mode=' . $mode . '&amp;sesskey=' . sesskey(), $initiale, $mode, $userid_filtre, $select_acc);
        } else {
            $userid_filtre = $USER->id;
            // les étudiants ne peuvent voir que leur fiche
        }
        // recuperer les utilisateurs filtres
        if (!empty($select_acc) && $userid_filtre == 0) {
            // eleves accompagnes
            $record_id_users = referentiel_get_accompagnements_teacher($referentiel_instance->id, $course->id, $USER->id);
        } else {
            // retourne les etudiants du cours ou userid_filtre si != 0
            $record_id_users = referentiel_get_students_course($course->id, $userid_filtre, 0);
        }
        // afficher le groupe courant
        if ($record_id_users && $gusers) {
            // liste des utilisateurs du groupe courant
            $record_users = array_intersect($gusers, array_keys($record_id_users));
            // recopier
            $record_id_users = array();
            foreach ($record_users as $record_id) {
                $a_obj = new stdClass();
                $a_obj->userid = $record_id;
                $record_id_users[] = $a_obj;
            }
        }
        // ALPHABETIQUE
        if (!empty($userids)) {
            $t_users_select = explode('_', $userids);
            $record_id_users = array();
            foreach ($t_users_select as $userid) {
                $a_obj = new stdClass();
                $a_obj->userid = $userid;
                $record_id_users[] = $a_obj;
            }
            // DEBUG
            /*
            echo "<br />DEBUG :: print_lib_certificat.php :: 2386<br />USERIDS : $userids<br />\n";
            print_r($t_users_select);
            echo "<br />\n";
            print_r($record_id_users);
            exit;
            */
        } elseif (($userid_filtre == $USER->id || $userid_filtre == 0) && ($isteacher || $isadmin || $istutor)) {
            // Ajouter l'utilisateur courant pour qu'il puisse voir ses propres activites
            $a_obj = new stdClass();
            $a_obj->userid = $USER->id;
            $record_id_users[] = $a_obj;
        }
        // echo "<br />DEBUG :: print_lib_certificat.php :: 1870 :: RECORD_USERS<br />\n";
        // print_r($record_users  );
        // echo "<br />\n";
        // afficher les activites
        if ($record_id_users) {
            // Afficher
            // ordre d'affichage utilisateurs
            if (isset($data_f) && isset($data_f->f_auteur) && $data_f->f_auteur == '-1') {
                $deb = -count($record_id_users) + 1;
                $fin = 1;
            } else {
                $deb = 0;
                $fin = count($record_id_users);
            }
            // Parcours des utilisateurs
            for ($j = $deb; $j < $fin; $j++) {
                $i = abs($j);
                // recupere les enregistrements
                // MODIF JF 23/10/2009
                if (isset($userid_filtre) && $userid_filtre == $USER->id) {
                    $actif = true;
                } else {
                    $actif = false;
                    // 	$records=referentiel_get_all_activites_user_course($referentiel_instance->ref_referentiel, $record_id->userid, $course->id);
                }
                // recuperation des certificats
                // ATTENTION
                // il faut introduire les filtres SQL
                //	$records=referentiel_get_all_activites_user($referentiel_instance->ref_referentiel, $record_id_users[$i]->userid, $sql_f_where, $sql_f_order);
                $records[] = referentiel_certificat_user_select($record_id_users[$i]->userid, $referentiel_instance->ref_referentiel, $sql_f_where, $sql_f_order);
            }
            if ($records) {
                echo '<table class="activite" width="100%"><tr valign="top">' . "\n";
                echo '<td colspan="6">' . "\n";
                echo referentiel_entete_filtre($CFG->wwwroot . '/mod/referentiel/certificat.php?d=' . $referentiel_instance->id . '&amp;mode=' . $mode . '&amp;sesskey=' . sesskey(), $data_f, false);
                echo '</td></tr>' . "\n";
                // formulaire global
                echo "\n\n" . '<form name="form" id="form" action="certificat.php?id=' . $cm->id . '&amp;courseid=' . $course->id . '&amp;f_auteur=' . $data_f->f_auteur . '&amp;f_verrou=' . $data_f->f_verrou . '&amp;f_valide=' . $data_f->f_valide . '&amp;f_referent=0' . $data_f->f_referent . '&amp;f_date_decision=' . $data_f->f_date_decision . '&amp;select_acc=' . $select_acc . '&amp;sesskey=' . sesskey() . '" method="post">' . "\n";
                echo '<tr valign="top">
<td class="ardoise" colspan="6">
 <img class="selectallarrow" src="./pix/arrow_ltr_bas.png"
     width="38" height="22" alt="' . get_string('mark_to_select', 'referentiel') . '" title="' . get_string('mark_to_select', 'referentiel') . '" />
 <i>' . get_string('cocher_enregistrer', 'referentiel') . '</i>
<input type="submit" value="' . get_string("savechanges") . '" />
<input type="reset" value="' . get_string("corriger", "referentiel") . '" />
<input type="submit" name="cancel" value="' . get_string("quit", "referentiel") . '" />
</td></tr>' . "\n";
                foreach ($records as $record) {
                    // afficher le certificat
                    // Afficher
                    if (isset($mode) && $mode == 'editcertif') {
                        echo referentiel_modifie_global_certificat($data_f, $mode, $cm, $course, $referentiel_instance, $record, $context, $actif, $liste_empreintes, $select_acc, $seuil_certification, $protocole_link, $nb_items);
                    }
                }
                echo '<tr valign="top">
<td class="ardoise" colspan="6">
 <img class="selectallarrow" src="./pix/arrow_ltr.png"
    width="38" height="22" alt="' . get_string('mark_to_select', 'referentiel') . '" title="' . get_string('mark_to_select', 'referentiel') . '" />
<i>' . get_string('cocher_enregistrer', 'referentiel') . '</i>
<input type="hidden" name="action" value="modifier_certificat_global" />
<!-- accompagnement -->
<input type="hidden" name="select_acc" value="' . $select_acc . '" />
<!-- These hidden variables are always the same -->
<input type="hidden" name="sesskey"     value="' . sesskey() . '" />
<input type="hidden" name="modulename"    value="referentiel" />
<input type="hidden" name="mode"          value="' . $mode . '" />
<input type="submit" value="' . get_string("savechanges") . '" />
<input type="reset" value="' . get_string("corriger", "referentiel") . '" />
<input type="submit" name="cancel" value="' . get_string("quit", "referentiel") . '" />
</td></tr>
</form>' . "\n";
                // liste des utilisateur achevee
                if (isset($mode) && $mode == 'editcertif') {
                    // echo referentiel_modifie_activite_2_complete($record, $context, $actif);
                    echo referentiel_enqueue_certificat();
                } else {
                    echo referentiel_print_enqueue_certificat();
                }
                echo '<br /><br />' . "\n";
            }
        }
    }
    return true;
}
 // echo "<br />DEBUG :: list_activites_users.php :: 140 : RECORD<br />\n";
 // print_object( $recs);
 // exit;
 // MODIF JF 2014/11/15
 // Le tri est fait dans la requête SQL
 /**************************************
 		if (!empty($order)) {
         	$recs=referentiel_order_users($recs, $order);
  			//echo "<br />DEBUG :: list_activites_users.php :: 122 : RECORD TRIES<br />\n";
 			//print_object( $recs);
 			//exit;
 		}
 		***/
 // affichage
 // preparer les variables globales pour Overlib
 referentiel_initialise_descriptions_items_referentiel($referentiel_referentiel->id);
 //Bareme
 $bareme = NULL;
 if ($CFG->referentiel_use_scale) {
     require_once 'lib_bareme.php';
     //echo "<br />OCCURRENCE<br />\n";
     //print_object($referentiel_referentiel);
     //echo "<br />\n";
     if ($rec_assoc = referentiel_get_assoc_bareme_occurrence($referentiel_referentiel->id)) {
         // DEBUG
         //echo "<br />A BAREME OCCURRENCE<br />\n";
         //print_object($rec_assoc);
         //echo "<br />\n";
         $bareme = referentiel_get_bareme($rec_assoc->refscaleid);
     }
 }