$amt = $row['amt'];
     $account_type = $row['account_type'];
     $linedesc = $row['linedesc'];
     if ($account_type == 4) {
         $paymentmethodtext = "Cheque :";
     } else {
         $paymentmethodtext = "Cash";
     }
     if ($m > 13) {
         $m = 1;
         $pdf->AddPage($pdf->CurOrientation);
     }
     $pdf->SetX($xmargin);
     $pdf->Cell(10, 4, $i, 0, 0, 'C');
     $currentx = $pdf->getX();
     $currenty = $pdf->getY();
     $pdf->Cell(120, 4, $subject, 0, 0, 'L');
     if ($linedesc != "") {
         $pdf->SetXY($currentx, $currenty + 5);
         $pdf->MultiCell(0, 4, "{$linedesc}", "0", 'L');
         //$pdf->Cell(40,4,$paymentmethodtext,0,0,'L');
         $maxy = $pdf->getY();
     } else {
         $maxy = $pdf->getY() + 2;
     }
     $pdf->SetXY($currentx + 120, $currenty);
     $pdf->Cell(0, 4, $amt, 0, 1, 'R');
 }
 //paymentvoucher AMT number in block (9)
 $pdf->SetXY($xmargin, 120 + 5);
 $pdf->SetFont("Times", "", 14);
