/**
 * generatePDF - Génère un fichier PDF à partir des données d'évaluation d'un service
 *
 * @category : eval_ccpc_functions
 * @param array $data Données d'évaluation récupérées à partir de la fonction {@link getEvaluationCCPCFullData()}
 * @param boolean $comment TRUE si on incut les commentaire, FALSE si on ne les inclut pas
 * @param boolean $commentMSG TRUE si on incut un message concernant la CSG, FALSE si on ne l'inclut pas
 * @return array Array contenant les informations du fichier généré
 *
 * @Author Ali Bellamine
 *
 * Contenu de l'array retourné :<br>
 * 	['pdfPath'] => (string) Chemin local vers le fichier généré<br>
 * 	['pdfURI'] => (string) URI pointant vers le fichier généré
 *
 */
function generatePDF($data, $comment = FALSE, $commentMSG = FALSE)
{
    // Array contenant les résultats
    $output = array();
    // On vérifie l'existence des données
    if (isset($data) && count($data) > 0) {
        /* 
        	Mise en cache
        */
        // Calcul du md5
        $hashdata = $data;
        $hashdata['optionsPDF'] = array('comment' => $comment, 'commentMSG' => $commentMSG);
        $hash = md5(json_encode($hashdata));
        $pdfPath = PLUGIN_PATH . 'cache/' . $hash . '.pdf';
        $pdfPathURI = ROOT . 'evaluations/ccpc/cache/' . $hash . '.pdf';
        if (is_file($pdfPath)) {
            $output['pdfPath'] = $pdfPath;
            $output['pdfURI'] = $pdfPathURI;
            return $output;
        } else {
            // On charge la librairie
            require_once PLUGIN_PATH . 'core/fpdf17/fpdf.php';
            // On charge le fichier XML
            if (is_file(PLUGIN_PATH . 'formulaire.xml')) {
                $form = simplexml_load_file(PLUGIN_PATH . 'formulaire.xml');
            }
            // Promotion
            if (count($data['service']['promotion']) > 1) {
                $promotion = false;
            } else {
                foreach ($data['service']['promotion'] as $promotionData) {
                    $promotion = $promotionData['id'];
                }
            }
            ob_end_clean();
            // On crée le PDF
            $A4Height = 842;
            $A4Width = 595;
            $titleSize = 15;
            $textSize = 11;
            $pdf = new FPDF('L', 'pt', 'A4');
            $pdf->SetTopMargin(10);
            $pdf->SetLeftMargin(15);
            $pdf->SetAutoPageBreak(TRUE, 10);
            /**
            						Page contenant le résumé des données d'évaluation
            					**/
            $pdf->AddPage();
            $pdf->SetFont('Arial', 'B', $titleSize);
            // On affiche le titre
            $pdf->SetFillColor(70, 70, 242);
            $pdf->SetTextColor(255, 255, 255);
            $pdf->SetX(floor(0.1 * $A4Height));
            $pdf->Cell(floor(0.8 * $A4Height), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_TITLE), 'LRTB', 0, 'C', TRUE);
            // Première ligne
            $pdf->Ln(2 * $titleSize);
            $pdf->SetFont('Arial', '', $textSize);
            // On affiche les informations concernant le service
            // Récupération des données
            $textToDisplay = LANG_FORM_CCPC_FILTER_SERVICE_TITLE . ' : ' . $data['service']['FullName'] . PHP_EOL . LANG_FORM_CCPC_PDF_STAGEPERIODE . ' : ' . date('d/m/Y', $data['service']['date']['min']) . ' - ' . date('d/m/Y', $data['service']['date']['max']) . PHP_EOL . LANG_FORM_CCPC_PDF_STUDENTPROMOTION . ' : ';
            $firstLoop = true;
            foreach ($data['service']['promotion'] as $promotionData) {
                if (!$firstLoop) {
                    $textToDisplay .= ', ';
                } else {
                    $firstLoop = FALSE;
                }
                $textToDisplay .= $promotionData['nom'] . ' (' . $promotionData['nb'] . ')';
            }
            $textToDisplay .= PHP_EOL . LANG_FORM_CCPC_PDF_STUDENTNB . ' : ' . $data['service']['nbEvaluation'] . PHP_EOL . LANG_FORM_CCPC_PDF_EVALUATIONNB . ' : ' . $data['nb'];
            $textToDisplay = utf8_decode($textToDisplay);
            // Affichage
            $pdf->SetFillColor(231, 231, 231);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->MultiCell(floor(0.35 * $A4Height), $textSize + 5, $textToDisplay, 'LRTB', 'L', TRUE);
            // On affiche les graphiques : mainGraphPDF
            // Récupération des données
            // Liste des graphiques à afficher
            $input = $form->xpath('categorie/input[@mainPDFGraph="1"]');
            $nbGraph = count($input);
            // Nombre de graphiques à intégrer
            // On génère $tempData, contenant les données utilisées pour génération du png
            foreach ($input as $select) {
                if ($select['type'] == 'select') {
                    $categorie = $select->xpath('..')[0];
                    // Catégorie du graphique
                    $tempData = array();
                    $tempData['settings'] = array('width' => 450, 'height' => 230);
                    foreach ($select->option as $option) {
                        if (isset($data[(string) $categorie['nom']][(string) $select['nomBDD']]['nb'][(string) $option['value']])) {
                            $value = $data[(string) $categorie['nom']][(string) $select['nomBDD']]['nb'][(string) $option['value']];
                            if (is_numeric($value)) {
                                $tempData['data'][constant((string) $option['text'])] = $value;
                            } else {
                                $tempData['data'][constant((string) $option['text'])] = 0;
                            }
                        } else {
                            $tempData['data'][constant((string) $option['text'])] = 0;
                        }
                    }
                    // On inclut l'image
                    $pdf->Image(eval_ccpc_genGraphPie($tempData), 0.4 * $A4Height, 3 * $titleSize, floor(0.4 * $A4Height), 0, 'PNG');
                    break;
                }
            }
            // On affiche l'icone des filtres
            $filtres = eval_ccpc_checkFilterExistence($data['service']['id'], $data['service']['date']['min'], $data['service']['date']['max'], $promotion);
            if (is_array($filtres)) {
                foreach ($filtres as $filtre) {
                    if (isset($filtre['icone'])) {
                        $pdf->Image($filtre['icone'], 0.8 * $A4Height, 3 * $titleSize, floor(0.2 * $A4Height), 0, 'PNG');
                        break;
                    }
                }
            }
            // Deuxième ligne
            $pdf->Ln(8 * $titleSize);
            // On affiche le radar sur 1 an de données
            $fullYearData = getEvaluationCCPCFullData($data['service']['id'], $promotion, $data['service']['date']['max'] - 31536000, $data['service']['date']['max'], FALSE);
            // Récupération des données
            // Titre
            $pdf->Cell(floor(0.4 * $A4Height), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_STAGEPERIODE_FULLYEAR . ' (' . date('d/m/Y', $fullYearData['service']['date']['min']) . ' ' . LANG_FORM_CCPC_PDF_STAGEPERIODE_END . ' ' . date('d/m/Y', $fullYearData['service']['date']['max']) . ')'), 0, 0, 'C', FALSE);
            // On affiche l'image
            // Liste des valeurs à afficher
            $input = $form->xpath('categorie/input[@radarPDFGraph="1"]');
            // Préparation des données
            $tempData = array();
            $tempData['settings'] = array('height' => 380, 'width' => 680, 'max' => 10);
            foreach ($input as $theinput) {
                // Récupération du parent
                $categorie = $theinput->xpath('..')[0];
                // Catégorie du graphique
                if (isset($data[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'])) {
                    $tempData['data'][constant($theinput['label'] . '_SHORT')] = $fullYearData[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'] + 5;
                }
            }
            // Affichage de l'image
            $pdf->Image(eval_ccpc_genGraphRadar($tempData), 10, $pdf->getY() + 40, floor(0.4 * $A4Height), 0, 'PNG');
            // On affiche le radar sur la période du stage
            // On décale du 0.05*largeur
            $pdf->Cell(floor(0.05 * $A4Height));
            // On crée un rectangle contenant les données
            $pdf->Rect($pdf->getX(), $pdf->getY() - 10, 0.5 * $A4Height, 0.3 * $A4Height, 'F');
            // Titre
            $pdf->Cell(floor(0.5 * $A4Height), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_STAGEPERIODE_START . ' ' . date('d/m/Y', $data['service']['date']['min']) . ' ' . LANG_FORM_CCPC_PDF_STAGEPERIODE_END . ' ' . date('d/m/Y', $data['service']['date']['max'])), 0, 0, 'C', FALSE);
            // On ajoute l'image
            // Liste des valeurs à afficher
            $input = $form->xpath('categorie/input[@radarPDFGraph="1"]');
            // Préparation des données
            $tempData = array();
            $tempData['settings'] = array('height' => 380, 'width' => 650, 'max' => 10);
            foreach ($input as $theinput) {
                // Récupération du parent
                $categorie = $theinput->xpath('..')[0];
                // Catégorie du graphique
                if (isset($data[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'])) {
                    $tempData['data'][constant($theinput['label'] . '_SHORT')] = $data[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'] + 5;
                }
            }
            // Affichage de l'image
            $pdf->Image(eval_ccpc_genGraphRadar($tempData), $pdf->getX() - 0.45 * $A4Height, $pdf->getY() + 40, floor(0.4 * $A4Height), 0, 'PNG');
            // Affiche du logo
            $pdf->Image(ROOT . 'theme/img/logo.png', 10, $A4Width - 100, 0, 50, 'PNG');
            // Pied de Page
            $pdf->SetX(0.5 * $A4Height);
            $pdf->SetY($A4Width - 40);
            $textSize = 10;
            $pdf->SetFont('Arial', 'I', $textSize);
            // Ligne de demarcation
            $pdf->Line(15, $pdf->getY(), $A4Height - 15, $pdf->getY());
            // Accès aux résultats
            $pdf->SetX(0.5 * $A4Height);
            $pdf->Cell(0.5 * $A4Height - 15, $textSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_FOOTER_FULLRESULT . ' ' . getPageUrl('evalView', array('evaluationType' => 1, 'service' => $data['service']['id']))), 0, 1, 'R', 0);
            // Coordonées CSG
            if ($commentMSG) {
                $pdf->SetFont('Arial', 'B', $textSize);
                $pdf->SetX(15);
                $pdf->Cell($A4Height - 15, $textSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_FOOTER_STRUCTURENAME . ' - ' . CONTACT_STAGE_MAIL), 0, 0, 'C', 0);
            }
            /**
            							Commentaires
            						**/
            // Ajout des commentaires, points positifs et points négatifs : 'pdfComment'
            if ($comment) {
                $pdf->addPage('P', 'A4');
                // Titre
                $pdf->SetFont('Arial', 'B', $titleSize);
                $pdf->SetFillColor(70, 70, 242);
                $pdf->SetTextColor(255, 255, 255);
                $pdf->SetX(floor(0.1 * $A4Width));
                $pdf->Cell(floor(0.8 * $A4Width), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_COMMENT_TITLE), 'LRTB', 1, 'C', TRUE);
                $pdf->SetTextColor(0, 0, 0);
                $pdf->SetFillColor(245, 245, 245);
                // Les commentaires
                $input = $form->xpath('categorie/input[@pdfComment="1"]');
                foreach ($input as $theinput) {
                    $categorie = $theinput->xpath('..')[0];
                    if ($theinput['type'] == 'text') {
                        $textArea = '';
                        $firstLoop = TRUE;
                        foreach ($theinput->text as $text) {
                            if (isset($data[(string) $categorie['nom']][(string) $text['nomBDD']])) {
                                foreach ($data[(string) $categorie['nom']][(string) $text['nomBDD']] as $comment) {
                                    if ($comment != '') {
                                        if (!$firstLoop) {
                                            $textArea .= PHP_EOL . PHP_EOL;
                                        } else {
                                            $firstLoop = FALSE;
                                        }
                                        // Saut de ligne
                                        $textArea .= $comment;
                                    }
                                }
                            }
                        }
                        if ($textArea != '') {
                            // On affiche les textes dans le PDF
                            $pdf->Ln(20);
                            $pdf->SetX(20);
                            $pdf->setFont('Arial', '', $titleSize);
                            $pdf->Cell(0, $titleSize + 5, utf8_decode(constant($theinput['label'] . '_SHORT')), 0, 1, 'L', FALSE);
                            $pdf->setFont('Arial', '', $textSize);
                            $pdf->SetX(20);
                            $pdf->MultiCell($A4Width - 40, $textSize + 5, utf8_decode($textArea), 'LTRB', 'L', TRUE);
                        }
                    } else {
                        if ($theinput['type'] == 'textarea') {
                            $textArea = '';
                            $firstLoop = TRUE;
                            if (isset($data[(string) $categorie['nom']][(string) $theinput['nomBDD']])) {
                                foreach ($data[(string) $categorie['nom']][(string) $theinput['nomBDD']] as $comment) {
                                    if (!$firstLoop) {
                                        $textArea .= PHP_EOL . PHP_EOL;
                                    } else {
                                        $firstLoop = FALSE;
                                    }
                                    // Saut de ligne
                                    $textArea .= $comment;
                                }
                            }
                            if ($textArea != '') {
                                // On affiche les textes dans le PDF
                                $pdf->Ln(20);
                                $pdf->SetX(20);
                                $pdf->setFont('Arial', '', $titleSize);
                                $pdf->Cell(0 * $A4Width, $titleSize + 5, utf8_decode(constant($theinput['label'] . '_SHORT')), 0, 1, 'L', FALSE);
                                $pdf->setFont('Arial', '', $textSize);
                                $pdf->SetX(20);
                                $pdf->MultiCell($A4Width - 40, $textSize + 5, utf8_decode($textArea), 'LTRB', 'L', TRUE);
                            }
                        }
                    }
                }
            }
            // On retourne le fichier PDF
            $pdf->Output($pdfPath, 'F');
            $output['pdfPath'] = $pdfPath;
            $output['pdfURI'] = $pdfPathURI;
            return $output;
        }
        exit;
    } else {
        return FALSE;
    }
}
/**
 * generatePDF - Génère un fichier PDF à partir des données d'évaluation d'un service
 *
 * @category : eval_ccpc_functions
 * @param array $data Données d'évaluation récupérées à partir de la fonction {@link getEvaluationCCPCFullData()}
 * @param boolean $comment TRUE si on incut les commentaire, FALSE si on ne les inclut pas
 * @param boolean $commentMSG TRUE si on incut un message concernant la CSG, FALSE si on ne l'inclut pas
 * @return array Array contenant les informations du fichier généré
 *
 * @Author Ali Bellamine
 *
 * Contenu de l'array retourné :<br>
 * 	['pdfPath'] => (string) Chemin local vers le fichier généré<br>
 * 	['pdfURI'] => (string) URI pointant vers le fichier généré
 *
 */
