/**
  * Turns referentiel instance into an xml segment
  * @param referentiel instanceobject
  * @return string xml segment
  */
 function write_archive()
 {
     global $CFG;
     // initial string;
     $expout = "";
     // REFERENTIEL
     if (!empty($this->rreferentiel)) {
         $expout .= $this->write_referentiel();
         // recuperer les instances associées à ce référentiel  pour l'affichage ultérieur
         $records_instance = referentiel_referentiel_get_instances($this->rreferentiel->id);
         foreach ($records_instance as $record_i) {
             $this->t_instances[$record_i->id] = $record_i;
         }
         // recuperer les etablissement associées à ce référentiel  pour l'affichage ultérieur
         $records_etablissement = referentiel_get_etablissements();
         foreach ($records_etablissement as $record_e) {
             $this->t_etablissements[$record_e->id] = $record_e;
         }
         if (!empty($this->records_users)) {
             //echo "<br />DEBUG .format/html/archive_format.php :: LIGNE 910<br />\n";
             //print_r($this->records_users);
             //echo "<br />\n";
             //exit;
             //
             // $expout .= "<users>\n";
             $u = 0;
             foreach ($this->records_users as $userid) {
                 // $expout .= "<user>\n";
                 if (is_object($userid)) {
                     $userid = $userid->userid;
                 }
                 //echo "<br />\n";
                 //echo($userid);
                 // exit;
                 $this->tab_users[$u][0] = $userid;
                 // id certificat
                 $lastname = referentiel_get_user_nom($userid);
                 $firstname = referentiel_get_user_prenom($userid);
                 //                        $this->tab_users[$u][1]=mb_strtoupper($lastname,'UTF-8').' '.mb_convert_case($firstname, MB_CASE_TITLE, 'UTF-8');
                 $this->tab_users[$u][1] = $this->m_special_case($lastname, true) . ' ' . $this->m_special_case($firstname, false);
                 $u++;
                 $expout .= '<a name="' . $userid . '"></a>' . "\n";
                 $expout .= '<p>&nbsp;</p><h3 align="center">' . mb_strtoupper($lastname, 'UTF-8') . ' ' . mb_convert_case($firstname, MB_CASE_TITLE, 'UTF-8') . '</h3>' . "\n";
                 //
                 $record_certificat = referentiel_get_certificat_user($userid, $this->rreferentiel->id);
                 if (!empty($record_certificat)) {
                     $expout .= $this->write_certificat($record_certificat);
                 } else {
                     $expout .= '<p align="center">' . get_string('nocertificat', 'referentiel') . '</p>' . "\n";
                 }
                 foreach ($this->t_instances as $record_i) {
                     //$expout .= "<activites>\n";
                     $recs = referentiel_get_activites_users_from_instance($record_i->id, $userid, '', 'userid ASC, date_creation ASC ');
                     //echo "<br />DEBUG .format/html/archive_format.php :: LIGNE 936<br />\n";
                     //print_r($recs);
                     //echo "<br />\n";
                     //exit;
                     if (!empty($recs)) {
                         $expout .= $this->write_instance($record_i);
                         $expout .= $this->write_liste_activites($recs);
                     }
                     //$expout .= "</activites>\n";
                 }
                 //$expout .= "</user>\n";
             }
             //$expout .= "</users>\n\n";
         }
     }
     return $expout;
 }
 /**
  * Turns referentiel instance into an xml segment
  * @param referentiel instanceobject
  * @return string xml segment
  */
 function write_archive()
 {
     global $CFG;
     // initial string;
     $expout = "";
     // REFERENTIEL
     if (!empty($this->rreferentiel)) {
         $expout .= $this->write_referentiel();
         // recuperer les instances associées à ce référentiel  pour l'affichage ultérieur
         $records_instance = referentiel_referentiel_get_instances($this->rreferentiel->id);
         foreach ($records_instance as $record_i) {
             $this->t_instances[$record_i->id] = $record_i;
         }
         // recuperer les etablissement associées à ce référentiel  pour l'affichage ultérieur
         $records_etablissement = referentiel_get_etablissements();
         foreach ($records_etablissement as $record_e) {
             $this->t_etablissements[$record_e->id] = $record_e;
         }
         if (!empty($this->records_users)) {
             $expout .= "<users>\n";
             $u = 0;
             foreach ($this->records_users as $userid) {
                 // $expout .= "<user>\n";
                 if (is_object($userid)) {
                     $userid = $userid->userid;
                 }
                 //echo "<br />\n";
                 //echo($userid);
                 // exit;
                 // certificat
                 $record_certificat = referentiel_get_certificat_user($userid, $this->rreferentiel->id);
                 if (!empty($record_certificat)) {
                     $expout .= $this->write_certificat($record_certificat);
                 }
                 foreach ($this->t_instances as $record_i) {
                     $expout .= "<activites>\n";
                     $recs = referentiel_get_activites_users_from_instance($record_i->id, $userid, '', 'userid ASC, date_creation ASC ');
                     if (!empty($recs)) {
                         $expout .= $this->write_instance($record_i);
                         $expout .= $this->write_liste_activites($recs);
                     }
                     $expout .= "</activites>\n";
                 }
                 $expout .= "</user>\n";
             }
             $expout .= "</users>\n\n";
         }
     }
     return $expout;
 }