Beispiel #1
0
function referentiel_set_occurrence($formdata)
{
    // Traite le formulaire de saisie d'une occurrence
    // mise a jour des tables referentiel_referentiel
    // mise a jour des tables referentiel_domaine,
    // referentiel_competence, referentiel_item et table referentiel_protocol
    global $CFG, $USER, $DB;
    $occurrenceid = 0;
    // DEBUG
    // echo "<br />DEBUG :: ./block/referentiel/lib.php :: 11 <br />\n";
    // print_object($mform);
    if (!empty($formdata)) {
        // DEBUG
        //echo "<br />DEBUG :: lib.php :: 416 <br />\n";
        //print_object($formdata);
        //echo "<br />EXIT<br />\n";
        //exit;
        $occurrence = new Object();
        $occurrence->name = $formdata->name;
        $occurrence->code_referentiel = $formdata->code_referentiel;
        $occurrence->description_referentiel = $formdata->description_referentiel;
        $occurrence->url_referentiel = $formdata->url_referentiel;
        $occurrence->logo_referentiel = $formdata->logo_referentiel;
        $occurrence->local = $formdata->local;
        $occurrence->nb_domaines = $formdata->nb_domaines;
        $occurrence->liste_codes_competence = $formdata->liste_codes_competence;
        $occurrence->liste_poids_competence = $formdata->liste_poids_competence;
        $occurrence->liste_empreintes_competence = $formdata->liste_empreintes_competence;
        if (!empty($formdata->label_domaine)) {
            $occurrence->label_domaine = $formdata->label_domaine;
        } else {
            $occurrence->label_domaine = get_string('label_domaine', 'referentiel');
        }
        if (!empty($formdata->label_competence)) {
            $occurrence->label_competence = $formdata->label_competence;
        } else {
            $occurrence->label_competence = get_string('label_competence', 'referentiel');
        }
        if (!empty($formdata->label_item)) {
            $occurrence->label_item = $formdata->label_item;
        } else {
            $occurrence->label_competence = get_string('label_item', 'referentiel');
        }
        $occurrence->config = $formdata->config;
        $occurrence->config_impression = $formdata->config_impression;
        $occurrence->cle_referentiel = $formdata->cle_referentiel;
        $occurrence->mail_auteur_referentiel = $formdata->mail_auteur_referentiel;
        $occurrence->pass_referentiel = $formdata->pass_referentiel;
        $occurrence->timemodified = time();
        if (isset($formdata->occurrenceid) && $formdata->occurrenceid == 0) {
            $occurrenceid = $DB->insert_record("referentiel_referentiel", $occurrence);
            if ($occurrenceid) {
                $occurrence->cle_referentiel = referentiel_recalcule_cle_referentiel($occurrenceid);
            }
        } else {
            // Update
            $occurrenceid = $formdata->occurrenceid;
            $occurrence->id = $formdata->occurrenceid;
            $DB->update_record("referentiel_referentiel", $occurrence);
        }
        // New Domains, Competencies , Items
        if (!empty($formdata->list_newdomains)) {
            //echo "<br />LIST_NEWDOMAINS :$formdata->list_newdomains\n";
            if ($t_domainids = explode(',', $formdata->list_newdomains)) {
                foreach ($t_domainids as $D_id) {
                    if (!empty($D_id)) {
                        // && is_int($D_id)){
                        $error = false;
                        $rec = new Object();
                        $rec->occurrence = $occurrence->id;
                        // mandatory
                        $s = 'new_code_domaine_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_code_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_description_domaine_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_description_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_type_domaine_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_type_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_minima_domaine_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_minima_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_seuil_domaine_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_seuil_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_num_domaine_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_num_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_nb_competences_' . $D_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_nb_competences = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        if (!$error) {
                            // exit;
                            // Update + protocole update
                            if (!referentiel_add_domaine($rec)) {
                                // DEBUG
                                echo "ERROR ADD DOMAIN :: 518 lib.php :: :: DOMAIN<br />\n";
                                print_object($rec);
                                echo "<br>ERROR\n";
                                exit;
                            }
                        }
                    }
                }
            }
        }
        if (!empty($formdata->list_newcompetencies)) {
            if ($t_competencyids = explode(',', $formdata->list_newcompetencies)) {
                foreach ($t_competencyids as $C_id) {
                    // echo "<br />COMPETENCY ID:$C_id\n";
                    if (!empty($C_id)) {
                        // && is_int($C_id)){
                        $error = false;
                        $rec = new Object();
                        $rec->reference_id = $occurrence->id;
                        // mandatory for protocole management
                        $s = 'new_ref_domaine_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_ref_domaine = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_code_competence_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_code_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_description_competence_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_description_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_type_competence_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_type_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_minima_competence_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_minima_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_seuil_competence_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_seuil_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_num_competence_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_num_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_nb_item_competences_' . $C_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_nb_item_competences = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        if (!$error) {
                            // Update + protocole update
                            if (!referentiel_add_competence($rec)) {
                                echo "<br>ERROR ADD COMPETENCY :: lib.php :: 595 :: COMPETENCY\n";
                                print_object($rec);
                                echo "<br />\n";
                                exit;
                            }
                        }
                    }
                }
            }
        }
        if (!empty($formdata->list_newitems)) {
            if ($t_itemids = explode(',', $formdata->list_newitems)) {
                foreach ($t_itemids as $I_id) {
                    //echo "<br />ITEM ID:$I_id\n";
                    if (!empty($I_id)) {
                        // && is_int($I_id)){
                        $error = false;
                        $rec = new Object();
                        $rec->occurrence = $occurrence->id;
                        // mandatory for protocole management
                        $s = 'new_ref_competence_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_ref_competence = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_code_item_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_code_item = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_description_item_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_description_item = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_type_item_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_type_item = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_poids_item_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_poids_item = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_empreinte_item_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_empreinte_item = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        $s = 'new_num_item_' . $I_id;
                        if (isset($formdata->{$s})) {
                            $rec->new_num_item = $formdata->{$s};
                        } else {
                            $error = true;
                        }
                        if (!$error) {
                            // Update + protocole update
                            if (!referentiel_add_item($rec)) {
                                echo "<br>ERROR ADD ITEM :: lib.php :: 265 :: ITEM\n";
                                print_object($rec);
                                echo "<br />\n";
                                exit;
                            }
                        }
                    }
                }
            }
        }
        // Domains, Competencies , Items
        if (!empty($formdata->list_domains)) {
            if ($t_domainids = explode(',', $formdata->list_domains)) {
                foreach ($t_domainids as $D_id) {
                    if (!empty($D_id)) {
                        // && is_int($D_id)){
                        //echo "<br />DOMAIN ID:$D_id\n";
                        $s = 'tdomain_id_' . $D_id;
                        if (!empty($formdata->{$s})) {
                            // Traiter cet objet
                            $error = false;
                            $rec = new Object();
                            $rec->domaine_id = $D_id;
                            $s = 'ref_referentiel_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->ref_referentiel = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'code_domaine_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->code_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'description_domaine_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->description_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'type_domaine_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->type_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'minima_domaine_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->minima_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'seuil_domaine_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->seuil_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'num_domaine_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->num_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'nb_competences_' . $D_id;
                            if (isset($formdata->{$s})) {
                                $rec->nb_competences = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            if (!$error) {
                                // DEBUG
                                // echo "DEBUG :: 107 lib.php :: :: DOMAIN<br />\n";
                                // print_object($rec);
                                // echo "<br />\n";
                                // exit;
                                // Update + protocole update
                                referentiel_update_domaine($rec);
                            }
                        }
                    }
                }
            }
        }
        if (!empty($formdata->list_competencies)) {
            if ($t_competencyids = explode(',', $formdata->list_competencies)) {
                foreach ($t_competencyids as $C_id) {
                    //echo "<br />COMPETENCY ID:$C_id\n";
                    if (!empty($C_id)) {
                        // && is_int($C_id)){
                        $s = 'tcomp_id_' . $C_id;
                        if (!empty($formdata->{$s})) {
                            // Traiter cet objet
                            $error = false;
                            $rec = new Object();
                            $rec->competence_id = $C_id;
                            $rec->reference_id = $occurrence->id;
                            // mandatory for protocole management
                            $s = 'ref_domaine_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->ref_domaine = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'code_competence_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->code_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'description_competence_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->description_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'type_competence_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->type_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'minima_competence_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->minima_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'seuil_competence_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->seuil_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'num_competence_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->num_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'nb_item_competences_' . $C_id;
                            if (isset($formdata->{$s})) {
                                $rec->nb_item_competences = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            if (!$error) {
                                // Update + protocole update
                                if (!referentiel_update_competence($rec)) {
                                    // DEBUG
                                    echo "ERROR :: 833 lib.php :: :: COMPETENCY<br />\n";
                                    print_object($rec);
                                    echo "<br />\n";
                                    exit;
                                }
                            }
                        }
                    }
                }
            }
        }
        if (!empty($formdata->list_items)) {
            if ($t_itemids = explode(',', $formdata->list_items)) {
                foreach ($t_itemids as $I_id) {
                    //echo "<br />ITEM ID:$I_id\n";
                    if (!empty($I_id)) {
                        // && is_int($I_id)){
                        $s = 'titem_id_' . $I_id;
                        if (!empty($formdata->{$s})) {
                            // Traiter cet objet
                            $error = false;
                            $rec = new Object();
                            $rec->item_id = $I_id;
                            $s = 'ref_competence_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->ref_competence = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'code_item_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->code_item = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'description_item_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->description_item = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'type_item_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->type_item = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'poids_item_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->poids_item = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'empreinte_item_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->empreinte_item = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            $s = 'num_item_' . $I_id;
                            if (isset($formdata->{$s})) {
                                $rec->num_item = $formdata->{$s};
                            } else {
                                $error = true;
                            }
                            if (!$error) {
                                // DEBUG
                                // echo "DEBUG :: 195 lib.php :: :: ITEM<br />\n";
                                // print_object($rec);
                                // echo "<br />\n";
                                // exit;
                                // Update + protocole update
                                referentiel_update_item($rec);
                            }
                        }
                    }
                }
            }
        }
    }
    return $occurrenceid;
}
Beispiel #2
0
     // enregistre les modifications
     if (isset($form->competence_id) && $form->competence_id > 0) {
         $return = referentiel_update_competence($form);
         $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id . " " . get_string("competence", "referentiel") . " " . $form->competence_id;
         $action = "update";
     }
 } else {
     if ($form->action == "modifieritem") {
         // enregistre le nouveau domaine
         $return = referentiel_update_item($form);
         $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id . " " . get_string("item", "referentiel") . " " . $form->item_id;
         $action = "update";
     } else {
         if ($form->action == "newdomaine") {
             // enregistre le nouveau domaine
             $return = referentiel_add_domaine($form);
             $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id . " " . get_string("domaine", "referentiel") . " " . $return;
             $action = "add";
         } else {
             if ($form->action == "newcompetence") {
                 // enregistre le nouvel item
                 $return = referentiel_add_competence($form);
                 $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id . " " . get_string("competence", "referentiel") . " " . $return;
                 $action = "add";
             } else {
                 if ($form->action == "newitem") {
                     // enregistre les modifications
                     $return = referentiel_add_item($form);
                     $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id . " " . get_string("item", "referentiel") . " " . $return;
                     $action = "add";
                 }
Beispiel #3
0
 /**
  * @param array referentiel array from xml tree
  * @return object import_referentiel object
  * modifie la base de donnees
  */
 function import_referentiel($xmlreferentiel)
 {
     // recupere le fichier xml
     // selon les parametres soit cree une nouvelle occurence
     // soit modifie une occurrence courante de referentiel
     global $SESSION;
     global $USER;
     global $CFG;
     $nbdomaines = 0;
     // compteur
     $nbcompetences = 0;
     // compteur
     $nbitems = 0;
     // compteur
     // print_r($xmlreferentiel);
     if (!isset($this->action) || isset($this->action) && $this->action != "selectreferentiel" && $this->action != "importreferentiel") {
         if (!(isset($this->course->id) && $this->course->id > 0) || !(isset($this->rreferentiel->id) && $this->rreferentiel->id > 0) || !(isset($this->coursemodule->id) && $this->coursemodule->id > 0)) {
             $this->error(get_string('incompletedata', 'referentiel'));
             return false;
         }
     } else {
         if (isset($this->action) && $this->action == "selectreferentiel") {
             if (!(isset($this->course->id) && $this->course->id > 0)) {
                 $this->error(get_string('incompletedata', 'referentiel'));
                 return false;
             }
         } else {
             if (isset($this->action) && $this->action == "importreferentiel") {
                 if (!(isset($this->course->id) && $this->course->id > 0)) {
                     $this->error(get_string('incompletedata', 'referentiel'));
                     return false;
                 }
             }
         }
     }
     $risque_ecrasement = false;
     // get some error strings
     $error_noname = get_string('xmlimportnoname', 'referentiel');
     $error_nocode = get_string('xmlimportnocode', 'referentiel');
     $error_override = get_string('overriderisk', 'referentiel');
     // this routine initialises the import object
     $re = $this->defaultreferentiel();
     //
     // $re->id = $this->getpath( $xmlreferentiel, array('#','id',0,'#'), '', false, '');
     $re->name = $this->getpath($xmlreferentiel, array('#', 'name', '0', '#'), '', true, $error_noname);
     $re->code_referentiel = $this->getpath($xmlreferentiel, array('#', 'code_referentiel', 0, '#'), '', true, $error_nocode);
     $re->description_referentiel = $this->getpath($xmlreferentiel, array('#', 'description_referentiel', 0, '#', 'text', 0, '#'), '', true, '');
     $re->url_referentiel = $this->getpath($xmlreferentiel, array('#', 'url_referentiel', 0, '#'), '', true, '');
     $re->seuil_certificat = $this->getpath($xmlreferentiel, array('#', 'seuil_certificat', 0, '#'), '', false, '');
     $re->minima_certificat = $this->getpath($xmlreferentiel, array('#', 'minima_certificat', 0, '#'), '', false, '');
     $re->timemodified = $this->getpath($xmlreferentiel, array('#', 'timemodified', 0, '#'), '', false, '');
     $re->nb_domaines = $this->getpath($xmlreferentiel, array('#', 'nb_domaines', 0, '#'), '', false, '');
     $re->liste_codes_competence = $this->getpath($xmlreferentiel, array('#', 'liste_codes_competence', 0, '#'), '', true, '');
     $re->liste_empreintes_competence = $this->getpath($xmlreferentiel, array('#', 'liste_empreintes_competence', 0, '#'), '', true, '');
     $re->logo_referentiel = $this->getpath($xmlreferentiel, array('#', 'logo_referentiel', 0, '#'), '', true, '');
     // $re->local = $this->getpath( $xmlreferentiel, array('#','course',0,'#'), '', false, '');
     /*
     // traitement d'une image associee
     // non implante
             $image = $this->getpath( $xmlreferentiel, array('#','image',0,'#'), $re->image );
             $image_base64 = $this->getpath( $xmlreferentiel, array('#','image_base64','0','#'),'' );
             if (!empty($image_base64)) {
                 $re->image = $this->importimagefile( $image, stripslashes($image_base64) );
             }
     */
     $re->export_process = false;
     $re->import_process = true;
     // le referentiel est toujours place dans le cours local d'appel
     $re->course = $this->course->id;
     $risque_ecrasement = false;
     if (!isset($this->action) || $this->action != "importreferentiel") {
         // importer dans le cours courant en remplacement du referentiel courant
         // Verifier si ecrasement referentiel local
         if (isset($re->name) && $re->name != "" && isset($re->code_referentiel) && $re->code_referentiel != "" && isset($re->id) && $re->id > 0 && isset($re->course) && $re->course > 0) {
             // sauvegarder ?
             if ($this->course->id == $re->course) {
                 if (isset($this->rreferentiel->id) && $this->rreferentiel->id == $re->id || isset($this->rreferentiel->name) && $this->rreferentiel->name == $re->name && (isset($this->rreferentiel->code_referentiel) && $this->rreferentiel->code_referentiel == $re->code_referentiel)) {
                     $risque_ecrasement = true;
                 }
             }
         }
     }
     if ($risque_ecrasement == false || $this->newinstance == 1) {
         // Enregistrer dans la base comme un nouveau referentiel_referentiel du cours courant
         $new_referentiel_id = referentiel_add_referentiel($re);
         $this->setReferentielId($new_referentiel_id);
         // DEBUG
         // echo "<br />DEBUG xml/format.php ligne 572<br />NEW REFERENTIEL ID ENREGISTRE : ".$this->new_referentiel_id."\n";
     } else {
         if ($risque_ecrasement == true && $this->override == 1) {
             // Enregistrer dans la base en remplaçant la version courante (update)
             // NE FAUDRAIT IL PAS SUPPRIMER LE REFERENTIEL AVANT DE LA RECHARGER ?
             $re->instance = $this->rreferentiel->id;
             // en realite instance est ici occurrence
             $re->referentiel_id = $this->rreferentiel->id;
             $ok = referentiel_update_referentiel($re);
             $new_referentiel_id = $this->rreferentiel->id;
         } else {
             // ni nouvelle instance ni recouvrement
             $this->error($error_override);
             return false;
         }
     }
     // MODIF JF 2012/03/09
     // importer le protocole
     $pindex = 0;
     $nbprotocoles = 0;
     // compteur
     $re->protocole = array();
     if (!empty($xmlreferentiel['#']['protocole'])) {
         $xmlprotocole = $xmlreferentiel['#']['protocole'];
         foreach ($xmlprotocole as $protocole) {
             // PROTOCOLE
             // print_r($protocole);
             $pindex++;
             $new_protocole = array();
             $new_protocole = $this->defaultprotocole();
             // $new_protocole->id=$this->getpath( $protocole, array('#','p_id',0,'#'), '', false, '');
             // $new_protocole->ref_occurrence=$this->getpath( $protocole, array('#','p_ref_occurrence',0,'#'), '', false, '');
             $new_protocole->seuil_referentiel = $this->getpath($protocole, array('#', 'p_seuil_referentiel', 0, '#'), '', false, '');
             $new_protocole->minima_referentiel = $this->getpath($protocole, array('#', 'p_minima_referentiel', 0, '#'), '', false, '');
             // La suite initialise en chargeant les domaines / compétences / items
             // $new_protocole->l_domaines_oblig=$this->getpath( $protocole, array('#','p_domaines_oblig',0,'#','text',0,'#'), '', true, '');
             // $new_protocole->l_seuils_domaines=$this->getpath( $protocole, array('#','p_seuils_domaines',0,'#','text',0,'#'), '', true, '');
             // $new_protocole->l_competences_oblig=$this->getpath( $protocole, array('#','p_competences_oblig',0,'#','text',0,'#'), '', true, '');
             // $new_protocole->l_seuils_competences=$this->getpath( $protocole, array('#','p_seuils_competences',0,'#','text',0,'#'), '', true, '');
             // $new_protocole->l_minimas_competences=$this->getpath( $protocole, array('#','p_minimas_competences',0,'#','text',0,'#'), '', true, '');
             // $new_protocole->l_items_oblig=$this->getpath( $protocole, array('#','p_items_oblig',0,'#','text',0,'#'), '', true, '');
             $new_protocole->timemodified = $this->getpath($protocole, array('#', 'p_timemodified', 0, '#'), '', false, '');
             $new_protocole->actif = $this->getpath($protocole, array('#', 'p_actif', 0, '#'), '', false, '');
             $new_protocole->commentaire = $this->getpath($protocole, array('#', 'p_commentaire', 0, '#', 'text', 0, '#'), '', true, '');
             // enregistrer
             $re->protocoles[$pindex] = $new_protocole;
             // sauvegarder dans la base
             // remplacer l'id du referentiel importe par l'id du referentiel cree
             // trafiquer les donnees pour appeler la fonction ad hoc
             $new_protocole->ref_occurrence = $new_referentiel_id;
             // DEBUG
             // echo "<br />DEBUG ./format/xml/format.php :: 710<br />\n";
             // print_object($new_protocole);
             if (referentiel_add_protocol($new_protocole)) {
                 $nbprotocoles++;
             }
         }
     } else {
         $new_protocole = $this->defaultprotocole();
         $new_protocole->ref_occurrence = $new_referentiel_id;
         $re->protocoles[1] = $new_protocole;
         if (referentiel_add_protocol($new_protocole)) {
             $nbprotocoles++;
         }
     }
     // importer les domaines
     $xmldomaines = $xmlreferentiel['#']['domaine'];
     $dindex = 0;
     $re->domaines = array();
     $nbdomaines = 0;
     // compteur
     foreach ($xmldomaines as $domaine) {
         // DOMAINES
         // print_r($domaine);
         $dindex++;
         $new_domaine = $this->defaultdomaine();
         // $new_domaine->id=$this->getpath( $domaine, array('#','id',0,'#'), '', false, '');
         $new_domaine->code_domaine = $this->getpath($domaine, array('#', 'code_domaine', 0, '#'), '', true, $error_nocode);
         $new_domaine->description_domaine = $this->getpath($domaine, array('#', 'description_domaine', 0, '#', 'text', 0, '#'), '', true, '');
         // MODIF JF 2012/05/22
         // retablir des sauts de ligne
         $new_domaine->description_domaine = preg_replace("/\\|\\|\\|/", "\r\n", $new_domaine->description_domaine);
         $new_domaine->num_domaine = $this->getpath($domaine, array('#', 'num_domaine', 0, '#'), '', false, '');
         $new_domaine->nb_competences = $this->getpath($domaine, array('#', 'nb_competences', 0, '#'), '', false, '');
         // $new_domaine->ref_referentiel=$this->getpath( $domaine, array('#','ref_referentiel',0,'#'), '', false, '');
         // MODIF 2012/03/08
         $new_domaine->type_domaine = $this->getpath($domaine, array('#', 'type_domaine', 0, '#'), '', false, '');
         if (empty($new_domaine->type_domaine)) {
             $new_domaine->type_domaine = 0;
         }
         $new_domaine->seuil_domaine = $this->getpath($domaine, array('#', 'seuil_domaine', 0, '#'), '', false, '');
         if (empty($new_domaine->seuil_domaine)) {
             $new_domaine->seuil_domaine = '0.0';
         }
         // MODIF 2012/03/26
         $new_domaine->minima_domaine = $this->getpath($domaine, array('#', 'minima_domaine', 0, '#'), '', false, '');
         if (empty($new_domaine->minima_domaine)) {
             $new_domaine->minima_domaine = '0';
         }
         // enregistrer
         $re->domaines[$dindex] = $new_domaine;
         // sauvegarder dans la base
         // remplacer l'id du referentiel importe par l'id du referentiel cree
         // trafiquer les donnees pour appeler la fonction ad hoc
         $new_domaine->ref_referentiel = $new_referentiel_id;
         $new_domaine->instance = $new_referentiel_id;
         // pour que ca marche
         $new_domaine->new_code_domaine = $new_domaine->code_domaine;
         $new_domaine->new_description_domaine = $new_domaine->description_domaine;
         $new_domaine->new_num_domaine = $new_domaine->num_domaine;
         $new_domaine->new_nb_competences = $new_domaine->num_domaine;
         // MODIF 2012/03/08
         $new_domaine->new_type_domaine = $new_domaine->type_domaine;
         $new_domaine->new_seuil_domaine = $new_domaine->seuil_domaine;
         // MODIF 2012/03/26
         $new_domaine->new_minima_domaine = $new_domaine->minima_domaine;
         $new_domaine_id = referentiel_add_domaine($new_domaine);
         if ($new_domaine_id) {
             $nbdomaines++;
         }
         // importer les competences
         $xmlcompetences = $domaine['#']['competence'];
         $cindex = 0;
         $re->domaines[$dindex]->competences = array();
         $nbcompetences = 0;
         // compteur
         foreach ($xmlcompetences as $competence) {
             $cindex++;
             $new_competence = array();
             $new_competence = $this->defaultcompetence();
             // $new_competence->id = $this->getpath( $competence, array('#','id',0,'#'), '', false, '');
             $new_competence->code_competence = $this->getpath($competence, array('#', 'code_competence', 0, '#'), '', true, $error_nocode);
             $new_competence->description_competence = $this->getpath($competence, array('#', 'description_competence', 0, '#', 'text', 0, '#'), '', true, '');
             // MODIF JF 2012/05/22
             // retablir des sauts de ligne
             $new_competence->description_competence = preg_replace("/\\|\\|\\|/", "\r\n", $new_competence->description_competence);
             $new_competence->num_competence = $this->getpath($competence, array('#', 'num_competence', 0, '#'), '', false, '');
             $new_competence->nb_item_competences = $this->getpath($competence, array('#', 'nb_item_competences', 0, '#'), '', false, '');
             // $new_competence->ref_domaine=$this->getpath( $competence, array('#','ref_domaine',0,'#'), '', false, '');
             // MODIF 2012/03/08
             $new_competence->type_competence = $this->getpath($competence, array('#', 'type_competence', 0, '#'), '', false, '');
             $new_competence->seuil_competence = $this->getpath($competence, array('#', 'seuil_competence', 0, '#'), '', false, '');
             if (empty($new_competence->type_competence)) {
                 $new_competence->type_competence = 0;
             }
             if (empty($new_competence->seuil_competence)) {
                 $new_competence->seuil_competence = '0.0';
             }
             // MODIF 2012/03/26
             $new_competence->minima_competence = $this->getpath($competence, array('#', 'minima_competence', 0, '#'), '', false, '');
             if (empty($new_competence->minima_competence)) {
                 $new_competence->minima_competence = 0;
             }
             // enregistrer
             $re->domaines[$dindex]->competences[$cindex] = $new_competence;
             // sauvegarder dans la base
             // remplacer l'id du referentiel importe par l'id du referentiel cree
             $new_competence->ref_domaine = $new_domaine_id;
             // trafiquer les donnees pour appeler la fonction ad hoc
             $new_competence->instance = $new_referentiel_id;
             // pour que ca marche
             $new_competence->new_code_competence = $new_competence->code_competence;
             $new_competence->new_description_competence = $new_competence->description_competence;
             $new_competence->new_ref_domaine = $new_competence->ref_domaine;
             $new_competence->new_num_competence = $new_competence->num_competence;
             $new_competence->new_nb_item_competences = $new_competence->nb_item_competences;
             // MODIF 2012/03/08
             $new_competence->new_type_competence = $new_competence->type_competence;
             $new_competence->new_seuil_competence = $new_competence->seuil_competence;
             // MODIF 2012/03/26
             $new_competence->new_minima_competence = $new_competence->minima_competence;
             // creation
             $new_competence_id = referentiel_add_competence($new_competence);
             if ($new_competence_id) {
                 $nbcompetences++;
                 // compteur
             }
             // importer les items
             $xmlitems = $competence['#']['item'];
             $iindex = 0;
             $re->domaines[$dindex]->competences[$cindex]->items = array();
             $nbitems = 0;
             // compteur
             foreach ($xmlitems as $item) {
                 $iindex++;
                 $new_item = array();
                 $new_item = $this->defaultitem();
                 // $new_item->id = $this->getpath( $item, array('#','id',0,'#'), '', false, '');
                 $new_item->code_item = $this->getpath($item, array('#', 'code', 0, '#'), '', true, $error_nocode);
                 $new_item->description_item = $this->getpath($item, array('#', 'description_item', 0, '#', 'text', 0, '#'), '', true, '');
                 // MODIF JF 2012/05/22
                 // retablir des sauts de ligne
                 $new_item->description_item = preg_replace("/\\|\\|\\|/", "\r\n", $new_item->description_item);
                 $new_item->num_item = $this->getpath($item, array('#', 'num_item', 0, '#'), '', false, '');
                 $new_item->type_item = $this->getpath($item, array('#', 'type_item', 0, '#'), '', true, '');
                 $new_item->poids_item = $this->getpath($item, array('#', 'poids_item', 0, '#'), '', false, '');
                 // $new_item->ref_competence=$this->getpath( $item, array('#','ref_competence',0,'#'), '', false, '');
                 // $new_item->ref_referentiel=$this->getpath( $item, array('#','ref_referentiel',0,'#'), '', false, '');
                 $new_item->empreinte_item = $this->getpath($item, array('#', 'empreinte_item', 0, '#'), '', false, '');
                 // enregistrer
                 $re->domaines[$dindex]->competences[$cindex]->items[$iindex] = $new_item;
                 // sauvegarder dans la base
                 // remplacer l'id du referentiel importe par l'id du referentiel cree
                 $new_item->ref_referentiel = $new_referentiel_id;
                 $new_item->ref_competence = $new_competence_id;
                 // trafiquer les donnees pour pouvoir appeler la fonction ad hoc
                 $new_item->instance = $new_item->ref_referentiel;
                 $new_item->new_ref_competence = $new_item->ref_competence;
                 $new_item->new_code_item = $new_item->code_item;
                 $new_item->new_description_item = $new_item->description_item;
                 $new_item->new_num_item = $new_item->num_item;
                 $new_item->new_type_item = $new_item->type_item;
                 $new_item->new_poids_item = $new_item->poids_item;
                 $new_item->new_empreinte_item = $new_item->empreinte_item;
                 // creer
                 $new_item_id = referentiel_add_item($new_item);
                 if ($new_item_id) {
                     $nbitems++;
                 }
                 // that's all folks
             }
             // items
             if ($nbitems > 0) {
                 // mettre a jour
                 referentiel_set_competence_nb_item($new_competence_id, $nbitems);
             }
         }
         // competences
         if ($nbcompetences > 0) {
             // mettre a jour
             referentiel_set_domaine_nb_competence($new_domaine_id, $nbcompetences);
         }
     }
     // mettre a jour
     if ($nbdomaines > 0) {
         // mettre a jour
         referentiel_set_referentiel_nb_domaine($new_referentiel_id, $nbdomaines);
     }
     return $re;
 }
Beispiel #4
0
 /**
  * @param array referentiel array from xml tree
  * @return object import_referentiel object
  * modifie la base de donnees
  */
 function import_referentiel($lines)
 {
     // recupere le tableau de lignes
     // selon les parametres soit cree une nouvelle instance
     // soit modifie une instance courante de referentiel
     global $SESSION;
     global $USER;
     global $CFG;
     if (!$this->importation_referentiel_possible()) {
         exit;
     }
     // initialiser les variables
     // id du nouveau referentiel si celui ci doit être cree
     $new_referentiel_id = 0;
     $auteur = "";
     $l_id_referentiel = "id_referentiel";
     $l_code_referentiel = "code_referentiel";
     $l_description_referentiel = "description_referentiel";
     $l_date_creation = "date_creation";
     $l_nb_domaine = "nb_domaine";
     $l_seuil_certification = "seuil_certificat";
     $l_local = "local";
     $l_name = "name";
     $l_url_referentiel = "url_referentiel";
     $l_liste_competences = "liste_competences";
     $l_liste_empreintes = "liste_empreintes";
     $l_logo = "logo_referentiel";
     $ok_referentiel_charge = false;
     // MODIF JF 2012/03/09
     $ok_protocole_charge = false;
     $ok_domaine_charge = false;
     $ok_competence_charge = false;
     $ok_item_charge = false;
     $risque_ecrasement = false;
     // get some error strings
     $error_noname = get_string('xmlimportnoname', 'referentiel');
     $error_nocode = get_string('xmlimportnocode', 'referentiel');
     $error_override = get_string('overriderisk', 'referentiel');
     // DEBUT
     // Decodage
     $line = 0;
     // TRAITER LA LIGNE D'ENTETE
     $nbl = count($lines);
     if ($nbl > 0) {
         // premiere ligne entete fichier csv
         // echo "<br />DEBUG :: forme/csv/format.php :: 424\n";
         // echo "<br />LIGNE $line --------------<br />\n".$lines[$line]."<br />\n";
         // "#Moodle Referentiel CSV Export;latin1;Prénom NOM\n";
         $fields = explode($this->sep, str_replace("\r", "", $lines[$line]));
         $line++;
         if (substr($lines[$line], 0, 1) == '#') {
             // labels
             /// If a line is incorrectly formatted
             if (count($fields) < 3) {
                 if (count($fields) > 1 or strlen($fields[0]) > 1) {
                     // no error for blank lines
                     $this->error("ERROR " . $lines[$line] . ": Line " . $line . "incorrectly formatted - ignoring\n");
                 }
             }
             if (isset($fields[1]) && $fields[1] != "") {
                 $this->table_caractere_input = trim($fields[1]);
             }
             $auteur = trim($fields[2]);
         }
     } else {
         $this->error("ERROR : CSV File incorrect\n");
     }
     // echo "<br />DEBUG :: 991 : $this->table_caractere_input\n";
     if ($nbl > 1) {
         // deuxieme ligne : entete referentiel
         // echo "<br />$line : ".$lines[$line]."\n";
         // #code_referentiel;name;description_referentiel;url_referentiel;date_creation;
         // nb_domaines;seuil_certification;liste_competences
         $fields = explode($this->sep, str_replace("\r", "", $lines[$line]));
         /// If a line is incorrectly formatted
         if (count($fields) < 3) {
             if (count($fields) > 1 or strlen($fields[0]) > 1) {
                 // no error for blank lines
                 $this->error("ERROR " . $lines[$line] . ": Line " . $line . "incorrectly formatted");
             }
         }
         if (substr($lines[$line], 0, 1) == '#') {
             // labels
             $l_code_referentiel = trim($fields[0]);
             $l_name = trim($fields[1]);
             $l_description_referentiel = trim($fields[2]);
             if (isset($fields[3])) {
                 $l_url_referentiel = trim($fields[3]);
             } else {
                 $l_url_referentiel = "";
             }
             if (isset($fields[4])) {
                 $l_date_creation = trim($fields[4]);
             } else {
                 $l_date_creation = "";
             }
             if (isset($fields[5])) {
                 $l_nb_domaines = trim($fields[5]);
             } else {
                 $l_nb_domaines = "";
             }
             if (isset($fields[6])) {
                 $l_seuil_certificat = trim($fields[6]);
             } else {
                 $l_seuil_certificat = "";
             }
             if (isset($fields[7])) {
                 $l_liste_competences = trim($fields[7]);
             } else {
                 $l_liste_competences = "";
             }
             if (isset($fields[8])) {
                 $l_liste_empreintes = trim($fields[8]);
             } else {
                 $l_liste_empreintes = "";
             }
             if (isset($fields[9])) {
                 $l_logo = trim($fields[9]);
             } else {
                 $l_logo = "";
             }
             // MODIF JF 2012/03/26
             if (isset($fields[10])) {
                 $l_minima_certificat = trim($fields[10]);
             } else {
                 $l_minima_certificat = "";
             }
         } else {
             // data  : referentiel
             $code_referentiel = $this->input_codage_caractere(trim($fields[0]));
             $name = $this->input_codage_caractere(trim($fields[1]));
             $description_referentiel = $this->input_codage_caractere(trim($fields[2]));
             if (isset($fields[3])) {
                 $url_referentiel = trim($fields[3]);
             } else {
                 $url_referentiel = "";
             }
             if (isset($fields[4])) {
                 $date_creation = trim($fields[4]);
             } else {
                 $date_creation = "";
             }
             if (isset($fields[5])) {
                 $nb_domaines = trim($fields[5]);
             } else {
                 $nb_domaines = "";
             }
             if (isset($fields[6])) {
                 $seuil_certificat = trim($fields[6]);
             } else {
                 $seuil_certificat = 0.0;
             }
             if (isset($fields[7])) {
                 $liste_competences = $this->input_codage_caractere(trim($fields[7]));
             } else {
                 $liste_competences = "";
             }
             if (isset($fields[8])) {
                 $liste_empreintes = $this->input_codage_caractere(trim($fields[8]));
             } else {
                 $liste_empreintes = "";
             }
             if (isset($fields[9])) {
                 $logo_referentiel = trim($fields[9]);
             } else {
                 $logo_referentiel = "";
             }
             // MODIF JF 2012/03/26
             if (isset($fields[10])) {
                 $minima_certificat = trim($fields[10]);
             } else {
                 $minima_certificat = 0;
             }
             $ok_referentiel_charge = true;
         }
         $line++;
     }
     // maintenant les données indispensables
     while ($line < $nbl && $ok_referentiel_charge == false) {
         // data : referentiel
         // echo "<br />$line : ".$lines[$line]."\n";
         // #referentiel_id;code_referentiel;description_referentiel;date_creation;
         // nb_domaines;seuil_certificat;local;name;url_referentiel;liste_competences
         $fields = explode($this->sep, str_replace("\r", "", $lines[$line]));
         /// If a line is incorrectly formatted
         if (count($fields) < 3) {
             if (count($fields) > 1 or strlen($fields[0]) > 1) {
                 // no error for blank lines
                 $this->error("ERROR " . $lines[$line] . ": Line " . $line . "incorrectly formatted");
             }
             continue;
         }
         // DEBUG
         // echo "<br />DEBUG : ./mod/refrentiel/format/csv/format.php :: 560<br >\n";
         // print_r($fields);
         // data  : referentiel
         $code_referentiel = $this->input_codage_caractere(trim($fields[0]));
         $name = $this->input_codage_caractere(trim($fields[1]));
         $description_referentiel = $this->input_codage_caractere(trim($fields[2]));
         if (isset($fields[3])) {
             $url_referentiel = trim($fields[3]);
         } else {
             $url_referentiel = "";
         }
         if (isset($fields[4])) {
             $date_creation = trim($fields[4]);
         } else {
             $date_creation = "";
         }
         if (isset($fields[5])) {
             $nb_domaines = trim($fields[5]);
         } else {
             $nb_domaines = "";
         }
         if (isset($fields[6])) {
             $seuil_certificat = trim($fields[6]);
         } else {
             $seuil_certificat = 0.0;
         }
         if (isset($fields[7])) {
             $liste_competences = $this->input_codage_caractere(trim($fields[7]));
         } else {
             $liste_competences = "";
         }
         if (isset($fields[8])) {
             $liste_empreintes = $this->input_codage_caractere(trim($fields[8]));
         } else {
             $liste_empreintes = "";
         }
         if (isset($fields[9])) {
             $logo_referentiel = trim($fields[9]);
         } else {
             $logo_referentiel = "";
         }
         // MODIF JF 2012/03/26
         if (isset($fields[10])) {
             $minima_certificat = trim($fields[10]);
         } else {
             $minima_certificat = 0;
         }
         $ok_referentiel_charge = true;
         $line++;
     }
     if (!$ok_referentiel_charge) {
         $this->error(get_string('incompletedata', 'referentiel'));
     }
     // this routine initialises the import object
     $re = $this->defaultreferentiel();
     $re->name = str_replace("'", " ", $name);
     // $re->name=addslashes($name);
     $re->code_referentiel = $code_referentiel;
     $re->description_referentiel = str_replace("'", "`", $description_referentiel);
     // $re->description_referentiel=addslashes($description_referentiel);
     $re->url_referentiel = $url_referentiel;
     $re->seuil_certificat = $seuil_certificat;
     $re->minima_certificat = $minima_certificat;
     $re->timemodified = $date_creation;
     $re->nb_domaines = $nb_domaines;
     $re->liste_codes_competence = $liste_competences;
     $re->liste_empreintes_competence = $liste_empreintes;
     $re->logo_referentiel = $logo_referentiel;
     /*
     // GROS BUG
     if ($id_referentiel!=""){
     	$re->id=$id_referentiel;
     }
     */
     $re->id = 0;
     // DEBUG
     // print_r($re);
     // RISQUE ECRASEMENT ?
     $risque_ecrasement = false;
     //
     if ($this->rreferentiel && $this->rreferentiel->id > 0) {
         // charger le referentiel associé à l'instance
         $this->rreferentiel = referentiel_get_referentiel_referentiel($this->rreferentiel->id);
         if ($this->rreferentiel) {
             $risque_ecrasement = $this->rreferentiel->name == $re->name && $this->rreferentiel->code_referentiel == $re->code_referentiel;
         }
     }
     // SI OUI arrêter
     if ($risque_ecrasement == true) {
         if ($this->override != 1) {
             $this->error($error_override);
         } else {
             // le referentiel courant est remplace
             $new_referentiel_id = $this->rreferentiel->id;
             $re->id = $new_referentiel_id;
         }
     }
     $re->export_process = false;
     $re->import_process = true;
     // le referentiel est toujours place dans le cours local d'appel
     $re->course = $this->course->id;
     $risque_ecrasement = false;
     if (!isset($this->action) || $this->action != "importreferentiel") {
         // importer dans le cours courant en remplacement du referentiel courant
         // Verifier si ecrasement referentiel local
         if (isset($re->name) && $re->name != "" && isset($re->code_referentiel) && $re->code_referentiel != "" && isset($re->id) && $re->id > 0 && isset($re->course) && $re->course > 0) {
             // sauvegarder ?
             if ($this->course->id == $re->course) {
                 if (isset($this->rreferentiel->id) && $this->rreferentiel->id == $re->id || isset($this->rreferentiel->name) && $this->rreferentiel->name == $re->name && (isset($this->rreferentiel->code_referentiel) && $this->rreferentiel->code_referentiel == $re->code_referentiel)) {
                     $risque_ecrasement = true;
                 }
             }
         }
     }
     // DEBUG
     /*
     if ($risque_ecrasement)
     	echo "<br />DEBUG : 607 : Risque d'ecrasement N:$this->newinstance O:$this->override\n";
     else
     	echo "<br />DEBUG : 607 : Pas de risque d'ecrasement N:$this->newinstance O:$this->override\n";
     */
     if ($risque_ecrasement == false || $this->newinstance == 1) {
         // Enregistrer dans la base comme un nouveau referentiel du cours courant
         // DEBUG
         // echo "<br />DEBUG csv/format.php ligne 704<br />\n";
         // print_object($re);
         // exit;
         $new_referentiel_id = referentiel_add_referentiel($re);
         // retourne un id de la table refrentiel_referentiel
         $this->setReferentielId($new_referentiel_id);
     } else {
         if ($risque_ecrasement == true && $this->override == 1) {
             // Enregistrer dans la base en remplaçant la version courante (update)
             // NE FAUDRAIT IL PAS SUPPRIMER LE REFERENTIEL AVANT DE LA RECHARGER ?
             $re->instance = $this->rreferentiel->id;
             $re->referentiel_id = $this->rreferentiel->id;
             // DEBUG
             // echo "<br />DEBUG csv/format.php ligne 638<br />MISE A JOUR  : ".$r->rreferentiel_id."\n";
             $ok = referentiel_update_referentiel($re);
             // retourne un id de la table referentiel_referentiel
             $new_referentiel_id = $this->rreferentiel->id;
         } else {
             // ni nouvelle instance ni recouvrement
             $this->error("ERREUR 2 " . $error_override);
             return false;
         }
     }
     if (isset($new_referentiel_id) && $new_referentiel_id > 0) {
         // IMPORTER LE RESTE DU REFERENTIEL
         $dindex = 0;
         $cindex = 0;
         $iindex = 0;
         $re->domaines = array();
         $new_domaine_id = 0;
         $new_competence_id = 0;
         $numero_domaine = 0;
         // compteur pour suppleer le numero si non importe
         $numero_competence = 0;
         $numero_item = 0;
         $num_domaine = 0;
         $num_competence = 0;
         $type_domaine = 0;
         $seuil_domaine = 0.0;
         $type_competence = 0;
         $seuil_competence = 0.0;
         $minima_domaine = 0.0;
         $minima_competence = 0;
         $num_item = 0;
         $is = "";
         $pindex = 0;
         $is_protocole = false;
         $ok_protocole_charge = false;
         $nbprotocoles = 0;
         $is_domaine = false;
         $is_competence = false;
         $is_item = false;
         $mode = "add";
         while ($line < $nbl) {
             // echo "<br />DEBUG 652 :: <br />".$lines[$line]."\n";
             $fields = explode($this->sep, str_replace("\r", "", $lines[$line]));
             if (count($fields) < 2) {
                 if (count($fields) > 1 or strlen($fields[0]) > 1) {
                     // no error for blank lines
                     $this->error("ERROR " . $lines[$line] . ": Line " . $line . "incorrectly formatted");
                 }
                 continue;
             }
             // print_r($fields);
             // Label ou data ?
             // echo "<br />".substr($fields[0],0,1)."\n";
             if (substr($fields[0], 0, 1) == '#') {
                 // labels
                 // on s'en sert pour construire l'arbre
                 $is = trim($fields[0]);
                 $is_protocole = false;
                 $is_domaine = false;
                 $is_competence = false;
                 $is_item = false;
                 switch ($is) {
                     case '#protocole_seuil':
                         // #protocole_seuil;l_domaines_oblig;l_seuils_domaines;l_competences_oblig;l_seuils_competences;l_items_oblig;timemodified;actif;commentaire
                         $is_protocole = true;
                         break;
                     case '#code_domaine':
                         // #code_domaine;description_domaine;num_domaine;nb_competences;type_domaine;seuil_domaine
                         $is_domaine = true;
                         break;
                     case '#code_competence':
                         // #code_competence;description_competence;num_competence;nb_item_competences;type_competence;seuil_competence
                         $is_competence = true;
                         break;
                     case '#code_item':
                         // #code_item;description_item;type_item;poids_item;num_item
                         $is_item = true;
                         break;
                     default:
                         $this->error("ERROR : CSV File incorrect line number:" . $line . "\n");
                         break;
                 }
             } else {
                 if (isset($is) && $is != "") {
                     // data
                     switch ($is) {
                         // MODIF JF 2012/03/09
                         case '#protocole_seuil':
                             // Protocole
                             // data
                             $seuil_referentiel = trim($fields[0]);
                             $minima_referentiel = trim($fields[1]);
                             $l_domaines_oblig = addslashes($this->input_codage_caractere(trim($fields[2])));
                             $l_seuils_domaines = addslashes($this->input_codage_caractere(trim($fields[3])));
                             $l_minimas_domaines = addslashes($this->input_codage_caractere(trim($fields[4])));
                             $l_competences_oblig = addslashes($this->input_codage_caractere(trim($fields[5])));
                             $l_seuils_competences = addslashes($this->input_codage_caractere(trim($fields[6])));
                             $l_minimas_competences = addslashes($this->input_codage_caractere(trim($fields[7])));
                             $l_items_oblig = addslashes($this->input_codage_caractere(trim($fields[8])));
                             $timemodified = trim($fields[9]);
                             $actif = trim($fields[10]);
                             $commentaire = addslashes($this->input_codage_caractere(trim($fields[11])));
                             // Creer un enregistrement
                             $new_protocole = $this->defaultprotocole();
                             // sauvegarder dans la base
                             // remplacer l'id du referentiel importe par l'id du referentiel cree
                             // trafiquer les donnees pour appeler la fonction ad hoc
                             $new_protocole->ref_occurrence = $new_referentiel_id;
                             // $new_protocole->id=$this->getpath( $protocole, array('#','p_id',0,'#'), '', false, '');
                             // $new_protocole->ref_occurrence;
                             $new_protocole->seuil_referentiel = $seuil_referentiel;
                             $new_protocole->minima_referentiel = $minima_referentiel;
                             // A recreer a partir des domaines et competences pourr eviter incoherences
                             // La suite initialise en chargeant les domaines / compétences / items
                             // $new_protocole->l_domaines_oblig=$l_competences_oblig;
                             // $new_protocole->l_seuils_domaines= $l_seuils_domaines;
                             // $new_protocole->l_competences_oblig=$l_competences_oblig;
                             // $new_protocole->l_seuils_competences=$l_seuils_competences;
                             // $new_protocole->l_minimas_competences=$l_minimas_competences;
                             // $new_protocole->l_items_oblig= $l_items_oblig;
                             $new_protocole->timemodified = $timemodified;
                             $new_protocole->actif = $actif;
                             $new_protocole->commentaire = $commentaire;
                             // sauvegarder dans la base
                             // remplacer l'id du referentiel importe par l'id du referentiel cree
                             // trafiquer les donnees pour appeler la fonction ad hoc
                             $new_protocole->ref_occurrence = $new_referentiel_id;
                             // DEBUG
                             // echo "<br />DEBUG ./format/csv/format.php :: 710<br />\n";
                             // print_object($new_protocole);
                             if (referentiel_add_protocol($new_protocole)) {
                                 $nbprotocoles++;
                             }
                             // enregistrer
                             $pindex++;
                             $re->protocoles[$pindex] = $new_protocole;
                             $ok_protocole_charge = true;
                             break;
                         case '#code_domaine':
                             // $code_domaine;$description_domaine;$num_domaine;$nb_competences
                             // Domaines
                             // data
                             $code_domaine = addslashes($this->input_codage_caractere(trim($fields[0])));
                             $description_domaine = addslashes($this->input_codage_caractere(trim($fields[1])));
                             $num_domaine = trim($fields[2]);
                             $nb_competences = trim($fields[3]);
                             if (isset($fields[4])) {
                                 $type_domaine = trim($fields[4]);
                             } else {
                                 $type_domaine = 0;
                             }
                             if (isset($fields[5])) {
                                 $seuil_domaine = trim($fields[5]);
                             } else {
                                 $seuil_domaine = 0;
                             }
                             if (isset($fields[6])) {
                                 $minima_domaine = trim($fields[6]);
                             } else {
                                 $minima_domaine = 0;
                             }
                             if ($code_domaine != "") {
                                 // Creer un domaine
                                 $numero_domaine++;
                                 $new_domaine = array();
                                 $new_domaine = $this->defaultdomaine();
                                 $new_domaine->code_domaine = $code_domaine;
                                 if ($description_domaine != "") {
                                     $new_domaine->description_domaine = $description_domaine;
                                 }
                                 if ($num_domaine != "") {
                                     $new_domaine->num_domaine = $num_domaine;
                                 } else {
                                     $new_domaine->num_domaine = $numero_domaine;
                                 }
                                 if ($nb_competences != "") {
                                     $new_domaine->nb_competences = $nb_competences;
                                 } else {
                                     $new_domaine->nb_competences = 0;
                                 }
                                 if ($type_domaine != "") {
                                     $new_domaine->type_domaine = $type_domaine;
                                 } else {
                                     $new_domaine->type_domaine = 0;
                                 }
                                 if ($seuil_domaine != "") {
                                     $new_domaine->seuil_domaine = $seuil_domaine;
                                 } else {
                                     $new_domaine->seuil_domaine = 0.0;
                                 }
                                 if ($minima_domaine != "") {
                                     $new_domaine->minima_domaine = $minima_domaine;
                                 } else {
                                     $new_domaine->minima_domaine = 0;
                                 }
                                 $new_domaine->ref_referentiel = $new_referentiel_id;
                                 // sauvegarder dans la base
                                 // remplacer l'id du referentiel importe par l'id du referentiel cree
                                 // trafiquer les donnees pour appeler la fonction ad hoc
                                 $new_domaine->ref_referentiel = $new_referentiel_id;
                                 $new_domaine->instance = $new_referentiel_id;
                                 // pour que ca marche
                                 $new_domaine->new_code_domaine = $new_domaine->code_domaine;
                                 $new_domaine->new_description_domaine = $new_domaine->description_domaine;
                                 $new_domaine->new_num_domaine = $new_domaine->num_domaine;
                                 $new_domaine->new_nb_competences = $new_domaine->num_domaine;
                                 $new_domaine->new_type_domaine = $new_domaine->type_domaine;
                                 $new_domaine->new_seuil_domaine = $new_domaine->seuil_domaine;
                                 $new_domaine->new_minima_domaine = $new_domaine->minima_domaine;
                                 $new_domaine_id = referentiel_add_domaine($new_domaine);
                                 if (isset($new_domaine_id) && $new_domaine_id > 0) {
                                     $new_domaine->id = $new_domaine_id;
                                 } else {
                                     $new_domaine->id = 0;
                                 }
                                 // enregistrer
                                 $dindex++;
                                 $re->domaines[$dindex] = $new_domaine;
                                 $cindex = 0;
                                 $re->domaines[$dindex]->competences = array();
                                 $numero_competence = 0;
                                 $ok_domaine_charge = true;
                             } else {
                                 $ok_domaine_charge = false;
                             }
                             break;
                         case '#code_competence':
                             // $competence_id;$code_competence;$description_competence;$ref_domaine;
                             // $num_competence;$nb_item_competences
                             $code_competence = addslashes($this->input_codage_caractere(trim($fields[0])));
                             $description_competence = addslashes($this->input_codage_caractere(trim($fields[1])));
                             $num_competence = trim($fields[2]);
                             $nb_item_competences = trim($fields[3]);
                             if (isset($fields[4])) {
                                 $type_competence = trim($fields[4]);
                             } else {
                                 $type_competence = 0;
                             }
                             if (isset($fields[5])) {
                                 $seuil_competence = trim($fields[5]);
                             } else {
                                 $seuil_competence = 0;
                             }
                             if (isset($fields[6])) {
                                 $minima_competence = trim($fields[6]);
                             } else {
                                 $minima_competence = 0;
                             }
                             if ($code_competence != "" && $ok_domaine_charge && $new_domaine_id > 0) {
                                 // Creer une competence
                                 $new_competence_id = 0;
                                 $numero_competence++;
                                 $new_competence = array();
                                 $new_competence = $this->defaultcompetence();
                                 $new_competence->id = 0;
                                 $new_competence->code_competence = $code_competence;
                                 if ($description_competence != "") {
                                     $new_competence->description_competence = $description_competence;
                                 }
                                 if ($num_competence != "") {
                                     $new_competence->num_competence = $num_competence;
                                 } else {
                                     $new_competence->num_competence = $numero_competence;
                                 }
                                 if ($nb_item_competences != "") {
                                     $new_competence->nb_item_competences = $nb_item_competences;
                                 } else {
                                     $new_competence->nb_item_competences = 0;
                                 }
                                 if ($type_competence != "") {
                                     $new_competence->type_competence = $type_competence;
                                 } else {
                                     $new_competence->type_competence = 0;
                                 }
                                 if ($seuil_competence != "") {
                                     $new_competence->seuil_competence = $seuil_competence;
                                 } else {
                                     $new_competence->seuil_competence = 0.0;
                                 }
                                 if ($minima_competence != "") {
                                     $new_competence->minima_competence = $minima_competence;
                                 } else {
                                     $new_competence->minima_competence = 0;
                                 }
                                 if (isset($new_domaine_id) && $new_domaine_id > 0) {
                                     $new_competence->ref_domaine = $new_domaine_id;
                                 } else {
                                     $new_competence->ref_domaine = 0;
                                 }
                                 // sauvegarder dans la base
                                 // remplacer l'id du referentiel importe par l'id du referentiel cree
                                 $new_competence->ref_domaine = $new_domaine_id;
                                 // trafiquer les donnees pour appeler la fonction ad hoc
                                 $new_competence->instance = $new_referentiel_id;
                                 // pour que ca marche
                                 $new_competence->new_code_competence = $new_competence->code_competence;
                                 $new_competence->new_description_competence = $new_competence->description_competence;
                                 $new_competence->new_ref_domaine = $new_domaine_id;
                                 $new_competence->new_num_competence = $new_competence->num_competence;
                                 $new_competence->new_nb_item_competences = $new_competence->nb_item_competences;
                                 $new_competence->new_type_competence = $new_competence->type_competence;
                                 $new_competence->new_seuil_competence = $new_competence->seuil_competence;
                                 $new_competence->new_minima_competence = $new_competence->minima_competence;
                                 // creation
                                 $new_competence_id = referentiel_add_competence($new_competence);
                                 $new_competence->id = $new_competence_id;
                                 // enregistrer
                                 $cindex++;
                                 $re->domaines[$dindex]->competences[$cindex] = $new_competence;
                                 $iindex = 0;
                                 // nouveaux items à suivre
                                 $re->domaines[$dindex]->competences[$cindex]->items = array();
                                 $numero_item = 0;
                                 $ok_competence_charge = true;
                             } else {
                                 $ok_competence_charge = false;
                             }
                             break;
                         case '#code_item':
                             // $code_item;$description_item;$type_item;$poids_item;$num_item;$empreinte_item
                             $code_item = $this->input_codage_caractere(addslashes(trim($fields[0])));
                             $description_item = $this->input_codage_caractere(addslashes(trim($fields[1])));
                             $type_item = $this->input_codage_caractere(addslashes(trim($fields[2])));
                             $poids_item = trim($fields[3]);
                             $num_item = trim($fields[4]);
                             if (isset($fields[5]) && trim($fields[5]) != "") {
                                 $empreinte_item = trim($fields[5]);
                             } else {
                                 $empreinte_item = "1";
                             }
                             if ($code_item != "" && $ok_competence_charge && $new_competence_id > 0) {
                                 // Creer un domaine
                                 $numero_item++;
                                 $new_item = array();
                                 $new_item = $this->defaultitem();
                                 $new_item->code_item = $code_item;
                                 if ($description_item != "") {
                                     $new_item->description_item = $description_item;
                                 }
                                 $new_item->ref_referentiel = $new_referentiel_id;
                                 $new_item->ref_competence = $new_competence_id;
                                 $new_item->type_item = $type_item;
                                 $new_item->poids_item = $poids_item;
                                 if ($num_item != "") {
                                     $new_item->num_item = $num_item;
                                 } else {
                                     $new_item->num_item = $numero_item;
                                 }
                                 $new_item->empreinte_item = $empreinte_item;
                                 // sauvegarder dans la base
                                 // remplacer l'id du referentiel importe par l'id du referentiel cree
                                 $new_item->ref_referentiel = $new_referentiel_id;
                                 $new_item->ref_competence = $new_competence_id;
                                 // trafiquer les donnees pour pouvoir appeler la fonction ad hoc
                                 $new_item->instance = $new_item->ref_referentiel;
                                 $new_item->new_ref_competence = $new_item->ref_competence;
                                 $new_item->new_code_item = $new_item->code_item;
                                 $new_item->new_description_item = $new_item->description_item;
                                 $new_item->new_num_item = $new_item->num_item;
                                 $new_item->new_type_item = $new_item->type_item;
                                 $new_item->new_poids_item = $new_item->poids_item;
                                 $new_item->new_empreinte_item = $new_item->empreinte_item;
                                 // creer
                                 $new_item_id = referentiel_add_item($new_item);
                                 $new_item->id = $new_item_id;
                                 $iindex++;
                                 $re->domaines[$dindex]->competences[$cindex]->items[$iindex] = $new_item;
                                 $ok_item_charge = true;
                             } else {
                                 $ok_item_charge = false;
                             }
                             break;
                         default:
                             $this->error("ERROR : CSV File incorrect line number:" . $line . "\n");
                             break;
                     }
                 }
             }
             // that's all folks
             $line++;
         }
         // end of while loop
         if ($mode == "add") {
             // rien de special ici ?
         }
         return $re;
     }
     return false;
 }