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; }
// gestion du mot de passe if (isset($form->suppression_pass_referentiel) && $form->suppression_pass_referentiel == 1) { $form->old_pass_referentiel = ''; } else { if (isset($form->pass_referentiel) && $form->pass_referentiel != '' && (isset($form->old_pass_referentiel) && $form->old_pass_referentiel != '' && $form->old_pass_referentiel != md5($form->pass_referentiel) || isset($form->old_pass_referentiel) && $form->old_pass_referentiel == '')) { $form->old_pass_referentiel = md5($form->pass_referentiel); } } $return = referentiel_update_referentiel_referentiel($form); $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id; $action = "update"; } else { if ($form->action == "modifierdomaine") { // enregistre les modifications if (isset($form->domaine_id) && $form->domaine_id > 0) { $return = referentiel_update_domaine($form); $msg = get_string("referentiel", "referentiel") . " " . $form->referentiel_id . " " . get_string("domaine", "referentiel") . " " . $form->domaine_id; $action = "update"; } } else { if ($form->action == "modifiercompetence") { // 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);