Ejemplo n.º 1
0
/**
 * eval_ccpc_applyFilter - Test l'ensemble des requêtes pour un service, et enregistre les filtres qui s'y appliquent dans la base de donnée
 *
 * @category : eval_ccpc_functions
 * @param int $id Identifiant du service
 * @param int $promotion Identifiant de la promotion pour laquelle les données seront restreinte si le filtre presente une restriction de promotion
 * @param string $debutStage Borne inférieur de l'intervalle temporel considéré, sous forme de timestamp
 * @param string $finStage Borne supérieure de l'intervalle temporel considéré, sous forme de timestamp
 * @return boolean TRUE si l'opération s'est déroulée avec succès, FALSE sinon
 * 
 * @Author Ali Bellamine
 *
 */
function eval_ccpc_applyFilter($id, $promotion, $dateDebut, $dateFin)
{
    /**
    					Prépare les variables
    				**/
    // Base de donnée
    global $db;
    // Objet XML du formulaire d'évaluation
    if (is_file(PLUGIN_PATH . 'formulaire.xml')) {
        $form = simplexml_load_file(PLUGIN_PATH . 'formulaire.xml');
    }
    // Liste des filtres
    $filtres = eval_ccpc_getFilterList();
    // Données d'évaluation
    // Pour la promotion
    $dataPromo = getEvaluationCCPCFullData($id, $promotion, $dateDebut, $dateFin, FALSE);
    // Sans la promotion (toutes les promotions)
    $dataAllPromo = getEvaluationCCPCFullData($id, FALSE, $dateDebut, $dateFin, FALSE);
    if (!isset($form)) {
        return FALSE;
    }
    /**
    					Effectue les test
    				**/
    foreach ($filtres as $filtre) {
        $res = FALSE;
        if ($filtre['promotion'] == 0) {
            $res = eval_ccpc_exploreQuery($filtre['query'], $form, $dataAllPromo);
        } else {
            $res = eval_ccpc_exploreQuery($filtre['query'], $form, $dataPromo);
        }
        // Si le filtre est vérifié
        if ($res == 'success') {
            /*
            	On enregistre le succès dans la BDD si il n'est pas déjà présent
            */
            $sqlData = array('service' => $id, 'filtre' => $filtre['id'], 'dateDebut' => TimestampToDatetime($dateDebut), 'dateFin' => TimestampToDatetime($dateFin));
            // On vérifie si il est déjà présent
            if ($filtre['promotion'] == 0) {
                $sql = 'SELECT count(*) FROM eval_ccpc_filtres_detected WHERE id_service = :service AND id_filtre = :filtre AND debutStage = :dateDebut AND finStage = :dateFin LIMIT 1';
            } else {
                $sql = 'SELECT count(*) FROM eval_ccpc_filtres_detected WHERE id_service = :service AND id_filtre = :filtre AND debutStage = :dateDebut AND finStage = :dateFin AND promotion = :promotion LIMIT 1';
                $sqlData['promotion'] = $promotion;
            }
            $res = $db->prepare($sql);
            $res->execute($sqlData);
            if ($res_f = $res->fetch()) {
                if ($res_f[0] == 0) {
                    // On insert dans la base de donnée
                    $sqlData['promotion'] = $promotion;
                    // Dans tous les cas on enregistre la promotion
                    $sql = 'INSERT INTO eval_ccpc_filtres_detected (id_service, id_filtre, debutStage, finStage, promotion) VALUES (:service, :filtre, :dateDebut, :dateFin, :promotion)';
                    $res = $db->prepare($sql);
                    $res->execute($sqlData);
                }
            }
        } else {
            // On le supprime de la BDD si il est présent
            $sqlData = array('service' => $id, 'filtre' => $filtre['id'], 'dateDebut' => TimestampToDatetime($dateDebut), 'dateFin' => TimestampToDatetime($dateFin));
            if ($filtre['promotion'] == 0) {
                $sql = 'DELETE FROM eval_ccpc_filtres_detected WHERE id_service = :service AND id_filtre = :filtre AND debutStage = :dateDebut AND finStage = :dateFin LIMIT 1';
            } else {
                $sql = 'DELETE FROM eval_ccpc_filtres_detected WHERE id_service = :service AND id_filtre = :filtre AND debutStage = :dateDebut AND finStage = :dateFin AND promotion = :promotion LIMIT 1';
                $sqlData['promotion'] = $promotion;
            }
            $res = $db->prepare($sql);
            $res->execute($sqlData);
        }
    }
}
Ejemplo n.º 2
0
    if (!isset($settings['message'])) {
        $settings['message'] = LANG_FORM_CCPC_ADMIN_MAILER_DEFAULT_MESSAGE;
    }
    $getArray = array('evaluationType' => $_GET['evaluationType'], 'service' => $_POST['service'], 'FILTER' => array('date' => array('min' => $_POST['debutStage'], 'max' => $_POST['finStage']), 'promotion' => $_POST['promotion']));
    // Tableau contenant les équivalents texte codé => variable
    $textCode = array('%DATEDEBUT%' => date('d/m/Y', $_POST['debutStage']), '%DATEFIN%' => date('d/m/Y', $_POST['finStage']), '%PROMOTION%' => $promotionData['nom'], '%URL%' => getPageUrl('evalView', $getArray), '%MAILCONTACT%' => CONTACT_STAGE_MAIL);
    // On remplace les codes %CODE% par les variables correspondante
    foreach ($textCode as $key => $value) {
        // Pour l'objet
        $settings['object'] = str_replace($key, $value, $settings['object']);
        // Pour le message
        $settings['message'] = str_replace($key, $value, $settings['message']);
    }
    // Pièce jointe
    // On génère le PDF
    $pdfPath = generatePDF(getEvaluationCCPCFullData($_POST['service'], $_POST['promotion'], $_POST['debutStage'], $_POST['finStage'], TRUE), FALSE, TRUE)['pdfPath'];
    if (!file_exists(PLUGIN_PATH . 'attachments/' . $_POST['codeCampagne'] . ' - ' . basename($pdfPath)) || !is_file(PLUGIN_PATH . 'attachments/' . $_POST['codeCampagne'] . ' - ' . basename($pdfPath))) {
        copy($pdfPath, PLUGIN_PATH . 'attachments/' . $_POST['codeCampagne'] . ' - ' . basename($pdfPath));
    }
    $attachments = array('Evaluations.pdf' => array('path' => PLUGIN_PATH . 'attachments/' . $_POST['codeCampagne'] . ' - ' . basename($pdfPath), 'url' => ROOT . 'evaluations/ccpc/attachments/' . $_POST['codeCampagne'] . ' - ' . basename($pdfPath)));
    // Destinataire
    $chefId = getServiceInfo($_POST['service'])['chef']['id'];
    // On crée le mail
    addMailCampagne($_POST['codeCampagne'], $title, $chefId, $settings['object'], $settings['message'], $attachments);
    exit;
} else {
    if ($action == 'setMail') {
        // On enregistre les données du formulaire après les avoir sérialisé dans la table typeevaluation pour le module correspondant
        if (isset($_POST['object']) && htmLawed($_POST['object']) && isset($_POST['message']) && htmLawed($_POST['message'])) {
            $res = $db->prepare('UPDATE typeevaluation SET settings = :settings WHERE id = :id');
            $res->execute(array('id' => $evaluationTypeData['id'], 'settings' => serialize($_POST)));
Ejemplo n.º 3
0
/**
 * 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;
    }
}
Ejemplo n.º 4
0
/**
 * 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;
    }
}
Ejemplo n.º 5
0
} else {
    $dateDebut = $filtres['dateMin'];
    $dateFin = $filtres['dateMax'];
    $promotion = false;
}
if ($_SESSION['rang'] >= 3) {
    $moderate = TRUE;
    // Les administrateurs peuvent voir les messages modérés
} else {
    $moderate = FALSE;
}
/**
		Récupération des informations concernant le service
		**/
if ($evaluationContentType == 'stat' || $evaluationContentType == 'data') {
    $evaluationData = getEvaluationCCPCFullData($_GET['service'], $promotion, $dateDebut, $dateFin, $moderate);
} else {
    if ($evaluationContentType == 'history') {
        $evaluationData['evaluations'] = array();
        // Array qui contiendra toutes les données
        $listeDate = listeMoisEntreDeuxDates($dateDebut, $dateFin);
        // Liste des dates d'évaluations dispo dans l'intervalle temporel choisit par l'utilisateur
        foreach ($listeDate as $dateKey => $date) {
            $tempEvaluationData = getEvaluationCCPCPartialData($_GET['service'], $promotion, $dateDebut, strtotime($date['Annee'] . '-' . $date['MoisNb'] . '-01 +1 month') - 1);
            // On récupère les données à la date choisie
            /**
            					On stocke les informations concernant le service
            				**/
            if (!isset($evaluationData['service'])) {
                $evaluationData['service'] = $tempEvaluationData['service'];
            }
Ejemplo n.º 6
0
 $allowedJoin['none'] = FALSE;
 // Pour le PDF
 if (isset($_POST['pdfJoin']) && isset($allowedJoin[$_POST['pdfJoin']]) && ($_POST['pdfJoin'] == 'none' || $allowedJoin[$_POST['pdfJoin']]['type'] == 'PDF')) {
     if ($_POST['pdfJoin'] != 'none') {
         foreach ($filtreData['detected'][$_GET['dateFin']][$_GET['dateDebut']] as $serviceDetected) {
             $_SESSION['sendMail']['settings']['pdf'] = generatePDF(getEvaluationCCPCFullData($serviceDetected['service']['id'], $serviceDetected['promotion'], $_GET['dateDebut'], $_GET['dateFin'], $allowedJoin[$_POST['pdfJoin']]['moderation']), $allowedJoin[$_POST['pdfJoin']]['comment'], TRUE)['pdfPath'];
         }
     }
 } else {
     $erreur['LANG_ERROR_CCPC_UNKNOWN'] = TRUE;
 }
 // Pour le CSV
 if (isset($_POST['csvJoin']) && isset($allowedJoin[$_POST['csvJoin']]) && ($_POST['csvJoin'] == 'none' || $allowedJoin[$_POST['csvJoin']]['type'] == 'CSV')) {
     if ($_POST['csvJoin'] != 'none') {
         foreach ($filtreData['detected'][$_GET['dateFin']][$_GET['dateDebut']] as $serviceDetected) {
             $_SESSION['sendMail']['settings']['csv'] = generateCSV(getEvaluationCCPCFullData($serviceDetected['service']['id'], $serviceDetected['promotion'], $_GET['dateDebut'], $_GET['dateFin'], $allowedJoin[$_POST['csvJoin']]['moderation']), TRUE)['csvPath'];
         }
     }
 } else {
     $erreur['LANG_ERROR_CCPC_UNKNOWN'] = TRUE;
 }
 /**
 				Liste des messages à envoyer
 			**/
 if (count($erreur) == 0) {
     foreach ($filtreData['detected'][$_GET['dateFin']][$_GET['dateDebut']] as $serviceDetected) {
         $serviceData = getServiceInfo($serviceDetected['service']['id']);
         $chefData = getUserData($serviceData['chef']['id']);
         $_SESSION['sendMail']['current'][$chefData['id']] = $chefData;
         // On ajoute les envoie à faire dans current
     }