示例#2
0
$pdf->SetFont('Courier', 'B', 14);
$pdf->Cell(55, 2, '', 0, 1);
$pdf->Cell(5, 10, '', 0, 0);
//$pdf->Cell(50,10,strtoupper($pmb[Nama]),0,1);
$pdf->MultiCell(50, 5, $pmb['Nama'], 0);
$pdf->Cell(55, 1, '', 0, 1);
$pdf->SetFont('Arial', '', 6);
$pdf->Cell(55, 4, 'NAMA', 0, 1);
$pdf->SetFont('Courier', 'B', 14);
$pdf->Cell(5, 10, '', 0, 0);
$pdf->Cell(50, 10, $ProdiNama['Nama'], 0, 1);
$pdf->SetFont('Arial', '', 6);
$pdf->Cell(55, 4, 'PROGRAM STUDI', 0, 1);
$ImagePath = GetaField('mhsw', "MhswID='{$pmb['MhswID']}' and KodeID", KodeID, "Foto");
if (empty($ImagePath)) {
    $pdf->SetXY($pdf->getX() + 60, $pdf->getY() - 40);
    $pdf->Cell(30, 40, 'FOTO', 1, 1, 'C');
} else {
    $pdf->Image('../' . $ImagePath, $pdf->getX() + 60, $pdf->getY() - 40, 30, 40);
}
$pdf->SetFont('Arial', '', 7);
$pdf->SetXY(110, 10);
$pdf->Cell(90, 5, "* Kartu Mahasiswa ini wajib dibawa untuk setiap kegiatan PMB di Kampus", 0, 1);
$pdf->SetX(110);
$pdf->Cell(90, 5, "* Kartu Mahasiswa ini berlaku selama Mahasiswa aktif atau dalam masa", 0, 1);
$pdf->SetX(110);
$pdf->Cell(90, 5, "  berlaku kartu", 0, 1);
$pdf->SetX(110);
$pdf->Cell(90, 5, "* Apabila kartu Mahasiswa ini hilang agar melapor ke Bag. Akademik dan", 0, 1);
$pdf->SetX(110);
$pdf->Cell(90, 5, "  dikenai biaya pembuatan kartu sebesar Rp 100.000,-", 0, 1);
    $pdf->Cell(11, 5, utf8_decode(sprintf('%s %%', number_format($umsatz['mwst_satz'], 2, ',', ''))), 1, 0, 'R');
    // Zeilenumbruch einfügen
    $pdf->Ln();
}
// Zeilenumbrüche einfügen
$pdf->Ln();
$pdf->Ln();
// Schriftgrad einstellen
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(20, 6, utf8_decode('MwSt-Satz'), 0, 0, 'R');
$pdf->Cell(15, 6, utf8_decode('Flüge'), 0, 0, 'C');
$pdf->Cell(27, 6, utf8_decode('Ges.-Umsatz'), 0, 0, 'R');
// Zeilenumbruch einfügen
$pdf->Ln();
// vertikale Y-Position ermitteln
$y = $pdf->getY();
// Linienbreite einstellen, 0.2 mm
$pdf->SetLineWidth(0.2);
// Linie(n) zeichnen
$pdf->Line(25, $y, 90, $y);
// Schriftgrad einstellen
$pdf->SetFont('Arial', '', 10);
// Variable zur Aufsumierung der Umsätze anlegen
$umsatz_ges = 0.0;
foreach ($umsaetze['gesamtumsatz'] as $key => $val) {
    $pdf->Cell(20, 6, sprintf('%s %%', number_format($key, 2, ',', '')), 0, 0, 'R');
    $pdf->Cell(15, 6, $val['fluege'], 0, 0, 'C');
    $pdf->Cell(27, 6, sprintf('%s EUR', number_format($val['summe'], 2, ',', '')), 0, 0, 'R');
    // Umsatz aufsumieren
    $umsatz_ges += $val['summe'];
    // Zeilenumbruch einfügen
示例#4
0
$pdf->SetFont($fonte, "b", 12);
$pdf->setx(5);
$pdf->ln();
$pdf->SetFont($fonte, "", 14);
$pdf->setx(5);
$pdf->cell(50, 5, "Controle de Entregas", 0, 1);
$pdf->line(5, $pdf->GetY(), 290, $pdf->GetY());
$pdf->ln(10);
$pdf->setfont($fonte, "B", "14");
$pdf->cell(0, 5, $_GET["dtvenda"], 0, 1, "C");
$pdf->setfillcolor(235);
$pdf->SetFont($fonte, "b", 10);
$total = $db->entregas["total"];
$sql = " SELECT fun_nome,count(*) as total\n         FROM   comandas inner join comandaentrega \n                on cet_comid = com_id\n                inner join funcionarios on fun_id = cet_funid\n         WHERE com_dtcomanda = '" . strformat($_GET["dtvenda"], "dten") . "' group by fun_nome order by fun_nome";
$rs = $db->executa($sql);
$pdf->cell(140, 5, "Funcionário", "B", 0, "C", 1);
$pdf->cell(45, 5, "Qtde", "B", 1, "C", 1);
$pdf->SetFont($fonte, "", 10);
while ($ln = $db->fetch_array($rs)) {
    if ($pdf->getY() >= $pdf->h - 15) {
        $pdf->addpage();
        $pdf->SetFont($fonte, "b", 10);
        $pdf->cell(140, 5, "Funcionário", "B", 0, "C", 1);
        $pdf->cell(45, 5, "Qtde", "B", 1, "C", 1);
        $pdf->SetFont($fonte, "", 10);
    }
    $pdf->cell(140, 5, $ln["fun_nome"], 1, 0);
    $pdf->cell(45, 5, $ln["total"], 1, 1);
}
$pdf->ln();
$pdf->output();
示例#5
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;
    }
}
/**
 * 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;
    }
}
 /**
  * Add relevant header info to the pdf output
  *
  * @param  FPDF  $newpdf  The report pdf we are creating
  */
 public function print_pdf_header($newpdf)
 {
     global $CFG;
     //initial y position
     $initial_y = $newpdf->getY();
     //determine page with, not including margins
     $effective_page_width = $newpdf->w - $newpdf->lMargin - $newpdf->rMargin;
     //store the original font size
     $old_font_size = $newpdf->FontSizePt;
     //use a large font size for the header info
     $newpdf->setFontSize(12);
     //used to track vertical positioning
     $i = 0;
     //render any appropriate text for each header
     if ($header_info = $this->get_gas_gauge_header_info()) {
         foreach ($header_info as $header_entry) {
             //render across
             $newpdf->Cell($effective_page_width, 0, $header_entry, 0, 0, 'C');
             //draw a line below the text
             $line_top = $initial_y + 0.2 * $i + 0.1;
             $newpdf->Line($newpdf->lMargin, $line_top, $newpdf->lMargin + $effective_page_width, $line_top);
             //add necessary spacing
             $newpdf->Ln(0.2);
             $i++;
         }
     }
     //if the max value is not zero, render the gas gauge
     if ($this->gas_gauge_max_value != 0) {
         //retrieve the color palette as defined by the report
         $palette = $this->get_gas_gauge_color_palette();
         //approximate pixels using points
         $actual_radius = PHP_REPORT_GAS_GAUGE_MAXIMUM_WIDTH / 2 / 72;
         //set up the variables needed by the gas-gauge-generating script
         //current value on the gas gauge
         $passthru_value = $this->gas_gauge_value;
         //maximum value on the gauge
         $passthru_total = $this->gas_gauge_max_value;
         //radius of the gas gauge
         $passthru_radius = PHP_REPORT_GAS_GAUGE_MAXIMUM_WIDTH;
         //colour palette to use (also specifies number of sections)
         $passthru_palette = $palette;
         //indicate that we are persisting the image
         $passthru_persist = 1;
         //filename to save the image to
         $passthru_filename = tempnam($CFG->dataroot . '/temp', 'gas_gauge_');
         //generate the necessary image file
         $gas_gauge_url = $CFG->dirroot . '/blocks/php_report/gas_gauge_output.php';
         require_once $gas_gauge_url;
         //leftmost position of the gas gauge
         $left_position = $newpdf->w / 2 - $actual_radius;
         //vertical offset, based on number of headers
         $top_position = $initial_y + 0.2 * count($header_info) + 0.1;
         //draw the gas gauge and add appropriate vertical space
         $newpdf->Image($passthru_filename, $left_position, $top_position, 2 * $actual_radius, $actual_radius, 'png');
         $newpdf->Ln($actual_radius + 0.2);
         //delete the temporary image file
         unlink($passthru_filename);
     }
     //revert the font size to its initial value
     $newpdf->setFontSize($old_font_size);
 }