Subversion Repositories ALCASAR

Compare Revisions

No changes between revisions

Ignore whitespace Rev 2167 → Rev 2168

/web/acc/manager/htdocs/import_file.php
1,83 → 1,57
<?php
require('../lib/fpdf/fpdf.php');
/**
* Print credentials of imported users
*
* @author Tom Houdayer
* @copyright Copyright (C) ALCASAR (http://www.alcasar.net)
* @license GPL-3.0
* @version $Id$
*/
 
class fichePDF extends FPDF {
if ((!isset($_GET['file'])) || (empty($_GET['file']))) {
exit();
}
 
function Header()
{
$filename = $_GET['file'];
$format = ((isset($_GET['format'])) ? $_GET['format'] : 'txt');
 
}
function Footer()
{
//Positionnement à 1,5 cm du bas
$this->SetY(-15);
//Arial italique 8
$this->SetFont('Arial','I',8);
//Couleur du texte en gris
$this->SetTextColor(128);
//Numéro de page
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
if (($format !== 'txt') && ($format !== 'pdf')) {
exit();
}
 
function lirefichier($fichier)
{
$this->AddPage();
//Lecture des lignes du fichier
$lines = file($fichier);
$n = 1;
foreach($lines as $line){
//Times 12
$this->SetFont('Times','',10);
//Sortie du texte justifié
$this->Cell(0,5,utf8_decode($line));
$this->Ln();
++$n;
if ($n > (50)){ // on affiche 50 ligne par page soit 5 fiches usagers
$this->AddPage();
$n = 1;
}
}
}
$filePath = '/tmp/'.$filename.'.pwd';
if ((!is_file($filePath)) || (!is_readable($filePath))) {
exit('FILE_NOT_FOUND');
}
 
function getImportFile($importFileName, $format = "txt"){
$importFile = "/tmp/$importFileName.pwd";
if(is_file($importFile)&&is_readable($importFile)){
if ($format=="txt"){
//telechargement
$taille=filesize($importFile);
header("Content-Type: application/x-download");
header("Content-Length: $taille");
header("Content-Disposition: attachment; filename=\"$importFileName.txt\"");
header("Cache-Control: private, max-age=0, must-revalidate");
header("Pragma: public");
header("Content-Type: application/force-download; filename=\"$importFileName.txt\"");
ini_set("zlib.output_compression","0");
readfile($importFile);
exit();
}elseif ($format=="pdf"){
$pdf=new fichePDF();
$pdf->lirefichier($importFile);
$pdf->Output($importFileName.".pdf","D");
}else{
getImportFile($importFileName,"txt");
}
} else {
return false;
}
if ($format === 'txt') {
header('Content-Type: application/x-download');
header('Content-Length: '.filesize($filePath));
header('Content-Disposition: attachment; filename="'.$filename.'.txt"');
header('Content-Type: application/force-download; filename="'.$filename.'.txt"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression', '0');
readfile($filePath);
} else if ($format === 'pdf') {
// Convert to PDF
$html = '<!doctype html><html><head><meta charset="utf-8"></head><body><pre>';
$html .= file_get_contents($filePath);
$html .= '</pre></body></html>';
file_put_contents("$filePath.pdf.html", $html);
 
$command = 'wkhtmltopdf' . ' --quiet --disable-smart-shrinking --footer-font-size 8 --footer-left "ALCASAR" --footer-center "[page] / [toPage]" --footer-right "' . date('Y-m-d H:i:s') . '" ' . escapeshellarg("$filePath.pdf.html") . ' ' . escapeshellarg("$filePath.pdf");
$output;
$exitCode;
exec($command, $output, $exitCode);
 
header('Content-Type: application/pdf');
header('Content-Length: '.filesize("$filePath.pdf"));
header('Content-Disposition: attachment; filename="'.$filename.'.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
readfile("$filePath.pdf");
 
unlink("$filePath.pdf");
unlink("$filePath.pdf.html");
}
if (isset($_GET['file']) && $_GET['file']){
if (isset($_GET['format'])){
$format = $_GET['format'];
} else {
$format = "txt";
}
if (getImportFile($_GET['file'], $format)){
//fichier en cour de téléchargement
} else {
echo "erreur 2 ";
}
} else {
echo "erreur 1 ";
}
?>
Property changes:
Added: svn:keywords
+Id
\ No newline at end of property