function generatePDF($data, $comment = FALSE, $commentMSG = FALSE)
{
    // Accès à la BDD
    global $db;
    // Array contenant les résultats
    $output = array();
    // On vérifie l'existence des données
    if (isset($data) && count($data) > 0) {
        /* 
        	Mise en cache
        */
        // Calcul du md5
        $hashdata = $data;
        $hashdata['optionsPDF'] = array('comment' => $comment, 'commentMSG' => $commentMSG);
        $hash = md5(json_encode($hashdata));
        $pdfPath = PLUGIN_PATH . 'cache/' . $hash . '.pdf';
        $pdfPathURI = ROOT . 'evaluations/ccpc/cache/' . $hash . '.pdf';
        if (is_file($pdfPath)) {
            $output['pdfPath'] = $pdfPath;
            $output['pdfURI'] = $pdfPathURI;
            return $output;
        } else {
            // On charge la librairie
            require_once PLUGIN_PATH . 'core/fpdf17/fpdf.php';
            // On charge le fichier XML
            if (is_file(PLUGIN_PATH . 'formulaire.xml')) {
                $form = simplexml_load_file(PLUGIN_PATH . 'formulaire.xml');
            }
            // Promotion
            if (count($data['service']['promotion']) > 1) {
                $promotion = false;
            } else {
                foreach ($data['service']['promotion'] as $promotionData) {
                    $promotion = $promotionData['id'];
                }
            }
            try {
                ob_end_clean();
            } catch (Exception $e) {
            }
            // On crée le PDF
            $A4Height = 842;
            $A4Width = 595;
            $titleSize = 15;
            $textSize = 11;
            $pdf = new FPDF('L', 'pt', 'A4');
            $pdf->SetTopMargin(10);
            $pdf->SetLeftMargin(15);
            $pdf->SetAutoPageBreak(TRUE, 10);
            /**
            						Page contenant le résumé des données d'évaluation
            					**/
            $pdf->AddPage();
            $pdf->SetFont('Arial', 'B', $titleSize);
            // On affiche le titre
            $pdf->SetFillColor(70, 70, 242);
            $pdf->SetTextColor(255, 255, 255);
            $pdf->SetX(floor(0.1 * $A4Height));
            $pdf->Cell(floor(0.8 * $A4Height), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_TITLE), 'LRTB', 0, 'C', TRUE);
            // Première ligne
            $pdf->Ln(2 * $titleSize);
            $pdf->SetFont('Arial', '', $textSize);
            // On affiche les informations concernant le service
            // Récupération des données
            $textToDisplay = LANG_FORM_CCPC_FILTER_SERVICE_TITLE . ' : ' . $data['service']['FullName'] . PHP_EOL . LANG_FORM_CCPC_PDF_STAGEPERIODE . ' : ' . date('d/m/Y', $data['service']['date']['min']) . ' - ' . date('d/m/Y', $data['service']['date']['max']);
            // Nombre d'étudiants par promotion
            $nbEtudiantsService = array();
            $sql = 'SELECT p.nom promotion, COUNT( ae.userId ) nombre
												FROM `affectationexterne` ae
												INNER JOIN user u ON u.id = ae.userId
												INNER JOIN promotion p ON p.id = u.promotion
												WHERE `dateDebut` >= "' . TimestampToDatetime($data['service']['date']['min']) . '" AND `dateFin` <= "' . TimestampToDatetime($data['service']['date']['max']) . '" AND service = ' . $data['service']['id'] . '
												GROUP BY u.promotion';
            $res = $db->query($sql);
            while ($res_f = $res->fetch()) {
                $nbEtudiantsService[$res_f['promotion']] = $res_f['nombre'];
            }
            $firstLoop = true;
            if (count($nbEtudiantsService) > 0) {
                $textToDisplay .= PHP_EOL . LANG_FORM_CCPC_PDF_STUDENTPROMOTION . ' : ';
                foreach ($nbEtudiantsService as $promotionNom => $promotionNombre) {
                    if (!$firstLoop) {
                        $textToDisplay .= ', ';
                    } else {
                        $firstLoop = FALSE;
                    }
                    $textToDisplay .= $promotionNom . ' (' . $promotionNombre . ')';
                }
            }
            $textToDisplay .= PHP_EOL . LANG_FORM_CCPC_PDF_STUDENTNB . ' : ' . $data['service']['nbEvaluation'] . PHP_EOL . LANG_FORM_CCPC_PDF_EVALUATIONNB . ' : ' . $data['nb'];
            $textToDisplay = utf8_decode($textToDisplay);
            // Affichage
            $pdf->SetFillColor(231, 231, 231);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->MultiCell(floor(0.35 * $A4Height), $textSize + 5, $textToDisplay, 'LRTB', 'L', TRUE);
            // On affiche les graphiques : mainGraphPDF
            // Récupération des données
            // Liste des graphiques à afficher
            $input = $form->xpath('categorie/input[@mainPDFGraph="1"]');
            $nbGraph = count($input);
            // Nombre de graphiques à intégrer
            // On génère $tempData, contenant les données utilisées pour génération du png
            foreach ($input as $select) {
                if ($select['type'] == 'select') {
                    $categorie = $select->xpath('..')[0];
                    // Catégorie du graphique
                    $tempData = array();
                    $tempData['settings'] = array('width' => 450, 'height' => 230);
                    foreach ($select->option as $option) {
                        if (isset($data[(string) $categorie['nom']][(string) $select['nomBDD']]['nb'][(string) $option['value']])) {
                            $value = $data[(string) $categorie['nom']][(string) $select['nomBDD']]['nb'][(string) $option['value']];
                            if (is_numeric($value)) {
                                $tempData['data'][constant((string) $option['text'])] = $value;
                            } else {
                                $tempData['data'][constant((string) $option['text'])] = 0;
                            }
                        } else {
                            $tempData['data'][constant((string) $option['text'])] = 0;
                        }
                    }
                    // On inclut l'image
                    $pdf->Image(eval_ccpc_genGraphPie($tempData), 0.4 * $A4Height, 3 * $titleSize, floor(0.4 * $A4Height), 0, 'PNG');
                    break;
                }
            }
            // On affiche l'icone des filtres : maximum 4
            $filtres = eval_ccpc_checkFilterExistence($data['service']['id'], $data['service']['date']['min'], $data['service']['date']['max'], $promotion);
            $numberOfIcons = 0;
            // Compte le nombre d'icones ajoutées
            $leftCornerX = 0.8 * $A4Height - 5;
            $leftCornerY = 3 * $titleSize - 5;
            if (is_array($filtres)) {
                foreach ($filtres as $filtre) {
                    if (isset($filtre['icone']) && strlen($filtre['icone']) > 1 && $numberOfIcons < 4) {
                        $pdf->Image($filtre['icone'], $leftCornerX, $leftCornerY, floor(0.1 * $A4Height), 0, 'PNG');
                        $numberOfIcons++;
                        if ($numberOfIcons == 1) {
                            $leftCornerX = 0.9 * $A4Height - 3;
                        } else {
                            if ($numberOfIcons == 2) {
                                $leftCornerX = 0.8 * $A4Height - 5;
                                $leftCornerY += 0.1 * $A4Height + 1;
                            } else {
                                if ($numberOfIcons == 3) {
                                    $leftCornerX = 0.9 * $A4Height - 3;
                                }
                            }
                        }
                        break;
                    }
                }
            }
            if ($numberOfIcons == 0) {
                // On ajoute l'icone neutre si aucune icone n'est présente
                $pdf->Image(PLUGIN_PATH . '/css/img/neutral.png', $leftCornerX, $leftCornerY, floor(0.1 * $A4Height), 0, 'PNG');
            }
            // Deuxième ligne
            $pdf->Ln(8 * $titleSize);
            // On affiche le radar sur 1 an de données
            $fullYearData = getEvaluationCCPCFullData($data['service']['id'], $promotion, $data['service']['date']['max'] - 31536000, $data['service']['date']['max'], FALSE);
            // Récupération des données
            // Titre
            $pdf->Cell(floor(0.4 * $A4Height), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_STAGEPERIODE_FULLYEAR . ' (' . date('d/m/Y', $fullYearData['service']['date']['min']) . ' ' . LANG_FORM_CCPC_PDF_STAGEPERIODE_END . ' ' . date('d/m/Y', $fullYearData['service']['date']['max']) . ')'), 0, 0, 'C', FALSE);
            // On affiche l'image
            // Liste des valeurs à afficher
            $input = $form->xpath('categorie/input[@radarPDFGraph="1"]');
            // Préparation des données
            $tempData = array();
            $tempData['settings'] = array('height' => 380, 'width' => 680, 'max' => 10);
            foreach ($input as $theinput) {
                // Récupération du parent
                $categorie = $theinput->xpath('..')[0];
                // Catégorie du graphique
                if (isset($data[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'])) {
                    $tempData['data'][constant($theinput['label'] . '_SHORT')] = $fullYearData[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'] + 5;
                }
            }
            // Affichage de l'image
            $pdf->Image(eval_ccpc_genGraphRadar($tempData), 10, $pdf->getY() + 40, floor(0.4 * $A4Height), 0, 'PNG');
            // On affiche le radar sur la période du stage
            // On décale du 0.05*largeur
            $pdf->Cell(floor(0.05 * $A4Height));
            // On crée un rectangle contenant les données
            $pdf->Rect($pdf->getX(), $pdf->getY() - 10, 0.5 * $A4Height, 0.3 * $A4Height, 'F');
            // Titre
            $pdf->Cell(floor(0.5 * $A4Height), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_STAGEPERIODE_START . ' ' . date('d/m/Y', $data['service']['date']['min']) . ' ' . LANG_FORM_CCPC_PDF_STAGEPERIODE_END . ' ' . date('d/m/Y', $data['service']['date']['max'])), 0, 0, 'C', FALSE);
            // On ajoute l'image
            // Liste des valeurs à afficher
            $input = $form->xpath('categorie/input[@radarPDFGraph="1"]');
            // Préparation des données
            $tempData = array();
            $tempData['settings'] = array('height' => 380, 'width' => 650, 'max' => 10);
            foreach ($input as $theinput) {
                // Récupération du parent
                $categorie = $theinput->xpath('..')[0];
                // Catégorie du graphique
                if (isset($data[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'])) {
                    $tempData['data'][constant($theinput['label'] . '_SHORT')] = $data[(string) $categorie['nom']][(string) $theinput['nomBDD']]['moyenne'] + 5;
                }
            }
            // Affichage de l'image
            $pdf->Image(eval_ccpc_genGraphRadar($tempData), $pdf->getX() - 0.45 * $A4Height, $pdf->getY() + 40, floor(0.4 * $A4Height), 0, 'PNG');
            // Affiche du logo
            $pdf->Image(ROOT . 'theme/img/logo.png', 10, $A4Width - 100, 0, 50, 'PNG');
            // Pied de Page
            $pdf->SetX(0.5 * $A4Height);
            $pdf->SetY($A4Width - 40);
            $textSize = 10;
            $pdf->SetFont('Arial', 'I', $textSize);
            // Ligne de demarcation
            $pdf->Line(15, $pdf->getY(), $A4Height - 15, $pdf->getY());
            // Accès aux résultats
            $pdf->SetX(0.5 * $A4Height);
            $pdf->Cell(0.5 * $A4Height - 15, $textSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_FOOTER_FULLRESULT . ' ' . getPageUrl('evalView', array('evaluationType' => 1, 'service' => $data['service']['id']))), 0, 1, 'R', 0);
            // Coordonées CSG
            if ($commentMSG) {
                $pdf->SetFont('Arial', 'B', $textSize);
                $pdf->SetX(15);
                $pdf->Cell($A4Height - 15, $textSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_FOOTER_STRUCTURENAME . ' - ' . CONTACT_STAGE_MAIL), 0, 0, 'C', 0);
            }
            /**
            							Commentaires
            						**/
            // Ajout des commentaires, points positifs et points négatifs : 'pdfComment'
            if ($comment) {
                $pdf->addPage('P', 'A4');
                // Titre
                $pdf->SetFont('Arial', 'B', $titleSize);
                $pdf->SetFillColor(70, 70, 242);
                $pdf->SetTextColor(255, 255, 255);
                $pdf->SetX(floor(0.1 * $A4Width));
                $pdf->Cell(floor(0.8 * $A4Width), $titleSize + 5, utf8_decode(LANG_FORM_CCPC_PDF_COMMENT_TITLE), 'LRTB', 1, 'C', TRUE);
                $pdf->SetTextColor(0, 0, 0);
                $pdf->SetFillColor(245, 245, 245);
                // Les commentaires
                $input = $form->xpath('categorie/input[@pdfComment="1"]');
                foreach ($input as $theinput) {
                    $categorie = $theinput->xpath('..')[0];
                    if ($theinput['type'] == 'text') {
                        // Création de l'array contenant les données à afficher sous forme [timestamp fin][timestamp début][timestamp commantaire][idMessage][] => message
                        $tempData = array();
                        foreach ($theinput->text as $value) {
                            if (isset($data[(string) $categorie['nom']][(string) $value['nomBDD']])) {
                                foreach ($data[(string) $categorie['nom']][(string) $value['nomBDD']] as $idEval => $textValue) {
                                    if (isset($data['donnees'][$idEval]['infos'])) {
                                        $tempData[$data['donnees'][$idEval]['infos']['dateFin']][$data['donnees'][$idEval]['infos']['dateDebut']][$data['donnees'][$idEval]['infos']['date']][$idEval][] = $textValue;
                                    }
                                }
                            }
                        }
                        $textArea = '';
                        $firstLoop = TRUE;
                        // On affiche les commentaires
                        krsort($tempData);
                        foreach ($tempData as $dateFin => $tempvalue) {
                            krsort($tempvalue);
                            foreach ($tempvalue as $dateDebut => $value2) {
                                krsort($value2);
                                foreach ($value2 as $date => $value3) {
                                    foreach ($value3 as $commentId => $comments) {
                                        foreach ($comments as $comment) {
                                            if ($comment != '') {
                                                if (!$firstLoop) {
                                                    $textArea .= PHP_EOL . PHP_EOL;
                                                } else {
                                                    $firstLoop = FALSE;
                                                }
                                                // Saut de ligne
                                                $textArea .= $comment . ' - ' . date('d/m/Y', $date) . ' #' . $commentId;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if ($textArea != '') {
                            // On affiche les textes dans le PDF
                            $pdf->Ln(20);
                            $pdf->SetX(20);
                            $pdf->setFont('Arial', '', $titleSize);
                            $pdf->Cell(0, $titleSize + 5, utf8_decode(constant($theinput['label'] . '_SHORT')), 0, 1, 'L', FALSE);
                            $pdf->setFont('Arial', '', $textSize);
                            $pdf->SetX(20);
                            $pdf->MultiCell($A4Width - 40, $textSize + 5, utf8_decode($textArea), 'LTRB', 'L', TRUE);
                        }
                    } else {
                        if ($theinput['type'] == 'textarea') {
                            // Création de l'array contenant les données à afficher sous forme [timestamp fin][timestamp début][timestamp commantaire][idCommentaire] => commentaire
                            $tempData = array();
                            foreach ($data[(string) $categorie['nom']][(string) $theinput['nomBDD']] as $commentId => $commentData) {
                                if (isset($data['donnees'][$commentId]['infos'])) {
                                    $tempData[$data['donnees'][$commentId]['infos']['dateFin']][$data['donnees'][$commentId]['infos']['dateDebut']][$data['donnees'][$commentId]['infos']['date']][$commentId] = $commentData;
                                }
                            }
                            $textArea = '';
                            $firstLoop = TRUE;
                            // On affiche les commentaires
                            krsort($tempData);
                            foreach ($tempData as $dateFin => $tempvalue) {
                                krsort($tempvalue);
                                foreach ($tempvalue as $dateDebut => $value2) {
                                    krsort($value2);
                                    foreach ($value2 as $date => $value3) {
                                        foreach ($value3 as $commentId => $comment) {
                                            if ($comment != '') {
                                                if (!$firstLoop) {
                                                    $textArea .= PHP_EOL . PHP_EOL;
                                                } else {
                                                    $firstLoop = FALSE;
                                                }
                                                // Saut de ligne
                                                $textArea .= $comment . ' - ' . date('d/m/Y', $date) . ' #' . $commentId;
                                            }
                                        }
                                    }
                                }
                            }
                            if ($textArea != '') {
                                // On affiche les textes dans le PDF
                                $pdf->Ln(20);
                                $pdf->SetX(20);
                                $pdf->setFont('Arial', '', $titleSize);
                                $pdf->Cell(0 * $A4Width, $titleSize + 5, utf8_decode(constant($theinput['label'] . '_SHORT')), 0, 1, 'L', FALSE);
                                $pdf->setFont('Arial', '', $textSize);
                                $pdf->SetX(20);
                                $pdf->MultiCell($A4Width - 40, $textSize + 5, utf8_decode($textArea), 'LTRB', 'L', TRUE);
                            }
                        }
                    }
                }
            }
            // On retourne le fichier PDF
            $pdf->Output($pdfPath, 'F');
            $output['pdfPath'] = $pdfPath;
            $output['pdfURI'] = $pdfPathURI;
            return $output;
        }
        exit;
    } else {
        return FALSE;
    }
}
Example #3
0
                                    foreach ($input->option as $key => $value) {
                                        if (isset($evaluation['nb'][(string) $value['value']])) {
                                            $tempData['data'][constant((string) $value['text'])] = $evaluation['nb'][(string) $value['value']];
                                        } else {
                                            $tempData['data'][constant((string) $value['text'])] = 0;
                                        }
                                    }
                                    $tempData['settings'] = array('height' => 220, 'width' => 300);
                                    ?>
												<div class = "EvaluationData">
													<h2><?php 
                                    echo constant($input['label'] . '_SHORT');
                                    ?>
</h2>
													<img src = "<?php 
                                    echo eval_ccpc_genGraphPie($tempData);
                                    ?>
" />
												</div>
												<?php 
                                } else {
                                    if ($inputName == 'radio') {
                                        $tempData = array();
                                        // Création de l'array permettant la génération du graphique
                                        $tempData['settings'] = array('height' => 210, 'width' => 300);
                                        ?>
												<div class = "EvaluationData">
													<?php 
                                        if (isset($input['label'])) {
                                            ?>
														<h2><?php