$fin_update->execute();
     $pdo->commit();
 } catch (Exception $e) {
     echo $e->getCode() . ' ' . $e->getMessage() . ' ' . $e->getLine() . ' in ' . $e->getFile();
     $pdo->rollback();
     $update = false;
 }
 // ----------------------------------------------
 /*
     ----------------------------------------------
     Début de la création du document.
     Le code qui suit pourrait être considéré comme un template si 
     on arrive à le paramétrer correctement.
      ----------------------------------------------
 */
 $result = fetchAllInfoPlanCadre($_SESSION['id_plancadre']);
 $info_plancadre = $result[0];
 $etat = $info_plancadre["Etat"];
 $nom_cours = "Titre du cours : " . $info_plancadre["NomCours"];
 $code_cours = "Numéro du cours : " . $info_plancadre["CodeCours"];
 $nom_programme = $info_plancadre["NomProgramme"];
 $code_programme = $info_plancadre["CodeProgramme"];
 $programme_cours = $nom_programme . "(" . $code_programme . ")";
 $ponderation_cours = "Pondération : " . $info_plancadre["Ponderation"];
 $nombre_unites_cours = "Nombre d'unité(s) : " . $info_plancadre["NombreUnites"];
 $prealable_cours = "Préalable(s) : " . "Aucun";
 $type_enseignement = $info_plancadre['TypeCours'];
 $php_word = new \PhpOffice\PhpWord\PhpWord();
 // ----------------------------------------------
 // ajout des styles au document
 $php_word->addParagraphStyle("style_align_right", $GLOBALS["style_align_right"]);
