Ejemplo n.º 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;
}
Ejemplo n.º 2
0
/**
 * Given an object containing all the necessary referentiel,
 * (defined by the form in mod.html) this function
 * will update an instance and return true
 *
 * @param object $form An object from the form in mod.html
 * @return boolean
 **/
function referentiel_update_referentiel($form)
{
    global $CFG;
    global $DB;
    global $USER;
    // $form : formulaire
    // DEBUG
    // echo "<br />DEBUG lib_referentiel.php Ligne 676";
    // print_object($form);
    // echo "<br />";
    $ok = false;
    if (isset($form->referentiel_id) && $form->referentiel_id > 0) {
        // referentiel
        $referentiel = new object();
        $referentiel->name = addslashes($form->name);
        $referentiel->code_referentiel = addslashes($form->code_referentiel);
        $referentiel->description_referentiel = addslashes($form->description_referentiel);
        $referentiel->url_referentiel = addslashes($form->url_referentiel);
        $referentiel->seuil_certificat = $form->seuil_certificat;
        $referentiel->timemodified = time();
        $referentiel->nb_domaines = $form->nb_domaines;
        $referentiel->liste_codes_competence = $form->liste_codes_competence;
        $referentiel->liste_empreintes_competence = $form->liste_empreintes_competence;
        $referentiel->timemodified = time();
        $referentiel->id = $form->referentiel_id;
        // Modif JF 2009/10/16
        if (isset($form->liste_poids_competence)) {
            $referentiel->liste_poids_competence = $form->liste_poids_competence;
        } else {
            $referentiel->liste_poids_competence = '';
        }
        if (isset($form->logo_referentiel)) {
            $referentiel->logo_referentiel = $form->logo_referentiel;
        } else {
            $referentiel->logo_referentiel = '';
        }
        // local ou global
        if (isset($form->local) && $form->local != 0 && isset($form->course) && $form->course != 0) {
            $referentiel->local = $form->course;
        } else {
            $referentiel->local = 0;
        }
        // traitements speciaux
        if (isset($form->mail_auteur_referentiel) && $form->mail_auteur_referentiel != '') {
            $referentiel->mail_auteur_referentiel = $form->mail_auteur_referentiel;
        } else {
            // Modif JF 2009/10/16
            if (isset($USER->email) && $USER->email != '') {
                $referentiel->mail_auteur_referentiel = $USER->email;
            } else {
                $referentiel->mail_auteur_referentiel = '';
            }
        }
        if (!isset($form->cle_referentiel)) {
            $referentiel->cle_referentiel = '';
        } else {
            $referentiel->cle_referentiel = $form->cle_referentiel;
        }
        if (isset($form->pass_referentiel) && $form->pass_referentiel != '') {
            // MD5
            $referentiel->pass_referentiel = md5($form->pass_referentiel);
        } else {
            if (isset($form->old_pass_referentiel)) {
                $referentiel->pass_referentiel = $form->old_pass_referentiel;
                // archive md5()
            } else {
                $referentiel->pass_referentiel = '';
            }
        }
        if (isset($form->minima_certificat)) {
            $referentiel->minima_certificat = $form->minima_certificat;
        } else {
            $referentiel->minima_certificat = '';
        }
        // Modif JF 2012/06/02
        if (isset($form->label_domaine)) {
            $referentiel->label_domaine = $form->label_domaine;
        } else {
            $referentiel->label_domaine = '';
        }
        if (isset($form->label_competence)) {
            $referentiel->label_competence = $form->label_competence;
        } else {
            $referentiel->label_competence = '';
        }
        if (isset($form->label_item)) {
            $referentiel->label_item = $form->label_item;
        } else {
            $referentiel->label_item = '';
        }
        // DEBUG
        // echo "<br />";
        // print_object($referentiel);
        // echo "<br />";
        if ($ok = $DB->update_record("referentiel_referentiel", $referentiel)) {
            // MODIF JF 2012/03/04
            referentiel_recalcule_cle_referentiel($referentiel->id);
        }
    }
    // DEBUG
    // exit;
    return $ok;
}