function buildPlanCadre($id_plancadre)
{
    $result = fetchAllInfoPlanCadre($id_plancadre);
    $info_plancadre = $result[0];
    $etat = $info_plancadre["Etat"];
    $nom_cours = "Titre du cours : " . $info_plancadre["NomCours"];
    $code_cours = "Numéro du cours : " . $info_plancadre["CodeCours"];
    $nom_programme = $info_plancadre["NomProgramme"];
    $code_programme = $info_plancadre["CodeProgramme"];
    $programme_cours = $nom_programme . "(" . $code_programme . ")";
    $ponderation_cours = "Pondération : " . $info_plancadre["Ponderation"];
    $nombre_unites_cours = "Nombre d'unité(s) : " . $info_plancadre["NombreUnites"];
    $prealable_cours = "Préalable(s) : " . "Aucun";
    $type_enseignement = $info_plancadre['TypeCours'];
    // le nom des fichiers textes serra :
    // clé primaire du plancadre + code ou le nom du cours + le nom de la section
    // exemple : 2_420-EDA-05_PresentationCours.txt
    $path_presentation = "../plancadre/" . $id_plancadre . "_" . $code_cours . "_" . "presentation" . ".txt";
    $path_integration = "../plancadre/" . $id_plancadre . "_" . $code_cours . "_" . "integration" . ".txt";
    $path_evalutation = "../plancadre/" . $id_plancadre . "_" . $code_cours . "_" . "evaluation" . ".txt";
    $path_competences = "../plancadre/" . $id_plancadre . "_" . $code_cours . "_" . "competences" . ".txt";
    $path_apprentissage = "../plancadre/" . $id_plancadre . "_" . $code_cours . "_" . "apprentissage" . ".txt";
    $presentation = ReadFrom($path_presentation);
    $integration = ReadFrom($path_integration);
    $evaluation = ReadFrom($path_evalutation);
    $competences = ReadFrom($path_competences);
    $apprentissage = ReadFrom($path_apprentissage);
    /*
        ----------------------------------------------
        Début de la création du document.
        Le code qui suit pourrait être considéré comme un template si 
        on arrive à le paramétrer correctement.
         ----------------------------------------------
    */
    $php_word = new \PhpOffice\PhpWord\PhpWord();
    // ----------------------------------------------
    // ajout des styles au document
    $php_word->addParagraphStyle("style_align_right", $GLOBALS["style_align_right"]);
    $php_word->addParagraphStyle("style_align_center", $GLOBALS["style_align_center"]);
    $php_word->addTableStyle('style_table', $GLOBALS["style_table"]);
    // ----------------------------------------------
    // ----------------------------------------------
    // Section de l'indentification du cours
    $section_template = $php_word->addSection();
    //
    $nom_etablissement = "Collège Lionel-Groulx";
    $section_template->addText($nom_etablissement);
    $section_template->addText($type_enseignement, null, "style_align_right");
    $section_template->addText($programme_cours, null, "style_align_right");
    switch ($info_plancadre["Etat"]) {
        case 'Adopté':
            if ($info_plancadre["Officiel"] > 0) {
                $titre_document = "Plan-cadre officiel";
            } else {
                $titre_document = "Plan-cadre en archive";
            }
            break;
        case 'Validé':
        case 'Élaboration':
        default:
            $titre_document = "Plan-cadre en élaboration";
            break;
    }
    // espace avant et après le titre du document
    $section_template->addText($GLOBALS["saut_ligne"]);
    $section_template->addText($titre_document, $GLOBALS["style_font_titre"], $GLOBALS["style_align_center"]);
    $section_template->addText($GLOBALS["saut_ligne"]);
    $table_identification = $section_template->addTable('style_table');
    $nombre_colonnes = 3;
    $cell_width = $GLOBALS["table_width"] / $nombre_colonnes;
    $table_identification->addRow($GLOBALS["style_row"]);
    $table_identification->addCell($cell_width, $GLOBALS["style_cellule_titre"])->addText("Identification du cours", $GLOBALS["style_font_titre"], $GLOBALS["style_align_center"]);
    $table_identification->addRow($GLOBALS["style_row"]);
    $table_identification->addCell($cell_width)->addText("Discipline", null, $GLOBALS["style_align_center"]);
    $table_identification->addCell($cell_width)->addText($nom_cours, null, $GLOBALS["style_align_center"]);
    $table_identification->addCell($cell_width)->addText($code_cours, null, $GLOBALS["style_align_center"]);
    $table_identification->addRow($GLOBALS["style_row"]);
    $table_identification->addCell($cell_width)->addText($ponderation_cours, null, $GLOBALS["style_align_center"]);
    $table_identification->addCell($cell_width)->addText($nombre_unites_cours, null, $GLOBALS["style_align_center"]);
    $table_identification->addCell($cell_width)->addText("test", null, $GLOBALS["style_align_center"]);
    // Fin de la section de l'indentification du cours
    // ----------------------------------------------
    // ----------------------------------------------
    // Section de la présentation du cours
    $titre = "Présentation du cours";
    addSection($php_word, $titre, $presentation);
    // Fin de la section de la présentation du cours
    // ----------------------------------------------
    // ----------------------------------------------
    // Section de l'objectif d'intégration
    $titre = "Objectif d'intégration";
    addSection($php_word, $titre, $integration);
    // Fin de la section de l'objectif d'intégration
    // ----------------------------------------------
    // ----------------------------------------------
    // Section de l'évaluation des apprentissages
    $titre = 'Évaluation des apprentissages';
    addSection($php_word, $titre, $evaluation);
    // Fin de la section de l'évaluation des apprentissages
    // ----------------------------------------------
    // ----------------------------------------------
    // Section de l'énoncé des compétences
    $titre_section = "Énoncé des compétences";
    addSection($php_word, $titre, $competences);
    // Fin de la section de l'énoncé des compétences
    // ----------------------------------------------
    // ----------------------------------------------
    // Section des objectifs d'apprentissage
    $titre = "Objectifs d'apprentissage";
    addSection($php_word, $titre, $apprentissage);
    // Fin de la section des objectifs d'apprentissage
    // ----------------------------------------------
    $path_docx = "../plancadre/" . $id_plancadre . "_" . $code_cours . ".docx";
    $php_word->save($path_docx);
}